summaryrefslogtreecommitdiffstats
path: root/src/modules/rlm_sql/drivers/rlm_sql_mysql/configure.ac
blob: 00e07b628049504f795911e7ebcf57b06bd1e9c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
AC_PREREQ([2.59])
AC_INIT(rlm_sql_mysql.c)
AC_REVISION($Revision$)
FR_INIT_MODULE([rlm_sql_mysql])
AC_CONFIG_HEADER(config.h)

fail=
SMART_LIBS=
SMART_CLFAGS=

if test x$with_[]modname != xno; then
	dnl ############################################################
	dnl # Check for command line options
	dnl ############################################################

	dnl extra argument: --with-mysql-include-dir=DIR
	mysql_include_dir=
	AC_ARG_WITH(mysql-include-dir,
	[AS_HELP_STRING([--with-mysql-include-dir=DIR],
		[Directory where the mysql includes may be found])],
	[case "$withval" in
		no)
		AC_MSG_ERROR(Need mysql-include-dir)
		;;
		yes)
		;;
		*)
		mysql_include_dir="$withval"
		;;
	esac])

	dnl extra argument: --with-mysql-lib-dir=DIR
	mysql_lib_dir=
	AC_ARG_WITH(mysql-lib-dir,
	[AS_HELP_STRING([--with-mysql-lib-dir=DIR],
		[Directory where the mysql libraries may be found])],
	[case "$withval" in
		no)
		AC_MSG_ERROR(Need mysql-lib-dir)
		;;
		yes)
		;;
		*)
		mysql_lib_dir="$withval"
		;;
	esac])

	dnl extra argument: --with-mysql-dir=DIR
	AC_ARG_WITH(mysql-dir,
	[AS_HELP_STRING([--with-mysql-dir=DIR],
		[Base directory where mysql is installed])],
	[case "$withval" in
		no)
		AC_MSG_ERROR(Need mysql-dir)
		;;
		yes)
		;;
		*)
		mysql_lib_dir="$withval/lib"
		mysql_include_dir="$withval/include"
		;;
	esac])

	dnl extra argument: --with-threads
	mysql_with_threads=yes
	AC_ARG_WITH(threads,
	[AS_HELP_STRING([--with-threads],
		[use threads, if available. (default=yes)])],
	[case "$withval" in
		no)
		mysql_with_threads=no
		;;
		*)
		;;
	esac])

	dnl ############################################################
	dnl # Check for programs
	dnl ############################################################

	AC_PROG_CC
	AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, yes, no)

	dnl ############################################################
	dnl # Check for libraries
	dnl ############################################################

	dnl # Older versions of mysqlclient packages had two variants libmysqlclient
	dnl # and libmysqlclient_r. libmysqlclient_r is the threadsafe variant that
	dnl # is per-connection threadsafe. If that is available on the system it
	dnl # should be used in preference to libmysqlclient.
	dnl # More recent versions >~ 5.6 have stopped including libmyqlclient_r
	dnl # however (as libmysqlclient is now threadsafe), so we should fall back
	dnl # to libmysqlclient if it is the only one available on the system.

	dnl # Use linker arguments from mysql_config if available, then fallback
	dnl # to hunting around if we can't find the client library.
	if test "x$MYSQL_CONFIG" = "xyes"; then
		mysql_libs="$(mysql_config --libs_r)"
		old_LIBS="$LIBS"
		LIBS="$mysql_libs $LIBS"

		dnl # First check for libmysqlclient_r
		AC_MSG_CHECKING([for mysql_init in -lmysqlclient_r (using mysql_config)])
		AC_TRY_LINK_FUNC([mysql_init], [have_libmysqlclient_r=yes])

		LIBS="$old_LIBS"
		if test "x$have_libmysqlclient_r" = "xyes"; then
			AC_MSG_RESULT(yes)

			have_a_libmysqlclient='yes'
			SMART_LIBS="$mysql_libs $SMART_LIBS"
		else
			AC_MSG_RESULT(no)
		fi

		dnl # If that's not available check for libmysqlclient
		if test "x$have_a_libmysqlclient" != "xyes"; then
			mysql_libs="$(mysql_config --libs)"
			old_LIBS="$LIBS"
			LIBS="$mysql_libs $LIBS"

			AC_MSG_CHECKING([for mysql_init in -lmysqlclient (using mysql_config)])
			AC_TRY_LINK_FUNC([mysql_init], [have_libmysqlclient=yes])

			LIBS="$old_LIBS"
			if test "x$have_libmysqlclient" = "xyes"; then
				AC_MSG_RESULT(yes)

				have_a_libmysqlclient=yes
				SMART_LIBS="$mysql_libs $SMART_LIBS"
			else
				AC_MSG_RESULT(no)
			fi
		fi
	fi

	dnl # Check for libmysqlclient_r
	if test "x$have_a_libmysqlclient" != "xyes"; then
	    smart_try_dir="$mysql_lib_dir /usr/lib /usr/lib/mysql /usr/local/lib/mysql /usr/local/mysql/lib/mysql"
	    FR_SMART_CHECK_LIB(mysqlclient_r, mysql_init)
	    if test "x$ac_cv_lib_mysqlclient_r_mysql_init" = "xyes"; then
			have_a_libmysqlclient='yes'
	    fi
	fi

	dnl # Check for libmysqlclient
	if test "x$have_a_libmysqlclient" != "xyes"; then
	    smart_try_dir="$mysql_lib_dir /usr/lib /usr/lib/mysql /usr/local/lib/mysql /usr/local/mysql/lib/mysql"
	    FR_SMART_CHECK_LIB(mysqlclient, mysql_init)
	    if test "x$ac_cv_lib_mysqlclient_mysql_init" = "xyes"; then
			have_a_libmysqlclient='yes'
	    fi
	fi

	dnl # Check for MariaDB
	dnl # If that's not available check for libmariadb
	if test "x$have_a_libmysqlclient" != "xyes"; then
		mysql_libs="$(mariadb_config --libs)"
		old_LIBS="$LIBS"
		LIBS="$mysql_libs $LIBS"

		AC_MSG_CHECKING([for mysql_init in -lmariadb (using mariadb_config)])
		AC_TRY_LINK_FUNC([mysql_init], [have_libmysqlclient=yes])

		LIBS="$old_LIBS"
		if test "x$have_libmysqlclient" = "xyes"; then
			AC_MSG_RESULT(yes)

			have_a_libmysqlclient=yes
			SMART_LIBS="$mysql_libs $SMART_LIBS"
		else
			AC_MSG_RESULT(no)
		fi
	fi

	if test "x$have_a_libmysqlclient" != "xyes"; then
		AC_MSG_WARN([MySQL libraries not found. Use --with-mysql-lib-dir=<path>.])
		fail="$fail libmysqlclient || libmysqlclient_r"
	fi

    dnl ############################################################
    dnl # Check for header files
    dnl ############################################################
    if test "x$MYSQL_CONFIG" = "xyes"; then
		mod_cflags="$(mysql_config --cflags)"
		old_CFLAGS="$CFLAGS"
		CFLAGS="$CFLAGS $mod_cflags"
		AC_MSG_CHECKING([for mysql.h (using mysql_config --cflags)])
		AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;], have_mysql_h=yes)
		if test "x$have_mysql_h" = "xyes"; then
			AC_MSG_RESULT(yes)
			AC_DEFINE(HAVE_MYSQL_H, [], [Define if you have <mysql.h>])
			SMART_CPPFLAGS="$SMART_CPPFLAGS $mod_cflags"
		else
			AC_MSG_RESULT(no)

			mod_cflags="$(mysql_config --include)"
			CFLAGS="$old_CFLAGS $mod_cflags"
			AC_MSG_CHECKING([for mysql.h (using mysql_config --include)])
			AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;], have_mysql_h=yes)
			if test "x$have_mysql_h" = "xyes"; then
				AC_MSG_RESULT(yes)
				AC_DEFINE(HAVE_MYSQL_H, [], [Define if you have <mysql.h>])
				SMART_CPPFLAGS="$SMART_CPPFLAGS $mod_cflags"
			else
				AC_MSG_RESULT(no)
			fi
		fi
		CFLAGS="$old_CFLAGS"
    fi

    # MariaDB
    if test "x$have_mysql_h" != "xyes"; then
		mod_cflags="$(mariadb_config --cflags)"
		old_CFLAGS="$CFLAGS"
		CFLAGS="$CFLAGS $mod_cflags"
		AC_MSG_CHECKING([for mysql.h (using mariadb_config --cflags)])
		AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;], have_mysql_h=yes)
		if test "x$have_mysql_h" = "xyes"; then
			AC_MSG_RESULT(yes)
			AC_DEFINE(HAVE_MYSQL_H, [], [Define if you have <mysql.h>])
			SMART_CPPFLAGS="$SMART_CPPFLAGS $mod_cflags"
		else
			AC_MSG_RESULT(no)

			mod_cflags="$(mariadb_config --include)"
			CFLAGS="$old_CFLAGS $mod_cflags"
			AC_MSG_CHECKING([for mysql.h (using mariadb_config --include)])
			AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;], have_mysql_h=yes)
			if test "x$have_mysql_h" = "xyes"; then
				AC_MSG_RESULT(yes)
				AC_DEFINE(HAVE_MYSQL_H, [], [Define if you have <mysql.h>])
				SMART_CPPFLAGS="$SMART_CPPFLAGS $mod_cflags"
			else
				AC_MSG_RESULT(no)
			fi
		fi
		CFLAGS="$old_CFLAGS"
    fi

    if test "x$have_mysql_h" != "xyes"; then
		smart_try_dir="$mysql_include_dir /usr/local/include /usr/local/mysql/include"
		FR_SMART_CHECK_INCLUDE(mysql/mysql.h)
		if test "x$ac_cv_header_mysql_mysql_h" = "xyes"; then
	    	AC_DEFINE(HAVE_MYSQL_MYSQL_H, [], [Define if you have <mysql/mysql.h>])
		else
	    	AC_MSG_WARN([MySQL headers not found. Use --with-mysql-include-dir=<path>.])
	    	fail="$fail mysql.h"
		fi
    fi

    targetname=modname
else
    targetname=
    echo \*\*\* module modname is disabled.
fi

dnl Don't change this section.
if test "x$fail" != x; then
	if test "x${enable_strict_dependencies}" = xyes; then
		AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
	else
		AC_MSG_WARN([silently not building ]modname[.])
		AC_MSG_WARN([FAILURE: ]modname[ requires:$fail.]);
		targetname=
	fi
fi

mod_ldflags="$SMART_LIBS"
mod_cflags="$SMART_CPPFLAGS"
AC_SUBST(mod_ldflags)
AC_SUBST(mod_cflags)
AC_SUBST(targetname)
AC_OUTPUT(all.mk)