]> granicus.if.org Git - apache/blob - build/apr_common.m4
Merge in APR[-util] macros from branches/trunk-buildconf-noapr
[apache] / build / apr_common.m4
1 dnl -------------------------------------------------------- -*- autoconf -*-
2 dnl Licensed to the Apache Software Foundation (ASF) under one or more
3 dnl contributor license agreements.  See the NOTICE file distributed with
4 dnl this work for additional information regarding copyright ownership.
5 dnl The ASF licenses this file to You under the Apache License, Version 2.0
6 dnl (the "License"); you may not use this file except in compliance with
7 dnl the License.  You may obtain a copy of the License at
8 dnl
9 dnl     http://www.apache.org/licenses/LICENSE-2.0
10 dnl
11 dnl Unless required by applicable law or agreed to in writing, software
12 dnl distributed under the License is distributed on an "AS IS" BASIS,
13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 dnl See the License for the specific language governing permissions and
15 dnl limitations under the License.
16
17 dnl
18 dnl apr_common.m4: APR's general-purpose autoconf macros
19 dnl
20
21 dnl
22 dnl APR_CONFIG_NICE(filename)
23 dnl
24 dnl Saves a snapshot of the configure command-line for later reuse
25 dnl
26 AC_DEFUN([APR_CONFIG_NICE], [
27   rm -f $1
28   cat >$1<<EOF
29 #! /bin/sh
30 #
31 # Created by configure
32
33 EOF
34   if test -n "$CC"; then
35     echo "CC=\"$CC\"; export CC" >> $1
36   fi
37   if test -n "$CFLAGS"; then
38     echo "CFLAGS=\"$CFLAGS\"; export CFLAGS" >> $1
39   fi
40   if test -n "$CPPFLAGS"; then
41     echo "CPPFLAGS=\"$CPPFLAGS\"; export CPPFLAGS" >> $1
42   fi
43   if test -n "$LDFLAGS"; then
44     echo "LDFLAGS=\"$LDFLAGS\"; export LDFLAGS" >> $1
45   fi
46   if test -n "$LTFLAGS"; then
47     echo "LTFLAGS=\"$LTFLAGS\"; export LTFLAGS" >> $1
48   fi
49   if test -n "$LIBS"; then
50     echo "LIBS=\"$LIBS\"; export LIBS" >> $1
51   fi
52   if test -n "$INCLUDES"; then
53     echo "INCLUDES=\"$INCLUDES\"; export INCLUDES" >> $1
54   fi
55   if test -n "$NOTEST_CFLAGS"; then
56     echo "NOTEST_CFLAGS=\"$NOTEST_CFLAGS\"; export NOTEST_CFLAGS" >> $1
57   fi
58   if test -n "$NOTEST_CPPFLAGS"; then
59     echo "NOTEST_CPPFLAGS=\"$NOTEST_CPPFLAGS\"; export NOTEST_CPPFLAGS" >> $1
60   fi
61   if test -n "$NOTEST_LDFLAGS"; then
62     echo "NOTEST_LDFLAGS=\"$NOTEST_LDFLAGS\"; export NOTEST_LDFLAGS" >> $1
63   fi
64   if test -n "$NOTEST_LIBS"; then
65     echo "NOTEST_LIBS=\"$NOTEST_LIBS\"; export NOTEST_LIBS" >> $1
66   fi
67
68   # Retrieve command-line arguments.
69   eval "set x $[0] $ac_configure_args"
70   shift
71
72   for arg
73   do
74     APR_EXPAND_VAR(arg, $arg)
75     echo "\"[$]arg\" \\" >> $1
76   done
77   echo '"[$]@"' >> $1
78   chmod +x $1
79 ])dnl
80
81 dnl APR_MKDIR_P_CHECK(fallback-mkdir-p)
82 dnl checks whether mkdir -p works
83 AC_DEFUN([APR_MKDIR_P_CHECK], [
84   AC_CACHE_CHECK(for working mkdir -p, ac_cv_mkdir_p,[
85     test -d conftestdir && rm -rf conftestdir
86     mkdir -p conftestdir/somedir >/dev/null 2>&1
87     if test -d conftestdir/somedir; then
88       ac_cv_mkdir_p=yes
89     else
90       ac_cv_mkdir_p=no
91     fi
92     rm -rf conftestdir
93   ])
94   if test "$ac_cv_mkdir_p" = "yes"; then
95       mkdir_p="mkdir -p"
96   else
97       mkdir_p="$1"
98   fi
99 ])
100
101 dnl
102 dnl APR_SUBDIR_CONFIG(dir [, sub-package-cmdline-args, args-to-drop])
103 dnl
104 dnl dir: directory to find configure in
105 dnl sub-package-cmdline-args: arguments to add to the invocation (optional)
106 dnl args-to-drop: arguments to drop from the invocation (optional)
107 dnl
108 dnl Note: This macro relies on ac_configure_args being set properly.
109 dnl
110 dnl The args-to-drop argument is shoved into a case statement, so
111 dnl multiple arguments can be separated with a |.
112 dnl
113 dnl Note: Older versions of autoconf do not single-quote args, while 2.54+
114 dnl places quotes around every argument.  So, if you want to drop the
115 dnl argument called --enable-layout, you must pass the third argument as:
116 dnl [--enable-layout=*|\'--enable-layout=*]
117 dnl
118 dnl Trying to optimize this is left as an exercise to the reader who wants
119 dnl to put up with more autoconf craziness.  I give up.
120 dnl
121 AC_DEFUN([APR_SUBDIR_CONFIG], [
122   # save our work to this point; this allows the sub-package to use it
123   AC_CACHE_SAVE
124
125   echo "configuring package in $1 now"
126   ac_popdir=`pwd`
127   apr_config_subdirs="$1"
128   test -d $1 || $mkdir_p $1
129   ac_abs_srcdir=`(cd $srcdir/$1 && pwd)`
130   cd $1
131
132 changequote(, )dnl
133       # A "../" for each directory in /$config_subdirs.
134       ac_dots=`echo $apr_config_subdirs|sed -e 's%^\./%%' -e 's%[^/]$%&/%' -e 's%[^/]*/%../%g'`
135 changequote([, ])dnl
136
137   # Make the cache file pathname absolute for the subdirs
138   # required to correctly handle subdirs that might actually
139   # be symlinks
140   case "$cache_file" in
141   /*) # already absolute
142     ac_sub_cache_file=$cache_file ;;
143   *)  # Was relative path.
144     ac_sub_cache_file="$ac_popdir/$cache_file" ;;
145   esac
146
147   ifelse($3, [], [apr_configure_args=$ac_configure_args],[
148   apr_configure_args=
149   apr_sep=
150   for apr_configure_arg in $ac_configure_args
151   do
152     case "$apr_configure_arg" in
153       $3)
154         continue ;;
155     esac
156     apr_configure_args="$apr_configure_args$apr_sep'$apr_configure_arg'"
157     apr_sep=" "
158   done
159   ])
160
161   dnl autoconf doesn't add --silent to ac_configure_args; explicitly pass it
162   test "x$silent" = "xyes" && apr_configure_args="$apr_configure_args --silent"
163
164   dnl AC_CONFIG_SUBDIRS silences option warnings, emulate this for 2.62
165   apr_configure_args="--disable-option-checking $apr_configure_args" 
166
167   dnl The eval makes quoting arguments work - specifically the second argument
168   dnl where the quoting mechanisms used is "" rather than [].
169   dnl
170   dnl We need to execute another shell because some autoconf/shell combinations
171   dnl will choke after doing repeated APR_SUBDIR_CONFIG()s.  (Namely Solaris
172   dnl and autoconf-2.54+)
173   if eval $SHELL $ac_abs_srcdir/configure $apr_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_abs_srcdir $2
174   then :
175     echo "$1 configured properly"
176   else
177     echo "configure failed for $1"
178     exit 1
179   fi
180
181   cd $ac_popdir
182
183   # grab any updates from the sub-package
184   AC_CACHE_LOAD
185 ])dnl
186
187 dnl
188 dnl APR_SAVE_THE_ENVIRONMENT(variable_name)
189 dnl
190 dnl Stores the variable (usually a Makefile macro) for later restoration
191 dnl
192 AC_DEFUN([APR_SAVE_THE_ENVIRONMENT], [
193   apr_ste_save_$1="$$1"
194 ])dnl
195
196 dnl
197 dnl APR_RESTORE_THE_ENVIRONMENT(variable_name, prefix_)
198 dnl
199 dnl Uses the previously saved variable content to figure out what configure
200 dnl has added to the variable, moving the new bits to prefix_variable_name
201 dnl and restoring the original variable contents.  This makes it possible
202 dnl for a user to override configure when it does something stupid.
203 dnl
204 AC_DEFUN([APR_RESTORE_THE_ENVIRONMENT], [
205 dnl Check whether $apr_ste_save_$1 is empty or
206 dnl only whitespace. The verbatim "X" is token number 1,
207 dnl the following whitespace will be ignored.
208 set X $apr_ste_save_$1
209 if test ${#} -eq 1; then
210   $2$1="$$1"
211   $1=
212 else
213   if test "x$apr_ste_save_$1" = "x$$1"; then
214     $2$1=
215   else
216     $2$1=`echo "$$1" | sed -e "s%${apr_ste_save_$1}%%"`
217     $1="$apr_ste_save_$1"
218   fi
219 fi
220 if test "x$silent" != "xyes"; then
221   echo "  restoring $1 to \"$$1\""
222   echo "  setting $2$1 to \"$$2$1\""
223 fi
224 AC_SUBST($2$1)
225 ])dnl
226
227 dnl
228 dnl APR_SETIFNULL(variable, value)
229 dnl
230 dnl  Set variable iff it's currently null
231 dnl
232 AC_DEFUN([APR_SETIFNULL], [
233   if test -z "$$1"; then
234     test "x$silent" != "xyes" && echo "  setting $1 to \"$2\""
235     $1="$2"
236   fi
237 ])dnl
238
239 dnl
240 dnl APR_SETVAR(variable, value)
241 dnl
242 dnl  Set variable no matter what
243 dnl
244 AC_DEFUN([APR_SETVAR], [
245   test "x$silent" != "xyes" && echo "  forcing $1 to \"$2\""
246   $1="$2"
247 ])dnl
248
249 dnl
250 dnl APR_ADDTO(variable, value)
251 dnl
252 dnl  Add value to variable
253 dnl
254 AC_DEFUN([APR_ADDTO], [
255   if test "x$$1" = "x"; then
256     test "x$silent" != "xyes" && echo "  setting $1 to \"$2\""
257     $1="$2"
258   else
259     apr_addto_bugger="$2"
260     for i in $apr_addto_bugger; do
261       apr_addto_duplicate="0"
262       for j in $$1; do
263         if test "x$i" = "x$j"; then
264           apr_addto_duplicate="1"
265           break
266         fi
267       done
268       if test $apr_addto_duplicate = "0"; then
269         test "x$silent" != "xyes" && echo "  adding \"$i\" to $1"
270         $1="$$1 $i"
271       fi
272     done
273   fi
274 ])dnl
275
276 dnl
277 dnl APR_REMOVEFROM(variable, value)
278 dnl
279 dnl Remove a value from a variable
280 dnl
281 AC_DEFUN([APR_REMOVEFROM], [
282   if test "x$$1" = "x$2"; then
283     test "x$silent" != "xyes" && echo "  nulling $1"
284     $1=""
285   else
286     apr_new_bugger=""
287     apr_removed=0
288     for i in $$1; do
289       if test "x$i" != "x$2"; then
290         apr_new_bugger="$apr_new_bugger $i"
291       else
292         apr_removed=1
293       fi
294     done
295     if test $apr_removed = "1"; then
296       test "x$silent" != "xyes" && echo "  removed \"$2\" from $1"
297       $1=$apr_new_bugger
298     fi
299   fi
300 ]) dnl
301
302 dnl
303 dnl APR_CHECK_DEFINE_FILES( symbol, header_file [header_file ...] )
304 dnl
305 AC_DEFUN([APR_CHECK_DEFINE_FILES], [
306   AC_CACHE_CHECK([for $1 in $2],ac_cv_define_$1,[
307     ac_cv_define_$1=no
308     for curhdr in $2
309     do
310       AC_EGREP_CPP(YES_IS_DEFINED, [
311 #include <$curhdr>
312 #ifdef $1
313 YES_IS_DEFINED
314 #endif
315       ], ac_cv_define_$1=yes)
316     done
317   ])
318   if test "$ac_cv_define_$1" = "yes"; then
319     AC_DEFINE(HAVE_$1, 1, [Define if $1 is defined])
320   fi
321 ])
322
323
324 dnl
325 dnl APR_CHECK_DEFINE(symbol, header_file)
326 dnl
327 AC_DEFUN([APR_CHECK_DEFINE], [
328   AC_CACHE_CHECK([for $1 in $2],ac_cv_define_$1,[
329     AC_EGREP_CPP(YES_IS_DEFINED, [
330 #include <$2>
331 #ifdef $1
332 YES_IS_DEFINED
333 #endif
334     ], ac_cv_define_$1=yes, ac_cv_define_$1=no)
335   ])
336   if test "$ac_cv_define_$1" = "yes"; then
337     AC_DEFINE(HAVE_$1, 1, [Define if $1 is defined in $2])
338   fi
339 ])
340
341 dnl
342 dnl APR_CHECK_APR_DEFINE( symbol )
343 dnl
344 AC_DEFUN([APR_CHECK_APR_DEFINE], [
345 apr_old_cppflags=$CPPFLAGS
346 CPPFLAGS="$CPPFLAGS $INCLUDES"
347 AC_EGREP_CPP(YES_IS_DEFINED, [
348 #include <apr.h>
349 #if $1
350 YES_IS_DEFINED
351 #endif
352 ], ac_cv_define_$1=yes, ac_cv_define_$1=no)
353 CPPFLAGS=$apr_old_cppflags
354 ])
355
356 dnl APR_CHECK_FILE(filename); set ac_cv_file_filename to
357 dnl "yes" if 'filename' is readable, else "no".
358 dnl @deprecated! - use AC_CHECK_FILE instead
359 AC_DEFUN([APR_CHECK_FILE], [
360 dnl Pick a safe variable name
361 define([apr_cvname], ac_cv_file_[]translit([$1], [./+-], [__p_]))
362 AC_CACHE_CHECK([for $1], [apr_cvname],
363 [if test -r $1; then
364    apr_cvname=yes
365  else
366    apr_cvname=no
367  fi])
368 ])
369
370 define(APR_IFALLYES,[dnl
371 ac_rc=yes
372 for ac_spec in $1; do
373     ac_type=`echo "$ac_spec" | sed -e 's/:.*$//'`
374     ac_item=`echo "$ac_spec" | sed -e 's/^.*://'`
375     case $ac_type in
376         header )
377             ac_item=`echo "$ac_item" | sed 'y%./+-%__p_%'`
378             ac_var="ac_cv_header_$ac_item"
379             ;;
380         file )
381             ac_item=`echo "$ac_item" | sed 'y%./+-%__p_%'`
382             ac_var="ac_cv_file_$ac_item"
383             ;;
384         func )   ac_var="ac_cv_func_$ac_item"   ;;
385         struct ) ac_var="ac_cv_struct_$ac_item" ;;
386         define ) ac_var="ac_cv_define_$ac_item" ;;
387         custom ) ac_var="$ac_item" ;;
388     esac
389     eval "ac_val=\$$ac_var"
390     if test ".$ac_val" != .yes; then
391         ac_rc=no
392         break
393     fi
394 done
395 if test ".$ac_rc" = .yes; then
396     :
397     $2
398 else
399     :
400     $3
401 fi
402 ])
403
404
405 define(APR_BEGIN_DECISION,[dnl
406 ac_decision_item='$1'
407 ac_decision_msg='FAILED'
408 ac_decision=''
409 ])
410
411
412 AC_DEFUN([APR_DECIDE],[dnl
413 dnl Define the flag (or not) in apr_private.h via autoheader
414 AH_TEMPLATE($1, [Define if $2 will be used])
415 ac_decision='$1'
416 ac_decision_msg='$2'
417 ac_decision_$1=yes
418 ac_decision_$1_msg='$2'
419 ])
420
421
422 define(APR_DECISION_OVERRIDE,[dnl
423     ac_decision=''
424     for ac_item in $1; do
425          eval "ac_decision_this=\$ac_decision_${ac_item}"
426          if test ".$ac_decision_this" = .yes; then
427              ac_decision=$ac_item
428              eval "ac_decision_msg=\$ac_decision_${ac_item}_msg"
429          fi
430     done
431 ])
432
433
434 define(APR_DECISION_FORCE,[dnl
435 ac_decision="$1"
436 eval "ac_decision_msg=\"\$ac_decision_${ac_decision}_msg\""
437 ])
438
439
440 define(APR_END_DECISION,[dnl
441 if test ".$ac_decision" = .; then
442     echo "[$]0:Error: decision on $ac_decision_item failed" 1>&2
443     exit 1
444 else
445     if test ".$ac_decision_msg" = .; then
446         ac_decision_msg="$ac_decision"
447     fi
448     AC_DEFINE_UNQUOTED(${ac_decision_item})
449     AC_MSG_RESULT([decision on $ac_decision_item... $ac_decision_msg])
450 fi
451 ])
452
453
454 dnl
455 dnl APR_CHECK_SIZEOF_EXTENDED(INCLUDES, TYPE [, CROSS_SIZE])
456 dnl
457 dnl A variant of AC_CHECK_SIZEOF which allows the checking of
458 dnl sizes of non-builtin types
459 dnl
460 AC_DEFUN([APR_CHECK_SIZEOF_EXTENDED],
461 [changequote(<<, >>)dnl
462 dnl The name to #define.
463 define(<<AC_TYPE_NAME>>, translit(sizeof_$2, [a-z *], [A-Z_P]))dnl
464 dnl The cache variable name.
465 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$2, [ *], [_p]))dnl
466 changequote([, ])dnl
467 AC_MSG_CHECKING(size of $2)
468 AC_CACHE_VAL(AC_CV_NAME,
469 [AC_TRY_RUN([#include <stdio.h>
470 $1
471 #ifdef WIN32
472 #define binmode "b"
473 #else
474 #define binmode
475 #endif
476 main()
477 {
478   FILE *f=fopen("conftestval", "w" binmode);
479   if (!f) exit(1);
480   fprintf(f, "%d\n", sizeof($2));
481   exit(0);
482 }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, ifelse([$3],,,
483 AC_CV_NAME=$3))])dnl
484 AC_MSG_RESULT($AC_CV_NAME)
485 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The size of ]$2)
486 undefine([AC_TYPE_NAME])dnl
487 undefine([AC_CV_NAME])dnl
488 ])
489
490
491 dnl
492 dnl APR_TRY_COMPILE_NO_WARNING(INCLUDES, FUNCTION-BODY,
493 dnl             [ACTIONS-IF-NO-WARNINGS], [ACTIONS-IF-WARNINGS])
494 dnl
495 dnl Tries a compile test with warnings activated so that the result
496 dnl is false if the code doesn't compile cleanly.  For compilers
497 dnl where it is not known how to activate a "fail-on-error" mode,
498 dnl it is undefined which of the sets of actions will be run.
499 dnl
500 AC_DEFUN([APR_TRY_COMPILE_NO_WARNING],
501 [apr_save_CFLAGS=$CFLAGS
502  CFLAGS="$CFLAGS $CFLAGS_WARN"
503  if test "$ac_cv_prog_gcc" = "yes"; then 
504    CFLAGS="$CFLAGS -Werror"
505  fi
506  AC_COMPILE_IFELSE(
507   [AC_LANG_SOURCE(
508    [#include "confdefs.h"
509    ]
510    [[$1]]
511    [int main(int argc, const char *const *argv) {]
512    [[$2]]
513    [   return 0; }]
514   )],
515   [$3], [$4])
516  CFLAGS=$apr_save_CFLAGS
517 ])
518
519 dnl
520 dnl APR_CHECK_STRERROR_R_RC
521 dnl
522 dnl  Decide which style of retcode is used by this system's 
523 dnl  strerror_r().  It either returns int (0 for success, -1
524 dnl  for failure), or it returns a pointer to the error 
525 dnl  string.
526 dnl
527 dnl
528 AC_DEFUN([APR_CHECK_STRERROR_R_RC], [
529 AC_MSG_CHECKING(for type of return code from strerror_r)
530 AC_TRY_RUN([
531 #include <errno.h>
532 #include <string.h>
533 #include <stdio.h>
534 main()
535 {
536   char buf[1024];
537   if (strerror_r(ERANGE, buf, sizeof buf) < 1) {
538     exit(0);
539   }
540   else {
541     exit(1);
542   }
543 }], [
544     ac_cv_strerror_r_rc_int=yes ], [
545     ac_cv_strerror_r_rc_int=no ], [
546     ac_cv_strerror_r_rc_int=no ] )
547 if test "x$ac_cv_strerror_r_rc_int" = xyes; then
548   AC_DEFINE(STRERROR_R_RC_INT, 1, [Define if strerror returns int])
549   msg="int"
550 else
551   msg="pointer"
552 fi
553 AC_MSG_RESULT([$msg])
554 ] )
555
556 dnl
557 dnl APR_CHECK_DIRENT_INODE
558 dnl
559 dnl  Decide if d_fileno or d_ino are available in the dirent
560 dnl  structure on this platform.  Single UNIX Spec says d_ino,
561 dnl  BSD uses d_fileno.  Undef to find the real beast.
562 dnl
563 AC_DEFUN([APR_CHECK_DIRENT_INODE], [
564 AC_CACHE_CHECK([for inode member of struct dirent], apr_cv_dirent_inode, [
565 apr_cv_dirent_inode=no
566 AC_TRY_COMPILE([
567 #include <sys/types.h>
568 #include <dirent.h>
569 ],[
570 #ifdef d_ino
571 #undef d_ino
572 #endif
573 struct dirent de; de.d_fileno;
574 ], apr_cv_dirent_inode=d_fileno)
575 if test "$apr_cv_dirent_inode" = "no"; then
576 AC_TRY_COMPILE([
577 #include <sys/types.h>
578 #include <dirent.h>
579 ],[
580 #ifdef d_fileno
581 #undef d_fileno
582 #endif
583 struct dirent de; de.d_ino;
584 ], apr_cv_dirent_inode=d_ino)
585 fi
586 ])
587 if test "$apr_cv_dirent_inode" != "no"; then
588   AC_DEFINE_UNQUOTED(DIRENT_INODE, $apr_cv_dirent_inode, 
589     [Define if struct dirent has an inode member])
590 fi
591 ])
592
593 dnl
594 dnl APR_CHECK_DIRENT_TYPE
595 dnl
596 dnl  Decide if d_type is available in the dirent structure 
597 dnl  on this platform.  Not part of the Single UNIX Spec.
598 dnl  Note that this is worthless without DT_xxx macros, so
599 dnl  look for one while we are at it.
600 dnl
601 AC_DEFUN([APR_CHECK_DIRENT_TYPE], [
602 AC_CACHE_CHECK([for file type member of struct dirent], apr_cv_dirent_type,[
603 apr_cv_dirent_type=no
604 AC_TRY_COMPILE([
605 #include <sys/types.h>
606 #include <dirent.h>
607 ],[
608 struct dirent de; de.d_type = DT_REG;
609 ], apr_cv_dirent_type=d_type)
610 ])
611 if test "$apr_cv_dirent_type" != "no"; then
612   AC_DEFINE_UNQUOTED(DIRENT_TYPE, $apr_cv_dirent_type, 
613     [Define if struct dirent has a d_type member]) 
614 fi
615 ])
616
617 dnl the following is a newline, a space, a tab, and a backslash (the
618 dnl backslash is used by the shell to skip newlines, but m4 sees it;
619 dnl treat it like whitespace).
620 dnl WARNING: don't reindent these lines, or the space/tab will be lost!
621 define([apr_whitespace],[
622         \])
623
624 dnl
625 dnl APR_COMMA_ARGS(ARG1 ...)
626 dnl  convert the whitespace-separated arguments into comman-separated
627 dnl  arguments.
628 dnl
629 dnl APR_FOREACH(CODE-BLOCK, ARG1, ARG2, ...)
630 dnl  subsitute CODE-BLOCK for each ARG[i]. "eachval" will be set to ARG[i]
631 dnl  within each iteration.
632 dnl
633 changequote({,})
634 define({APR_COMMA_ARGS},{patsubst([$}{1],[[}apr_whitespace{]+],[,])})
635 define({APR_FOREACH},
636   {ifelse($}{2,,,
637           [define([eachval],
638                   $}{2)$}{1[]APR_FOREACH([$}{1],
639                                          builtin([shift],
640                                                  builtin([shift], $}{@)))])})
641 changequote([,])
642
643 dnl APR_FLAG_HEADERS(HEADER-FILE ... [, FLAG-TO-SET ] [, "yes" ])
644 dnl  we set FLAG-TO-SET to 1 if we find HEADER-FILE, otherwise we set to 0
645 dnl  if FLAG-TO-SET is null, we automagically determine it's name
646 dnl  by changing all "/" to "_" in the HEADER-FILE and dropping
647 dnl  all "." and "-" chars. If the 3rd parameter is "yes" then instead of
648 dnl  setting to 1 or 0, we set FLAG-TO-SET to yes or no.
649 dnl  
650 AC_DEFUN([APR_FLAG_HEADERS], [
651 AC_CHECK_HEADERS($1)
652 for aprt_i in $1
653 do
654     ac_safe=`echo "$aprt_i" | sed 'y%./+-%__p_%'`
655     aprt_2=`echo "$aprt_i" | sed -e 's%/%_%g' -e 's/\.//g' -e 's/-//g'`
656     if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
657        eval "ifelse($2,,$aprt_2,$2)=ifelse($3,yes,yes,1)"
658     else
659        eval "ifelse($2,,$aprt_2,$2)=ifelse($3,yes,no,0)"
660     fi
661 done
662 ])
663
664 dnl APR_FLAG_FUNCS(FUNC ... [, FLAG-TO-SET] [, "yes" ])
665 dnl  if FLAG-TO-SET is null, we automagically determine it's name
666 dnl  prepending "have_" to the function name in FUNC, otherwise
667 dnl  we use what's provided as FLAG-TO-SET. If the 3rd parameter
668 dnl  is "yes" then instead of setting to 1 or 0, we set FLAG-TO-SET
669 dnl  to yes or no.
670 dnl
671 AC_DEFUN([APR_FLAG_FUNCS], [
672 AC_CHECK_FUNCS($1)
673 for aprt_j in $1
674 do
675     aprt_3="have_$aprt_j"
676     if eval "test \"`echo '$ac_cv_func_'$aprt_j`\" = yes"; then
677        eval "ifelse($2,,$aprt_3,$2)=ifelse($3,yes,yes,1)"
678     else
679        eval "ifelse($2,,$aprt_3,$2)=ifelse($3,yes,no,0)"
680     fi
681 done
682 ])
683
684 dnl Iteratively interpolate the contents of the second argument
685 dnl until interpolation offers no new result. Then assign the
686 dnl final result to $1.
687 dnl
688 dnl Example:
689 dnl
690 dnl foo=1
691 dnl bar='${foo}/2'
692 dnl baz='${bar}/3'
693 dnl APR_EXPAND_VAR(fraz, $baz)
694 dnl   $fraz is now "1/2/3"
695 dnl 
696 AC_DEFUN([APR_EXPAND_VAR], [
697 ap_last=
698 ap_cur="$2"
699 while test "x${ap_cur}" != "x${ap_last}";
700 do
701   ap_last="${ap_cur}"
702   ap_cur=`eval "echo ${ap_cur}"`
703 done
704 $1="${ap_cur}"
705 ])
706
707 dnl
708 dnl Removes the value of $3 from the string in $2, strips of any leading
709 dnl slashes, and returns the value in $1.
710 dnl
711 dnl Example:
712 dnl orig_path="${prefix}/bar"
713 dnl APR_PATH_RELATIVE(final_path, $orig_path, $prefix)
714 dnl    $final_path now contains "bar"
715 AC_DEFUN([APR_PATH_RELATIVE], [
716 ap_stripped=`echo $2 | sed -e "s#^$3##"`
717 # check if the stripping was successful
718 if test "x$2" != "x${ap_stripped}"; then
719     # it was, so strip of any leading slashes
720     $1="`echo ${ap_stripped} | sed -e 's#^/*##'`"
721 else
722     # it wasn't so return the original
723     $1="$2"
724 fi
725 ])
726
727 dnl APR_HELP_STRING(LHS, RHS)
728 dnl Autoconf 2.50 can not handle substr correctly.  It does have 
729 dnl AC_HELP_STRING, so let's try to call it if we can.
730 dnl Note: this define must be on one line so that it can be properly returned
731 dnl as the help string.  When using this macro with a multi-line RHS, ensure
732 dnl that you surround the macro invocation with []s
733 AC_DEFUN([APR_HELP_STRING], [ifelse(regexp(AC_ACVERSION, 2\.1), -1, AC_HELP_STRING([$1],[$2]),[  ][$1] substr([                       ],len($1))[$2])])
734
735 dnl
736 dnl APR_LAYOUT(configlayout, layoutname [, extravars])
737 dnl
738 AC_DEFUN([APR_LAYOUT], [
739   if test ! -f $srcdir/config.layout; then
740     echo "** Error: Layout file $srcdir/config.layout not found"
741     echo "** Error: Cannot use undefined layout '$LAYOUT'"
742     exit 1
743   fi
744   # Catch layout names including a slash which will otherwise
745   # confuse the heck out of the sed script.
746   case $2 in
747   */*) 
748     echo "** Error: $2 is not a valid layout name"
749     exit 1 ;;
750   esac
751   pldconf=./config.pld
752   changequote({,})
753   sed -e "1s/[  ]*<[lL]ayout[   ]*$2[   ]*>[    ]*//;1t" \
754       -e "1,/[  ]*<[lL]ayout[   ]*$2[   ]*>[    ]*/d" \
755       -e '/[    ]*<\/Layout>[   ]*/,$d' \
756       -e "s/^[  ]*//g" \
757       -e "s/:[  ]*/=\'/g" \
758       -e "s/[   ]*$/'/g" \
759       $1 > $pldconf
760   layout_name=$2
761   if test ! -s $pldconf; then
762     echo "** Error: unable to find layout $layout_name"
763     exit 1
764   fi
765   . $pldconf
766   rm $pldconf
767   for var in prefix exec_prefix bindir sbindir libexecdir mandir \
768              sysconfdir datadir includedir localstatedir runtimedir \
769              logfiledir libdir installbuilddir libsuffix $3; do
770     eval "val=\"\$$var\""
771     case $val in
772       *+)
773         val=`echo $val | sed -e 's;\+$;;'`
774         eval "$var=\"\$val\""
775         autosuffix=yes
776         ;;
777       *)
778         autosuffix=no
779         ;;
780     esac
781     val=`echo $val | sed -e 's:\(.\)/*$:\1:'`
782     val=`echo $val | sed -e 's:[\$]\([a-z_]*\):${\1}:g'`
783     if test "$autosuffix" = "yes"; then
784       if echo $val | grep apache >/dev/null; then
785         addtarget=no
786       else
787         addtarget=yes
788       fi
789       if test "$addtarget" = "yes"; then
790         val="$val/apache2"
791       fi
792     fi
793     eval "$var='$val'"
794   done
795   changequote([,])
796 ])dnl
797
798 dnl
799 dnl APR_ENABLE_LAYOUT(default layout name [, extra vars])
800 dnl
801 AC_DEFUN([APR_ENABLE_LAYOUT], [
802 AC_ARG_ENABLE(layout,
803 [  --enable-layout=LAYOUT],[
804   LAYOUT=$enableval
805 ])
806
807 if test -z "$LAYOUT"; then
808   LAYOUT="$1"
809 fi
810 APR_LAYOUT($srcdir/config.layout, $LAYOUT, $2)
811
812 AC_MSG_CHECKING(for chosen layout)
813 AC_MSG_RESULT($layout_name)
814 ])
815
816
817 dnl
818 dnl APR_PARSE_ARGUMENTS
819 dnl a reimplementation of autoconf's argument parser,
820 dnl used here to allow us to co-exist layouts and argument based
821 dnl set ups.
822 AC_DEFUN([APR_PARSE_ARGUMENTS], [
823 ac_prev=
824 # Retrieve the command-line arguments.  The eval is needed because
825 # the arguments are quoted to preserve accuracy.
826 eval "set x $ac_configure_args"
827 shift
828 for ac_option
829 do
830   # If the previous option needs an argument, assign it.
831   if test -n "$ac_prev"; then
832     eval "$ac_prev=\$ac_option"
833     ac_prev=
834     continue
835   fi
836
837   ac_optarg=`expr "x$ac_option" : 'x[[^=]]*=\(.*\)'`
838
839   case $ac_option in
840
841   -bindir | --bindir | --bindi | --bind | --bin | --bi)
842     ac_prev=bindir ;;
843   -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
844     bindir="$ac_optarg" ;;
845
846   -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
847     ac_prev=datadir ;;
848   -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
849   | --da=*)
850     datadir="$ac_optarg" ;;
851
852   -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
853   | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
854   | --exec | --exe | --ex)
855     ac_prev=exec_prefix ;;
856   -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
857   | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
858   | --exec=* | --exe=* | --ex=*)
859     exec_prefix="$ac_optarg" ;;
860
861   -includedir | --includedir | --includedi | --included | --include \
862   | --includ | --inclu | --incl | --inc)
863     ac_prev=includedir ;;
864   -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
865   | --includ=* | --inclu=* | --incl=* | --inc=*)
866     includedir="$ac_optarg" ;;
867
868   -infodir | --infodir | --infodi | --infod | --info | --inf)
869     ac_prev=infodir ;;
870   -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
871     infodir="$ac_optarg" ;;
872
873   -libdir | --libdir | --libdi | --libd)
874     ac_prev=libdir ;;
875   -libdir=* | --libdir=* | --libdi=* | --libd=*)
876     libdir="$ac_optarg" ;;
877
878   -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
879   | --libexe | --libex | --libe)
880     ac_prev=libexecdir ;;
881   -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
882   | --libexe=* | --libex=* | --libe=*)
883     libexecdir="$ac_optarg" ;;
884
885   -localstatedir | --localstatedir | --localstatedi | --localstated \
886   | --localstate | --localstat | --localsta | --localst \
887   | --locals | --local | --loca | --loc | --lo)
888     ac_prev=localstatedir ;;
889   -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
890   | --localstate=* | --localstat=* | --localsta=* | --localst=* \
891   | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
892     localstatedir="$ac_optarg" ;;
893
894   -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
895     ac_prev=mandir ;;
896   -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
897     mandir="$ac_optarg" ;;
898
899   -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
900     ac_prev=prefix ;;
901   -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
902     prefix="$ac_optarg" ;;
903
904   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
905     ac_prev=sbindir ;;
906   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
907   | --sbi=* | --sb=*)
908     sbindir="$ac_optarg" ;;
909
910   -sharedstatedir | --sharedstatedir | --sharedstatedi \
911   | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
912   | --sharedst | --shareds | --shared | --share | --shar \
913   | --sha | --sh)
914     ac_prev=sharedstatedir ;;
915   -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
916   | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
917   | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
918   | --sha=* | --sh=*)
919     sharedstatedir="$ac_optarg" ;;
920
921   -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
922   | --syscon | --sysco | --sysc | --sys | --sy)
923     ac_prev=sysconfdir ;;
924   -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
925   | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
926     sysconfdir="$ac_optarg" ;;
927
928   esac
929 done
930
931 # Be sure to have absolute paths.
932 for ac_var in exec_prefix prefix
933 do
934   eval ac_val=$`echo $ac_var`
935   case $ac_val in
936     [[\\/$]]* | ?:[[\\/]]* | NONE | '' ) ;;
937     *)  AC_MSG_ERROR([expected an absolute path for --$ac_var: $ac_val]);;
938   esac
939 done
940
941 ])dnl
942
943 dnl
944 dnl APR_CHECK_DEPEND
945 dnl
946 dnl Determine what program we can use to generate .deps-style dependencies
947 dnl
948 AC_DEFUN([APR_CHECK_DEPEND], [
949 dnl Try to determine what depend program we can use
950 dnl All GCC-variants should have -MM.
951 dnl If not, then we can check on those, too.
952 if test "$GCC" = "yes"; then
953   MKDEP='$(CC) -MM'
954 else
955   rm -f conftest.c
956 dnl <sys/types.h> should be available everywhere!
957   cat > conftest.c <<EOF
958 #include <sys/types.h>
959   int main() { return 0; }
960 EOF
961   MKDEP="true"
962   for i in "$CC -MM" "$CC -M" "$CPP -MM" "$CPP -M" "cpp -M"; do
963     AC_MSG_CHECKING([if $i can create proper make dependencies])
964     if $i conftest.c 2>/dev/null | grep 'conftest.o: conftest.c' >/dev/null; then
965       MKDEP=$i
966       AC_MSG_RESULT(yes)
967       break;
968     fi
969     AC_MSG_RESULT(no)
970   done
971   rm -f conftest.c
972 fi
973
974 AC_SUBST(MKDEP)
975 ])
976
977 dnl
978 dnl APR_CHECK_TYPES_COMPATIBLE(TYPE-1, TYPE-2, [ACTION-IF-TRUE])
979 dnl
980 dnl Try to determine whether two types are the same. Only works
981 dnl for gcc and icc.
982 dnl
983 AC_DEFUN([APR_CHECK_TYPES_COMPATIBLE], [
984 define([apr_cvname], apr_cv_typematch_[]translit([$1], [ ], [_])_[]translit([$2], [ ], [_]))
985 AC_CACHE_CHECK([whether $1 and $2 are the same], apr_cvname, [
986 AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [
987     int foo[0 - !__builtin_types_compatible_p($1, $2)];
988 ], [apr_cvname=yes
989 $3], [apr_cvname=no])])
990 ])