5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # autoheader -- create `config.h.in' from `configure.ac'
10 # Copyright (C) 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001, 2002,
11 # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2, or (at your option)
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 # Written by Roland McGrath.
30 # Rewritten in Perl by Akim Demaille.
34 my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
35 unshift @INC, "$pkgdatadir";
37 # Override SHELL. On DJGPP SHELL may not be set to a shell
38 # that can handle redirection and quote arguments correctly,
39 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
41 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
44 use Autom4te::ChannelDefs;
45 use Autom4te::Channels;
46 use Autom4te::Configure_ac;
47 use Autom4te::FileUtils;
48 use Autom4te::General;
52 # Using `do FILE', we need `local' vars.
53 use vars qw ($config_h %verbatim %symbol);
56 my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
65 $help = "Usage: $0 [OPTION]... [TEMPLATE-FILE]
67 Create a template file of C \`\#define\' statements for \`configure\' to
68 use. To this end, scan TEMPLATE-FILE, or \`configure.ac\' if present,
69 or else \`configure.in\'.
71 -h, --help print this help, then exit
72 -V, --version print version number, then exit
73 -v, --verbose verbosely report processing
74 -d, --debug don\'t remove temporary files
75 -f, --force consider all files obsolete
76 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
78 " . Autom4te::ChannelDefs::usage () . "
81 -B, --prepend-include=DIR prepend directory DIR to search path
82 -I, --include=DIR append directory DIR to search path
84 Report bugs to <bug-autoconf\@gnu.org>.
85 GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
86 General help using GNU software: <http://www.gnu.org/gethelp/>.
92 $version = "autoheader (@PACKAGE_NAME@) @VERSION@
93 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
94 License GPLv2+: GNU GPL version 2 or later
95 <http://gnu.org/licenses/old-licenses/gpl-2.0.html>
96 This is free software: you are free to change and redistribute it.
97 There is NO WARRANTY, to the extent permitted by law.
99 Written by Roland McGrath and Akim Demaille.
110 # Process any command line arguments.
116 getopt ('I|include=s' => \@include,
117 'B|prepend-include=s' => \@prepend_include,
118 'W|warnings=s' => \&parse_warnings);
122 my $configure_ac = require_configure_ac;
123 push @ARGV, $configure_ac;
133 switch_warning 'obsolete';
137 my $config_h_top = find_file ("config.h.top?",
138 reverse (@prepend_include), @include);
139 my $config_h_bot = find_file ("config.h.bot?",
140 reverse (@prepend_include), @include);
141 my $acconfig_h = find_file ("acconfig.h?",
142 reverse (@prepend_include), @include);
143 if ($config_h_top || $config_h_bot || $acconfig_h)
146 Using auxiliary files such as \`acconfig.h\', \`config.h.bot\'
147 and \`config.h.top\', to define templates for \`config.h.in\'
148 is deprecated and discouraged.
150 Using the third argument of \`AC_DEFINE\' and
151 \`AC_DEFINE_UNQUOTED\' allows one to define a template without
154 AC_DEFINE([NEED_FUNC_MAIN], 1,
155 [Define if a function \`main\' is needed.])
157 More sophisticated templates can also be produced, see the
160 $msg =~ s/^ /WARNING: /gm;
161 msg 'obsolete', $msg;
165 my $autoconf = "'$autom4te' --language=autoconf ";
166 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
167 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
168 $autoconf .= ' --debug' if $debug;
169 $autoconf .= ' --force' if $force;
170 $autoconf .= ' --verbose' if $verbose;
172 # ----------------------- #
173 # Real work starts here. #
174 # ----------------------- #
176 # Source what the traces are trying to tell us.
177 verb "$me: running $autoconf to trace from $ARGV[0]";
178 my $quoted_tmp = shell_quote ($tmp);
180 # If you change this list, update the
181 # `Autoheader-preselections' section of autom4te.in.
182 . ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= \'"\'"\'$1\'"\'"\';\''
183 . ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = \'"\'"\'$2\'"\'"\';\''
184 . ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} = 1;\''
185 . " " . shell_quote ($ARGV[0]) . " >$quoted_tmp/traces.pl");
187 local (%verbatim, %symbol);
188 debug "$me: \`do'ing $tmp/traces.pl:\n" . `sed 's/^/| /' $quoted_tmp/traces.pl`;
190 warn "couldn't parse $tmp/traces.pl: $@" if $@;
193 error "error: AC_CONFIG_HEADERS not found in $ARGV[0]";
197 # We template only the first CONFIG_HEADER.
198 $config_h =~ s/ .*//;
199 # Support "outfile[:infile]", defaulting infile="outfile.in".
200 ($config_h, $config_h_in) = split (':', $config_h, 2);
201 $config_h_in ||= "$config_h.in";
203 # %SYMBOL might contain things like `F77_FUNC(name,NAME)', but we keep
204 # only the name of the macro.
205 %symbol = map { s/\(.*//; $_ => 1 } keys %symbol;
207 my $out = new Autom4te::XFile ("> " . open_quote ("$tmp/config.hin"));
209 # Don't write "do not edit" -- it will get copied into the
210 # config.h, which it's ok to edit.
211 print $out "/* $config_h_in. Generated from $ARGV[0] by autoheader. */\n";
216 my $in = new Autom4te::XFile ("< " . open_quote ($config_h_top));
217 while ($_ = $in->getline)
223 # Dump `acconfig.h', except for its bottom portion.
226 my $in = new Autom4te::XFile ("< " . open_quote ($acconfig_h));
227 while ($_ = $in->getline)
229 last if /\@BOTTOM\@/;
235 # Dump the templates from `configure.ac'.
236 foreach (sort keys %verbatim)
238 print $out "\n$verbatim{$_}\n";
241 # Dump bottom portion of `acconfig.h'.
244 my $in = new Autom4te::XFile ("< " . open_quote ($acconfig_h));
246 while ($_ = $in->getline)
248 print $out $_ if $dump;
249 $dump = 1 if /\@BOTTOM\@/;
256 my $in = new Autom4te::XFile ("< " . open_quote ($config_h_bot));
257 while ($_ = $in->getline)
265 # Check that all the symbols have a template.
267 my $in = new Autom4te::XFile ("< " . open_quote ("$tmp/config.hin"));
268 my $suggest_ac_define = 1;
269 while ($_ = $in->getline)
271 my ($symbol) = /^\#\s*\w+\s+(\w+)/
273 delete $symbol{$symbol};
275 foreach (sort keys %symbol)
277 msg 'syntax', "warning: missing template: $_";
278 if ($suggest_ac_define)
280 msg 'syntax', "Use AC_DEFINE([$_], [], [Description])";
281 $suggest_ac_define = 0;
289 update_file ("$tmp/config.hin", "$config_h_in", $force);
291 ### Setup "GNU" style for perl-mode and cperl-mode.
293 ## perl-indent-level: 2
294 ## perl-continued-statement-offset: 2
295 ## perl-continued-brace-offset: 0
296 ## perl-brace-offset: 0
297 ## perl-brace-imaginary-offset: 0
298 ## perl-label-offset: -2
299 ## cperl-indent-level: 2
300 ## cperl-brace-offset: 0
301 ## cperl-continued-brace-offset: 0
302 ## cperl-label-offset: -2
303 ## cperl-extra-newline-before-brace: t
304 ## cperl-merge-trailing-else: nil
305 ## cperl-continued-statement-offset: 2