]> arthur.barton.de Git - bup.git/blob - config/configure.inc
Update base_version to 0.34~ for 0.34 development
[bup.git] / config / configure.inc
1 # -*-shell-script-*-
2
3 #   @(#) configure.inc 1.40@(#)
4 #   Copyright (c) 1999-2007 David Parsons. All rights reserved.
5 #   
6 #   Redistribution and use in source and binary forms, with or without
7 #   modification, are permitted provided that the following conditions
8 #   are met:
9 #  1. Redistributions of source code must retain the above copyright
10 #     notice, this list of conditions and the following disclaimer.
11 #  2. Redistributions in binary form must reproduce the above copyright
12 #     notice, this list of conditions and the following disclaimer in
13 #     the documentation and/or other materials provided with the
14 #     distribution.
15 #  3. My name may not be used to endorse or promote products derived
16 #     from this software without specific prior written permission.
17 #     
18 #  THIS SOFTWARE IS PROVIDED BY DAVID PARSONS ``AS IS'' AND ANY
19 #  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 #  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 #  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
22 #  PARSONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 #  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 #  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 #  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 #  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 #  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 #  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 #  THE POSSIBILITY OF SUCH DAMAGE.
30 #
31
32
33 #
34 # this preamble code is executed when this file is sourced and it picks
35 # interesting things off the command line.
36 #
37 ac_default_path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin"
38
39 ac_standard="--src=DIR          where the source lives (.)
40 --prefix=DIR            where to install the final product (/usr/local)
41 --execdir=DIR           where to put executables (prefix/bin)
42 --sbindir=DIR           where to put static executables (prefix/sbin)
43 --confdir=DIR           where to put configuration information (/etc)
44 --libdir=DIR            where to put libraries (prefix/lib)
45 --libexecdir=DIR        where to put private executables
46 --mandir=DIR            where to put manpages"
47
48 __fail=exit
49
50
51 __ac_tmpdir=''
52 __ac_clean_up () {
53     if test "$__ac_tmpdir"; then
54         rm -rf "$__ac_tmpdir"
55     fi
56 }
57 trap __ac_clean_up EXIT
58
59
60 if dirname B/A 2>/dev/null >/dev/null; then
61 __ac_dirname() {
62     dirname "$1"
63 }
64 else
65 __ac_dirname() {
66     echo "$1" | sed -e 's:/[^/]*$::'
67 }
68 fi
69
70 ac_progname=$0
71 ac_configure_command=
72 Q=\'
73 for x in "$@"; do
74     ac_configure_command="$ac_configure_command $Q$x$Q"
75 done
76 # ac_configure_command="$*"
77
78 __d=`__ac_dirname "$ac_progname"`
79 if [ "$__d" = "$ac_progname" ]; then
80     AC_SRCDIR=`pwd`
81 else
82     AC_SRCDIR=`cd $__d;pwd`
83 fi
84
85 __ac_dir() {
86     if test -d "$1"; then
87         (cd "$1";pwd)
88     else
89         echo "$1";
90     fi
91 }
92
93 while [ $# -gt 0 ]; do
94     unset matched
95
96     case X"$1" in
97     X--src|X--srcdir)
98         AC_SRCDIR=`__ac_dir "$2"`
99         _set_srcdir=1
100         shift 2;;
101
102     X--src=*|X--srcdir=*)
103         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
104         AC_SRCDIR=`__ac_dir "$__d"`
105         _set_srcdir=1
106         shift 1 ;;
107
108     X--prefix)
109         AC_PREFIX=`__ac_dir "$2"`
110         _set_prefix=1
111         shift 2;;
112
113     X--prefix=*)
114         __d=`echo "$1"| sed -e 's/^[^=]*=//'`
115         AC_PREFIX=`__ac_dir "$__d"`
116         _set_prefix=1
117         shift 1;;
118
119     X--confdir)
120         AC_CONFDIR=`__ac_dir "$2"`
121         _set_confdir=1
122         shift 2;;
123
124     X--confdir=*)
125         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
126         AC_CONFDIR=`__ac_dir "$__d"`
127         _set_confdir=1
128         shift 1;;
129
130     X--libexec|X--libexecdir)
131         AC_LIBEXEC=`__ac_dir "$2"`
132         _set_libexec=1
133         shift 2;;
134
135     X--libexec=*|X--libexecdir=*)
136         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
137         AC_LIBEXEC=`__ac_dir "$__d"`
138         _set_libexec=1
139         shift 1;;
140
141     X--lib|X--libdir)
142         AC_LIBDIR=`__ac_dir "$2"`
143         _set_libdir=1
144         shift 2;;
145
146     X--lib=*|X--libdir=*)
147         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
148         AC_LIBDIR=`__ac_dir "$__d"`
149         _set_libdir=1
150         shift 1;;
151
152     X--exec|X--execdir)
153         AC_EXECDIR=`__ac_dir "$2"`
154         _set_execdir=1
155         shift 2;;
156
157     X--exec=*|X--execdir=*)
158         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
159         AC_EXECDIR=`__ac_dir "$__d"`
160         _set_execdir=1
161         shift 1;;
162
163     X--sbin|X--sbindir)
164         AC_SBINDIR=`__ac_dir "$2"`
165         _set_sbindir=1
166         shift 2;;
167
168     X--sbin=*|X--sbindir=*)
169         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
170         AC_SBINDIR=`__ac_dir "$__d"`
171         _set_sbindir=1
172         shift 1;;
173
174     X--man|X--mandir)
175         AC_MANDIR=`__ac_dir "$2"`
176         _set_mandir=1
177         shift 2;;
178
179     X--man=*|X--mandir=*)
180         __d=`echo "$1" | sed -e 's/^[^=]*=//'`
181         AC_MANDIR=`__ac_dir "$__d"`
182         _set_mandir=1
183         shift 1;;
184
185     X--use-*=*)
186         _var=`echo "$1"| sed -n 's/^--use-\([A-Za-z][-A-Za-z0-9_]*\)=.*$/\1/p'`
187         if [ "$_var" ]; then
188             _val=`echo "$1" | sed -e 's/^--use-[^=]*=\(.*\)$/\1/'`
189             _v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
190             case X"$_val" in
191             X[Yy][Ee][Ss]|X[Tt][Rr][Uu][Ee]) eval USE_${_v}=T ;;
192             X[Nn][Oo]|X[Ff][Aa][Ll][Ss][Ee]) eval unset USE_${_v} ;;
193             *) echo "Bad value for --use-$_var ; must be yes or no"
194                exit 1 ;;
195             esac
196         else
197             echo "Bad option $1.   Use --help to show options" 1>&2
198             exit 1
199         fi
200         shift 1 ;;
201
202     X--use-*)
203         _var=`echo "$1"|sed -n 's/^--use-\([A-Za-z][-A-Za-z0-9_]*\)$/\1/p'`
204         _v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
205         eval USE_${_v}=T
206         shift 1;;
207
208     X--with-*=*)
209         _var=`echo "$1"| sed -n 's/^--with-\([A-Za-z][-A-Za-z0-9_]*\)=.*$/\1/p'`
210         if [ "$_var" ]; then
211             _val=`echo "$1" | sed -e 's/^--with-[^=]*=\(.*\)$/\1/'`
212             _v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
213             eval WITH_${_v}=\"$_val\"
214         else
215             echo "Bad option $1.   Use --help to show options" 1>&2
216             exit 1
217         fi
218         shift 1 ;;
219
220     X--with-*)
221         _var=`echo "$1" | sed -n 's/^--with-\([A-Za-z][A-Za-z0-9_-]*\)$/\1/p'`
222         if [ "$_var" ]; then
223             _v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
224             eval WITH_${_v}=1
225         else
226             echo "Bad option $1.   Use --help to show options" 1>&2
227             exit 1
228         fi
229         shift 1 ;;
230
231     X--help)
232         echo "$ac_standard"
233         test "$ac_help" && echo "$ac_help"
234         exit 0;;
235
236     *)  if [ "$LOCAL_AC_OPTIONS" ]; then
237             eval "$LOCAL_AC_OPTIONS"
238         else
239             ac_error=T
240         fi
241         if [ "$ac_error" ]; then
242             echo "Bad option $1.   Use --help to show options" 1>&2
243             exit 1
244         fi ;;
245     esac
246 done
247
248
249 #
250 # echo w/o newline
251 #
252 echononl()
253 {
254     ${ac_echo:-echo} "${@}$ac_echo_nonl"
255 }
256
257 #
258 # log something to the terminal and to a logfile.
259 #
260 LOG () {
261     echo "$@"
262     echo "$@" 1>&5
263 }
264
265 #
266 # log something to the terminal without a newline, and to a logfile with
267 # a newline
268 #
269 LOGN () {
270     echononl "$@" 1>&5
271     echo "$@"
272 }
273
274 #
275 # log something to the terminal
276 #
277 TLOG () {
278     echo "$@" 1>&5
279 }
280
281 #
282 # log something to the terminal, no newline
283 #
284 TLOGN () {
285     echononl "$@" 1>&5
286 }
287
288
289 #
290 # AC_CONTINUE tells configure not to bomb if something fails, but to
291 # continue blithely along
292 #
293 AC_CONTINUE () {
294     __fail="return"
295 }
296
297 #
298 # Emulate gnu autoconf's AC_CHECK_HEADERS() function
299 #
300 AC_CHECK_HEADERS () {
301     AC_PROG_CC
302
303     echo "/* AC_CHECK_HEADERS */" > "$__ac_tmpdir/ngc$$.c"
304     for hdr in $*; do
305         echo "#include <$hdr>" >> "$__ac_tmpdir/ngc$$.c"
306     done
307     echo "main() { }" >> "$__ac_tmpdir/ngc$$.c"
308
309     LOGN "checking for header $hdr"
310
311     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c"; then
312         AC_DEFINE 'HAVE_'`echo $hdr | tr 'a-z' 'A-Z' | tr './' '_'` 1
313         TLOG " (found)"
314         rc=0
315     else
316         TLOG " (not found)"
317         rc=1
318     fi
319     rm -f "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$"
320     return $rc
321 }
322
323
324 #
325 # emulate GNU autoconf's AC_CHECK_FUNCS function
326 #
327 AC_CHECK_FUNCS () {
328     AC_PROG_CC
329
330 F=$1
331 shift
332 rm -f "$__ac_tmpdir/ngc$$.c"
333
334 while [ "$1" ]; do
335     echo "#include <$1>" >> "$__ac_tmpdir/ngc$$.c"
336     shift
337 done
338
339     cat >> "$__ac_tmpdir/ngc$$.c" << EOF
340 main()
341 {
342
343     $F();
344 }
345 EOF
346
347     LOGN "checking for the $F function"
348
349     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $LIBS; then
350         AC_DEFINE `echo ${2:-HAVE_$F} | tr 'a-z' 'A-Z'` 1
351         TLOG " (found)"
352         rc=0
353     else
354         echo "offending command was:"
355         cat "$__ac_tmpdir/ngc$$.c"
356         echo "$AC_CC -o $__ac_tmpdir/ngc$$ $__ac_tmpdir/ngc$$.c $LIBS"
357         TLOG " (not found)"
358         rc=1
359     fi
360     rm -f "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$"
361     return $rc
362 }
363
364
365 #
366 # check to see if some structure exists
367 #
368 # usage: AC_CHECK_STRUCT structure {include ...}
369 #
370 AC_CHECK_STRUCT () {
371     AC_PROG_CC
372     struct=$1
373     shift
374
375     rm -f "$__ac_tmpdir/ngc$$.c"
376
377     for include in $*; do
378         echo "#include <$include>" >> "$__ac_tmpdir/ngc$$.c"
379     done
380
381     cat >> "$__ac_tmpdir/ngc$$.c" << EOF
382 main()
383 {
384     struct $struct foo;
385 }
386 EOF
387
388     LOGN "checking for struct $struct"
389
390     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $AC_LIBS 2>>config.log; then
391         AC_DEFINE HAVE_STRUCT_`echo ${struct} | tr 'a-z' 'A-Z'`
392         TLOG " (found)"
393         rc=0
394     else
395         TLOG " (not found)"
396         rc=1
397     fi
398     rm -f "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$"
399     return $rc
400 }
401
402
403 #
404 # check to see if some structure contains a field
405 #
406 # usage: AC_CHECK_FIELD structure field {include ...}
407 #
408 AC_CHECK_FIELD () {
409     AC_PROG_CC
410
411     struct=$1
412     field=$2
413     shift 2
414
415     rm -f "$__ac_tmpdir/ngc$$.c"
416
417     for include in $*;do
418         echo "#include <$include>" >> "$__ac_tmpdir/ngc$$.c"
419     done
420
421     cat >> "$__ac_tmpdir/ngc$$.c" << EOF
422 main()
423 {
424     struct $struct foo;
425
426     foo.$field;
427 }
428 EOF
429
430     LOGN "checking that struct $struct has a $field field"
431
432     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $AC_LIBS 2>>config.log; then
433         AC_DEFINE HAVE_`echo ${struct}_$field | tr 'a-z' 'A-Z'`
434         TLOG " (yes)"
435         rc=0
436     else
437         TLOG " (no)"
438         rc=1
439     fi
440     rm -f "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$"
441     return $rc
442 }
443
444
445 #
446 # check that the C compiler works
447 #
448 AC_PROG_CC () {
449     test "$AC_CC" && return 0
450
451     cat > "$__ac_tmpdir/ngc$$.c" << \EOF
452 #include <stdio.h>
453 main()
454 {
455     puts("hello, sailor");
456 }
457 EOF
458
459     TLOGN "checking the C compiler"
460
461     unset AC_CFLAGS AC_LDFLAGS
462
463     if [ "$CC" ] ; then
464         AC_CC="$CC"
465     elif [ "$WITH_PATH" ]; then
466         AC_CC=`acLookFor cc`
467     elif [ "`acLookFor cc`" ]; then
468         # don't specify the full path if the user is looking in their $PATH
469         # for a C compiler.
470         AC_CC=cc
471     fi
472
473     # finally check for POSIX c89
474     test "$AC_CC" || AC_CC=`acLookFor c89`
475
476     if [ ! "$AC_CC" ]; then
477         TLOG " (no C compiler found)"
478         $__fail 1
479     fi
480     echo "checking out the C compiler"
481
482     $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c"
483     status=$?
484
485     TLOGN " ($AC_CC)"
486     if [ $status -eq 0 ]; then
487         TLOG " ok"
488
489         # check that the CFLAGS and LDFLAGS aren't bogus
490
491         unset AC_CFLAGS AC_LDFLAGS
492
493         if [ "$CFLAGS" ]; then
494             test "$CFLAGS" && echo "validating CFLAGS=${CFLAGS}"
495             if $AC_CC $CFLAGS -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" ; then
496                 AC_CFLAGS=${CFLAGS:-"-g"}
497                 test "$CFLAGS" && echo "CFLAGS=\"${CFLAGS}\" are okay"
498             elif [ "$CFLAGS" ]; then
499                 echo "ignoring bogus CFLAGS=\"${CFLAGS}\""
500             fi
501         else
502             AC_CFLAGS=-g
503         fi
504         if [ "$LDFLAGS" ]; then
505             echo "validating LDFLAGS=${LDFLAGS}"
506             $AC_CC $AC_CFLAGS -c -o "$__ac_tmpdir/ngc$$.o" "$__ac_tmpdir/ngc$$.c"
507             if $AC_CC $AC_CFLAGS $LDFLAGS -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.o"; then
508                 AC_LDFLAGS=${LDFLAGS:-"-g"}
509                 test "$LDFLAGS" && TLOG "LDFLAGS=\"${LDFLAGS}\" are okay"
510             elif [ "$LDFLAGS" ]; then
511                 TLOG "ignoring bogus LDFLAGS=\"${LDFLAGS}\""
512             fi
513         else
514             AC_LDFLAGS=${CFLAGS:-"-g"}
515         fi
516     else
517         AC_FAIL " does not compile code properly"
518     fi
519
520     AC_SUB 'CC' "$AC_CC"
521
522     rm -f "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$.o"
523
524     return $status
525 }
526
527
528 #
529 # acLookFor actually looks for a program, without setting anything.
530 #
531 acLookFor () {
532     path="${AC_PATH:-$ac_default_path}"
533     case "X$1" in
534     X-[rx]) __mode=$1
535             shift
536             ;;
537     *)      __mode=-x
538             ;;
539     esac
540     oldifs="$IFS"
541     for program in $*; do
542         IFS=":"
543         for x in $path; do
544             if [ $__mode "$x/$program" -a -f "$x/$program" ]; then
545                 echo "$x/$program"
546                 break 2
547             fi
548         done
549     done
550     IFS="$oldifs"
551     unset __mode
552 }
553
554
555 #
556 # check that a program exists and set its path
557 #
558 MF_PATH_INCLUDE () {
559     SYM=$1; shift
560
561     case X$1 in
562     X-[rx]) __mode=$1
563             shift
564             ;;
565     *)      unset __mode
566             ;;
567     esac
568
569     TLOGN "looking for $1"
570
571     DEST=`acLookFor $__mode $*`
572
573     __sym=`echo "$SYM" | tr '[a-z]' '[A-Z]'`
574     if [ "$DEST" ]; then
575         TLOG " ($DEST)"
576         echo "$1 is $DEST"
577         AC_MAK $SYM
578         AC_DEFINE PATH_$__sym \""$DEST"\"
579         AC_SUB $__sym "$DEST"
580         eval CF_$SYM="'$DEST'"
581         return 0
582     else
583         #AC_SUB $__sym ''
584         echo "$1 is not found"
585         TLOG " (not found)"
586         return 1
587     fi
588 }
589
590
591 #
592 # AC_INIT starts the ball rolling
593 #
594 # After AC_INIT, fd's 1 and 2 point to config.log
595 # and fd 5 points to what used to be fd 1
596 #
597 AC_INIT () {
598     __ac_tmpdir=$(mktemp -d configure-XXXXXX)
599     __config_files="config.cmd config.sub config.h config.mak config.log"
600     __config_detritus="config.h.tmp"
601     rm -f $__config_files $__config_detritus
602     __cwd=`pwd`
603     exec 5>&1 1>$__cwd/config.log 2>&1
604     AC_CONFIGURE_FOR=__AC_`echo $1 | sed -e 's/\..$//' | tr 'a-z' 'A-Z' | tr ' ' '_'`_D
605
606     # check to see whether to use echo -n or echo ...\c
607     #
608     echo -n hello > $$
609     echo world >> $$
610     if grep "helloworld" $$ >/dev/null; then
611         ac_echo="echo -n"
612         echo "[echo -n] works"
613     else
614         ac_echo="echo"
615         echo 'hello\c' > $$
616         echo 'world' >> $$
617         if grep "helloworld" $$ >/dev/null; then
618             ac_echo_nonl='\c'
619             echo "[echo ...\\c] works"
620         fi
621     fi
622     rm -f $$
623
624     LOG "Configuring for [$1]"
625
626     rm -f $__cwd/config.h
627     cat > $__cwd/config.h.tmp << EOF
628 /*
629  * configuration for $1${2:+" ($2)"}, generated `date`
630  * by ${LOGNAME:-`whoami`}@`hostname`
631  */
632 #ifndef $AC_CONFIGURE_FOR
633 #define $AC_CONFIGURE_FOR 1
634
635
636 EOF
637
638     unset __share
639     if [ -d $AC_PREFIX/share/man ]; then
640         for t in 1 2 3 4 5 6 7 8 9; do
641             if [ -d $AC_PREFIX/share/man/man$t ]; then
642                 __share=/share
643             elif [ -d $AC_PREFIX/share/man/cat$t ]; then
644                 __share=/share
645             fi
646         done
647     else
648         __share=
649     fi
650
651     if [ -d $AC_PREFIX/libexec ]; then
652         __libexec=libexec
653     else
654         __libexec=lib
655     fi
656
657
658     AC_PREFIX=${AC_PREFIX:-/usr/local}
659     AC_EXECDIR=${AC_EXECDIR:-$AC_PREFIX/bin}
660     AC_SBINDIR=${AC_SBINDIR:-$AC_PREFIX/sbin}
661     AC_LIBDIR=${AC_LIBDIR:-$AC_PREFIX/lib}
662     AC_MANDIR=${AC_MANDIR:-$AC_PREFIX$__share/man}
663     AC_LIBEXEC=${AC_LIBEXEC:-$AC_PREFIX/$__libexec}
664     AC_CONFDIR=${AC_CONFDIR:-/etc}
665
666     AC_PATH=${WITH_PATH:-$PATH}
667     AC_PROG_CPP
668     AC_PROG_INSTALL
669
670     ac_os=`uname -s | sed 's/[-_].*//; s/[^a-zA-Z0-9]/_/g'`
671     _os=`echo $ac_os | tr '[a-z]' '[A-Z]'`
672     AC_DEFINE OS_$_os   1
673     eval OS_${_os}=1
674     unset _os
675 }
676
677
678 #
679 # AC_LIBRARY checks to see if a given library exists and contains the
680 # given function.
681 # usage: AC_LIBRARY function library [alternate ...]
682 #
683 AC_LIBRARY() {
684     SRC=$1
685     shift
686
687     __acllibs=
688     __aclhdrs=
689
690     for x in "$@"; do
691         case X"$x" in
692         X-l*) __acllibs="$__acllibs $x" ;;
693         *)    __aclhdrs="$__aclhdrs $x" ;;
694         esac
695     done
696
697     # first see if the function can be found in any of the
698     # current libraries
699     AC_QUIET AC_CHECK_FUNCS $SRC $__aclhdrs && return 0
700
701     # then search through the list of libraries
702     __libs="$LIBS"
703     for x in $__acllibs; do
704         LIBS="$__libs $x"
705         if AC_QUIET AC_CHECK_FUNCS $SRC $__aclhdrs; then
706             AC_LIBS="$AC_LIBS $x"
707             return 0
708         fi
709     done
710     return 1
711 }
712
713
714 #
715 # AC_PROG_LEX checks to see if LEX exists, and if it's lex or flex.
716 #
717 AC_PROG_LEX() {
718     TLOGN "looking for lex "
719
720     DEST=`acLookFor lex`
721     if [ "$DEST" ]; then
722         AC_MAK LEX
723         AC_DEFINE PATH_LEX \"$DEST\"
724         AC_SUB 'LEX' "$DEST"
725         echo "lex is $DEST"
726     else
727         DEST=`acLookFor flex`
728         if [ "$DEST" ]; then
729             AC_MAK FLEX
730             AC_DEFINE 'LEX' \"$DEST\"
731             AC_SUB 'LEX', "$DEST"
732             echo "lex is $DEST"
733         else
734             AC_SUB LEX ''
735             echo "neither lex or flex found"
736             TLOG " (not found)"
737             return 1
738         fi
739     fi
740
741     if AC_LIBRARY yywrap -ll -lfl; then
742         TLOG "($DEST)"
743         return 0
744     fi
745     TLOG "(no lex library found)"
746     return 1
747 }
748
749
750 #
751 # AC_PROG_YACC checks to see if YACC exists, and if it's bison or
752 # not.
753 #
754 AC_PROG_YACC () {
755
756     TLOGN "looking for yacc "
757
758     DEST=`acLookFor yacc`
759     if [ "$DEST" ]; then
760         AC_MAK YACC
761         AC_DEFINE PATH_YACC \"$DEST\"
762         AC_SUB 'YACC' "$DEST"
763         TLOG "($DEST)"
764         echo "yacc is $DEST"
765     else
766         DEST=`acLookFor bison`
767         if [ "$DEST" ]; then
768             AC_MAK BISON
769             AC_DEFINE 'YACC' \"$DEST\"
770             AC_SUB 'YACC' "$DEST -y"
771             echo "yacc is $DEST -y"
772             TLOG "($DEST -y)"
773         else
774             AC_SUB 'YACC' ''
775             echo "neither yacc or bison found"
776             TLOG " (not found)"
777             return 1
778         fi
779     fi
780     return 0
781 }
782
783
784 #
785 # AC_PROG_LN_S checks to see if ln exists, and, if so, if ln -s works
786 #
787 AC_PROG_LN_S () {
788     test "$AC_FIND_PROG" || AC_PROG_FIND
789
790     test "$AC_FIND_PROG" || return 1
791     
792     TLOGN "looking for \"ln -s\""
793     DEST=`acLookFor ln`
794
795     if [ "$DEST" ]; then
796         rm -f "$__ac_tmpdir/b$$"
797         "$DEST" -s "$__ac_tmpdir/a$$" "$__ac_tmpdir/b$$"
798         if [ "`$AC_FIND_PROG $__ac_tmpdir/b$$ -type l -print`" ]; then
799             TLOG " ($DEST)"
800             echo "$DEST exists, and ln -s works"
801             AC_SUB 'LN_S' "$DEST -s"
802             rm -f "$__ac_tmpdir/b$$"
803         else
804             AC_SUB 'LN_S' ''
805             TLOG " ($DEST exists, but -s does not seem to work)"
806             echo "$DEST exists, but ln -s doesn't seem to work"
807             rm -f "$__ac_tmpdir/b$$"
808             return 1
809         fi
810     else
811         AC_SUB 'LN_S' ''
812         echo "ln not found"
813         TLOG " (not found)"
814         return 1
815     fi
816 }
817
818
819 #
820 # AC_PROG_FIND looks for the find program and sets the FIND environment
821 # variable
822 #
823 AC_PROG_FIND () {
824     if test -z "$AC_FIND_PROG"; then
825         MF_PATH_INCLUDE FIND find
826         rc=$?
827         AC_FIND_PROG="$DEST"
828         return $rc
829     fi
830     return 0
831 }
832
833
834 #
835 # AC_PROG_AWK looks for the awk program and sets the AWK environment
836 # variable
837 #
838 AC_PROG_AWK () {
839     if test -z "$AC_AWK_PROG"; then
840         MF_PATH_INCLUDE AWK awk
841         rc=$?
842         AC_AWK_PROG="$DEST"
843         return $rc
844     fi
845     return 0
846 }
847
848
849 #
850 # AC_PROG_SED looks for the sed program and sets the SED environment
851 # variable
852 #
853 AC_PROG_SED () {
854     if test -z "$AC_SED_PROG"; then
855         MF_PATH_INCLUDE SED sed
856         rc=$?
857         AC_SED_PROG="$DEST"
858         return $rc
859     fi
860     return 0
861 }
862
863
864 #
865 # AC_HEADER_SYS_WAIT looks for sys/wait.h
866 #
867 AC_HEADER_SYS_WAIT () {
868     AC_CHECK_HEADERS sys/wait.h || return 1
869 }
870
871 #
872 # AC_TYPE_PID_T checks to see if the pid_t type exists
873 #
874 AC_TYPE_PID_T () {
875     cat > "$__ac_tmpdir/pd$$.c" << EOF
876 #include <sys/types.h>
877 main() { pid_t me; }
878 EOF
879
880     LOGN "checking for pid_t"
881
882     if $AC_CC -c "$__ac_tmpdir/pd$$.c" -o "$__ac_tmpdir/pd$$.o"; then
883         TLOG " (found)"
884         rc=0
885     else
886         echo "typedef int pid_t;" >> $__cwd/config.h.tmp
887         TLOG " (not found)"
888         rc=1
889     fi
890     rm -f "$__ac_tmpdir/pd$$.o" "$__ac_tmpdir/pd$$.c"
891     return $rc
892 }
893
894
895 #
896 # AC_C_CONST checks to see if the compiler supports the const keyword
897 #
898 AC_C_CONST () {
899     cat > "$__ac_tmpdir/pd$$.c" << EOF
900 const char me=1;
901 EOF
902     LOGN "checking for \"const\" keyword"
903
904     if $AC_CC -c "$__ac_tmpdir/pd$$.c" -o "$__ac_tmpdir/pd$$.o"; then
905         TLOG " (yes)"
906         rc=0
907     else
908         AC_DEFINE 'const' '/**/'
909         TLOG " (no)"
910         rc=1
911     fi
912     rm -f "$__ac_tmpdir/pd$$.o" "$__ac_tmpdir/pd$$.c"
913     return $rc
914 }
915
916
917 #
918 # AC_SCALAR_TYPES checks to see if the compiler can generate 2 and 4 byte ints.
919 #
920 AC_SCALAR_TYPES () {
921     cat > "$__ac_tmpdir/pd$$.c" << EOF
922 #include <stdio.h>
923 main()
924 {
925     unsigned long v_long;
926     unsigned int v_int;
927     unsigned short v_short;
928
929     if (sizeof v_long == 4)
930         puts("#define DWORD     unsigned long");
931     else if (sizeof v_int == 4)
932         puts("#define DWORD     unsigned int");
933     else
934         exit(1);
935
936     if (sizeof v_int == 2)
937         puts("#define WORD      unsigned int");
938     else if (sizeof v_short == 2)
939         puts("#define WORD      unsigned short");
940     else
941         exit(2);
942     puts("#define BYTE  unsigned char");
943     exit(0);
944 }
945 EOF
946     rc=1
947     LOGN "defining WORD & DWORD scalar types"
948     if $AC_CC "$__ac_tmpdir/pd$$.c" -o "$__ac_tmpdir/pd$$"; then
949         if "$__ac_tmpdir/pd$$"  >> $__cwd/config.h.tmp; then
950             rc=0
951         fi
952     fi
953     case "$rc" in
954     0) TLOG "" ;;
955     *) TLOG " ** FAILED **" ;;
956     esac
957     rm -f "$__ac_tmpdir/pd$$" "$__ac_tmpdir/pd$$.c"
958 }
959
960
961 #
962 # AC_OUTPUT generates makefiles from makefile.in's
963 #
964 AC_OUTPUT () {
965     cd $__cwd
966     AC_SUB 'LIBS'    "$AC_LIBS"
967     AC_SUB 'CONFIGURE_FILES' "$__config_files"
968     AC_SUB 'CONFIGURE_DETRITUS' "$__config_detritus"
969     AC_SUB 'GENERATED_FILES' "$*"
970     AC_SUB 'CFLAGS'  "$AC_CFLAGS"
971     AC_SUB 'FCFLAGS' "$AC_FCFLAGS"
972     AC_SUB 'CPPFLAGS' "$AC_CPPFLAGS"
973     AC_SUB 'CXXFLAGS' "$AC_CXXFLAGS"
974     AC_SUB 'LDFLAGS' "$AC_LDFLAGS"
975     AC_SUB 'srcdir'  "$AC_SRCDIR"
976     AC_SUB 'prefix'  "$AC_PREFIX"
977     AC_SUB 'exedir'  "$AC_EXECDIR"
978     AC_SUB 'sbindir' "$AC_SBINDIR"
979     AC_SUB 'libdir'  "$AC_LIBDIR"
980     AC_SUB 'libexec' "$AC_LIBEXEC"
981     AC_SUB 'confdir' "$AC_CONFDIR"
982     AC_SUB 'mandir'  "$AC_MANDIR"
983
984     if [ -r config.sub ]; then
985         test "$AC_SED_PROG" || AC_PROG_SED
986         test "$AC_SED_PROG" || return 1
987
988         echo                                   >> config.h.tmp
989         echo "#endif/* ${AC_CONFIGURE_FOR} */" >> config.h.tmp
990
991         rm -f config.cmd
992         Q=\'
993         cat - > config.cmd << EOF
994 #! /bin/sh
995 ${CXX:+CXX=${Q}${CXX}${Q}} ${CPPFLAGS:+CPPFLAGS=${Q}${CPPFLAGS}${Q}} ${CXXFLAGS:+CXXFLAGS=${Q}${CXXFLAGS}${Q}} ${FC:+FC=${Q}${FC}${Q}} ${FCFLAGS:+FCFLAGS=${Q}${FCFLAGS}${Q}} ${CC:+CC=${Q}${CC}${Q}} ${CFLAGS:+CFLAGS=${Q}${CFLAGS}${Q}} $ac_progname $ac_configure_command
996 EOF
997         chmod +x config.cmd
998
999         __d=$AC_SRCDIR
1000         for makefile in $*;do
1001             if test -r $__d/${makefile}.in; then
1002                 LOG "generating $makefile"
1003                 ./config.md `__ac_dirname ./$makefile` 2>/dev/null
1004                 $AC_SED_PROG -f config.sub < $__d/${makefile}.in > $makefile
1005                 __config_files="$__config_files $makefile"
1006             else
1007                 LOG "WARNING: ${makefile}.in does not exist!"
1008             fi
1009         done
1010         unset __d
1011
1012     else
1013         echo 
1014     fi
1015     cp $__cwd/config.h.tmp $__cwd/config.h
1016 }
1017
1018 #
1019 # AC_CHECK_FLOCK checks to see if flock() exists and if the LOCK_NB argument
1020 # works properly.
1021 #
1022 AC_CHECK_FLOCK() {
1023
1024     AC_CHECK_HEADERS sys/types.h sys/file.h fcntl.h
1025
1026     cat << EOF > $$.c
1027 #include <stdio.h>
1028 #include <sys/file.h>
1029 #include <sys/types.h>
1030 #include <fcntl.h>
1031
1032 main()
1033 {
1034     int x = open("$$.c", O_RDWR, 0666);
1035     int y = open("$$.c", O_RDWR, 0666);
1036
1037     if (flock(x, LOCK_EX) != 0)
1038         exit(1);
1039     if (flock(y, LOCK_EX|LOCK_NB) == 0)
1040         exit(1);
1041     exit(0);
1042 }
1043 EOF
1044
1045     LOGN "checking for flock()"
1046     HAS_FLOCK=0
1047     if $AC_CC -o flock $$.c ; then
1048         if ./flock ; then
1049             LOG " (found)"
1050             HAS_FLOCK=1
1051             AC_DEFINE HAS_FLOCK
1052         else
1053             LOG " (bad)"
1054         fi
1055     else
1056         LOG " (no)"
1057     fi
1058
1059     rm -f flock $$.c
1060
1061     case "$HAS_FLOCK" in
1062     0) return 1 ;;
1063     *) return 0 ;;
1064     esac
1065 }
1066
1067
1068 #
1069 # AC_CHECK_RESOLVER finds out whether the berkeley resolver is
1070 # present on this system.
1071 #
1072 AC_CHECK_RESOLVER () {
1073     AC_PROG_CC
1074
1075     TLOGN "checking for the Berkeley resolver library"
1076
1077     cat > "$__ac_tmpdir/ngc$$.c" << EOF
1078 #include <sys/types.h>
1079 #include <netinet/in.h>
1080 #include <arpa/nameser.h>
1081 #include <resolv.h>
1082
1083 main()
1084 {
1085     char bfr[256];
1086
1087     res_init();
1088     res_query("hello", C_IN, T_A, bfr, sizeof bfr);
1089 }
1090 EOF
1091
1092     # first see if res_init() and res_query() actually exist...
1093
1094     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c"; then
1095         __extralib=
1096     elif $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" -lresolv; then
1097         __extralib=-lresolv
1098         AC_LIBS="$AC_LIBS -lresolv"
1099     else
1100         TLOG " (not found)"
1101         rm -f "$__ac_tmpdir/ngc$$.c"
1102         return 1
1103     fi
1104
1105     # if res_init() and res_query() actually exist, check to
1106     # see if the HEADER structure is defined ...
1107
1108     cat > "$__ac_tmpdir/ngc$$.c" << EOF
1109 #include <sys/types.h>
1110 #include <netinet/in.h>
1111 #include <arpa/nameser.h>
1112 #include <resolv.h>
1113
1114 main()
1115 {
1116     HEADER hhh;
1117     res_init();
1118 }
1119 EOF
1120
1121     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $__extralib; then
1122         TLOG " (found)"
1123     elif $AC_CC -DBIND_8_COMPAT -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $__extralib; then
1124         TLOG " (bind9 with BIND_8_COMPAT)"
1125         AC_DEFINE BIND_8_COMPAT 1
1126     else
1127         TLOG " (broken)"
1128         rm -f "$__ac_tmpdir/ngc$$.c"
1129         return 1
1130     fi
1131     rm -f "$__ac_tmpdir/ngc$$.c"
1132     return 0
1133 }
1134
1135
1136 #
1137 # AC_PROG_INSTALL finds the install program and guesses whether it's a 
1138 # Berkeley or GNU install program
1139 #
1140 AC_PROG_INSTALL () {
1141
1142     DEST=`acLookFor install`
1143
1144     LOGN "checking for install"
1145     unset IS_BSD
1146     if [ "$DEST" ]; then
1147         # BSD install or GNU install?  Let's find out...
1148         touch "$__ac_tmpdir/a$$"
1149
1150         "$DEST" "$__ac_tmpdir/a$$" "$__ac_tmpdir/b$$"
1151
1152         if test -r "$__ac_tmpdir/a$$"; then
1153             LOG " ($DEST)"
1154         else
1155             IS_BSD=1
1156             LOG " ($DEST) bsd install"
1157         fi
1158         rm -f "$__ac_tmpdir/a$$" "$__ac_tmpdir/b$$"
1159     else
1160         DEST=`acLookFor ginstall`
1161         if [ "$DEST" ]; then
1162             LOG " ($DEST)"
1163         else
1164             DEST="false"
1165             LOG " (not found)"
1166         fi
1167     fi
1168
1169     if [ "$IS_BSD" ]; then
1170         PROG_INSTALL="$DEST -c"
1171     else
1172         PROG_INSTALL="$DEST"
1173     fi
1174
1175     AC_SUB 'INSTALL' "$PROG_INSTALL"
1176     AC_SUB 'INSTALL_PROGRAM' "$PROG_INSTALL -s -m 755"
1177     AC_SUB 'INSTALL_DATA' "$PROG_INSTALL -m 444"
1178
1179     # finally build a little directory installer
1180     # if mkdir -p works, use that, otherwise use install -d,
1181     # otherwise build a script to do it by hand.
1182     # in every case, test to see if the directory exists before
1183     # making it.
1184
1185     if mkdir -p $$a/b; then
1186         # I like this method best.
1187         __mkdir="mkdir -p"
1188         rmdir $$a/b
1189         rmdir $$a
1190     elif $PROG_INSTALL -d $$a/b; then
1191         __mkdir="$PROG_INSTALL -d"
1192         rmdir $$a/b
1193         rmdir $$a
1194     fi
1195
1196     __config_files="$__config_files config.md"
1197     AC_SUB 'INSTALL_DIR' "$__cwd/config.md"
1198     echo "#! /bin/sh"                                   > $__cwd/config.md
1199     echo "# script generated" `date` "by configure.sh" >> $__cwd/config.md
1200     echo                                               >> $__cwd/config.md
1201     if [ "$__mkdir" ]; then
1202         echo "test -d \"\$1\" || $__mkdir \"\$1\""     >> $__cwd/config.md
1203         echo "exit $?"                                 >> $__cwd/config.md
1204     else
1205         cat - >> $__cwd/config.md << \EOD
1206 pieces=`IFS=/; for x in $1; do echo $x; done`
1207 dir=
1208 for x in $pieces; do
1209     dir="$dir$x"
1210     mkdir $dir || exit 1
1211     dir="$dir/"
1212 done
1213 exit 0
1214 EOD
1215     fi
1216     chmod +x $__cwd/config.md
1217 }
1218
1219 #
1220 # acCheckCPP is a local that runs a C preprocessor with a given set of
1221 # compiler options
1222 #
1223 acCheckCPP () {
1224         cat > "$__ac_tmpdir/ngc$$.c" << EOF
1225 #define FOO BAR
1226
1227 FOO
1228 EOF
1229
1230     if $1 $2 "$__ac_tmpdir/ngc$$.c" > "$__ac_tmpdir/ngc$$.o"; then
1231         if grep -v '#define' "$__ac_tmpdir/ngc$$.o" | grep -s BAR >/dev/null; then
1232             echo "CPP=[$1], CPPFLAGS=[$2]"
1233             AC_SUB 'CPP' "$1"
1234             AC_SUB 'CPPFLAGS' "$2"
1235             rm "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$.o"
1236             return 0
1237         fi
1238     fi
1239     rm "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$.o"
1240     return 1
1241 }
1242
1243
1244 #
1245 # AC_PROG_CPP checks for cpp, then checks to see which CPPFLAGS are needed
1246 # to run it as a filter.
1247 #
1248 AC_PROG_CPP () {
1249     if [ "$AC_CPP_PROG" ]; then
1250         DEST="$AC_CPP_PROG"
1251     else
1252         __ac_path="$AC_PATH"
1253         AC_PATH="/lib:/usr/lib:${__ac_path:-$ac_default_path}"
1254         DEST=`acLookFor cpp`
1255         AC_PATH="$__ac_path"
1256     fi
1257
1258     unset fail
1259     LOGN "Looking for cpp"
1260     if [ "$DEST" ]; then
1261         TLOGN " ($DEST)"
1262         acCheckCPP "$DEST" "$CPPFLAGS" || \
1263                  acCheckCPP "$DEST" -traditional-cpp -E || \
1264                  acCheckCPP "$DEST" -E || \
1265                  acCheckCPP "$DEST" -traditional-cpp -pipe || \
1266                  acCheckCPP "$DEST" -pipe || fail=1
1267
1268         if [ "$fail" ]; then
1269             AC_FAIL " (can't run cpp as a pipeline)"
1270         else
1271             TLOG " ok"
1272             return 0
1273         fi
1274     fi
1275     AC_FAIL " (not found)"
1276 }
1277
1278 #
1279 # AC_FAIL spits out an error message, then __fail's 
1280 AC_FAIL() {
1281     LOG "$*" 
1282     $__fail 1
1283 }
1284
1285 #
1286 # AC_SUB writes a substitution into config.sub
1287 AC_SUB() {
1288     (   echononl "s;@$1@;"
1289         _subst=`echo $2 | sed -e 's/;/\\;/g'`
1290         echononl "$_subst"
1291         echo ';g' ) >> $__cwd/config.sub
1292 }
1293
1294 #
1295 # AC_MAK writes a define into config.mak
1296 AC_MAK() {
1297     echo "HAVE_$1 = 1" >> $__cwd/config.mak
1298 }
1299
1300 #
1301 # AC_DEFINE adds a #define to config.h
1302 AC_DEFINE() {
1303     local name="$1" value="${2:-1}"
1304     if ! printf -v "ac_defined_$name" '%s' "$value"; then
1305         AC_FATAL 'AC_DEFINE unable to set "ac_defined_$name" to "$value"'
1306     fi
1307     echo "#define $name $value" >> $__cwd/config.h.tmp
1308 }
1309
1310 #
1311 # AC_INCLUDE adds a #include to config.h
1312 AC_INCLUDE() {
1313     echo "#include \"$1\"" >> $__cwd/config.h.tmp
1314 }
1315
1316 #
1317 # AC_CONFIG adds a configuration setting to all the config files
1318 AC_CONFIG() {
1319     AC_DEFINE "PATH_$1" \""$2"\"
1320     AC_MAK "$1"
1321     AC_SUB "$1" "$2"
1322 }
1323
1324 #
1325 # AC_QUIET does something quietly
1326 AC_QUIET() {
1327     eval $* 5>/dev/null
1328 }