source: trunk/essentials/sys-devel/autoconf-2.13/autoheader.sh@ 3275

Last change on this file since 3275 was 3159, checked in by bird, 18 years ago

Applied OS/2 patches.

File size: 8.7 KB
Line 
1#! @SHELL@
2# autoheader -- create `config.h.in' from `configure.in'
3# Copyright (C) 1992, 1993, 1994, 1996, 1998 Free Software Foundation, Inc.
4
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.
9
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.
14
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
18# 02111-1307, USA.
19
20# Written by Roland McGrath.
21
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.
25
26usage="\
27Usage: autoheader [-h] [--help] [-m dir] [--macrodir=dir]
28 [-l dir] [--localdir=dir] [--version] [template-file]"
29
30# NLS nuisances.
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.
35if test "${LANG+set}" = set; then LANG=C; export LANG; fi
36if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
37if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
38if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
39
40if test -z "${AC_MACRODIR}"; then
41 if test -d "${UNIXROOT}@datadir@"; then
42 AC_MACRODIR=${UNIXROOT}@datadir@
43 else
44 AC_MACRODIR=@datadir@
45 fi
46fi
47test -z "${M4}" && M4=@M4@
48case "${M4}" in
49[/\\]*|[a-zA-Z]:*) # Handle the case that m4 has moved since we were configured.
50 # It may have been found originally in a build directory.
51 test -f "${M4}" || M4=m4 ;;
52esac
53
54localdir=.
55show_version=no
56
57while test $# -gt 0 ; do
58 case "${1}" in
59 -h | --help | --h* )
60 echo "${usage}"; exit 0 ;;
61 --localdir=* | --l*=* )
62 localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
63 shift ;;
64 -l | --localdir | --l*)
65 shift
66 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
67 localdir="${1}"
68 shift ;;
69 --macrodir=* | --m*=* )
70 AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
71 shift ;;
72 -m | --macrodir | --m* )
73 shift
74 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
75 AC_MACRODIR="${1}"
76 shift ;;
77 --version | --v* )
78 show_version=yes; shift ;;
79 -- ) # Stop option processing
80 shift; break ;;
81 - ) # Use stdin as input.
82 break ;;
83 -* )
84 echo "${usage}" 1>&2; exit 1 ;;
85 * )
86 break ;;
87 esac
88done
89
90if test $show_version = yes; then
91 version=`sed -n 's/define.AC_ACVERSION.[ ]*\([0-9.]*\).*/\1/p' \
92 $AC_MACRODIR/acgeneral.m4`
93 echo "Autoconf version $version"
94 exit 0
95fi
96
97TEMPLATES="${AC_MACRODIR}/acconfig.h"
98test -r $localdir/acconfig.h && TEMPLATES="${TEMPLATES} $localdir/acconfig.h"
99
100case $# in
101 0) infile=configure.in ;;
102 1) infile=$1 ;;
103 *) echo "$usage" >&2; exit 1 ;;
104esac
105
106config_h=config.h
107syms=
108types=
109funcs=
110headers=
111libs=
112
113if test "$localdir" != .; then
114 use_localdir="-I$localdir -DAC_LOCALDIR=$localdir"
115else
116 use_localdir=
117fi
118
119# Use the frozen version of Autoconf if available.
120r= f=
121# Some non-GNU m4's don't reject the --help option, so give them /dev/null.
122case `$M4 --help < /dev/null 2>&1` in
123*reload-state*) test -r $AC_MACRODIR/autoheader.m4f && { r=--reload f=f; } ;;
124*traditional*) ;;
125*) echo Autoconf requires GNU m4 1.1 or later >&2; exit 1 ;;
126esac
127
128# Extract assignments of SYMS, TYPES, FUNCS, HEADERS, and LIBS from the
129# modified autoconf processing of the input file. The sed hair is
130# necessary to win for multi-line macro invocations.
131eval "`$M4 -I$AC_MACRODIR $use_localdir $r autoheader.m4$f $infile |
132 sed -n -e '
133 : again
134 /^@@@.*@@@$/s/^@@@\(.*\)@@@$/\1/p
135 /^@@@/{
136 s/^@@@//p
137 n
138 s/^/@@@/
139 b again
140 }'`"
141
142# Make SYMS newline-separated rather than blank-separated, and remove dups.
143# Start each symbol with a blank (to match the blank after "#undef")
144# to reduce the possibility of mistakenly matching another symbol that
145# is a substring of it.
146syms="`for sym in $syms; do echo $sym; done | sort | uniq | sed 's@^@ @'`"
147
148if test $# -eq 0; then
149 tmpout=autoh$$
150 trap "rm -f $tmpout; exit 1" 1 2 15
151 exec > $tmpout
152fi
153
154# Support "outfile[:infile]", defaulting infile="outfile.in".
155case "$config_h" in
156*:*) config_h_in=`echo "$config_h"|sed 's%.*:%%'`
157 config_h=`echo "$config_h"|sed 's%:.*%%'` ;;
158*) config_h_in="${config_h}.in" ;;
159esac
160
161# Don't write "do not edit" -- it will get copied into the
162# config.h, which it's ok to edit.
163cat <<EOF
164/* ${config_h_in}. Generated automatically from $infile by autoheader. */
165EOF
166
167test -r ${config_h}.top && cat ${config_h}.top
168test -r $localdir/acconfig.h &&
169 grep @TOP@ $localdir/acconfig.h >/dev/null &&
170 sed '/@TOP@/,$d' $localdir/acconfig.h
171
172# This puts each template paragraph on its own line, separated by @s.
173if test -n "$syms"; then
174 # Make sure the boundary of template files is also the boundary
175 # of the paragraph. Extra newlines don't hurt since they will
176 # be removed.
177 # Undocumented useless feature: stuff outside of @TOP@ and @BOTTOM@
178 # is ignored in the systemwide acconfig.h too.
179 for t in $TEMPLATES; do
180 sedscript=""
181 grep @TOP@ $t >/dev/null && sedscript="1,/@TOP@/d;"
182 grep @BOTTOM@ $t >/dev/null && sedscript="$sedscript /@BOTTOM@/,\$d;"
183 # This substitution makes "#undef<TAB>FOO" in acconfig.h work.
184 sed -n -e "$sedscript s/ / /g; p" $t
185 echo; echo
186 done |
187 # The sed script is suboptimal because it has to take care of
188 # some broken seds (e.g. AIX) that remove '\n' from the
189 # pattern/hold space if the line is empty. (junio@twinsun.com).
190 sed -n -e '
191 /^[ ]*$/{
192 x
193 s/\n/@/g
194 p
195 s/.*/@/
196 x
197 }
198 H' | sed -e 's/@@*/@/g' |
199 # Select each paragraph that refers to a symbol we picked out above.
200 # Some fgrep's have limits on the number of lines that can be in the
201 # pattern on the command line, so use a temporary file containing the
202 # pattern.
203 (fgrep_tmp=${TMPDIR-/tmp}/autoh$$
204 trap "rm -f $fgrep_tmp; exit 1" 1 2 15
205 cat > $fgrep_tmp <<EOF
206$syms
207EOF
208 fgrep -f $fgrep_tmp
209 rm -f $fgrep_tmp) |
210 tr @ \\012
211fi
212
213echo "$types" | tr , \\012 | sort | uniq | while read ctype; do
214 test -z "$ctype" && continue
215 sym="`echo "${ctype}" | tr 'abcdefghijklmnopqrstuvwxyz *' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_P'`"
216 echo "
217/* The number of bytes in a ${ctype}. */
218#undef SIZEOF_${sym}"
219done
220
221# /bin/sh on the Alpha gives `for' a random value if $funcs is empty.
222if test -n "$funcs"; then
223 for func in `for x in $funcs; do echo $x; done | sort | uniq`; do
224 sym="`echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
225 echo "
226/* Define if you have the ${func} function. */
227#undef HAVE_${sym}"
228 done
229fi
230
231if test -n "$headers"; then
232 for header in `for x in $headers; do echo $x; done | sort | uniq`; do
233
234 sym="`echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
235 echo "
236/* Define if you have the <${header}> header file. */
237#undef HAVE_${sym}"
238 done
239fi
240
241if test -n "$libs"; then
242 for lib in `for x in $libs; do echo $x; done | sort | uniq`; do
243 sym="`echo ${lib} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
244 echo "
245/* Define if you have the ${lib} library (-l${lib}). */
246#undef HAVE_LIB${sym}"
247 done
248fi
249
250if test -n "$verbatim"; then
251 echo "$verbatim"
252fi
253
254# Handle the case where @BOTTOM@ is the first line of acconfig.h.
255test -r $localdir/acconfig.h &&
256 grep @BOTTOM@ $localdir/acconfig.h >/dev/null &&
257 sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h
258test -f ${config_h}.bot && cat ${config_h}.bot
259
260status=0
261
262if test -n "$syms"; then
263 for sym in $syms; do
264 if fgrep $sym $TEMPLATES >/dev/null; then
265 : # All is well.
266 else
267 echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
268 status=1
269 fi
270 done
271fi
272
273if test $# -eq 0; then
274 # bird: OS/2 hack here for missing link counting.
275 exec 2>&1
276 if test $status -eq 0; then
277 if test -f ${config_h_in} && cmp -s $tmpout ${config_h_in}; then
278 rm -f $tmpout # File didn't change, so don't update its mod time.
279 else
280 # bird: Do a copy just to be on the safe side.
281 cp -f $tmpout ${config_h_in}
282 rm -f $tmpout
283 fi
284 else
285 rm -f $tmpout
286 fi
287fi
288
289exit $status
Note: See TracBrowser for help on using the repository browser.