]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/Autom4te/General.pm (&find_file, &update_file): New.
authorAkim Demaille <akim@epita.fr>
Fri, 31 Aug 2001 13:32:35 +0000 (13:32 +0000)
committerAkim Demaille <akim@epita.fr>
Fri, 31 Aug 2001 13:32:35 +0000 (13:32 +0000)
* bin/autoupdate.in, bin/autoheader.in: Adjust.
Drop AC_MACRODIR dead for real.
* tests/atspecific.m4 (AT_CHECK_AUTOHEADER): Now autoheader says
`autoheader: `config.hin' is created'.
* tests/tools.at (Syntax of the Perl scripts): Check autoheader.

ChangeLog
bin/autoheader.in
bin/autom4te.in
bin/autoupdate.in
lib/Autom4te/General.pm
tests/atspecific.m4
tests/tools.at

index b585506b51a19a6d8a5f449f660994a76a23a771..a827377f22d9f6f60988c447151fb5ec81c8f02f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2001-08-31  Akim Demaille  <akim@epita.fr>
+
+       * lib/Autom4te/General.pm (&find_file, &update_file): New.
+       * bin/autoupdate.in, bin/autoheader.in: Adjust.
+       Drop AC_MACRODIR dead for real.
+       * tests/atspecific.m4 (AT_CHECK_AUTOHEADER): Now autoheader says
+       `autoheader: `config.hin' is created'.
+       * tests/tools.at (Syntax of the Perl scripts): Check autoheader.
+
 2001-08-31  Akim Demaille  <akim@epita.fr>
 
        * bin/autoheader.in: Rewrite in Perl.
index ec19fffafaa1883d6af796d85cad9559c56163a6..d3c6ccf54679aa0f2e79a0b599c3da5b3f908b70 100644 (file)
@@ -29,17 +29,12 @@ eval 'exec @PERL@ -S $0 ${1+"$@"}'
 
 BEGIN
 {
-  my $datadir = ($ENV{'autom4te_perllibdir'}
-                || $ENV{'AC_MACRODIR'}
-                || '@datadir@');
-  unshift @INC, "$datadir";
+  my $perllibdir = $ENV{'autom4te_perllibdir'} || '@datadir@';
+  unshift @INC, "$perllibdir";
 }
 
 use Getopt::Long;
 use File::Basename;
-use File::Compare;
-use File::Copy;
-use File::Spec;
 use IO::File;
 use Autom4te::General;
 use strict;
@@ -66,46 +61,6 @@ my $SIMPLE_BACKUP_SUFFIX = $ENV{'SIMPLE_BACKUP_SUFFIX'} || '~';
 ## ---------- ##
 
 
-# $FILENAME
-# find_file ($FILENAME)
-# ---------------------
-# 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 ($)
-{
-  my ($filename) = @_;
-  my $optional = 0;
-
-  $optional = 1
-    if $filename =~ s/\?$//;
-
-  return File::Spec->canonpath ($filename)
-    if -e $filename;
-
-  if (File::Spec->file_name_is_absolute ($filename))
-    {
-      die "$me: no such file or directory: $filename\n"
-       unless $optional;
-      return undef;
-    }
-
-  foreach my $path (@include)
-    {
-      return File::Spec->canonpath (File::Spec->catfile ($path, $filename))
-       if -e File::Spec->catfile ($path, $filename)
-    }
-
-  die "$me: no such file or directory: $filename\n"
-    unless $optional;
-
-  return undef;
-}
-
-
 # print_usage ()
 # --------------
 # Display usage (--help).
@@ -202,9 +157,9 @@ mktmpdir ('ah');
 parse_args;
 
 # Preach.
-my $config_h_top = find_file ("config.h.top?");
-my $config_h_bot = find_file ("config.h.bot?");
-my $acconfig_h = find_file ("acconfig.h?");
+my $config_h_top = find_file ("config.h.top?", @include);
+my $config_h_bot = find_file ("config.h.bot?", @include);
+my $acconfig_h = find_file ("acconfig.h?", @include);
 if ($config_h_top || $config_h_bot || $acconfig_h)
   {
     my $msg = << "END";
@@ -297,31 +252,6 @@ $out->close;
 #   done
 # fi
 
-if (compare ("$tmp/config.hin", "$config_h_in") == 0)
-  {
-    # File didn't change, so don't update its mod time.
-    print STDERR "$me: `$config_h_in' is unchanged\n"
-  }
-else
-  {
-    # Back up and install the new one.
-    if (-f $config_h_in)
-      {
-       move ("$config_h_in",  "$config_h_in$SIMPLE_BACKUP_SUFFIX")
-         or die "$me: cannot not backup $config_h_in: $!\n";
-      }
-    move ("$tmp/config.hin", "$config_h_in")
-      or die "$me: cannot not update $config_h_in: $!\n";
-    # print STDERR "$me: `$config_h_in' is updated\n";
-  }
-
+update_file ("$tmp/config.hin", "$config_h_in");
 
 __END__
-
-
-
-
-
-
-
-(exit $status); exit $status
index f004ddc636f80ecb2116d19b064229c03cee33b7..3c362de29a74ff767f01648d788f7560206df650 100644 (file)
@@ -44,7 +44,6 @@ use Autom4te::Struct;
 use Carp;
 use Getopt::Long;
 use IO::File;
-use File::Spec;
 use strict;
 
 # List of requests.
@@ -361,46 +360,6 @@ my %m4_builtin_alternate_name;
 ## ---------- ##
 
 
-# $FILENAME
-# find_file ($FILENAME)
-# ---------------------
-# 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 ($)
-{
-  my ($filename) = @_;
-  my $optional = 0;
-
-  $optional = 1
-    if $filename =~ s/\?$//;
-
-  return File::Spec->canonpath ($filename)
-    if -e $filename;
-
-  if (File::Spec->file_name_is_absolute ($filename))
-    {
-      die "$me: no such file or directory: $filename\n"
-       unless $optional;
-      return undef;
-    }
-
-  foreach my $path (@include)
-    {
-      return File::Spec->canonpath (File::Spec->catfile ($path, $filename))
-       if -e File::Spec->catfile ($path, $filename)
-    }
-
-  die "$me: no such file or directory: $filename\n"
-    unless $optional;
-
-  return undef;
-}
-
-
 # print_usage ()
 # --------------
 # Display usage (--help).
@@ -605,7 +564,7 @@ Try `$me --help' for more information.\n"
   # We don't want to depend upon m4's --include to find the top level
   # files.  Try to get a canonical name, as it's part of the key for
   # caching.  And some files are optional.
-  @ARGV = grep { defined $_ } map { find_file ($_) } @ARGV;
+  @ARGV = grep { defined $_ } map { find_file ($_, @include) } @ARGV;
 }
 
 
@@ -1064,7 +1023,7 @@ sub up_to_date_p ($)
                 ('include'    => '$1',
                  'm4_include' => '$1'));
   my $deps = new IO::File ("$tmp/dependencies");
-  push @dep, map { chomp; find_file ($_) } $deps->getlines;
+  push @dep, map { chomp; find_file ($_, @include) } $deps->getlines;
 
   # If $FILE is younger than one of its dependencies, it is outdated.
   verbose "$file is the youngest cache file";
index cb24556a52ebd54d266d5b172d75f80f388a4e8b..d0999c66f5b661b0dcc76e456cc821e6869b88ea 100644 (file)
 
 BEGIN
 {
-  my $prefix = "@prefix@";
   my $perllibdir = $ENV{'autom4te_perllibdir'} || "@datadir@";
   unshift @INC, "$perllibdir";
 }
 
 use Getopt::Long;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Autom4te::General;
 use strict;
 
@@ -41,7 +38,6 @@ my $autoconf = $ENV{'AUTOCONF'} || '@autoconf-name@';
 my $localdir = '.';
 # m4.
 my $m4 = $ENV{"M4"} || "@M4@";
-my $SIMPLE_BACKUP_SUFFIX = $ENV{'SIMPLE_BACKUP_SUFFIX'} || '~';
 
 
 ## ---------- ##
@@ -372,30 +368,10 @@ EOF
        or die "$me: cannot close $tmp/input.m4: $!\n";
 
     # Now ask m4 to perform the update.
-    if ("$file" eq "$tmp/stdin")
-       {
-        xsystem ("$m4 --include=$autoconf_dir $tmp/input.m4");
-       }
-    else
-       {
-        xsystem ("$m4 --include=$autoconf_dir $tmp/input.m4 >$tmp/updated");
-        if (compare ("$tmp/updated", "$file") == 0)
-          {
-            # File didn't change, so don't update its mod time.
-            print STDERR "$me: `$file' is unchanged\n"
-          }
-        else
-          {
-            # Back up and install the new one.
-            move ("$file",  "$file$SIMPLE_BACKUP_SUFFIX")
-              or die "$me: cannot not backup $file: $!\n";
-            move ("$tmp/updated", "$file")
-              or die "$me: cannot not update $file: $!\n";
-            print STDERR "$me: `$file' is updated\n";
-          }
-       }
-     }
-
+    xsystem ("$m4 --include=$autoconf_dir $tmp/input.m4 >$tmp/updated");
+    update_file ("$tmp/updated",
+                "$file" eq "$tmp/stdin" ? '-' : "$file");
+  }
 exit 0;
 
 
index 619dd6a2add1376453e6800ba1b3c9fb4a7f548a..dead90686280675c4723fd22a4765c3abcdf8976 100644 (file)
@@ -28,8 +28,8 @@ use strict;
 use vars qw (@ISA @EXPORT);
 
 @ISA = qw (Exporter);
-@EXPORT = qw (&find_configure_ac &mktmpdir &mtime
-              &uniq &verbose &xsystem
+@EXPORT = qw (&find_configure_ac &find_file &mktmpdir &mtime
+              &uniq &update_file &verbose &xsystem
              $me $verbose $debug $tmp);
 
 # Variable we share with the main package.  Be sure to have a single
@@ -104,6 +104,48 @@ sub find_configure_ac ()
 }
 
 
+# $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;
+
+  my ($filename, @include) = @_;
+  my $optional = 0;
+
+  $optional = 1
+    if $filename =~ s/\?$//;
+
+  return File::Spec->canonpath ($filename)
+    if -e $filename;
+
+  if (File::Spec->file_name_is_absolute ($filename))
+    {
+      die "$me: no such file or directory: $filename\n"
+       unless $optional;
+      return undef;
+    }
+
+  foreach my $path (@include)
+    {
+      return File::Spec->canonpath (File::Spec->catfile ($path, $filename))
+       if -e File::Spec->catfile ($path, $filename)
+    }
+
+  die "$me: no such file or directory: $filename\n"
+    unless $optional;
+
+  return undef;
+}
+
+
 # mktmpdir ($SIGNATURE)
 # ---------------------
 # Create a temporary directory which name is based on $SIGNATURE.
@@ -168,6 +210,56 @@ sub uniq (@)
 }
 
 
+# &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) = @_;
+  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;
+      remove ($from)
+       or die "$me: cannot not remove $from: $!\n";
+      return;
+    }
+
+  if (-f "$to" && compare ("$from", "$to") == 0)
+    {
+      # File didn't change, so don't update its mod time.
+      print STDERR "$me: `$to' is unchanged\n";
+      return
+    }
+
+  if (-f "$to")
+    {
+      # Back up and install the new one.
+      move ("$to",  "$to$SIMPLE_BACKUP_SUFFIX")
+       or die "$me: cannot not backup $to: $!\n";
+      move ("$from", "$to")
+       or die "$me: cannot not rename $from as $to: $!\n";
+      print STDERR "$me: `$to' is updated\n";
+    }
+  else
+    {
+      move ("$from", "$to")
+       or die "$me: cannot not rename $from as $to: $!\n";
+      print STDERR "$me: `$to' is created\n";
+    }
+}
+
+
 # verbose
 # -------
 sub verbose (@)
index 47c80b9884cb1056aa34ee41ab4d1c718da1df4b..43f4e19126cd8031545ec75e0367cfcfeb9d5072 100644 (file)
@@ -61,19 +61,23 @@ AC_STATE_SAVE(after)
 ]])])
 
 
-# AT_CHECK_AUTOCONF(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
-# -----------------------------------------------------------
+# AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
+# ----------------------------------------------------------
 m4_define([AT_CHECK_AUTOCONF],
 [AT_CLEANUP_FILES(configure.in configure autom4te.cache)dnl
 AT_CHECK([autoconf --include=$srcdir $1],
-         m4_default([$2], [0]), [$3], [$4])])
+         [$2], [$3], [$4])])
 
 
-# AT_CHECK_AUTOHEADER
-# -------------------
+# AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0],
+#                     STDOUT, [STDERR = `autoheader: `config.hin' is created'])
+# -----------------------------------------------------------------------------
 m4_define([AT_CHECK_AUTOHEADER],
 [AT_CLEANUP_FILES(config.hin)dnl
-AT_CHECK([autoheader --localdir=$srcdir], 0, [], [])])
+AT_CHECK([autoheader --localdir=$srcdir $1], [$2],
+         [$3],
+         m4_default([$4], [[autoheader: `config.hin' is created
+]]))])
 
 
 # AT_CHECK_CONFIGURE(END-COMMAND,
index dfe6a0399b6689a1961cfcb48bcab6c6b7bc6e36..aad110c4f20b7d131672c7fa16dc6b0b0fb30aff 100644 (file)
@@ -98,6 +98,7 @@ AT_SETUP([Syntax of the Perl scripts])
 # | ./autom4te syntax OK
 # Ignore it, it might change between releases.
 AT_CHECK([$PERL -c ../bin/autom4te],   0, [], [ignore])
+AT_CHECK([$PERL -c ../bin/autoheader], 0, [], [ignore])
 AT_CHECK([$PERL -c ../bin/autoscan],   0, [], [ignore])
 AT_CHECK([$PERL -c ../bin/autoupdate], 0, [], [ignore])