revert previous push
[autoconf.git] / bin / autoheader.in
blob9f9fba36e71ce96530016e8ee8ff9f3df7c96562
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, 2007, 2008, 2009 Free Software Foundation,
12 # Inc.
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)
17 # any later version.
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
27 # 02110-1301, USA.
29 # Written by Roland McGrath.
30 # Rewritten in Perl by Akim Demaille.
32 BEGIN
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
40   # has detected.
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;
49 use Autom4te::XFile;
50 use strict;
52 # Using `do FILE', we need `local' vars.
53 use vars qw ($config_h %verbatim %symbol);
55 # Lib files.
56 my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
57 local $config_h;
58 my $config_h_in;
59 my @prepend_include;
60 my @include;
63 # $HELP
64 # -----
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 () . "
80 Library directories:
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/>.
90 # $VERSION
91 # --------
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.
103 ## ---------- ##
104 ## Routines.  ##
105 ## ---------- ##
108 # parse_args ()
109 # -------------
110 # Process any command line arguments.
111 sub parse_args ()
113   my $srcdir;
115   parse_WARNINGS;
116   getopt ('I|include=s'         => \@include,
117           'B|prepend-include=s' => \@prepend_include,
118           'W|warnings=s'        => \&parse_warnings);
120   if (! @ARGV)
121     {
122       my $configure_ac = require_configure_ac;
123       push @ARGV, $configure_ac;
124     }
128 ## -------------- ##
129 ## Main program.  ##
130 ## -------------- ##
132 mktmpdir ('ah');
133 switch_warning 'obsolete';
134 parse_args;
136 # Preach.
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)
144   {
145     my $msg = << "END";
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
152     \`acconfig.h\':
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
158     documentation.
160     $msg =~ s/^    /WARNING: /gm;
161     msg 'obsolete', $msg;
162   }
164 # Set up autoconf.
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);
179 xsystem ("$autoconf"
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`;
189 do "$tmp/traces.pl";
190 warn "couldn't parse $tmp/traces.pl: $@" if $@;
191 unless ($config_h)
192   {
193     error "error: AC_CONFIG_HEADERS not found in $ARGV[0]";
194     exit 1;
195   }
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";
213 # Dump the top.
214 if ($config_h_top)
215   {
216     my $in = new Autom4te::XFile ("< " . open_quote ($config_h_top));
217     while ($_ = $in->getline)
218       {
219         print $out $_;
220       }
221   }
223 # Dump `acconfig.h', except for its bottom portion.
224 if ($acconfig_h)
225   {
226     my $in = new Autom4te::XFile ("< " . open_quote ($acconfig_h));
227     while ($_ = $in->getline)
228       {
229         last if /\@BOTTOM\@/;
230         next if /\@TOP\@/;
231         print $out $_;
232       }
233   }
235 # Dump the templates from `configure.ac'.
236 foreach (sort keys %verbatim)
237   {
238     print $out "\n$verbatim{$_}\n";
239   }
241 # Dump bottom portion of `acconfig.h'.
242 if ($acconfig_h)
243   {
244     my $in = new Autom4te::XFile ("< " . open_quote ($acconfig_h));
245     my $dump = 0;
246     while ($_ = $in->getline)
247       {
248         print $out $_ if $dump;
249         $dump = 1  if /\@BOTTOM\@/;
250       }
251   }
253 # Dump the bottom.
254 if ($config_h_bot)
255   {
256     my $in = new Autom4te::XFile ("< " . open_quote ($config_h_bot));
257     while ($_ = $in->getline)
258       {
259         print $out $_;
260       }
261   }
263 $out->close;
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)
270     {
271       my ($symbol) = /^\#\s*\w+\s+(\w+)/
272         or next;
273       delete $symbol{$symbol};
274     }
275   foreach (sort keys %symbol)
276     {
277       msg 'syntax', "warning: missing template: $_";
278       if ($suggest_ac_define)
279         {
280           msg 'syntax',  "Use AC_DEFINE([$_], [], [Description])";
281           $suggest_ac_define = 0;
282         }
284     }
285   exit 1
286     if keys %symbol;
289 update_file ("$tmp/config.hin", "$config_h_in", $force);
291 ### Setup "GNU" style for perl-mode and cperl-mode.
292 ## Local Variables:
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
306 ## End: