3 # autoheader -- create `config.h.in' from `configure.ac'
4 # Copyright 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001
5 # Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 # Written by Roland McGrath.
24 me=`echo "$0" | sed -e 's,.*[/\\],,'`
27 Usage: $0 [OPTION] ... [TEMPLATE-FILE]
29 Create a template file of C \`#define' statements for \`configure' to
30 use. To this end, scan TEMPLATE-FILE, or \`configure.ac' if present,
31 or else \`configure.in'.
33 -h, --help print this help, then exit
34 -V, --version print version number, then exit
35 -v, --verbose verbosely report processing
36 -d, --debug don't remove temporary files
37 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
39 Warning categories include:
40 \`obsolete' obsolete constructs
41 \`all' all the warnings
42 \`no-CATEGORY' turn off the warnings on CATEGORY
43 \`none' turn off all the warnings
44 \`error' warnings are error
47 -A, --autoconf-dir=ACDIR Autoconf's macro files location (rarely needed)
48 -l, --localdir=DIR location of \`aclocal.m4' and \`acconfig.h'
50 Report bugs to <bug-autoconf@gnu.org>."
53 autoheader (@PACKAGE_NAME@) @VERSION@
54 Written by Roland McGrath.
56 Copyright 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001
57 Free Software Foundation, Inc.
58 This is free software; see the source for copying conditions. There is NO
59 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
62 Try \`$me --help' for more information."
65 echo \"$me: option \\\`\$1' requires an argument\" >&2
70 # Only set these to C if already set. These must not be set unconditionally
71 # because not all systems understand e.g. LANG=C (notably SCO).
72 # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
73 # Non-C LC_CTYPE values break the ctype check.
74 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
75 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
76 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
77 if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
80 : ${autoconf_dir=${AC_MACRODIR=@datadir@}}
81 dir=`echo "$0" | sed -e 's,[^/]*$,,'`
82 # We test "$dir/autoconf" in case we are in the build tree, in which case
83 # the names are not transformed yet.
84 for autoconf in "$AUTOCONF" \
85 "$dir/@autoconf-name@" \
87 "@bindir@/@autoconf-name@"; do
88 test -f "$autoconf" && break
97 warning_obsolete=false
100 while test $# -gt 0 ; do
101 optarg=`expr "x$1" : 'x--[^=]*=\(.*\)' \| \
105 echo "$version" ; exit 0 ;;
107 echo "$usage"; exit 0 ;;
115 --localdir=* | -l?* )
119 test $# = 1 && eval "$exit_missing_arg"
124 --autoconf-dir=* | -A?* )
127 --autoconf-dir | -A )
128 test $# = 1 && eval "$exit_missing_arg"
132 --macrodir=* | -m?* )
133 echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2
137 echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2
138 test $# = 1 && eval "$exit_missing_arg"
143 --warnings=* | -W?* )
144 warnings=$warnings,$optarg
147 test $# = 1 && eval "$exit_missing_arg"
149 warnings=$warnings,$1
152 -- ) # Stop option processing
154 - ) # Use stdin as input.
158 echo "$me: invalid option $1"
166 # The warnings are the concatenation of 1. application's defaults
167 # (here, none), 2. $WARNINGS, $3 command line options, in that order.
168 alphabet='abcdefghijklmnopqrstuvwxyz'
169 ALPHABET='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
171 for warning in `IFS=,; echo $WARNINGS,$warnings | tr $ALPHABET $alphabet`
175 no-*) eval warning_`expr x$warning : 'xno-\(.*\)'`=false;;
176 *) eval warning_$warning=:;;
180 # Trap on 0 to stop playing with `rm'.
183 trap 'status=$?; rm -rf $tmp && exit $status' 0
184 trap '(exit 1); exit 1' 1 2 13 15
187 # Create a (secure) tmp directory for tmp files.
190 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/ahXXXXXX") 2>/dev/null` &&
191 test -n "$tmp" && test -d "$tmp"
195 (umask 077 && mkdir $tmp)
198 echo "$me: cannot create a temporary directory in $TMPDIR" >&2
203 if ($warning_all || $warning_obsolete) &&
204 (test -f $config_h.top ||
205 test -f $config_h.bot ||
206 test -f $localdir/acconfig.h); then
207 sed -e "s/^ /$me: WARNING: /" >&2 <<\EOF
208 Using auxiliary files such as `acconfig.h', `config.h.bot'
209 and `config.h.top', to define templates for `config.h.in'
210 is deprecated and discouraged.
212 Using the third argument of `AC_DEFINE' and
213 `AC_DEFINE_UNQUOTED' allows to define a template without
216 AC_DEFINE([NEED_MAIN], 1,
217 [Define if a function `main' is needed.])
219 More sophisticated templates can also be produced, see the
222 $warning_error && { (exit 1); exit 1; }
226 test -r $localdir/acconfig.h && acconfigs="$acconfigs $localdir/acconfig.h"
228 # Find the input file.
231 case `ls configure.ac configure.in 2>/dev/null` in
233 echo "$me: warning: both \`configure.ac' and \`configure.in' are present." >&2
234 echo "$me: warning: proceeding with \`configure.ac'." >&2
235 infile=configure.ac;;
236 *ac ) infile=configure.ac;;
237 *in ) infile=configure.in;;
239 echo "$me: no input file" >&2
244 echo "$me: invalid number of arguments."
250 autoconf="$autoconf -l $localdir"
253 # ----------------------- #
254 # Real work starts here. #
255 # ----------------------- #
257 # Source what the traces are trying to tell us.
258 $verbose $me: running $autoconf to trace from $infile >&2
260 --trace AC_CONFIG_HEADERS:': $${config_h="$1"}' \
261 --trace AH_OUTPUT:'ac_verbatim_$1="\
263 --trace AC_DEFINE_TRACE_LITERAL:'syms="$$syms $1"' \
264 $infile >$tmp/traces.sh || { (exit 1); exit 1; }
266 $verbose $me: sourcing $tmp/traces.sh >&2
267 if (set -e && . $tmp/traces.sh) >/dev/null 2>&1; then
270 echo "$me: error: shell error while sourcing $tmp/traces.sh" >&2
275 # Make SYMS newline-separated rather than blank-separated, and remove dups.
276 # Start each symbol with a blank (to match the blank after "#undef")
277 # to reduce the possibility of mistakenly matching another symbol that
278 # is a substring of it.
279 # Beware that some of the symbols might actually be macro with arguments:
280 # keep only their name.
281 syms=`for sym in $syms; do echo $sym; done |
288 # We template only the first CONFIG_HEADER.
289 config_h=`set X $config_h; echo $2`
290 # Support "outfile[:infile]", defaulting infile="outfile.in".
292 "") echo "$me: error: AC_CONFIG_HEADERS not found in $infile" >&2
294 *:*) config_h_in=`echo "$config_h" | sed 's/.*://'`
295 config_h=`echo "$config_h" | sed 's/:.*//'` ;;
296 *) config_h_in="$config_h.in" ;;
299 # Don't write "do not edit" -- it will get copied into the
300 # config.h, which it's ok to edit.
301 cat <<EOF >$tmp/config.hin
302 /* $config_h_in. Generated automatically from $infile by autoheader. */
306 test -r $config_h.top && cat $config_h.top >>$tmp/config.hin
308 # Dump `acconfig.h' but its bottom.
309 test -r $localdir/acconfig.h &&
310 sed '/@BOTTOM@/,$d;s/@TOP@//' $localdir/acconfig.h >>$tmp/config.hin
312 # Dump the templates from `configure.ac'.
313 for verb in `(set) 2>&1 | sed -n -e '/^ac_verbatim/s/^\([^=]*\)=.*$/\1/p' | sort`; do
315 cat >>$tmp/config.hin <<EOF
321 # Handle the case where @BOTTOM@ is the first line of acconfig.h.
322 test -r $localdir/acconfig.h &&
323 grep @BOTTOM@ $localdir/acconfig.h >/dev/null &&
324 sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h >>$tmp/config.hin
325 test -f $config_h.bot && cat $config_h.bot >>$tmp/config.hin
328 # Check that all the symbols have a template.
329 $verbose $me: checking completeness of the template >&2
330 # Regexp for a white space.
332 if test -n "$syms"; then
334 if egrep "^#$w*[a-z]*$w$w*$sym($w*|$w.*)$" $tmp/config.hin >/dev/null; then
337 echo "$me: No template for symbol \`$sym'" >&2
344 # If the run was successful, output the result.
345 if test $status = 0; then
348 if test -f $config_h_in && cmp -s $tmp/config.hin $config_h_in; then
349 # File didn't change, so don't update its mod time.
350 echo "$me: $config_h_in is unchanged" >&2
352 mv -f $tmp/config.hin $config_h_in
360 (exit $status); exit $status