@ai-ecoverse/wasix-autoconf 0.0.0-stage → 2.72.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +338 -0
  2. package/README.md +2 -2
  3. package/bin/autoconf +215 -0
  4. package/bin/autoheader +335 -0
  5. package/bin/autom4te +1174 -0
  6. package/bin/autoreconf +937 -0
  7. package/bin/autoscan +686 -0
  8. package/bin/autoupdate +1074 -0
  9. package/bin/ifnames +158 -0
  10. package/package.json +75 -4
  11. package/share/autoconf/Autom4te/C4che.pm +263 -0
  12. package/share/autoconf/Autom4te/ChannelDefs.pm +549 -0
  13. package/share/autoconf/Autom4te/Channels.pm +856 -0
  14. package/share/autoconf/Autom4te/Config.pm +43 -0
  15. package/share/autoconf/Autom4te/Configure_ac.pm +112 -0
  16. package/share/autoconf/Autom4te/FileUtils.pm +429 -0
  17. package/share/autoconf/Autom4te/General.pm +413 -0
  18. package/share/autoconf/Autom4te/Getopt.pm +99 -0
  19. package/share/autoconf/Autom4te/Request.pm +121 -0
  20. package/share/autoconf/Autom4te/XFile.pm +304 -0
  21. package/share/autoconf/INSTALL +368 -0
  22. package/share/autoconf/autoconf/autoconf.m4 +105 -0
  23. package/share/autoconf/autoconf/autoconf.m4f +15460 -0
  24. package/share/autoconf/autoconf/autoheader.m4 +78 -0
  25. package/share/autoconf/autoconf/autoscan.m4 +51 -0
  26. package/share/autoconf/autoconf/autotest.m4 +81 -0
  27. package/share/autoconf/autoconf/autoupdate.m4 +123 -0
  28. package/share/autoconf/autoconf/c.m4 +2794 -0
  29. package/share/autoconf/autoconf/erlang.m4 +270 -0
  30. package/share/autoconf/autoconf/fortran.m4 +1933 -0
  31. package/share/autoconf/autoconf/functions.m4 +2127 -0
  32. package/share/autoconf/autoconf/general.m4 +3374 -0
  33. package/share/autoconf/autoconf/go.m4 +177 -0
  34. package/share/autoconf/autoconf/headers.m4 +839 -0
  35. package/share/autoconf/autoconf/lang.m4 +730 -0
  36. package/share/autoconf/autoconf/libs.m4 +493 -0
  37. package/share/autoconf/autoconf/oldnames.m4 +92 -0
  38. package/share/autoconf/autoconf/programs.m4 +1015 -0
  39. package/share/autoconf/autoconf/specific.m4 +763 -0
  40. package/share/autoconf/autoconf/status.m4 +1787 -0
  41. package/share/autoconf/autoconf/trailer.m4 +4 -0
  42. package/share/autoconf/autoconf/types.m4 +1133 -0
  43. package/share/autoconf/autom4te.cfg +169 -0
  44. package/share/autoconf/autoscan/autoscan.list +264 -0
  45. package/share/autoconf/autotest/autotest.m4 +27 -0
  46. package/share/autoconf/autotest/autotest.m4f +3915 -0
  47. package/share/autoconf/autotest/general.m4 +2292 -0
  48. package/share/autoconf/autotest/specific.m4 +74 -0
  49. package/share/autoconf/build-aux/config.guess +1807 -0
  50. package/share/autoconf/build-aux/config.sub +1960 -0
  51. package/share/autoconf/build-aux/install-sh +541 -0
  52. package/share/autoconf/m4sugar/foreach.m4 +362 -0
  53. package/share/autoconf/m4sugar/m4sh.m4 +2217 -0
  54. package/share/autoconf/m4sugar/m4sh.m4f +2046 -0
  55. package/share/autoconf/m4sugar/m4sugar.m4 +3307 -0
  56. package/share/autoconf/m4sugar/m4sugar.m4f +868 -0
  57. package/share/autoconf/version.m4 +12 -0
package/bin/autom4te ADDED
@@ -0,0 +1,1174 @@
1
+ #!/usr/bin/perl
2
+ # -*- perl -*-
3
+ # Generated from bin/autom4te.in; do not edit by hand.
4
+
5
+ eval 'case $# in 0) exec /usr/bin/perl -S "$0";; *) exec /usr/bin/perl -S "$0" "$@";; esac'
6
+ if 0;
7
+
8
+ # autom4te - Wrapper around M4 libraries.
9
+ # Copyright (C) 2001-2003, 2005-2017, 2020-2023 Free Software
10
+ # Foundation, Inc.
11
+
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 3 of the License, or
15
+ # (at your option) any later version.
16
+
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.
21
+
22
+ # You should have received a copy of the GNU General Public License
23
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
24
+
25
+ use 5.006;
26
+ use strict;
27
+ use warnings FATAL => 'all';
28
+
29
+ BEGIN
30
+ {
31
+ my $pkgdatadir = $ENV{'autom4te_perllibdir'} || do { require File::Basename; require File::Spec; File::Spec->catdir(File::Basename::dirname(File::Basename::dirname(File::Spec->rel2abs($0))), 'share', 'autoconf') };
32
+ unshift @INC, $pkgdatadir;
33
+
34
+ # Override SHELL. On DJGPP SHELL may not be set to a shell
35
+ # that can handle redirection and quote arguments correctly,
36
+ # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
37
+ # has detected.
38
+ $ENV{'SHELL'} = '/bin/sh' if ($^O eq 'dos');
39
+ }
40
+
41
+ use File::Basename;
42
+
43
+ use Autom4te::C4che;
44
+ use Autom4te::ChannelDefs;
45
+ use Autom4te::Channels;
46
+ use Autom4te::FileUtils;
47
+ use Autom4te::General;
48
+ use Autom4te::XFile;
49
+
50
+ # Data directory.
51
+ my $pkgdatadir = $ENV{'AC_MACRODIR'} || do { require File::Basename; require File::Spec; File::Spec->catdir(File::Basename::dirname(File::Basename::dirname(File::Spec->rel2abs($0))), 'share', 'autoconf') };
52
+
53
+ # $LANGUAGE{LANGUAGE} -- Automatic options for LANGUAGE.
54
+ my %language;
55
+
56
+ my $output = '-';
57
+
58
+ # Mode of the output file except for traces.
59
+ my $mode = "0666";
60
+
61
+ # If melt, don't use frozen files.
62
+ my $melt = 0;
63
+
64
+ # Names of the cache directory, cache directory index, trace cache
65
+ # prefix, and output cache prefix. And the IO object for the index.
66
+ my $cache;
67
+ my $icache;
68
+ my $tcache;
69
+ my $ocache;
70
+ my $icache_file;
71
+
72
+ my $flock_implemented = 'yes';
73
+
74
+ # The macros to trace mapped to their format, as specified by the
75
+ # user.
76
+ my %trace;
77
+
78
+ # The macros the user will want to trace in the future.
79
+ # We need 'include' to get the included file, 'm4_pattern_forbid' and
80
+ # 'm4_pattern_allow' to check the output.
81
+ #
82
+ # FIXME: What about 'sinclude'?
83
+ my @preselect = ('include',
84
+ 'm4_pattern_allow', 'm4_pattern_forbid',
85
+ '_m4_warn');
86
+
87
+ # M4 include path.
88
+ my @include;
89
+
90
+ # Do we freeze?
91
+ my $freeze = 0;
92
+
93
+ # $M4.
94
+ my $m4 = $ENV{"M4"} || '/usr/bin/gm4';
95
+ # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
96
+ fatal "need GNU m4 1.4 or later: $m4"
97
+ if system "$m4 --help </dev/null 2>&1 | grep reload-state >/dev/null";
98
+
99
+ # Set some high recursion limit as the default limit, 250, has already
100
+ # been hit with AC_OUTPUT. Don't override the user's choice.
101
+ $m4 .= ' --nesting-limit=1024'
102
+ if " $m4 " !~ / (--nesting-limit(=[0-9]+)?|-L[0-9]*) /;
103
+
104
+
105
+ # @M4_BUILTIN -- M4 builtins and a useful comment.
106
+ my @m4_builtin = `echo dumpdef | $m4 2>&1 >/dev/null`;
107
+ map { s/:.*//;s/\W// } @m4_builtin;
108
+
109
+
110
+ # %M4_BUILTIN_ALTERNATE_NAME
111
+ # --------------------------
112
+ # The builtins are renamed, e.g., 'define' is renamed 'm4_define'.
113
+ # So map 'define' to 'm4_define' and conversely.
114
+ # Some macros don't follow this scheme: be sure to properly map to their
115
+ # alternate name too.
116
+ #
117
+ # FIXME: Trace status of renamed builtins was fixed in M4 1.4.5, which
118
+ # we now depend on; do we still need to do this mapping?
119
+ #
120
+ # So we will merge them, i.e., tracing 'BUILTIN' or tracing
121
+ # 'm4_BUILTIN' will be the same: tracing both, but honoring the
122
+ # *last* trace specification.
123
+ #
124
+ # FIXME: This is not enough: in the output '$0' will be 'BUILTIN'
125
+ # sometimes and 'm4_BUILTIN' at others. We should return a unique name,
126
+ # the one specified by the user.
127
+ #
128
+ # FIXME: To be absolutely rigorous, I would say that given that we
129
+ # _redefine_ divert (instead of _copying_ it), divert and the like
130
+ # should not be part of this list.
131
+ my %m4_builtin_alternate_name;
132
+ @m4_builtin_alternate_name{"$_", "m4_$_"} = ("m4_$_", "$_")
133
+ foreach (grep { !/m4wrap|m4exit|dnl|ifelse|__.*__/ } @m4_builtin);
134
+ @m4_builtin_alternate_name{"ifelse", "m4_if"} = ("m4_if", "ifelse");
135
+ @m4_builtin_alternate_name{"m4exit", "m4_exit"} = ("m4_exit", "m4exit");
136
+ @m4_builtin_alternate_name{"m4wrap", "m4_wrap"} = ("m4_wrap", "m4wrap");
137
+
138
+
139
+ # $HELP
140
+ # -----
141
+ $help = "Usage: $0 [OPTION]... [FILES]
142
+
143
+ Run GNU M4 on the FILES, avoiding useless runs. Output the traces if tracing,
144
+ the frozen file if freezing, otherwise the expansion of the FILES.
145
+
146
+ If some of the FILES are named 'FILE.m4f' they are considered to be M4
147
+ frozen files of all the previous files (which are therefore not loaded).
148
+ If 'FILE.m4f' is not found, then 'FILE.m4' will be used, together with
149
+ all the previous files.
150
+
151
+ Some files may be optional, i.e., will only be processed if found in the
152
+ include path, but then must end in '.m4?'; the question mark is not part
153
+ of the actual file name.
154
+
155
+ Operation modes:
156
+ -h, --help print this help, then exit
157
+ -V, --version print version number, then exit
158
+ -v, --verbose verbosely report processing
159
+ -d, --debug don't remove temporary files
160
+ -o, --output=FILE save output in FILE (defaults to '-', stdout)
161
+ -f, --force don't rely on cached values
162
+ -W, --warnings=CATEGORY report the warnings falling in CATEGORY
163
+ (comma-separated list accepted)
164
+ -l, --language=LANG specify the set of M4 macros to use
165
+ -C, --cache=DIRECTORY preserve results for future runs in DIRECTORY
166
+ --no-cache disable the cache
167
+ -m, --mode=OCTAL change the non trace output file mode (0666)
168
+ -M, --melt don't use M4 frozen files
169
+
170
+ Languages include:
171
+ 'Autoconf' create Autoconf configure scripts
172
+ 'Autotest' create Autotest test suites
173
+ 'M4sh' create M4sh shell scripts
174
+ 'M4sugar' create M4sugar output
175
+
176
+ " . Autom4te::ChannelDefs::usage . "
177
+
178
+ The environment variables 'M4' and 'WARNINGS' are honored.
179
+
180
+ Library directories:
181
+ -B, --prepend-include=DIR prepend directory DIR to search path
182
+ -I, --include=DIR append directory DIR to search path
183
+
184
+ Tracing:
185
+ -t, --trace=MACRO[:FORMAT] report the MACRO invocations
186
+ -p, --preselect=MACRO prepare to trace MACRO in a future run
187
+
188
+ Freezing:
189
+ -F, --freeze produce an M4 frozen state file for FILES
190
+
191
+ FORMAT defaults to '\$f:\$l:\$n:\$%', and can use the following escapes:
192
+ \$\$ literal \$
193
+ \$f file where macro was called
194
+ \$l line where macro was called
195
+ \$d nesting depth of macro call
196
+ \$n name of the macro
197
+ \$NUM argument NUM, unquoted and with newlines
198
+ \$SEP\@ all arguments, with newlines, quoted, and separated by SEP
199
+ \$SEP* all arguments, with newlines, unquoted, and separated by SEP
200
+ \$SEP% all arguments, without newlines, unquoted, and separated by SEP
201
+ SEP can be empty for the default (comma for \@ and *, colon for %),
202
+ a single character for that character, or {STRING} to use a string.
203
+
204
+ Report bugs to <bug-autoconf\@gnu.org>.
205
+
206
+ The full documentation for Autoconf can be read via 'info autoconf',
207
+ or on the Web at <https://www.gnu.org/software/autoconf/manual/>.
208
+ ";
209
+
210
+ # $VERSION
211
+ # --------
212
+ $version = "autom4te (GNU Autoconf) 2.72\n"
213
+ . ($Autom4te::FileUtils::subsecond_mtime
214
+ ? "Features: subsecond-mtime\n" : "")
215
+ . "\nCopyright (C) 2023 Free Software Foundation, Inc.
216
+ License GPLv3+/Autoconf: GNU GPL version 3 or later
217
+ <https://gnu.org/licenses/gpl.html>, <https://gnu.org/licenses/exceptions.html>
218
+ This is free software: you are free to change and redistribute it.
219
+ There is NO WARRANTY, to the extent permitted by law.
220
+
221
+ Written by Akim Demaille.
222
+ ";
223
+
224
+
225
+ ## ---------- ##
226
+ ## Routines. ##
227
+ ## ---------- ##
228
+
229
+ # tempfile_with_mode ($dir, $mode)
230
+ # --------------------------------
231
+ # Create a temporary file in $dir with access control bits $mode.
232
+ # Returns a list ($fh, $fname) where $fh is a filehandle open for
233
+ # writing to the file, and $fname is the name of the file.
234
+ sub tempfile_with_mode ($$)
235
+ {
236
+ my ($dir, $mode) = @_;
237
+
238
+ require File::Temp;
239
+ my $template = "actmp." . File::Temp::TEMPXXX;
240
+
241
+ # The PERMS argument was added to File::Temp::tempfile in version
242
+ # 0.2310 of the File::Temp module; it will be silently ignored if
243
+ # passed to an older version of the function. This is the simplest
244
+ # way to do a non-fatal version check without features of Perl 5.10.
245
+ local $@;
246
+ if (eval { File::Temp->VERSION("0.2310"); 1 })
247
+ {
248
+ # Can use PERMS argument to tempfile().
249
+ return File::Temp::tempfile ($template, DIR => $dir, PERMS => $mode,
250
+ UNLINK => 0);
251
+ }
252
+ else
253
+ {
254
+ # PERMS is not available.
255
+ # This is functionally equivalent to what it would do.
256
+ require Fcntl;
257
+ my $openflags = Fcntl::O_RDWR | Fcntl::O_CREAT | Fcntl::O_EXCL;
258
+
259
+ require File::Spec;
260
+ $template = File::Spec->catfile($dir, $template);
261
+
262
+ # 50 = $MAX_GUESS in File::Temp (not an exported constant).
263
+ for (my $i = 0; $i < 50; $i++)
264
+ {
265
+ my $filename = File::Temp::mktemp($template);
266
+ my $fh;
267
+ my $success = sysopen ($fh, $filename, $openflags, $mode);
268
+ return ($fh, $filename) if $success;
269
+ fatal "Could not create temp file $filename: $!"
270
+ unless $!{EEXIST};
271
+ }
272
+ fatal "Could not create any temp file from $template: $!";
273
+ }
274
+ }
275
+
276
+ # $OPTION
277
+ # files_to_options (@FILE)
278
+ # ------------------------
279
+ # Transform Autom4te conventions (e.g., using foo.m4f to designate a frozen
280
+ # file) into a suitable command line for M4 (e.g., using --reload-state).
281
+ # parse_args guarantees that we will see at most one frozen file, and that
282
+ # if a frozen file is present, it is the first argument.
283
+ sub files_to_options (@)
284
+ {
285
+ my (@file) = @_;
286
+ my @res;
287
+ foreach my $file (@file)
288
+ {
289
+ my $arg = shell_quote ($file);
290
+ if ($file =~ /\.m4f$/)
291
+ {
292
+ $arg = "--reload-state=$arg";
293
+ # If the user downgraded M4 from 1.6 to 1.4.x after freezing
294
+ # the file, then we ensure the frozen __m4_version__ will
295
+ # not cause m4_init to make the wrong decision about the
296
+ # current M4 version.
297
+ $arg .= " --undefine=__m4_version__"
298
+ unless grep {/__m4_version__/} @m4_builtin;
299
+ }
300
+ push @res, $arg;
301
+ }
302
+ return join ' ', @res;
303
+ }
304
+
305
+
306
+ # load_configuration ($FILE)
307
+ # --------------------------
308
+ # Load the configuration $FILE.
309
+ sub load_configuration ($)
310
+ {
311
+ my ($file) = @_;
312
+ use Text::ParseWords;
313
+
314
+ my $cfg = new Autom4te::XFile ($file, "<");
315
+ my $lang;
316
+ while ($_ = $cfg->getline)
317
+ {
318
+ chomp;
319
+ # Comments.
320
+ next
321
+ if /^\s*(\#.*)?$/;
322
+
323
+ my @words = shellwords ($_);
324
+ my $type = shift @words;
325
+ if ($type eq 'begin-language:')
326
+ {
327
+ fatal "$file:$.: end-language missing for: $lang"
328
+ if defined $lang;
329
+ $lang = lc $words[0];
330
+ }
331
+ elsif ($type eq 'end-language:')
332
+ {
333
+ error "$file:$.: end-language mismatch: $lang"
334
+ if $lang ne lc $words[0];
335
+ $lang = undef;
336
+ }
337
+ elsif ($type eq 'args:')
338
+ {
339
+ fatal "$file:$.: no current language"
340
+ unless defined $lang;
341
+ push @{$language{$lang}}, @words;
342
+ }
343
+ else
344
+ {
345
+ error "$file:$.: unknown directive: $type";
346
+ }
347
+ }
348
+ }
349
+
350
+
351
+ # parse_args ()
352
+ # -------------
353
+ # Process any command line arguments.
354
+ sub parse_args ()
355
+ {
356
+ # We want to look for the early options, which should not be found
357
+ # in the configuration file. Prepend to the user arguments.
358
+ # Perform this repeatedly so that we can use --language in language
359
+ # definitions. Beware that there can be several --language
360
+ # invocations.
361
+ my @language;
362
+ do {
363
+ @language = ();
364
+ use Getopt::Long;
365
+ Getopt::Long::Configure ("pass_through", "permute");
366
+ GetOptions ("l|language=s" => \@language);
367
+
368
+ foreach (@language)
369
+ {
370
+ error "unknown language: $_"
371
+ unless exists $language{lc $_};
372
+ unshift @ARGV, @{$language{lc $_}};
373
+ }
374
+ } while @language;
375
+
376
+ # --debug is useless: it is parsed below.
377
+ if (exists $ENV{'AUTOM4TE_DEBUG'})
378
+ {
379
+ print STDERR "$me: concrete arguments:\n";
380
+ foreach my $arg (@ARGV)
381
+ {
382
+ print STDERR "| $arg\n";
383
+ }
384
+ }
385
+
386
+ # Process the arguments for real this time.
387
+ my @trace;
388
+ my @prepend_include;
389
+ my @warnings;
390
+
391
+ getopt
392
+ (
393
+ # Operation modes:
394
+ "o|output=s" => \$output,
395
+ "W|warnings=s" => \@warnings,
396
+ "m|mode=s" => \$mode,
397
+ "M|melt" => \$melt,
398
+
399
+ # Library directories:
400
+ "B|prepend-include=s" => \@prepend_include,
401
+ "I|include=s" => \@include,
402
+
403
+ # Tracing:
404
+ # Using a hash for traces is seducing. Unfortunately, upon '-t FOO',
405
+ # instead of mapping 'FOO' to undef, Getopt maps it to '1', preventing
406
+ # us from distinguishing '-t FOO' from '-t FOO=1'. So let's do it
407
+ # by hand.
408
+ "t|trace=s" => \@trace,
409
+ "p|preselect=s" => \@preselect,
410
+
411
+ # Freezing.
412
+ "F|freeze" => \$freeze,
413
+
414
+ # Caching.
415
+ "C|cache=s" => \$cache,
416
+ "no-cache" => sub { $cache = undef; },
417
+ );
418
+
419
+ parse_WARNINGS;
420
+ parse_warnings @warnings;
421
+
422
+ fatal "too few arguments
423
+ Try '$me --help' for more information."
424
+ unless @ARGV;
425
+
426
+ # Freezing:
427
+ # We cannot trace at the same time (well, we can, but it sounds insane).
428
+ # And it implies melting: there is risk not to update properly using
429
+ # old frozen files, and worse yet: we could load a frozen file and
430
+ # refreeze it! A sort of caching :)
431
+ fatal "cannot freeze and trace"
432
+ if $freeze && @trace;
433
+ $melt = 1
434
+ if $freeze;
435
+
436
+ # Names of the cache directory, cache directory index, trace cache
437
+ # prefix, and output cache prefix. If the cache is not to be
438
+ # preserved, default to a temporary directory (automatically removed
439
+ # on exit).
440
+ $cache = $tmp
441
+ unless $cache;
442
+ $icache = "$cache/requests";
443
+ $tcache = "$cache/traces.";
444
+ $ocache = "$cache/output.";
445
+
446
+ # Normalize the includes: the first occurrence is enough, several is
447
+ # a pain since it introduces a useless difference in the path which
448
+ # invalidates the cache. And strip '.' which is implicit and always
449
+ # first.
450
+ @include = grep { !/^\.$/ } uniq (reverse(@prepend_include), @include);
451
+ # homescoop: relocatable package datadir
452
+ unshift @include, $pkgdatadir;
453
+
454
+ # Convert @trace to %trace, and work around the M4 builtins tracing
455
+ # problem.
456
+ # The default format is '$f:$l:$n:$%'.
457
+ foreach (@trace)
458
+ {
459
+ /^([^:]+)(?::(.*))?$/ms;
460
+ $trace{$1} = defined $2 ? $2 : '$f:$l:$n:$%';
461
+ $trace{$m4_builtin_alternate_name{$1}} = $trace{$1}
462
+ if exists $m4_builtin_alternate_name{$1};
463
+ }
464
+
465
+ # Work around the M4 builtins tracing problem for @PRESELECT.
466
+ # FIXME: Is this still needed, now that we rely on M4 1.4.5?
467
+ push (@preselect,
468
+ map { $m4_builtin_alternate_name{$_} }
469
+ grep { exists $m4_builtin_alternate_name{$_} } @preselect);
470
+
471
+ # If we find frozen files, then all the files before it are
472
+ # discarded: the frozen file is supposed to include them all.
473
+ #
474
+ # We don't want to depend upon m4's --include to find the top level
475
+ # files, so we use 'find_file' here. Try to get a canonical name,
476
+ # as it's part of the key for caching. And some files are optional
477
+ # (also handled by 'find_file').
478
+ my @argv;
479
+ foreach (@ARGV)
480
+ {
481
+ if ($_ eq '-')
482
+ {
483
+ push @argv, $_;
484
+ }
485
+ elsif (/\.m4f$/)
486
+ {
487
+ # Frozen files are optional => pass a '?' to 'find_file'.
488
+ my $file = find_file ("$_?", @include);
489
+ if (!$melt && $file)
490
+ {
491
+ @argv = ($file);
492
+ }
493
+ else
494
+ {
495
+ s/\.m4f$/.m4/;
496
+ push @argv, find_file ($_, @include);
497
+ }
498
+ }
499
+ else
500
+ {
501
+ my $file = find_file ($_, @include);
502
+ push @argv, $file
503
+ if $file;
504
+ }
505
+ }
506
+ @ARGV = @argv;
507
+ }
508
+
509
+
510
+ # handle_m4 ($REQ, @MACRO)
511
+ # ------------------------
512
+ # Run m4 on the input files, and save the traces on the @MACRO.
513
+ sub handle_m4 ($@)
514
+ {
515
+ my ($req, @macro) = @_;
516
+
517
+ # GNU m4 appends when using --debugfile/--error-output.
518
+ unlink ($tcache . $req->id . "t");
519
+
520
+ # Run m4.
521
+ #
522
+ # We don't output directly to the cache files, to avoid problems
523
+ # when we are interrupted (that leaves corrupted files).
524
+ xsystem ("$m4 "
525
+ . join (' --include=', '', map { shell_quote ($_) } @include)
526
+ . ' --debug=aflq'
527
+ . (!exists $ENV{'AUTOM4TE_NO_FATAL'} ? ' --fatal-warning' : '')
528
+ . " --error-output=" . shell_quote ("$tcache" . $req->id . "t")
529
+ . join (' --trace=', '', map { shell_quote ($_) } sort @macro)
530
+ . " " . files_to_options (@ARGV)
531
+ . " > " . shell_quote ("$ocache" . $req->id . "t"));
532
+
533
+ # Everything went ok: preserve the outputs.
534
+ foreach my $file (map { $_ . $req->id } ($tcache, $ocache))
535
+ {
536
+ use File::Copy;
537
+ move ("${file}t", "$file")
538
+ or fatal "cannot rename ${file}t as $file: $!";
539
+ }
540
+ }
541
+
542
+
543
+ # warn_forbidden ($WHERE, $WORD, %FORBIDDEN)
544
+ # ------------------------------------------
545
+ # $WORD is forbidden. Warn with a dedicated error message if in
546
+ # %FORBIDDEN, otherwise a simple 'error: possibly undefined macro'
547
+ # will do.
548
+ my $first_warn_forbidden = 1;
549
+ sub warn_forbidden ($$%)
550
+ {
551
+ my ($where, $word, %forbidden) = @_;
552
+ my $message;
553
+
554
+ for my $re (sort keys %forbidden)
555
+ {
556
+ if ($word =~ $re)
557
+ {
558
+ $message = $forbidden{$re};
559
+ last;
560
+ }
561
+ }
562
+ $message ||= "possibly undefined macro: $word";
563
+ warn "$where: error: $message\n";
564
+ if ($first_warn_forbidden)
565
+ {
566
+ warn <<EOF;
567
+ If this token and others are legitimate, please use m4_pattern_allow.
568
+ See the Autoconf documentation.
569
+ EOF
570
+ $first_warn_forbidden = 0;
571
+ }
572
+ }
573
+
574
+
575
+ # handle_output ($REQ, $OUTPUT)
576
+ # -----------------------------
577
+ # Run m4 on the input files, perform quadrigraphs substitution, check for
578
+ # forbidden tokens, and save into $OUTPUT.
579
+ sub handle_output ($$)
580
+ {
581
+ my ($req, $output) = @_;
582
+
583
+ verb "creating $output";
584
+
585
+ # Load the forbidden/allowed patterns.
586
+ handle_traces ($req, "$tmp/patterns",
587
+ ('m4_pattern_forbid' => 'forbid:$1:$2',
588
+ 'm4_pattern_allow' => 'allow:$1'));
589
+ my @patterns = new Autom4te::XFile ("$tmp/patterns", "<")->getlines;
590
+ chomp @patterns;
591
+ my %forbidden =
592
+ map { /^forbid:([^:]+):.+$/ => /^forbid:[^:]+:(.+)$/ } @patterns;
593
+ my $forbidden = join ('|', map { /^forbid:([^:]+)/ } @patterns) || "^\$";
594
+ my $allowed = join ('|', map { /^allow:([^:]+)/ } @patterns) || "^\$";
595
+
596
+ verb "forbidden tokens: $forbidden";
597
+ verb "forbidden token : $_ => $forbidden{$_}"
598
+ foreach (sort keys %forbidden);
599
+ verb "allowed tokens: $allowed";
600
+
601
+ # Read the (cached) raw M4 output, produce the actual result.
602
+ # If we are writing to a regular file, replace it atomically.
603
+ my $scratchfile;
604
+ my $out;
605
+ if ($output eq '-')
606
+ {
607
+ # Don't just make $out be STDOUT, because then we would close STDOUT,
608
+ # which we already do in END.
609
+ $out = new Autom4te::XFile ('>&STDOUT');
610
+ }
611
+ elsif (-e $output && ! -f $output)
612
+ {
613
+ $out = new Autom4te::XFile ($output, '>');
614
+ }
615
+ else
616
+ {
617
+ my (undef, $outdir, undef) = fileparse ($output);
618
+ ($out, $scratchfile) = tempfile_with_mode ($outdir, oct($mode));
619
+ }
620
+
621
+ my $in = new Autom4te::XFile ($ocache . $req->id, "<");
622
+
623
+ my %prohibited;
624
+ my $res;
625
+ while ($_ = $in->getline)
626
+ {
627
+ s/\s+$//;
628
+ s/__oline__/$./g;
629
+ s/\@<:\@/[/g;
630
+ s/\@:>\@/]/g;
631
+ s/\@\{:\@/(/g;
632
+ s/\@:\}\@/)/g;
633
+ s/\@S\|\@/\$/g;
634
+ s/\@%:\@/#/g;
635
+
636
+ $res = $_;
637
+
638
+ # Don't complain in comments. Well, until we have something
639
+ # better, don't consider '#include' etc. are comments.
640
+ s/\#.*//
641
+ unless /^\#\s*(if|include|endif|ifdef|ifndef|define)\b/;
642
+ foreach (split (/\W+/))
643
+ {
644
+ $prohibited{$_} = $.
645
+ if !/^$/ && /$forbidden/o && !/$allowed/o
646
+ && ! exists $prohibited{$_};
647
+ }
648
+
649
+ # Performed *last*: the empty quadrigraph.
650
+ $res =~ s/\@&t\@//g;
651
+
652
+ print $out "$res\n";
653
+ }
654
+
655
+ $out->close();
656
+ # Always update the file, even if it didn't change;
657
+ # Automake relies on this.
658
+ update_file ($scratchfile, $output, 1)
659
+ if defined $scratchfile;
660
+
661
+ # If no forbidden words, we're done.
662
+ return
663
+ if ! %prohibited;
664
+
665
+ # Locate the forbidden words in the last input file.
666
+ # This is unsatisfying but...
667
+ $exit_code = 1;
668
+ if ($ARGV[$#ARGV] ne '-')
669
+ {
670
+ my $prohibited = '\b(' . join ('|', keys %prohibited) . ')\b';
671
+ my $file = new Autom4te::XFile ($ARGV[$#ARGV], "<");
672
+
673
+ while ($_ = $file->getline)
674
+ {
675
+ # Don't complain in comments. Well, until we have something
676
+ # better, don't consider '#include' etc. to be comments.
677
+ s/\#.*//
678
+ unless /^\#(if|include|endif|ifdef|ifndef|define)\b/;
679
+
680
+ # Complain once per word, but possibly several times per line.
681
+ while (/$prohibited/)
682
+ {
683
+ my $word = $1;
684
+ warn_forbidden ("$ARGV[$#ARGV]:$.", $word, %forbidden);
685
+ delete $prohibited{$word};
686
+ # If we're done, exit.
687
+ return
688
+ if ! %prohibited;
689
+ $prohibited = '\b(' . join ('|', keys %prohibited) . ')\b';
690
+ }
691
+ }
692
+ }
693
+ warn_forbidden ("$output:$prohibited{$_}", $_, %forbidden)
694
+ foreach (sort { $prohibited{$a} <=> $prohibited{$b} } keys %prohibited);
695
+ }
696
+
697
+
698
+ ## --------------------- ##
699
+ ## Handling the traces. ##
700
+ ## --------------------- ##
701
+
702
+
703
+ # $M4_MACRO
704
+ # trace_format_to_m4 ($FORMAT)
705
+ # ----------------------------
706
+ # Convert a trace $FORMAT into a M4 trace processing macro's body.
707
+ sub trace_format_to_m4 ($)
708
+ {
709
+ my ($format) = @_;
710
+ my $underscore = $_;
711
+ my %escape = (# File name.
712
+ 'f' => '$1',
713
+ # Line number.
714
+ 'l' => '$2',
715
+ # Depth.
716
+ 'd' => '$3',
717
+ # Name (also available as $0).
718
+ 'n' => '$4',
719
+ # Escaped dollar.
720
+ '$' => '$');
721
+
722
+ my $res = '';
723
+ $_ = $format;
724
+ while ($_)
725
+ {
726
+ # $n -> $(n + 4)
727
+ if (s/^\$(\d+)//)
728
+ {
729
+ $res .= "\$" . ($1 + 4);
730
+ }
731
+ # $x, no separator given.
732
+ elsif (s/^\$([fldn\$])//)
733
+ {
734
+ $res .= $escape{$1};
735
+ }
736
+ # $.x or ${sep}x.
737
+ elsif (s/^\$\{([^}]*)\}([@*%])//
738
+ || s/^\$(.?)([@*%])//)
739
+ {
740
+ # $@, list of quoted effective arguments.
741
+ if ($2 eq '@')
742
+ {
743
+ $res .= ']at_at([' . ($1 ? $1 : ',') . '], $@)[';
744
+ }
745
+ # $*, list of unquoted effective arguments.
746
+ elsif ($2 eq '*')
747
+ {
748
+ $res .= ']at_star([' . ($1 ? $1 : ',') . '], $@)[';
749
+ }
750
+ # $%, list of flattened unquoted effective arguments.
751
+ elsif ($2 eq '%')
752
+ {
753
+ $res .= ']at_percent([' . ($1 ? $1 : ':') . '], $@)[';
754
+ }
755
+ }
756
+ elsif (/^(\$.)/)
757
+ {
758
+ error "invalid escape: $1";
759
+ }
760
+ else
761
+ {
762
+ s/^([^\$]+)//;
763
+ $res .= $1;
764
+ }
765
+ }
766
+
767
+ $_ = $underscore;
768
+ return '[[' . $res . ']]';
769
+ }
770
+
771
+
772
+ # handle_traces($REQ, $OUTPUT, %TRACE)
773
+ # ------------------------------------
774
+ # We use M4 itself to process the traces. But to avoid name clashes when
775
+ # processing the traces, the builtins are disabled, and moved into 'at_'.
776
+ # Actually, all the low level processing macros are in 'at_' (and '_at_').
777
+ # To avoid clashes between user macros and 'at_' macros, the macros which
778
+ # implement tracing are in 'AT_'.
779
+ #
780
+ # Having $REQ is needed to neutralize the macros which have been traced,
781
+ # but are not wanted now.
782
+ sub handle_traces ($$%)
783
+ {
784
+ my ($req, $output, %trace) = @_;
785
+
786
+ verb "formatting traces for '$output': " . join (', ', sort keys %trace);
787
+
788
+ # Processing the traces.
789
+ my $trace_m4 = new Autom4te::XFile ("$tmp/traces.m4", ">");
790
+
791
+ $_ = <<'EOF';
792
+ divert(-1)
793
+ changequote([, ])
794
+ # _at_MODE(SEPARATOR, ELT1, ELT2...)
795
+ # ----------------------------------
796
+ # List the elements, separating then with SEPARATOR.
797
+ # MODE can be:
798
+ # 'at' -- the elements are enclosed in brackets.
799
+ # 'star' -- the elements are listed as are.
800
+ # 'percent' -- the elements are 'flattened': spaces are singled out,
801
+ # and no new line remains.
802
+ define([_at_at],
803
+ [at_ifelse([$#], [1], [],
804
+ [$#], [2], [[[$2]]],
805
+ [[[$2]][$1]$0([$1], at_shift(at_shift($@)))])])
806
+
807
+ define([_at_percent],
808
+ [at_ifelse([$#], [1], [],
809
+ [$#], [2], [at_flatten([$2])],
810
+ [at_flatten([$2])[$1]$0([$1], at_shift(at_shift($@)))])])
811
+
812
+ define([_at_star],
813
+ [at_ifelse([$#], [1], [],
814
+ [$#], [2], [[$2]],
815
+ [[$2][$1]$0([$1], at_shift(at_shift($@)))])])
816
+
817
+ # FLATTEN quotes its result.
818
+ # Note that the second pattern is 'newline, tab or space'. Don't lose
819
+ # the tab!
820
+ define([at_flatten],
821
+ [at_patsubst(at_patsubst([[[$1]]], [\\\n]), [[\n\t ]+], [ ])])
822
+
823
+ define([at_args], [at_shift(at_shift(at_shift(at_shift(at_shift($@)))))])
824
+ define([at_at], [_$0([$1], at_args($@))])
825
+ define([at_percent], [_$0([$1], at_args($@))])
826
+ define([at_star], [_$0([$1], at_args($@))])
827
+
828
+ EOF
829
+ s/^ //mg;s/\\t/\t/mg;s/\\n/\n/mg;
830
+ print $trace_m4 $_;
831
+
832
+ # If you trace 'define', then on 'define([m4_exit], defn([m4exit])' you
833
+ # will produce
834
+ #
835
+ # AT_define([m4sugar.m4], [115], [1], [define], [m4_exit], <m4exit>)
836
+ #
837
+ # Since '<m4exit>' is not quoted, the outer m4, when processing
838
+ # 'trace.m4' will exit prematurely. Hence, move all the builtins to
839
+ # the 'at_' name space.
840
+
841
+ print $trace_m4 "# Copy the builtins.\n";
842
+ map { print $trace_m4 "define([at_$_], defn([$_]))\n" } @m4_builtin;
843
+ print $trace_m4 "\n";
844
+
845
+ print $trace_m4 "# Disable them.\n";
846
+ map { print $trace_m4 "at_undefine([$_])\n" } @m4_builtin;
847
+ print $trace_m4 "\n";
848
+
849
+
850
+ # Neutralize traces: we don't want traces of cached requests (%REQUEST).
851
+ print $trace_m4
852
+ "## -------------------------------------- ##\n",
853
+ "## By default neutralize all the traces. ##\n",
854
+ "## -------------------------------------- ##\n",
855
+ "\n";
856
+ print $trace_m4 "at_define([AT_$_], [at_dnl])\n"
857
+ foreach (sort keys %{$req->macro});
858
+ print $trace_m4 "\n";
859
+
860
+ # Implement traces for current requests (%TRACE).
861
+ print $trace_m4
862
+ "## ------------------------- ##\n",
863
+ "## Trace processing macros. ##\n",
864
+ "## ------------------------- ##\n",
865
+ "\n";
866
+ foreach (sort keys %trace)
867
+ {
868
+ # Trace request can be embed \n.
869
+ (my $comment = "Trace $_:$trace{$_}") =~ s/^/\# /;
870
+ print $trace_m4 "$comment\n";
871
+ print $trace_m4 "at_define([AT_$_],\n";
872
+ print $trace_m4 trace_format_to_m4 ($trace{$_}) . ")\n\n";
873
+ }
874
+ print $trace_m4 "\n";
875
+
876
+ # Reenable output.
877
+ print $trace_m4 "at_divert(0)at_dnl\n";
878
+
879
+ # Transform the traces from m4 into an m4 input file.
880
+ # Typically, transform:
881
+ #
882
+ # | m4trace:configure.ac:3: -1- AC_SUBST([exec_prefix], [NONE])
883
+ #
884
+ # into
885
+ #
886
+ # | AT_AC_SUBST([configure.ac], [3], [1], [AC_SUBST], [exec_prefix], [NONE])
887
+ #
888
+ # Pay attention that the file name might include colons, if under DOS
889
+ # for instance, so we don't use '[^:]+'.
890
+ my $traces = new Autom4te::XFile ($tcache . $req->id, "<");
891
+ while ($_ = $traces->getline)
892
+ {
893
+ # Trace with arguments, as the example above. We don't try
894
+ # to match the trailing parenthesis as it might be on a
895
+ # separate line.
896
+ s{^m4trace:(.+):(\d+): -(\d+)- ([^(]+)\((.*)$}
897
+ {AT_$4([$1], [$2], [$3], [$4], $5};
898
+ # Traces without arguments, always on a single line.
899
+ s{^m4trace:(.+):(\d+): -(\d+)- ([^)]*)\n$}
900
+ {AT_$4([$1], [$2], [$3], [$4])\n};
901
+ print $trace_m4 "$_";
902
+ }
903
+ $trace_m4->close;
904
+
905
+ my $in = new Autom4te::XFile ("$m4 " . shell_quote ("$tmp/traces.m4") . " |");
906
+ my $out = new Autom4te::XFile;
907
+ if ($output eq '-')
908
+ {
909
+ $out->open (">$output");
910
+ }
911
+ else
912
+ {
913
+ $out->open ($output, ">");
914
+ }
915
+
916
+ # This is dubious: should we really transform the quadrigraphs in
917
+ # traces? It might break balanced [ ] etc. in the output. The
918
+ # consensus seems to be that traces are more useful this way.
919
+ while ($_ = $in->getline)
920
+ {
921
+ # It makes no sense to try to transform __oline__.
922
+ s/\@<:\@/[/g;
923
+ s/\@:>\@/]/g;
924
+ s/\@\{:\@/(/g;
925
+ s/\@:\}\@/)/g;
926
+ s/\@S\|\@/\$/g;
927
+ s/\@%:\@/#/g;
928
+ s/\@&t\@//g;
929
+ print $out $_;
930
+ }
931
+ }
932
+
933
+
934
+ # $BOOL
935
+ # up_to_date ($REQ)
936
+ # -----------------
937
+ # Are the cache files of $REQ up to date?
938
+ # $REQ is 'valid' if it corresponds to the request and exists, which
939
+ # does not mean it is up to date. It is up to date if, in addition,
940
+ # its files are younger than its dependencies.
941
+ sub up_to_date ($)
942
+ {
943
+ my ($req) = @_;
944
+
945
+ return 0
946
+ if ! $req->valid;
947
+
948
+ my $tfile = $tcache . $req->id;
949
+ my $ofile = $ocache . $req->id;
950
+
951
+ # We can't answer properly if the traces are not computed since we
952
+ # need to know what other files were included. Actually, if any of
953
+ # the cache files are missing, we are not up to date.
954
+ return 0
955
+ if ! -f $tfile || ! -f $ofile;
956
+
957
+ # Both cache files must be younger than all dependencies,
958
+ # so use the minimum of the two cache files' timestamps.
959
+ my $tmtime = mtime ($tfile);
960
+ my $omtime = mtime ($ofile);
961
+ my ($file, $mtime) = ($omtime < $tmtime
962
+ ? ($ofile, $omtime) : ($tfile, $tmtime));
963
+
964
+ # stdin is always out of date.
965
+ if (grep { $_ eq '-' } @ARGV)
966
+ { return 0 }
967
+
968
+ # We depend at least upon the arguments.
969
+ foreach my $dep (@ARGV)
970
+ {
971
+ if ($mtime <= mtime ($dep))
972
+ {
973
+ verb "up_to_date ($file): outdated: $dep";
974
+ return 0;
975
+ }
976
+ }
977
+
978
+ # Files may include others. We can use traces since we just checked
979
+ # if they are available.
980
+ handle_traces ($req, "$tmp/dependencies",
981
+ ('include' => '$1',
982
+ 'm4_include' => '$1'));
983
+ my $deps = new Autom4te::XFile ("$tmp/dependencies", "<");
984
+ while ($_ = $deps->getline)
985
+ {
986
+ chomp;
987
+ my $dep = find_file ("$_?", @include);
988
+ # If a file which used to be included is no longer there, then
989
+ # don't say it's missing (it might no longer be included). But
990
+ # of course, that causes the output to be outdated (as if the
991
+ # timestamp of that missing file was newer).
992
+ return 0
993
+ if ! $dep;
994
+ if ($mtime <= mtime ($dep))
995
+ {
996
+ verb "up_to_date ($file): outdated: $dep";
997
+ return 0;
998
+ }
999
+ }
1000
+
1001
+ verb "up_to_date ($file): up to date";
1002
+ return 1;
1003
+ }
1004
+
1005
+
1006
+ ## ---------- ##
1007
+ ## Freezing. ##
1008
+ ## ---------- ##
1009
+
1010
+ # freeze ($OUTPUT)
1011
+ # ----------------
1012
+ sub freeze ($)
1013
+ {
1014
+ my ($output) = @_;
1015
+
1016
+ # When processing the file with diversion disabled, there must be no
1017
+ # output but comments and empty lines.
1018
+ my $result = xqx ("$m4"
1019
+ . ' --fatal-warning'
1020
+ . join (' --include=', '', map { shell_quote ($_) } @include)
1021
+ . ' --define=divert'
1022
+ . " " . files_to_options (@ARGV)
1023
+ . ' </dev/null');
1024
+ $result =~ s/#.*\n//g;
1025
+ $result =~ s/^\n//mg;
1026
+
1027
+ fatal "freezing produced output:\n$result"
1028
+ if $result;
1029
+
1030
+ # If freezing produces output, something went wrong: a bad 'divert',
1031
+ # or an improper paren etc.
1032
+ xsystem ("$m4"
1033
+ . ' --fatal-warning'
1034
+ . join (' --include=', '', map { shell_quote ($_) } @include)
1035
+ . " --freeze-state=" . shell_quote ($output)
1036
+ . " " . files_to_options (@ARGV)
1037
+ . ' </dev/null');
1038
+ }
1039
+
1040
+ ## -------------- ##
1041
+ ## Main program. ##
1042
+ ## -------------- ##
1043
+
1044
+ mktmpdir ('am4t');
1045
+ load_configuration ($ENV{'AUTOM4TE_CFG'} || "$pkgdatadir/autom4te.cfg");
1046
+ load_configuration ("$ENV{'HOME'}/.autom4te.cfg")
1047
+ if exists $ENV{'HOME'} && -f "$ENV{'HOME'}/.autom4te.cfg";
1048
+ load_configuration (".autom4te.cfg")
1049
+ if -f ".autom4te.cfg";
1050
+ parse_args;
1051
+
1052
+ # Freezing does not involve the cache.
1053
+ if ($freeze)
1054
+ {
1055
+ freeze ($output);
1056
+ exit $exit_code;
1057
+ }
1058
+
1059
+ # Ensure the cache directory exists.
1060
+ if (! mkdir ($cache, 0755))
1061
+ {
1062
+ # Snapshot $! immediately, the next few operations may clobber it.
1063
+ my $eexist = $!{EEXIST};
1064
+ my $errmsg = "$!";
1065
+
1066
+ # If mkdir failed with EEXIST, that means the *name* $cache
1067
+ # already exists, but it might be the wrong kind of file.
1068
+ if (! $eexist || ! -d $cache)
1069
+ {
1070
+ require Cwd;
1071
+ my $cwd = Cwd::cwd();
1072
+ fatal "cannot create $cache in $cwd: $errmsg";
1073
+ }
1074
+ }
1075
+
1076
+ # Open the index for update, and lock it. autom4te handles several
1077
+ # files, but the index is the first and last file to be updated, so
1078
+ # locking it is sufficient.
1079
+ $icache_file = new Autom4te::XFile $icache, O_RDWR|O_CREAT;
1080
+ $icache_file->lock (LOCK_EX)
1081
+ if ($flock_implemented eq "yes");
1082
+
1083
+ # Read the cache index if available and younger than autom4te itself.
1084
+ # If the cache index is not younger, some structures such as C4che might
1085
+ # have changed, which would corrupt its processing.
1086
+ Autom4te::C4che->load ($icache_file)
1087
+ if (-f $icache && mtime ($icache) > mtime ($0)
1088
+ && Autom4te::C4che->good_version ($icache_file, '2.72'));
1089
+
1090
+ # Add the new trace requests.
1091
+ my $req = Autom4te::C4che->request ('input' => \@ARGV,
1092
+ 'path' => \@include,
1093
+ 'macro' => [keys %trace, @preselect]);
1094
+
1095
+ # If $REQ's cache files are not up to date, or simply if the user
1096
+ # discarded them (-f), declare it invalid.
1097
+ $req->valid (0)
1098
+ if $force || ! up_to_date ($req);
1099
+
1100
+ # We now know whether we can trust the Request object. Say it.
1101
+ verb "the trace request object is:\n" . $req->marshall;
1102
+
1103
+ # We need to run M4 if (i) the user wants it (--force), (ii) $REQ is
1104
+ # invalid.
1105
+ handle_m4 ($req, keys %{$req->macro})
1106
+ if $force || ! $req->valid;
1107
+
1108
+ # Issue the warnings each time autom4te was run.
1109
+ my $separator = "\n" . ('-' x 25) . " END OF WARNING " . ('-' x 25) . "\n\n";
1110
+ handle_traces ($req, "$tmp/warnings",
1111
+ ('_m4_warn' => "\$1::\$f:\$l::\$2::\$3$separator"));
1112
+ # Swallow excessive newlines.
1113
+ for (split (/\n*$separator\n*/o, contents ("$tmp/warnings")))
1114
+ {
1115
+ # The message looks like:
1116
+ # | syntax::input.as:5::ouch
1117
+ # | ::input.as:4: baz is expanded from...
1118
+ # | input.as:2: bar is expanded from...
1119
+ # | input.as:3: foo is expanded from...
1120
+ # | input.as:5: the top level
1121
+ # In particular, m4_warn guarantees that either $stackdump is empty, or
1122
+ # it consists of lines where only the last line ends in "top level".
1123
+ my ($cat, $loc, $msg, $stacktrace) = split ('::', $_, 4);
1124
+ # There might not have been a stacktrace.
1125
+ $stacktrace = '' unless defined $stacktrace;
1126
+ msg $cat, $loc, $msg,
1127
+ partial => ($stacktrace =~ /top level$/) + 0;
1128
+ for (split /\n/, $stacktrace)
1129
+ {
1130
+ my ($loc, $trace) = split (': ', $_, 2);
1131
+ msg $cat, $loc, $trace, partial => ($trace !~ /top level$/) + 0;
1132
+ }
1133
+ }
1134
+
1135
+ # Now output...
1136
+ if (%trace)
1137
+ {
1138
+ # Always produce traces, since even if the output is young enough,
1139
+ # there is no guarantee that the traces use the same *format*
1140
+ # (e.g., '-t FOO:foo' and '-t FOO:bar' are both using the same M4
1141
+ # traces, hence the M4 traces cache is usable, but its formatting
1142
+ # will yield different results).
1143
+ handle_traces ($req, $output, %trace);
1144
+ }
1145
+ else
1146
+ {
1147
+ # Actual M4 expansion, if the user wants it, or if $output is old
1148
+ # (STDOUT is pretty old).
1149
+ handle_output ($req, $output)
1150
+ if $force || mtime ($output) <= mtime ($ocache . $req->id);
1151
+ }
1152
+
1153
+ # If we ran up to here, the cache is valid.
1154
+ $req->valid (1);
1155
+ Autom4te::C4che->save ($icache_file, '2.72');
1156
+
1157
+ exit $exit_code;
1158
+
1159
+ ### Setup "GNU" style for perl-mode and cperl-mode.
1160
+ ## Local Variables:
1161
+ ## perl-indent-level: 2
1162
+ ## perl-continued-statement-offset: 2
1163
+ ## perl-continued-brace-offset: 0
1164
+ ## perl-brace-offset: 0
1165
+ ## perl-brace-imaginary-offset: 0
1166
+ ## perl-label-offset: -2
1167
+ ## cperl-indent-level: 2
1168
+ ## cperl-brace-offset: 0
1169
+ ## cperl-continued-brace-offset: 0
1170
+ ## cperl-label-offset: -2
1171
+ ## cperl-extra-newline-before-brace: t
1172
+ ## cperl-merge-trailing-else: nil
1173
+ ## cperl-continued-statement-offset: 2
1174
+ ## End: