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