Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / bin / autoheader
blob5ccf6c5a1893a938b08e6fe3dc4c0d7994e98960
1 #! /bin/perl
2 # -*- Perl -*-
3 # @configure_input@
5 eval 'case $# in 0) exec /bin/perl -S "$0";; *) exec /bin/perl -S "$0" "$@";; esac'
6 if 0;
8 # autoheader -- create `config.h.in' from `configure.ac'
9 # Copyright (C) 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001, 2002
10 # Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
15 # any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 # 02111-1307, USA.
27 # Written by Roland McGrath.
28 # Rewritten in Perl by Akim Demaille.
30 BEGIN
32 my $perllibdir = $ENV{'autom4te_perllibdir'} || '/usr/share/autoconf';
33 unshift @INC, "$perllibdir";
36 use Autom4te::General;
37 use Autom4te::XFile;
38 use strict;
40 # Using `do FILE', we need `local' vars.
41 use vars qw ($config_h %verbatim %symbol);
43 # Lib files.
44 my $autom4te = $ENV{'AUTOM4TE'} || '/usr/bin/autom4te';
45 local $config_h;
46 my $config_h_in;
47 my @prepend_include;
48 my @include;
49 my @warning;
52 # $HELP
53 # -----
54 $help = <<"END";
55 Usage: $0 [OPTION] ... [TEMPLATE-FILE]
57 Create a template file of C \`\#define\' statements for \`configure\' to
58 use. To this end, scan TEMPLATE-FILE, or \`configure.ac\' if present,
59 or else \`configure.in\'.
61 -h, --help print this help, then exit
62 -V, --version print version number, then exit
63 -v, --verbose verbosely report processing
64 -d, --debug don\'t remove temporary files
65 -f, --force consider all files obsolete
66 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
68 Warning categories include:
69 \`obsolete\' obsolete constructs
70 \`all\' all the warnings
71 \`no-CATEGORY\' turn off the warnings on CATEGORY
72 \`none\' turn off all the warnings
73 \`error\' warnings are error
75 Library directories:
76 -B, --prepend-include=DIR prepend directory DIR to search path
77 -I, --include=DIR append directory DIR to search path
79 Report bugs to <bug-autoconf\@gnu.org>.
80 END
83 # $VERSION
84 # --------
85 $version = <<"END";
86 autoheader (GNU Autoconf) 2.56
87 Written by Roland McGrath and Akim Demaille.
89 Copyright 2002 Free Software Foundation, Inc.
90 This is free software; see the source for copying conditions. There is NO
91 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
92 END
95 ## ---------- ##
96 ## Routines. ##
97 ## ---------- ##
100 # parse_args ()
101 # -------------
102 # Process any command line arguments.
103 sub parse_args ()
105 my $srcdir;
107 getopt ('I|include=s' => \@include,
108 'B|prepend-include=s' => \@prepend_include,
109 'W|warnings=s' => \@warning);
111 if (! @ARGV)
113 my $configure_ac = find_configure_ac;
114 error "no input file"
115 unless $configure_ac;
116 push @ARGV, $configure_ac;
121 ## -------------- ##
122 ## Main program. ##
123 ## -------------- ##
125 mktmpdir ('ah');
126 parse_args;
128 # Preach.
129 my $config_h_top = find_file ("config.h.top?",
130 reverse (@prepend_include), @include);
131 my $config_h_bot = find_file ("config.h.bot?",
132 reverse (@prepend_include), @include);
133 my $acconfig_h = find_file ("acconfig.h?",
134 reverse (@prepend_include), @include);
135 if ($config_h_top || $config_h_bot || $acconfig_h)
137 my $msg = << "END";
138 Using auxiliary files such as \`acconfig.h\', \`config.h.bot\'
139 and \`config.h.top\', to define templates for \`config.h.in\'
140 is deprecated and discouraged.
142 Using the third argument of \`AC_DEFINE\' and
143 \`AC_DEFINE_UNQUOTED\' allows to define a template without
144 \`acconfig.h\':
146 AC_DEFINE([NEED_MAIN], 1,
147 [Define if a function \`main\' is needed.])
149 More sophisticated templates can also be produced, see the
150 documentation.
152 $msg =~ s/^ /WARNING: /gm;
153 print STDERR $msg;
156 # Set up autoconf.
157 my $autoconf = "$autom4te --language=autoconf ";
158 $autoconf .= join (' ', map { "--include=$_" } @include);
159 $autoconf .= join (' ', map { "--prepend-include=$_" } @prepend_include);
160 $autoconf .= ' --debug' if $debug;
161 $autoconf .= ' --force' if $force;
162 $autoconf .= ' --verbose' if $verbose;
164 # ----------------------- #
165 # Real work starts here. #
166 # ----------------------- #
168 # Source what the traces are trying to tell us.
169 verbose "$me: running $autoconf to trace from $ARGV[0]";
170 xsystem ("$autoconf"
171 # If you change this list, update the
172 # `Autoheader-preselections' section of autom4te.in.
173 . ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= \'"\'"\'$1\'"\'"\';\''
174 . ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = \'"\'"\'$2\'"\'"\';\''
175 . ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} = 1;\''
176 . " $ARGV[0] >$tmp/traces.pl");
178 local (%verbatim, %symbol);
179 debug "$me: \`do'ing $tmp/traces.pl:\n" . `sed 's/^/| /' $tmp/traces.pl`;
180 do "$tmp/traces.pl";
181 warn "couldn't parse $tmp/traces.pl: $@" if $@;
182 error "error: AC_CONFIG_HEADERS not found in $ARGV[0]"
183 unless $config_h;
185 # We template only the first CONFIG_HEADER.
186 $config_h =~ s/ .*//;
187 # Support "outfile[:infile]", defaulting infile="outfile.in".
188 ($config_h, $config_h_in) = split (':', $config_h, 2);
189 $config_h_in ||= "$config_h.in";
191 # %SYMBOL might contain things like `F77_FUNC(name,NAME)', but we keep
192 # only the name of the macro.
193 %symbol = map { s/\(.*//; $_ => 1 } keys %symbol;
195 my $out = new Autom4te::XFile (">$tmp/config.hin");
197 # Don't write "do not edit" -- it will get copied into the
198 # config.h, which it's ok to edit.
199 print $out "/* $config_h_in. Generated from $ARGV[0] by autoheader. */\n";
201 # Dump the top.
202 if ($config_h_top)
204 my $in = new Autom4te::XFile ($config_h_top);
205 while ($_ = $in->getline)
207 print $out $_;
211 # Dump `acconfig.h', except for its bottom portion.
212 if ($acconfig_h)
214 my $in = new Autom4te::XFile ($acconfig_h);
215 while ($_ = $in->getline)
217 last if /\@BOTTOM\@/;
218 next if /\@TOP\@/;
219 print $out $_;
223 # Dump the templates from `configure.ac'.
224 foreach (sort keys %verbatim)
226 print $out "\n$verbatim{$_}\n";
229 # Dump bottom portion of `acconfig.h'.
230 if ($acconfig_h)
232 my $in = new Autom4te::XFile ($acconfig_h);
233 my $dump = 0;
234 while ($_ = $in->getline)
236 print $out $_ if $dump;
237 $dump = 1 if /\@BOTTOM\@/;
241 # Dump the bottom.
242 if ($config_h_bot)
244 my $in = new Autom4te::XFile ($config_h_bot);
245 while ($_ = $in->getline)
247 print $out $_;
251 $out->close;
253 # Check that all the symbols have a template.
255 my $in = new Autom4te::XFile ("$tmp/config.hin");
256 my $suggest_ac_define = 1;
257 while ($_ = $in->getline)
259 my ($symbol) = /^\#\s*\w+\s+(\w+)/
260 or next;
261 delete $symbol{$symbol};
263 foreach (sort keys %symbol)
265 print STDERR "$me: missing template: $_\n";
266 if ($suggest_ac_define)
268 print STDERR "Use AC_DEFINE([$_], [], [Description])";
269 $suggest_ac_define = 0;
273 exit 1
274 if keys %symbol;
277 update_file ("$tmp/config.hin", "$config_h_in");
279 ### Setup "GNU" style for perl-mode and cperl-mode.
280 ## Local Variables:
281 ## perl-indent-level: 2
282 ## perl-continued-statement-offset: 2
283 ## perl-continued-brace-offset: 0
284 ## perl-brace-offset: 0
285 ## perl-brace-imaginary-offset: 0
286 ## perl-label-offset: -2
287 ## cperl-indent-level: 2
288 ## cperl-brace-offset: 0
289 ## cperl-continued-brace-offset: 0
290 ## cperl-label-offset: -2
291 ## cperl-extra-newline-before-brace: t
292 ## cperl-merge-trailing-else: nil
293 ## cperl-continued-statement-offset: 2
294 ## End: