Get the --enable-mysql configure argument to work properly
[shibboleth/sp.git] / configure.ac
1 AC_PREREQ([2.50])
2 AC_INIT([shibboleth], [1.0], [mace-shib-users@internet2.edu], [shibboleth])
3 AM_CONFIG_HEADER(config.h)
4 AM_INIT_AUTOMAKE(shibboleth, 1.0)
5
6 sinclude(acx_pthread.m4)
7 sinclude(acx_rpctest.m4)
8
9 AC_PROG_CC([gcc3 gcc cc])
10 AC_PROG_CXX([g++3 g++ c++ CC])
11 AC_DISABLE_STATIC
12 AC_PROG_LIBTOOL
13
14 AC_LANG(C++)
15
16 # Checks for typedefs, structures, and compiler characteristics.
17 AC_C_CONST
18 AC_TYPE_SIZE_T
19 AC_STRUCT_TM
20
21 # Checks for library functions.
22 AC_FUNC_STRFTIME
23 AC_CHECK_FUNCS([strchr strdup strstr gmtime_r strcasecmp])
24 AC_CHECK_HEADERS([dlfcn.h])
25
26 # C++ requirements
27 AC_CXX_REQUIRE_STL
28 AC_CXX_NAMESPACES
29
30
31 # old_LIBS="$LIBS"
32 # AC_SEARCH_LIBS(xdr_uint64_t,nsl,,
33 #       [CFLAGS="$CFLAGS -DNEED_XDR_LONGLONG"
34 #        CXXFLAGS="$CXXFLAGS -DNEED_XDR_LONGLONG"])
35 # LIBS="$old_LIBS"
36
37 # checks for pthreads
38 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
39 if test $enable_threads != "pthread"; then
40     AC_MSG_ERROR([unable to find pthreads, currently this is required])
41 else
42     AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
43     LIBS="$PTHREAD_LIBS $LIBS"
44     CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
45     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
46 fi
47
48 # Test RPC now -- deal with it later
49 ACX_RPCTEST([rpctest="yes"],[rpctest="no"])
50
51 AC_ARG_WITH(dmalloc,
52             AC_HELP_STRING([--with-dmalloc=PATH], [where dmalloc is installed]),
53             [if test x_$with_dmalloc != x_/usr; then
54                 LDFLAGS="-L${with_dmalloc}/lib $LDFLAGS"
55                 CPPFLAGS="-I${with_dmalloc}/include $CPPFLAGS"
56             fi
57             AC_CHECK_LIB(dmallocxx, dmalloc_shutdown,,
58                          AC_MSG_ERROR([unable to find dmallocxx library]))
59             ])
60
61 AC_ARG_WITH(xerces, 
62             AC_HELP_STRING([--with-xerces=PATH], [where xerces-c is installed]),
63             [if test x_$with_xerces != x_/usr; then
64                 LDFLAGS="-L${with_xerces}/lib $LDFLAGS"
65                 CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
66             fi])
67
68
69 AC_ARG_WITH(openssl, 
70             AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
71             [if test x_$with_openssl != x_/usr; then
72                 LDFLAGS="-L${with_openssl}/lib $LDFLAGS"
73                 CPPFLAGS="-I${with_openssl}/include $CPPFLAGS"
74             fi])
75
76 AC_ARG_WITH(log4cpp, 
77             AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp is installed]),
78             [if test x_$with_log4cpp != x_/usr; then
79                 LDFLAGS="-L${with_log4cpp}/lib $LDFLAGS"
80                 CPPFLAGS="-I${with_log4cpp}/include $CPPFLAGS"
81             fi])
82
83 AC_ARG_WITH(xmlsec,
84             AC_HELP_STRING([--with-xmlsec=PATH], [where xmlsec is installed]),
85             [if test x_$with_xmlsec != x_/usr; then
86                 LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
87                 CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
88             fi])
89
90 AC_ARG_WITH(saml,
91             AC_HELP_STRING([--with-saml=PATH], [where saml is installed]),
92             [if test x_$with_saml != x_/usr; then
93                 LDFLAGS="-L${with_saml}/lib $LDFLAGS"
94                 CPPFLAGS="-I${with_saml}/include $CPPFLAGS"
95             fi])
96
97 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,
98                 AC_MSG_ERROR([unable to find xerces header files]))
99 saved_LIBS="$LIBS"
100 LIBS="-lxerces-c $LIBS"
101 AC_TRY_LINK(
102         [#include <xercesc/util/PlatformUtils.hpp>],
103         [xercesc::XMLPlatformUtils::Initialize()],
104         [AC_DEFINE(HAVE_LIBXERCESC,1,[Define if Xerces-C library was found])],
105         [AC_MSG_ERROR([unable to link with Xerces])
106                 LIBS="$saved_LIBS"
107         ])
108
109 AC_CHECK_HEADER([openssl/ssl.h],,
110                 AC_MSG_ERROR([unable to find openssl header files]))
111 AC_CHECK_LIB([crypto], [ERR_load_CRYPTO_strings],,
112              AC_MSG_ERROR([unable to link with openssl libraries]))
113 AC_CHECK_LIB([ssl], [SSL_library_init],, 
114              AC_MSG_ERROR([unable to link with openssl libraries]))
115
116 AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,
117                 AC_MSG_ERROR([unable to find xsec header files]))
118 saved_LIBS="$LIBS"
119 LIBS="-lxml-security-c $LIBS"
120 AC_TRY_LINK(
121         [#include <xsec/utils/XSECPlatformUtils.hpp>],
122         [XSECPlatformUtils::Initialise()],
123         [AC_DEFINE(HAVE_LIBXSEC,1,[Define if XML-Sec library was found])],
124         [AC_MSG_ERROR([unable to link with XML-Sec])
125                 LIBS="$saved_LIBS"
126         ])
127
128 AC_CHECK_HEADER([log4cpp/Category.hh],,
129                 AC_MSG_ERROR([unable to find log4cpp header files]))
130
131 AC_CHECK_HEADER([saml/saml.h],,
132                 AC_MSG_ERROR([unable to find saml header files]))
133
134 saved_LIBS="$LIBS"
135 LIBS="-llog4cpp $LIBS"
136 AC_TRY_LINK(
137         [#include <log4cpp/Category.hh>],
138         [log4cpp::Category::getInstance("foo")],
139         [AC_DEFINE(HAVE_LIBLOG4CPP,1,[Define if log4cpp library was found])],
140         [AC_MSG_ERROR([unable to link with log4cpp])
141                 LIBS="$saved_LIBS"
142         ])
143
144 saved_LIBS="$LIBS"
145 LIBS="-lsaml $LIBS"
146 AC_TRY_LINK(
147         [#include <saml/saml.h>],
148         [saml::SAMLConfig::getConfig()],
149         [AC_DEFINE(HAVE_SAML,1,[Define if saml library was found])],
150         [AC_MSG_ERROR([unable to link with saml])
151                 LIBS="$saved_LIBS"
152         ])
153
154 # output the underlying makefiles
155 WANT_SUBDIRS="doc shib schemas configs shib-target shar siterefresh test"
156 AC_CONFIG_FILES([Makefile doc/Makefile shib/Makefile schemas/Makefile \
157                  configs/Makefile oncrpc/Makefile oncrpc/rpc/Makefile \
158                  shib-target/Makefile shar/Makefile siterefresh/Makefile \
159                  test/Makefile])
160
161 # now deal with the rpc library, to see if we need to build our own
162 if test $rpctest = "no"; then
163     WANT_SUBDIRS="oncrpc $WANT_SUBDIRS"
164 fi
165 AM_CONDITIONAL(USE_OUR_ONCRPC,test "$rpctest" = "no")
166
167 # Much of this is taken from mod_dav.
168 # The basic idea is to use configure options to control whether/which types
169 # of web server modules get built. We assume there may eventually be multiple
170 # types (Apache 1/2, iPlanet, others).
171
172 # Apache 1.3 (mod_shire/mod_shibrm)
173 #   --with-apache   (static build, no idea how to do this yet, so not supported)
174 #   --with-apxs     (DSO build, the normal way, uses apxs to derive build flags)
175 #   --without-apxs  (DSO build, you tell us how to build using the environment)
176
177 AC_ARG_ENABLE(apache-13,
178         AC_HELP_STRING([--disable-apache-13], [disable the Apache 1.3 modules]))
179 if test "x$enable_apache_13" = "x" ; then
180    enable_apache_13=yes
181 fi
182
183 if test "$enable_apache_13" != yes ; then
184    AC_MSG_WARN(Building without Apache...)
185    WANT_APACHE=no
186 else
187
188 AC_MSG_CHECKING([for dynamic Apache module support (w/ or w/o APXS)])
189 AC_ARG_WITH(apxs,
190 [  --with-apxs[=FILE]        Build shared Apache module(s). FILE is the optional
191                           pathname to the Apache apxs tool; defaults to "apxs".],
192 [
193     if test "$withval" = "yes"; then
194       for i in /usr/sbin /usr/local/apache/bin ; do
195         if test -f "$i/apxs"; then
196           APXS="$i/apxs"
197         fi
198       done
199       if test -z "$APXS"; then
200         APXS=apxs
201       fi
202     else
203       APXS="$withval"
204     fi
205 ])
206
207 if test "$APXS" = "no"; then
208
209     # --without-apxs means you want the modules,
210     #       but want to tell us how to build them
211     AC_MSG_RESULT(yes, but use environment, not apxs)
212     echo
213     echo "Did you set one or more of these?"
214     echo
215     echo "APXS_CFLAGS APXS_PREFIX APXS_INCLUDE APXS_LIBEXEC APXS_SYSCONFDIR"
216     echo
217
218     AC_MSG_NOTICE([APXS_CFLAGS is $APXS_CFLAGS])
219
220     # try and find the Apache root
221     if test -z "$APXS_PREFIX"; then
222         if test -d "/usr/local/apache"; then
223             APXS_PREFIX="/usr/local/apache"
224         else
225             AC_MSG_ERROR([You MUST set APXS_PREFIX so the right Apache can be located!])
226         fi
227     elif test ! -d "$APXS_PREFIX"; then
228         AC_MSG_ERROR([APXS_PREFIX of $APXS_PREFIX cannot be found])
229     fi
230     AC_MSG_NOTICE([APXS_PREFIX is $APXS_PREFIX])
231     
232
233     # other subfolders might be derived from APXS_PREFIX
234     if test -z "$APXS_INCLUDE"; then
235         if test -f "$APXS_PREFIX/include/httpd.h"; then
236             APXS_INCLUDE="$APXS_PREFIX/include"
237         else
238             AC_MSG_ERROR([can't find Apache include files beneath $APXS_PREFIX])
239         fi
240     elif ! test -f "$APXS_INCLUDE/httpd.h"; then
241         AC_MSG_ERROR([APXS_INCLUDE of $APXS_INCLUDE does not contain Apache headers])
242     fi
243     AC_MSG_NOTICE([APXS_INCLUDE is $APXS_INCLUDE])
244
245     if test -z "$APXS_LIBEXEC"; then
246         if test -d "$APXS_PREFIX/libexec"; then
247             APXS_LIBEXEC="$APXS_PREFIX/libexec"
248         elif test -d "$APXS_PREFIX/modules"; then
249             APXS_LIBEXEC="$APXS_PREFIX/modules"
250         else
251             AC_MSG_ERROR([can't find Apache libexec/module directory beneath $APXS_PREFIX])
252         fi
253     elif ! test -d "$APXS_LIBEXEC"; then
254         AC_MSG_ERROR([APXS_LIBEXEC of $APXS_LIBEXEC does not exist])
255     fi
256     AC_MSG_NOTICE([APXS_LIBEXEC is $APXS_LIBEXEC])
257
258     if test -z "$APXS_SYSCONFDIR"; then
259         if test -d "$APXS_PREFIX/conf"; then
260             APXS_SYSCONFDIR="$APXS_PREFIX/conf"
261         else
262             AC_MSG_ERROR([can't find Apache conf directory beneath $APXS_PREFIX])
263         fi
264     elif ! test -d "$APXS_SYSCONFDIR"; then
265         AC_MSG_ERROR([APXS_SYSCONFDIR of $APXS_SYSCONFDIR does not exist])
266     fi
267     AC_MSG_NOTICE([APXS_SYSCONFDIR is $APXS_SYSCONFDIR])
268
269     WANT_APACHE="yes"
270
271 elif test -n "$APXS"; then
272
273     # extract settings we need from APXS -q
274     APXS_CC="`$APXS -q CC`"
275     APXS_CFLAGS="`$APXS -q CFLAGS` `$APXS -q CFLAGS_SHLIB`"
276     APXS_INCLUDE="`$APXS -q INCLUDEDIR`"
277     APXS_LIBEXEC="`$APXS -q LIBEXECDIR`"
278     APXS_SYSCONFDIR="`$APXS -q SYSCONFDIR`"
279
280     AC_SUBST(APXS)
281     AC_MSG_RESULT(found at $APXS)
282
283     if test -z "`$APXS -q LD_SHLIB`" || test "$APXS_LIBEXEC" = "modules"; then
284             AC_MSG_ERROR(
285 [Your APXS installation is broken and cannot be used.
286     Please see http://www.webdav.org/mod_dav/install.html#apxs for
287     more information.])
288     fi
289
290     WANT_APACHE="yes"
291
292 else
293     # guess we're not doing Apache 1.3
294     AC_MSG_RESULT(no)
295     WANT_APACHE="no"
296 fi
297
298 fi
299
300 AM_CONDITIONAL(HAVE_APXS,test -n "$APXS")
301
302 if test "$WANT_APACHE" = "yes"; then
303     AC_ARG_WITH(apreq,
304                 AC_HELP_STRING([--with-apreq=PATH], [where libapreq is installed]),
305                 [if test x_$with_apreq != x_/usr; then
306                     LDFLAGS="-L${with_apreq}/lib $LDFLAGS"
307                     CPPFLAGS="-I${with_apreq}/include $CPPFLAGS"
308                 fi])
309
310     saved_CPPFLAGS="$CPPFLAGS"
311     CPPFLAGS="-I$APXS_INCLUDE $APXS_CFLAGS $CPPFLAGS"
312     AC_TRY_COMPILE([#include <libapreq/apache_request.h>],
313                    [int i=0],
314                    test_apreq="yes",test_apreq="no")
315     if test "$test_apreq" = "no"; then
316         CPPFLAGS="$CPPFLAGS -U_XOPEN_SOURCE"
317         APXS_CFLAGS="$APXS_CFLAGS -U_XOPEN_SOURCE"
318         AC_CHECK_HEADER([libapreq/apache_request.h],,
319             AC_MSG_ERROR([unable to find a usable libapreq header]))
320     fi
321
322 dnl    saved_LIBS="$LIBS"
323 dnl    LIBS="-lapreq $LIBS"
324 dnl    AC_TRY_LINK(
325 dnl        [#include <libapreq/apache_request.h>],
326 dnl        [ApacheRequest_expires],
327 dnl        [AC_DEFINE(HAVE_APREQ,1,[Define if apreq library was found])],
328 dnl        [AC_MSG_ERROR([unable to link with apreq])
329 dnl        ])
330 dnl    LIBS="$saved_LIBS"
331     CPPFLAGS="$saved_CPPFLAGS"
332
333     AC_ARG_ENABLE([apxs-install],
334         AC_HELP_STRING([--enable-apxs-install],
335                         [use apxs to install the apache modules]),
336         APXS_INSTALL="yes", )
337
338
339     AC_SUBST(APXS_CFLAGS)
340     AC_SUBST(APXS_INCLUDE)
341     AC_SUBST(APXS_LIBEXEC)
342     AC_SUBST(APXS_SYSCONFDIR)
343
344     # output the Apache 1.3 makefiles
345     WANT_SUBDIRS="$WANT_SUBDIRS mod_shire mod_shibrm"
346 fi
347 # always output the Makefile, even if we don't use it
348 AC_CONFIG_FILES([mod_shire/Makefile mod_shibrm/Makefile])
349
350 AM_CONDITIONAL(DO_APXS_INSTALL,test -n "$APXS_INSTALL")
351
352 #
353 # Implement the checks of the MySQL Credential Cache
354 #
355 # 1) Assume the user wants MySQL; if it's not found then just continue without
356 # 2) If the user specifically requested Mysql, look for it and ERROR if not found
357 # 3) If the user specifically requested no-mysql, don't build it.
358 #
359
360 AC_CONFIG_FILES([shib-mysql-ccache/Makefile])
361
362 # determine whether we should enable the mysql ccache
363 AC_ARG_ENABLE([mysql],
364         AC_HELP_STRING([--disable-mysql], [disable the MySQL Credential Cache]),
365         [mysql_enabled=$enableval], [mysql_enabled=default])
366
367 if test "x$mysql_enabled" = "x" ; then
368    mysql_enabled=yes
369 fi
370
371 # Are we trying to build MySQL?
372 AC_MSG_CHECKING(whether to build the MySQL ccache)
373 if test "$mysql_enabled" = "yes" ; then
374    build_mysql=yes
375    AC_MSG_RESULT(yes)
376 elif test "$mysql_enabled" = "default" ; then
377    build_mysql=yes
378    AC_MSG_RESULT([yes, if it can be found])
379 else
380    build_mysql=no
381    AC_MSG_RESULT(no)
382 fi
383
384 # If we're trying to build MySQL, try to find the mysql_config program,
385 # verify we've got mysql >= 4, and make sure we can build with mysqld
386 if test "$build_mysql" = "yes" ; then
387    mysql_dir=""
388    AC_ARG_WITH(mysql,
389         AC_HELP_STRING([--with-mysql=PATH], [directory where mysql is installed]),
390             [if test "$with_mysql" = no ; then
391                AC_MSG_ERROR([Try running --disable-mysql instead.])
392              elif test "$with_mysql" != yes ; then
393                mysql_dir="$with_mysql/bin"
394              fi ])
395
396    # Try to find the mysql_config program
397    AC_PATH_PROG(MYSQL_CONFIG, mysql_config, no, $mysql_dir $PATH )
398
399    if test "$MYSQL_CONFIG" = no ; then
400       if test "$mysql_enabled" = "yes" ; then
401         AC_MSG_ERROR(Cannot find mysql_config)
402       else
403         AC_MSG_WARN(MySQL not found.  skipping.)
404       fi
405    fi
406 fi
407
408 # if we found mysql_config then build_mysql is 'yes'
409 if test "$MYSQL_CONFIG" != no ; then
410    AC_MSG_CHECKING(for mysql version >= 4)
411    mysql_version=`$MYSQL_CONFIG --version`
412    mysql_major_version=`echo $mysql_version | awk -F. '{print $1}'`
413    mysql_version_ok=yes
414    if test $mysql_major_version -lt 4 ; then
415      mysql_version_ok=no
416      if test "$mysql_enabled" = "yes" ; then
417        AC_MSG_ERROR(You need MySQL version >= 4, found $mysql_version)
418      fi
419      AC_MSG_RESULT(no.. skipping MySQL)
420    else
421      AC_MSG_RESULT(yes)
422    fi
423 fi
424
425 # if mysql_version_ok is 'yes', then we've made it this far.. ;)
426 if test "$mysql_version_ok" = "yes" ; then
427    AC_MSG_CHECKING(for embedded-MySQL libraries)
428    MYSQL_LIBS=`$MYSQL_CONFIG --libmysqld-libs`
429    if test $? != 0 ; then
430       found_mysql=no
431       if test "$mysql_enabled" = "yes" ; then
432         AC_MSG_ERROR(Could not find the MySQL Embedded-server libraries.)
433       else
434         AC_MSG_RESULT(no.. skipping MySQL)
435       fi
436    else
437       found_mysql=yes
438       AC_MSG_RESULT(yes)
439    fi
440 fi
441
442 # if found_mysql=yes then test that we can actually build mysql
443 if test "$found_mysql" = yes ; then
444    MYSQL_CFLAGS=`$MYSQL_CONFIG --cflags`
445    MYSQL_CFLAGS=`eval echo $MYSQL_CFLAGS`
446    MYSQL_LIBS=`eval echo $MYSQL_LIBS`
447
448    save_CPPFLAGS="$CPPFLAGS"
449    CPPFLAGS="$CPPFLAGS $MYSQL_CFLAGS"
450
451    AC_CHECK_HEADER([mysql.h], [have_mysql_h=yes], [have_mysql_h=no])
452    if test "$have_mysql_h" = no -a "$mysql_enabled" = "yes" ; then
453      AC_MSG_ERROR(unable to find MySQL header files)
454    fi
455
456    if test "$have_mysql_h" = yes ; then
457       save_LIBS="$LIBS"
458       LIBS="$LIBS $MYSQL_LIBS"
459       AC_MSG_CHECKING(if we can link againt mysql)
460       AC_TRY_LINK(
461         [#include <mysql.h>],
462         [mysql_server_init(0, NULL, NULL)],
463         [have_mysql_libs=yes],
464         [have_mysql_libs=no])
465       LIBS="$save_LIBS"
466
467       if test "$have_mysql_libs" = no ; then
468          if "$mysql_enabled" = "yes" ; then
469             AC_MSG_ERROR([unable to link with MySQL Embedded Server Library])
470          else
471             AC_MSG_RESULT(no.  skipping MySQL)
472          fi
473       fi
474    fi
475
476    CPPFLAGS="$save_CPPFLAGS"
477 fi
478
479 # if have_mysql_libs=yes then go ahead with building MySQL
480 if test "$have_mysql_libs" = yes ; then
481    # this AC_MSG_RESULT is from above!
482    AC_MSG_RESULT(yes)
483    WANT_SUBDIRS="$WANT_SUBDIRS shib-mysql-ccache"
484    AC_SUBST(MYSQL_CFLAGS)
485    AC_SUBST(MYSQL_LIBS)
486 fi
487
488
489 AC_SUBST(WANT_SUBDIRS)
490
491 if test -n "$APXS_CC" && test "$APXS_CC" != "$CC" ; then
492   echo "=================================================================="
493   echo "WARNING: You have chosen to compile Apache modules with a different"
494   echo "         compiler than the one used to compile Apache."
495   echo ""
496   echo "    Current compiler:      $CC"
497   echo "   Apache's compiler:      $APXS_CC"
498   echo ""
499   echo "This could cause some problems."
500   echo "=================================================================="
501 fi
502
503 AC_OUTPUT
504