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