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