+2002-08-29 Akim Demaille <akim@epita.fr>
+
+ * lib/Autom4te/General.pm (&xqx): New.
+ (&xsystem): Use WIFEXITED and WEXITSTATUS instead of decoding $? by
+ hand, which is not portable.
+ (&error): New.
+ * bin/autom4te.in: Use them.
+ Use &error instead of die.
+ * tests/m4sugar.at (m4_warn, m4_require: circular dependencies):
+ Adjust.
+
2002-08-17 Paul Eggert <eggert@twinsun.com>
* lib/autoconf/fortran.m4 (AC_PROG_F77): Remove fc from the
# $M4.
my $m4 = $ENV{"M4"} || '@M4@';
# Some non-GNU m4's don't reject the --help option, so give them /dev/null.
-die "$me: need GNU m4 1.4 or later: $m4\n"
+error "need GNU m4 1.4 or later: $m4"
if system "$m4 --help </dev/null 2>&1 | grep reload-state >/dev/null";
# Set some high recursion limit as the default limit, 250, has already
}
elsif ($type eq 'end-language:')
{
- die "$me: $autom4te_cfg:$.: end-language mismatch: $lang\n"
+ error "$autom4te_cfg:$.: end-language mismatch: $lang"
if $lang ne lc $words[0];
}
elsif ($type eq 'args:')
}
else
{
- die "$me: $autom4te_cfg:$.: unknown directive: $type\n";
+ error "$autom4te_cfg:$.: unknown directive: $type";
}
}
}
foreach (@language)
{
- die "$me: unknown language: $_\n"
+ error "unknown language: $_"
unless exists $language{lc $_};
unshift @ARGV, @{$language{lc $_}};
}
"F|freeze" => \$freeze,
);
- die "$me: too few arguments
-Try `$me --help' for more information.\n"
+ error "too few arguments
+Try `$me --help' for more information."
unless @ARGV;
# Freezing:
# 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"
+ error "cannot freeze and trace"
if $freeze && @trace;
$melt = 1
if $freeze;
#
# We don't output directly to the cache files, to avoid problems
# when we are interrupted (that leaves corrupted files).
- my $command = ("$m4"
- . join (' --include=', '', @include)
- . " --define=m4_warnings=$m4_warnings"
- . ' --debug=aflq'
- . " --error-output=$tcache" . $req->id . "t"
- . join (' --trace=', '', sort @macro)
- . " @ARGV"
- . ' </dev/null'
- . " >$ocache" . $req->id . "t");
- verbose "running: $command";
- system $command;
- if ($?)
- {
- verbose "$m4: failed with exit status: " . ($? >> 8) . "\n";
- exit $? >> 8;
- }
+ xsystem ("$m4"
+ . join (' --include=', '', @include)
+ . " --define=m4_warnings=$m4_warnings"
+ . ' --debug=aflq'
+ . " --error-output=$tcache" . $req->id . "t"
+ . join (' --trace=', '', sort @macro)
+ . " @ARGV"
+ . ' </dev/null'
+ . " >$ocache" . $req->id . "t");
# Everything went ok: preserve the outputs.
foreach my $file (map { $_ . $req->id } ($tcache, $ocache))
{
use File::Copy;
move ("${file}t", "$file")
- or die "$me: cannot not rename ${file}t as $file: $!\n";
+ or error "cannot not rename ${file}t as $file: $!";
}
}
{
$out->open($output, O_CREAT | O_WRONLY | O_TRUNC, oct ($mode));
}
- die "$me: cannot create $output: $!\n"
+ error "cannot create $output: $!"
unless $out;
my $in = new Autom4te::XFile ($ocache . $req->id);
}
elsif (/^(\$.)/)
{
- die "$me: invalid escape: $1\n";
+ error "invalid escape: $1";
}
else
{
# When processing the file with diversion disabled, there must be no
# output but comments and empty lines.
- my $command = ("$m4"
- . ' --fatal-warning'
- . join (' --include=', '', @include)
- . ' --define=divert'
- . " @ARGV"
- . ' </dev/null');
- verbose "running: $command";
- my $result = `$command`;
+ my $result = xqx ("$m4"
+ . ' --fatal-warning'
+ . join (' --include=', '', @include)
+ . ' --define=divert'
+ . " @ARGV"
+ . ' </dev/null');
$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";
# If freezing produces output, something went wrong: a bad `divert',
# or an improper paren etc.
- $command = ("$m4"
- . ' --fatal-warning'
- . join (' --include=', '', @include)
- . " --freeze-state=$output"
- . " @ARGV"
- . ' </dev/null');
- verbose "running: $command";
- system $command;
- if ($?)
- {
- verbose "$m4: failed with exit status: " . ($? >> 8) . "\n";
- exit $? >> 8;
- }
+ xsystem ("$m4"
+ . ' --fatal-warning'
+ . join (' --include=', '', @include)
+ . " --freeze-state=$output"
+ . " @ARGV"
+ . ' </dev/null');
}
## -------------- ##
if (! -d "$cache")
{
mkdir "$cache", 0755
- or die "$me: cannot create $cache: $!\n";
+ or error "cannot create $cache: $!";
}
# Read the cache index if available and older than autom4te itself.
install_sh = @install_sh@
lispdir = @lispdir@
-MAKEINFO = @MAKEINFO@ --no-split
+AM_MAKEINFOFLAGS = --no-split
TEXI2HTML = texi2html
TEXI2HTML_FLAGS = -split_chapter
cd $(srcdir) \
&& $(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) \
`echo $< | sed 's,.*/,,'`
+
+MAKEINFO = @MAKEINFO@
TEXI2DVI = texi2dvi
DVIPS = dvips
.dvi.ps:
# Functions we define and export.
my @export_subs =
- qw (&backname &catfile &canonpath &debug
+ qw (&backname &catfile &canonpath &debug &error
&file_name_is_absolute &find_configure_ac &find_file
&getopt &mktmpdir &mtime
- &uniq &update_file &up_to_date_p &verbose &xsystem);
+ &uniq &update_file &up_to_date_p &verbose &xsystem &xqx);
# Functions we forward (coming from modules we use).
my @export_forward_subs =
}
+# &error (@MESSAGE)
+# -----------------
+# Same as die or confess, depending on $debug.
+sub error (@)
+{
+ if ($debug)
+ {
+ confess "$me: ", @_, "\n";
+ }
+ else
+ {
+ die "$me: ", @_, "\n";
+ }
+}
+
+
# $BOOLEAN
# &file_name_is_absolute ($FILE)
# ------------------------------
if (file_name_is_absolute ($filename))
{
- die "$me: no such file or directory: $filename\n"
+ error "no such file or directory: $filename"
unless $optional;
return undef;
}
if -e catfile ($path, $filename);
}
- die "$me: no such file or directory: $filename\n"
+ error "no such file or directory: $filename"
unless $optional;
return undef;
}
$in->close;
unlink ($from)
- or die "$me: cannot not remove $from: $!\n";
+ or die "cannot not remove $from: $!";
return;
}
# File didn't change, so don't update its mod time.
print STDERR "$me: `$to' is unchanged\n";
unlink ($from)
- or die "$me: cannot not remove $from: $!\n";
+ or error "cannot not remove $from: $!";
return
}
{
# Back up and install the new one.
move ("$to", "$to$SIMPLE_BACKUP_SUFFIX")
- or die "$me: cannot not backup $to: $!\n";
+ or error "cannot not backup $to: $!";
move ("$from", "$to")
- or die "$me: cannot not rename $from as $to: $!\n";
+ or error "cannot not rename $from as $to: $!";
print STDERR "$me: `$to' is updated\n";
}
else
{
move ("$from", "$to")
- or die "$me: cannot not rename $from as $to: $!\n";
+ or error "cannot not rename $from as $to: $!";
print STDERR "$me: `$to' is created\n";
}
}
}
+# xqx ($COMMAND)
+# --------------
+# Same as `qx' (but in scalar context), but fails on errors.
+sub xqx ($)
+{
+ use POSIX qw (WIFEXITED WEXITSTATUS);
+
+ my ($command) = @_;
+
+ verbose "running: $command";
+ my $res = `$command`;
+
+ error ((split (' ', $command))[0]
+ . " failed with exit status: "
+ . WEXITSTATUS ($?))
+ if WIFEXITED ($?) && WEXITSTATUS ($?) != 0;
+
+ return $res;
+}
+
+
# xsystem ($COMMAND)
# ------------------
sub xsystem ($)
{
+ use POSIX qw (WEXITSTATUS);
+
my ($command) = @_;
verbose "running: $command";
(system $command) == 0
- or croak ("$me: "
- . (split (' ', $command))[0]
+ or error ((split (' ', $command))[0]
. " failed with exit status: "
- . ($? >> 8)
- . "\n");
+ . WEXITSTATUS ($?));
}
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
-.TH AUTOM4TE "1" "July 2002" "autom4te 2.53c" "User Commands"
+.TH AUTOM4TE "1" "August 2002" "autom4te 2.53c" "User Commands"
.SH NAME
autom4te \- Generate files and scripts thanks to M4
.SH SYNOPSIS
AT_BANNER([M4sugar.])
-# 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
[script.4s:2: warning: bar
])
-AT_CHECK_M4SUGAR([-o- -Wnone,bar,error -f], 1, [],
-[script.4s:2: error: bar
+AT_CHECK_M4SUGAR([-o- -Wnone,bar,error -f], 1, [], [stderr])
+# The error message contains the path to m4, which might change.
+AT_CHECK([sed 's/^autom4te.*failed/autom4te: m4 failed/' stderr], 0,
+[[script.4s:2: error: bar
script.4s:2: the top level
-])
+autom4te: m4 failed with exit status: 1
+]])
AT_CLEANUP
baz
]])
-AT_DATA_M4SUGAR([experr],
+# Expected stderr.
+AT_DATA_M4SUGAR([expout],
[[script.4s:11: error: m4_require: circular dependency of foo
script.4s:11: foo is required by...
script.4s:5: bar is expanded from...
script.4s:11: foo is required by...
script.4s:8: baz is expanded from...
script.4s:11: the top level
+autom4te: m4 failed with exit status: 1
]])
-AT_CHECK_M4SUGAR([], 1, [], experr)
+AT_CHECK_M4SUGAR([], 1, [], stderr)
+# The error message contains the path to m4, which might change.
+AT_CHECK([sed 's/^autom4te.*failed/autom4te: m4 failed/' stderr], 0, [expout])
AT_CLEANUP