[3157] | 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 |
|
---|
| 26 | usage="\
|
---|
| 27 | Usage: 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.
|
---|
| 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
|
---|
| 39 |
|
---|
| 40 | test -z "${AC_MACRODIR}" && AC_MACRODIR=@datadir@
|
---|
| 41 | test -z "${M4}" && M4=@M4@
|
---|
| 42 | case "${M4}" in
|
---|
| 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 ;;
|
---|
| 46 | esac
|
---|
| 47 |
|
---|
| 48 | localdir=.
|
---|
| 49 | show_version=no
|
---|
| 50 |
|
---|
| 51 | while test $# -gt 0 ; do
|
---|
| 52 | case "${1}" in
|
---|
| 53 | -h | --help | --h* )
|
---|
| 54 | echo "${usage}"; exit 0 ;;
|
---|
| 55 | --localdir=* | --l*=* )
|
---|
| 56 | localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
|
---|
| 57 | shift ;;
|
---|
| 58 | -l | --localdir | --l*)
|
---|
| 59 | shift
|
---|
| 60 | test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
|
---|
| 61 | localdir="${1}"
|
---|
| 62 | shift ;;
|
---|
| 63 | --macrodir=* | --m*=* )
|
---|
| 64 | AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
|
---|
| 65 | shift ;;
|
---|
| 66 | -m | --macrodir | --m* )
|
---|
| 67 | shift
|
---|
| 68 | test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
|
---|
| 69 | AC_MACRODIR="${1}"
|
---|
| 70 | shift ;;
|
---|
| 71 | --version | --v* )
|
---|
| 72 | show_version=yes; shift ;;
|
---|
| 73 | -- ) # Stop option processing
|
---|
| 74 | shift; break ;;
|
---|
| 75 | - ) # Use stdin as input.
|
---|
| 76 | break ;;
|
---|
| 77 | -* )
|
---|
| 78 | echo "${usage}" 1>&2; exit 1 ;;
|
---|
| 79 | * )
|
---|
| 80 | break ;;
|
---|
| 81 | esac
|
---|
| 82 | done
|
---|
| 83 |
|
---|
| 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"
|
---|
| 88 | exit 0
|
---|
| 89 | fi
|
---|
| 90 |
|
---|
| 91 | TEMPLATES="${AC_MACRODIR}/acconfig.h"
|
---|
| 92 | test -r $localdir/acconfig.h && TEMPLATES="${TEMPLATES} $localdir/acconfig.h"
|
---|
| 93 |
|
---|
| 94 | case $# in
|
---|
| 95 | 0) infile=configure.in ;;
|
---|
| 96 | 1) infile=$1 ;;
|
---|
| 97 | *) echo "$usage" >&2; exit 1 ;;
|
---|
| 98 | esac
|
---|
| 99 |
|
---|
| 100 | config_h=config.h
|
---|
| 101 | syms=
|
---|
| 102 | types=
|
---|
| 103 | funcs=
|
---|
| 104 | headers=
|
---|
| 105 | libs=
|
---|
| 106 |
|
---|
| 107 | if test "$localdir" != .; then
|
---|
| 108 | use_localdir="-I$localdir -DAC_LOCALDIR=$localdir"
|
---|
| 109 | else
|
---|
| 110 | use_localdir=
|
---|
| 111 | fi
|
---|
| 112 |
|
---|
| 113 | # Use the frozen version of Autoconf if available.
|
---|
| 114 | r= f=
|
---|
| 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; } ;;
|
---|
| 118 | *traditional*) ;;
|
---|
| 119 | *) echo Autoconf requires GNU m4 1.1 or later >&2; exit 1 ;;
|
---|
| 120 | esac
|
---|
| 121 |
|
---|
| 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 |
|
---|
| 126 | sed -n -e '
|
---|
| 127 | : again
|
---|
| 128 | /^@@@.*@@@$/s/^@@@\(.*\)@@@$/\1/p
|
---|
| 129 | /^@@@/{
|
---|
| 130 | s/^@@@//p
|
---|
| 131 | n
|
---|
| 132 | s/^/@@@/
|
---|
| 133 | b again
|
---|
| 134 | }'`"
|
---|
| 135 |
|
---|
| 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@^@ @'`"
|
---|
| 141 |
|
---|
| 142 | if test $# -eq 0; then
|
---|
| 143 | tmpout=autoh$$
|
---|
| 144 | trap "rm -f $tmpout; exit 1" 1 2 15
|
---|
| 145 | exec > $tmpout
|
---|
| 146 | fi
|
---|
| 147 |
|
---|
| 148 | # Support "outfile[:infile]", defaulting infile="outfile.in".
|
---|
| 149 | case "$config_h" 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" ;;
|
---|
| 153 | esac
|
---|
| 154 |
|
---|
| 155 | # Don't write "do not edit" -- it will get copied into the
|
---|
| 156 | # config.h, which it's ok to edit.
|
---|
| 157 | cat <<EOF
|
---|
| 158 | /* ${config_h_in}. Generated automatically from $infile by autoheader. */
|
---|
| 159 | EOF
|
---|
| 160 |
|
---|
| 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
|
---|
| 165 |
|
---|
| 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
|
---|
| 170 | # be removed.
|
---|
| 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
|
---|
| 174 | sedscript=""
|
---|
| 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
|
---|
| 179 | echo; echo
|
---|
| 180 | done |
|
---|
| 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).
|
---|
| 184 | sed -n -e '
|
---|
| 185 | /^[ ]*$/{
|
---|
| 186 | x
|
---|
| 187 | s/\n/@/g
|
---|
| 188 | p
|
---|
| 189 | s/.*/@/
|
---|
| 190 | x
|
---|
| 191 | }
|
---|
| 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
|
---|
| 196 | # pattern.
|
---|
| 197 | (fgrep_tmp=${TMPDIR-/tmp}/autoh$$
|
---|
| 198 | trap "rm -f $fgrep_tmp; exit 1" 1 2 15
|
---|
| 199 | cat > $fgrep_tmp <<EOF
|
---|
| 200 | $syms
|
---|
| 201 | EOF
|
---|
| 202 | fgrep -f $fgrep_tmp
|
---|
| 203 | rm -f $fgrep_tmp) |
|
---|
| 204 | tr @ \\012
|
---|
| 205 | fi
|
---|
| 206 |
|
---|
| 207 | echo "$types" | tr , \\012 | sort | uniq | while read ctype; do
|
---|
| 208 | test -z "$ctype" && continue
|
---|
| 209 | sym="`echo "${ctype}" | tr 'abcdefghijklmnopqrstuvwxyz *' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_P'`"
|
---|
| 210 | echo "
|
---|
| 211 | /* The number of bytes in a ${ctype}. */
|
---|
| 212 | #undef SIZEOF_${sym}"
|
---|
| 213 | done
|
---|
| 214 |
|
---|
| 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'`"
|
---|
| 219 | echo "
|
---|
| 220 | /* Define if you have the ${func} function. */
|
---|
| 221 | #undef HAVE_${sym}"
|
---|
| 222 | done
|
---|
| 223 | fi
|
---|
| 224 |
|
---|
| 225 | if test -n "$headers"; then
|
---|
| 226 | for header in `for x in $headers; do echo $x; done | sort | uniq`; do
|
---|
| 227 |
|
---|
| 228 | sym="`echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
|
---|
| 229 | echo "
|
---|
| 230 | /* Define if you have the <${header}> header file. */
|
---|
| 231 | #undef HAVE_${sym}"
|
---|
| 232 | done
|
---|
| 233 | fi
|
---|
| 234 |
|
---|
| 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'`"
|
---|
| 238 | echo "
|
---|
| 239 | /* Define if you have the ${lib} library (-l${lib}). */
|
---|
| 240 | #undef HAVE_LIB${sym}"
|
---|
| 241 | done
|
---|
| 242 | fi
|
---|
| 243 |
|
---|
| 244 | if test -n "$verbatim"; then
|
---|
| 245 | echo "$verbatim"
|
---|
| 246 | fi
|
---|
| 247 |
|
---|
| 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
|
---|
| 253 |
|
---|
| 254 | status=0
|
---|
| 255 |
|
---|
| 256 | if test -n "$syms"; then
|
---|
| 257 | for sym in $syms; do
|
---|
| 258 | if fgrep $sym $TEMPLATES >/dev/null; then
|
---|
| 259 | : # All is well.
|
---|
| 260 | else
|
---|
| 261 | echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
|
---|
| 262 | status=1
|
---|
| 263 | fi
|
---|
| 264 | done
|
---|
| 265 | fi
|
---|
| 266 |
|
---|
| 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.
|
---|
| 271 | else
|
---|
| 272 | mv -f $tmpout ${config_h_in}
|
---|
| 273 | fi
|
---|
| 274 | else
|
---|
| 275 | rm -f $tmpout
|
---|
| 276 | fi
|
---|
| 277 | fi
|
---|
| 278 |
|
---|
| 279 | exit $status
|
---|