Better r.e. to prevent from substituing empty strings on some platforms
[mod_auth_kerb.cvs/.git] / configure.in
1 # Process this file with autoconf to produce a configure script.
2 AC_REVISION($Revision$)
3 AC_PREREQ(2.57)
4 AC_INIT(mod_auth_kerb, 5.4, modauthkerb-developers@lists.sourceforge.net)
5 AC_CONFIG_SRCDIR([src/mod_auth_kerb.c])
6 AC_CONFIG_HEADER([config.h])
7
8 # Checks for programs.
9 AC_PROG_CC
10 AC_PROG_MAKE_SET
11
12 # Checks for libraries.
13 # FIXME: Replace `main' with a function in `-lresolv':
14 LIB_resolv=""
15 AC_CHECK_LIB([resolv], [main], [LIB_resolv=-lresolv])
16 AC_SUBST(LIB_resolv)
17
18 # Checks for header files.
19 AC_HEADER_STDC
20 AC_CHECK_HEADERS([limits.h netdb.h stddef.h stdlib.h string.h unistd.h])
21
22 # Checks for typedefs, structures, and compiler characteristics.
23 #AC_C_CONST
24 AC_TYPE_SIZE_T
25 AC_STRUCT_TM
26
27 # Checks for library functions.
28 #AC_FUNC_MALLOC
29 #AC_FUNC_MEMCMP
30 #AC_CHECK_FUNCS([gethostbyname memset putenv strcasecmp strchr strdup strerror])
31
32 #
33 # kerberos5 enviroment
34 #
35 SPNEGO_SRCS=""
36
37 AC_ARG_WITH(krb5,
38   AC_HELP_STRING([--with-krb5=dir],[use krb5 in dir]),
39   [ with_krb5="$withval" ])
40
41 if test "x$with_krb5" = "xyes" ; then
42   with_krb5=""
43 fi
44
45 if test "x$with_krb5" != "xno" ; then
46
47   AC_PATH_PROG(krb5_config_command,krb5-config,:,[$PATH:/usr/kerberos/bin:/usr/krb5/bin])
48   if test $krb5_config_command = : ; then
49      AC_MSG_ERROR(krb5-config not found)
50   fi
51
52   ac_save_CPPFLAGS="$CPPFLAGS"
53   ac_save_LDFLAGS="$LDFLAGS"
54   ac_save_LIBS="$LIBS"
55    
56   if test -n "$with_krb5"; then
57      if test -x "$with_krb5/bin/krb5-config"; then
58         krb5_config_command="$with_krb5/bin/krb5-config"
59      else
60         krb5_config_command=""
61      fi
62   fi
63
64   dnl
65   dnl find header files
66   dnl
67
68   if test -z "$KRB5_CPPFLAGS"; then
69      TMP_KRB5_CPPFLAGS=""
70      if test -n "$krb5_config_command"; then
71         TMP_KRB5_CPPFLAGS=`$krb5_config_command --cflags gssapi 2>/dev/null`
72      fi
73      if test -z "$TMP_KRB5_CPPFLAGS" -a -n "with_krb5"; then
74         TMP_KRB5_CPPFLAGS="-I$with_krb5/include"
75      fi
76      CPPFLAGS="$CPPFLAGS $TMP_KRB5_CPPFLAGS"
77      AC_CHECK_HEADERS(gssapi.h, 
78                       [ KRB5_CPPFLAGS="$TMP_KRB5_CPPFLAGS" ])
79      if test -z "$KRB5_CPPFLAGS"; then
80         AC_CHECK_HEADERS(gssapi/gssapi.h, 
81                          [ KRB5_CPPFLAGS="$TMP_KRB5_CPPFLAGS" ])
82      fi
83      CPPFLAGS="$ac_save_CPPFLAGS" 
84   fi
85
86   dnl
87   dnl find libraries
88   dnl
89
90   if test -z "$KRB5_LDFLAGS" -a -n "$krb5_config_command"; then
91      TMP_KRB5_LDFLAGS=`$krb5_config_command --libs gssapi 2>/dev/null`
92      if test -n "$TMP_KRB5_LDFLAGS"; then
93         LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
94         AC_CHECK_LIB(krb5, krb5_init_context,
95                      [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
96         LIBS="$ac_save_LIBS"
97      fi
98   fi
99   if test "x$with_krb5"="x"; then
100         tmp_lf_inc=""
101      else
102         tmp_lf_inc="-L"
103   fi
104   if test -z "$KRB5_LDFLAGS"; then
105      #try MIT
106      TMP_KRB5_LDFLAGS="$tmp_lf_inc$with_krb5/lib -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err"
107      LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
108      AC_CHECK_LIB(krb5, krb5_init_context, [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
109      LIBS="$ac_save_LIBS"
110   fi
111
112   if test -z "$KRB5_LDFLAGS"; then
113      #Try Heimdal
114      TMP_KRB5_LDFLAGS="$tmp_lf_inc$with_krb5/lib -lgssapi -lkrb5 -lasn1 -lcrypto -lroken -lcrypt"
115      LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
116      AC_CHECK_LIB(krb5, krb5_init_context, [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
117      LIBS="$ac_save_LIBS"
118   fi
119
120   if test -z "$KRB5_LDFLAGS"; then
121      #Try Heimdal on OpenBSD
122      TMP_KRB5_LDFLAGS="$tmp_lf_inc$with_krb5/lib -lgssapi -lkrb5 -lasn1 -ldes -lcrypto"
123      LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
124      AC_CHECK_LIB(krb5, krb5_init_context, [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
125      LIBS="$ac_save_LIBS"
126   fi
127
128   if test -z "$KRB5_LDFLAGS"; then
129      with_krb5=no
130   else
131      AC_DEFINE(KRB5)
132      AC_CHECK_LIB(krb5,
133                   krb5_cc_new_unique,
134                   [ AC_DEFINE(HAVE_KRB5_CC_NEW_UNIQUE) ])
135
136      # check for Heimdal
137      have_heimdal=""
138      AC_MSG_CHECKING(whether we are using Heimdal)
139      ac_save_CFLAGS="$CFLAGS"
140      CFLAGS="$KRB5_CPPFLAGS"
141      AC_TRY_COMPILE([#include <krb5.h>],
142                     [ char *tmp = heimdal_version; ],
143                     [ AC_MSG_RESULT(yes)
144                       AC_DEFINE(HEIMDAL)
145                       have_heimdal=yes ],
146                     [ AC_MSG_RESULT(no) ])
147      CFLAGS="$ac_save_CFLAGS"
148
149 # If SPNEGO is supported by the gssapi libraries, we shouln't build our support.
150 # SPNEGO is supported as of Heimdal 0.7, and MIT 1.5.
151      gssapi_supports_spnego=""
152      AC_MSG_CHECKING(whether the GSSAPI libraries support SPNEGO)
153
154      ac_save_CFLAGS="$CFLAGS"
155      CFLAGS="$KRB5_CPPFLAGS"
156      ac_save_LDFLAGS="$LDFLAGS"
157      if test -n "$with_krb5"; then
158         LDFLAGS="$KRB5_LDFLAGS -Wl,-rpath -Wl,$with_krb5/lib"
159      else 
160         LDFLAGS="$KRB5_LDFLAGS"
161      fi
162      AC_TRY_RUN([
163 #include <string.h>
164 #include <krb5.h>
165 #ifdef HEIMDAL
166 #include <gssapi.h>
167 #else
168 #include <gssapi/gssapi.h>
169 #endif
170 int main(int argc, char** argv)
171 {
172        OM_uint32 major_status, minor_status;
173        gss_OID_set mech_set;
174        gss_OID_desc spnego_oid_desc = {6, (void *)"\x2b\x06\x01\x05\x05\x02"};
175        int SPNEGO = 0;
176                                                                                
177        major_status = gss_indicate_mechs(&minor_status, &mech_set);
178        if (GSS_ERROR(major_status))
179                return 1;
180        else {
181                unsigned int i;
182                for (i=0; i < mech_set->count && !SPNEGO; i++) {
183                        gss_OID tmp_oid = &mech_set->elements[i];
184                       if (tmp_oid->length == spnego_oid_desc.length &&
185                            !memcmp(tmp_oid->elements, spnego_oid_desc.elements, 
186                                    tmp_oid->length)) {
187                                SPNEGO = 1;
188                                break;
189                        }
190                }
191                gss_release_oid_set(&minor_status, &mech_set);
192                return (!SPNEGO);
193        }
194 }],
195                 [ if test $? -eq 0; then 
196                      AC_MSG_RESULT(yes)
197                      AC_DEFINE(GSSAPI_SUPPORTS_SPNEGO)
198                      gssapi_supports_spnego=yes 
199                   else
200                      AC_MSG_RESULT(no)
201                   fi],
202                 [AC_MSG_RESULT(no)])
203
204      CFLAGS="$ac_save_CFLAGS"
205      LDFLAGS="$ac_save_LDFLAGS"
206
207      if test -z "$gssapi_supports_spnego"; then
208         if test -n "$have_heimdal"; then SPNEGO_SRCS="\
209                 spnegokrb5/asn1_MechType.c         \
210                 spnegokrb5/asn1_MechTypeList.c     \
211                 spnegokrb5/asn1_ContextFlags.c     \
212                 spnegokrb5/asn1_NegTokenInit.c     \
213                 spnegokrb5/asn1_NegTokenTarg.c     \
214                 spnegokrb5/init_sec_context.c      \
215                 spnegokrb5/accept_sec_context.c    \
216                 spnegokrb5/encapsulate.c           \
217                 spnegokrb5/decapsulate.c           \
218                 spnegokrb5/external.c"
219         else SPNEGO_SRCS="\
220                 spnegokrb5/asn1_MechType.c         \
221                 spnegokrb5/asn1_MechTypeList.c     \
222                 spnegokrb5/asn1_ContextFlags.c     \
223                 spnegokrb5/asn1_NegTokenInit.c     \
224                 spnegokrb5/asn1_NegTokenTarg.c     \
225                 spnegokrb5/der_get.c               \
226                 spnegokrb5/der_put.c               \
227                 spnegokrb5/der_free.c              \
228                 spnegokrb5/der_length.c            \
229                 spnegokrb5/der_copy.c              \
230                 spnegokrb5/timegm.c                \
231                 spnegokrb5/init_sec_context.c      \
232                 spnegokrb5/accept_sec_context.c    \
233                 spnegokrb5/encapsulate.c           \
234                 spnegokrb5/decapsulate.c           \
235                 spnegokrb5/external.c"
236         fi
237      fi
238   fi
239 fi
240 AC_SUBST(KRB5_CPPFLAGS)
241 AC_SUBST(KRB5_LDFLAGS)
242 AC_SUBST(SPNEGO_SRCS)
243
244 #
245 # Kerberos4 enviroment
246 #
247
248 AC_ARG_WITH(krb4,
249   AC_HELP_STRING([--with-krb4=dir], [use krb4 in dir]),
250   [ with_krb4="$withval" ])
251
252 if test "x$with_krb4" = "xyes" ; then
253   with_krb4=""
254 fi
255
256 if test "x$with_krb4" != "xno"; then
257   AC_MSG_CHECKING([for Kerberos4 installation])
258   if test "x$with_krb4" != "x"; then
259      if test -x "$with_krb4/bin/krb4-config"; then
260         KRB4_CPPFLAGS=`$with_krb4/bin/krb4-config --cflags krb4 2>/dev/null`
261         KRB4_LDFLAGS=`$with_krb4/bin/krb4-config --libs krb4 2>/dev/null`
262      elif test -x "$with_krb4/bin/krb5-config"; then
263         KRB4_CPPFLAGS=`$with_krb4/bin/krb5-config --cflags krb4 2>/dev/null`
264         KRB4_LDFLAGS=`$with_krb4/bin/krb5-config --libs krb4 2>/dev/null`
265      else
266         AC_MSG_ERROR([failed to find krb4-config or krb5-config in $with_krb4/bin])
267      fi
268   else
269      KRB4_CPPFLAGS=`krb4-config --cflags krb4 2>/dev/null`
270      KRB4_LDFLAGS=`krb4-config --libs krb4 2>/dev/null`
271      if test "x$KRB4_LDFLAGS" = "x" -a -n "$krb5_config_command"; then
272         KRB4_CPPFLAGS=`$krb5_config_command --cflags krb4 2>/dev/null`
273         KRB4_LDFLAGS=`$krb5_config_command --libs krb4 2>/dev/null`
274         if test $? -ne 0; then
275            KRB4_CPPFLAGS=""
276            KRB4_LDFLAGS=""
277         fi
278      fi
279   fi
280   if test "x$KRB4_LDFLAGS" = "x"; then
281      with_krb4=no
282      AC_MSG_RESULT(no)
283   else
284      AC_MSG_RESULT(yes)
285
286      ac_save_CFLAGS=$CFLAGS
287      ac_save_CPPFLAGS=$CPPFLAGS
288      ac_save_LDFLAGS=$LDFLAGS
289      ac_save_LIBS=$LIBS
290      CFLAGS="$CFLAGS $KRB4_CPPFLAGS"
291      CPPFLAGS="$CFLAGS $KRB4_CPPFLAGS"
292      LDFLAGS="$LDFLAGS $KRB4_LDFLAGS"
293      LIBS="$LIBS $LDFLAGS $LIB_resolv"
294
295 #    if not found krb.h suppose it's in the kerberosIV subdirectory
296      AC_CHECK_HEADER(krb.h, , with_krb4=no)
297      if test "x$with_krb4" = "xno"; then
298          KRB4_CPPFLAGS="$KRB4_CPPFLAGS ${KRB4_CPPFLAGS}/kerberosIV"
299 #        second run of AC_CHECK_HEADER for the same library returns the cached
300 #        result created by previous run :-(
301          AC_CHECK_HEADER(kerberosIV/krb.h, with_krb4=yes,
302                          [  with_krb4=no
303                             KRB4_CPPFLAGS=""
304                             KRB4_LDFLAGS=""])
305      fi
306
307      if test "x$with_krb4" != "xno"; then
308         AC_CHECK_LIB(krb4, krb_get_pw_in_tkt, [], [with_krb4=no])
309         if test "x$with_krb4" = "xno"; then
310            AC_CHECK_LIB(krb, krb_get_pw_in_tkt, [with_krb4=yes], 
311                         [with_krb4=no
312                          KRB4_CPPFLAGS=""
313                          KRB4_LDFLAGS=""])
314         fi
315      fi
316
317      CFLAGS=$ac_save_CFLAGS
318      CPPFLAGS=$ac_save_CPPFLAGS
319      LDFLAGS=$ac_save_LDFLAGS
320      LIBS=$ac_save_LIBS
321
322      AC_DEFINE(KRB4)
323   fi
324 fi
325 AC_SUBST(KRB4_CPPFLAGS)
326 AC_SUBST(KRB4_LDFLAGS)
327
328
329 if test "x$with_krb5" = "xno" -a "x$with_krb4" = "xno"; then
330   AC_MSG_ERROR([No Kerberos enviroment found])
331 fi
332
333 #
334 # Apache enviroment
335 #
336 AC_ARG_WITH(apache,
337   AC_HELP_STRING([--with-apache=dir],[use apache in dir]),
338   [ with_apache="$withval" ])
339
340 AC_PATH_PROG([APXS], [apxs], [], [$with_apache/bin:$with_apache/sbin:$PATH])
341 if test -z "$APXS"; then
342    AC_PATH_PROG([APXS], [apxs2], [], [$with_apache/bin:$with_apache/sbin:$PATH])
343    if test -z "$APXS"; then
344       AC_MSG_ERROR([failed to find apache apxs executable])
345    fi
346 fi
347 AC_SUBST(APXS)
348
349 AC_CONFIG_FILES([Makefile])
350
351 AC_OUTPUT