]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
* doc/automake.texi (limitations on file names): New section.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 13 Sep 2005 23:14:57 +0000 (23:14 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 13 Sep 2005 23:14:57 +0000 (23:14 +0000)
* lib/install-sh: Rewrite to support '*' in file names.
Also, tune so that we don't invoke so many commands in the usual case.
* tests/instspc.test: The "*" test is now fixed.

ChangeLog
doc/automake.texi
lib/install-sh
tests/instspc.test

index 6a9623828f252ecc4fb1f0218881c1540fd0b8f7..04413dc866e5b1e5ed3d692bbc653a30b5c458ac 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-09-13  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * doc/automake.texi (limitations on file names): New section.
+       * lib/install-sh: Rewrite to support '*' in file names.
+       Also, tune so that we don't invoke so many commands in the usual case.
+       * tests/instspc.test: The "*" test is now fixed.
+
 2005-09-13  Stepan Kasal  <kasal@ucw.cz>
 
        * automake.in (Languages) <cppasm>: Fix typo in the comment.
index 190c3896ea293fa94cf532b132dbe0b42bd6cd3d..29ce995a17918650a6c2e4b2ab64145b2aaf94b0 100644 (file)
@@ -253,6 +253,7 @@ Frequently Asked Questions about Automake
 * CVS::                         CVS and generated files
 * maintainer-mode::             missing and AM_MAINTAINER_MODE
 * wildcards::                   Why doesn't Automake support wildcards?
+* limitations on file names::   Limitations on source and installed file names
 * distcleancheck::              Files left in build directory after distclean
 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
 * renamed objects::             Why are object files sometimes renamed?
@@ -8031,6 +8032,7 @@ lists.
 * CVS::                         CVS and generated files
 * maintainer-mode::             missing and AM_MAINTAINER_MODE
 * wildcards::                   Why doesn't Automake support wildcards?
+* limitations on file names::   Limitations on source and installed file names
 * distcleancheck::              Files left in build directory after distclean
 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
 * renamed objects::             Why are object files sometimes renamed?
@@ -8357,6 +8359,69 @@ variables as far Automake is concerned.
 You can get warnings about @samp{$(wildcard ...}) constructs using the
 @option{-Wportability} flag.
 
+@node limitations on file names
+@section Limitations on file names
+@cindex file names, limitations on
+
+Automake attempts to support all kinds of file names, even those that
+contain unusual characters or are unusually long.  However, some
+limitations are imposed by the underlying operating system and tools.
+
+Most operating systems prohibit the use of the null byte in file
+names, and reserve @samp{/} as a directory separator.  Also, they
+require that file names are properly encoded for the user's locale.
+Automake is subject to these limits.
+
+Portable packages should limit themselves to @acronym{POSIX} file
+names.  These can contain @acronym{ASCII} letters and digits,
+@samp{_}, @samp{.}, and @samp{-}.  File names consist of components
+separated by @samp{/}.  File name components cannot begin with
+@samp{-}.
+
+Portable POSIX file names cannot contain components that exceed a
+14-byte limit, but nowadays it's normally safe to assume the
+more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
+limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
+but you may want to limit a source tarball to file names to 99 bytes
+to avoid interoperability problems with old versions of @command{tar}.
+
+If you depart from these rules (e.g., by using non-@acronym{ASCII}
+characters in file names, or by using lengthy file names), your
+installers may have problems for reasons unrelated to Automake.
+However, if this does not concern you, you should know about the
+limitations imposed by Automake itself.  These limitations are
+undesirable, but some of them seem to be inherent to underlying tools
+like Autoconf, Make, M4, and the shell.  They fall into three
+categories: install directories, build directories, and file names.
+
+The following characters:
+
+@example
+@r{newline} " # $ ' `
+@end example
+
+should not appear in the names of install directories.  For example,
+the operand of @command{configure}'s @option{--prefix} option should
+not contain these characters.
+
+Build directories suffer the same limitations as install directories,
+and in addition should not contain the following characters:
+
+@example
+& @@ \
+@end example
+
+For example, the full name of the directory containing the source
+files should not contain these characters.
+
+Source and installation file names like @file{main.c} are limited even
+further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
+rules described above.  In addition, if you plan to port to
+non-@acronym{POSIX} environments, you should avoid file names that
+differ only in case (e.g., @file{makefile} and @file{Makefile}).
+Nowadays it is no longer worth worrying about the 8.3 limits of
+@acronym{DOS} file systems.
+
 @node distcleancheck
 @section Files left in build directory after distclean
 @cindex @code{distclean}, diagnostic
index f56e147640dc843b1fafa0639dea583c1c309496..5ac8da43d5f6b63246416a725496bd2902449366 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2005-07-09.12
+scriptversion=2005-09-13.16
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -58,7 +58,21 @@ stripprog="${STRIPPROG-strip}"
 rmprog="${RMPROG-rm}"
 mkdirprog="${MKDIRPROG-mkdir}"
 
-chmodcmd="$chmodprog 0755"
+posix_glob=
+posix_mkdir=
+
+# Symbolic mode for testing mkdir with directories.
+# It is the same as 755, but also tests that "u+" works.
+test_mode=u=rwx,g=rx,o=rx,u+wx
+
+# Desired mode of installed file.
+mode=0755
+
+# Desired mode of newly created intermediate directories.
+# It is empty if not known yet.
+intermediate_mode=
+
+chmodcmd=$chmodprog
 chowncmd=
 chgrpcmd=
 stripcmd=
@@ -111,7 +125,7 @@ while test -n "$1"; do
 
     --help) echo "$usage"; exit $?;;
 
-    -m) chmodcmd="$chmodprog $2"
+    -m) mode=$2
         shift
         shift
         continue;;
@@ -164,6 +178,8 @@ if test -z "$1"; then
   exit 0
 fi
 
+test -n "$dir_arg" || trap '(exit $?); exit' 1 2 13 15
+
 for src
 do
   # Protect names starting with `-'.
@@ -173,15 +189,11 @@ do
 
   if test -n "$dir_arg"; then
     dst=$src
-    src=
-
-    if test -d "$dst"; then
-      mkdircmd=:
-      chmodcmd=
-    else
-      mkdircmd=$mkdirprog
-    fi
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
   else
+
     # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
     # might cause directories to be created, which would be especially bad
     # if $src (and thus $dsttmp) contains '*'.
@@ -208,53 +220,122 @@ do
        echo "$0: $dstarg: Is a directory" >&2
        exit 1
       fi
-      dst=$dst/`basename "$src"`
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+       (dirname "$dst") 2>/dev/null ||
+       expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+            X"$dst" : 'X\(//\)[^/]' \| \
+            X"$dst" : 'X\(//\)$' \| \
+            X"$dst" : 'X\(/\)' \| \
+            .       : '\(.\)' 2>/dev/null ||
+       echo X"$dst" |
+           sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+                 /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+                 /^X\(\/\/\)$/{ s//\1/; q; }
+                 /^X\(\/\).*/{ s//\1/; q; }
+                 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
     fi
   fi
 
-  # This sed command emulates the dirname command.
-  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+       posix_mkdir=false
+       if $mkdirprog -m $test_mode -p -- / >/dev/null 2>&1; then
+         posix_mkdir=true
+       else
+         # Remove any dirs left behind by ancient mkdir implementations.
+         rmdir ./-m "$test_mode" ./-p ./-- 2>/dev/null
+       fi ;;
+    esac
 
-  # Make sure that the destination directory exists.
+    if
+      $posix_mkdir && {
+
+       # With -d, create the new directory with the user-specified mode.
+       # Otherwise, create it using the same intermediate mode that
+       # mkdir -p would use when creating intermediate directories.
+       # POSIX says that this mode is "$(umask -S),u+wx", so use that
+       # if umask -S works.
+
+       if test -n "$dir_arg"; then
+         mkdir_mode=$mode
+       else
+         case $intermediate_mode in
+           '')
+             if umask_S=`(umask -S) 2>/dev/null`; then
+               intermediate_mode=$umask_S,u+wx
+             else
+               intermediate_mode=$test_mode
+             fi ;;
+         esac
+         mkdir_mode=$intermediate_mode
+       fi
+
+       $mkdirprog -m "$mkdir_mode" -p -- "$dstdir"
+      }
+    then :
+    else
 
-  # Skip lots of stat calls in the usual case.
-  if test ! -d "$dstdir"; then
-    case $dstdir in
-      /*) pathcomp=/ ;;
-      -*) pathcomp=./ ;;
-      *)  pathcomp= ;;
-    esac
-    oIFS=$IFS
-    IFS=/
-    set fnord $dstdir
-    shift
-    IFS=$oIFS
-
-    for d
-    do
-      test "x$d" = x && continue
-
-      pathcomp=$pathcomp$d
-      if test ! -d "$pathcomp"; then
-        $mkdirprog "$pathcomp"
-       # mkdir can fail with a `File exist' error in case several
-       # install-sh are creating the directory concurrently.  This
-       # is OK.
-       test -d "$pathcomp" || exit 1
-      fi
-      pathcomp=$pathcomp/
-    done
+      # mkdir does not conform to POSIX, or it failed possibly due to
+      # a race condition.  Create the directory the slow way, step by
+      # step, checking for races as we go.
+
+      case $dstdir in
+       /*) pathcomp=/ ;;
+       -*) pathcomp=./ ;;
+       *)  pathcomp= ;;
+      esac
+
+      case $posix_glob in
+        '')
+         if (set -f) 2>/dev/null; then
+           posix_glob=true
+         else
+           posix_glob=false
+         fi ;;
+      esac
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob && set -f
+      set fnord $dstdir
+      shift
+      $posix_glob && set +f
+      IFS=$oIFS
+
+      for d
+      do
+       test "x$d" = x && continue
+
+       pathcomp=$pathcomp$d
+       if test ! -d "$pathcomp"; then
+         $mkdirprog "$pathcomp"
+         # Don't fail if two instances are running concurrently.
+         test -d "$pathcomp" || exit 1
+       fi
+       pathcomp=$pathcomp/
+      done
+      obsolete_mkdir_used=true
+    fi
   fi
 
   if test -n "$dir_arg"; then
-    $doit $mkdircmd "$dst" \
-      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
-      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
-      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
-      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
-
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dst"; } || exit 1
   else
-    dstfile=`basename "$dst"`
 
     # Make a couple of temp file names in the proper directory.
     dsttmp=$dstdir/_inst.$$_
@@ -262,7 +343,6 @@ do
 
     # Trap to clean up those temp files at exit.
     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
-    trap '(exit $?); exit' 1 2 13 15
 
     # Copy the file name to the temp name.
     $doit $cpprog "$src" "$dsttmp" &&
@@ -276,10 +356,10 @@ do
     { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
       && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
       && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
-      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dsttmp"; } &&
 
     # Now rename the file to the real destination.
-    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
+    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
       || {
           # The rename failed, perhaps because mv can't rename something else
           # to itself, or perhaps because mv is so ancient that it does not
@@ -291,11 +371,12 @@ do
           # reasons.  In this case, the final cleanup might fail but the new
           # file should still install successfully.
           {
-            if test -f "$dstdir/$dstfile"; then
-              $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
-              || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
+            if test -f "$dst"; then
+              $doit $rmcmd -f "$dst" 2>/dev/null \
+              || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
+                    && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
               || {
-                echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+                echo "$0: cannot unlink or rename $dst" >&2
                 (exit 1); exit 1
               }
             else
@@ -304,16 +385,13 @@ do
           } &&
 
           # Now rename the file to the real destination.
-          $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+          $doit $mvcmd "$dsttmp" "$dst"
         }
-    }
-  fi || { (exit 1); exit 1; }
-done
+    } || exit 1
 
-# The final little trick to "correctly" pass the exit status to the exit trap.
-{
-  (exit 0); exit 0
-}
+    trap - 0
+  fi
+done
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
index bc63033c6c0e9658578a306269a0956be285b77e..72f5d94c8bd35db3e129dc630b8e812ff1ce400b 100755 (executable)
@@ -152,7 +152,7 @@ done
 
 # The list of the above file names that cannot be used as a build directory
 # on a POSIX host.  This list should be empty, but is not due to limitations
-# in Autoconf, Automake, Make, or M4.
+# in Autoconf, Automake, Make, M4, or the shell.
 expected_build_failures='
 "
 #
@@ -172,7 +172,6 @@ expected_install_failures='
 #
 $
 '\''
-*
 `
 '"$lf"'
 a'"${lf}"'b'