*** empty log message ***
[autoconf.git] / autoconf.sh
blob5ae95c710a447c0fb7682424a406b016673f0c96
1 #!/bin/sh
2 # autoconf -- create `configure' using m4 macros
3 # Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # If given no args, create `configure' from template file `configure.in'.
20 # With one arg, create a configure script on standard output from
21 # the given template file.
23 usage="\
24 Usage: autoconf [-h] [--help] [-m dir] [--macrodir=dir]
25 [-l dir] [--localdir=dir] [--version] [template-file]"
27 # NLS nuisances.
28 # Only set `LANG' and `LC_ALL' to "C" if already set.
29 # These must not be set unconditionally because not all systems understand
30 # e.g. LANG=C (notably SCO).
31 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
32 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
34 test -z "${AC_MACRODIR}" && AC_MACRODIR=@datadir@
35 test -z "${M4}" && M4=@M4@
36 case "${M4}" in
37 /*) # Handle the case that m4 has moved since we were configured.
38 # It may have been found originally in a build directory.
39 test -f "${M4}" || M4=m4 ;;
40 esac
42 tmpout=/tmp/acout.$$
43 localdir=
44 show_version=no
46 while test $# -gt 0 ; do
47 case "${1}" in
48 -h | --help | --h* )
49 echo "${usage}" 1>&2; exit 0 ;;
50 --localdir=* | --l*=* )
51 localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
52 shift ;;
53 -l | --localdir | --l*)
54 shift
55 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
56 localdir="${1}"
57 shift ;;
58 --macrodir=* | --m*=* )
59 AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
60 shift ;;
61 -m | --macrodir | --m* )
62 shift
63 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
64 AC_MACRODIR="${1}"
65 shift ;;
66 --version | --v* )
67 show_version=yes; shift ;;
68 -- ) # Stop option processing
69 shift; break ;;
70 - ) # Use stdin as input.
71 break ;;
72 -* )
73 echo "${usage}" 1>&2; exit 1 ;;
74 * )
75 break ;;
76 esac
77 done
79 if test $show_version = yes; then
80 version=`sed -n 's/define.AC_ACVERSION.[ ]*\([0-9.]*\).*/\1/p' \
81 $AC_MACRODIR/acgeneral.m4`
82 echo "Autoconf version $version"
83 exit 0
86 case $# in
87 0) infile=configure.in ;;
88 1) infile="$1" ;;
89 *) echo "$usage" >&2; exit 1 ;;
90 esac
92 trap 'rm -f $tmpin $tmpout; exit 1' 1 2 15
94 tmpin=/tmp/acin.$$ # Always set this, to avoid bogus errors from some rm's.
95 if test z$infile = z-; then
96 infile=$tmpin
97 cat > $infile
98 elif test ! -r "$infile"; then
99 echo "autoconf: ${infile}: No such file or directory" >&2
100 exit 1
103 if test -n "$localdir"; then
104 use_localdir="-I$localdir -DAC_LOCALDIR=$localdir"
105 else
106 use_localdir=
109 # Use the frozen version of Autoconf if available.
110 r= f=
111 # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
112 case `$M4 --help < /dev/null 2>&1` in
113 *reload-state*) test -r $AC_MACRODIR/autoconf.m4f && { r=--reload f=f; } ;;
114 *traditional*) ;;
115 *) echo Autoconf requires GNU m4 1.1 or later >&2; rm -f $tmpin; exit 1 ;;
116 esac
118 $M4 -I$AC_MACRODIR $use_localdir $r autoconf.m4$f $infile > $tmpout ||
119 { rm -f $tmpin $tmpout; exit 2; }
121 # You could add your own prefixes to pattern if you wanted to check for
122 # them too, e.g. pattern="AC_\|ILT_", except that UNIX sed doesn't do
123 # alternation.
124 pattern="AC_"
126 status=0
127 if grep "${pattern}" $tmpout > /dev/null 2>&1; then
128 echo "autoconf: Undefined macros:" >&2
129 grep "${pattern}" $tmpout | sed "s/.*\(${pattern}[_A-Z0-9]*\).*/\1/" |
130 while read name; do
131 grep -n $name $infile /dev/null
132 done | sort -u >&2
133 status=1
136 if test $# -eq 0; then
137 exec 4> configure; chmod +x configure
138 else
139 exec 4>&1
142 # Put the real line numbers into configure to make config.log more helpful.
143 awk '
144 /__oline__/ { printf "%d:", NR + 1 }
145 { print }
146 ' $tmpout | sed '
147 /__oline__/s/^\([0-9][0-9]*\):\(.*\)__oline__\(.*\)$/\2\1\3/
148 ' >&4
150 rm -f $tmpout
152 exit $status