sendmail transition: Do not pre-generate sendmail.cf
[dragonfly.git] / contrib / sendmail-8.14 / devtools / bin / find_m4.sh
1 #!/bin/sh
2
3 # Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
4 #       All rights reserved.
5 #
6 # By using this file, you agree to the terms and conditions set
7 # forth in the LICENSE file which can be found at the top level of
8 # the sendmail distribution.
9 #
10 #
11 #       $Id: find_m4.sh,v 8.13 2001/01/23 01:47:45 gshapiro Exp $
12 #
13
14 # Try to find a working M4 program.
15 # If $M4 is already set, we use it, otherwise we prefer GNU m4.
16
17 EX_UNAVAILABLE=69
18
19 test="ifdef(\`pushdef', \`',
20 \`errprint(\`You need a newer version of M4, at least as new as System V or GNU')
21 include(NoSuchFile)')
22 define(\`BadNumber', \`10')
23 ifdef(\`BadNumber', \`',
24 \`errprint(\`This version of m4 is broken: trailing zero problem')
25 include(NoSuchFile)')
26 define(\`LongList', \` assert.c debug.c exc.c heap.c match.c rpool.c strdup.c strerror.c strl.c clrerr.c fclose.c feof.c ferror.c fflush.c fget.c fpos.c findfp.c flags.c fopen.c fprintf.c fpurge.c fput.c fread.c fscanf.c fseek.c fvwrite.c fwalk.c fwrite.c get.c makebuf.c put.c refill.c rewind.c rget.c setvbuf.c smstdio.c snprintf.c sscanf.c stdio.c strio.c syslogio.c ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vsnprintf.c vsprintf.c vsscanf.c wbuf.c wsetup.c stringf.c xtrap.c strto.c test.c path.c strcasecmp.c signal.c clock.c config.c shm.c ')
27 define(\`SameList', \`substr(LongList, 0, index(LongList, \`.'))\`'substr(LongList, index(LongList, \`.'))')
28 ifelse(len(LongList), len(SameList), \`',
29 \`errprint(\`This version of m4 is broken: length problem')
30 include(NoSuchFile)')"
31
32 if [ "$M4" ]
33 then
34         err="`(echo "$test" | $M4) 2>&1 >/dev/null`"
35         code=$?
36 else
37         firstfound=
38         ifs="$IFS"; IFS="${IFS}:"
39         for m4 in gm4 gnum4 pdm4 m4
40         do
41                 for dir in $PATH /usr/5bin /usr/ccs/bin
42                 do
43                         [ -z "$dir" ] && dir=.
44                         if [ -f $dir/$m4 ]
45                         then
46                                 err="`(echo "$test" | $dir/$m4) 2>&1 >/dev/null`"
47                                 ret=$?
48                                 if [ $ret -eq 0 -a "X$err" = "X" ]
49                                 then
50                                         M4=$dir/$m4
51                                         code=0
52                                         break
53                                 else
54                                         case "$firstfound:$err" in
55                                           :*version\ of*)
56                                                 firstfound=$dir/$m4
57                                                 firsterr="$err"
58                                                 firstcode=$ret
59                                                 ;;
60                                         esac
61                                 fi
62                         fi
63                 done
64                 [ "$M4" ] && break
65         done
66         IFS="$ifs"
67         if [ ! "$M4" ]
68         then
69                 if [ "$firstfound" ]
70                 then
71                         M4=$firstfound
72                         err="$firsterr"
73                         code=$firstcode
74                 else
75                         echo "ERROR: Can not locate an M4 program" >&2
76                         exit $EX_UNAVAILABLE
77                 fi
78         fi
79 fi
80 if [ $code -ne 0 ]
81 then
82         echo "ERROR: Using M4=$M4: $err" | grep -v NoSuchFile >&2
83         exit $EX_UNAVAILABLE
84 elif [ "X$err" != "X" ]
85 then
86         echo "WARNING: $err" >&2
87 fi
88 echo $M4
89 exit 0