corrected typo
[freeradius.git] / src / modules / rlm_sql / drivers / rlm_sql_mysql / configure.in
1 AC_INIT(sql_mysql.c)
2 AC_REVISION($Revision$)
3 AC_DEFUN(modname,[rlm_sql_mysql])
4 AC_CONFIG_HEADER(config.h)
5
6 SMART_LIBS=""
7 SMART_CLFAGS=""
8 mysql_lib_dir=""
9 mysql_include_dir=""
10
11 if test x$with_[]modname != xno; then
12
13     targetname=modname # we change this if a test fails
14
15     dnl ############################################################
16     dnl # Check for command line options
17     dnl ############################################################
18
19     dnl extra argument: --with-mysql-dir=DIR
20     AC_ARG_WITH(mysql-dir,
21     [  --with-mysql-dir=DIR          base directory where MySQL is installed ],
22     [ mysql_lib_dir="$withval/lib/mysql"
23       mysql_include_dir="$withval/include" ]
24     )
25
26     dnl extra argument: --with-mysql-lib-dir=DIR
27     AC_ARG_WITH(mysql-lib-dir,
28     [  --with-mysql-lib-dir=DIR      directory where the MySQL libraries may be found ],
29     [ mysql_lib_dir="$withval" ]
30     )
31
32     dnl extra argument: --with-mysql-include-dir=DIR
33     AC_ARG_WITH(mysql-include-dir,
34     [  --with-mysql-include-dir=DIR  directory where the MySQL includes may be found ],
35     [ mysql_include_dir="$withval" ]
36     )
37
38     dnl extra argument: --with-threads
39     mysql_with_threads=yes
40     AC_ARG_WITH(threads,
41     [  --with-threads                use threads, if available. (default=yes) ],
42     [ case "$withval" in
43         no)
44             mysql_with_threads=no
45             ;;
46         *)
47             ;;
48         esac ]
49     )
50
51     dnl ############################################################
52     dnl # Check for programs
53     dnl ############################################################
54
55     AC_PROG_CC
56     AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, yes, no)
57
58     dnl ############################################################
59     dnl # Check for libraries
60     dnl ############################################################
61
62     dnl pthread stuff is usually in -lpthread
63     dnl or in -lc_r, on *BSD
64     if test "x$mysql_with_threads" = "xyes"; then
65         AC_CHECK_LIB(pthread, pthread_create,
66                      [ LIBS="-lpthread $LIBS" ],
67                      AC_CHECK_LIB(c_r, pthread_create,
68                                   [ LIBS="-lc_r $LIBS" ],
69                                   [ mysql_with_threads=no ]
70                                   )
71                      )
72     fi
73
74     if test "x$mysql_with_threads" = "xyes"; then
75         dnl try to link to libmysqlclient_r
76         if test "x$MYSQL_CONFIG" = "xyes"; then
77             mysql_libs="$(mysql_config --libs_r)"
78             old_LIBS="$LIBS"
79             LIBS="$mysql_libs $LIBS"
80             AC_MSG_CHECKING([for mysql_init in -lmysqlclient_r (using mysql_config)])
81             AC_TRY_LINK_FUNC(mysql_init, have_libmysqlclient_r=yes)
82             LIBS="$old_LIBS"
83             if test "x$have_libmysqlclient_r" = "xyes"; then
84                 AC_MSG_RESULT(yes)
85                 SMART_LIBS="$mysql_libs $SMART_LIBS"
86             else
87                 AC_MSG_RESULT(no)
88             fi
89         fi
90         if test "x$have_libmysqlclient_r" != "xyes"; then
91             dnl mysql_config didn't work :(
92             smart_try_dir="$mysql_lib_dir /usr/lib /usr/lib/mysql \
93                 /usr/local/lib/mysql /usr/local/mysql/lib/mysql"
94             AC_SMART_CHECK_LIB(mysqlclient_r, mysql_init)
95             if test "x$ac_cv_lib_mysqlclient_r_mysql_init" != "xyes"
96                 then
97                 dnl nothing worked :(
98                 AC_MSG_WARN([mysql libraries not found. Use --with-mysql-lib-dir=<path>.])
99                 targetname="" # disable module
100             fi
101         fi
102     else
103         dnl try to link to libmysqlclient (without threads support)
104         if test "x$MYSQL_CONFIG" = "xyes"; then
105             mysql_libs="$(mysql_config --libs)"
106             old_LIBS="$LIBS"
107             LIBS="$mysql_libs $LIBS"
108             AC_MSG_CHECKING([for mysql_init in -lmysqlclient (using mysql_config)])
109             AC_TRY_LINK_FUNC(mysql_init, have_libmysqlclient=yes)
110             LIBS="$old_LIBS"
111             if test "x$have_libmysqlclient" = "xyes"; then
112                 AC_MSG_RESULT(yes)
113                 SMART_LIBS="$mysql_libs $SMART_LIBS"
114             else
115                 AC_MSG_RESULT(no)
116             fi
117         fi
118         if test "x$have_libmysqlclient" != "xyes"; then
119             dnl mysql_config didn't work :(
120             smart_try_dir="$mysql_lib_dir /usr/lib /usr/lib/mysql \
121                 /usr/local/lib/mysql /usr/local/mysql/lib/mysql"
122             AC_SMART_CHECK_LIB(mysqlclient, mysql_init)
123             if test "x$ac_cv_lib_mysqlclient_mysql_init" != "xyes"
124                 then
125                 dnl nothing worked :(
126                 AC_MSG_WARN([mysql libraries not found. Use --with-mysql-lib-dir=<path>.])
127                 targetname="" # disable module
128             fi
129         fi
130     fi
131
132     dnl ############################################################
133     dnl # Check for header files
134     dnl ############################################################
135
136     if test "x$MYSQL_CONFIG" = "xyes"; then
137         mysql_cflags="$(mysql_config --cflags)"
138         old_CFLAGS="$CFLAGS"
139         CFLAGS="$CFLAGS $mysql_cflags"
140         AC_MSG_CHECKING([for mysql.h (using mysql_config)])
141         AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;],
142                        have_mysql_h=yes)
143         if test "x$have_mysql_h" = "xyes"; then
144             AC_MSG_RESULT(yes)
145             AC_DEFINE(HAVE_MYSQL_H, [], [Define if you have <mysql.h>])
146             SMART_CFLAGS="$SMART_CFLAGS $mysql_cflags"
147         else
148             AC_MSG_RESULT(no)
149         fi
150         CFLAGS="$old_CFLAGS"
151     fi
152     if test "x$have_mysql_h" != "xyes"; then
153         dnl mysql_config didn't work :(
154         smart_try_dir="$mysql_include_dir /usr/local/include \
155                 /usr/local/mysql/include"
156         AC_SMART_CHECK_INCLUDE(mysql/mysql.h)
157         if test "$ac_cv_header_mysql_mysql_h" = "yes"; then
158             AC_DEFINE(HAVE_MYSQL_MYSQL_H, [],
159                       [Define if you have <mysql/mysql.h>])
160         else
161             dnl nothing worked :(
162             AC_MSG_WARN([mysql headers not found. Use --with-mysql-include-dir=<path>.])
163             targetname="" # disable module
164         fi
165     fi
166
167     if test "x$targetname" = "x"; then
168         AC_MSG_WARN([sql submodule 'mysql' disabled])
169     fi
170 else
171     targetname=
172     echo \*\*\* module modname is disabled.
173 fi
174
175 sql_mysql_ldflags="$SMART_LIBS"
176 sql_mysql_cflags="$SMART_CFLAGS"
177 AC_SUBST(sql_mysql_ldflags)
178 AC_SUBST(sql_mysql_cflags)
179 AC_SUBST(targetname)
180 AC_OUTPUT(Makefile)