# 0 for EXIT_SUCCESS.
my $exit_status = 0;
+# Do we freeze?
+my $freeze = 0;
+
# $M4.
my $m4 = $ENV{"M4"} || '@M4@';
# Some non-GNU m4's don't reject the --help option, so give them /dev/null.
$help = << "EOF";
Usage: $0 [OPTION] ... [FILES]
-Run GNU M4 on the FILES, avoiding useless runs. If tracing, the output
-consists of the traces only, otherwise output the expansion of the FILES.
+Run GNU M4 on the FILES, avoiding useless runs. Output the traces if tracing,
+the frozen file if freezing, otherwise the expansion of the FILES.
If some of the FILES are named \`FILE.m4f\' they are considered to be M4
frozen files of all the previous files (which are therefore not loaded).
-t, --trace=MACRO report the MACRO invocations
-p, --preselect=MACRO prepare to trace MACRO in a future run
+Freezing:
+ -F, --freeze produce an M4 frozen state file for FILES
+
Report bugs to <bug-autoconf\@gnu.org>.
EOF
# by hand.
"t|trace=s" => \@trace,
"p|preselect=s" => \@preselect,
+
+ # Freezing.
+ "F|freeze" => \$freeze,
);
die "$me: too few arguments
Try `$me --help' for more information.\n"
unless @ARGV;
+ # Freezing:
+ # We cannot trace at the same time (well, we can, but it sounds insane).
+ # And it implies melting: there is risk not to update properly using
+ # old frozen files, and worse yet: we could load a frozen file and
+ # refreeze it! A sort of caching :)
+ die "$me: cannot freeze and trace\n"
+ if $freeze && @trace;
+ $melt = 1
+ if $freeze;
+
# Normalize the includes: the first occurrence is enough, several is
# a pain since it introduces a useless difference in the path which
# invalidates the cache. And strip `.' which is implicit and always
}
+## ---------- ##
+## Freezing. ##
+## ---------- ##
+
+# freeze ($OUTPUT)
+# ----------------
+sub freeze ($)
+{
+ my ($output) = @_;
+
+ # When processing the file with diversion disabled, there must be no
+ # output but comments and empty lines.
+ my $command = ("$m4"
+ . ' --fatal-warning'
+ . join (' --include=', '', reverse @include)
+ . ' --define=divert'
+ . " @ARGV"
+ . ' </dev/null');
+ verbose "running: $command";
+ my $result = `$command`;
+ $result =~ s/#.*\n//g;
+ $result =~ s/^\n//mg;
+ if ($?)
+ {
+ verbose "$m4: failed with exit status: " . ($? >> 8) . "\n";
+ exit $? >> 8;
+ }
+ if ($result)
+ {
+ print STDERR "$me: freezing produced output:\n$result";
+ exit 1;
+ }
+
+ # If freezing produces output, something went wrong: a bad `divert',
+ # or an improper paren etc.
+ $command = ("$m4"
+ . ' --fatal-warning'
+ . join (' --include=', '', reverse @include)
+ . " --freeze-state=$output"
+ . " @ARGV"
+ . ' </dev/null');
+ verbose "running: $command";
+ system $command;
+ if ($?)
+ {
+ verbose "$m4: failed with exit status: " . ($? >> 8) . "\n";
+ exit $? >> 8;
+ }
+}
+
## -------------- ##
## Main program. ##
## -------------- ##
load_configuration;
parse_args;
+# Freezing does not involve the cache.
+if ($freeze)
+ {
+ freeze ($output);
+ exit 0;
+ }
+
# We need our cache directory.
if (! -d "$cache")
{
-divert(-1)# -*- Autoconf -*-
-# This file is part of Autoconf.
+# This file is part of Autoconf. -*- Autoconf -*-
# Driver that loads the Autoconf macro files.
-# Copyright 1994, 1999, 2000, 2001 Free Software Foundation, Inc.
+# Copyright 1994, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# yet when Autoconf is frozen.
# Do not sinclude ./aclocal.m4 here, to prevent it from being frozen.
-changequote()
-changequote([, ])
-include([m4sugar/m4sh.m4])
# general includes some AU_DEFUN.
m4_include([autoconf/autoupdate.m4])
-divert(-1)# -*- Autoconf -*-
-# This file is part of Autoconf.
+# This file is part of Autoconf. -*- Autoconf -*-
# M4 macros used in building test suites.
-# Copyright 2000, 2001 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# such potential, you must delete any notice of this special exception
# to the GPL from your modified version.
-changequote()
-changequote([, ])
-include([m4sugar/m4sh.m4])
m4_include([autotest/general.m4])
-changequote()changequote([, ])include(m4sugar/m4sugar.m4)# -*- Autoconf -*-
-# This file is part of Autoconf.
+# This file is part of Autoconf. -*- Autoconf -*-
# M4 sugar for common shell constructs.
# Requires GNU M4 and M4sugar.
-# Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by