* lib/Automake/FileUtils.pm (dir_has_case_matching_file,
authorAlexandre Duret-Lutz <adl@gnu.org>
Wed, 8 Dec 2004 22:00:50 +0000 (22:00 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Wed, 8 Dec 2004 22:00:50 +0000 (22:00 +0000)
reset_dir_cache): New functions.
* automake.in (handle_dist, require_file_internal): Use them, so
that CHANGELOG is not confused with ChangeLog on case-insensitive
case-preserving file systems.
* tests/hfs.test: New file.
* tests/Makefile.am (TESTS): Add hfs.test.

ChangeLog
THANKS
automake.in
lib/Automake/FileUtils.pm
tests/Makefile.am
tests/Makefile.in
tests/hfs.test [new file with mode: 0755]

index 5cc55f0..cb3cedb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-12-08  Peter O'Gorman  <peter@pogma.com>
+           Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * lib/Automake/FileUtils.pm (dir_has_case_matching_file,
+       reset_dir_cache): New functions.
+       * automake.in (handle_dist, require_file_internal): Use them, so
+       that CHANGELOG is not confused with ChangeLog on case-insensitive
+       case-preserving file systems.
+       * tests/hfs.test: New file.
+       * tests/Makefile.am (TESTS): Add hfs.test.
+
 2004-12-08  Paul Eggert  <eggert@cs.ucla.edu>
 
        * lib/mdate-sh: Don't use "set - x`$ls_command /`", as zsh mishandles
@@ -5,7 +16,7 @@
        <http://lists.gnu.org/archive/html/autoconf/2004-12/msg00074.html>.
        Don't use "set - x"; plain "set x" is enough, and simplifies debugging.
 
-2004-11-15  Toshio Kuratomi  <toshio@tiki-lounge.com>
+2004-12-05  Toshio Kuratomi  <toshio@tiki-lounge.com>
 
        * lib/py-compile: Add --destdir switch to py-compile that takes a
        path argument that is not compiled into the file when byte compiling.
diff --git a/THANKS b/THANKS
index d13d6a8..6bc07be 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -202,6 +202,7 @@ Peter Eisentraut    peter_e@gmx.net
 Peter Gavin            pgavin@debaser.kicks-ass.org
 Peter Mattis           petm@scam.XCF.Berkeley.EDU
 Peter Muir             iyhi@yahoo.com
+Peter O'Gorman         peter@pogma.com
 Peter Seiderer         seiderer123@ciselant.de
 Petter Reinholdtsen    pere@hungry.com
 Phil Edwards           phil@jaj.com
index 4a085ef..84aa4c8 100755 (executable)
@@ -3505,7 +3505,7 @@ sub handle_dist ()
     }
   foreach my $cfile (@common_files)
     {
-      if (-f ($relative_dir . "/" . $cfile)
+      if (dir_has_case_matching_file ($relative_dir, $cfile)
          # The file might be absent, but if it can be built it's ok.
          || rule $cfile)
        {
@@ -3514,7 +3514,7 @@ sub handle_dist ()
 
       # Don't use `elsif' here because a file might meaningfully
       # appear in both directories.
-      if ($check_aux && -f "$config_aux_dir/$cfile")
+      if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
        {
          &push_dist_common ("$config_aux_dir/$cfile")
        }
@@ -6925,7 +6925,7 @@ sub require_file_internal ($$$@)
        {
          $dangling_sym = 1;
        }
-      elsif (-f $fullfile)
+      elsif (dir_has_case_matching_file ($dir, $file))
        {
          $found_it = 1;
          maybe_push_required_file ($dir, $file, $fullfile);
@@ -6989,6 +6989,7 @@ sub require_file_internal ($$$@)
                          $suppress = 0;
                          $trailer = "\n    error while copying";
                        }
+                     reset_dir_cache ($dir);
                    }
 
                  if (! maybe_push_required_file (dirname ($fullfile),
index bb8304e..2c9cba3 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004  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
@@ -44,7 +44,7 @@ use vars qw (@ISA @EXPORT);
 @EXPORT = qw (&contents
              &find_file &mtime
              &update_file &up_to_date_p
-             &xsystem &xqx);
+             &xsystem &xqx &dir_has_case_matching_file &reset_dir_cache);
 
 
 =item C<find_file ($filename, @include)>
@@ -310,6 +310,58 @@ sub contents ($)
 }
 
 
+=item C<dir_has_case_matching_file ($DIRNAME, $FILENAME)>
+
+Return true iff $DIR contains a filename that matches $FILENAME case
+insensitively.
+
+We need to be cautious on case-insensitive case-preserving file
+systems (e.g. Mac OS X's HFS+).  On such systems C<-f 'Foo'> and C<-f
+'foO'> answer the same thing.  Hence if a package distributes its own
+F<CHANGELOG> file, but has no F<ChangeLog> file, automake would still
+try to distribute F<ChangeLog> (because it thinks it exists) in
+addition to F<CHANGELOG>, although it is impossible for these two
+files to be in the same directory (the two filenames designate the
+same file).
+
+=cut
+
+use vars '%_directory_cache';
+sub dir_has_case_matching_file ($$)
+{
+  # Note that print File::Spec->case_tolerant returns 0 even on MacOS
+  # X (with Perl v5.8.1-RC3 at least), so do not try to shortcut this
+  # function using that.
+
+  my ($dirname, $filename) = @_;
+  return 0 unless -f "$dirname/$filename";
+
+  # The file appears to exist, however it might be a mirage if the
+  # system is case insensitive.  Let's browse the directory and check
+  # whether the file is really in.  We maintain a cache of directories
+  # so Automake doesn't spend all its time reading the same directory
+  # again and again.
+  if (!exists $_directory_cache{$dirname})
+    {
+      error "failed to open directory `$dirname'"
+       unless opendir (DIR, $dirname);
+      $_directory_cache{$dirname} = { map { $_ => 1 } readdir (DIR) };
+      closedir (DIR);
+    }
+  return exists $_directory_cache{$dirname}{$filename};
+}
+
+=item C<reset_dir_cache ($dirname)>
+
+Clear C<dir_has_case_matching_file>'s cache for C<$dirname>.
+
+=cut
+
+sub reset_dir_cache ($)
+{
+  delete $_directory_cache{$_[0]};
+}
+
 1; # for require
 
 ### Setup "GNU" style for perl-mode and cperl-mode.
index 62adf63..527c19e 100644 (file)
@@ -248,6 +248,7 @@ gnits2.test \
 gnits3.test \
 header.test \
 help.test \
+hfs.test \
 hosts.test \
 implicit.test \
 include.test \
index 11bfe1f..79f0e88 100644 (file)
@@ -367,6 +367,7 @@ gnits2.test \
 gnits3.test \
 header.test \
 help.test \
+hfs.test \
 hosts.test \
 implicit.test \
 include.test \
diff --git a/tests/hfs.test b/tests/hfs.test
new file mode 100755 (executable)
index 0000000..9e3748f
--- /dev/null
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2004  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+
+# Automake should not think that ChangeLog == CHANGELOG on
+# case-preserving case-insensitive filesystems (such as HFS+, on
+# Darwin).
+# Report from Peter O'Gorman.
+
+. ./defs
+set -e
+
+echo AC_OUTPUT >>configure.in
+
+: >CHANGELOG
+echo 'EXTRA_DIST = CHANGELOG' >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck