backport from HEAD
[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 AC_PROG_CC
7 AC_PROG_CPP
8
9 AC_ARG_WITH(mysql-include-dir,
10 [  --with-mysql-include-dir=DIR       Directory where the MySQL includes may be found ],
11 [ mysql_include_dir="$withval" ]
12 )
13
14 AC_ARG_WITH(mysql-lib-dir,
15 [  --with-mysql-lib-dir=DIR       Directory where the MySQL libraries may be found ],
16 [ mysql_lib_dir="$withval" ]
17 )
18
19 AC_ARG_WITH(mysql-dir,
20 [  --with-mysql-dir=DIR       Base directory where MySQL is installed ],
21 [ mysql_lib_dir="$withval/lib/mysql"
22   mysql_include_dir="$withval/include"
23 ]
24 )
25
26 if test x$with_[]modname != xno; then
27
28         targetname=modname   # we might change this later.
29
30         AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, yes, no)
31         if test "x$MYSQL_CONFIG" = "xyes"
32         then
33                 sql_mysql_ldflags=`mysql_config --libs`
34                 sql_mysql_cflags=`mysql_config --cflags`
35                 AC_DEFINE(HAVE_MYSQL_H)
36         else
37                 AC_CHECK_LIB(z, compress, LIBS="$LIBS -lz")
38
39                 AC_MSG_CHECKING([for mysql/mysql.h])
40
41                 AC_TRY_COMPILE([#include <mysql/mysql.h>], [int a = 1;],
42                         MYSQL_INCLUDE=" ",
43                         MYSQL_INCLUDE=
44                 )
45
46                 if test "x$MYSQL_INCLUDE" = "x"; then
47                         old_CFLAGS="$CFLAGS"
48
49 dnl                     AC_LOCATE_DIR(mysql_include_dir,[mysql/mysql.h])
50
51                         for try in $mysql_include_dir /usr/local/include /usr/local/mysql/include ; do
52                                 CFLAGS="$old_CFLAGS -I$try"
53                                 AC_TRY_COMPILE([#include <mysql/mysql.h>], [int a = 1;],
54                                         MYSQL_INCLUDE="-I$try",
55                                         MYSQL_INCLUDE=
56                                 )
57                                 if test "x$MYSQL_INCLUDE" != "x"; then
58                                         AC_DEFINE(HAVE_MYSQL_MYSQL_H)
59                                         break;
60                                 fi
61                         done
62                         CFLAGS="$old_CFLAGS"
63                 fi
64
65                 if test "x$MYSQL_INCLUDE" = "x"; then
66                         AC_MSG_RESULT(no)
67                         AC_MSG_WARN([mysql headers not found.  Use --with-mysql-include-dir=<path>.])
68                         targetname=   # disabled module
69                 else
70                         sql_mysql_cflags="${sql_mysql_cflags} ${MYSQL_INCLUDE}"
71                         AC_MSG_RESULT(yes)
72                         AC_DEFINE(HAVE_MYSQL_H)
73   
74                         AC_MSG_CHECKING([for mysql_init in -lmysqlclient])
75
76                         old_LIBS="$LIBS"
77
78 dnl                     AC_LOCATE_DIR(mysql_lib_dir,[libmysqlclient.so])
79 dnl                     AC_LOCATE_DIR(mysql_lib_dir,[libmysqlclient.a])
80
81                         for try in $mysql_lib_dir /usr/lib /usr/lib/mysql /usr/local/lib/mysql /usr/local/mysql/lib/mysql; do
82                                 LIBS="$old_LIBS -L$try -lmysqlclient"
83                                 AC_TRY_LINK([extern char mysql_init();], [mysql_init()],
84                                         MYSQL_LIBS="-L$try -lmysqlclient $old_LIBS",
85                                         MYSQL_LIBS=
86                                 )
87                                 if test "x$MYSQL_LIBS" != "x"; then
88                                         break;
89                                 fi
90                         done
91                         LIBS="$old_LIBS"
92
93                         dnl #  If one or the other isn't found, disable them both..
94                         dnl #  If both are found, enable them both.
95                         if test "x$MYSQL_LIBS" = "x"; then
96                                 AC_MSG_RESULT(no)
97                                 MYSQL_INCLUDE=
98                                 AC_MSG_WARN([mysql libraries not found.  Use --with-mysql-lib-dir=<path>.])
99                                 targetname=   # disabled module
100                         else
101                                 AC_MSG_RESULT(yes) 
102                                 sql_mysql_ldflags="$sql_mysql_ldflags $MYSQL_LIBS"
103                         fi
104                 fi
105                 sql_mysql_ldflags="$sql_mysql_ldflags $LIBS"
106         fi
107
108         if test "x$targetname" = "x"; then
109                 AC_MSG_WARN([sql submodule 'mysql' disabled])
110         fi
111
112 else
113         targetname=
114         echo \*\*\* module modname is disabled.
115 fi
116
117 AC_SUBST(sql_mysql_ldflags)
118 AC_SUBST(sql_mysql_cflags)
119 AC_SUBST(targetname)
120 AC_OUTPUT(Makefile)