Fix debug option for non-GCC compilers
[shibboleth/sp.git] / configure.ac
1 AC_PREREQ([2.50])
2 AC_INIT([shibboleth], [1.2], [shibboleth-users@internet2.edu], [shibboleth])
3 AM_CONFIG_HEADER(config.h)
4 AM_INIT_AUTOMAKE(shibboleth, 1.2)
5
6 sinclude(acx_pthread.m4)
7 sinclude(acx_rpctest.m4)
8
9 AC_ARG_ENABLE(debug,
10     AC_HELP_STRING(--enable-debug, [Have GCC compile with symbols (Default = no)
11 ]),
12     enable_debug=$enableval, enable_debug=no)
13
14 if test "$enable_debug" = "yes" ; then
15     GCC_CFLAGS="$CFLAGS -g -D_DEBUG"
16     GCC_CXXFLAGS="$CXXFLAGS -g -D_DEBUG"
17 else
18     GCC_CFLAGS="$CFLAGS -O2 -DNDEBUG"
19     GCC_CXXFLAGS="$CXXFLAGS -O2 -DNDEBUG"
20 fi
21
22 AC_PROG_CC([gcc3 gcc cc])
23 AC_PROG_CXX([g++3 g++ c++ CC])
24
25 if test "$GCC" = "yes" ; then
26     CFLAGS="$GCC_CFLAGS"
27     CXXFLAGS="$GCC_CXXFLAGS"
28 fi
29
30 AC_DISABLE_STATIC
31 AC_PROG_LIBTOOL
32
33 AC_LANG(C++)
34
35 # Checks for typedefs, structures, and compiler characteristics.
36 AC_C_CONST
37 AC_TYPE_SIZE_T
38 AC_STRUCT_TM
39
40 # Checks for library functions.
41 AC_FUNC_STRFTIME
42 AC_FUNC_STRERROR_R
43 AC_CHECK_FUNCS([strchr strdup strstr gmtime_r strtok_r strcasecmp])
44 AC_CHECK_HEADERS([dlfcn.h])
45
46 # C++ requirements
47 AC_CXX_REQUIRE_STL
48 AC_CXX_NAMESPACES
49
50
51 # old_LIBS="$LIBS"
52 # AC_SEARCH_LIBS(xdr_uint64_t,nsl,,
53 #       [CFLAGS="$CFLAGS -DNEED_XDR_LONGLONG"
54 #        CXXFLAGS="$CXXFLAGS -DNEED_XDR_LONGLONG"])
55 # LIBS="$old_LIBS"
56
57 # checks for pthreads
58 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
59 if test $enable_threads != "pthread"; then
60     AC_MSG_ERROR([unable to find pthreads, currently this is required])
61 else
62     AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
63     LIBS="$PTHREAD_LIBS $LIBS"
64     CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
65     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
66 fi
67
68 # Test RPC now -- deal with it later
69 ACX_RPCTEST([rpctest="yes"],[rpctest="no"])
70
71 AC_ARG_WITH(dmalloc,
72             AC_HELP_STRING([--with-dmalloc=PATH], [where dmalloc is installed]),
73             [if test x_$with_dmalloc != x_/usr; then
74                 LDFLAGS="-L${with_dmalloc}/lib $LDFLAGS"
75                 CPPFLAGS="-I${with_dmalloc}/include $CPPFLAGS"
76             fi
77             AC_CHECK_LIB(dmallocxx, dmalloc_shutdown,,
78                          AC_MSG_ERROR([unable to find dmallocxx library]))
79             ])
80
81 # OpenSSL settings
82 AC_PATH_PROG(PKG_CONFIG, pkg-config)
83 if test "x$PKG_CONFIG" = x || test "x$PKG_CONFIG" = "xno" ; then
84     AC_ARG_WITH(openssl, 
85             AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
86             [if test x_$with_openssl != x_/usr; then
87             SSLLIBS="-L${with_openssl}/lib"
88             SSLFLAGS="-I${with_openssl}/include"
89             fi])
90     SSLLIBS="$SSLLIBS -lssl -lcrypto"
91 else
92     SSLLIBS="`$PKG_CONFIG --libs openssl`"
93     SSLFLAGS="`$PKG_CONFIG --cflags openssl`"
94 fi
95 AC_MSG_CHECKING(for OpenSSL libraries)
96 AC_MSG_RESULT($SSLLIBS)
97 LIBS="$LIBS $SSLLIBS"
98 AC_MSG_CHECKING(for OpenSSL cflags)
99 AC_MSG_RESULT($SSLFLAGS)
100 CPPFLAGS="$SSLFLAGS $CPPFLAGS"
101
102 AC_CHECK_HEADER([openssl/ssl.h],,
103                 AC_MSG_ERROR([unable to find openssl header files]))
104 AC_MSG_CHECKING(for ERR_load_CRYPTO_string)
105 AC_TRY_LINK_FUNC([ERR_load_CRYPTO_strings],,
106              AC_MSG_ERROR([unable to link with openssl libraries]))
107 AC_MSG_RESULT(yes)
108 AC_MSG_CHECKING(for SSL_library_init)
109 AC_TRY_LINK_FUNC([SSL_library_init],, 
110              AC_MSG_ERROR([unable to link with openssl libraries]))
111 AC_MSG_RESULT(yes)
112
113 # log4cpp settings
114 AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config)
115 AC_ARG_WITH(log4cpp,
116             AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp is installed]),
117             [LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config"])
118 if test -f "${LOG4CPP_CONFIG}"; then
119     LDFLAGS="`${LOG4CPP_CONFIG} --libs` $LDFLAGS"
120     CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS"
121 else
122     AC_MSG_WARN([log4cpp-config not found, guessing at log4cpp build settings])
123     LIBS="-llog4cpp $LIBS"
124 fi
125 AC_CHECK_HEADER([log4cpp/Category.hh],,AC_MSG_ERROR([unable to find log4cpp header files]))
126 AC_TRY_LINK(
127         [#include <log4cpp/Category.hh>],
128         [log4cpp::Category::getInstance("foo")],
129         [AC_DEFINE(HAVE_LIBLOG4CPP,1,[Define if log4cpp library was found])],
130         [AC_MSG_ERROR([unable to link with log4cpp])])
131
132 # Xerces settings
133 AC_ARG_WITH(xerces, 
134             AC_HELP_STRING([--with-xerces=PATH], [where xerces-c is installed]),
135             [if test x_$with_xerces != x_/usr; then
136                 LDFLAGS="-L${with_xerces}/lib $LDFLAGS"
137                 CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
138             fi])
139 LIBS="-lxerces-c $LIBS"
140 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,
141                 AC_MSG_ERROR([unable to find xerces header files]))
142 AC_TRY_LINK(
143         [#include <xercesc/util/PlatformUtils.hpp>
144 #include <xercesc/util/XercesVersion.hpp>],
145         [#if _XERCES_VERSION >= 20300
146 xercesc::XMLPlatformUtils::Initialize();
147 #else
148 #error Need Xerces-C version 2.3 or higher
149 #endif],
150         [AC_DEFINE(HAVE_LIBXERCESC,1,[Define if Xerces-C library was found])],
151         [AC_MSG_ERROR([unable to link with Xerces])])
152
153 # XML-Security settings
154 AC_ARG_WITH(xmlsec,
155             AC_HELP_STRING([--with-xmlsec=PATH], [where xmlsec is installed]),
156             [if test x_$with_xmlsec != x_/usr; then
157                 LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
158                 CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
159             fi])
160 LIBS="-lxml-security-c $LIBS"
161 AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,AC_MSG_ERROR([unable to find xsec header files]))
162 AC_TRY_LINK(
163         [#include <xsec/utils/XSECPlatformUtils.hpp>],
164         [XSECPlatformUtils::Initialise()],
165         [AC_DEFINE(HAVE_LIBXSEC,1,[Define if XML-Sec library was found])],
166         [AC_MSG_ERROR([unable to link with XML-Sec])])
167
168 # OpenSAML settings
169 AC_ARG_WITH(saml,
170             AC_HELP_STRING([--with-saml=PATH], [where saml is installed]),
171             [if test x_$with_saml != x_/usr; then
172                 LDFLAGS="-L${with_saml}/lib $LDFLAGS"
173                 CPPFLAGS="-I${with_saml}/include $CPPFLAGS"
174             fi])
175 AC_CHECK_HEADER([saml/saml.h],,
176                 AC_MSG_ERROR([unable to find saml header files]))
177 LIBS="-lsaml $LIBS"
178 AC_TRY_LINK(
179         [#include <saml/saml.h>
180 #include <saml/version.h>],
181         [#if _OPENSAML_VERSION >= 10000
182 saml::SAMLConfig::getConfig();
183 #else
184 #error Need OpenSAML version 1.0 or higher
185 #endif],
186         [AC_DEFINE(HAVE_SAML,1,[Define if saml library was found])],
187         [AC_MSG_ERROR([unable to link with saml, or version too old])])
188
189 # output the underlying makefiles
190 WANT_SUBDIRS="doc shib schemas configs shib-target shar siterefresh test xmlproviders"
191 AC_CONFIG_FILES([Makefile doc/Makefile shib/Makefile schemas/Makefile \
192                  configs/Makefile oncrpc/Makefile oncrpc/rpc/Makefile \
193                  shib-target/Makefile shar/Makefile siterefresh/Makefile \
194                  test/Makefile xmlproviders/Makefile])
195
196
197 # now deal with the rpc library, to see if we need to build our own
198 if test $rpctest = "no"; then
199     WANT_SUBDIRS="oncrpc $WANT_SUBDIRS"
200         AC_DEFINE(USE_OUR_ONCRPC,1,[Define if using embedded version of ONC RPC.])
201 fi
202 AM_CONDITIONAL(USE_OUR_ONCRPC,test "$rpctest" = "no")
203
204
205 # Apache 1.3 (mod_shib_13)
206 #   --with-apache-13 (static build, no idea how to do this yet, so not supported)
207 #   --with-apxs      (DSO build, the normal way, uses apxs to derive build flags)
208 #   --without-apxs   (DSO build, you tell us how to build using the environment)
209
210 AC_ARG_ENABLE(apache-13,
211         AC_HELP_STRING([--enable-apache-13], [enable the Apache 1.3 modules]),
212         [ if test "x$enableval" = "x" ; then
213               WANT_APACHE_13=yes
214           else
215               WANT_APACHE_13="$enableval"
216           fi
217         ], [ WANT_APACHE_13=no ])
218 AC_MSG_CHECKING(whether to build Apache-1.3 support)
219 if test "$WANT_APACHE_13" != yes && test "$WANT_APACHE_13" != no ; then
220    WANT_APACHE_13=yes
221 fi
222 AC_MSG_RESULT($WANT_APACHE_13)
223
224 if test "$WANT_APACHE_13" = yes ; then
225
226 AC_ARG_WITH(apxs,
227 [  --with-apxs[=FILE]        Build shared Apache module(s). FILE is the optional
228                           pathname to the Apache apxs tool; defaults to "apxs".],
229 [
230     if test "$withval" = "yes"; then
231       for i in /usr/sbin /usr/local/apache/bin ; do
232         if test -f "$i/apxs"; then
233           APXS="$i/apxs"
234         fi
235       done
236       if test -z "$APXS"; then
237         APXS=apxs
238       fi
239     else
240       APXS="$withval"
241     fi
242 ],
243 [
244     AC_PATH_PROG(APXS, apxs, no)
245 ])
246
247 AC_MSG_CHECKING([for dynamic Apache-1.3 module support (w/ or w/o APXS)])
248 if test "$APXS" = "no"; then
249
250     # --without-apxs means you want the modules,
251     #       but want to tell us how to build them
252     AC_MSG_RESULT(yes, but use environment, not apxs)
253     echo
254     echo "Did you set one or more of these?"
255     echo
256     echo "APXS_CFLAGS APXS_PREFIX APXS_INCLUDE APXS_LIBEXEC APXS_SYSCONFDIR"
257     echo
258
259     AC_MSG_NOTICE([APXS_CFLAGS is $APXS_CFLAGS])
260
261     # try and find the Apache root
262     if test -z "$APXS_PREFIX"; then
263         if test -d "/usr/local/apache"; then
264             APXS_PREFIX="/usr/local/apache"
265         else
266             AC_MSG_ERROR([You MUST set APXS_PREFIX so the right Apache can be located!])
267         fi
268     elif test ! -d "$APXS_PREFIX"; then
269         AC_MSG_ERROR([APXS_PREFIX of $APXS_PREFIX cannot be found])
270     fi
271     AC_MSG_NOTICE([APXS_PREFIX is $APXS_PREFIX])
272     
273
274     # other subfolders might be derived from APXS_PREFIX
275     if test -z "$APXS_INCLUDE"; then
276         if test -f "$APXS_PREFIX/include/httpd.h"; then
277             APXS_INCLUDE="$APXS_PREFIX/include"
278         else
279             AC_MSG_ERROR([can't find Apache include files beneath $APXS_PREFIX])
280         fi
281     elif ! test -f "$APXS_INCLUDE/httpd.h"; then
282         AC_MSG_ERROR([APXS_INCLUDE of $APXS_INCLUDE does not contain Apache headers])
283     fi
284     AC_MSG_NOTICE([APXS_INCLUDE is $APXS_INCLUDE])
285
286     if test -z "$APXS_LIBEXEC"; then
287         if test -d "$APXS_PREFIX/libexec"; then
288             APXS_LIBEXEC="$APXS_PREFIX/libexec"
289         elif test -d "$APXS_PREFIX/modules"; then
290             APXS_LIBEXEC="$APXS_PREFIX/modules"
291         else
292             AC_MSG_ERROR([can't find Apache libexec/module directory beneath $APXS_PREFIX])
293         fi
294     elif ! test -d "$APXS_LIBEXEC"; then
295         AC_MSG_ERROR([APXS_LIBEXEC of $APXS_LIBEXEC does not exist])
296     fi
297     AC_MSG_NOTICE([APXS_LIBEXEC is $APXS_LIBEXEC])
298
299     if test -z "$APXS_SYSCONFDIR"; then
300         if test -d "$APXS_PREFIX/conf"; then
301             APXS_SYSCONFDIR="$APXS_PREFIX/conf"
302         else
303             AC_MSG_ERROR([can't find Apache conf directory beneath $APXS_PREFIX])
304         fi
305     elif ! test -d "$APXS_SYSCONFDIR"; then
306         AC_MSG_ERROR([APXS_SYSCONFDIR of $APXS_SYSCONFDIR does not exist])
307     fi
308     AC_MSG_NOTICE([APXS_SYSCONFDIR is $APXS_SYSCONFDIR])
309
310     WANT_APACHE_13="yes"
311
312 elif test -n "$APXS"; then
313
314     # extract settings we need from APXS -q
315     APXS_CC="`$APXS -q CC`"
316     APXS_CFLAGS="`$APXS -q CFLAGS` `$APXS -q CFLAGS_SHLIB`"
317     APXS_INCLUDE="`$APXS -q INCLUDEDIR`"
318     APXS_LIBEXEC="`$APXS -q LIBEXECDIR`"
319     APXS_SYSCONFDIR="`$APXS -q SYSCONFDIR`"
320
321     AC_SUBST(APXS)
322     AC_MSG_RESULT(found at $APXS)
323
324     if test -z "`$APXS -q LD_SHLIB`" || test "$APXS_LIBEXEC" = "modules"; then
325             AC_MSG_ERROR(
326 [Your APXS installation is broken and cannot be used.
327     Please see http://www.webdav.org/mod_dav/install.html#apxs for
328     more information.])
329     fi
330
331     WANT_APACHE_13="yes"
332
333 else
334     # guess we're not doing Apache 1.3
335     AC_MSG_RESULT(no)
336     WANT_APACHE_13="no"
337 fi
338 fi
339
340 AC_SUBST(APXS_CFLAGS)
341 AC_SUBST(APXS_INCLUDE)
342 AC_SUBST(APXS_LIBEXEC)
343 AC_SUBST(APXS_SYSCONFDIR)
344 AM_CONDITIONAL(HAVE_APXS,test -n "$APXS")
345
346
347 # Apache 2.0 (mod_shib_20)
348 #   --with-apache-20   (static build, no idea how to do this yet, so not supported)
349 #   --with-apxs2       (DSO build, the normal way, uses apxs to derive build flags)
350 #   --without-apxs2    (DSO build, you tell us how to build using the environment)
351
352 AC_ARG_ENABLE(apache-20,
353         AC_HELP_STRING([--enable-apache-20], [enable the Apache 2.0 modules]),
354         [ if test "x$enableval" = "x" ; then
355               WANT_APACHE_20=yes
356           else
357               WANT_APACHE_20="$enableval"
358           fi
359         ], [ WANT_APACHE_20=no ])
360
361 AC_MSG_CHECKING(whether to build Apache-2.0 support)
362 if test "$WANT_APACHE_20" != yes && test "$WANT_APACHE_20" != no ; then
363    WANT_APACHE_20=yes
364 fi
365 AC_MSG_RESULT($WANT_APACHE_20)
366
367 if test "$WANT_APACHE_20" = yes ; then
368
369 AC_ARG_WITH(apxs2,
370 [  --with-apxs2[=FILE]        Build shared Apache module(s). FILE is the optional
371                           pathname to the Apache apxs tool; defaults to "apxs".],
372 [
373     if test "$withval" = "yes"; then
374       for i in /usr/sbin /usr/local/apache/bin ; do
375         if test -f "$i/apxs"; then
376           APXS2="$i/apxs"
377         fi
378       done
379       if test -z "$APXS2"; then
380         APXS2=apxs
381       fi
382     else
383       APXS2="$withval"
384     fi
385 ],
386 [
387     AC_PATH_PROG(APXS2, apxs, no)
388 ])
389
390 AC_MSG_CHECKING([for dynamic Apache-2 module support (w/ or w/o APXS)])
391 if test "$APXS2" = "no"; then
392
393     # --without-apxs2 means you want the modules,
394     #       but want to tell us how to build them
395     AC_MSG_RESULT(yes, but use environment, not apxs)
396     echo
397     echo "Did you set one or more of these?"
398     echo
399     echo "APXS2_CFLAGS APXS2_PREFIX APXS2_INCLUDE APXS2_LIBEXEC APXS2_SYSCONFDIR"
400     echo
401
402     AC_MSG_NOTICE([APXS2_CFLAGS is $APXS2_CFLAGS])
403
404     # try and find the Apache root
405     if test -z "$APXS2_PREFIX"; then
406         if test -d "/usr/local/apache"; then
407             APXS2_PREFIX="/usr/local/apache"
408         else
409             AC_MSG_ERROR([You MUST set APXS2_PREFIX so the right Apache-2 can be located!])
410         fi
411     elif test ! -d "$APXS2_PREFIX"; then
412         AC_MSG_ERROR([APXS2_PREFIX of $APXS2_PREFIX cannot be found])
413     fi
414     AC_MSG_NOTICE([APXS2_PREFIX is $APXS2_PREFIX])
415     
416
417     # other subfolders might be derived from APXS2_PREFIX
418     if test -z "$APXS2_INCLUDE"; then
419         if test -f "$APXS2_PREFIX/include/httpd.h"; then
420             APXS2_INCLUDE="$APXS2_PREFIX/include"
421         else
422             AC_MSG_ERROR([can't find Apache-2 include files beneath $APXS2_PREFIX])
423         fi
424     elif ! test -f "$APXS2_INCLUDE/httpd.h"; then
425         AC_MSG_ERROR([APXS2_INCLUDE of $APXS2_INCLUDE does not contain Apache-2 headers])
426     fi
427     AC_MSG_NOTICE([APXS2_INCLUDE is $APXS2_INCLUDE])
428
429     if test -z "$APXS2_LIBEXEC"; then
430         if test -d "$APXS2_PREFIX/libexec"; then
431             APXS2_LIBEXEC="$APXS2_PREFIX/libexec"
432         elif test -d "$APXS2_PREFIX/modules"; then
433             APXS2_LIBEXEC="$APXS2_PREFIX/modules"
434         else
435             AC_MSG_ERROR([can't find Apache-2 libexec/module directory beneath $APXS2_PREFIX])
436         fi
437     elif ! test -d "$APXS2_LIBEXEC"; then
438         AC_MSG_ERROR([APXS2_LIBEXEC of $APXS2_LIBEXEC does not exist])
439     fi
440     AC_MSG_NOTICE([APXS2_LIBEXEC is $APXS2_LIBEXEC])
441
442     if test -z "$APXS2_SYSCONFDIR"; then
443         if test -d "$APXS2_PREFIX/conf"; then
444             APXS2_SYSCONFDIR="$APXS2_PREFIX/conf"
445         else
446             AC_MSG_ERROR([can't find Apache-2 conf directory beneath $APXS2_PREFIX])
447         fi
448     elif ! test -d "$APXS2_SYSCONFDIR"; then
449         AC_MSG_ERROR([APXS2_SYSCONFDIR of $APXS2_SYSCONFDIR does not exist])
450     fi
451     AC_MSG_NOTICE([APXS2_SYSCONFDIR is $APXS2_SYSCONFDIR])
452
453     WANT_APACHE_20="yes"
454
455 elif test -n "$APXS2"; then
456
457     # extract settings we need from APXS2 -q
458     APXS2_CC="`$APXS2 -q CC`"
459     APXS2_CFLAGS="`$APXS2 -q CFLAGS` `$APXS2 -q CFLAGS_SHLIB`"
460     APXS2_INCLUDE="`$APXS2 -q INCLUDEDIR`"
461     APXS2_LIBEXEC="`$APXS2 -q LIBEXECDIR`"
462     APXS2_SYSCONFDIR="`$APXS2 -q SYSCONFDIR`"
463
464     AC_SUBST(APXS2)
465     AC_MSG_RESULT(found at $APXS2)
466
467     if test -z "`$APXS2 -q LD_SHLIB`" && test -z "`$APXS2 -q LIBEXECDIR`" \
468        || test "$APXS2_LIBEXEC" = "modules"; then
469             AC_MSG_ERROR(
470 [Your APXS installation is broken and cannot be used.
471     Please see http://www.webdav.org/mod_dav/install.html#apxs for
472     more information.])
473     fi
474
475     WANT_APACHE_20="yes"
476
477 else
478     # guess we're not doing Apache 2.0
479     AC_MSG_RESULT(no)
480     WANT_APACHE_20="no"
481 fi
482 fi
483
484 AC_SUBST(APXS2_CFLAGS)
485 AC_SUBST(APXS2_INCLUDE)
486 AC_SUBST(APXS2_LIBEXEC)
487 AC_SUBST(APXS2_SYSCONFDIR)
488 AM_CONDITIONAL(HAVE_APXS2,test -n "$APXS2")
489
490 # always output the Makefile, even if you don't use it
491 AC_CONFIG_FILES([apache/Makefile])
492 AM_CONDITIONAL(BUILD_AP13,test "$WANT_APACHE_13" = "yes")
493 AM_CONDITIONAL(BUILD_AP20,test "$WANT_APACHE_20" = "yes")
494
495 # add the apache module to the list of wanted subdirs..
496 if test "$WANT_APACHE_13" = "yes" || test "$WANT_APACHE_20" = "yes" ; then
497     WANT_SUBDIRS="$WANT_SUBDIRS apache"
498 fi
499
500
501 #
502 # Implement the checks of the MySQL Credential Cache
503 #
504 # 1) Assume the user wants MySQL; if it's not found then just continue without
505 # 2) If the user specifically requested Mysql, look for it and ERROR if not found
506 # 3) If the user specifically requested no-mysql, don't build it.
507 #
508
509 AC_CONFIG_FILES([shib-mysql-ccache/Makefile])
510
511 # determine whether we should enable the mysql ccache
512 AC_ARG_ENABLE([mysql],
513         AC_HELP_STRING([--disable-mysql], [disable the MySQL Credential Cache]),
514         [mysql_enabled=$enableval], [mysql_enabled=default])
515
516 if test "x$mysql_enabled" = "x" ; then
517    mysql_enabled=yes
518 fi
519
520 # Are we trying to build MySQL?
521 AC_MSG_CHECKING(whether to build the MySQL ccache)
522 if test "$mysql_enabled" = "yes" ; then
523    build_mysql=yes
524    AC_MSG_RESULT(yes)
525 elif test "$mysql_enabled" = "default" ; then
526    build_mysql=yes
527    AC_MSG_RESULT([yes, if it can be found])
528 else
529    build_mysql=no
530    AC_MSG_RESULT(no)
531 fi
532
533 # If we're trying to build MySQL, try to find the mysql_config program,
534 # verify we've got mysql >= 4, and make sure we can build with mysqld
535 if test "$build_mysql" = "yes" ; then
536    mysql_dir=""
537    AC_ARG_WITH(mysql,
538         AC_HELP_STRING([--with-mysql=PATH], [directory where mysql is installed]),
539             [if test "$with_mysql" = no ; then
540                AC_MSG_ERROR([Try running --disable-mysql instead.])
541              elif test "$with_mysql" != yes ; then
542                mysql_dir="$with_mysql/bin"
543              fi ])
544
545    # Try to find the mysql_config program
546    AC_PATH_PROG(MYSQL_CONFIG, mysql_config, no, $mysql_dir $PATH )
547
548    if test "$MYSQL_CONFIG" = no ; then
549       if test "$mysql_enabled" = "yes" ; then
550         AC_MSG_ERROR(Cannot find mysql_config)
551       else
552         AC_MSG_WARN(MySQL not found.  skipping.)
553       fi
554    fi
555 fi
556
557 # if we found mysql_config then build_mysql is 'yes'
558 if test "$MYSQL_CONFIG" != no ; then
559    AC_MSG_CHECKING(for mysql version >= 4)
560    mysql_version=`$MYSQL_CONFIG --version`
561    mysql_major_version=`echo $mysql_version | awk -F. '{print $1}'`
562    mysql_version_ok=yes
563    if test $mysql_major_version -lt 4 ; then
564      mysql_version_ok=no
565      if test "$mysql_enabled" = "yes" ; then
566        AC_MSG_ERROR(You need MySQL version >= 4, found $mysql_version)
567      fi
568      AC_MSG_RESULT(no.. skipping MySQL)
569    else
570      AC_MSG_RESULT(yes)
571    fi
572 fi
573
574 # if mysql_version_ok is 'yes', then we've made it this far.. ;)
575 if test "$mysql_version_ok" = "yes" ; then
576    AC_MSG_CHECKING(for embedded-MySQL libraries)
577    MYSQL_LIBS=`$MYSQL_CONFIG --libmysqld-libs`
578    if test $? != 0 ; then
579       found_mysql=no
580       if test "$mysql_enabled" = "yes" ; then
581         AC_MSG_ERROR(Could not find the MySQL Embedded-server libraries.)
582       else
583         AC_MSG_RESULT(no.. skipping MySQL)
584       fi
585    else
586       found_mysql=yes
587       AC_MSG_RESULT(yes)
588    fi
589 fi
590
591 # if found_mysql=yes then test that we can actually build mysql
592 if test "$found_mysql" = yes ; then
593    MYSQL_CFLAGS=`$MYSQL_CONFIG --cflags`
594    MYSQL_CFLAGS=`eval echo $MYSQL_CFLAGS`
595    MYSQL_LIBS=`eval echo $MYSQL_LIBS`
596
597    save_CPPFLAGS="$CPPFLAGS"
598    CPPFLAGS="$CPPFLAGS $MYSQL_CFLAGS"
599
600    AC_CHECK_HEADER([mysql.h], [have_mysql_h=yes], [have_mysql_h=no])
601    if test "$have_mysql_h" = no -a "$mysql_enabled" = "yes" ; then
602      AC_MSG_ERROR(unable to find MySQL header files)
603    fi
604
605    if test "$have_mysql_h" = yes ; then
606       save_LIBS="$LIBS"
607       LIBS="$LIBS $MYSQL_LIBS"
608       AC_MSG_CHECKING(if we can link againt mysql)
609       AC_TRY_LINK(
610         [#include <mysql.h>
611          #include <stdio.h>],
612         [mysql_server_init(0, NULL, NULL)],
613         [have_mysql_libs=yes],
614         [have_mysql_libs=no])
615       LIBS="$save_LIBS"
616
617       if test "$have_mysql_libs" = no ; then
618          if test "$mysql_enabled" = "yes" ; then
619             AC_MSG_ERROR([unable to link with MySQL Embedded Server Library])
620          else
621             AC_MSG_RESULT(no.  skipping MySQL)
622          fi
623       fi
624    fi
625
626    CPPFLAGS="$save_CPPFLAGS"
627 fi
628
629 # if have_mysql_libs=yes then go ahead with building MySQL
630 if test "$have_mysql_libs" = yes ; then
631    # this AC_MSG_RESULT is from above!
632    AC_MSG_RESULT(yes)
633    WANT_SUBDIRS="$WANT_SUBDIRS shib-mysql-ccache"
634    AC_SUBST(MYSQL_CFLAGS)
635    AC_SUBST(MYSQL_LIBS)
636 fi
637
638
639 AC_SUBST(WANT_SUBDIRS)
640
641 if test -n "$APXS_CC" && test "$APXS_CC" != "$CC" ; then
642   echo "=================================================================="
643   echo "WARNING: You have chosen to compile Apache-1.3 modules with a different"
644   echo "         compiler than the one used to compile Apache."
645   echo ""
646   echo "    Current compiler:      $CC"
647   echo "   Apache's compiler:      $APXS_CC"
648   echo ""
649   echo "This could cause some problems."
650   echo "=================================================================="
651 fi
652
653 if test -n "$APXS2_CC" && test "$APXS2_CC" != "$CC" ; then
654   echo "=================================================================="
655   echo "WARNING: You have chosen to compile Apache-2 modules with a different"
656   echo "         compiler than the one used to compile Apache."
657   echo ""
658   echo "    Current compiler:      $CC"
659   echo "   Apache's compiler:      $APXS2_CC"
660   echo ""
661   echo "This could cause some problems."
662   echo "=================================================================="
663 fi
664
665 AC_OUTPUT
666