1#! @SHELL@ 2# -*- shell-script -*- 3# autoheader -- create `config.h.in' from `configure.ac' 4# Copyright 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001 5# Free Software Foundation, Inc. 6 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) 10# any later version. 11 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. 16 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 20# 02111-1307, USA. 21 22# Written by Roland McGrath. 23 24me=`echo "$0" | sed -e 's,.*[/\\],,'` 25 26usage="\ 27Usage: $0 [OPTION] ... [TEMPLATE-FILE] 28 29Create a template file of C \`#define' statements for \`configure' to 30use. To this end, scan TEMPLATE-FILE, or \`configure.ac' if present, 31or else \`configure.in'. 32 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 38 39Warning 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 45 46Library directories: 47 -A, --autoconf-dir=ACDIR Autoconf's macro files location (rarely needed) 48 -l, --localdir=DIR location of \`aclocal.m4' and \`acconfig.h' 49 50Report bugs to <bug-autoconf@gnu.org>." 51 52version="\ 53autoheader (@PACKAGE_NAME@) @VERSION@ 54Written by Roland McGrath. 55 56Copyright 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001 57Free Software Foundation, Inc. 58This is free software; see the source for copying conditions. There is NO 59warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 60 61help="\ 62Try \`$me --help' for more information." 63 64exit_missing_arg="\ 65echo \"$me: option \\\`\$1' requires an argument\" >&2 66echo \"\$help\" >&2 67exit 1" 68 69# NLS nuisances. 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. 74if test "${LANG+set}" = set; then LANG=C; export LANG; fi 75if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi 76if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi 77if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi 78 79# Variables. 80: ${autoconf_dir=${AC_MACRODIR=@datadir@}} 81dir=`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. 84for autoconf in "$AUTOCONF" \ 85 "$dir/@autoconf-name@" \ 86 "$dir/autoconf" \ 87 "@bindir@/@autoconf-name@"; do 88 test -f "$autoconf" && break 89done 90debug=false 91localdir=. 92status=0 93tmp= 94verbose=: 95warning_all=false 96warning_error=false 97warning_obsolete=false 98 99# Parse command line. 100while test $# -gt 0 ; do 101 optarg=`expr "x$1" : 'x--[^=]*=\(.*\)' \| \ 102 "x$1" : 'x-.\(.*\)'` 103 case $1 in 104 --version | -V ) 105 echo "$version" ; exit 0 ;; 106 --help | -h ) 107 echo "$usage"; exit 0 ;; 108 109 --debug | -d ) 110 debug=:; shift ;; 111 --verbose | -v ) 112 verbose=echo 113 shift;; 114 115 --localdir=* | -l?* ) 116 localdir=$optarg 117 shift ;; 118 --localdir | -l ) 119 test $# = 1 && eval "$exit_missing_arg" 120 shift 121 localdir=$1 122 shift ;; 123 124 --autoconf-dir=* | -A?* ) 125 autoconf_dir=$optarg 126 shift ;; 127 --autoconf-dir | -A ) 128 test $# = 1 && eval "$exit_missing_arg" 129 shift 130 autoconf_dir=$1 131 shift ;; 132 --macrodir=* | -m?* ) 133 echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2 134 autoconf_dir=$optarg 135 shift ;; 136 --macrodir | -m ) 137 echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2 138 test $# = 1 && eval "$exit_missing_arg" 139 shift 140 autoconf_dir=$1 141 shift ;; 142 143 --warnings=* | -W?* ) 144 warnings=$warnings,$optarg 145 shift ;; 146 --warnings | -W ) 147 test $# = 1 && eval "$exit_missing_arg" 148 shift 149 warnings=$warnings,$1 150 shift ;; 151 152 -- ) # Stop option processing 153 shift; break ;; 154 - ) # Use stdin as input. 155 break ;; 156 -* ) 157 exec >&2 158 echo "$me: invalid option $1" 159 echo "$help" 160 exit 1 ;; 161 * ) 162 break ;; 163 esac 164done 165 166# The warnings are the concatenation of 1. application's defaults 167# (here, none), 2. $WARNINGS, $3 command line options, in that order. 168alphabet='abcdefghijklmnopqrstuvwxyz' 169ALPHABET='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 170_ac_warnings= 171for warning in `IFS=,; echo $WARNINGS,$warnings | tr $ALPHABET $alphabet` 172do 173 case $warning in 174 '' | ,) continue;; 175 no-*) eval warning_`expr x$warning : 'xno-\(.*\)'`=false;; 176 *) eval warning_$warning=:;; 177 esac 178done 179 180# Trap on 0 to stop playing with `rm'. 181$debug || 182{ 183 trap 'status=$?; rm -rf $tmp && exit $status' 0 184 trap '(exit 1); exit 1' 1 2 13 15 185} 186 187# Create a (secure) tmp directory for tmp files. 188: ${TMPDIR=/tmp} 189{ 190 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/ahXXXXXX") 2>/dev/null` && 191 test -n "$tmp" && test -d "$tmp" 192} || 193{ 194 tmp=$TMPDIR/ah$$ 195 (umask 077 && mkdir $tmp) 196} || 197{ 198 echo "$me: cannot create a temporary directory in $TMPDIR" >&2 199 (exit 1); exit 1 200} 201 202# Preach. 203if ($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. 211 212 Using the third argument of `AC_DEFINE' and 213 `AC_DEFINE_UNQUOTED' allows to define a template without 214 `acconfig.h': 215 216 AC_DEFINE([NEED_MAIN], 1, 217 [Define if a function `main' is needed.]) 218 219 More sophisticated templates can also be produced, see the 220 documentation. 221EOF 222 $warning_error && { (exit 1); exit 1; } 223fi 224 225acconfigs= 226test -r $localdir/acconfig.h && acconfigs="$acconfigs $localdir/acconfig.h" 227 228# Find the input file. 229case $# in 230 0) 231 case `ls configure.ac configure.in 2>/dev/null` in 232 *ac*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;; 238 * ) 239 echo "$me: no input file" >&2 240 (exit 1); exit 1;; 241 esac;; 242 1) infile=$1 ;; 243 *) exec >&2 244 echo "$me: invalid number of arguments." 245 echo "$help" 246 (exit 1); exit 1;; 247esac 248 249# Set up autoconf. 250autoconf="$autoconf -l $localdir" 251export autoconf_dir 252 253# ----------------------- # 254# Real work starts here. # 255# ----------------------- # 256 257# Source what the traces are trying to tell us. 258$verbose $me: running $autoconf to trace from $infile >&2 259$autoconf \ 260 --trace AC_CONFIG_HEADERS:': $${config_h="$1"}' \ 261 --trace AH_OUTPUT:'ac_verbatim_$1="\ 262$2"' \ 263 --trace AC_DEFINE_TRACE_LITERAL:'syms="$$syms $1"' \ 264 $infile >$tmp/traces.sh || { (exit 1); exit 1; } 265 266$verbose $me: sourcing $tmp/traces.sh >&2 267if (set -e && . $tmp/traces.sh) >/dev/null 2>&1; then 268 . $tmp/traces.sh 269else 270 echo "$me: error: shell error while sourcing $tmp/traces.sh" >&2 271 (exit 1); exit 1 272fi 273 274 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. 281syms=`for sym in $syms; do echo $sym; done | 282 sed -e 's/(.*//' | 283 sort | 284 uniq | 285 sed -e 's@^@ @'` 286 287 288# We template only the first CONFIG_HEADER. 289config_h=`set X $config_h; echo $2` 290# Support "outfile[:infile]", defaulting infile="outfile.in". 291case "$config_h" in 292"") echo "$me: error: AC_CONFIG_HEADERS not found in $infile" >&2 293 (exit 1); exit 1 ;; 294*:*) config_h_in=`echo "$config_h" | sed 's/.*://'` 295 config_h=`echo "$config_h" | sed 's/:.*//'` ;; 296*) config_h_in="$config_h.in" ;; 297esac 298 299# Don't write "do not edit" -- it will get copied into the 300# config.h, which it's ok to edit. 301cat <<EOF >$tmp/config.hin 302/* $config_h_in. Generated automatically from $infile by autoheader. */ 303EOF 304 305# Dump the top. 306test -r $config_h.top && cat $config_h.top >>$tmp/config.hin 307 308# Dump `acconfig.h' but its bottom. 309test -r $localdir/acconfig.h && 310 sed '/@BOTTOM@/,$d;s/@TOP@//' $localdir/acconfig.h >>$tmp/config.hin 311 312# Dump the templates from `configure.ac'. 313for verb in `(set) 2>&1 | sed -n -e '/^ac_verbatim/s/^\([^=]*\)=.*$/\1/p' | sort`; do 314 eval value=\$$verb 315 cat >>$tmp/config.hin <<EOF 316 317$value 318EOF 319done 320 321# Handle the case where @BOTTOM@ is the first line of acconfig.h. 322test -r $localdir/acconfig.h && 323 grep @BOTTOM@ $localdir/acconfig.h >/dev/null && 324 sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h >>$tmp/config.hin 325test -f $config_h.bot && cat $config_h.bot >>$tmp/config.hin 326 327 328# Check that all the symbols have a template. 329$verbose $me: checking completeness of the template >&2 330# Regexp for a white space. 331w='[ ]' 332if test -n "$syms"; then 333 for sym in $syms; do 334 if egrep "^#$w*[a-z]*$w$w*$sym($w*|$w.*)$" $tmp/config.hin >/dev/null; then 335 : # All is well. 336 else 337 echo "$me: No template for symbol \`$sym'" >&2 338 status=1 339 fi 340 done 341fi 342 343 344# If the run was successful, output the result. 345if test $status = 0; then 346 if test $# = 0; then 347 # Output is a file 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 351 else 352 mv -f $tmp/config.hin $config_h_in 353 fi 354 else 355 # Output is stdout 356 cat $tmp/config.hin 357 fi 358fi 359 360(exit $status); exit $status 361