Portability fix: readlink is not portable.
authorBruno Haible <bruno@clisp.org>
Mon, 19 Sep 2005 15:32:08 +0000 (15:32 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 19 Sep 2005 15:32:08 +0000 (15:32 +0000)
ChangeLog
gnulib-tool

index 190700d96bfde7562331c4eab56b33b0c1cd9187..3b7fb0f5bf8b8342a54ac81ee98a430702fb9d87 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-09-18  Bruno Haible  <bruno@clisp.org>
+
+       Portability fix.
+       * gnulib-tool (func_readlink): New function.
+       (func_ln_if_changed): Use it.
+
 2005-09-18  Bruno Haible  <bruno@clisp.org>
 
        * gnulib-tool: Revise --dry-run implementation. Use variable $doit
index 44985c9ab50369ebaeca1b03929d504229badf1b..0bd9eb11827366f6582332638ef8a65747dcf0ad 100755 (executable)
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2005-09-19 15:31:32 $'
+cvsdatestamp='$Date: 2005-09-19 15:32:08 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 
@@ -162,6 +162,23 @@ func_fatal_error ()
   exit 1
 }
 
+# func_readlink SYMLINK
+# outputs the target of the given symlink.
+if (type -p readlink) > /dev/null 2>&1; then
+  func_readlink ()
+  {
+    # Use the readlink program from GNU coreutils.
+    readlink "$1"
+  }
+else
+  func_readlink ()
+  {
+    # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
+    # would do the wrong link if the link target contains " -> ".
+    LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
+  }
+fi
+
 # func_ln_if_changed SRC DEST
 # Like ln -s, but avoids munging timestamps if the link is correct.
 func_ln_if_changed ()
@@ -169,7 +186,7 @@ func_ln_if_changed ()
   if test $# -ne 2; then
     echo "usage: func_ln_if_changed SRC DEST" >&2
   fi
-  if test -L "$2" && test "$1" = "`readlink "$2"`"; then
+  if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
     :
   else
     rm -f "$2"
@@ -371,9 +388,7 @@ case "$0" in
 esac
 while test -h "$self_abspathname"; do
   # Resolve symbolic link.
-  sedexpr1='s, -> ,#%%#,'
-  sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
-  linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
+  linkval=`func_readlink "$self_abspathname"`
   test -n "$linkval" || break
   case "$linkval" in
     /* ) self_abspathname="$linkval" ;;