5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # autom4te - Wrapper around M4 libraries.
9 # Copyright (C) 2001, 2002, 2003, 2005, 2006, 2007 Free Software
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)
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., 51 Franklin Street, Fifth Floor, Boston, MA
30 my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@';
31 unshift @INC, $datadir;
33 # Override SHELL. On DJGPP SHELL may not be set to a shell
34 # that can handle redirection and quote arguments correctly,
35 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
37 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
41 use Autom4te::ChannelDefs;
42 use Autom4te::Channels;
43 use Autom4te::FileUtils;
44 use Autom4te::General;
50 my $datadir = $ENV{'AC_MACRODIR'} || '@datadir@';
52 # $LANGUAGE{LANGUAGE} -- Automatic options for LANGUAGE.
57 # Mode of the output file except for traces.
60 # If melt, don't use frozen files.
63 # Names of the cache directory, cache directory index, trace cache
64 # prefix, and output cache prefix. And the IO object for the index.
71 # The macros to trace mapped to their format, as specified by the
75 # The macros the user will want to trace in the future.
76 # We need `include' to get the included file, `m4_pattern_forbid' and
77 # `m4_pattern_allow' to check the output.
79 # FIXME: What about `sinclude'?
80 my @preselect = ('include',
81 'm4_pattern_allow', 'm4_pattern_forbid',
91 my $m4 = $ENV{"M4"} || '@M4@';
92 # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
93 fatal "need GNU m4 1.4 or later: $m4"
94 if system "$m4 --help </dev/null 2>&1 | grep reload-state >/dev/null";
96 # Set some high recursion limit as the default limit, 250, has already
97 # been hit with AC_OUTPUT. Don't override the user's choice.
98 $m4 .= ' --nesting-limit=1024'
99 if " $m4 " !~ / (--nesting-limit(=[0-9]+)?|-L[0-9]*) /;
102 # @M4_BUILTIN -- M4 builtins and a useful comment.
103 my @m4_builtin = `echo dumpdef | $m4 2>&1 >/dev/null`;
104 map { s/:.*//;s/\W// } @m4_builtin;
107 # %M4_BUILTIN_ALTERNATE_NAME
108 # --------------------------
109 # The builtins are renamed, e.g., `define' is renamed `m4_define'.
110 # So map `define' to `m4_define' and conversely.
111 # Some macros don't follow this scheme: be sure to properly map to their
112 # alternate name too.
114 # This is because GNU M4 1.4's tracing of builtins is buggy. When run on
118 # | changequote([, ])
119 # | define([m4_eval], defn([eval]))
125 # it behaves this way:
127 # | % m4 input.m4 -da -t eval
128 # | m4trace: -1- eval(1)
129 # | m4trace: -1- m4_eval(2)
130 # | m4trace: -1- m4_eval(3)
135 # | % m4 input.m4 -da -t m4_eval
138 # So we will merge them, i.e., tracing `BUILTIN' or tracing
139 # `m4_BUILTIN' will be the same: tracing both, but honoring the
140 # *last* trace specification.
142 # FIXME: This is not enough: in the output `$0' will be `BUILTIN'
143 # sometimes and `m4_BUILTIN' at others. We should return a unique name,
144 # the one specified by the user.
146 # FIXME: To be absolutely rigorous, I would say that given that we
147 # _redefine_ divert (instead of _copying_ it), divert and the like
148 # should not be part of this list.
149 my %m4_builtin_alternate_name;
150 @m4_builtin_alternate_name{"$_", "m4_$_"} = ("m4_$_", "$_")
151 foreach (grep { !/m4wrap|m4exit|dnl|ifelse|__.*__/ } @m4_builtin);
152 @m4_builtin_alternate_name{"ifelse", "m4_if"} = ("m4_if", "ifelse");
153 @m4_builtin_alternate_name{"m4exit", "m4_exit"} = ("m4_exit", "m4exit");
154 @m4_builtin_alternate_name{"m4wrap", "m4_wrap"} = ("m4_wrap", "m4wrap");
159 $help = "Usage: $0 [OPTION] ... [FILES]
161 Run GNU M4 on the FILES, avoiding useless runs. Output the traces if tracing,
162 the frozen file if freezing, otherwise the expansion of the FILES.
164 If some of the FILES are named \`FILE.m4f\' they are considered to be M4
165 frozen files of all the previous files (which are therefore not loaded).
166 If \`FILE.m4f\' is not found, then \`FILE.m4\' will be used, together with
167 all the previous files.
169 Some files may be optional, i.e., will only be processed if found in the
170 include path, but then must end in \`.m4?\'; the question mark is not part of
171 the actual file name.
174 -h, --help print this help, then exit
175 -V, --version print version number, then exit
176 -v, --verbose verbosely report processing
177 -d, --debug don\'t remove temporary files
178 -o, --output=FILE save output in FILE (defaults to \`-\', stdout)
179 -f, --force don\'t rely on cached values
180 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
181 -l, --language=LANG specify the set of M4 macros to use
182 -C, --cache=DIRECTORY preserve results for future runs in DIRECTORY
183 --no-cache disable the cache
184 -m, --mode=OCTAL change the non trace output file mode (0666)
185 -M, --melt don\'t use M4 frozen files
188 \`Autoconf\' create Autoconf configure scripts
189 \`Autotest\' create Autotest test suites
190 \`M4sh\' create M4sh shell scripts
191 \`M4sugar\' create M4sugar output
193 " . Autom4te::ChannelDefs::usage . "
195 The environment variables \`M4\' and \`WARNINGS\' are honored.
198 -B, --prepend-include=DIR prepend directory DIR to search path
199 -I, --include=DIR append directory DIR to search path
202 -t, --trace=MACRO report the MACRO invocations
203 -p, --preselect=MACRO prepare to trace MACRO in a future run
206 -F, --freeze produce an M4 frozen state file for FILES
208 Report bugs to <bug-autoconf\@gnu.org>.
214 autom4te (@PACKAGE_NAME@) @VERSION@
215 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
216 This is free software. You may redistribute copies of it under the terms of
217 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
218 There is NO WARRANTY, to the extent permitted by law.
220 Written by Akim Demaille.
230 # files_to_options (@FILE)
231 # ------------------------
232 # Transform Autom4te conventions (e.g., using foo.m4f to designate a frozen
233 # file) into a suitable command line for M4 (e.g., using --reload-state).
234 sub files_to_options (@)
238 foreach my $file (@file)
240 if ($file =~ /\.m4f$/)
242 push @res, "--reload-state=$file";
249 return join ' ', @res;
253 # load_configuration ($FILE)
254 # --------------------------
255 # Load the configuration $FILE.
256 sub load_configuration ($)
259 use Text::ParseWords;
261 my $cfg = new Autom4te::XFile ($file);
263 while ($_ = $cfg->getline)
270 my @words = shellwords ($_);
271 my $type = shift @words;
272 if ($type eq 'begin-language:')
274 fatal "$file:$.: end-language missing for: $lang"
276 $lang = lc $words[0];
278 elsif ($type eq 'end-language:')
280 error "$file:$.: end-language mismatch: $lang"
281 if $lang ne lc $words[0];
284 elsif ($type eq 'args:')
286 fatal "$file:$.: no current language"
287 unless defined $lang;
288 push @{$language{$lang}}, @words;
292 error "$file:$.: unknown directive: $type";
300 # Process any command line arguments.
303 # We want to look for the early options, which should not be found
304 # in the configuration file. Prepend to the user arguments.
305 # Perform this repeatedly so that we can use --language in language
306 # definitions. Beware that there can be several --language
312 Getopt::Long::Configure ("pass_through", "permute");
313 GetOptions ("l|language=s" => \@language);
317 error "unknown language: $_"
318 unless exists $language{lc $_};
319 unshift @ARGV, @{$language{lc $_}};
323 # --debug is useless: it is parsed below.
324 if (exists $ENV{'AUTOM4TE_DEBUG'})
326 print STDERR "$me: concrete arguments:\n";
327 foreach my $arg (@ARGV)
329 print STDERR "| $arg\n";
333 # Process the arguments for real this time.
340 "o|output=s" => \$output,
341 "W|warnings=s" => \&parse_warnings,
342 "m|mode=s" => \$mode,
345 # Library directories:
346 "B|prepend-include=s" => \@prepend_include,
347 "I|include=s" => \@include,
350 # Using a hash for traces is seducing. Unfortunately, upon `-t FOO',
351 # instead of mapping `FOO' to undef, Getopt maps it to `1', preventing
352 # us from distinguishing `-t FOO' from `-t FOO=1'. So let's do it
354 "t|trace=s" => \@trace,
355 "p|preselect=s" => \@preselect,
358 "F|freeze" => \$freeze,
361 "C|cache=s" => \$cache,
362 "no-cache" => sub { $cache = undef; },
365 fatal "too few arguments
366 Try `$me --help' for more information."
370 # We cannot trace at the same time (well, we can, but it sounds insane).
371 # And it implies melting: there is risk not to update properly using
372 # old frozen files, and worse yet: we could load a frozen file and
373 # refreeze it! A sort of caching :)
374 fatal "cannot freeze and trace"
375 if $freeze && @trace;
379 # Names of the cache directory, cache directory index, trace cache
380 # prefix, and output cache prefix. If the cache is not to be
381 # preserved, default to a temporary directory (automatically removed
385 $icache = "$cache/requests";
386 $tcache = "$cache/traces.";
387 $ocache = "$cache/output.";
389 # Normalize the includes: the first occurrence is enough, several is
390 # a pain since it introduces a useless difference in the path which
391 # invalidates the cache. And strip `.' which is implicit and always
393 @include = grep { !/^\.$/ } uniq (reverse(@prepend_include), @include);
395 # Convert @trace to %trace, and work around the M4 builtins tracing
397 # The default format is `$f:$l:$n:$%'.
400 /^([^:]+)(?::(.*))?$/ms;
401 $trace{$1} = defined $2 ? $2 : '$f:$l:$n:$%';
402 $trace{$m4_builtin_alternate_name{$1}} = $trace{$1}
403 if exists $m4_builtin_alternate_name{$1};
406 # Work around the M4 builtins tracing problem for @PRESELECT.
408 map { $m4_builtin_alternate_name{$_} }
409 grep { exists $m4_builtin_alternate_name{$_} } @preselect);
411 # If we find frozen files, then all the files before it are
412 # discarded: the frozen file is supposed to include them all.
414 # We don't want to depend upon m4's --include to find the top level
415 # files, so we use `find_file' here. Try to get a canonical name,
416 # as it's part of the key for caching. And some files are optional
417 # (also handled by `find_file').
427 # Frozen files are optional => pass a `?' to `find_file'.
428 my $file = find_file ("$_?", @include);
436 push @argv, find_file ($_, @include);
441 my $file = find_file ($_, @include);
450 # handle_m4 ($REQ, @MACRO)
451 # ------------------------
452 # Run m4 on the input files, and save the traces on the @MACRO.
455 my ($req, @macro) = @_;
457 # GNU m4 appends when using --debugfile/--error-output.
458 unlink ($tcache . $req->id . "t");
462 # We don't output directly to the cache files, to avoid problems
463 # when we are interrupted (that leaves corrupted files).
465 . join (' --include=', '', @include)
467 . (!exists $ENV{'AUTOM4TE_NO_FATAL'} ? ' --fatal-warning' : '')
468 . " @M4_DEBUGFILE@=$tcache" . $req->id . "t"
469 . join (' --trace=', '', sort @macro)
470 . " " . files_to_options (@ARGV)
471 . " >$ocache" . $req->id . "t");
473 # Everything went ok: preserve the outputs.
474 foreach my $file (map { $_ . $req->id } ($tcache, $ocache))
477 move ("${file}t", "$file")
478 or fatal "cannot rename ${file}t as $file: $!";
483 # warn_forbidden ($WHERE, $WORD, %FORBIDDEN)
484 # ------------------------------------------
485 # $WORD is forbidden. Warn with a dedicated error message if in
486 # %FORBIDDEN, otherwise a simple `error: possibly undefined macro'
488 my $first_warn_forbidden = 1;
489 sub warn_forbidden ($$%)
491 my ($where, $word, %forbidden) = @_;
494 for my $re (sort keys %forbidden)
498 $message = $forbidden{$re};
502 $message ||= "possibly undefined macro: $word";
503 warn "$where: error: $message\n";
504 if ($first_warn_forbidden)
507 If this token and others are legitimate, please use m4_pattern_allow.
508 See the Autoconf documentation.
510 $first_warn_forbidden = 0;
515 # handle_output ($REQ, $OUTPUT)
516 # -----------------------------
517 # Run m4 on the input files, perform quadrigraphs substitution, check for
518 # forbidden tokens, and save into $OUTPUT.
519 sub handle_output ($$)
521 my ($req, $output) = @_;
523 verb "creating $output";
525 # Load the forbidden/allowed patterns.
526 handle_traces ($req, "$tmp/patterns",
527 ('m4_pattern_forbid' => 'forbid:$1:$2',
528 'm4_pattern_allow' => 'allow:$1'));
529 my @patterns = new Autom4te::XFile ("$tmp/patterns")->getlines;
532 map { /^forbid:([^:]+):.+$/ => /^forbid:[^:]+:(.+)$/ } @patterns;
533 my $forbidden = join ('|', map { /^forbid:([^:]+)/ } @patterns) || "^\$";
534 my $allowed = join ('|', map { /^allow:([^:]+)/ } @patterns) || "^\$";
536 verb "forbidden tokens: $forbidden";
537 verb "forbidden token : $_ => $forbidden{$_}"
538 foreach (sort keys %forbidden);
539 verb "allowed tokens: $allowed";
541 # Read the (cached) raw M4 output, produce the actual result. We
542 # have to use the 2nd arg to have Autom4te::XFile honor the third, but then
543 # stdout is to be handled by hand :(. Don't use fdopen as it means
544 # we will close STDOUT, which we already do in END.
545 my $out = new Autom4te::XFile;
548 $out->open (">$output");
552 $out->open($output, O_CREAT | O_WRONLY | O_TRUNC, oct ($mode));
554 fatal "cannot create $output: $!"
556 my $in = new Autom4te::XFile ($ocache . $req->id);
560 while ($_ = $in->getline)
571 # Don't complain in comments. Well, until we have something
572 # better, don't consider `#include' etc. are comments.
574 unless /^\#\s*(if|include|endif|ifdef|ifndef|define)\b/;
575 foreach (split (/\W+/))
578 if !/^$/ && /$forbidden/o && !/$allowed/o && ! exists $prohibited{$_};
581 # Performed *last*: the empty quadrigraph.
587 # If no forbidden words, we're done.
591 # Locate the forbidden words in the last input file.
592 # This is unsatisfying but...
594 if ($ARGV[$#ARGV] ne '-')
596 my $prohibited = '\b(' . join ('|', keys %prohibited) . ')\b';
597 my $file = new Autom4te::XFile ($ARGV[$#ARGV]);
599 while ($_ = $file->getline)
601 # Don't complain in comments. Well, until we have something
602 # better, don't consider `#include' etc. to be comments.
604 unless /^\#(if|include|endif|ifdef|ifndef|define)\b/;
606 # Complain once per word, but possibly several times per line.
607 while (/$prohibited/)
610 warn_forbidden ("$ARGV[$#ARGV]:$.", $word, %forbidden);
611 delete $prohibited{$word};
612 # If we're done, exit.
615 $prohibited = '\b(' . join ('|', keys %prohibited) . ')\b';
619 warn_forbidden ("$output:$prohibited{$_}", $_, %forbidden)
620 foreach (sort { $prohibited{$a} <=> $prohibited{$b} } keys %prohibited);
624 ## --------------------- ##
625 ## Handling the traces. ##
626 ## --------------------- ##
630 # trace_format_to_m4 ($FORMAT)
631 # ----------------------------
632 # Convert a trace $FORMAT into a M4 trace processing macro's body.
633 sub trace_format_to_m4 ($)
637 my %escape = (# File name.
643 # Name (also available as $0).
655 $res .= "\$" . ($1 + 4);
657 # $x, no separator given.
658 elsif (s/^\$([fldn\$])//)
663 elsif (s/^\$\{([^}]*)\}([@*%])//
664 || s/^\$(.?)([@*%])//)
666 # $@, list of quoted effective arguments.
669 $res .= ']at_at([' . ($1 ? $1 : ',') . '], $@)[';
671 # $*, list of unquoted effective arguments.
674 $res .= ']at_star([' . ($1 ? $1 : ',') . '], $@)[';
676 # $%, list of flattened unquoted effective arguments.
679 $res .= ']at_percent([' . ($1 ? $1 : ':') . '], $@)[';
684 error "invalid escape: $1";
694 return '[[' . $res . ']]';
698 # handle_traces($REQ, $OUTPUT, %TRACE)
699 # ------------------------------------
700 # We use M4 itself to process the traces. But to avoid name clashes when
701 # processing the traces, the builtins are disabled, and moved into `at_'.
702 # Actually, all the low level processing macros are in `at_' (and `_at_').
703 # To avoid clashes between user macros and `at_' macros, the macros which
704 # implement tracing are in `AT_'.
706 # Having $REQ is needed to neutralize the macros which have been traced,
707 # but are not wanted now.
708 sub handle_traces ($$%)
710 my ($req, $output, %trace) = @_;
712 verb "formatting traces for `$output': " . join (', ', sort keys %trace);
714 # Processing the traces.
715 my $trace_m4 = new Autom4te::XFile (">$tmp/traces.m4");
720 # _at_MODE(SEPARATOR, ELT1, ELT2...)
721 # ----------------------------------
722 # List the elements, separating then with SEPARATOR.
724 # `at' -- the elements are enclosed in brackets.
725 # `star' -- the elements are listed as are.
726 # `percent' -- the elements are `flattened': spaces are singled out,
727 # and no new line remains.
729 [at_ifelse([$#], [1], [],
731 [[[$2]][$1]$0([$1], at_shift(at_shift($@)))])])
733 define([_at_percent],
734 [at_ifelse([$#], [1], [],
735 [$#], [2], [at_flatten([$2])],
736 [at_flatten([$2])[$1]$0([$1], at_shift(at_shift($@)))])])
739 [at_ifelse([$#], [1], [],
741 [[$2][$1]$0([$1], at_shift(at_shift($@)))])])
743 # FLATTEN quotes its result.
744 # Note that the second pattern is `newline, tab or space'. Don't lose
747 [at_patsubst(at_patsubst(at_patsubst(at_patsubst([[[[$1]]]], [\\\n]),
750 [^ *\(.*\)], [[\1]])])
752 define([at_args], [at_shift(at_shift(at_shift(at_shift(at_shift($@)))))])
753 define([at_at], [_$0([$1], at_args($@))])
754 define([at_percent], [_$0([$1], at_args($@))])
755 define([at_star], [_$0([$1], at_args($@))])
758 s/^ //mg;s/\\t/\t/mg;s/\\n/\n/mg;
761 # If you trace `define', then on `define([m4_exit], defn([m4exit])' you
764 # AT_define([m4sugar.m4], [115], [1], [define], [m4_exit], <m4exit>)
766 # Since `<m4exit>' is not quoted, the outer m4, when processing
767 # `trace.m4' will exit prematurely. Hence, move all the builtins to
768 # the `at_' name space.
770 print $trace_m4 "# Copy the builtins.\n";
771 map { print $trace_m4 "define([at_$_], defn([$_]))\n" } @m4_builtin;
772 print $trace_m4 "\n";
774 print $trace_m4 "# Disable them.\n";
775 map { print $trace_m4 "at_undefine([$_])\n" } @m4_builtin;
776 print $trace_m4 "\n";
779 # Neutralize traces: we don't want traces of cached requests (%REQUEST).
781 "## -------------------------------------- ##\n",
782 "## By default neutralize all the traces. ##\n",
783 "## -------------------------------------- ##\n",
785 print $trace_m4 "at_define([AT_$_], [at_dnl])\n"
786 foreach (sort keys %{$req->macro});
787 print $trace_m4 "\n";
789 # Implement traces for current requests (%TRACE).
791 "## ------------------------- ##\n",
792 "## Trace processing macros. ##\n",
793 "## ------------------------- ##\n",
795 foreach (sort keys %trace)
797 # Trace request can be embed \n.
798 (my $comment = "Trace $_:$trace{$_}") =~ s/^/\# /;
799 print $trace_m4 "$comment\n";
800 print $trace_m4 "at_define([AT_$_],\n";
801 print $trace_m4 trace_format_to_m4 ($trace{$_}) . ")\n\n";
803 print $trace_m4 "\n";
806 print $trace_m4 "at_divert(0)at_dnl\n";
808 # Transform the traces from m4 into an m4 input file.
809 # Typically, transform:
811 # | m4trace:configure.ac:3: -1- AC_SUBST([exec_prefix], [NONE])
815 # | AT_AC_SUBST([configure.ac], [3], [1], [AC_SUBST], [exec_prefix], [NONE])
817 # Pay attention that the file name might include colons, if under DOS
818 # for instance, so we don't use `[^:]+'.
819 my $traces = new Autom4te::XFile ($tcache . $req->id);
820 while ($_ = $traces->getline)
822 # Trace with arguments, as the example above. We don't try
823 # to match the trailing parenthesis as it might be on a
825 s{^m4trace:(.+):(\d+): -(\d+)- ([^(]+)\((.*)$}
826 {AT_$4([$1], [$2], [$3], [$4], $5};
827 # Traces without arguments, always on a single line.
828 s{^m4trace:(.+):(\d+): -(\d+)- ([^)]*)\n$}
829 {AT_$4([$1], [$2], [$3], [$4])\n};
830 print $trace_m4 "$_";
834 my $in = new Autom4te::XFile ("$m4 $tmp/traces.m4 |");
835 my $out = new Autom4te::XFile (">$output");
837 # This is dubious: should we really transform the quadrigraphs in
838 # traces? It might break balanced [ ] etc. in the output. The
839 # consensus seeems to be that traces are more useful this way.
840 while ($_ = $in->getline)
842 # It makes no sense to try to transform __oline__.
856 # Are the cache files of $REQ up to date?
857 # $REQ is `valid' if it corresponds to the request and exists, which
858 # does not mean it is up to date. It is up to date if, in addition,
859 # its files are younger than its dependencies.
867 my $tfile = $tcache . $req->id;
868 my $ofile = $ocache . $req->id;
870 # We can't answer properly if the traces are not computed since we
871 # need to know what other files were included. Actually, if any of
872 # the cache files is missing, we are not up to date.
874 if ! -f $tfile || ! -f $ofile;
876 # The youngest of the cache files must be older than the oldest of
878 my $tmtime = mtime ($tfile);
879 my $omtime = mtime ($ofile);
880 my ($file, $mtime) = ($tmtime < $omtime
881 ? ($ofile, $omtime) : ($tfile, $tmtime));
883 # We depend at least upon the arguments.
886 # stdin is always out of date.
887 if (grep { $_ eq '-' } @dep)
890 # Files may include others. We can use traces since we just checked
891 # if they are available.
892 handle_traces ($req, "$tmp/dependencies",
894 'm4_include' => '$1'));
895 my $deps = new Autom4te::XFile ("$tmp/dependencies");
896 while ($_ = $deps->getline)
899 my $file = find_file ("$_?", @include);
900 # If a file which used to be included is no longer there, then
901 # don't say it's missing (it might no longer be included). But
902 # of course, that causes the output to be outdated (as if the
903 # time stamp of that missing file was newer).
909 # If $FILE is younger than one of its dependencies, it is outdated.
910 return up_to_date_p ($file, @dep);
924 # When processing the file with diversion disabled, there must be no
925 # output but comments and empty lines.
926 my $result = xqx ("$m4"
928 . join (' --include=', '', @include)
930 . " " . files_to_options (@ARGV)
932 $result =~ s/#.*\n//g;
933 $result =~ s/^\n//mg;
935 fatal "freezing produced output:\n$result"
938 # If freezing produces output, something went wrong: a bad `divert',
939 # or an improper paren etc.
942 . join (' --include=', '', @include)
943 . " --freeze-state=$output"
944 . " " . files_to_options (@ARGV)
953 load_configuration ($ENV{'AUTOM4TE_CFG'} || "$datadir/autom4te.cfg");
954 load_configuration ("$ENV{'HOME'}/.autom4te.cfg")
955 if exists $ENV{'HOME'} && -f "$ENV{'HOME'}/.autom4te.cfg";
956 load_configuration (".autom4te.cfg")
957 if -f ".autom4te.cfg";
960 # Freezing does not involve the cache.
967 # We need our cache directory.
971 or fatal "cannot create $cache: $!";
974 # Open the index for update, and lock it. autom4te handles several
975 # files, but the index is the first and last file to be updated, so
976 # locking it is sufficient.
977 $icache_file = new Autom4te::XFile $icache, O_RDWR|O_CREAT;
978 $icache_file->lock (LOCK_EX);
980 # Read the cache index if available and older than autom4te itself.
981 # If autom4te is younger, then some structures such as C4che might
982 # have changed, which would corrupt its processing.
983 Autom4te::C4che->load ($icache_file)
984 if -f $icache && mtime ($icache) > mtime ($0);
986 # Add the new trace requests.
987 my $req = Autom4te::C4che->request ('input' => \@ARGV,
989 'macro' => [keys %trace, @preselect]);
991 # If $REQ's cache files are not up to date, or simply if the user
992 # discarded them (-f), declare it invalid.
994 if $force || ! up_to_date ($req);
996 # We now know whether we can trust the Request object. Say it.
997 verb "the trace request object is:\n" . $req->marshall;
999 # We need to run M4 if (i) the user wants it (--force), (ii) $REQ is
1001 handle_m4 ($req, keys %{$req->macro})
1002 if $force || ! $req->valid;
1004 # Issue the warnings each time autom4te was run.
1005 my $separator = "\n" . ('-' x 25) . " END OF WARNING " . ('-' x 25) . "\n\n";
1006 handle_traces ($req, "$tmp/warnings",
1007 ('_m4_warn' => "\$1::\$f:\$l::\$2::\$3$separator"));
1008 # Swallow excessive newlines.
1009 for (split (/\n*$separator\n*/o, contents ("$tmp/warnings")))
1011 # The message looks like:
1012 # | syntax::input.as:5::ouch
1013 # | ::input.as:4: baz is expanded from...
1014 # | input.as:2: bar is expanded from...
1015 # | input.as:3: foo is expanded from...
1016 # | input.as:5: the top level
1017 my ($cat, $loc, $msg, $stacktrace) = split ('::', $_, 4);
1018 msg $cat, $loc, "warning: $msg";
1019 for (split /\n/, $stacktrace)
1021 my ($loc, $trace) = split (': ', $_, 2);
1022 msg $cat, $loc, $trace;
1029 # Always produce traces, since even if the output is young enough,
1030 # there is no guarantee that the traces use the same *format*
1031 # (e.g., `-t FOO:foo' and `-t FOO:bar' are both using the same M4
1032 # traces, hence the M4 traces cache is usable, but its formatting
1033 # will yield different results).
1034 handle_traces ($req, $output, %trace);
1038 # Actual M4 expansion, if the user wants it, or if $output is old
1039 # (STDOUT is pretty old).
1040 handle_output ($req, $output)
1041 if $force || mtime ($output) < mtime ($ocache . $req->id);
1044 # If we ran up to here, the cache is valid.
1046 Autom4te::C4che->save ($icache_file);
1050 ### Setup "GNU" style for perl-mode and cperl-mode.
1052 ## perl-indent-level: 2
1053 ## perl-continued-statement-offset: 2
1054 ## perl-continued-brace-offset: 0
1055 ## perl-brace-offset: 0
1056 ## perl-brace-imaginary-offset: 0
1057 ## perl-label-offset: -2
1058 ## cperl-indent-level: 2
1059 ## cperl-brace-offset: 0
1060 ## cperl-continued-brace-offset: 0
1061 ## cperl-label-offset: -2
1062 ## cperl-extra-newline-before-brace: t
1063 ## cperl-merge-trailing-else: nil
1064 ## cperl-continued-statement-offset: 2