File Coverage

File:/usr/local/bin/autoheader
Coverage:74.6%

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