1dnl -------------------------------------------------------- -*- autoconf -*-
2dnl Licensed to the Apache Software Foundation (ASF) under one or more
3dnl contributor license agreements.  See the NOTICE file distributed with
4dnl this work for additional information regarding copyright ownership.
5dnl The ASF licenses this file to You under the Apache License, Version 2.0
6dnl (the "License"); you may not use this file except in compliance with
7dnl the License.  You may obtain a copy of the License at
8dnl
9dnl     http://www.apache.org/licenses/LICENSE-2.0
10dnl
11dnl Unless required by applicable law or agreed to in writing, software
12dnl distributed under the License is distributed on an "AS IS" BASIS,
13dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dnl See the License for the specific language governing permissions and
15dnl limitations under the License.
16
17
18dnl
19dnl custom autoconf rules for APRUTIL
20dnl
21
22dnl
23dnl APU_FIND_APR: figure out where APR is located
24dnl
25AC_DEFUN([APU_FIND_APR], [
26
27  dnl use the find_apr.m4 script to locate APR. sets apr_found and apr_config
28  APR_FIND_APR(,,,[1])
29  if test "$apr_found" = "no"; then
30    AC_MSG_ERROR(APR could not be located. Please use the --with-apr option.)
31  fi
32
33  APR_BUILD_DIR="`$apr_config --installbuilddir`"
34
35  dnl make APR_BUILD_DIR an absolute directory (we'll need it in the
36  dnl sub-projects in some cases)
37  APR_BUILD_DIR="`cd $APR_BUILD_DIR && pwd`"
38
39  APR_INCLUDES="`$apr_config --includes`"
40  APR_LIBS="`$apr_config --link-libtool --libs`"
41  APR_SO_EXT="`$apr_config --apr-so-ext`"
42  APR_LIB_TARGET="`$apr_config --apr-lib-target`"
43
44  AC_SUBST(APR_INCLUDES)
45  AC_SUBST(APR_LIBS)
46  AC_SUBST(APR_BUILD_DIR)
47])
48
49dnl
50dnl APU_TRY_EXPAT_LINK(
51dnl      test-message, cache-var-name, hdrs, libs,
52dnl      [actions-on-success], [actions-on-failure])
53dnl
54dnl Tests linking against expat with libraries 'libs' and includes
55dnl 'hdrs', passing message + cache-var-name to AC_CACHE_CHECK.
56dnl On success, sets $expat_libs to libs, sets $apu_have_expat to 1,
57dnl and runs actions-on-success; on failure runs actions-on-failure.
58dnl
59AC_DEFUN([APU_TRY_EXPAT_LINK], [
60AC_CACHE_CHECK([$1], [$2], [
61  apu_expat_LIBS=$LIBS
62  LIBS="$LIBS $4"
63  AC_TRY_LINK([#include <stdlib.h>
64#include <$3>], [XML_ParserCreate(NULL);],
65    [$2=yes], [$2=no])
66  LIBS=$apu_expat_LIBS
67])
68
69if test $[$2] = yes; then
70   AC_DEFINE([HAVE_]translit([$3], [a-z./], [A-Z__]), 1,
71             [Define if $3 is available])
72   apu_expat_libs="$4"
73   apu_has_expat=1
74   $5
75else
76   apu_has_expat=0
77   $6
78fi
79])
80
81dnl
82dnl APU_SYSTEM_EXPAT: tests for a system expat installation
83dnl If present, sets $apu_has_expat to 1 and adjusts LDFLAGS/CPPFLAGS
84dnl appropriately.  This is mostly for compatibility with existing
85dnl expat releases; all but the first APU_TRY_EXPAT_LINK call could
86dnl be dropped later.
87dnl
88AC_DEFUN([APU_SYSTEM_EXPAT], [
89
90  APU_TRY_EXPAT_LINK([Expat 1.95.x], apu_cv_expat_system,
91    [expat.h], [-lexpat])
92
93  if test $apu_has_expat = 0; then
94    APU_TRY_EXPAT_LINK([old Debian-packaged expat], apu_cv_expat_debian,
95       [xmltok/xmlparse.h], [-lxmlparse -lxmltok])
96  fi
97
98  if test $apu_has_expat = 0; then
99    APU_TRY_EXPAT_LINK([old FreeBSD-packaged expat], apu_cv_expat_freebsd,
100       [xml/xmlparse.h], [-lexpat])
101  fi
102
103  if test $apu_has_expat = 0; then
104    APU_TRY_EXPAT_LINK([Expat 1.0/1.1], apu_cv_expat_1011,
105       [xmlparse/xmlparse.h], [-lexpat])
106  fi
107
108  if test $apu_has_expat = 0; then
109    APR_ADDTO(LDFLAGS, [-L/usr/local/lib])
110    APR_ADDTO(CPPFLAGS, [-I/usr/local/include])
111
112    APU_TRY_EXPAT_LINK([Expat 1.95.x in /usr/local],
113       apu_cv_expat_usrlocal, [expat.h], [-lexpat],
114       [APR_ADDTO(APRUTIL_INCLUDES, [-I/usr/local/include])
115        APR_ADDTO(APRUTIL_LDFLAGS, [-L/usr/local/lib])],[
116       APR_REMOVEFROM(LDFLAGS, [-L/usr/local/lib])
117       APR_REMOVEFROM(CPPFLAGS, [-I/usr/local/include])
118      ])
119  fi
120])
121
122
123dnl
124dnl APU_FIND_EXPAT: figure out where EXPAT is located
125dnl
126AC_DEFUN([APU_FIND_EXPAT], [
127
128save_cppflags="$CPPFLAGS"
129save_ldflags="$LDFLAGS"
130
131apu_has_expat=0
132
133apu_try_external_expat=1
134
135AC_ARG_WITH([expat],
136[  --with-expat=DIR        specify Expat location], [
137  if test "$withval" = "yes"; then
138    AC_MSG_ERROR([a directory must be specified for --with-expat])
139  elif test "$withval" = "no"; then
140    AC_MSG_ERROR([Expat cannot be disabled (at this time)])
141  else
142    # Add given path to standard search paths if appropriate:
143    if test "$withval" != "/usr"; then
144      APR_ADDTO(LDFLAGS, [-L$withval/lib])
145      APR_ADDTO(CPPFLAGS, [-I$withval/include])
146      APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
147      APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
148    fi
149  fi
150])
151
152if test $apu_try_external_expat = 1; then
153  APU_SYSTEM_EXPAT
154fi
155
156APR_ADDTO(APRUTIL_EXPORT_LIBS, [$apu_expat_libs])
157APR_ADDTO(APRUTIL_LIBS, [$apu_expat_libs])
158
159CPPFLAGS=$save_cppflags
160LDFLAGS=$save_ldflags
161])
162
163
164dnl
165dnl Find a particular LDAP library
166dnl
167AC_DEFUN([APU_FIND_LDAPLIB], [
168  if test ${apu_has_ldap} != "1"; then
169    ldaplib=$1
170    extralib=$2
171    # Clear the cache entry for subsequent APU_FIND_LDAPLIB invocations.
172    changequote(,)
173    ldaplib_cache_id="`echo $ldaplib | sed -e 's/[^a-zA-Z0-9_]/_/g'`"
174    changequote([,])
175    unset ac_cv_lib_${ldaplib_cache_id}_ldap_init
176    unset ac_cv_lib_${ldaplib_cache_id}___ldap_init
177    AC_CHECK_LIB(${ldaplib}, ldap_init,
178      [
179        LDADD_ldap_found="-l${ldaplib} ${extralib}"
180        AC_CHECK_LIB(${ldaplib}, ldapssl_client_init, apu_has_ldapssl_client_init="1", , ${extralib})
181        AC_CHECK_LIB(${ldaplib}, ldapssl_client_deinit, apu_has_ldapssl_client_deinit="1", , ${extralib})
182        AC_CHECK_LIB(${ldaplib}, ldapssl_add_trusted_cert, apu_has_ldapssl_add_trusted_cert="1", , ${extralib})
183        AC_CHECK_LIB(${ldaplib}, ldap_start_tls_s, apu_has_ldap_start_tls_s="1", , ${extralib})
184        AC_CHECK_LIB(${ldaplib}, ldap_sslinit, apu_has_ldap_sslinit="1", , ${extralib})
185        AC_CHECK_LIB(${ldaplib}, ldapssl_init, apu_has_ldapssl_init="1", , ${extralib})
186        AC_CHECK_LIB(${ldaplib}, ldapssl_install_routines, apu_has_ldapssl_install_routines="1", , ${extralib})
187        apu_has_ldap="1";
188      ], , ${extralib})
189  fi
190])
191
192
193dnl
194dnl APU_FIND_LDAP: figure out where LDAP is located
195dnl
196AC_DEFUN([APU_FIND_LDAP],  [
197
198echo $ac_n "${nl}checking for ldap support..."
199
200apu_has_ldap="0";
201apu_has_ldapssl_client_init="0"
202apu_has_ldapssl_client_deinit="0"
203apu_has_ldapssl_add_trusted_cert="0"
204apu_has_ldap_start_tls_s="0"
205apu_has_ldapssl_init="0"
206apu_has_ldap_sslinit="0"
207apu_has_ldapssl_install_routines="0"
208apu_has_ldap_openldap="0"
209apu_has_ldap_solaris="0"
210apu_has_ldap_novell="0"
211apu_has_ldap_microsoft="0"
212apu_has_ldap_netscape="0"
213apu_has_ldap_mozilla="0"
214apu_has_ldap_tivoli="0"
215apu_has_ldap_zos="0"
216apu_has_ldap_other="0"
217LDADD_ldap_found=""
218
219AC_ARG_WITH(lber,[  --with-lber=library     lber library to use],
220  [
221    if test "$withval" = "yes"; then
222      apu_liblber_name="lber"
223    else
224      apu_liblber_name="$withval"
225    fi
226  ],
227  [
228    apu_liblber_name="lber"
229  ])
230
231AC_ARG_WITH(ldap-include,[  --with-ldap-include=path  path to ldap include files with trailing slash])
232AC_ARG_WITH(ldap-lib,[  --with-ldap-lib=path    path to ldap lib file])
233AC_ARG_WITH(ldap,[  --with-ldap=library     ldap library to use],
234  [
235    if test "$with_ldap" != "no"; then
236      save_cppflags="$CPPFLAGS"
237      save_ldflags="$LDFLAGS"
238      save_libs="$LIBS"
239      if test -n "$with_ldap_include"; then
240        CPPFLAGS="$CPPFLAGS -I$with_ldap_include"
241        APR_ADDTO(APRUTIL_INCLUDES, [-I$with_ldap_include])
242      fi
243      if test -n "$with_ldap_lib"; then
244        LDFLAGS="$LDFLAGS -L$with_ldap_lib"
245        APR_ADDTO(APRUTIL_LDFLAGS, [-L$with_ldap_lib])
246      fi
247
248      LIBLDAP="$withval"
249      if test "$LIBLDAP" = "yes"; then
250        dnl The iPlanet C SDK 5.0 is as yet untested...
251        APU_FIND_LDAPLIB("ldap50", "-lnspr4 -lplc4 -lplds4 -liutil50 -llber50 -lldif50 -lnss3 -lprldap50 -lssl3 -lssldap50")
252        APU_FIND_LDAPLIB("ldapssl41", "-lnspr3 -lplc3 -lplds3")
253        APU_FIND_LDAPLIB("ldapssl40")
254        APU_FIND_LDAPLIB("ldapssl30")
255        APU_FIND_LDAPLIB("ldapssl20")
256        APU_FIND_LDAPLIB("ldapsdk", "-lldapx -lldapssl -lldapgss -lgssapi_krb5")
257        APU_FIND_LDAPLIB("ldapsdk", "-lldapx -lldapssl -lldapgss -lgss -lresolv -lsocket")
258        APU_FIND_LDAPLIB("ldap", "-llber")
259        APU_FIND_LDAPLIB("ldap", "-llber -lresolv")
260        APU_FIND_LDAPLIB("ldap", "-llber -lresolv -lsocket -lnsl")
261        APU_FIND_LDAPLIB("ldap", "-ldl -lpthread")
262      else
263        APU_FIND_LDAPLIB($LIBLDAP)
264        APU_FIND_LDAPLIB($LIBLDAP, "-lresolv")
265        APU_FIND_LDAPLIB($LIBLDAP, "-lresolv -lsocket -lnsl")
266        APU_FIND_LDAPLIB($LIBLDAP, "-ldl -lpthread")
267      fi
268
269      if test ${apu_has_ldap} != "1"; then
270        AC_MSG_ERROR(could not find an LDAP library)
271      else
272        APR_ADDTO(LDADD_ldap, [$LDADD_ldap_found])
273      fi
274      AC_CHECK_LIB($apu_liblber_name, ber_init,
275        [APR_ADDTO(LDADD_ldap, [-l${apu_liblber_name}])])
276
277      AC_CHECK_HEADERS(lber.h, lber_h=["#include <lber.h>"])
278
279      # Solaris has a problem in <ldap.h> which prevents it from
280      # being included by itself.  Check for <ldap.h> manually,
281      # including lber.h first.
282      AC_CACHE_CHECK([for ldap.h], [apr_cv_hdr_ldap_h],
283      [AC_TRY_CPP(
284      [#ifdef HAVE_LBER_H
285      #include <lber.h>
286      #endif
287      #include <ldap.h>
288      ], [apr_cv_hdr_ldap_h=yes], [apr_cv_hdr_ldap_h=no])])
289      if test "$apr_cv_hdr_ldap_h" = "yes"; then
290        ldap_h=["#include <ldap.h>"]
291        AC_DEFINE([HAVE_LDAP_H], 1, [Defined if ldap.h is present])
292      fi
293
294      AC_CHECK_HEADERS(ldap_ssl.h, ldap_ssl_h=["#include <ldap_ssl.h>"])
295
296      if test "$apr_cv_hdr_ldap_h" = "yes"; then
297        AC_CACHE_CHECK([for LDAP toolkit],
298                       [apr_cv_ldap_toolkit], [
299          if test "x$apr_cv_ldap_toolkit" = "x"; then
300            AC_EGREP_CPP([OpenLDAP], [$lber_h
301                         $ldap_h
302                         LDAP_VENDOR_NAME], [apu_has_ldap_openldap="1"
303                                             apr_cv_ldap_toolkit="OpenLDAP"])
304          fi
305          if test "x$apr_cv_ldap_toolkit" = "x"; then
306            AC_EGREP_CPP([Sun Microsystems Inc.], [$lber_h
307                         $ldap_h
308                         LDAP_VENDOR_NAME], [apu_has_ldap_solaris="1"
309                                             apr_cv_ldap_toolkit="Solaris"])
310          fi
311          if test "x$apr_cv_ldap_toolkit" = "x"; then
312            AC_EGREP_CPP([Novell], [$lber_h
313                         $ldap_h
314                         LDAP_VENDOR_NAME], [apu_has_ldap_novell="1"
315                                             apr_cv_ldap_toolkit="Novell"])
316          fi
317          if test "x$apr_cv_ldap_toolkit" = "x"; then
318            AC_EGREP_CPP([Microsoft Corporation.], [$lber_h
319                         $ldap_h
320                         LDAP_VENDOR_NAME], [apu_has_ldap_microsoft="1"
321                                             apr_cv_ldap_toolkit="Microsoft"])
322          fi
323          if test "x$apr_cv_ldap_toolkit" = "x"; then
324            AC_EGREP_CPP([Netscape Communications Corp.], [$lber_h
325                         $ldap_h
326                         LDAP_VENDOR_NAME], [apu_has_ldap_netscape="1"
327                                             apr_cv_ldap_toolkit="Netscape"])
328          fi
329          if test "x$apr_cv_ldap_toolkit" = "x"; then
330            AC_EGREP_CPP([mozilla.org], [$lber_h
331                         $ldap_h
332                         LDAP_VENDOR_NAME], [apu_has_ldap_mozilla="1"
333                                             apr_cv_ldap_toolkit="Mozilla"])
334          fi
335          if test "x$apr_cv_ldap_toolkit" = "x"; then
336            AC_EGREP_CPP([International Business Machines], [$lber_h
337                         $ldap_h
338                         LDAP_VENDOR_NAME], [apu_has_ldap_tivoli="1"
339                                             apr_cv_ldap_toolkit="Tivoli"])
340          fi
341          if test "x$apr_cv_ldap_toolkit" = "x"; then
342            case "$host" in
343            *-ibm-os390)
344              AC_EGREP_CPP([IBM], [$lber_h
345                                   $ldap_h], [apu_has_ldap_zos="1"
346                                              apr_cv_ldap_toolkit="z/OS"])
347              ;;
348            esac
349          fi
350          if test "x$apr_cv_ldap_toolkit" = "x"; then
351            apu_has_ldap_other="1"
352            apr_cv_ldap_toolkit="unknown"
353          fi
354        ])
355      fi
356
357      CPPFLAGS=$save_cppflags
358      LDFLAGS=$save_ldflags
359      LIBS=$save_libs
360    fi
361  ])
362
363if test "$apu_has_ldap_openldap" = "1"; then
364    save_cppflags="$CPPFLAGS"
365    save_ldflags="$LDFLAGS"
366    save_libs="$LIBS"
367
368    CPPFLAGS="$CPPFLAGS $APRUTIL_INCLUDES"
369    LDFLAGS="$LDFLAGS $APRUTIL_LDFLAGS"
370    AC_CACHE_CHECK([style of ldap_set_rebind_proc routine], ac_cv_ldap_set_rebind_proc_style,
371    APR_TRY_COMPILE_NO_WARNING([
372    #ifdef HAVE_LBER_H
373    #include <lber.h>
374    #endif
375    #ifdef HAVE_LDAP_H
376    #include <ldap.h>
377    #endif
378    ], [
379    ldap_set_rebind_proc((LDAP *)0, (LDAP_REBIND_PROC *)0, (void *)0);
380    ], ac_cv_ldap_set_rebind_proc_style=three, ac_cv_ldap_set_rebind_proc_style=two))
381
382    if test "$ac_cv_ldap_set_rebind_proc_style" = "three"; then
383        AC_DEFINE(LDAP_SET_REBIND_PROC_THREE, 1, [Define if ldap_set_rebind_proc takes three arguments])
384    fi
385
386    CPPFLAGS="$save_cppflags"
387    LDFLAGS="$save_ldflags"
388    LIBS="$save_libs"
389fi
390
391AC_SUBST(ldap_h)
392AC_SUBST(lber_h)
393AC_SUBST(ldap_ssl_h)
394AC_SUBST(apu_has_ldapssl_client_init)
395AC_SUBST(apu_has_ldapssl_client_deinit)
396AC_SUBST(apu_has_ldapssl_add_trusted_cert)
397AC_SUBST(apu_has_ldap_start_tls_s)
398AC_SUBST(apu_has_ldapssl_init)
399AC_SUBST(apu_has_ldap_sslinit)
400AC_SUBST(apu_has_ldapssl_install_routines)
401AC_SUBST(apu_has_ldap)
402AC_SUBST(apu_has_ldap_openldap)
403AC_SUBST(apu_has_ldap_solaris)
404AC_SUBST(apu_has_ldap_novell)
405AC_SUBST(apu_has_ldap_microsoft)
406AC_SUBST(apu_has_ldap_netscape)
407AC_SUBST(apu_has_ldap_mozilla)
408AC_SUBST(apu_has_ldap_tivoli)
409AC_SUBST(apu_has_ldap_zos)
410AC_SUBST(apu_has_ldap_other)
411AC_SUBST(LDADD_ldap)
412
413])
414
415dnl
416dnl APU_CHECK_CRYPT_R_STYLE
417dnl
418dnl  Decide which of a couple of flavors of crypt_r() is necessary for
419dnl  this platform.
420dnl
421AC_DEFUN([APU_CHECK_CRYPT_R_STYLE], [
422
423AC_CACHE_CHECK([style of crypt_r], apr_cv_crypt_r_style,
424[AC_TRY_COMPILE([#include <crypt.h>],
425 [CRYPTD buffer;
426  crypt_r("passwd", "hash", &buffer);],
427 [apr_cv_crypt_r_style=cryptd],
428 [AC_TRY_COMPILE([#include <crypt.h>],
429  [struct crypt_data buffer;
430   crypt_r("passwd", "hash", &buffer);],
431  [apr_cv_crypt_r_style=struct_crypt_data],
432  [apr_cv_crypt_r_style=none])])])
433
434if test "$apr_cv_crypt_r_style" = "cryptd"; then
435   AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
436elif test "$apr_cv_crypt_r_style" = "struct_crypt_data"; then
437   AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])
438fi
439])
440