Reword to pacify "make alpha".
[autoconf.git] / bin / autoheader.in
blob1e0d5d27689ff327350a687b1b7ca1bbfaa13aaa
1 #! @PERL@
2 # -*- Perl -*-
3 # @configure_input@
5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
6     if 0;
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 Free Software Foundation, Inc.
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.
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.
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.
28 # Written by Roland McGrath.
29 # Rewritten in Perl by Akim Demaille.
31 BEGIN
33   my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@';
34   unshift @INC, "$datadir";
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');
43 use Autom4te::ChannelDefs;
44 use Autom4te::Channels;
45 use Autom4te::Configure_ac;
46 use Autom4te::FileUtils;
47 use Autom4te::General;
48 use Autom4te::XFile;
49 use strict;
51 # Using `do FILE', we need `local' vars.
52 use vars qw ($config_h %verbatim %symbol);
54 # Lib files.
55 my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
56 local $config_h;
57 my $config_h_in;
58 my @prepend_include;
59 my @include;
62 # $HELP
63 # -----
64 $help = "Usage: $0 [OPTION] ... [TEMPLATE-FILE]
66 Create a template file of C \`\#define\' statements for \`configure\' to
67 use.  To this end, scan TEMPLATE-FILE, or \`configure.ac\' if present,
68 or else \`configure.in\'.
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
77 " . Autom4te::ChannelDefs::usage () . "
79 Library directories:
80   -B, --prepend-include=DIR  prepend directory DIR to search path
81   -I, --include=DIR          append directory DIR to search path
83 Report bugs to <bug-autoconf\@gnu.org>.
87 # $VERSION
88 # --------
89 $version = "autoheader (@PACKAGE_NAME@) @VERSION@
90 Written by Roland McGrath and Akim Demaille.
92 Copyright (C) 2006 Free Software Foundation, Inc.
93 This is free software; see the source for copying conditions.  There is NO
94 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
98 ## ---------- ##
99 ## Routines.  ##
100 ## ---------- ##
103 # parse_args ()
104 # -------------
105 # Process any command line arguments.
106 sub parse_args ()
108   my $srcdir;
110   parse_WARNINGS;
111   getopt ('I|include=s'         => \@include,
112           'B|prepend-include=s' => \@prepend_include,
113           'W|warnings=s'        => \&parse_warnings);
115   if (! @ARGV)
116     {
117       my $configure_ac = require_configure_ac;
118       push @ARGV, $configure_ac;
119     }
123 ## -------------- ##
124 ## Main program.  ##
125 ## -------------- ##
127 mktmpdir ('ah');
128 switch_warning 'obsolete';
129 parse_args;
131 # Preach.
132 my $config_h_top = find_file ("config.h.top?",
133                               reverse (@prepend_include), @include);
134 my $config_h_bot = find_file ("config.h.bot?",
135                               reverse (@prepend_include), @include);
136 my $acconfig_h = find_file ("acconfig.h?",
137                             reverse (@prepend_include), @include);
138 if ($config_h_top || $config_h_bot || $acconfig_h)
139   {
140     my $msg = << "END";
141     Using auxiliary files such as \`acconfig.h\', \`config.h.bot\'
142     and \`config.h.top\', to define templates for \`config.h.in\'
143     is deprecated and discouraged.
145     Using the third argument of \`AC_DEFINE\' and
146     \`AC_DEFINE_UNQUOTED\' allows one to define a template without
147     \`acconfig.h\':
149       AC_DEFINE([NEED_FUNC_MAIN], 1,
150                 [Define if a function \`main\' is needed.])
152     More sophisticated templates can also be produced, see the
153     documentation.
155     $msg =~ s/^    /WARNING: /gm;
156     msg 'obsolete', $msg;
157   }
159 # Set up autoconf.
160 my $autoconf = "'$autom4te' --language=autoconf ";
161 $autoconf .= join (' ', map { "--include='$_'" } @include);
162 $autoconf .= join (' ', map { "--prepend-include='$_'" } @prepend_include);
163 $autoconf .= ' --debug' if $debug;
164 $autoconf .= ' --force' if $force;
165 $autoconf .= ' --verbose' if $verbose;
167 # ----------------------- #
168 # Real work starts here.  #
169 # ----------------------- #
171 # Source what the traces are trying to tell us.
172 verb "$me: running $autoconf to trace from $ARGV[0]";
173 xsystem ("$autoconf"
174          # If you change this list, update the
175          # `Autoheader-preselections' section of autom4te.in.
176          . ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= \'"\'"\'$1\'"\'"\';\''
177          . ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = \'"\'"\'$2\'"\'"\';\''
178          . ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} = 1;\''
179          . " $ARGV[0] >$tmp/traces.pl");
181 local (%verbatim, %symbol);
182 debug "$me: \`do'ing $tmp/traces.pl:\n" . `sed 's/^/| /' $tmp/traces.pl`;
183 do "$tmp/traces.pl";
184 warn "couldn't parse $tmp/traces.pl: $@" if $@;
185 unless ($config_h)
186   {
187     error "error: AC_CONFIG_HEADERS not found in $ARGV[0]";
188     exit 1;
189   }
191 # We template only the first CONFIG_HEADER.
192 $config_h =~ s/ .*//;
193 # Support "outfile[:infile]", defaulting infile="outfile.in".
194 ($config_h, $config_h_in) = split (':', $config_h, 2);
195 $config_h_in ||= "$config_h.in";
197 # %SYMBOL might contain things like `F77_FUNC(name,NAME)', but we keep
198 # only the name of the macro.
199 %symbol = map { s/\(.*//; $_ => 1 } keys %symbol;
201 my $out = new Autom4te::XFile (">$tmp/config.hin");
203 # Don't write "do not edit" -- it will get copied into the
204 # config.h, which it's ok to edit.
205 print $out "/* $config_h_in.  Generated from $ARGV[0] by autoheader.  */\n";
207 # Dump the top.
208 if ($config_h_top)
209   {
210     my $in = new Autom4te::XFile ($config_h_top);
211     while ($_ = $in->getline)
212       {
213         print $out $_;
214       }
215   }
217 # Dump `acconfig.h', except for its bottom portion.
218 if ($acconfig_h)
219   {
220     my $in = new Autom4te::XFile ($acconfig_h);
221     while ($_ = $in->getline)
222       {
223         last if /\@BOTTOM\@/;
224         next if /\@TOP\@/;
225         print $out $_;
226       }
227   }
229 # Dump the templates from `configure.ac'.
230 foreach (sort keys %verbatim)
231   {
232     print $out "\n$verbatim{$_}\n";
233   }
235 # Dump bottom portion of `acconfig.h'.
236 if ($acconfig_h)
237   {
238     my $in = new Autom4te::XFile ($acconfig_h);
239     my $dump = 0;
240     while ($_ = $in->getline)
241       {
242         print $out $_ if $dump;
243         $dump = 1  if /\@BOTTOM\@/;
244       }
245   }
247 # Dump the bottom.
248 if ($config_h_bot)
249   {
250     my $in = new Autom4te::XFile ($config_h_bot);
251     while ($_ = $in->getline)
252       {
253         print $out $_;
254       }
255   }
257 $out->close;
259 # Check that all the symbols have a template.
261   my $in = new Autom4te::XFile ("$tmp/config.hin");
262   my $suggest_ac_define = 1;
263   while ($_ = $in->getline)
264     {
265       my ($symbol) = /^\#\s*\w+\s+(\w+)/
266         or next;
267       delete $symbol{$symbol};
268     }
269   foreach (sort keys %symbol)
270     {
271       msg 'syntax', "warning: missing template: $_";
272       if ($suggest_ac_define)
273         {
274           msg 'syntax',  "Use AC_DEFINE([$_], [], [Description])";
275           $suggest_ac_define = 0;
276         }
278     }
279   exit 1
280     if keys %symbol;
283 update_file ("$tmp/config.hin", "$config_h_in", $force);
285 ### Setup "GNU" style for perl-mode and cperl-mode.
286 ## Local Variables:
287 ## perl-indent-level: 2
288 ## perl-continued-statement-offset: 2
289 ## perl-continued-brace-offset: 0
290 ## perl-brace-offset: 0
291 ## perl-brace-imaginary-offset: 0
292 ## perl-label-offset: -2
293 ## cperl-indent-level: 2
294 ## cperl-brace-offset: 0
295 ## cperl-continued-brace-offset: 0
296 ## cperl-label-offset: -2
297 ## cperl-extra-newline-before-brace: t
298 ## cperl-merge-trailing-else: nil
299 ## cperl-continued-statement-offset: 2
300 ## End: