2 # autoheader -- create `config.h.in' from `configure.in'
3 # Copyright (C) 1992, 1993, 1994, 1996, 1998 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)
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., 59 Temple Place - Suite 330, Boston, MA
20 # Written by Roland McGrath.
22 # If given no args, create `config.h.in' from template file `configure.in'.
23 # With one arg, create a header file on standard output from
24 # the given template file.
27 Usage: autoheader [-h] [--help] [-m dir] [--macrodir=dir]
28 [-l dir] [--localdir=dir] [--version] [template-file]"
31 # Only set these to C if already set. These must not be set unconditionally
32 # because not all systems understand e.g. LANG=C (notably SCO).
33 # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
34 # Non-C LC_CTYPE values break the ctype check.
35 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
36 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
37 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
38 if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
40 test -z "${AC_MACRODIR}" && AC_MACRODIR=@datadir@
41 test -z "${M4}" && M4=@M4@
43 /*) # Handle the case that m4 has moved since we were configured.
44 # It may have been found originally in a build directory.
45 test -f "${M4}" || M4=m4 ;;
51 while test $# -gt 0 ; do
54 echo "${usage}"; exit 0 ;;
55 --localdir=* | --l*=* )
56 localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
58 -l | --localdir | --l*)
60 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
63 --macrodir=* | --m*=* )
64 AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
66 -m | --macrodir | --m* )
68 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
72 show_version=yes; shift ;;
73 -- ) # Stop option processing
75 - ) # Use stdin as input.
78 echo "${usage}" 1>&2; exit 1 ;;
84 if test $show_version = yes; then
85 version=`sed -n 's/define.AC_ACVERSION.[ ]*\([0-9.]*\).*/\1/p' \
86 $AC_MACRODIR/acgeneral.m4`
87 echo "Autoconf version $version"
91 TEMPLATES="${AC_MACRODIR}/acconfig.h"
92 test -r $localdir/acconfig.h && TEMPLATES="${TEMPLATES} $localdir/acconfig.h"
95 0) infile=configure.in ;;
97 *) echo "$usage" >&2; exit 1 ;;
107 if test "$localdir" != .; then
108 use_localdir="-I$localdir -DAC_LOCALDIR=$localdir"
113 # Use the frozen version of Autoconf if available.
115 # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
116 case `$M4 --help < /dev/null 2>&1` in
117 *reload-state*) test -r $AC_MACRODIR/autoheader.m4f && { r=--reload f=f; } ;;
119 *) echo Autoconf requires GNU m4 1.1 or later >&2; exit 1 ;;
122 # Extract assignments of SYMS, TYPES, FUNCS, HEADERS, and LIBS from the
123 # modified autoconf processing of the input file. The sed hair is
124 # necessary to win for multi-line macro invocations.
125 eval "`$M4 -I$AC_MACRODIR $use_localdir $r autoheader.m4$f $infile |
128 /^@@@.*@@@$/s/^@@@\(.*\)@@@$/\1/p
136 # Make SYMS newline-separated rather than blank-separated, and remove dups.
137 # Start each symbol with a blank (to match the blank after "#undef")
138 # to reduce the possibility of mistakenly matching another symbol that
139 # is a substring of it.
140 syms="`for sym in $syms; do echo $sym; done | sort | uniq | sed 's@^@ @'`"
142 if test $# -eq 0; then
144 trap "rm -f $tmpout; exit 1" 1 2 15
148 # Support "outfile[:infile]", defaulting infile="outfile.in".
150 *:*) config_h_in=`echo "$config_h"|sed 's%.*:%%'`
151 config_h=`echo "$config_h"|sed 's%:.*%%'` ;;
152 *) config_h_in="${config_h}.in" ;;
155 # Don't write "do not edit" -- it will get copied into the
156 # config.h, which it's ok to edit.
158 /* ${config_h_in}. Generated automatically from $infile by autoheader. */
161 test -r ${config_h}.top && cat ${config_h}.top
162 test -r $localdir/acconfig.h &&
163 grep @TOP@ $localdir/acconfig.h >/dev/null &&
164 sed '/@TOP@/,$d' $localdir/acconfig.h
166 # This puts each template paragraph on its own line, separated by @s.
167 if test -n "$syms"; then
168 # Make sure the boundary of template files is also the boundary
169 # of the paragraph. Extra newlines don't hurt since they will
171 # Undocumented useless feature: stuff outside of @TOP@ and @BOTTOM@
172 # is ignored in the systemwide acconfig.h too.
173 for t in $TEMPLATES; do
175 grep @TOP@ $t >/dev/null && sedscript="1,/@TOP@/d;"
176 grep @BOTTOM@ $t >/dev/null && sedscript="$sedscript /@BOTTOM@/,\$d;"
177 # This substitution makes "#undef<TAB>FOO" in acconfig.h work.
178 sed -n -e "$sedscript s/ / /g; p" $t
181 # The sed script is suboptimal because it has to take care of
182 # some broken seds (e.g. AIX) that remove '\n' from the
183 # pattern/hold space if the line is empty. (junio@twinsun.com).
192 H' | sed -e 's/@@*/@/g' |
193 # Select each paragraph that refers to a symbol we picked out above.
194 # Some fgrep's have limits on the number of lines that can be in the
195 # pattern on the command line, so use a temporary file containing the
197 (fgrep_tmp=${TMPDIR-/tmp}/autoh$$
198 trap "rm -f $fgrep_tmp; exit 1" 1 2 15
199 cat > $fgrep_tmp <<EOF
207 echo "$types" | tr , \\012 | sort | uniq | while read ctype; do
208 test -z "$ctype" && continue
209 sym="`echo "${ctype}" | tr 'abcdefghijklmnopqrstuvwxyz *' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_P'`"
211 /* The number of bytes in a ${ctype}. */
212 #undef SIZEOF_${sym}"
215 # /bin/sh on the Alpha gives `for' a random value if $funcs is empty.
216 if test -n "$funcs"; then
217 for func in `for x in $funcs; do echo $x; done | sort | uniq`; do
218 sym="`echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
220 /* Define if you have the ${func} function. */
225 if test -n "$headers"; then
226 for header in `for x in $headers; do echo $x; done | sort | uniq`; do
228 sym="`echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
230 /* Define if you have the <${header}> header file. */
235 if test -n "$libs"; then
236 for lib in `for x in $libs; do echo $x; done | sort | uniq`; do
237 sym="`echo ${lib} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
239 /* Define if you have the ${lib} library (-l${lib}). */
240 #undef HAVE_LIB${sym}"
244 if test -n "$verbatim"; then
248 # Handle the case where @BOTTOM@ is the first line of acconfig.h.
249 test -r $localdir/acconfig.h &&
250 grep @BOTTOM@ $localdir/acconfig.h >/dev/null &&
251 sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h
252 test -f ${config_h}.bot && cat ${config_h}.bot
256 if test -n "$syms"; then
258 if fgrep $sym $TEMPLATES >/dev/null; then
261 echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
267 if test $# -eq 0; then
268 if test $status -eq 0; then
269 if test -f ${config_h_in} && cmp -s $tmpout ${config_h_in}; then
270 rm -f $tmpout # File didn't change, so don't update its mod time.
272 mv -f $tmpout ${config_h_in}