]> 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$$.o" "$__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             test "$LDFLAGS" && echo "validating LDFLAGS=${LDFLAGS}"
506             if $AC_CC $LDFLAGS -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.o"; then
507                 AC_LDFLAGS=${LDFLAGS:-"-g"}
508                 test "$LDFLAGS" && TLOG "LDFLAGS=\"${LDFLAGS}\" are okay"
509             elif [ "$LDFLAGS" ]; then
510                 TLOG "ignoring bogus LDFLAGS=\"${LDFLAGS}\""
511             fi
512         else
513             AC_LDFLAGS=${CFLAGS:-"-g"}
514         fi
515     else
516         AC_FAIL " does not compile code properly"
517     fi
518
519     AC_SUB 'CC' "$AC_CC"
520
521     rm -f "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$.o"
522
523     return $status
524 }
525
526
527 #
528 # acLookFor actually looks for a program, without setting anything.
529 #
530 acLookFor () {
531     path="${AC_PATH:-$ac_default_path}"
532     case "X$1" in
533     X-[rx]) __mode=$1
534             shift
535             ;;
536     *)      __mode=-x
537             ;;
538     esac
539     oldifs="$IFS"
540     for program in $*; do
541         IFS=":"
542         for x in $path; do
543             if [ $__mode "$x/$program" -a -f "$x/$program" ]; then
544                 echo "$x/$program"
545                 break 2
546             fi
547         done
548     done
549     IFS="$oldifs"
550     unset __mode
551 }
552
553
554 #
555 # check that a program exists and set its path
556 #
557 MF_PATH_INCLUDE () {
558     SYM=$1; shift
559
560     case X$1 in
561     X-[rx]) __mode=$1
562             shift
563             ;;
564     *)      unset __mode
565             ;;
566     esac
567
568     TLOGN "looking for $1"
569
570     DEST=`acLookFor $__mode $*`
571
572     __sym=`echo "$SYM" | tr '[a-z]' '[A-Z]'`
573     if [ "$DEST" ]; then
574         TLOG " ($DEST)"
575         echo "$1 is $DEST"
576         AC_MAK $SYM
577         AC_DEFINE PATH_$__sym \""$DEST"\"
578         AC_SUB $__sym "$DEST"
579         eval CF_$SYM="'$DEST'"
580         return 0
581     else
582         #AC_SUB $__sym ''
583         echo "$1 is not found"
584         TLOG " (not found)"
585         return 1
586     fi
587 }
588
589
590 #
591 # AC_INIT starts the ball rolling
592 #
593 # After AC_INIT, fd's 1 and 2 point to config.log
594 # and fd 5 points to what used to be fd 1
595 #
596 AC_INIT () {
597     __ac_tmpdir=$(mktemp -d configure-XXXXX)
598     __config_files="config.cmd config.sub config.h config.mak config.log"
599     __config_detritus="config.h.tmp"
600     rm -f $__config_files $__config_detritus
601     __cwd=`pwd`
602     exec 5>&1 1>$__cwd/config.log 2>&1
603     AC_CONFIGURE_FOR=__AC_`echo $1 | sed -e 's/\..$//' | tr 'a-z' 'A-Z' | tr ' ' '_'`_D
604
605     # check to see whether to use echo -n or echo ...\c
606     #
607     echo -n hello > $$
608     echo world >> $$
609     if grep "helloworld" $$ >/dev/null; then
610         ac_echo="echo -n"
611         echo "[echo -n] works"
612     else
613         ac_echo="echo"
614         echo 'hello\c' > $$
615         echo 'world' >> $$
616         if grep "helloworld" $$ >/dev/null; then
617             ac_echo_nonl='\c'
618             echo "[echo ...\\c] works"
619         fi
620     fi
621     rm -f $$
622
623     LOG "Configuring for [$1]"
624
625     rm -f $__cwd/config.h
626     cat > $__cwd/config.h.tmp << EOF
627 /*
628  * configuration for $1${2:+" ($2)"}, generated `date`
629  * by ${LOGNAME:-`whoami`}@`hostname`
630  */
631 #ifndef $AC_CONFIGURE_FOR
632 #define $AC_CONFIGURE_FOR 1
633
634
635 EOF
636
637     unset __share
638     if [ -d $AC_PREFIX/share/man ]; then
639         for t in 1 2 3 4 5 6 7 8 9; do
640             if [ -d $AC_PREFIX/share/man/man$t ]; then
641                 __share=/share
642             elif [ -d $AC_PREFIX/share/man/cat$t ]; then
643                 __share=/share
644             fi
645         done
646     else
647         __share=
648     fi
649
650     if [ -d $AC_PREFIX/libexec ]; then
651         __libexec=libexec
652     else
653         __libexec=lib
654     fi
655
656
657     AC_PREFIX=${AC_PREFIX:-/usr/local}
658     AC_EXECDIR=${AC_EXECDIR:-$AC_PREFIX/bin}
659     AC_SBINDIR=${AC_SBINDIR:-$AC_PREFIX/sbin}
660     AC_LIBDIR=${AC_LIBDIR:-$AC_PREFIX/lib}
661     AC_MANDIR=${AC_MANDIR:-$AC_PREFIX$__share/man}
662     AC_LIBEXEC=${AC_LIBEXEC:-$AC_PREFIX/$__libexec}
663     AC_CONFDIR=${AC_CONFDIR:-/etc}
664
665     AC_PATH=${WITH_PATH:-$PATH}
666     AC_PROG_CPP
667     AC_PROG_INSTALL
668
669     ac_os=`uname -s | sed 's/[-_].*//; s/[^a-zA-Z0-9]/_/g'`
670     _os=`echo $ac_os | tr '[a-z]' '[A-Z]'`
671     AC_DEFINE OS_$_os   1
672     eval OS_${_os}=1
673     unset _os
674 }
675
676
677 #
678 # AC_LIBRARY checks to see if a given library exists and contains the
679 # given function.
680 # usage: AC_LIBRARY function library [alternate ...]
681 #
682 AC_LIBRARY() {
683     SRC=$1
684     shift
685
686     __acllibs=
687     __aclhdrs=
688
689     for x in "$@"; do
690         case X"$x" in
691         X-l*) __acllibs="$__acllibs $x" ;;
692         *)    __aclhdrs="$__aclhdrs $x" ;;
693         esac
694     done
695
696     # first see if the function can be found in any of the
697     # current libraries
698     AC_QUIET AC_CHECK_FUNCS $SRC $__aclhdrs && return 0
699
700     # then search through the list of libraries
701     __libs="$LIBS"
702     for x in $__acllibs; do
703         LIBS="$__libs $x"
704         if AC_QUIET AC_CHECK_FUNCS $SRC $__aclhdrs; then
705             AC_LIBS="$AC_LIBS $x"
706             return 0
707         fi
708     done
709     return 1
710 }
711
712
713 #
714 # AC_PROG_LEX checks to see if LEX exists, and if it's lex or flex.
715 #
716 AC_PROG_LEX() {
717     TLOGN "looking for lex "
718
719     DEST=`acLookFor lex`
720     if [ "$DEST" ]; then
721         AC_MAK LEX
722         AC_DEFINE PATH_LEX \"$DEST\"
723         AC_SUB 'LEX' "$DEST"
724         echo "lex is $DEST"
725     else
726         DEST=`acLookFor flex`
727         if [ "$DEST" ]; then
728             AC_MAK FLEX
729             AC_DEFINE 'LEX' \"$DEST\"
730             AC_SUB 'LEX', "$DEST"
731             echo "lex is $DEST"
732         else
733             AC_SUB LEX ''
734             echo "neither lex or flex found"
735             TLOG " (not found)"
736             return 1
737         fi
738     fi
739
740     if AC_LIBRARY yywrap -ll -lfl; then
741         TLOG "($DEST)"
742         return 0
743     fi
744     TLOG "(no lex library found)"
745     return 1
746 }
747
748
749 #
750 # AC_PROG_YACC checks to see if YACC exists, and if it's bison or
751 # not.
752 #
753 AC_PROG_YACC () {
754
755     TLOGN "looking for yacc "
756
757     DEST=`acLookFor yacc`
758     if [ "$DEST" ]; then
759         AC_MAK YACC
760         AC_DEFINE PATH_YACC \"$DEST\"
761         AC_SUB 'YACC' "$DEST"
762         TLOG "($DEST)"
763         echo "yacc is $DEST"
764     else
765         DEST=`acLookFor bison`
766         if [ "$DEST" ]; then
767             AC_MAK BISON
768             AC_DEFINE 'YACC' \"$DEST\"
769             AC_SUB 'YACC' "$DEST -y"
770             echo "yacc is $DEST -y"
771             TLOG "($DEST -y)"
772         else
773             AC_SUB 'YACC' ''
774             echo "neither yacc or bison found"
775             TLOG " (not found)"
776             return 1
777         fi
778     fi
779     return 0
780 }
781
782
783 #
784 # AC_PROG_LN_S checks to see if ln exists, and, if so, if ln -s works
785 #
786 AC_PROG_LN_S () {
787     test "$AC_FIND_PROG" || AC_PROG_FIND
788
789     test "$AC_FIND_PROG" || return 1
790     
791     TLOGN "looking for \"ln -s\""
792     DEST=`acLookFor ln`
793
794     if [ "$DEST" ]; then
795         rm -f "$__ac_tmpdir/b$$"
796         "$DEST" -s "$__ac_tmpdir/a$$" "$__ac_tmpdir/b$$"
797         if [ "`$AC_FIND_PROG $__ac_tmpdir/b$$ -type l -print`" ]; then
798             TLOG " ($DEST)"
799             echo "$DEST exists, and ln -s works"
800             AC_SUB 'LN_S' "$DEST -s"
801             rm -f "$__ac_tmpdir/b$$"
802         else
803             AC_SUB 'LN_S' ''
804             TLOG " ($DEST exists, but -s does not seem to work)"
805             echo "$DEST exists, but ln -s doesn't seem to work"
806             rm -f "$__ac_tmpdir/b$$"
807             return 1
808         fi
809     else
810         AC_SUB 'LN_S' ''
811         echo "ln not found"
812         TLOG " (not found)"
813         return 1
814     fi
815 }
816
817
818 #
819 # AC_PROG_FIND looks for the find program and sets the FIND environment
820 # variable
821 #
822 AC_PROG_FIND () {
823     if test -z "$AC_FIND_PROG"; then
824         MF_PATH_INCLUDE FIND find
825         rc=$?
826         AC_FIND_PROG="$DEST"
827         return $rc
828     fi
829     return 0
830 }
831
832
833 #
834 # AC_PROG_AWK looks for the awk program and sets the AWK environment
835 # variable
836 #
837 AC_PROG_AWK () {
838     if test -z "$AC_AWK_PROG"; then
839         MF_PATH_INCLUDE AWK awk
840         rc=$?
841         AC_AWK_PROG="$DEST"
842         return $rc
843     fi
844     return 0
845 }
846
847
848 #
849 # AC_PROG_SED looks for the sed program and sets the SED environment
850 # variable
851 #
852 AC_PROG_SED () {
853     if test -z "$AC_SED_PROG"; then
854         MF_PATH_INCLUDE SED sed
855         rc=$?
856         AC_SED_PROG="$DEST"
857         return $rc
858     fi
859     return 0
860 }
861
862
863 #
864 # AC_HEADER_SYS_WAIT looks for sys/wait.h
865 #
866 AC_HEADER_SYS_WAIT () {
867     AC_CHECK_HEADERS sys/wait.h || return 1
868 }
869
870 #
871 # AC_TYPE_PID_T checks to see if the pid_t type exists
872 #
873 AC_TYPE_PID_T () {
874     cat > "$__ac_tmpdir/pd$$.c" << EOF
875 #include <sys/types.h>
876 main() { pid_t me; }
877 EOF
878
879     LOGN "checking for pid_t"
880
881     if $AC_CC -c "$__ac_tmpdir/pd$$.c" -o "$__ac_tmpdir/pd$$.o"; then
882         TLOG " (found)"
883         rc=0
884     else
885         echo "typedef int pid_t;" >> $__cwd/config.h.tmp
886         TLOG " (not found)"
887         rc=1
888     fi
889     rm -f "$__ac_tmpdir/pd$$.o" "$__ac_tmpdir/pd$$.c"
890     return $rc
891 }
892
893
894 #
895 # AC_C_CONST checks to see if the compiler supports the const keyword
896 #
897 AC_C_CONST () {
898     cat > "$__ac_tmpdir/pd$$.c" << EOF
899 const char me=1;
900 EOF
901     LOGN "checking for \"const\" keyword"
902
903     if $AC_CC -c "$__ac_tmpdir/pd$$.c" -o "$__ac_tmpdir/pd$$.o"; then
904         TLOG " (yes)"
905         rc=0
906     else
907         AC_DEFINE 'const' '/**/'
908         TLOG " (no)"
909         rc=1
910     fi
911     rm -f "$__ac_tmpdir/pd$$.o" "$__ac_tmpdir/pd$$.c"
912     return $rc
913 }
914
915
916 #
917 # AC_SCALAR_TYPES checks to see if the compiler can generate 2 and 4 byte ints.
918 #
919 AC_SCALAR_TYPES () {
920     cat > "$__ac_tmpdir/pd$$.c" << EOF
921 #include <stdio.h>
922 main()
923 {
924     unsigned long v_long;
925     unsigned int v_int;
926     unsigned short v_short;
927
928     if (sizeof v_long == 4)
929         puts("#define DWORD     unsigned long");
930     else if (sizeof v_int == 4)
931         puts("#define DWORD     unsigned int");
932     else
933         exit(1);
934
935     if (sizeof v_int == 2)
936         puts("#define WORD      unsigned int");
937     else if (sizeof v_short == 2)
938         puts("#define WORD      unsigned short");
939     else
940         exit(2);
941     puts("#define BYTE  unsigned char");
942     exit(0);
943 }
944 EOF
945     rc=1
946     LOGN "defining WORD & DWORD scalar types"
947     if $AC_CC "$__ac_tmpdir/pd$$.c" -o "$__ac_tmpdir/pd$$"; then
948         if "$__ac_tmpdir/pd$$"  >> $__cwd/config.h.tmp; then
949             rc=0
950         fi
951     fi
952     case "$rc" in
953     0) TLOG "" ;;
954     *) TLOG " ** FAILED **" ;;
955     esac
956     rm -f "$__ac_tmpdir/pd$$" "$__ac_tmpdir/pd$$.c"
957 }
958
959
960 #
961 # AC_OUTPUT generates makefiles from makefile.in's
962 #
963 AC_OUTPUT () {
964     cd $__cwd
965     AC_SUB 'LIBS'    "$AC_LIBS"
966     AC_SUB 'CONFIGURE_FILES' "$__config_files"
967     AC_SUB 'CONFIGURE_DETRITUS' "$__config_detritus"
968     AC_SUB 'GENERATED_FILES' "$*"
969     AC_SUB 'CFLAGS'  "$AC_CFLAGS"
970     AC_SUB 'FCFLAGS' "$AC_FCFLAGS"
971     AC_SUB 'CXXFLAGS' "$AC_CXXFLAGS"
972     AC_SUB 'LDFLAGS' "$AC_LDFLAGS"
973     AC_SUB 'srcdir'  "$AC_SRCDIR"
974     AC_SUB 'prefix'  "$AC_PREFIX"
975     AC_SUB 'exedir'  "$AC_EXECDIR"
976     AC_SUB 'sbindir' "$AC_SBINDIR"
977     AC_SUB 'libdir'  "$AC_LIBDIR"
978     AC_SUB 'libexec' "$AC_LIBEXEC"
979     AC_SUB 'confdir' "$AC_CONFDIR"
980     AC_SUB 'mandir'  "$AC_MANDIR"
981
982     if [ -r config.sub ]; then
983         test "$AC_SED_PROG" || AC_PROG_SED
984         test "$AC_SED_PROG" || return 1
985
986         echo                                   >> config.h.tmp
987         echo "#endif/* ${AC_CONFIGURE_FOR} */" >> config.h.tmp
988
989         rm -f config.cmd
990         Q=\'
991         cat - > config.cmd << EOF
992 #! /bin/sh
993 ${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
994 EOF
995         chmod +x config.cmd
996
997         __d=$AC_SRCDIR
998         for makefile in $*;do
999             if test -r $__d/${makefile}.in; then
1000                 LOG "generating $makefile"
1001                 ./config.md `__ac_dirname ./$makefile` 2>/dev/null
1002                 $AC_SED_PROG -f config.sub < $__d/${makefile}.in > $makefile
1003                 __config_files="$__config_files $makefile"
1004             else
1005                 LOG "WARNING: ${makefile}.in does not exist!"
1006             fi
1007         done
1008         unset __d
1009
1010     else
1011         echo 
1012     fi
1013     cp $__cwd/config.h.tmp $__cwd/config.h
1014 }
1015
1016 #
1017 # AC_CHECK_FLOCK checks to see if flock() exists and if the LOCK_NB argument
1018 # works properly.
1019 #
1020 AC_CHECK_FLOCK() {
1021
1022     AC_CHECK_HEADERS sys/types.h sys/file.h fcntl.h
1023
1024     cat << EOF > $$.c
1025 #include <stdio.h>
1026 #include <sys/file.h>
1027 #include <sys/types.h>
1028 #include <fcntl.h>
1029
1030 main()
1031 {
1032     int x = open("$$.c", O_RDWR, 0666);
1033     int y = open("$$.c", O_RDWR, 0666);
1034
1035     if (flock(x, LOCK_EX) != 0)
1036         exit(1);
1037     if (flock(y, LOCK_EX|LOCK_NB) == 0)
1038         exit(1);
1039     exit(0);
1040 }
1041 EOF
1042
1043     LOGN "checking for flock()"
1044     HAS_FLOCK=0
1045     if $AC_CC -o flock $$.c ; then
1046         if ./flock ; then
1047             LOG " (found)"
1048             HAS_FLOCK=1
1049             AC_DEFINE HAS_FLOCK
1050         else
1051             LOG " (bad)"
1052         fi
1053     else
1054         LOG " (no)"
1055     fi
1056
1057     rm -f flock $$.c
1058
1059     case "$HAS_FLOCK" in
1060     0) return 1 ;;
1061     *) return 0 ;;
1062     esac
1063 }
1064
1065
1066 #
1067 # AC_CHECK_RESOLVER finds out whether the berkeley resolver is
1068 # present on this system.
1069 #
1070 AC_CHECK_RESOLVER () {
1071     AC_PROG_CC
1072
1073     TLOGN "checking for the Berkeley resolver library"
1074
1075     cat > "$__ac_tmpdir/ngc$$.c" << EOF
1076 #include <sys/types.h>
1077 #include <netinet/in.h>
1078 #include <arpa/nameser.h>
1079 #include <resolv.h>
1080
1081 main()
1082 {
1083     char bfr[256];
1084
1085     res_init();
1086     res_query("hello", C_IN, T_A, bfr, sizeof bfr);
1087 }
1088 EOF
1089
1090     # first see if res_init() and res_query() actually exist...
1091
1092     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c"; then
1093         __extralib=
1094     elif $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" -lresolv; then
1095         __extralib=-lresolv
1096         AC_LIBS="$AC_LIBS -lresolv"
1097     else
1098         TLOG " (not found)"
1099         rm -f "$__ac_tmpdir/ngc$$.c"
1100         return 1
1101     fi
1102
1103     # if res_init() and res_query() actually exist, check to
1104     # see if the HEADER structure is defined ...
1105
1106     cat > "$__ac_tmpdir/ngc$$.c" << EOF
1107 #include <sys/types.h>
1108 #include <netinet/in.h>
1109 #include <arpa/nameser.h>
1110 #include <resolv.h>
1111
1112 main()
1113 {
1114     HEADER hhh;
1115     res_init();
1116 }
1117 EOF
1118
1119     if $AC_CC -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $__extralib; then
1120         TLOG " (found)"
1121     elif $AC_CC -DBIND_8_COMPAT -o "$__ac_tmpdir/ngc$$" "$__ac_tmpdir/ngc$$.c" $__extralib; then
1122         TLOG " (bind9 with BIND_8_COMPAT)"
1123         AC_DEFINE BIND_8_COMPAT 1
1124     else
1125         TLOG " (broken)"
1126         rm -f "$__ac_tmpdir/ngc$$.c"
1127         return 1
1128     fi
1129     rm -f "$__ac_tmpdir/ngc$$.c"
1130     return 0
1131 }
1132
1133
1134 #
1135 # AC_PROG_INSTALL finds the install program and guesses whether it's a 
1136 # Berkeley or GNU install program
1137 #
1138 AC_PROG_INSTALL () {
1139
1140     DEST=`acLookFor install`
1141
1142     LOGN "checking for install"
1143     unset IS_BSD
1144     if [ "$DEST" ]; then
1145         # BSD install or GNU install?  Let's find out...
1146         touch "$__ac_tmpdir/a$$"
1147
1148         "$DEST" "$__ac_tmpdir/a$$" "$__ac_tmpdir/b$$"
1149
1150         if test -r "$__ac_tmpdir/a$$"; then
1151             LOG " ($DEST)"
1152         else
1153             IS_BSD=1
1154             LOG " ($DEST) bsd install"
1155         fi
1156         rm -f "$__ac_tmpdir/a$$" "$__ac_tmpdir/b$$"
1157     else
1158         DEST=`acLookFor ginstall`
1159         if [ "$DEST" ]; then
1160             LOG " ($DEST)"
1161         else
1162             DEST="false"
1163             LOG " (not found)"
1164         fi
1165     fi
1166
1167     if [ "$IS_BSD" ]; then
1168         PROG_INSTALL="$DEST -c"
1169     else
1170         PROG_INSTALL="$DEST"
1171     fi
1172
1173     AC_SUB 'INSTALL' "$PROG_INSTALL"
1174     AC_SUB 'INSTALL_PROGRAM' "$PROG_INSTALL -s -m 755"
1175     AC_SUB 'INSTALL_DATA' "$PROG_INSTALL -m 444"
1176
1177     # finally build a little directory installer
1178     # if mkdir -p works, use that, otherwise use install -d,
1179     # otherwise build a script to do it by hand.
1180     # in every case, test to see if the directory exists before
1181     # making it.
1182
1183     if mkdir -p $$a/b; then
1184         # I like this method best.
1185         __mkdir="mkdir -p"
1186         rmdir $$a/b
1187         rmdir $$a
1188     elif $PROG_INSTALL -d $$a/b; then
1189         __mkdir="$PROG_INSTALL -d"
1190         rmdir $$a/b
1191         rmdir $$a
1192     fi
1193
1194     __config_files="$__config_files config.md"
1195     AC_SUB 'INSTALL_DIR' "$__cwd/config.md"
1196     echo "#! /bin/sh"                                   > $__cwd/config.md
1197     echo "# script generated" `date` "by configure.sh" >> $__cwd/config.md
1198     echo                                               >> $__cwd/config.md
1199     if [ "$__mkdir" ]; then
1200         echo "test -d \"\$1\" || $__mkdir \"\$1\""     >> $__cwd/config.md
1201         echo "exit $?"                                 >> $__cwd/config.md
1202     else
1203         cat - >> $__cwd/config.md << \EOD
1204 pieces=`IFS=/; for x in $1; do echo $x; done`
1205 dir=
1206 for x in $pieces; do
1207     dir="$dir$x"
1208     mkdir $dir || exit 1
1209     dir="$dir/"
1210 done
1211 exit 0
1212 EOD
1213     fi
1214     chmod +x $__cwd/config.md
1215 }
1216
1217 #
1218 # acCheckCPP is a local that runs a C preprocessor with a given set of
1219 # compiler options
1220 #
1221 acCheckCPP () {
1222         cat > "$__ac_tmpdir/ngc$$.c" << EOF
1223 #define FOO BAR
1224
1225 FOO
1226 EOF
1227
1228     if $1 $2 "$__ac_tmpdir/ngc$$.c" > "$__ac_tmpdir/ngc$$.o"; then
1229         if grep -v '#define' "$__ac_tmpdir/ngc$$.o" | grep -s BAR >/dev/null; then
1230             echo "CPP=[$1], CPPFLAGS=[$2]"
1231             AC_SUB 'CPP' "$1"
1232             AC_SUB 'CPPFLAGS' "$2"
1233             rm "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$.o"
1234             return 0
1235         fi
1236     fi
1237     rm "$__ac_tmpdir/ngc$$.c" "$__ac_tmpdir/ngc$$.o"
1238     return 1
1239 }
1240
1241
1242 #
1243 # AC_PROG_CPP checks for cpp, then checks to see which CPPFLAGS are needed
1244 # to run it as a filter.
1245 #
1246 AC_PROG_CPP () {
1247     if [ "$AC_CPP_PROG" ]; then
1248         DEST="$AC_CPP_PROG"
1249     else
1250         __ac_path="$AC_PATH"
1251         AC_PATH="/lib:/usr/lib:${__ac_path:-$ac_default_path}"
1252         DEST=`acLookFor cpp`
1253         AC_PATH="$__ac_path"
1254     fi
1255
1256     unset fail
1257     LOGN "Looking for cpp"
1258     if [ "$DEST" ]; then
1259         TLOGN " ($DEST)"
1260         acCheckCPP "$DEST" "$CPPFLAGS" || \
1261                  acCheckCPP "$DEST" -traditional-cpp -E || \
1262                  acCheckCPP "$DEST" -E || \
1263                  acCheckCPP "$DEST" -traditional-cpp -pipe || \
1264                  acCheckCPP "$DEST" -pipe || fail=1
1265
1266         if [ "$fail" ]; then
1267             AC_FAIL " (can't run cpp as a pipeline)"
1268         else
1269             TLOG " ok"
1270             return 0
1271         fi
1272     fi
1273     AC_FAIL " (not found)"
1274 }
1275
1276 #
1277 # AC_FAIL spits out an error message, then __fail's 
1278 AC_FAIL() {
1279     LOG "$*" 
1280     $__fail 1
1281 }
1282
1283 #
1284 # AC_SUB writes a substitution into config.sub
1285 AC_SUB() {
1286     (   echononl "s;@$1@;"
1287         _subst=`echo $2 | sed -e 's/;/\\;/g'`
1288         echononl "$_subst"
1289         echo ';g' ) >> $__cwd/config.sub
1290 }
1291
1292 #
1293 # AC_MAK writes a define into config.mak
1294 AC_MAK() {
1295     echo "HAVE_$1 = 1" >> $__cwd/config.mak
1296 }
1297
1298 #
1299 # AC_DEFINE adds a #define to config.h
1300 AC_DEFINE() {
1301     local name="$1" value="${2:-1}"
1302     if ! printf -v "ac_defined_$name" '%s' "$value"; then
1303         AC_FATAL 'AC_DEFINE unable to set "ac_defined_$name" to "$value"'
1304     fi
1305     echo "#define $name $value" >> $__cwd/config.h.tmp
1306 }
1307
1308 #
1309 # AC_INCLUDE adds a #include to config.h
1310 AC_INCLUDE() {
1311     echo "#include \"$1\"" >> $__cwd/config.h.tmp
1312 }
1313
1314 #
1315 # AC_CONFIG adds a configuration setting to all the config files
1316 AC_CONFIG() {
1317     AC_DEFINE "PATH_$1" \""$2"\"
1318     AC_MAK "$1"
1319     AC_SUB "$1" "$2"
1320 }
1321
1322 #
1323 # AC_QUIET does something quietly
1324 AC_QUIET() {
1325     eval $* 5>/dev/null
1326 }