From: Akim Demaille Date: Wed, 20 Aug 2003 12:52:18 +0000 (+0000) Subject: * bin/autoupdate.in, bin/auheader.in, bin/autoreconf.in, X-Git-Tag: AUTOCONF-2.57b~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c99bf18b5ccc5123bd7946bca6f0a0b31d4bdc55;p=thirdparty%2Fautoconf.git * bin/autoupdate.in, bin/auheader.in, bin/autoreconf.in, * bin/autom4te: Adjust. In particular, be Autoconf tools are really silent when properly working, bind the verbosity of the 'note' channel to $verbose. * lib/Autom4te/General.pm (&find_file, &mtime, &update_file) (&xsystem, &contents): Remove, since they are exported by... * lib/Autom4te/FileUtils.pm: this. More perldoc. * lib/Autom4te/General.pm (&up_to_date_p): Move to... * lib/Autom4te/FileUtils.pm: here. --- diff --git a/ChangeLog b/ChangeLog index 66cddb61..71af37b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2003-08-20 Akim Demaille + + * bin/autoupdate.in, bin/auheader.in, bin/autoreconf.in, + * bin/autom4te: Adjust. + In particular, be Autoconf tools are really silent when properly + working, bind the verbosity of the 'note' channel to $verbose. + * lib/Autom4te/General.pm (&find_file, &mtime, &update_file) + (&xsystem, &contents): Remove, since they are exported by... + * lib/Autom4te/FileUtils.pm: this. + More perldoc. + * lib/Autom4te/General.pm (&up_to_date_p): Move to... + * lib/Autom4te/FileUtils.pm: here. + 2003-08-20 Akim Demaille * lib/Autom4te/Channels.pm, lib/Autom4te/ChannelDefs.pm diff --git a/bin/autoheader.in b/bin/autoheader.in index 407d3d3e..4b2c6526 100644 --- a/bin/autoheader.in +++ b/bin/autoheader.in @@ -39,6 +39,10 @@ BEGIN $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos'); } +use Autom4te::ChannelDefs; +use Autom4te::Channels; +use Autom4te::FileUtils; +use Autom4te::FileUtils; use Autom4te::General; use Autom4te::XFile; use strict; @@ -114,6 +118,8 @@ sub parse_args () 'B|prepend-include=s' => \@prepend_include, 'W|warnings=s' => \@warning); + setup_channel 'note', silent => !$verbose; + if (! @ARGV) { my $configure_ac = find_configure_ac; diff --git a/bin/autom4te.in b/bin/autom4te.in index 9e66ebdc..6c028dbc 100644 --- a/bin/autom4te.in +++ b/bin/autom4te.in @@ -43,6 +43,7 @@ BEGIN package Request; use Data::Dumper; +use Autom4te::FileUtils; use Autom4te::General; use Autom4te::Struct; use Autom4te::XFile; @@ -235,6 +236,7 @@ sub load package Autom4te; +use Autom4te::FileUtils; use Autom4te::General; use File::Basename; use Autom4te::XFile; diff --git a/bin/autoreconf.in b/bin/autoreconf.in index 5e29f495..cb2f9e69 100644 --- a/bin/autoreconf.in +++ b/bin/autoreconf.in @@ -39,6 +39,7 @@ BEGIN $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos'); } +use Autom4te::FileUtils; use Autom4te::General; use Autom4te::XFile; # Do not use Cwd::chdir, since it might hang. diff --git a/bin/autoupdate.in b/bin/autoupdate.in index 3b828d0f..c4e9ed23 100644 --- a/bin/autoupdate.in +++ b/bin/autoupdate.in @@ -37,9 +37,12 @@ BEGIN $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos'); } -use File::Basename; +use Autom4te::ChannelDefs; +use Autom4te::Channels; +use Autom4te::FileUtils; use Autom4te::General; use Autom4te::XFile; +use File::Basename; use strict; # Lib files. @@ -101,6 +104,8 @@ sub parse_args () 'B|prepend-include=s' => \@prepend_include, 'f|force' => \$force); + setup_channel 'note', silent => !$verbose; + if (! @ARGV) { my $configure_ac = find_configure_ac; diff --git a/lib/Autom4te/FileUtils.pm b/lib/Autom4te/FileUtils.pm index a0e40733..65cc6b7a 100644 --- a/lib/Autom4te/FileUtils.pm +++ b/lib/Autom4te/FileUtils.pm @@ -17,6 +17,20 @@ package Autom4te::FileUtils; +=head1 NAME + +Autom4te::FileUtils - handling files + +=head1 SYNOPSIS + + use Autom4te::FileUtils + +=head1 DESCRIPTION + +This perl module provides various general purpose file handling functions. + +=cut + use strict; use Exporter; use File::stat; @@ -27,18 +41,28 @@ use Autom4te::ChannelDefs; use vars qw (@ISA @EXPORT); @ISA = qw (Exporter); -@EXPORT = qw (&find_file &mtime &update_file &xsystem &contents); +@EXPORT = qw (&contents + &find_file &mtime + &update_file &up_to_date_p + &xsystem &xqx); + + +=item C + +Return the first path for a C<$filename> in the Cs. + +We match exactly the behavior of GNU M4: first look in the current +directory (which includes the case of absolute file names), and, if +the file is not absolute, just fail. Otherwise, look in C<@include>. +If the file is flagged as optional (ends with C), then return undef +if absent, otherwise exit with error. + +=cut # $FILENAME # find_file ($FILENAME, @INCLUDE) # ------------------------------- -# We match exactly the behavior of GNU m4: first look in the current -# directory (which includes the case of absolute file names), and, if -# the file is not absolute, just fail. Otherwise, look in the path. -# -# If the file is flagged as optional (ends with `?'), then return undef -# if absent. sub find_file ($@) { use File::Spec; @@ -71,11 +95,16 @@ sub find_file ($@) return undef; } +=item C + +Return the mtime of C<$file>. Missing files, or C<-> standing for +C or C are ``obsolete'', i.e., as old as possible. + +=cut + # $MTIME # MTIME ($FILE) # ------------- -# Return the mtime of $FILE. Missing files, or `-' standing for STDIN -# or STDOUT are ``obsolete'', i.e., as old as possible. sub mtime ($) { my ($file) = @_; @@ -90,10 +119,16 @@ sub mtime ($) } +=item C + +Rename C<$from> as C<$to>, preserving C<$to> timestamp if it has not +changed. Recognize C<$to> = C<-> standing for C. C<$from> is +always removed/renamed. + +=cut + # &update_file ($FROM, $TO) # ------------------------- -# Rename $FROM as $TO, preserving $TO timestamp if it has not changed. -# Recognize `$TO = -' standing for stdin. sub update_file ($$) { my ($from, $to) = @_; @@ -139,9 +174,43 @@ sub update_file ($$) } +=item C + +Is C<$file> more recent than C<@dep>? + +=cut + +# $BOOLEAN +# &up_to_date_p ($FILE, @DEP) +# --------------------------- +sub up_to_date_p ($@) +{ + my ($file, @dep) = @_; + my $mtime = mtime ($file); + + foreach my $dep (@dep) + { + if ($mtime < mtime ($dep)) + { + verb "up_to_date ($file): outdated: $dep"; + return 0; + } + } + + verb "up_to_date ($file): up to date"; + return 1; +} + + +=item C + +Display an error message for C<$command>, based on the content of +C<$?> and C<$!>. + +=cut + # handle_exec_errors ($COMMAND) # ----------------------------- -# Display an error message for $COMMAND, based on the content of $? and $!. sub handle_exec_errors ($) { my ($command) = @_; @@ -159,7 +228,8 @@ sub handle_exec_errors ($) { my $status = WEXITSTATUS ($?); # Propagate exit codes. - fatal ("$command failed with exit status: $status", + fatal ('', + "$command failed with exit status: $status", exit_code => $status); } elsif (WIFSIGNALED ($?)) @@ -174,9 +244,14 @@ sub handle_exec_errors ($) } } +=item C + +Same as C (but in scalar context), but fails on errors. + +=cut + # xqx ($COMMAND) # -------------- -# Same as `qx' (but in scalar context), but fails on errors. sub xqx ($) { my ($command) = @_; @@ -192,6 +267,13 @@ sub xqx ($) } +=item C + +Same as C, but fails on errors, and reports the C<$command> +in verbose mode. + +=cut + # xsystem ($COMMAND) # ------------------ sub xsystem ($) @@ -206,9 +288,14 @@ sub xsystem ($) } +=item C + +Return the contents of c<$filename>. + +=cut + # contents ($FILENAME) # -------------------- -# Swallow the contents of file $FILENAME. sub contents ($) { my ($file) = @_; diff --git a/lib/Autom4te/General.pm b/lib/Autom4te/General.pm index bd4b1768..c4c30bc9 100644 --- a/lib/Autom4te/General.pm +++ b/lib/Autom4te/General.pm @@ -35,6 +35,7 @@ used in several executables of the Autoconf and Automake packages. use 5.005_03; use Exporter; +use Autom4te::ChannelDefs; use File::Basename; use File::Spec; use File::stat; @@ -52,10 +53,10 @@ my @export_vars = # Functions we define and export. my @export_subs = - qw (&catfile &canonpath &contents &debug &error - &file_name_is_absolute &find_configure_ac &find_file - &getopt &mktmpdir &mtime - &uniq &update_file &up_to_date_p &verbose &xsystem &xqx); + qw (&catfile &canonpath &debug &error + &file_name_is_absolute &find_configure_ac + &getopt &mktmpdir + &uniq &verbose); # Functions we forward (coming from modules we use). my @export_forward_subs = @@ -266,27 +267,6 @@ sub canonpath ($) } -=item C - -Return the contents of c<$filename>. Exit with diagnostic on failure. - -=cut - -# &contents ($FILENAME) -# --------------------- -# Swallow the contents of file $FILENAME. -sub contents ($) -{ - my ($file) = @_; - verbose "reading $file"; - local $/; # Turn on slurp-mode. - my $f = new Autom4te::XFile "< $file"; - my $contents = $f->getline; - $f->close; - return $contents; -} - - =item C If the debug mode is enabled (C<$debug> and C<$verbose>), report the @@ -304,30 +284,6 @@ sub debug (@) } -=item C - -Report the C<@message> on C, signed with the name of the -program, and exit with failure. If the debug mode is enabled -(C<$debug>), then in addition dump the call stack. - -=cut - -# &error (@MESSAGE) -# ----------------- -# Same as die or confess, depending on $debug. -sub error (@) -{ - if ($debug) - { - confess "$me: ", @_, "\n"; - } - else - { - die "$me: ", @_, "\n"; - } -} - - =item C Wrapper around Cfile_name_is_absolute>. Return true iff @@ -380,51 +336,6 @@ sub find_configure_ac (;$) } -=item C - -Return the first path for a C<$filename> in the Cs. - -We match exactly the behavior of GNU M4: first look in the current -directory (which includes the case of absolute file names), and, if -the file is not absolute, just fail. Otherwise, look in C<@include>. - -If the file is flagged as optional (ends with C), then return undef -if absent, otherwise exit with error. - -=cut - -# $FILENAME -# find_file ($FILENAME, @INCLUDE) -# ------------------------------- -sub find_file ($@) -{ - my ($filename, @include) = @_; - my $optional = 0; - - $optional = 1 - if $filename =~ s/\?$//; - - return canonpath ($filename) - if -e $filename; - - if (file_name_is_absolute ($filename)) - { - error "no such file or directory: $filename" - unless $optional; - return undef; - } - - foreach my $path (@include) - { - return canonpath (catfile ($path, $filename)) - if -e catfile ($path, $filename); - } - - error "no such file or directory: $filename" - unless $optional; - - return undef; -} =item C @@ -508,30 +419,6 @@ sub mktmpdir ($) } -=item C - -Return the mtime of C<$file>. Missing files, or C<-> standing for -C or C are ``obsolete'', i.e., as old as possible. - -=cut - -# $MTIME -# MTIME ($FILE) -# ------------- -sub mtime ($) -{ - my ($file) = @_; - - return 0 - if $file eq '-' || ! -f $file; - - my $stat = stat ($file) - or croak "$me: cannot stat $file: $!\n"; - - return $stat->mtime; -} - - =item C Return C<@list> with no duplicates, keeping only the first @@ -558,92 +445,6 @@ sub uniq (@) } -=item C - -Is C<$file> more recent than C<@dep>? - -=cut - -# $BOOLEAN -# &up_to_date_p ($FILE, @DEP) -# --------------------------- -sub up_to_date_p ($@) -{ - my ($file, @dep) = @_; - my $mtime = mtime ($file); - - foreach my $dep (@dep) - { - if ($mtime < mtime ($dep)) - { - debug "up_to_date ($file): outdated: $dep"; - return 0; - } - } - - debug "up_to_date ($file): up to date"; - return 1; -} - - -=item C - -Rename C<$from> as C<$to>, preserving C<$to> timestamp if it has not -changed. Recognize C<$to> = C<-> standing for C. C<$from> is -always removed/renamed. - -=cut - -# &update_file ($FROM, $TO) -# ------------------------- -sub update_file ($$) -{ - my ($from, $to) = @_; - my $SIMPLE_BACKUP_SUFFIX = $ENV{'SIMPLE_BACKUP_SUFFIX'} || '~'; - use File::Compare; - use File::Copy; - - if ($to eq '-') - { - my $in = new IO::File ("$from"); - my $out = new IO::File (">-"); - while ($_ = $in->getline) - { - print $out $_; - } - $in->close; - unlink ($from) - or error "cannot not remove $from: $!"; - return; - } - - if (-f "$to" && compare ("$from", "$to") == 0) - { - # File didn't change, so don't update its mod time. - verbose "`$to' is unchanged"; - unlink ($from) - or error "cannot not remove $from: $!"; - return - } - - if (-f "$to") - { - # Back up and install the new one. - move ("$to", "$to$SIMPLE_BACKUP_SUFFIX") - or error "cannot not backup $to: $!"; - move ("$from", "$to") - or error "cannot not rename $from as $to: $!"; - verbose "`$to' is updated"; - } - else - { - move ("$from", "$to") - or error "cannot not rename $from as $to: $!"; - verbose "`$to' is created"; - } -} - - =item C If the verbose mode is enabled (C<$verbose>), report the C<@message> @@ -707,50 +508,6 @@ sub handle_exec_errors ($) } } - -=item C - -Same as C (but in scalar context), but fails on errors. - -=cut - -# xqx ($COMMAND) -# -------------- -sub xqx ($) -{ - my ($command) = @_; - - verbose "running: $command"; - - $! = 0; - my $res = `$command`; - handle_exec_errors $command - if $?; - - return $res; -} - - -=item C - -Same as C, but fails on errors, and reports the C<$command> -in verbose mode. - -=cut - -# xsystem ($COMMAND) -# ------------------ -sub xsystem ($) -{ - my ($command) = @_; - - verbose "running: $command"; - - $! = 0; - handle_exec_errors $command - if system $command; -} - =back =head1 SEE ALSO