]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/apr/configure.in
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / apr / configure.in
1 dnl 
2 dnl Autoconf configuration file for APR
3 dnl 
4 dnl Process this file with autoconf to produce a configure script.
5 dnl Use ./buildconf to prepare build files and run autoconf for APR.
6
7 AC_PREREQ(2.59)
8
9 AC_INIT(build/apr_common.m4)
10 AC_CONFIG_HEADER(include/arch/unix/apr_private.h)
11 AC_CONFIG_AUX_DIR(build)
12 AC_CONFIG_MACRO_DIR(build)
13
14 dnl 
15 dnl Include our own M4 macros along with those for libtool
16 dnl 
17 sinclude(build/apr_common.m4)
18 sinclude(build/apr_network.m4)
19 sinclude(build/apr_threads.m4)
20 sinclude(build/apr_win32.m4)
21 sinclude(build/apr_hints.m4)
22 sinclude(build/libtool.m4)
23 sinclude(build/ltsugar.m4)
24 sinclude(build/argz.m4)
25 sinclude(build/ltoptions.m4)
26 sinclude(build/ltversion.m4)
27 sinclude(build/lt~obsolete.m4)
28
29 dnl Hard-coded top of apr_private.h:
30 AH_TOP([
31 #ifndef APR_PRIVATE_H
32 #define APR_PRIVATE_H
33 ])
34
35 dnl Hard-coded inclusion at the tail end of apr_private.h:
36 AH_BOTTOM([
37 /* switch this on if we have a BeOS version below BONE */
38 #if defined(BEOS) && !defined(HAVE_BONE_VERSION)
39 #define BEOS_R5 1
40 #else
41 #define BEOS_BONE 1
42 #endif
43
44 /*
45  * Darwin 10's default compiler (gcc42) builds for both 64 and
46  * 32 bit architectures unless specifically told not to.
47  * In those cases, we need to override types depending on how
48  * we're being built at compile time.
49  * NOTE: This is an ugly work-around for Darwin's
50  * concept of universal binaries, a single package
51  * (executable, lib, etc...) which contains both 32
52  * and 64 bit versions. The issue is that if APR is
53  * built universally, if something else is compiled
54  * against it, some bit sizes will depend on whether
55  * it is 32 or 64 bit. This is determined by the __LP64__
56  * flag. Since we need to support both, we have to
57  * handle OS X unqiuely.
58  */
59 #ifdef DARWIN_10
60
61 #undef APR_OFF_T_STRFN
62 #undef APR_INT64_STRFN
63 #undef SIZEOF_LONG
64 #undef SIZEOF_SIZE_T
65 #undef SIZEOF_SSIZE_T
66 #undef SIZEOF_VOIDP
67 #undef SIZEOF_STRUCT_IOVEC
68
69 #ifdef __LP64__
70  #define APR_INT64_STRFN strtol
71  #define SIZEOF_LONG    8
72  #define SIZEOF_SIZE_T  8
73  #define SIZEOF_SSIZE_T 8
74  #define SIZEOF_VOIDP   8
75  #define SIZEOF_STRUCT_IOVEC 16
76 #else
77  #define APR_INT64_STRFN strtoll
78  #define SIZEOF_LONG    4
79  #define SIZEOF_SIZE_T  4
80  #define SIZEOF_SSIZE_T 4
81  #define SIZEOF_VOIDP   4
82  #define SIZEOF_STRUCT_IOVEC 8
83 #endif
84
85 #undef APR_OFF_T_STRFN
86 #define APR_OFF_T_STRFN APR_INT64_STRFN
87  
88
89 #undef SETPGRP_VOID
90 #ifdef __DARWIN_UNIX03
91  #define SETPGRP_VOID 1
92 #else
93 /* #undef SETPGRP_VOID */
94 #endif
95  
96 #endif /* DARWIN_10 */
97
98 /*
99  * Include common private declarations.
100  */
101 #include "../apr_private_common.h"
102 #endif /* APR_PRIVATE_H */
103 ])
104
105 dnl Save user-defined environment settings for later restoration
106 dnl
107 APR_SAVE_THE_ENVIRONMENT(CPPFLAGS)
108 APR_SAVE_THE_ENVIRONMENT(CFLAGS)
109 APR_SAVE_THE_ENVIRONMENT(LDFLAGS)
110 APR_SAVE_THE_ENVIRONMENT(LIBS)
111 APR_SAVE_THE_ENVIRONMENT(INCLUDES)
112
113 dnl Generate ./config.nice for reproducing runs of configure
114 dnl
115 APR_CONFIG_NICE(config.nice)
116
117 AC_CANONICAL_SYSTEM
118 echo "Configuring APR library"
119 echo "Platform: $host"
120
121 dnl Some initial steps for configuration.  We setup the default directory
122 dnl and which files are to be configured.
123
124 dnl Setup the directory macros now
125
126 # Absolute source/build directory
127 apr_srcdir=`(cd $srcdir && pwd)`
128 apr_builddir=`pwd`
129 AC_SUBST(apr_srcdir)
130 AC_SUBST(apr_builddir)
131
132 if test "$apr_builddir" != "$apr_srcdir"; then
133   USE_VPATH=1
134   APR_CONFIG_LOCATION=build
135 else
136   APR_CONFIG_LOCATION=source
137 fi
138
139 AC_SUBST(APR_CONFIG_LOCATION)
140
141 # Libtool might need this symbol -- it must point to the location of
142 # the generated libtool script (not necessarily the "top" build dir).
143 #
144 top_builddir="$apr_builddir"
145 AC_SUBST(top_builddir)
146
147 # Directory containing apr build macros, helpers, and make rules
148 # NOTE: make rules (apr_rules.mk) will be in the builddir for vpath
149 #
150 apr_buildout=$apr_builddir/build
151 apr_builders=$apr_srcdir/build
152 AC_SUBST(apr_builders)
153
154 MKDIR=$apr_builders/mkdir.sh
155
156 dnl Initialize mkdir -p functionality.
157 APR_MKDIR_P_CHECK($apr_builders/mkdir.sh)
158
159 # get our version information
160 get_version="$apr_builders/get-version.sh"
161 version_hdr="$apr_srcdir/include/apr_version.h"
162 APR_MAJOR_VERSION="`$get_version major $version_hdr APR`"
163 APR_DOTTED_VERSION="`$get_version all $version_hdr APR`"
164
165 AC_SUBST(APR_DOTTED_VERSION)
166 AC_SUBST(APR_MAJOR_VERSION)
167
168 echo "APR Version: ${APR_DOTTED_VERSION}"
169
170 dnl Enable the layout handling code, then reparse the prefix-style
171 dnl arguments due to autoconf being a PITA.
172 APR_ENABLE_LAYOUT(apr)
173 APR_PARSE_ARGUMENTS
174
175 dnl Set optional CC hints here in case autoconf makes an inappropriate choice.
176 dnl This allows us to suggest what the compiler should be, but still
177 dnl allows the user to override CC externally.
178 APR_CC_HINTS
179
180 dnl Do the various CC checks *before* preloading values. The preload code
181 dnl may need to use compiler characteristics to make decisions. This macro
182 dnl can only be used once within a configure script, so this prevents a
183 dnl preload section from invoking the macro to get compiler info.
184 AC_PROG_CC
185
186 dnl AC_PROG_SED is only avaliable in recent autoconf versions.
187 dnl Use AC_CHECK_PROG instead if AC_PROG_SED is not present.
188 ifdef([AC_PROG_SED],
189       [AC_PROG_SED],
190       [AC_CHECK_PROG(SED, sed, sed)])
191
192 dnl Preload
193 APR_PRELOAD
194
195 dnl These added to allow default directories to be used...
196 DEFAULT_OSDIR="unix"
197 echo "(Default will be ${DEFAULT_OSDIR})"
198
199 apr_modules="file_io network_io threadproc misc locks time mmap shmem user memory atomic poll support random"
200
201 dnl Checks for programs.
202 AC_PROG_MAKE_SET
203 AC_PROG_CPP
204 AC_PROG_AWK
205 AC_PROG_LN_S
206 AC_PROG_RANLIB
207 AC_PROG_INSTALL
208 AC_CHECK_PROG(RM, rm, rm)
209 AC_CHECK_PROG(AS, as, as)
210 AC_CHECK_PROG(ASCPP, cpp, cpp)
211 AC_CHECK_TOOL(AR, ar, ar)
212
213 dnl Various OS checks that apparently set required flags
214 ifdef([AC_USE_SYSTEM_EXTENSIONS], [
215 AC_USE_SYSTEM_EXTENSIONS
216 ], [
217 AC_AIX
218 AC_MINIX
219 ])
220
221 AC_ISC_POSIX
222 APR_EBCDIC
223
224 dnl this is our library name
225 APR_LIBNAME="apr${libsuffix}"
226 AC_SUBST(APR_LIBNAME)
227
228 dnl prep libtool
229 dnl
230 echo "performing libtool configuration..."
231
232 AC_ARG_ENABLE(experimental-libtool,[  --enable-experimental-libtool Use experimental custom libtool],
233   [experimental_libtool=$enableval],[experimental_libtool=no])
234
235 dnl Workarounds for busted Libtool 2.x when we don't call AC_PROG_LIBTOOL
236 if test "x$Xsed" = "x"; then
237   Xsed="$SED -e 1s/^X//"
238 fi
239
240 case $host in
241 *-os2*)
242     # Use a custom-made libtool replacement
243     echo "using aplibtool"
244     LIBTOOL="$srcdir/build/aplibtool"
245     gcc $CFLAGS $CPPFLAGS -o $LIBTOOL.exe $LIBTOOL.c
246     ;;
247 *)
248     if test "x$LTFLAGS" = "x"; then
249         LTFLAGS='--silent'
250     fi
251     if test "$experimental_libtool" = "yes"; then
252         # Use a custom-made libtool replacement
253         echo "using jlibtool"
254         LIBTOOL="$apr_builddir/libtool"
255         LIBTOOL_SRC="$apr_srcdir/build/jlibtool.c"
256         $CC $CFLAGS $CPPFLAGS -o $LIBTOOL $LIBTOOL_SRC
257         eval `$apr_builddir/libtool --config | grep "^shlibpath_var=[[A-Z_]]*$"`
258         if test "x$shlibpath_var" = "x"; then
259             shlibpath_var=REPLACE_WITH_YOUR_SHLIBPATH_VAR
260         fi
261     else
262     dnl libtoolize requires that the following not be indented
263     dnl should become LT_INIT(win32-dll)
264 AC_LIBTOOL_WIN32_DLL
265 AC_PROG_LIBTOOL
266         # get libtool's setting of shlibpath_var
267         eval `grep "^shlibpath_var=[[A-Z_]]*$" $apr_builddir/libtool`
268         if test "x$shlibpath_var" = "x"; then
269             shlibpath_var=REPLACE_WITH_YOUR_SHLIBPATH_VAR
270         fi
271     fi
272     ;;
273 esac
274
275 AC_ARG_WITH(installbuilddir, [  --with-installbuilddir=DIR location to store APR build files (defaults to '${datadir}/build')],
276   [ installbuilddir=$withval ], [ installbuilddir="${datadir}/build-${APR_MAJOR_VERSION}" ] )
277 AC_SUBST(installbuilddir)
278
279 AC_ARG_WITH(libtool, [  --without-libtool       avoid using libtool to link the library],
280   [ use_libtool=$withval ], [ use_libtool="yes" ] )
281
282 if test "x$use_libtool" = "xyes"; then
283       lt_compile='$(LIBTOOL) $(LTFLAGS) --mode=compile $(COMPILE) -o $@ -c $< && touch $@'
284       LT_VERSION="-version-info `$get_version libtool $version_hdr APR`"
285       link="\$(LIBTOOL) \$(LTFLAGS) --mode=link \$(COMPILE) \$(LT_LDFLAGS) \$(LT_VERSION) \$(ALL_LDFLAGS) -o \$@"
286       so_ext='lo'
287       lib_target='-rpath $(libdir) $(OBJECTS)'
288       export_lib_target='-rpath \$(libdir) \$(OBJECTS)'
289 else
290       lt_compile='$(COMPILE) -o $@ -c $<'
291       link='$(AR) cr $(TARGET_LIB) $(OBJECTS); $(RANLIB) $(TARGET_LIB)'
292       so_ext='o'
293       lib_target=''
294       export_lib_target=''
295 fi
296
297 case $host in
298     *-solaris2*)
299         apr_platform_runtime_link_flag="-R"
300         ;;
301     *-mingw* | *-cygwin*)
302         LT_LDFLAGS="$LT_LDFLAGS -no-undefined"
303         ;;
304     *)
305         ;;
306 esac
307
308 AC_SUBST(lt_compile)
309 AC_SUBST(link)
310 AC_SUBST(so_ext)
311 AC_SUBST(lib_target)
312 AC_SUBST(export_lib_target)
313 AC_SUBST(shlibpath_var)
314 AC_SUBST(LTFLAGS)
315 AC_SUBST(LT_LDFLAGS)
316 AC_SUBST(LT_VERSION)
317
318 dnl ----------------------------- Checks for compiler flags
319 nl='
320 '
321 echo "${nl}Check for compiler flags..."
322
323 dnl AC_PROG_CC sets -g in CFLAGS (and -O2 for gcc) by default.
324 dnl On OS/390 this causes the compiler to insert extra debugger
325 dnl hook instructions.  That's fine for debug/maintainer builds, not fine
326 dnl otherwise.
327
328 case $host in
329     *os390)
330         if test "$ac_test_CFLAGS" != set; then
331            APR_REMOVEFROM(CFLAGS,-g)
332         fi
333         ;;
334 esac
335
336 AC_ARG_ENABLE(debug,[  --enable-debug          Turn on debugging and compile time warnings],
337   [APR_ADDTO(CFLAGS,-g)
338    if test "$GCC" = "yes"; then
339      APR_ADDTO(CFLAGS,-Wall)
340    elif test "$AIX_XLC" = "yes"; then
341      APR_ADDTO(CFLAGS,-qfullpath)
342    fi
343 ])dnl
344
345 AC_ARG_ENABLE(maintainer-mode,[  --enable-maintainer-mode  Turn on debugging and compile time warnings],
346   [APR_ADDTO(CFLAGS,-g)
347    if test "$GCC" = "yes"; then
348      APR_ADDTO(CFLAGS,[-Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations])
349    elif test "$AIX_XLC" = "yes"; then
350      APR_ADDTO(CFLAGS,-qfullpath -qinitauto=FE -qcheck=all -qinfo=pro)
351    fi
352 ])dnl
353
354 AC_ARG_ENABLE(profile,[  --enable-profile        Turn on profiling for the build (GCC)],
355   if test "$GCC" = "yes"; then
356     APR_ADDTO(CFLAGS, -pg)
357     APR_REMOVEFROM(CFLAGS, -g)
358     if test "$host" = "i586-pc-beos"; then
359         APR_REMOVEFROM(CFLAGS, -O2)
360         APR_ADDTO(CFLAGS, -O1)
361         APR_ADDTO(LDFLAGS, -p)
362     fi
363   fi
364 )dnl
365
366 AC_ARG_ENABLE(pool-debug,
367   [  --enable-pool-debug[[=yes|no|verbose|verbose-alloc|lifetime|owner|all]]    Turn on pools debugging],
368   [ if test -z "$enableval"; then
369         APR_ADDTO(CPPFLAGS, -DAPR_POOL_DEBUG=1)
370     elif test ! "$enableval" = "no"; then
371         apr_pool_debug=1
372     
373         for i in $enableval
374         do
375             flag=0
376         
377             case $i in
378             yes)
379                 flag=1
380                 ;;
381             verbose)
382                 flag=2
383                 ;;
384             lifetime)
385                 flag=4
386                 ;;
387             owner)
388                 flag=8
389                 ;;
390             verbose-alloc)
391                 flag=16
392                 ;;
393             all)
394                 apr_pool_debug=31
395                 ;;
396             *)
397                 ;;
398             esac
399
400             if test $flag -gt 0; then
401                 apr_pool_debug=`expr '(' $apr_pool_debug - $apr_pool_debug % \
402                     '(' $flag '*' 2 ')' ')' + $flag + $apr_pool_debug % $flag`
403             fi
404         done
405       
406         APR_ADDTO(CPPFLAGS, -DAPR_POOL_DEBUG=$apr_pool_debug)
407     fi
408   ])
409
410 if test "$host" = "i586-pc-beos"; then
411   AC_ARG_ENABLE(malloc-debug,[  --enable-malloc-debug   Switch on malloc_debug for BeOS],
412     APR_REMOVEFROM(CFLAGS, -O2)
413     APR_ADDTO(CPPFLAGS, -fcheck-memory-usage -D_KERNEL_MODE)
414   ) dnl
415 fi
416
417 # this is the place to put specific options for platform/compiler
418 # combinations
419 case "$host:$CC" in
420     *-hp-hpux*:cc )
421         APR_ADDTO(CFLAGS,[-Ae +Z])
422         case $host in
423           ia64-* )
424             ;;
425           * )
426             if echo "$CFLAGS " | grep '+DA' >/dev/null; then :
427             else
428               APR_ADDTO(CFLAGS,[+DAportable])
429             fi 
430             ;;
431         esac
432         ;;
433     powerpc-*-beos:mwcc* )
434         APR_SETVAR(CPP,[mwcc -E])
435         APR_SETVAR(CC,mwcc)
436         APR_SETVAR(AR,ar)
437         ;;
438     dnl If building static APR, both the APR build and the app build
439     dnl need -DAPR_DECLARE_STATIC to generate the right linkage from    
440     dnl APR_DECLARE et al.
441     dnl If building dynamic APR, the APR build needs APR_DECLARE_EXPORT
442     dnl and the app build should have neither define.
443     *-mingw* | *-cygwin*)
444         if test "$enable_shared" = "yes"; then
445             APR_ADDTO(INTERNAL_CPPFLAGS, -DAPR_DECLARE_EXPORT)
446         else
447             APR_ADDTO(CPPFLAGS, -DAPR_DECLARE_STATIC)
448         fi
449         ;;
450 esac
451
452 AC_CACHE_CHECK([whether the compiler provides atomic builtins], [ap_cv_atomic_builtins],
453 [AC_TRY_RUN([
454 int main()
455 {
456     unsigned long val = 1010, tmp, *mem = &val;
457
458     if (__sync_fetch_and_add(&val, 1010) != 1010 || val != 2020)
459         return 1;
460
461     tmp = val;
462
463     if (__sync_fetch_and_sub(mem, 1010) != tmp || val != 1010)
464         return 1;
465
466     if (__sync_sub_and_fetch(&val, 1010) != 0 || val != 0)
467         return 1;
468
469     tmp = 3030;
470
471     if (__sync_val_compare_and_swap(mem, 0, tmp) != 0 || val != tmp)
472         return 1;
473
474     if (__sync_lock_test_and_set(&val, 4040) != 3030)
475         return 1;
476
477     mem = &tmp;
478
479     if (__sync_val_compare_and_swap(&mem, &tmp, &val) != &tmp)
480         return 1;
481
482     __sync_synchronize();
483
484     if (mem != &val)
485         return 1;
486
487     return 0;
488 }], [ap_cv_atomic_builtins=yes], [ap_cv_atomic_builtins=no], [ap_cv_atomic_builtins=no])])
489
490 if test "$ap_cv_atomic_builtins" = "yes"; then
491     AC_DEFINE(HAVE_ATOMIC_BUILTINS, 1, [Define if compiler provides atomic builtins])
492 fi
493
494 case $host in
495     powerpc-405-*)
496         # The IBM ppc405cr processor has a bugged stwcx instruction.
497         AC_DEFINE(PPC405_ERRATA, 1, [Define on PowerPC 405 where errata 77 applies])
498         ;;
499     *)
500         ;;
501 esac
502
503 dnl Check the depend program we can use
504 APR_CHECK_DEPEND
505
506 proc_mutex_is_global=0
507
508 config_subdirs="none"
509 INSTALL_SUBDIRS="none"
510 OBJECTS_PLATFORM='$(OBJECTS_unix)'
511
512 case $host in
513    i386-ibm-aix* | *-ibm-aix[[1-2]].* | *-ibm-aix3.* | *-ibm-aix4.1 | *-ibm-aix4.1.* | *-ibm-aix4.2 | *-ibm-aix4.2.*)
514        OSDIR="aix"
515        APR_ADDTO(LDFLAGS,-lld)
516        eolstr="\\n"
517        OBJECTS_PLATFORM='$(OBJECTS_aix)'
518        ;;
519    *-os2*)
520        APR_ADDTO(CPPFLAGS,-DOS2)
521        APR_ADDTO(CFLAGS,-Zmt)
522        AC_CHECK_LIB(bsd, random)
523        OSDIR="os2"
524        enable_threads="system_threads"
525        eolstr="\\r\\n"
526        file_as_socket="0"
527        proc_mutex_is_global=1
528        OBJECTS_PLATFORM='$(OBJECTS_os2)'
529        ;;
530    *beos*)
531        OSDIR="beos"
532        APR_ADDTO(CPPFLAGS,-DBEOS)
533        enable_threads="system_threads"
534        native_mmap_emul="1"
535        APR_CHECK_DEFINE(BONE_VERSION, sys/socket.h)
536        eolstr="\\n"
537        osver=`uname -r`
538        proc_mutex_is_global=1
539        OBJECTS_PLATFORM='$(OBJECTS_beos)'
540        case $osver in
541           5.0.4)
542              file_as_socket="1"
543              ;;
544           *)
545              file_as_socket="0"
546              ;;
547        esac
548        ;;
549    *os390)
550        OSDIR="os390"
551        OBJECTS_PLATFORM='$(OBJECTS_os390)'
552        eolstr="\\n"
553        ;;
554    *os400)
555        OSDIR="as400"
556        eolstr="\\n"
557        ;;
558    *mingw*)
559        OSDIR="win32"
560        enable_threads="system_threads"
561        eolstr="\\r\\n"
562        file_as_socket=0
563        proc_mutex_is_global=1
564        OBJECTS_PLATFORM='$(OBJECTS_win32)'
565        ;;
566    *cygwin*)
567        OSDIR="unix"
568        enable_threads="no"
569        eolstr="\\n"
570        ;;
571    *hpux10* ) 
572        enable_threads="no"
573        OSDIR="unix"
574        eolstr="\\n"
575        ;;
576    *)
577        OSDIR="unix"
578        eolstr="\\n"
579        ;;
580 esac
581
582 AC_SUBST(OBJECTS_PLATFORM)
583
584 # Check whether LFS has explicitly been disabled
585 AC_ARG_ENABLE(lfs,[  --disable-lfs           Disable large file support on 32-bit platforms],
586 [apr_lfs_choice=$enableval], [apr_lfs_choice=yes])
587
588 if test "$apr_lfs_choice" = "yes"; then
589    # Check whether the transitional LFS API is sufficient
590    AC_CACHE_CHECK([whether to enable -D_LARGEFILE64_SOURCE], [apr_cv_use_lfs64], [
591    apr_save_CPPFLAGS=$CPPFLAGS
592    CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
593    AC_TRY_RUN([
594 #include <sys/types.h>
595 #include <sys/stat.h>
596 #include <fcntl.h>
597 #include <stdlib.h>
598 #include <stdio.h>
599 #include <unistd.h>
600
601 void main(void)
602 {
603     int fd, ret = 0;
604     struct stat64 st;
605     off64_t off = 4242;
606
607     if (sizeof(off64_t) != 8 || sizeof(off_t) != 4)
608        exit(1);
609     if ((fd = open("conftest.lfs", O_LARGEFILE|O_CREAT|O_WRONLY, 0644)) < 0)
610        exit(2);
611     if (ftruncate64(fd, off) != 0)
612        ret = 3;
613     else if (fstat64(fd, &st) != 0 || st.st_size != off)
614        ret = 4;
615     else if (lseek64(fd, off, SEEK_SET) != off)
616        ret = 5;
617     else if (close(fd) != 0)
618        ret = 6;
619     else if (lstat64("conftest.lfs", &st) != 0 || st.st_size != off)
620        ret = 7;
621     else if (stat64("conftest.lfs", &st) != 0 || st.st_size != off)
622        ret = 8;
623     unlink("conftest.lfs");
624
625     exit(ret);
626 }], [apr_cv_use_lfs64=yes], [apr_cv_use_lfs64=no], [apr_cv_use_lfs64=no])
627    CPPFLAGS=$apr_save_CPPFLAGS])
628    if test "$apr_cv_use_lfs64" = "yes"; then
629       APR_ADDTO(CPPFLAGS, [-D_LARGEFILE64_SOURCE])
630    fi
631 fi
632
633 AC_ARG_ENABLE(nonportable-atomics,
634 [  --enable-nonportable-atomics  Use optimized atomic code which may produce nonportable binaries],
635 [if test $enableval = yes; then
636    force_generic_atomics=no
637  else
638    force_generic_atomics=yes
639  fi
640 ],
641 [case $host_cpu in
642    i[[456]]86) force_generic_atomics=yes ;;
643    *) force_generic_atomics=no ;;
644 esac
645 ])
646
647 if test $force_generic_atomics = yes; then
648    AC_DEFINE([USE_ATOMICS_GENERIC], 1,
649              [Define if use of generic atomics is requested])
650 fi
651
652 AC_SUBST(proc_mutex_is_global)
653 AC_SUBST(eolstr)
654 AC_SUBST(INSTALL_SUBDIRS)
655
656 # For some platforms we need a version string which allows easy numeric
657 # comparisons.
658 case $host in
659     *freebsd*)
660         if test -x /sbin/sysctl; then
661             os_version=`/sbin/sysctl -n kern.osreldate`
662         else
663             os_version=000000
664         fi
665         ;;
666     *linux*)
667         os_major=[`uname -r | sed -e 's/\([1-9][0-9]*\)\..*/\1/'`]
668         os_minor=[`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]\+\)\..*/\1/'`]
669         if test $os_major -lt 2 -o \( $os_major -eq 2 -a $os_minor -lt 4 \); then
670             AC_MSG_WARN([Configured for pre-2.4 Linux $os_major.$os_minor])
671             os_pre24linux=1
672         else
673             os_pre24linux=0
674             AC_MSG_NOTICE([Configured for Linux $os_major.$os_minor])
675         fi
676         ;;
677     *os390)
678         os_version=`uname -r | sed -e 's/\.//g'`
679         ;;
680     *)
681         os_version=OS_VERSION_IS_NOT_SET
682         ;;
683 esac
684
685 echo "${nl}Checking for libraries..."
686
687 dnl ----------------------------- Checks for Any required Libraries
688 dnl Note: Autoconf will always append LIBS with an extra " " in AC_CHECK_LIB.
689 dnl It should check for LIBS being empty and set LIBS equal to the new value 
690 dnl without the extra " " in that case, but they didn't do that.  So, we
691 dnl end up LIBS="-lm -lcrypt -lnsl  -ldl" which is an annoyance.
692 case $host in
693    *mingw*)
694       APR_ADDTO(LIBS,[-lshell32 -ladvapi32 -lws2_32 -lrpcrt4 -lmswsock])
695       ac_cv_func_CreateFileMapping=yes
696       ;;
697    *)
698       AC_SEARCH_LIBS(gethostbyname, nsl)
699       AC_SEARCH_LIBS(gethostname, nsl)
700       AC_SEARCH_LIBS(socket, socket)
701       AC_SEARCH_LIBS(crypt, crypt ufc)
702       AC_CHECK_LIB(truerand, main)
703       AC_SEARCH_LIBS(modf, m)
704        ;;
705 esac
706
707 dnl ----------------------------- Checking for Threads
708 echo "${nl}Checking for Threads..."
709
710 if test -z "$enable_threads"; then
711         AC_ARG_ENABLE(threads,
712         [  --enable-threads        Enable threading support in APR.],
713         [ enable_threads=$enableval] ,
714         [ APR_CHECK_PTHREADS_H([ enable_threads="pthread" ] ,
715                                [ enable_threads="no" ] ) ] )
716 fi
717
718 if test "$enable_threads" = "no"; then
719     threads="0"
720     pthreadh="0"
721     pthreadser="0"
722 else
723     if test "$enable_threads" = "pthread"; then
724 # We have specified pthreads for our threading library, just make sure
725 # that we have everything we need
726       APR_PTHREADS_CHECK_SAVE
727       APR_PTHREADS_CHECK
728       APR_CHECK_PTHREADS_H([
729           threads="1"
730           pthreadh="1"
731           pthreadser="1" ], [
732           threads="0"
733           pthreadh="0"
734           pthreadser="0"
735           APR_PTHREADS_CHECK_RESTORE ] )
736     elif test "$enable_threads" = "system_threads"; then
737         threads="1"
738         pthreadh="0"
739         pthreadser="0"
740     else
741 # We basically specified that we wanted threads, but not how to implement
742 # them.  In this case, just look for pthreads.  In the future, we can check
743 # for other threading libraries as well.
744       APR_PTHREADS_CHECK_SAVE
745       APR_PTHREADS_CHECK
746       APR_CHECK_PTHREADS_H([
747           threads="1"
748           pthreadh="1"
749           pthreadser="1" ], [
750           threads="0"
751           pthreadser="0"
752           pthreadh="0"
753           APR_PTHREADS_CHECK_RESTORE ] )
754     fi
755     if test "$pthreadh" = "1"; then
756         APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
757         APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
758         APR_CHECK_PTHREAD_RECURSIVE_MUTEX
759         AC_CHECK_FUNCS([pthread_key_delete pthread_rwlock_init \
760                         pthread_attr_setguardsize pthread_yield])
761
762         if test "$ac_cv_func_pthread_rwlock_init" = "yes"; then
763             dnl ----------------------------- Checking for pthread_rwlock_t
764             AC_CACHE_CHECK([for pthread_rwlock_t], [apr_cv_type_rwlock_t],
765             AC_TRY_COMPILE([#include <sys/types.h>
766 #include <pthread.h>], [pthread_rwlock_t *rwlock;],
767               [apr_cv_type_rwlock_t=yes], [apr_cv_type_rwlock_t=no], 
768               [apr_cv_type_rwlock_t=no]))
769             if test "$apr_cv_type_rwlock_t" = "yes"; then
770                AC_DEFINE(HAVE_PTHREAD_RWLOCKS, 1, [Define if pthread rwlocks are available])
771             fi
772         fi
773
774         if test "$ac_cv_func_pthread_yield" = "no"; then
775             dnl ----------------------------- Checking for sched_yield
776             AC_CHECK_HEADERS([sched.h])
777             AC_CHECK_FUNCS([sched_yield])
778         fi
779     fi
780 fi
781
782 ac_cv_define_READDIR_IS_THREAD_SAFE=no
783 ac_cv_define_GETHOSTBYNAME_IS_THREAD_SAFE=no
784 ac_cv_define_GETHOSTBYADDR_IS_THREAD_SAFE=no
785 ac_cv_define_GETSERVBYNAME_IS_THREAD_SAFE=no
786 if test "$threads" = "1"; then
787     echo "APR will use threads"
788     AC_CHECK_LIB(c_r, readdir,
789         AC_DEFINE(READDIR_IS_THREAD_SAFE, 1, 
790                   [Define if readdir is thread safe]))
791     if test "x$apr_gethostbyname_is_thread_safe" = "x"; then
792         AC_CHECK_LIB(c_r, gethostbyname, apr_gethostbyname_is_thread_safe=yes)
793     fi
794     if test "$apr_gethostbyname_is_thread_safe" = "yes"; then
795         AC_DEFINE(GETHOSTBYNAME_IS_THREAD_SAFE, 1,
796                   [Define if gethostbyname is thread safe])
797     fi
798     if test "x$apr_gethostbyaddr_is_thread_safe" = "x"; then
799         AC_CHECK_LIB(c_r, gethostbyaddr, apr_gethostbyaddr_is_thread_safe=yes)
800     fi
801     if test "$apr_gethostbyaddr_is_thread_safe" = "yes"; then
802         AC_DEFINE(GETHOSTBYADDR_IS_THREAD_SAFE, 1, 
803                   [Define if gethostbyaddr is thread safe])
804     fi
805     if test "x$apr_getservbyname_is_thread_safe" = "x"; then
806         AC_CHECK_LIB(c_r, getservbyname, apr_getservbyname_is_thread_safe=yes)
807     fi
808     if test "$apr_getservbyname_is_thread_safe" = "yes"; then
809         AC_DEFINE(GETSERVBYNAME_IS_THREAD_SAFE, 1, 
810                   [Define if getservbyname is thread safe])
811     fi
812     AC_CHECK_FUNCS(gethostbyname_r gethostbyaddr_r getservbyname_r)
813 else
814     echo "APR will be non-threaded"
815 fi
816
817 dnl Electric Fence malloc checker.
818 dnl --with-efence specifies the path to Electric Fence.
819 dnl This test should remain after the threads checks since libefence
820 dnl may depend on libpthread.
821 AC_ARG_WITH(efence, 
822   [  --with-efence[[=DIR]]     path to Electric Fence installation], 
823   [ apr_efence_dir="$withval"
824     if test "$apr_efence_dir" != "yes"; then
825       APR_ADDTO(LDFLAGS,[-L$apr_efence_dir/lib])
826       if test "x$apr_platform_runtime_link_flag" != "x"; then
827           APR_ADDTO(LDFLAGS, 
828                     [$apr_platform_runtime_link_flag$apr_efence_dir/lib])
829       fi
830     fi
831     AC_CHECK_LIB(efence, malloc, 
832                  [ APR_ADDTO(LIBS,-lefence) ],
833                  [ AC_MSG_ERROR(Electric Fence requested but not detected) ])
834   ])
835
836 AC_CHECK_FUNCS(sigsuspend, [ have_sigsuspend="1" ], [ have_sigsuspend="0" ])
837 AC_CHECK_FUNCS(sigwait, [ have_sigwait="1" ], [ have_sigwait="0" ]) 
838 dnl AC_CHECK_FUNCS doesn't work for this on Tru64 since the function
839 dnl is renamed in signal.h.  Todo: Autodetect
840 case $host in
841     *alpha*-dec-osf* )
842         have_sigwait="1"
843         ;;
844 esac
845
846 AC_SUBST(threads)
847 AC_SUBST(have_sigsuspend)
848 AC_SUBST(have_sigwait)
849
850 AC_CHECK_FUNCS(poll kqueue port_create)
851
852 # Check for the Linux epoll interface; epoll* may be available in libc
853 # but return ENOSYS on a pre-2.6 kernel, so do a run-time check.
854 AC_CACHE_CHECK([for epoll support], [apr_cv_epoll],
855 [AC_TRY_RUN([
856 #include <sys/epoll.h>
857 #include <unistd.h>
858
859 int main()
860 {
861     return epoll_create(5) == -1;
862 }], [apr_cv_epoll=yes], [apr_cv_epoll=no], [apr_cv_epoll=no])])
863
864 if test "$apr_cv_epoll" = "yes"; then
865    AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
866 fi
867
868 dnl ----------------------------- Checking for extended file descriptor handling
869 # test for epoll_create1
870 AC_CACHE_CHECK([for epoll_create1 support], [apr_cv_epoll_create1],
871 [AC_TRY_RUN([
872 #include <sys/epoll.h>
873 #include <unistd.h>
874
875 int main()
876 {
877     return epoll_create1(0) == -1;
878 }], [apr_cv_epoll_create1=yes], [apr_cv_epoll_create1=no], [apr_cv_epoll_create1=no])])
879
880 if test "$apr_cv_epoll_create1" = "yes"; then
881    AC_DEFINE([HAVE_EPOLL_CREATE1], 1, [Define if epoll_create1 function is supported])
882 fi
883
884 # test for dup3
885 AC_CACHE_CHECK([for dup3 support], [apr_cv_dup3],
886 [AC_TRY_RUN([
887 #include <unistd.h>
888
889 int main()
890 {
891     return dup3(STDOUT_FILENO, STDERR_FILENO, 0) == -1;
892 }], [apr_cv_dup3=yes], [apr_cv_dup3=no], [apr_cv_dup3=no])])
893
894 if test "$apr_cv_dup3" = "yes"; then
895    AC_DEFINE([HAVE_DUP3], 1, [Define if dup3 function is supported])
896 fi
897
898 # Test for accept4().  Create a non-blocking socket, bind it to
899 # an unspecified port & address (kernel picks), and attempt to
900 # call accept4() on it.  If the syscall is wired up (i.e. the
901 # kernel is new enough), it should return EAGAIN.
902 AC_CACHE_CHECK([for accept4 support], [apr_cv_accept4],
903 [AC_TRY_RUN([
904 #include <sys/types.h>
905 #include <sys/socket.h>
906 #include <sys/wait.h>
907 #include <netinet/in.h>
908 #include <netinet/tcp.h>
909 #include <errno.h>
910 #include <string.h>
911 #include <unistd.h>
912 #include <fcntl.h>
913
914 int main(int argc, char **argv)
915 {
916     int fd, flags;
917     struct sockaddr_in sin;
918
919     if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
920         return 1;
921     flags = fcntl(fd, F_GETFL);
922     if (flags == -1 || fcntl(fd, F_SETFL, flags|O_NONBLOCK) == -1)
923         return 5;
924
925     memset(&sin, 0, sizeof sin);
926     sin.sin_family = AF_INET;
927     
928     if (bind(fd, (struct sockaddr *) &sin, sizeof sin) == -1)
929         return 2;
930     
931     if (listen(fd, 5) == -1)
932         return 3;
933
934     if (accept4(fd, NULL, 0, SOCK_NONBLOCK) == 0
935         || errno == EAGAIN || errno == EWOULDBLOCK)
936         return 0;
937
938     return 4;
939 }], [apr_cv_accept4=yes], [apr_cv_accept4=no], [apr_cv_accept4=no])])
940
941 if test "$apr_cv_accept4" = "yes"; then
942    AC_DEFINE([HAVE_ACCEPT4], 1, [Define if accept4 function is supported])
943 fi
944
945 AC_CACHE_CHECK([for SOCK_CLOEXEC support], [apr_cv_sock_cloexec],
946 [AC_TRY_RUN([
947 #include <sys/types.h>
948 #include <sys/socket.h>
949
950 int main()
951 {
952     return socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0) == -1;
953 }], [apr_cv_sock_cloexec=yes], [apr_cv_sock_cloexec=no], [apr_cv_sock_cloexec=no])])
954
955 if test "$apr_cv_sock_cloexec" = "yes"; then
956    AC_DEFINE([HAVE_SOCK_CLOEXEC], 1, [Define if the SOCK_CLOEXEC flag is supported])
957 fi
958
959 dnl ----------------------------- Checking for fdatasync: OS X doesn't have it
960 AC_CHECK_FUNCS(fdatasync)
961
962 dnl ----------------------------- Checking for extended file descriptor handling
963 # test for epoll_create1
964 AC_CACHE_CHECK([for epoll_create1 support], [apr_cv_epoll_create1],
965 [AC_TRY_RUN([
966 #include <sys/epoll.h>
967 #include <unistd.h>
968
969 int main()
970 {
971     return epoll_create1(0) == -1;
972 }], [apr_cv_epoll_create1=yes], [apr_cv_epoll_create1=no], [apr_cv_epoll_create1=no])])
973
974 if test "$apr_cv_epoll_create1" = "yes"; then
975    AC_DEFINE([HAVE_EPOLL_CREATE1], 1, [Define if epoll_create1 function is supported])
976 fi
977
978 # Check for z/OS async i/o support.  
979 AC_CACHE_CHECK([for asio -> message queue support], [apr_cv_aio_msgq],
980 [AC_TRY_RUN([
981 #define _AIO_OS390
982 #include <aio.h>
983
984 int main()
985 {
986     struct aiocb a;
987
988     a.aio_notifytype = AIO_MSGQ;  /* use IPC message queue for notification */
989
990     return aio_cancel(2, NULL) == -1;
991 }], [apr_cv_aio_msgq=yes], [apr_cv_aio_msgq=no], [apr_cv_aio_msgq=no])])
992
993 if test "$apr_cv_aio_msgq" = "yes"; then
994    AC_DEFINE([HAVE_AIO_MSGQ], 1, [Define if async i/o supports message q's])
995 fi
996
997 # test for dup3
998 AC_CACHE_CHECK([for dup3 support], [apr_cv_dup3],
999 [AC_TRY_RUN([
1000 #include <unistd.h>
1001
1002 int main()
1003 {
1004     return dup3(STDOUT_FILENO, STDERR_FILENO, 0) == -1;
1005 }], [apr_cv_dup3=yes], [apr_cv_dup3=no], [apr_cv_dup3=no])])
1006
1007 if test "$apr_cv_dup3" = "yes"; then
1008    AC_DEFINE([HAVE_DUP3], 1, [Define if dup3 function is supported])
1009 fi
1010
1011 # test for accept4
1012 AC_CACHE_CHECK([for accept4 support], [apr_cv_accept4],
1013 [AC_TRY_RUN([
1014 #include <unistd.h>
1015 #include <sys/types.h>
1016 #include <sys/socket.h>
1017 #include <sys/un.h>
1018 #include <sys/wait.h>
1019 #include <signal.h>
1020 #include <errno.h>
1021
1022 #define A4_SOCK "./apr_accept4_test_socket"
1023
1024 int main()
1025 {
1026     pid_t pid;
1027     int fd;
1028     struct sockaddr_un loc, rem;
1029     socklen_t rem_sz;
1030
1031     if ((pid = fork())) {
1032         int status;
1033
1034         unlink(A4_SOCK);
1035
1036         if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
1037             goto cleanup_failure2;
1038
1039         loc.sun_family = AF_UNIX;
1040         strncpy(loc.sun_path, A4_SOCK, sizeof(loc.sun_path) - 1);
1041
1042         if (bind(fd, (struct sockaddr *) &loc,
1043                  sizeof(struct sockaddr_un)) == -1)
1044             goto cleanup_failure;
1045
1046         if (listen(fd, 5) == -1)
1047             goto cleanup_failure;
1048
1049         rem_sz = sizeof(struct sockaddr_un);
1050         if (accept4(fd, (struct sockaddr *) &rem, &rem_sz, 0) == -1) {
1051             goto cleanup_failure;
1052         }
1053         else {
1054             close(fd);
1055             waitpid(pid, &status, 0);
1056             unlink(A4_SOCK);
1057             return 0;
1058         }
1059
1060 cleanup_failure:
1061         close(fd);
1062 cleanup_failure2:
1063         kill(pid, SIGKILL);
1064         waitpid(pid, &status, 0);
1065         unlink(A4_SOCK);
1066         return 1;
1067     }
1068     else {
1069         if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
1070             return 1; /* this will be bad: we'll hang */
1071
1072         loc.sun_family = AF_UNIX;
1073         strncpy(loc.sun_path, A4_SOCK, sizeof(loc.sun_path) - 1);
1074
1075         while(connect(fd, (struct sockaddr *) &loc,
1076                       sizeof(struct sockaddr_un)) == -1 &&
1077               (errno==ENOENT || errno==ECONNREFUSED))
1078             ;
1079
1080         close(fd);
1081         return 0;
1082     }
1083 }], [apr_cv_accept4=yes], [apr_cv_accept4=no], [apr_cv_accept4=no])])
1084
1085 if test "$apr_cv_accept4" = "yes"; then
1086    AC_DEFINE([HAVE_ACCEPT4], 1, [Define if accept4 function is supported])
1087 fi
1088
1089 AC_CACHE_CHECK([for SOCK_CLOEXEC support], [apr_cv_sock_cloexec],
1090 [AC_TRY_RUN([
1091 #include <sys/types.h>
1092 #include <sys/socket.h>
1093
1094 int main()
1095 {
1096     return socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0) == -1;
1097 }], [apr_cv_sock_cloexec=yes], [apr_cv_sock_cloexec=no], [apr_cv_sock_cloexec=no])])
1098
1099 if test "$apr_cv_sock_cloexec" = "yes"; then
1100    AC_DEFINE([HAVE_SOCK_CLOEXEC], 1, [Define if the SOCK_CLOEXEC flag is supported])
1101 fi
1102
1103 dnl ----------------------------- Checking for missing POSIX thread functions
1104 AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
1105
1106 dnl ----------------------------- Checking for Shared Memory Support 
1107 echo "${nl}Checking for Shared Memory Support..."
1108
1109 # The real-time POSIX extensions (e.g. shm_*, sem_*) may only
1110 # be available if linking against librt.
1111 AC_SEARCH_LIBS(shm_open, rt)
1112
1113 case $host in
1114  *-sysv*)
1115    ac_includes_default="$ac_includes_default
1116 #if HAVE_SYS_MUTEX_H /* needed to define lock_t for sys/shm.h */
1117 # include <sys/mutex.h>
1118 #endif";;
1119 esac
1120
1121 AC_CHECK_HEADERS([sys/types.h sys/mman.h sys/ipc.h sys/mutex.h sys/shm.h sys/file.h kernel/OS.h os2.h windows.h])
1122 AC_CHECK_FUNCS([mmap munmap shm_open shm_unlink shmget shmat shmdt shmctl \
1123                 create_area])
1124
1125 APR_CHECK_DEFINE(MAP_ANON, sys/mman.h)
1126 AC_CHECK_FILE(/dev/zero)
1127
1128 # Not all systems can mmap /dev/zero (such as HP-UX).  Check for that.
1129 if test "$ac_cv_func_mmap" = "yes" &&
1130    test "$ac_cv_file__dev_zero" = "yes"; then
1131     AC_MSG_CHECKING(for mmap that can map /dev/zero)
1132     AC_TRY_RUN([
1133 #include <sys/types.h>
1134 #include <sys/stat.h>
1135 #include <fcntl.h>
1136 #ifdef HAVE_SYS_MMAN_H
1137 #include <sys/mman.h>
1138 #endif
1139     int main()
1140     {
1141         int fd;
1142         void *m;
1143         fd = open("/dev/zero", O_RDWR);
1144         if (fd < 0) {
1145             return 1;
1146         }
1147         m = mmap(0, sizeof(void*), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
1148         if (m == (void *)-1) {  /* aka MAP_FAILED */
1149             return 2;
1150         }
1151         if (munmap(m, sizeof(void*)) < 0) {
1152             return 3;
1153         }
1154         return 0;
1155     }], [], [ac_cv_file__dev_zero=no], [ac_cv_file__dev_zero=no])
1156
1157     AC_MSG_RESULT($ac_cv_file__dev_zero)
1158 fi
1159
1160 # Now we determine which one is our anonymous shmem preference.
1161 haveshmgetanon="0"
1162 havemmapzero="0"
1163 havemmapanon="0"
1164 APR_BEGIN_DECISION([anonymous shared memory allocation method])
1165 APR_IFALLYES(header:sys/ipc.h header:sys/shm.h header:sys/file.h dnl
1166              func:shmget func:shmat func:shmdt func:shmctl,
1167              [haveshmgetanon="1"
1168               APR_DECIDE(USE_SHMEM_SHMGET_ANON, [SysV IPC shmget()])])
1169 APR_IFALLYES(header:sys/mman.h func:mmap func:munmap file:/dev/zero,
1170              [havemmapzero="1"
1171               APR_DECIDE(USE_SHMEM_MMAP_ZERO, 
1172                   [SVR4-style mmap() on /dev/zero])])
1173 APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
1174              [havemmapanon="1"
1175               APR_DECIDE(USE_SHMEM_MMAP_ANON, 
1176                   [4.4BSD-style mmap() via MAP_ANON])])
1177 APR_IFALLYES(header:os2.h,
1178              [haveos2shm="1"
1179               APR_DECIDE(USE_SHMEM_OS2_ANON, [OS/2 DosAllocSharedMem()])])
1180 APR_IFALLYES(header:kernel/OS.h func:create_area,
1181              [havebeosshm="1"
1182               APR_DECIDE(USE_SHMEM_BEOS_ANON,
1183                          [BeOS areas])])
1184 APR_IFALLYES(header:windows.h func:CreateFileMapping,
1185              [havewin32shm="1"
1186               APR_DECIDE(USE_SHMEM_WIN32_ANON,
1187                          [Windows CreateFileMapping()])])
1188 case $host in
1189     *linux* ) 
1190         # Linux has problems with MM_SHMT_MMANON even though it reports
1191         # that it has it.
1192         # FIXME - find exact 2.3 version that MMANON was fixed in.  It is
1193         # confirmed fixed in 2.4 series.
1194         if test $os_pre24linux -eq 1; then
1195             AC_MSG_WARN([Disabling anon mmap() support for Linux pre-2.4])
1196             APR_DECISION_OVERRIDE(USE_SHMEM_MMAP_ZERO USE_SHMEM_SHMGET_ANON)
1197         fi
1198         ;;
1199     *hpux11* ) 
1200         APR_DECISION_OVERRIDE(USE_SHMEM_SHMGET_ANON)
1201         ;;
1202 esac
1203 APR_END_DECISION
1204 AC_DEFINE_UNQUOTED($ac_decision)
1205
1206 useshmgetanon="0"
1207 usemmapzero="0"
1208 usemmapanon="0"
1209
1210 case $ac_decision in
1211     USE_SHMEM_SHMGET_ANON )
1212         useshmgetanon="1"
1213         ;;
1214     USE_SHMEM_MMAP_ZERO )
1215         usemmapzero="1"
1216         ;;
1217     USE_SHMEM_MMAP_ANON )
1218         usemmapanon="1"
1219         ;;
1220 esac
1221
1222 AC_SUBST(useshmgetanon)
1223 AC_SUBST(usemmapzero)
1224 AC_SUBST(usemmapanon)
1225 AC_SUBST(haveshmgetanon)
1226 AC_SUBST(havemmapzero)
1227 AC_SUBST(havemmapanon)
1228
1229 # Now we determine which one is our name-based shmem preference.
1230 havemmaptmp="0"
1231 havemmapshm="0"
1232 haveshmget="0"
1233 havebeosarea="0"
1234 haveos2shm="0"
1235 havewin32shm="0"
1236 APR_BEGIN_DECISION([namebased memory allocation method])
1237 APR_IFALLYES(header:sys/mman.h func:mmap func:munmap,
1238              [havemmaptmp="1"
1239               APR_DECIDE(USE_SHMEM_MMAP_TMP, 
1240                   [Classical mmap() on temporary file])])
1241 APR_IFALLYES(header:sys/mman.h func:mmap func:munmap func:shm_open dnl
1242              func:shm_unlink,
1243              [havemmapshm="1"
1244               APR_DECIDE(USE_SHMEM_MMAP_SHM, 
1245                   [mmap() via POSIX.1 shm_open() on temporary file])])
1246 APR_IFALLYES(header:sys/ipc.h header:sys/shm.h header:sys/file.h dnl
1247              func:shmget func:shmat func:shmdt func:shmctl,
1248              [haveshmget="1"
1249               APR_DECIDE(USE_SHMEM_SHMGET, [SysV IPC shmget()])])
1250 APR_IFALLYES(header:kernel/OS.h func:create_area,
1251              [havebeosshm="1"
1252               APR_DECIDE(USE_SHMEM_BEOS, [BeOS areas])])
1253 APR_IFALLYES(header:os2.h,
1254              [haveos2shm="1"
1255               APR_DECIDE(USE_SHMEM_OS2, [OS/2 DosAllocSharedMem()])])
1256 APR_IFALLYES(header:windows.h,
1257              [havewin32shm="1"
1258               APR_DECIDE(USE_SHMEM_WIN32, [Windows shared memory])])
1259 AC_ARG_ENABLE(posix-shm,
1260 [  --enable-posix-shm      Use POSIX shared memory (shm_open) if available],
1261 [
1262 if test "$havemmapshm" = "1"; then
1263   APR_DECISION_OVERRIDE(USE_SHMEM_MMAP_SHM)
1264 fi
1265 ])
1266 case $host in
1267     *linux* ) 
1268         # Linux pre-2.4 had problems with MM_SHMT_MMANON even though
1269         # it reports that it has it.
1270         if test $os_pre24linux -eq 1; then
1271             APR_DECISION_OVERRIDE(USE_SHMEM_MMAP_TMP USE_SHMEM_MMAP_SHM dnl
1272                                   USE_SHMEM_SHMGET)
1273         fi
1274         ;;
1275 esac
1276 APR_END_DECISION
1277 AC_DEFINE_UNQUOTED($ac_decision)
1278
1279 usemmaptmp="0"
1280 usemmapshm="0"
1281 useshmget="0"
1282 usebeosarea="0"
1283 useos2shm="0"
1284 usewin32shm="0"
1285
1286 case $ac_decision in
1287     USE_SHMEM_MMAP_TMP )
1288         usemmaptmp="1"
1289         ;;
1290     USE_SHMEM_MMAP_SHM )
1291         usemmapshm="1"
1292         ;;
1293     USE_SHMEM_SHMGET )
1294         useshmget="1"
1295         ;;
1296     USE_SHMEM_BEOS )
1297         usebeosarea="1"
1298         ;;
1299     USE_SHMEM_OS2 )
1300         useos2shm="1"
1301         ;;
1302     USE_SHMEM_WIN32 )
1303         usewin32shm="1"
1304         ;;
1305 esac
1306
1307 # Do we have any shared memory support?
1308 if test "$usemmaptmp$usemmapshm$usemmapzero$useshmget$usemmapanon$usebeosarea$useos2shm$usewin32shm" = "00000000"; then
1309   sharedmem="0"
1310 else
1311   sharedmem="1"
1312 fi
1313
1314 AC_SUBST(usemmaptmp)
1315 AC_SUBST(usemmapshm)
1316 AC_SUBST(useshmget)
1317 AC_SUBST(usebeosarea)
1318 AC_SUBST(useos2shm)
1319 AC_SUBST(usewin32shm)
1320 AC_SUBST(havemmaptmp)
1321 AC_SUBST(havemmapshm)
1322 AC_SUBST(haveshmget)
1323 AC_SUBST(havebeosarea)
1324 AC_SUBST(haveos2shm)
1325 AC_SUBST(havewin32shm)
1326 AC_SUBST(sharedmem)
1327
1328 dnl ----------------------------- Checks for Any required Functions
1329 dnl Checks for library functions. (N.B. poll is further down)
1330
1331 AC_FUNC_ALLOCA
1332
1333 AC_CHECK_FUNCS([calloc setsid isinf isnan \
1334                 getenv putenv setenv unsetenv \
1335                 writev getifaddrs utime utimes])
1336 AC_CHECK_FUNCS(setrlimit, [ have_setrlimit="1" ], [ have_setrlimit="0" ]) 
1337 AC_CHECK_FUNCS(getrlimit, [ have_getrlimit="1" ], [ have_getrlimit="0" ]) 
1338 sendfile="0"
1339 AC_CHECK_LIB(sendfile, sendfilev)
1340 AC_CHECK_FUNCS(sendfile send_file sendfilev, [ sendfile="1" ])
1341
1342 dnl THIS MUST COME AFTER THE THREAD TESTS - FreeBSD doesn't always have a
1343 dnl threaded poll() and we don't want to use sendfile on early FreeBSD 
1344 dnl systems if we are also using threads.
1345
1346 AC_ARG_WITH(sendfile, [  --with-sendfile         Override decision to use sendfile],
1347   [ if test "$withval" = "yes"; then
1348         sendfile="1"
1349     else
1350         sendfile="0"
1351     fi ], [
1352     orig_sendfile=$sendfile
1353     case $host in
1354         *freebsd*)
1355             # FreeBSD < 4.2 has issues with threads+sendfile
1356             if test $os_version -le "401999"; then
1357                 if test "$threads" = "1"; then
1358                     sendfile="0"
1359                 fi
1360             fi
1361             ;;
1362         *alpha*-dec-osf* )
1363             sendfile="0"
1364             ;;
1365         s390-*-linux-gnu)
1366             # disable sendfile support for 2.2 on S/390
1367             if test $os_pre24linux -eq 1; then
1368                 AC_MSG_WARN([Disabled sendfile support for Linux 2.2 on S/390])
1369                 sendfile="0"
1370             fi
1371             ;;
1372         *aix*)
1373             # compiler-independent check for 64-bit build
1374             AC_CHECK_SIZEOF(void*, 4)
1375             if test "x$ac_cv_sizeof_voidp" = "x8"; then
1376                 # sendfile not working for 64-bit build
1377                 sendfile="0"
1378             fi
1379             ;;
1380     esac       
1381     if test "$orig_sendfile" != "$sendfile"; then
1382       echo "sendfile support disabled to avoid system problem"
1383     fi ] )
1384 AC_SUBST(sendfile)
1385
1386 AC_CHECK_FUNCS(sigaction, [ have_sigaction="1" ], [ have_sigaction="0" ]) 
1387 AC_DECL_SYS_SIGLIST
1388
1389 AC_CHECK_FUNCS(fork, [ fork="1" ], [ fork="0" ])
1390 APR_CHECK_INET_ADDR
1391 APR_CHECK_INET_NETWORK
1392 AC_SUBST(apr_inaddr_none)
1393 AC_CHECK_FUNC(_getch)
1394 AC_CHECK_FUNCS(strerror_r, [ strerror_r="1" ], [ strerror_r="0" ])
1395 if test "$strerror_r" = "1"; then
1396   APR_CHECK_STRERROR_R_RC
1397 fi
1398 AC_CHECK_FUNCS(mmap, [ mmap="1" ], [ mmap="0" ])
1399 if test "$native_mmap_emul" = "1"; then
1400     mmap="1"
1401 fi
1402 AC_CHECK_FUNCS(memmove, [ have_memmove="1" ], [have_memmove="0" ])
1403 AC_CHECK_FUNCS([getpass getpassphrase gmtime_r localtime_r mkstemp])
1404
1405 AC_SUBST(fork)
1406 AC_SUBST(have_inet_addr)
1407 AC_SUBST(tcp_nodelay_inherited)
1408 AC_SUBST(o_nonblock_inherited)
1409 AC_SUBST(have_inet_network)
1410 AC_SUBST(have_sigaction)
1411 AC_SUBST(have_setrlimit)
1412 AC_SUBST(have_getrlimit)
1413 AC_SUBST(mmap)
1414 AC_SUBST(have_memmove)
1415
1416 APR_CHECK_SIGWAIT_ONE_ARG
1417
1418 dnl ----------------------------- Checks for Any required Headers
1419 AC_HEADER_STDC
1420
1421 APR_FLAG_HEADERS(
1422     ByteOrder.h         \
1423     conio.h             \
1424     crypt.h             \
1425     ctype.h             \
1426     dir.h               \
1427     dirent.h            \
1428     dl.h                \
1429     dlfcn.h             \
1430     errno.h             \
1431     fcntl.h             \
1432     grp.h               \
1433     io.h                \
1434     limits.h            \
1435     mach-o/dyld.h       \
1436     malloc.h            \
1437     memory.h            \
1438     netdb.h             \
1439     osreldate.h         \
1440     poll.h              \
1441     process.h           \
1442     pwd.h               \
1443     semaphore.h         \
1444     signal.h            \
1445     stdarg.h            \
1446     stddef.h            \
1447     stdio.h             \
1448     stdlib.h            \
1449     string.h            \
1450     strings.h           \
1451     sysapi.h            \
1452     sysgtime.h          \
1453     termios.h           \
1454     time.h              \
1455     tpfeq.h             \
1456     tpfio.h             \
1457     unistd.h            \
1458     unix.h              \
1459     windows.h           \
1460     winsock2.h          \
1461     arpa/inet.h         \
1462     kernel/OS.h         \
1463     net/errno.h         \
1464     netinet/in.h        \
1465     netinet/sctp.h      \
1466     netinet/sctp_uio.h  \
1467     sys/file.h          \
1468     sys/ioctl.h         \
1469     sys/mman.h          \
1470     sys/param.h         \
1471     sys/poll.h          \
1472     sys/resource.h      \
1473     sys/select.h        \
1474     sys/sem.h           \
1475     sys/sendfile.h      \
1476     sys/signal.h        \
1477     sys/socket.h        \
1478     sys/sockio.h        \
1479     sys/stat.h          \
1480     sys/sysctl.h        \
1481     sys/syslimits.h     \
1482     sys/time.h          \
1483     sys/types.h         \
1484     sys/uio.h           \
1485     sys/un.h            \
1486     sys/wait.h)
1487
1488 # IRIX 6.5 has a problem in <netinet/tcp.h> which prevents it from
1489 # being included by itself.  Check for <netinet/tcp.h> manually,
1490 # including another header file first.
1491 AC_CACHE_CHECK([for netinet/tcp.h], [apr_cv_hdr_netinet_tcp_h],
1492 [AC_TRY_CPP(
1493 [#ifdef HAVE_NETINET_IN_H
1494 #include <netinet/in.h>
1495 #endif
1496 #include <netinet/tcp.h>
1497 ], [apr_cv_hdr_netinet_tcp_h=yes], [apr_cv_hdr_netinet_tcp_h=no])])
1498 if test "$apr_cv_hdr_netinet_tcp_h" = "yes"; then
1499    netinet_tcph=1
1500    AC_DEFINE([HAVE_NETINET_TCP_H], 1, [Defined if netinet/tcp.h is present])
1501 else
1502    netinet_tcph=0
1503 fi
1504
1505 AC_SUBST(arpa_ineth)
1506 AC_SUBST(conioh)
1507 AC_SUBST(ctypeh)
1508 AC_SUBST(crypth)
1509 AC_SUBST(errnoh)
1510 AC_SUBST(direnth)
1511 AC_SUBST(fcntlh)
1512 AC_SUBST(ioh)
1513 AC_SUBST(limitsh)
1514 AC_SUBST(netdbh)
1515 AC_SUBST(sys_syslimitsh)
1516 AC_SUBST(netinet_inh)
1517 AC_SUBST(netinet_sctph)
1518 AC_SUBST(netinet_sctp_uioh)
1519 AC_SUBST(netinet_tcph)
1520 AC_SUBST(stdargh)
1521 AC_SUBST(stdioh)
1522 AC_SUBST(stdlibh)
1523 AC_SUBST(stringh)
1524 AC_SUBST(stringsh)
1525 AC_SUBST(sys_ioctlh)
1526 AC_SUBST(sys_sendfileh)
1527 AC_SUBST(sys_signalh)
1528 AC_SUBST(sys_socketh)
1529 AC_SUBST(sys_sockioh)
1530 AC_SUBST(sys_typesh)
1531 AC_SUBST(sys_timeh)
1532 AC_SUBST(sys_uioh)
1533 AC_SUBST(sys_unh)
1534 AC_SUBST(timeh)
1535 AC_SUBST(unistdh)
1536 AC_SUBST(signalh)
1537 AC_SUBST(sys_waith)
1538 AC_SUBST(processh)
1539 AC_SUBST(pthreadh)
1540 AC_SUBST(semaphoreh)
1541 AC_SUBST(windowsh)
1542 AC_SUBST(winsock2h)
1543
1544 # Checking for h_errno in <netdb.h>
1545 if test "$netdbh" = "1"; then
1546   APR_CHECK_H_ERRNO_FLAG
1547   if test "$ac_cv_h_errno_cflags" = "no"; then
1548     AC_MSG_ERROR([can not find h_errno in netdb.h])
1549   fi
1550 fi
1551
1552 AC_ARG_ENABLE(allocator-uses-mmap,
1553   [  --enable-allocator-uses-mmap    Use mmap in apr_allocator instead of malloc ],
1554   [ if test "$enableval" = "yes"; then
1555         APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
1556                      [AC_DEFINE(APR_ALLOCATOR_USES_MMAP, 1,
1557                                 [Define if apr_allocator should use mmap]) ],
1558                      [AC_MSG_ERROR([mmap()/MAP_ANON not supported]) ]
1559                     )
1560     fi ]
1561 )
1562
1563 dnl ----------------------------- Checks for standard typedefs
1564 AC_TYPE_OFF_T
1565 AC_TYPE_PID_T
1566 AC_TYPE_SIZE_T
1567 AC_TYPE_UID_T
1568 AC_CHECK_TYPE(ssize_t, int)
1569 AC_C_INLINE
1570 AC_C_CONST
1571 AC_FUNC_SETPGRP
1572
1573 APR_CHECK_SOCKLEN_T
1574
1575 dnl Checks for pointer size
1576 AC_CHECK_SIZEOF(void*, 4)
1577
1578 if test "x$ac_cv_sizeof_voidp" != "x"; then
1579     voidp_size=$ac_cv_sizeof_voidp
1580 else
1581     AC_ERROR([Cannot determine size of void*])
1582 fi
1583
1584 dnl Checks for integer size
1585 AC_CHECK_SIZEOF(char, 1)
1586 AC_CHECK_SIZEOF(int, 4)
1587 AC_CHECK_SIZEOF(long, 4)
1588 AC_CHECK_SIZEOF(short, 2)
1589 AC_CHECK_SIZEOF(long long, 8)
1590
1591 if test "$ac_cv_sizeof_short" = "2"; then
1592     short_value=short
1593 fi
1594 if test "$ac_cv_sizeof_int" = "4"; then
1595     int_value=int
1596 fi
1597 # Now we need to find what apr_int64_t (sizeof == 8) will be.
1598 # The first match is our preference.
1599 if test "$ac_cv_sizeof_int" = "8"; then
1600     int64_literal='#define APR_INT64_C(val) (val)'
1601     uint64_literal='#define APR_UINT64_C(val) (val##U)'
1602     int64_t_fmt='#define APR_INT64_T_FMT "d"'
1603     uint64_t_fmt='#define APR_UINT64_T_FMT "u"'
1604     uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "x"'
1605     int64_value="int"
1606     long_value=int
1607     int64_strfn="strtoi"
1608 elif test "$ac_cv_sizeof_long" = "8"; then
1609     int64_literal='#define APR_INT64_C(val) (val##L)'
1610     uint64_literal='#define APR_UINT64_C(val) (val##UL)'
1611     int64_t_fmt='#define APR_INT64_T_FMT "ld"'
1612     uint64_t_fmt='#define APR_UINT64_T_FMT "lu"'
1613     uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "lx"'
1614     int64_value="long"
1615     long_value=long
1616     int64_strfn="strtol"
1617 elif test "$ac_cv_sizeof_long_long" = "8"; then
1618     int64_literal='#define APR_INT64_C(val) (val##LL)'
1619     uint64_literal='#define APR_UINT64_C(val) (val##ULL)'
1620     # Linux, Solaris, FreeBSD all support ll with printf.
1621     # BSD 4.4 originated 'q'.  Solaris is more popular and 
1622     # doesn't support 'q'.  Solaris wins.  Exceptions can
1623     # go to the OS-dependent section.
1624     int64_t_fmt='#define APR_INT64_T_FMT "lld"'
1625     uint64_t_fmt='#define APR_UINT64_T_FMT "llu"'
1626     uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "llx"'
1627     int64_value="long long"
1628     long_value="long long"
1629     int64_strfn="strtoll"
1630 elif test "$ac_cv_sizeof_longlong" = "8"; then
1631     int64_literal='#define APR_INT64_C(val) (val##LL)'
1632     uint64_literal='#define APR_UINT64_C(val) (val##ULL)'
1633     int64_t_fmt='#define APR_INT64_T_FMT "qd"'
1634     uint64_t_fmt='#define APR_UINT64_T_FMT "qu"'
1635     uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "qx"'
1636     int64_value="__int64"
1637     long_value="__int64"
1638     int64_strfn="strtoll"
1639 else
1640     # int64_literal may be overriden if your compiler thinks you have
1641     # a 64-bit value but APR does not agree.
1642     AC_ERROR([could not detect a 64-bit integer type])
1643 fi
1644
1645 # If present, allow the C99 macro INT64_C to override our conversion.
1646 #
1647 # HP-UX's ANSI C compiler provides this without any includes, so we
1648 # will first look for INT64_C without adding stdint.h
1649 AC_CACHE_CHECK([for INT64_C], [apr_cv_define_INT64_C], [
1650 AC_EGREP_CPP(YES_IS_DEFINED,
1651 [#ifdef INT64_C
1652 YES_IS_DEFINED
1653 #endif], [apr_cv_define_INT64_C=yes], [
1654     # Now check for INT64_C in stdint.h
1655     AC_EGREP_CPP(YES_IS_DEFINED, [#include <stdint.h>
1656 #ifdef INT64_C
1657 YES_IS_DEFINED
1658 #endif], [apr_cv_define_INT64_C=yes], [apr_cv_define_INT64_C=no])])])
1659
1660 if test "$apr_cv_define_INT64_C" = "yes"; then
1661     int64_literal='#define APR_INT64_C(val) INT64_C(val)'
1662     uint64_literal='#define APR_UINT64_C(val) UINT64_C(val)'
1663     stdint=1
1664 else
1665     stdint=0
1666 fi
1667
1668 if test "$ac_cv_type_size_t" = "yes"; then
1669     size_t_value="size_t"
1670 else
1671     size_t_value="apr_int32_t"
1672 fi
1673 if test "$ac_cv_type_ssize_t" = "yes"; then
1674     ssize_t_value="ssize_t"
1675 else
1676     ssize_t_value="apr_int32_t"
1677 fi
1678 if test "$ac_cv_socklen_t" = "yes"; then
1679     socklen_t_value="socklen_t"
1680     case $host in
1681         *-hp-hpux*)
1682             if test "$ac_cv_sizeof_long" = "8"; then
1683                 # 64-bit HP-UX requires 32-bit socklens in
1684                 # kernel, but user-space declarations say
1685                 # 64-bit (socklen_t == size_t == long).
1686                 # This will result in many compile warnings,
1687                 # but we're functionally busted otherwise.
1688                 socklen_t_value="int"
1689             fi
1690             ;;
1691     esac
1692 else
1693     socklen_t_value="int"
1694 fi
1695
1696 APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], pid_t, 8)
1697
1698 if test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_short"; then
1699     pid_t_fmt='#define APR_PID_T_FMT "hd"'
1700 elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_int"; then
1701     pid_t_fmt='#define APR_PID_T_FMT "d"'
1702 elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_long"; then
1703     pid_t_fmt='#define APR_PID_T_FMT "ld"'
1704 elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_long_long"; then
1705     pid_t_fmt='#define APR_PID_T_FMT APR_INT64_T_FMT'
1706 else
1707     pid_t_fmt='#error Can not determine the proper size for pid_t'
1708 fi
1709
1710 # Basically, we have tried to figure out the correct format strings
1711 # for APR types which vary between platforms, but we don't always get
1712 # it right.
1713 case $host in
1714    s390*linux*)
1715        # uniquely, the 31-bit Linux/s390 uses "unsigned long int"
1716        # for size_t rather than "unsigned int":
1717        size_t_fmt="lu"
1718        ssize_t_fmt="ld"
1719        ;;
1720    *-os2*)
1721        size_t_fmt="lu"
1722        ;;
1723    *-solaris*)
1724        if test "$ac_cv_sizeof_long" = "8"; then
1725          pid_t_fmt='#define APR_PID_T_FMT "d"'
1726        else
1727          pid_t_fmt='#define APR_PID_T_FMT "ld"'
1728        fi
1729        ;;
1730    *aix4*|*aix5*)
1731        ssize_t_fmt="ld"
1732        size_t_fmt="lu"
1733        ;;
1734     *beos*)
1735         ssize_t_fmt="ld"
1736         size_t_fmt="ld"
1737         ;;
1738     *apple-darwin*)
1739         osver=`uname -r`
1740         case $osver in
1741            [[0-7]].*)
1742               ssize_t_fmt="d"
1743               ;;
1744            *)
1745               ssize_t_fmt="ld"
1746               ;;
1747         esac
1748         size_t_fmt="lu"
1749         ;;
1750     *-mingw*)
1751         int64_t_fmt='#define APR_INT64_T_FMT "I64d"'
1752         uint64_t_fmt='#define APR_UINT64_T_FMT "I64u"'
1753         uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "I64x"'
1754         int64_value="__int64"
1755         long_value="__int64"
1756         int64_strfn="_strtoi64"
1757         ;; 
1758 esac
1759
1760 APR_CHECK_TYPES_COMPATIBLE(ssize_t, int, [ssize_t_fmt="d"])
1761 APR_CHECK_TYPES_COMPATIBLE(ssize_t, long, [ssize_t_fmt="ld"])
1762 APR_CHECK_TYPES_COMPATIBLE(size_t, unsigned int, [size_t_fmt="u"])
1763 APR_CHECK_TYPES_COMPATIBLE(size_t, unsigned long, [size_t_fmt="lu"])
1764
1765 APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], ssize_t, 8)
1766
1767 AC_MSG_CHECKING([which format to use for apr_ssize_t])
1768 if test -n "$ssize_t_fmt"; then
1769     AC_MSG_RESULT(%$ssize_t_fmt)
1770 elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then
1771     ssize_t_fmt="d"
1772     AC_MSG_RESULT(%d)
1773 elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long"; then
1774     ssize_t_fmt="ld"
1775     AC_MSG_RESULT(%ld)
1776 else
1777     AC_ERROR([could not determine the proper format for apr_ssize_t])
1778 fi
1779
1780 ssize_t_fmt="#define APR_SSIZE_T_FMT \"$ssize_t_fmt\""
1781
1782 APR_CHECK_SIZEOF_EXTENDED([#include <stddef.h>], size_t, 8)
1783
1784 AC_MSG_CHECKING([which format to use for apr_size_t])
1785 if test -n "$size_t_fmt"; then
1786     AC_MSG_RESULT(%$size_t_fmt)
1787 elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then
1788     size_t_fmt="d"
1789     AC_MSG_RESULT(%d)
1790 elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long"; then
1791     size_t_fmt="ld"
1792     AC_MSG_RESULT(%ld)
1793 else
1794     AC_ERROR([could not determine the proper format for apr_size_t])
1795 fi
1796
1797 size_t_fmt="#define APR_SIZE_T_FMT \"$size_t_fmt\""
1798
1799 APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], off_t, 8)
1800
1801 if test "${ac_cv_sizeof_off_t}${apr_cv_use_lfs64}" = "4yes"; then
1802     # Enable LFS
1803     aprlfs=1
1804     AC_CHECK_FUNCS([mmap64 sendfile64 sendfilev64 mkstemp64 readdir64_r])
1805 elif test "${ac_cv_sizeof_off_t}" != "${ac_cv_sizeof_size_t}"; then
1806     # unsure of using -gt above is as portable, can can't forsee where
1807     # off_t can legitimately be smaller than size_t
1808     aprlfs=1
1809 else
1810     aprlfs=0     
1811 fi
1812
1813 AC_MSG_CHECKING([which type to use for apr_off_t])
1814 if test "${ac_cv_sizeof_off_t}${apr_cv_use_lfs64}" = "4yes"; then
1815     # LFS is go!
1816     off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
1817     off_t_value='off64_t'
1818     off_t_strfn='apr_strtoi64'
1819 elif test "${ac_cv_sizeof_off_t}x${ac_cv_sizeof_long}" = "4x4"; then
1820     # Special case: off_t may change size with _FILE_OFFSET_BITS
1821     # on 32-bit systems with LFS support.  To avoid compatibility
1822     # issues when other packages do define _FILE_OFFSET_BITS,
1823     # hard-code apr_off_t to long.
1824     off_t_value=long
1825     off_t_fmt='#define APR_OFF_T_FMT "ld"'
1826     off_t_strfn='strtol'
1827 elif test "$ac_cv_type_off_t" = "yes"; then
1828     off_t_value=off_t
1829     # off_t is more commonly a long than an int; prefer that case
1830     # where int and long are the same size.
1831     if test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_long"; then
1832         off_t_fmt='#define APR_OFF_T_FMT "ld"'
1833         off_t_strfn='strtol'
1834     elif test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_int"; then
1835         off_t_fmt='#define APR_OFF_T_FMT "d"'
1836         off_t_strfn='strtoi'
1837     elif test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_long_long"; then
1838         off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
1839         off_t_strfn='apr_strtoi64'
1840     else
1841         AC_ERROR([could not determine the size of off_t])
1842     fi
1843     # Per OS tuning...
1844     case $host in
1845     *-mingw*)
1846         off_t_value=apr_int64_t
1847         off_t_fmt='#define APR_OFF_T_FMT "I64d"'
1848         off_t_strfn='_strtoi64'
1849         ;;
1850     esac
1851 else
1852    # Fallback on int
1853    off_t_value=apr_int32_t
1854    off_t_fmt=d
1855    off_t_strfn='strtoi'
1856 fi
1857 AC_MSG_RESULT($off_t_value)
1858
1859 # Regardless of whether _LARGEFILE64_SOURCE is used, on some
1860 # platforms _FILE_OFFSET_BITS will affect the size of ino_t and hence
1861 # the build-time ABI may be different from the apparent ABI when using
1862 # APR with another package which *does* define _FILE_OFFSET_BITS.
1863 # (Exactly as per the case above with off_t where LFS is *not* used)
1864 #
1865 # To be safe, hard-code apr_ino_t as 'unsigned long' or 'unsigned int'
1866 # iff that is exactly the size of ino_t here; otherwise use ino_t as existing
1867 # releases did.  To be correct, apr_ino_t should have been made an
1868 # ino64_t as apr_off_t is off64_t, but this can't be done now without
1869 # breaking ABI.
1870
1871 # Per OS tuning...
1872 case $host in
1873 *mingw*)
1874     ino_t_value=apr_int64_t
1875     ;;
1876 *)
1877     ino_t_value=ino_t
1878     APR_CHECK_SIZEOF_EXTENDED(AC_INCLUDES_DEFAULT, ino_t, $ac_cv_sizeof_long)
1879     if test $ac_cv_sizeof_ino_t = 4; then
1880         if test $ac_cv_sizeof_long = 4; then
1881             ino_t_value="unsigned long"
1882         else
1883             ino_t_value="unsigned int"
1884         fi
1885     fi
1886     ;;
1887 esac
1888 AC_MSG_NOTICE([using $ino_t_value for ino_t])
1889
1890 # Checks for endianness
1891 AC_C_BIGENDIAN
1892 if test $ac_cv_c_bigendian = yes; then
1893     bigendian=1
1894 else
1895     bigendian=0
1896 fi
1897
1898 APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>
1899 #include <sys/uio.h>],struct iovec,0)
1900 if test "$ac_cv_sizeof_struct_iovec" = "0"; then
1901     have_iovec=0
1902 else
1903     have_iovec=1
1904 fi
1905
1906 AC_SUBST(voidp_size)
1907 AC_SUBST(short_value)
1908 AC_SUBST(int_value)
1909 AC_SUBST(long_value)
1910 AC_SUBST(int64_value)
1911 AC_SUBST(off_t_value)
1912 AC_SUBST(size_t_value)
1913 AC_SUBST(ssize_t_value)
1914 AC_SUBST(socklen_t_value)
1915 AC_SUBST(int64_t_fmt) 
1916 AC_SUBST(uint64_t_fmt) 
1917 AC_SUBST(uint64_t_hex_fmt) 
1918 AC_SUBST(ssize_t_fmt) 
1919 AC_SUBST(size_t_fmt)
1920 AC_SUBST(off_t_fmt) 
1921 AC_SUBST(pid_t_fmt)
1922 AC_SUBST(int64_literal) 
1923 AC_SUBST(uint64_literal) 
1924 AC_SUBST(stdint) 
1925 AC_SUBST(bigendian)
1926 AC_SUBST(aprlfs)
1927 AC_SUBST(have_iovec)
1928 AC_SUBST(ino_t_value)
1929
1930 dnl ----------------------------- Checking for string functions
1931 AC_CHECK_FUNCS(strnicmp, have_strnicmp="1", have_strnicmp="0")
1932 AC_CHECK_FUNCS(strncasecmp, have_strncasecmp="1", have_strncasecmp="0")
1933 AC_CHECK_FUNCS(stricmp, have_stricmp="1", have_stricmp="0")
1934 AC_CHECK_FUNCS(strcasecmp, have_strcasecmp="1", have_strcasecmp="0")
1935 AC_CHECK_FUNCS(strdup, have_strdup="1", have_strdup="0")
1936 AC_CHECK_FUNCS(strstr, have_strstr="1", have_strstr="0")
1937 AC_CHECK_FUNCS(memchr, have_memchr="1", have_memchr="0")
1938 AC_CHECK_FUNC($int64_strfn, have_int64_strfn="1", have_int64_strfn="0")
1939
1940 dnl ----------------------------- We have a fallback position
1941 if test "$have_int64_strfn" = "0" && test "$int64_strfn" = "strtoll"; then
1942     int64_strfn="strtoq"
1943     AC_CHECK_FUNC(strtoq, [have_int64_strfn=1], [have_int64_strfn=0])
1944 fi
1945
1946 if test "$have_int64_strfn" = "1"; then
1947   AC_DEFINE_UNQUOTED(APR_INT64_STRFN, [$int64_strfn],
1948       [Define as function which can be used for conversion of strings to apr_int64_t])
1949 fi
1950
1951 AC_SUBST(have_strnicmp)
1952 AC_SUBST(have_strncasecmp)
1953 AC_SUBST(have_stricmp)
1954 AC_SUBST(have_strcasecmp)
1955 AC_SUBST(have_strdup)
1956 AC_SUBST(have_strstr)
1957 AC_SUBST(have_memchr)
1958
1959 if test "$off_t_strfn" = "apr_strtoi64" && test "$have_int64_strfn" = "1"; then
1960     off_t_strfn=$int64_strfn
1961 fi
1962 AC_DEFINE_UNQUOTED(APR_OFF_T_STRFN, [$off_t_strfn],
1963           [Define as function used for conversion of strings to apr_off_t])
1964
1965 dnl ----------------------------- Checking for DSO support
1966 echo "${nl}Checking for DSO..."
1967 AC_ARG_ENABLE(dso,
1968   [  --disable-dso           Disable DSO support ],
1969   [if test "x$enableval" = "xyes"; then
1970       dsotype=any
1971    else
1972       dsotype=$enableval
1973    fi
1974   ], [dsotype=any])
1975
1976 if test "$dsotype" = "any"; then
1977     if test "$dsotype" = "any"; then
1978       case $host in
1979         *darwin[[0-8]]\.*) 
1980           # Original Darwin, not for 9.0!:
1981           AC_CHECK_FUNC(NSLinkModule, [dsotype=dyld]);;
1982         hppa*-hpux[[1-9]]\.*|hppa*-hpux1[[01]]*)
1983           # shl is specific to parisc hpux SOM binaries, not used for 64 bit
1984           AC_CHECK_LIB(dld, shl_load, [have_shl=1])
1985           if test "$ac_cv_sizeof_voidp$have_shl" = "41"; then
1986             dsotype=shl; APR_ADDTO(LIBS,-ldld)
1987           fi;;
1988         *mingw*|*-os2*)
1989           # several 'other's below probably belong up here.  If they always
1990           # use a platform implementation and shouldn't test the dlopen/dlfcn
1991           # features, then bring them up here.
1992           # But if they -should- optionally use dlfcn, and/or need the config
1993           # detection of dlopen/dlsym, do not move them up.
1994           dsotype=other ;;
1995       esac
1996     fi
1997     # Normal POSIX:
1998     if test "$dsotype" = "any"; then
1999       AC_CHECK_FUNC(dlopen, [dsotype=dlfcn])
2000     fi
2001     if test "$dsotype" = "any"; then
2002       AC_CHECK_LIB(dl, dlopen, [dsotype=dlfcn; APR_ADDTO(LIBS,-ldl)])
2003     fi
2004     if test "$dsotype" = "dlfcn"; then
2005         # ReliantUnix has dlopen() in libc but dlsym() in libdl :(
2006         AC_CHECK_FUNC(dlsym, [], 
2007           [AC_CHECK_LIB(dl, dlsym, 
2008              [APR_ADDTO(LIBS, -ldl)],
2009              [dsotype=any
2010               echo "Weird: dlopen() was found but dlsym() was not found!"])])
2011     fi
2012     if test "$dsotype" = "any"; then
2013       # BeOS:
2014       AC_CHECK_LIB(root, load_image, [dsotype=other])
2015     fi
2016     # Everything else:
2017     if test "$dsotype" = "any"; then
2018         case $host in
2019         *os390|*os400|*-aix*)
2020           # Some -aix5 will use dl, no hassles.  Keep that pattern here.
2021           dsotype=other ;;
2022         *-hpux*)
2023           if test "$have_shl" = "1"; then
2024             dsotype=shl; APR_ADDTO(LIBS,-ldld)
2025           fi;;
2026         esac
2027     fi
2028 fi
2029
2030 if test "$dsotype" = "any"; then
2031     AC_MSG_ERROR([Could not detect suitable DSO implementation])
2032 elif test "$dsotype" = "no"; then
2033     aprdso="0"
2034 else
2035     case "$dsotype" in
2036     dlfcn) AC_DEFINE(DSO_USE_DLFCN, 1, [Define if DSO support uses dlfcn.h]);;
2037     shl)   AC_DEFINE(DSO_USE_SHL, 1, [Define if DSO support uses shl_load]);;
2038     dyld)  AC_DEFINE(DSO_USE_DYLD, 1, [Define if DSO support uses dyld.h]);;
2039     other) ;; # Use whatever is in dso/OSDIR
2040     *) AC_MSG_ERROR([Unknown DSO implementation "$dsotype"]);;
2041     esac
2042     aprdso="1"
2043     apr_modules="$apr_modules dso"
2044 fi
2045
2046 AC_SUBST(aprdso)
2047
2048 dnl ----------------------------- Checking for Processes
2049 echo "${nl}Checking for Processes..."
2050
2051 AC_CHECK_FUNCS(waitpid)
2052
2053 AC_ARG_ENABLE(other-child,
2054   [  --enable-other-child    Enable reliable child processes ],
2055   [ if test "$enableval" = "yes"; then
2056         oc="1"
2057     else
2058         oc="0"
2059     fi ],
2060   [ oc=1 ] ) 
2061   
2062 AC_SUBST(oc) 
2063
2064 if test -z "$have_proc_invoked"; then
2065   have_proc_invoked="0"
2066 fi
2067
2068 AC_SUBST(have_proc_invoked)
2069
2070 AC_MSG_CHECKING(for Variable Length Arrays)
2071 APR_TRY_COMPILE_NO_WARNING([],
2072 [
2073     int foo[argc];
2074     foo[0] = 0;
2075 ], vla_msg=yes, vla_msg=no )
2076 AC_MSG_RESULT([$vla_msg])
2077 if test "$vla_msg" = "yes"; then
2078     AC_DEFINE(HAVE_VLA, 1, [Define if C compiler supports VLA])
2079 fi
2080
2081 AC_CACHE_CHECK(struct rlimit,ac_cv_struct_rlimit,[
2082 AC_TRY_RUN([
2083 #include <sys/types.h>
2084 #include <sys/time.h>
2085 #include <sys/resource.h>
2086 main()
2087 {
2088     struct rlimit limit;
2089     limit.rlim_cur = 0;
2090     limit.rlim_max = 0;
2091     exit(0);
2092 }], [
2093     ac_cv_struct_rlimit=yes ], [
2094     ac_cv_struct_rlimit=no ], [
2095     ac_cv_struct_rlimit=no ] ) ] )
2096 struct_rlimit=0
2097 test "x$ac_cv_struct_rlimit" = xyes && struct_rlimit=1
2098 AC_SUBST(struct_rlimit)
2099
2100 dnl ----------------------------- Checking for Locking Characteristics 
2101 echo "${nl}Checking for Locking..."
2102
2103 AC_CHECK_FUNCS(semget semctl flock)
2104 AC_CHECK_HEADERS(semaphore.h OS.h)
2105 AC_SEARCH_LIBS(sem_open, rt)
2106 AC_CHECK_FUNCS(sem_close sem_unlink sem_post sem_wait create_sem)
2107
2108 # Some systems return ENOSYS from sem_open.
2109 AC_CACHE_CHECK(for working sem_open,ac_cv_func_sem_open,[
2110 AC_TRY_RUN([
2111 #include <errno.h>
2112 #include <stdlib.h>
2113 #include <fcntl.h>
2114 #include <semaphore.h>
2115 #ifndef SEM_FAILED
2116 #define SEM_FAILED (-1)
2117 #endif
2118 main()
2119 {
2120     sem_t *psem;
2121     const char *sem_name = "/apr_autoconf";
2122
2123     psem = sem_open(sem_name, O_CREAT, 0644, 1);
2124     if (psem == (sem_t *)SEM_FAILED) {
2125         exit(1);
2126     }
2127     sem_close(psem);
2128     psem = sem_open(sem_name, O_CREAT | O_EXCL, 0644, 1);
2129     if (psem != (sem_t *)SEM_FAILED) {
2130         sem_close(psem);
2131         exit(1);
2132     }
2133     sem_unlink(sem_name);
2134     exit(0);
2135 }], [ac_cv_func_sem_open=yes], [ac_cv_func_sem_open=no],
2136 [ac_cv_func_sem_open=no])])
2137
2138 # It's stupid, but not all platforms have union semun, even those that need it.
2139 AC_MSG_CHECKING(for union semun in sys/sem.h)
2140 AC_TRY_COMPILE([
2141 #include <sys/types.h>
2142 #include <sys/ipc.h>
2143 #include <sys/sem.h>
2144 ],[
2145 union semun arg;
2146 semctl(0, 0, 0, arg);
2147 ], [have_union_semun="1" union_semun=yes ]
2148 msg=yes, [
2149 have_union_semun="0"
2150 msg=no ] )
2151 AC_MSG_RESULT([$msg])
2152 AC_SUBST(have_union_semun)
2153
2154 dnl Checks for libraries.
2155 APR_CHECK_DEFINE(LOCK_EX, sys/file.h)
2156 APR_CHECK_DEFINE(F_SETLK, fcntl.h)
2157 APR_CHECK_DEFINE(SEM_UNDO, sys/sem.h)
2158
2159 # We are assuming that if the platform doesn't have POLLIN, it doesn't have
2160 # any POLL definitions.
2161 APR_CHECK_DEFINE_FILES(POLLIN, poll.h sys/poll.h)
2162
2163 if test "$threads" = "1"; then
2164     APR_CHECK_DEFINE(PTHREAD_PROCESS_SHARED, pthread.h)
2165     AC_CHECK_FUNCS(pthread_mutexattr_setpshared)
2166     # Some systems have setpshared and define PROCESS_SHARED, but don't 
2167     # really support PROCESS_SHARED locks.  So, we must validate that we 
2168     # can go through the steps without receiving some sort of system error.
2169     # Linux and older versions of AIX have this problem.
2170     APR_IFALLYES(header:pthread.h define:PTHREAD_PROCESS_SHARED func:pthread_mutexattr_setpshared, [
2171       AC_CACHE_CHECK([for working PROCESS_SHARED locks], apr_cv_process_shared_works, [
2172       AC_TRY_RUN([
2173 #include <sys/types.h>
2174 #include <pthread.h>
2175         int main()
2176         {
2177             pthread_mutex_t mutex;
2178             pthread_mutexattr_t attr;
2179             if (pthread_mutexattr_init(&attr))
2180                 exit(1);
2181             if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
2182                 exit(2);
2183             if (pthread_mutex_init(&mutex, &attr))
2184                 exit(3);
2185             if (pthread_mutexattr_destroy(&attr))
2186                 exit(4);
2187             if (pthread_mutex_destroy(&mutex))
2188                 exit(5);
2189             exit(0);
2190         }], [apr_cv_process_shared_works=yes], [apr_cv_process_shared_works=no])])
2191       # Override detection of pthread_mutexattr_setpshared
2192       ac_cv_func_pthread_mutexattr_setpshared=$apr_cv_process_shared_works])
2193
2194     if test "$ac_cv_func_pthread_mutexattr_setpshared" = "yes"; then
2195         APR_CHECK_PTHREAD_ROBUST_SHARED_MUTEX
2196     fi
2197 fi
2198
2199 # See which lock mechanisms we can support on this system.
2200 APR_IFALLYES(header:semaphore.h func:sem_open func:sem_close dnl
2201              func:sem_unlink func:sem_post func:sem_wait,
2202              hasposixser="1", hasposixser="0")
2203 APR_IFALLYES(func:semget func:semctl define:SEM_UNDO, hassysvser="1", 
2204              hassysvser="0")
2205 APR_IFALLYES(func:flock define:LOCK_EX, hasflockser="1", hasflockser="0")
2206 APR_IFALLYES(header:fcntl.h define:F_SETLK, hasfcntlser="1", hasfcntlser="0")
2207 # note: the current APR use of shared mutex requires /dev/zero
2208 APR_IFALLYES(header:pthread.h define:PTHREAD_PROCESS_SHARED dnl
2209              func:pthread_mutexattr_setpshared dnl
2210              file:/dev/zero,
2211              hasprocpthreadser="1", hasprocpthreadser="0")
2212 APR_IFALLYES(header:OS.h func:create_sem, hasbeossem="1", hasbeossem="0")
2213
2214 # See which lock mechanism we'll select by default on this system.
2215 # The last APR_DECIDE to execute sets the default.
2216 # At this stage, we match the ordering in Apache 1.3
2217 # which is (highest to lowest): sysvsem -> fcntl -> flock.
2218 # POSIX semaphores and cross-process pthread mutexes are not
2219 # used by default since they have less desirable behaviour when
2220 # e.g. a process holding the mutex segfaults.
2221 # The BEOSSEM decision doesn't require any substitutions but is
2222 # included here to prevent the fcntl() branch being selected
2223 # from the decision making.
2224 APR_BEGIN_DECISION([apr_lock implementation method])
2225 APR_IFALLYES(func:flock define:LOCK_EX,
2226             APR_DECIDE(USE_FLOCK_SERIALIZE, [4.2BSD-style flock()]))
2227 APR_IFALLYES(header:fcntl.h define:F_SETLK,
2228             APR_DECIDE(USE_FCNTL_SERIALIZE, [SVR4-style fcntl()]))
2229 APR_IFALLYES(func:semget func:semctl define:SEM_UNDO,
2230             APR_DECIDE(USE_SYSVSEM_SERIALIZE, [SysV IPC semget()]))
2231 APR_IFALLYES(header:OS.h func:create_sem, 
2232             APR_DECIDE(USE_BEOSSEM, [BeOS Semaphores])) 
2233 if test "x$apr_lock_method" != "x"; then
2234     APR_DECISION_FORCE($apr_lock_method)
2235 fi
2236 APR_END_DECISION
2237 AC_DEFINE_UNQUOTED($ac_decision)
2238
2239 flockser="0"
2240 sysvser="0"
2241 posixser="0"
2242 procpthreadser="0"
2243 fcntlser="0"
2244 case $ac_decision in
2245     USE_FLOCK_SERIALIZE )
2246         flockser="1"
2247         ;;
2248     USE_FCNTL_SERIALIZE )
2249         fcntlser="1"
2250         ;;
2251     USE_SYSVSEM_SERIALIZE )
2252         sysvser="1"
2253         ;;
2254     USE_POSIXSEM_SERIALIZE )
2255         posixser="1"
2256         ;;
2257     USE_PROC_PTHREAD_SERIALIZE )
2258         procpthreadser="1"
2259         ;;
2260     USE_BEOSSEM )
2261         beossem="1"
2262         ;;
2263 esac
2264
2265 if test $hasfcntlser = "1"; then
2266 AC_MSG_CHECKING(if fcntl returns EACCES when F_SETLK is already held)
2267 AC_TRY_RUN([
2268 #ifdef HAVE_STDLIB_H
2269 #include <stdlib.h>
2270 #endif
2271 #ifdef HAVE_SYS_TYPES_H
2272 #include <sys/types.h>
2273 #endif
2274 #ifdef HAVE_SYS_STAT_H
2275 #include <sys/stat.h>
2276 #endif
2277 #ifdef HAVE_SYS_WAIT_H
2278 #include <sys/wait.h>
2279 #endif
2280 #if defined(HAVE_UNISTD_H)
2281 #include <unistd.h>
2282 #endif
2283 #include <fcntl.h>
2284 #include <errno.h>
2285
2286 int fd;
2287 struct flock proc_mutex_lock_it = {0};
2288 const char *fname = "conftest.fcntl";
2289
2290 int main()
2291 {
2292     int rc, status;;
2293     proc_mutex_lock_it.l_whence = SEEK_SET;   /* from current point */
2294     proc_mutex_lock_it.l_type = F_WRLCK;      /* set exclusive/write lock */
2295
2296     fd = creat(fname, S_IRWXU);
2297     unlink(fname);
2298
2299     if (rc = lockit()) {
2300         exit(-1);
2301     }
2302
2303     if (fork()) {
2304         wait(&status);
2305     }
2306     else {
2307       return(lockit());
2308     }
2309
2310     close(fd);
2311     exit(WEXITSTATUS(status) != EACCES);
2312 }
2313
2314 int lockit() {
2315     int rc;
2316     do {
2317         rc = fcntl(fd, F_SETLK, &proc_mutex_lock_it);
2318     } while ( rc < 0 && errno == EINTR);
2319
2320     return (rc < 0) ? errno : 0;
2321 }], [apr_fcntl_tryacquire_eacces=1], [apr_fcntl_tryacquire_eacces=0], [apr_fcntl_tryacquire_eacces=0])
2322 fi
2323
2324 if test "$apr_fcntl_tryacquire_eacces" = "1"; then
2325   AC_DEFINE(FCNTL_TRYACQUIRE_EACCES, 1, [Define if fcntl returns EACCES when F_SETLK is already held])
2326   AC_MSG_RESULT(yes)
2327 else
2328   AC_MSG_RESULT(no)
2329 fi
2330
2331
2332 AC_SUBST(hasflockser)
2333 AC_SUBST(hassysvser)
2334 AC_SUBST(hasposixser)
2335 AC_SUBST(hasfcntlser)
2336 AC_SUBST(hasprocpthreadser)
2337 AC_SUBST(flockser)
2338 AC_SUBST(sysvser)
2339 AC_SUBST(posixser)
2340 AC_SUBST(fcntlser)
2341 AC_SUBST(procpthreadser)
2342 AC_SUBST(pthreadser)
2343
2344 AC_MSG_CHECKING(if all interprocess locks affect threads)
2345 if test "x$apr_process_lock_is_global" = "xyes"; then
2346     proclockglobal="1"
2347     AC_MSG_RESULT(yes)
2348 else
2349     proclockglobal="0"
2350     AC_MSG_RESULT(no)
2351 fi
2352
2353 AC_SUBST(proclockglobal)
2354
2355 AC_MSG_CHECKING(if POSIX sems affect threads in the same process)
2356 if test "x$apr_posixsem_is_global" = "xyes"; then
2357   AC_DEFINE(POSIXSEM_IS_GLOBAL, 1, 
2358             [Define if POSIX semaphores affect threads within the process])
2359   AC_MSG_RESULT(yes)
2360 else
2361   AC_MSG_RESULT(no)
2362 fi
2363
2364 AC_MSG_CHECKING(if SysV sems affect threads in the same process)
2365 if test "x$apr_sysvsem_is_global" = "xyes"; then
2366   AC_DEFINE(SYSVSEM_IS_GLOBAL, 1,
2367             [Define if SysV semaphores affect threads within the process])
2368   AC_MSG_RESULT(yes)
2369 else
2370   AC_MSG_RESULT(no)
2371 fi
2372
2373 AC_MSG_CHECKING(if fcntl locks affect threads in the same process)
2374 if test "x$apr_fcntl_is_global" = "xyes"; then
2375   AC_DEFINE(FCNTL_IS_GLOBAL, 1,
2376             [Define if fcntl locks affect threads within the process])
2377   AC_MSG_RESULT(yes)
2378 else
2379   AC_MSG_RESULT(no)
2380 fi
2381
2382 AC_MSG_CHECKING(if flock locks affect threads in the same process)
2383 if test "x$apr_flock_is_global" = "xyes"; then
2384   AC_DEFINE(FLOCK_IS_GLOBAL, 1,
2385             [Define if flock locks affect threads within the process])
2386   AC_MSG_RESULT(yes)
2387 else
2388   AC_MSG_RESULT(no)
2389 fi
2390
2391 dnl ----------------------------- Checking for /dev/random 
2392 AC_MSG_CHECKING(for entropy source)
2393
2394 why_no_rand=""
2395
2396 AC_ARG_WITH(egd, 
2397   [  --with-egd[[=DIR]]        use EGD-compatible socket],
2398   [ AC_DEFINE(HAVE_EGD, 1, [Define if EGD is supported])
2399     if test "$withval" = "yes"; then
2400         AC_DEFINE_UNQUOTED(EGD_DEFAULT_SOCKET, ["/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"], 
2401          [Define to list of paths to EGD sockets])
2402     else
2403         AC_DEFINE_UNQUOTED(EGD_DEFAULT_SOCKET, ["$withval"])
2404     fi
2405     AC_MSG_RESULT(EGD-compatible daemon)
2406     rand="1"
2407   ])
2408
2409 if test "$rand" != "1"; then
2410   AC_ARG_WITH(devrandom,
2411     [  --with-devrandom[[=DEV]]  use /dev/random or compatible [[searches by default]]],
2412     [ apr_devrandom="$withval" ], [ apr_devrandom="yes" ])
2413
2414   if test "$apr_devrandom" = "yes"; then
2415     # /dev/random on OpenBSD doesn't provide random data, so
2416     # prefer /dev/arandom, which does; see random(4).
2417     for f in /dev/arandom /dev/urandom /dev/random; do
2418       if test -r $f; then
2419         apr_devrandom=$f
2420         rand=1
2421         break
2422       fi
2423     done
2424   elif test "$apr_devrandom" != "no"; then
2425     if test -r "$apr_devrandom"; then
2426       rand="1"
2427     else
2428       AC_ERROR([$apr_devrandom not found or unreadable.])
2429     fi
2430   fi
2431
2432   if test "$rand" = "1"; then
2433     case $host in
2434       *os390)
2435         if test $os_version -lt 1700; then
2436           rand="0"
2437           why_no_rand=" ($apr_devrandom unusable on z/OS before V1R7)"
2438         fi
2439         ;;
2440     esac
2441   fi
2442
2443   if test "$rand" = "1"; then
2444     AC_DEFINE_UNQUOTED(DEV_RANDOM, ["$apr_devrandom"], [Define to path of random device])
2445     AC_MSG_RESULT([$apr_devrandom])
2446   fi
2447 fi
2448
2449 if test "$rand" != "1"; then
2450     case $host in
2451         # we have built in support for OS/2
2452         *-os2*)
2453             AC_MSG_RESULT([Using OS/2 builtin random])
2454             rand="1"
2455             ;;
2456         *)
2457             if test "$rand" != "1"; then
2458               if test "$ac_cv_lib_truerand_main" = "yes"; then
2459                 AC_DEFINE(HAVE_TRUERAND, 1, [Define if truerand is supported])
2460                 AC_MSG_RESULT(truerand)
2461                 rand="1"
2462               else
2463                 AC_MSG_RESULT(not found$why_no_rand)
2464                 rand="0"
2465               fi
2466             fi
2467             ;;
2468     esac
2469 fi
2470
2471 AC_SUBST(rand)
2472
2473 dnl ----------------------------- Checking for File Info Support 
2474 echo "${nl}Checking for File Info Support..."
2475 AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_atimensec,
2476 struct stat.st_ctimensec, struct stat.st_mtimensec, struct stat.st_atim.tv_nsec,
2477 struct stat.st_ctim.tv_nsec, struct stat.st_mtim.tv_nsec,
2478 struct stat.st_atime_n, struct stat.st_ctime_n, struct stat.st_mtime_n],,,[
2479 #ifdef HAVE_SYS_TYPES_H
2480 #include <sys/types.h>
2481 #endif
2482 #ifdef HAVE_SYS_STAT_H
2483 #include <sys/stat.h>
2484 #endif
2485 #ifdef HAVE_UNISTD_H
2486 #include <unistd.h>
2487 #endif])
2488
2489 APR_CHECK_DIRENT_INODE
2490 APR_CHECK_DIRENT_TYPE
2491
2492 dnl ----------------------------- Checking for UUID Support 
2493 echo "${nl}Checking for OS UUID Support..."
2494
2495 AC_CHECK_HEADERS(uuid.h uuid/uuid.h sys/uuid.h, break)
2496
2497 apr_revert_save_LIBS=$LIBS
2498
2499 # Prefer the flavor(s) that live in libc;
2500 AC_SEARCH_LIBS(uuid_create, uuid)
2501 AC_SEARCH_LIBS(uuid_generate, uuid)
2502 if test "$ac_cv_search_uuid_create" = "none required" -o \
2503         "$ac_cv_search_uuid_generate" = "none required"; then
2504  LIBS=$apr_revert_save_LIBS
2505 fi
2506
2507 AC_CHECK_FUNCS(uuid_create uuid_generate)
2508
2509 AC_CACHE_CHECK([for os uuid usability], [apr_cv_osuuid], [
2510 # Ensure this test closely mirrors misc/unix/rand.c!
2511 uuid_includes="
2512 #if defined(HAVE_SYS_TYPES_H)
2513 #include <sys/types.h>
2514 #endif
2515 #if defined(HAVE_UNISTD_H)
2516 #include <unistd.h>
2517 #endif
2518 #if defined(HAVE_UUID_H)
2519 #include <uuid.h>
2520 #elif defined(HAVE_UUID_UUID_H)
2521 #include <uuid/uuid.h>
2522 #elif defined(HAVE_SYS_UUID_H)
2523 #include <sys/uuid.h>
2524 #endif
2525 "
2526  apr_cv_osuuid=no
2527  if test $ac_cv_func_uuid_create = yes; then
2528   AC_TRY_LINK([$uuid_includes], [
2529     uuid_t g;
2530     uint32_t s;
2531     uuid_create(&g, &s);
2532     if (s == uuid_s_ok) s = 0;
2533   ], [apr_cv_osuuid=yes], [apr_cv_func_uuid_create=no])
2534  fi
2535  if test $ac_cv_func_uuid_generate = yes; then
2536   AC_TRY_LINK([$uuid_includes], [
2537     uuid_t g;
2538     uuid_generate(g);
2539   ], [apr_cv_osuuid=yes], [apr_cv_func_uuid_generate=no])
2540  fi 
2541 ])
2542
2543 if test $apr_cv_osuuid = yes; then
2544   osuuid="1"
2545 else
2546   osuuid="0"
2547   LIBS=$apr_revert_save_LIBS
2548 fi
2549 AC_SUBST(osuuid)
2550
2551
2552 dnl ----------------------------- Checking for Time Support 
2553 echo "${nl}Checking for Time Support..."
2554
2555 AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,[
2556 #include <sys/types.h>
2557 #include <time.h>])
2558
2559 dnl ----------------------------- Checking for Networking Support 
2560 echo "${nl}Checking for Networking support..."
2561 APR_TYPE_IN_ADDR
2562 if test "$ac_cv_type_in_addr" = "yes"; then
2563   have_in_addr="1"
2564 else
2565   have_in_addr="0"
2566 fi
2567
2568 AC_MSG_CHECKING([if fd == socket on this platform])
2569 if test "x$file_as_socket" != "x0" ; then
2570     file_as_socket="1";
2571     echo "yes"
2572 else
2573     echo "no"
2574 fi
2575
2576 AC_SUBST(have_in_addr)
2577 AC_SUBST(file_as_socket)
2578
2579 if test "$ac_cv_func_poll $file_as_socket" = "yes 1"; then
2580     AC_DEFINE(WAITIO_USES_POLL, 1,
2581               [Define if apr_wait_for_io_or_timeout() uses poll(2)])
2582 fi
2583
2584 # Check the types only if we have gethostbyname_r
2585 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
2586     APR_CHECK_GETHOSTBYNAME_R_STYLE
2587 fi
2588
2589 # Check the types only if we have getservbyname_r
2590 if test "$ac_cv_func_getservbyname_r" = "yes"; then
2591     APR_CHECK_GETSERVBYNAME_R_STYLE
2592 fi
2593
2594 APR_CHECK_TCP_NODELAY_INHERITED
2595 APR_CHECK_O_NONBLOCK_INHERITED
2596 APR_CHECK_TCP_NODELAY_WITH_CORK
2597
2598 # Look for a way of corking TCP...
2599 APR_CHECK_DEFINE(TCP_CORK, netinet/tcp.h)
2600 APR_CHECK_DEFINE(TCP_NOPUSH, netinet/tcp.h)
2601 apr_tcp_nopush_flag="0"
2602 have_corkable_tcp="0"
2603 if test "x$ac_cv_define_TCP_CORK" = "xyes"; then
2604     apr_tcp_nopush_flag="TCP_CORK"
2605     have_corkable_tcp="1"
2606 else
2607     case $host in
2608         *linux*)
2609             AC_EGREP_CPP(yes,[
2610 #include <linux/socket.h>
2611 #ifdef TCP_CORK
2612 yes
2613 #endif
2614             ],[
2615                 apr_tcp_nopush_flag="3"
2616                 have_corkable_tcp="1"
2617             ])
2618             ;;
2619         *)
2620             ;;
2621     esac
2622 fi
2623 if test "x$ac_cv_define_TCP_NOPUSH" = "xyes"; then
2624     apr_tcp_nopush_flag="TCP_NOPUSH"
2625     have_corkable_tcp="1"
2626 fi
2627
2628 APR_CHECK_DEFINE(SO_ACCEPTFILTER, sys/socket.h)
2629 if test "x$ac_cv_define_SO_ACCEPTFILTER" = "xyes"; then
2630     acceptfilter="1"
2631 else
2632     acceptfilter="0"
2633 fi
2634
2635 APR_CHECK_SCTP
2636 APR_CHECK_MCAST
2637
2638 AC_SUBST(apr_tcp_nopush_flag)
2639 AC_SUBST(have_corkable_tcp)
2640 AC_SUBST(acceptfilter)
2641 AC_SUBST(have_sctp)
2642
2643 AC_CHECK_FUNCS(set_h_errno)
2644
2645 echo "${nl}Checking for IPv6 Networking support..."
2646 dnl Start of checking for IPv6 support...
2647
2648 AC_ARG_ENABLE(ipv6,
2649   [  --disable-ipv6          Disable IPv6 support in APR.],
2650   [ if test "$enableval" = "no"; then
2651         user_disabled_ipv6=1
2652     fi ],
2653   [ user_disabled_ipv6=0 ] )
2654
2655 case $host in
2656   *)
2657     broken_ipv6=0
2658 esac
2659
2660 AC_SEARCH_LIBS(getaddrinfo, socket inet6)
2661 AC_SEARCH_LIBS(gai_strerror, socket inet6)
2662 AC_SEARCH_LIBS(getnameinfo, socket inet6)
2663 AC_CHECK_FUNCS(gai_strerror)
2664 APR_CHECK_WORKING_GETADDRINFO
2665 APR_CHECK_NEGATIVE_EAI
2666 APR_CHECK_WORKING_GETNAMEINFO
2667 APR_CHECK_SOCKADDR_IN6
2668 APR_CHECK_SOCKADDR_STORAGE
2669
2670 have_ipv6="0"
2671 if test "$user_disabled_ipv6" = 1; then
2672     ipv6_result="no -- disabled by user"
2673 else
2674     if test "x$broken_ipv6" = "x0"; then
2675         if test "x$have_sockaddr_in6" = "x1"; then
2676             if test "x$ac_cv_working_getaddrinfo" = "xyes"; then
2677                 if test "x$ac_cv_working_getnameinfo" = "xyes"; then
2678                     APR_CHECK_GETADDRINFO_ADDRCONFIG
2679                     have_ipv6="1"
2680                     ipv6_result="yes"
2681                 else
2682                     ipv6_result="no -- no getnameinfo"
2683                 fi
2684             else
2685                 ipv6_result="no -- no working getaddrinfo"
2686             fi
2687         else
2688             ipv6_result="no -- no sockaddr_in6"
2689         fi
2690     else
2691         ipv6_result="no -- the platform has known problems supporting IPv6"
2692     fi
2693 fi
2694
2695 AC_MSG_CHECKING(if APR supports IPv6)
2696 AC_MSG_RESULT($ipv6_result)
2697
2698 AC_SUBST(have_ipv6)
2699
2700 # hstrerror is only needed if IPv6 is not enabled,
2701 # so getaddrinfo/gai_strerror are not used.
2702 if test $have_ipv6 = 0; then
2703   AC_SEARCH_LIBS(hstrerror, resolv,
2704     [AC_DEFINE(HAVE_HSTRERROR, 1, [Define if hstrerror is present])])
2705 fi
2706
2707 dnl Check for langinfo support
2708
2709 AC_CHECK_HEADERS(langinfo.h)
2710 AC_CHECK_FUNCS(nl_langinfo)
2711
2712 dnl ------------------------------ Defaults for some platform nuances
2713
2714 dnl Do we have a Win32-centric Unicode FS?
2715 APR_SETIFNULL(have_unicode_fs, [0])
2716 AC_SUBST(have_unicode_fs)
2717
2718 APR_SETIFNULL(apr_has_xthread_files, [0])
2719 AC_SUBST(apr_has_xthread_files)
2720
2721 APR_SETIFNULL(apr_procattr_user_set_requires_password, [0])
2722 AC_SUBST(apr_procattr_user_set_requires_password)
2723
2724 APR_SETIFNULL(apr_thread_func, [])
2725 AC_SUBST(apr_thread_func)
2726
2727 APR_SETIFNULL(apr_has_user, [1])
2728 AC_SUBST(apr_has_user)
2729
2730 dnl ----------------------------- Finalize the variables
2731
2732 echo "${nl}Restore user-defined environment settings..."
2733
2734 APR_RESTORE_THE_ENVIRONMENT(CPPFLAGS, EXTRA_)
2735 APR_RESTORE_THE_ENVIRONMENT(CFLAGS, EXTRA_)
2736 APR_RESTORE_THE_ENVIRONMENT(LDFLAGS, EXTRA_)
2737 APR_RESTORE_THE_ENVIRONMENT(LIBS, EXTRA_)
2738 APR_RESTORE_THE_ENVIRONMENT(INCLUDES, EXTRA_)
2739 AC_SUBST(NOTEST_CPPFLAGS)
2740 AC_SUBST(NOTEST_CFLAGS)
2741 AC_SUBST(NOTEST_LDFLAGS)
2742 AC_SUBST(NOTEST_LIBS)
2743 AC_SUBST(NOTEST_INCLUDES)
2744
2745 dnl ----------------------------- Construct the files
2746
2747 AC_SUBST(INTERNAL_CPPFLAGS)
2748 AC_SUBST(LDLIBS)
2749 AC_SUBST(INCLUDES)
2750 AC_SUBST(AR)
2751 AC_SUBST(RM)
2752 AC_SUBST(OSDIR)
2753 AC_SUBST(DEFAULT_OSDIR)
2754 AC_SUBST(EXEEXT)
2755 AC_SUBST(LIBTOOL_LIBS)
2756
2757 # Use -no-install or -no-fast-install to link the test 
2758 # programs on all platforms but Darwin, where it would cause
2759 # the programs to be linked against installed versions of
2760 # libapr instead of those just built.
2761 case $host in
2762     *-apple-darwin*)
2763         LT_NO_INSTALL=""
2764         ;;
2765     *-mingw*)
2766         LT_NO_INSTALL="-no-fast-install"
2767         ;;
2768     *)
2769         LT_NO_INSTALL="-no-install"
2770         ;;
2771 esac
2772 AC_SUBST(LT_NO_INSTALL)
2773
2774 #
2775 # BSD/OS (BSDi) needs to use a different include syntax in the Makefiles
2776 #
2777 case $host in
2778 *bsdi*)
2779     # Check whether they've installed GNU make
2780     if make --version > /dev/null 2>&1; then 
2781         INCLUDE_RULES="include $apr_buildout/apr_rules.mk"
2782         INCLUDE_OUTPUTS="include $apr_srcdir/build-outputs.mk"
2783     else
2784         # BSDi make
2785         INCLUDE_RULES=".include \"$apr_buildout/apr_rules.mk\""
2786         INCLUDE_OUTPUTS=".include \"$apr_srcdir/build-outputs.mk\""
2787     fi
2788     ;;
2789 *)
2790     INCLUDE_RULES="include $apr_buildout/apr_rules.mk"
2791     INCLUDE_OUTPUTS="include $apr_srcdir/build-outputs.mk"
2792     ;;
2793 esac
2794 AC_SUBST(INCLUDE_RULES)
2795 AC_SUBST(INCLUDE_OUTPUTS)
2796
2797 AC_CONFIG_FILES([Makefile
2798                  include/apr.h
2799                  build/apr_rules.mk
2800                  build/pkg/pkginfo
2801                  apr-$APR_MAJOR_VERSION-config:apr-config.in
2802                  apr.pc])
2803
2804 if test -d $srcdir/test; then
2805    AC_CONFIG_FILES([test/Makefile test/internal/Makefile])
2806 fi
2807
2808 dir=include/arch/unix
2809 test -d $dir || $MKDIR $dir
2810
2811 AC_CONFIG_COMMANDS([default], [
2812 # Commands run at the end of config.status:
2813 for i in $APR_SAVE_HEADERS; do
2814   if cmp -s $i $i.save 2>/dev/null; then
2815     mv $i.save $i
2816     AC_MSG_NOTICE([$i is unchanged])
2817   fi
2818   rm -f $i.save
2819 done
2820 chmod +x apr-$APR_MAJOR_VERSION-config
2821 ],[
2822 dnl This section is expanded by configure UNQUOTED so variable 
2823 dnl references must be backslash-escaped as necessary.
2824
2825 # Commands run at the beginning of config.status:
2826 APR_SAVE_HEADERS="include/apr.h include/arch/unix/apr_private.h"
2827 APR_MAJOR_VERSION=$APR_MAJOR_VERSION
2828 APR_PLATFORM=$host
2829
2830 for apri in \${APR_SAVE_HEADERS}; do
2831   test -r \${apri} && mv \${apri} \${apri}.save
2832 done
2833 ])
2834
2835 AC_OUTPUT