* doc/automake.texi (Autotools Introduction) New chapter.
[platform/upstream/automake.git] / aclocal.in
index a05ba72..5cc280f 100644 (file)
@@ -134,15 +134,35 @@ my $ac_defun_rx =
 # Matches an AC_REQUIRE line.
 my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
 
-# Matches an m4_include line
-my $m4_include_rx = "(?:m4_)?(s?)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
+# Matches an m4_include line.
+my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
 
-# Match a serial number
+# Match a serial number.
 my $serial_line_rx = '^#\s*serial\s+(\S*)';
 my $serial_number_rx = '^\d+(?:\.\d+)*$';
+
+# Autoconf version
+# Set by trace_used_macros.
+my $ac_version;
+
+# If set, names a temporary file that must be erased on abnormal exit.
+my $erase_me;
 \f
 ################################################################
 
+# Erase temporary file ERASE_ME.
+sub unlink_tmp
+{
+  if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
+    {
+      fatal "could not remove `$erase_me': $!";
+    }
+  undef $erase_me;
+}
+
+$SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
+END { unlink_tmp }
+
 # Check macros in acinclude.m4.  If one is not used, warn.
 sub check_acinclude ()
 {
@@ -176,7 +196,7 @@ sub reset_maps ()
 sub install_file ($$)
 {
   my ($src, $dest) = @_;
-  my $diff_dest = $dest;
+  my $diff_dest;
 
   if ($force_output
       || !exists $file_contents{$dest}
@@ -185,21 +205,48 @@ sub install_file ($$)
       if (-e $dest)
        {
          msg 'note', "overwriting `$dest' with `$src'";
+         $diff_dest = $dest;
        }
       else
        {
          msg 'note', "installing `$dest' from `$src'";
-         $diff_dest = '/dev/null';
        }
 
       if (@diff_command)
        {
+         if (! defined $diff_dest)
+           {
+             # $dest does not exist.  We create an empty one just to
+             # run diff, and we erase it afterward.  Using the real
+             # the destination file (rather than a temporary file) is
+             # good when diff is run with options that display the
+             # file name.
+             #
+             # If creating $dest fails, fall back to /dev/null.  At
+             # least one diff implementation (Tru64's) cannot deal
+             # with /dev/null.  However working around this is not
+             # worth the trouble since nobody run aclocal on a
+             # read-only tree anyway.
+             $erase_me = $dest;
+             my $f = new IO::File "> $dest";
+             if (! defined $f)
+               {
+                 undef $erase_me;
+                 $diff_dest = '/dev/null';
+               }
+             else
+               {
+                 $diff_dest = $dest;
+                 $f->close;
+               }
+           }
          my @cmd = (@diff_command, $diff_dest, $src);
          $! = 0;
          verb "running: @cmd";
          my $res = system (@cmd);
          Automake::FileUtils::handle_exec_errors "@cmd", 1
            if $res;
+         unlink_tmp;
        }
       elsif (!$dry_run)
        {
@@ -348,12 +395,14 @@ sub scan_configure_dep ($)
       # Remove comments from current line.
       s/\bdnl\b.*$//;
       s/\#.*$//;
+      # Avoid running all the following regexes on white lines.
+      next if /^\s*$/;
 
       while (/$m4_include_rx/go)
        {
          my $ifile = $2 || $3;
          # Skip missing `sinclude'd files.
-         next if $1 eq 's' && ! -f $ifile;
+         next if $1 ne 'm4_' && ! -f $ifile;
          push @ilist, $ifile;
        }
 
@@ -486,6 +535,11 @@ sub scan_file ($$$)
            }
        }
 
+      # Remove comments from current line.
+      # Do not do it earlier, because the serial line is a comment.
+      $line =~ s/\bdnl\b.*$//;
+      $line =~ s/\#.*$//;
+
       while ($line =~ /$ac_defun_rx/go)
        {
          $defun_seen = 1;
@@ -528,7 +582,7 @@ sub scan_file ($$$)
        {
          my $ifile = $2 || $3;
          # Skip missing `sinclude'd files.
-         next if $1 eq 's' && ! -f $ifile;
+         next if $1 ne 'm4_' && ! -f $ifile;
          push (@inc_files, $ifile);
          $inc_lines{$ifile} = $.;
        }
@@ -600,9 +654,11 @@ sub trace_used_macros ()
   $traces .= join (' ', grep { exists $files{$_} } @file_order) . " ";
   # All candidate macros.
   $traces .= join (' ',
-                  (map { "--trace='$_:\$f::\$n::\$1'" } ('AC_DEFUN',
-                                                         'AC_DEFUN_ONCE',
-                                                         'AU_DEFUN')),
+                  (map { "--trace='$_:\$f::\$n::\$1'" }
+                   ('AC_DEFUN',
+                    'AC_DEFUN_ONCE',
+                    'AU_DEFUN',
+                    '_AM_AUTOCONF_VERSION')),
                   # Do not trace $1 for all other macros as we do
                   # not need it and it might contains harmful
                   # characters (like newlines).
@@ -625,6 +681,8 @@ sub trace_used_macros ()
        if ($macro eq 'AC_DEFUN'
            || $macro eq 'AC_DEFUN_ONCE'
            || $macro eq 'AU_DEFUN');
+
+      $ac_version = $arg1 if $macro eq '_AM_AUTOCONF_VERSION';
     }
 
   $tracefh->close;
@@ -719,6 +777,17 @@ sub write_aclocal ($@)
   # FIXME: Shouldn't we diagnose this?
   return 1 if ! length ($output);
 
+  if ($ac_version)
+    {
+      # Do not use "$output_file" here for the same reason we do not
+      # use it in the header below.  autom4te will output the name of
+      # the file in the diagnostic anyway.
+      $output = "m4_if(m4_PACKAGE_VERSION, [$ac_version],,
+[m4_fatal([this file was generated for autoconf $ac_version], [63])])
+
+$output";
+    }
+
   # We used to print `# $output_file generated automatically etc.'  But
   # this creates spurious differences when using autoreconf.  Autoreconf
   # creates aclocal.m4t and then rename it to aclocal.m4, but the
@@ -942,7 +1011,10 @@ sub parse_arguments ()
              # strip off newlines and end-of-line comments
              s/\s*\#.*$//;
              chomp;
-             push (@system_includes, $_) if -d $_;
+             foreach my $dir (glob)
+               {
+                 push (@system_includes, $dir) if -d $dir;
+               }
            }
          close (DIRLIST);
        }