1#! @PERL@ 2# -*- Perl -*- 3# @configure_input@ 4 5eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac' 6 if 0; 7 8# autoheader -- create `config.h.in' from `configure.ac' 9 10# Copyright (C) 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001, 2002, 11# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 12 13# This program is free software; you can redistribute it and/or modify 14# it under the terms of the GNU General Public License as published by 15# the Free Software Foundation; either version 2, or (at your option) 16# any later version. 17 18# This program is distributed in the hope that it will be useful, 19# but WITHOUT ANY WARRANTY; without even the implied warranty of 20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21# GNU General Public License for more details. 22 23# You should have received a copy of the GNU General Public License 24# along with this program; if not, write to the Free Software 25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 26# 02110-1301, USA. 27 28# Written by Roland McGrath. 29# Rewritten in Perl by Akim Demaille. 30 31BEGIN 32{ 33 my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@'; 34 unshift @INC, "$datadir"; 35 36 # Override SHELL. On DJGPP SHELL may not be set to a shell 37 # that can handle redirection and quote arguments correctly, 38 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure 39 # has detected. 40 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos'); 41} 42 43use Autom4te::ChannelDefs; 44use Autom4te::Channels; 45use Autom4te::Configure_ac; 46use Autom4te::FileUtils; 47use Autom4te::General; 48use Autom4te::XFile; 49use strict; 50 51# Using `do FILE', we need `local' vars. 52use vars qw ($config_h %verbatim %symbol); 53 54# Lib files. 55my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@'; 56local $config_h; 57my $config_h_in; 58my @prepend_include; 59my @include; 60 61 62# $HELP 63# ----- 64$help = "Usage: $0 [OPTION] ... [TEMPLATE-FILE] 65 66Create a template file of C \`\#define\' statements for \`configure\' to 67use. To this end, scan TEMPLATE-FILE, or \`configure.ac\' if present, 68or else \`configure.in\'. 69 70 -h, --help print this help, then exit 71 -V, --version print version number, then exit 72 -v, --verbose verbosely report processing 73 -d, --debug don\'t remove temporary files 74 -f, --force consider all files obsolete 75 -W, --warnings=CATEGORY report the warnings falling in CATEGORY 76 77" . Autom4te::ChannelDefs::usage () . " 78 79Library directories: 80 -B, --prepend-include=DIR prepend directory DIR to search path 81 -I, --include=DIR append directory DIR to search path 82 83Report bugs to <bug-autoconf\@gnu.org>. 84"; 85 86 87# $VERSION 88# -------- 89$version = "autoheader (@PACKAGE_NAME@) @VERSION@ 90Copyright (C) 2006 Free Software Foundation, Inc. 91This is free software. You may redistribute copies of it under the terms of 92the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. 93There is NO WARRANTY, to the extent permitted by law. 94 95Written by Roland McGrath and Akim Demaille. 96"; 97 98 99## ---------- ## 100## Routines. ## 101## ---------- ## 102 103 104# parse_args () 105# ------------- 106# Process any command line arguments. 107sub parse_args () 108{ 109 my $srcdir; 110 111 parse_WARNINGS; 112 getopt ('I|include=s' => \@include, 113 'B|prepend-include=s' => \@prepend_include, 114 'W|warnings=s' => \&parse_warnings); 115 116 if (! @ARGV) 117 { 118 my $configure_ac = require_configure_ac; 119 push @ARGV, $configure_ac; 120 } 121} 122 123 124## -------------- ## 125## Main program. ## 126## -------------- ## 127 128mktmpdir ('ah'); 129switch_warning 'obsolete'; 130parse_args; 131 132# Preach. 133my $config_h_top = find_file ("config.h.top?", 134 reverse (@prepend_include), @include); 135my $config_h_bot = find_file ("config.h.bot?", 136 reverse (@prepend_include), @include); 137my $acconfig_h = find_file ("acconfig.h?", 138 reverse (@prepend_include), @include); 139if ($config_h_top || $config_h_bot || $acconfig_h) 140 { 141 my $msg = << "END"; 142 Using auxiliary files such as \`acconfig.h\', \`config.h.bot\' 143 and \`config.h.top\', to define templates for \`config.h.in\' 144 is deprecated and discouraged. 145 146 Using the third argument of \`AC_DEFINE\' and 147 \`AC_DEFINE_UNQUOTED\' allows one to define a template without 148 \`acconfig.h\': 149 150 AC_DEFINE([NEED_FUNC_MAIN], 1, 151 [Define if a function \`main\' is needed.]) 152 153 More sophisticated templates can also be produced, see the 154 documentation. 155END 156 $msg =~ s/^ /WARNING: /gm; 157 msg 'obsolete', $msg; 158 } 159 160# Set up autoconf. 161my $autoconf = "'$autom4te' --language=autoconf "; 162$autoconf .= join (' ', map { "--include='$_'" } @include); 163$autoconf .= join (' ', map { "--prepend-include='$_'" } @prepend_include); 164$autoconf .= ' --debug' if $debug; 165$autoconf .= ' --force' if $force; 166$autoconf .= ' --verbose' if $verbose; 167 168# ----------------------- # 169# Real work starts here. # 170# ----------------------- # 171 172# Source what the traces are trying to tell us. 173verb "$me: running $autoconf to trace from $ARGV[0]"; 174xsystem ("$autoconf" 175 # If you change this list, update the 176 # `Autoheader-preselections' section of autom4te.in. 177 . ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= \'"\'"\'$1\'"\'"\';\'' 178 . ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = \'"\'"\'$2\'"\'"\';\'' 179 . ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} = 1;\'' 180 . " $ARGV[0] >$tmp/traces.pl"); 181 182local (%verbatim, %symbol); 183debug "$me: \`do'ing $tmp/traces.pl:\n" . `sed 's/^/| /' $tmp/traces.pl`; 184do "$tmp/traces.pl"; 185warn "couldn't parse $tmp/traces.pl: $@" if $@; 186unless ($config_h) 187 { 188 error "error: AC_CONFIG_HEADERS not found in $ARGV[0]"; 189 exit 1; 190 } 191 192# We template only the first CONFIG_HEADER. 193$config_h =~ s/ .*//; 194# Support "outfile[:infile]", defaulting infile="outfile.in". 195($config_h, $config_h_in) = split (':', $config_h, 2); 196$config_h_in ||= "$config_h.in"; 197 198# %SYMBOL might contain things like `F77_FUNC(name,NAME)', but we keep 199# only the name of the macro. 200%symbol = map { s/\(.*//; $_ => 1 } keys %symbol; 201 202my $out = new Autom4te::XFile (">$tmp/config.hin"); 203 204# Don't write "do not edit" -- it will get copied into the 205# config.h, which it's ok to edit. 206print $out "/* $config_h_in. Generated from $ARGV[0] by autoheader. */\n"; 207 208# Dump the top. 209if ($config_h_top) 210 { 211 my $in = new Autom4te::XFile ($config_h_top); 212 while ($_ = $in->getline) 213 { 214 print $out $_; 215 } 216 } 217 218# Dump `acconfig.h', except for its bottom portion. 219if ($acconfig_h) 220 { 221 my $in = new Autom4te::XFile ($acconfig_h); 222 while ($_ = $in->getline) 223 { 224 last if /\@BOTTOM\@/; 225 next if /\@TOP\@/; 226 print $out $_; 227 } 228 } 229 230# Dump the templates from `configure.ac'. 231foreach (sort keys %verbatim) 232 { 233 print $out "\n$verbatim{$_}\n"; 234 } 235 236# Dump bottom portion of `acconfig.h'. 237if ($acconfig_h) 238 { 239 my $in = new Autom4te::XFile ($acconfig_h); 240 my $dump = 0; 241 while ($_ = $in->getline) 242 { 243 print $out $_ if $dump; 244 $dump = 1 if /\@BOTTOM\@/; 245 } 246 } 247 248# Dump the bottom. 249if ($config_h_bot) 250 { 251 my $in = new Autom4te::XFile ($config_h_bot); 252 while ($_ = $in->getline) 253 { 254 print $out $_; 255 } 256 } 257 258$out->close; 259 260# Check that all the symbols have a template. 261{ 262 my $in = new Autom4te::XFile ("$tmp/config.hin"); 263 my $suggest_ac_define = 1; 264 while ($_ = $in->getline) 265 { 266 my ($symbol) = /^\#\s*\w+\s+(\w+)/ 267 or next; 268 delete $symbol{$symbol}; 269 } 270 foreach (sort keys %symbol) 271 { 272 msg 'syntax', "warning: missing template: $_"; 273 if ($suggest_ac_define) 274 { 275 msg 'syntax', "Use AC_DEFINE([$_], [], [Description])"; 276 $suggest_ac_define = 0; 277 } 278 279 } 280 exit 1 281 if keys %symbol; 282} 283 284update_file ("$tmp/config.hin", "$config_h_in", $force); 285 286### Setup "GNU" style for perl-mode and cperl-mode. 287## Local Variables: 288## perl-indent-level: 2 289## perl-continued-statement-offset: 2 290## perl-continued-brace-offset: 0 291## perl-brace-offset: 0 292## perl-brace-imaginary-offset: 0 293## perl-label-offset: -2 294## cperl-indent-level: 2 295## cperl-brace-offset: 0 296## cperl-continued-brace-offset: 0 297## cperl-label-offset: -2 298## cperl-extra-newline-before-brace: t 299## cperl-merge-trailing-else: nil 300## cperl-continued-statement-offset: 2 301## End: 302