This fix makes sure that the package installation will work
on systems using versions of 'GNU coreutils' older than 8.16.

Please see tools/lnr.sh for limitations for this fix.
---
 configure.ac |   16 ++++++++++
 tools/lnr.sh |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100755 tools/lnr.sh

diff --git a/configure.ac b/configure.ac
index ead697b..399a52f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -315,6 +315,22 @@ fi
 AM_CONDITIONAL(ENABLE_COVERAGE, [test "$have_coverage" = "yes"])
 
 # 
------------------------------------------------------------------------------
+ln_relative_support=yes
+AC_CHECK_PROG(ln_found, [ln], [yes], [no])
+if test "x$ln_found" = xno ; then
+        AC_MSG_ERROR([*** ln support requested but the program was not found])
+else
+        ln_version_major="`ln --version | head -1 | cut -d ' ' -f 4 | cut -d 
'.' -f 1`"
+        ln_version_minor="`ln --version | head -1 | cut -d ' ' -f 4 | cut -d 
'.' -f 2`"
+        if test "$ln_version_major" -lt 8 || test "$ln_version_major" -eq 8 -a 
"$ln_version_minor" -lt 16; then
+                ln_relative_support=no
+        fi
+        if test "x$ln_relative_support" = "xno"; then
+                LN_S=$(echo "$LN_S" | sed s:"ln":""$srcdir"\/tools\/lnr.sh":)
+        fi
+fi
+
+# 
------------------------------------------------------------------------------
 have_kmod=no
 AC_ARG_ENABLE(kmod, AS_HELP_STRING([--disable-kmod], [disable loadable modules 
support]))
 if test "x$enable_kmod" != "xno"; then
diff --git a/tools/lnr.sh b/tools/lnr.sh
new file mode 100755
index 0000000..74e1644
--- /dev/null
+++ b/tools/lnr.sh
@@ -0,0 +1,93 @@
+# This script makes the 'ln --relative' command work as expected on a system 
where the
+# 'relative' option of 'ln' is not supported.
+#
+# NOTE:
+# The script assumes that the 'relative' option of 'ln' is used with any
+# of the following syntaxes:
+# '--relative'
+# '-r'
+#
+# The script will NOT handle combined options e.g. '-rf', '-ir' etc.
+# The script will also only handle the 1st form of the 'ln' command (see man 
page
+# for the 'ln' command for the different forms).
+#
+
+
+relative_file() {
+       # Calculate the relative path from $1 to $2.
+       # $1 and $2 are files (including paths).
+
+       source=$(dirname $1)
+       target=$(dirname $2)
+
+       # Make the paths absolute
+       [ "${source#/}" != "$source" ] || source="$(pwd)/$source"
+       [ "${target#/}" != "$target" ] || target="$(pwd)/$target"
+
+       common_part=$source
+       result=""
+
+       while [ "${target#$common_part}" = "${target}" ]; do
+               # No match, means that the candidate common part is not correct
+               # Go up one level (reduce common part)
+               common_part="$(dirname $common_part)"
+               # and record that we went back, with correct / handling
+               if [ -z "$result" ]; then
+                       result=".."
+               else
+                       result="../$result"
+               fi
+       done
+
+       if [ "$common_part" = / ]; then
+               # Special case for root (no common path)
+               result="$result/"
+       fi
+
+       # Since we now have identified the common part,compute the non-common
+       # part
+       forward_part="${target#$common_part}"
+
+       # And now stick all parts together
+       result="$result$forward_part"
+       result="${result%/}"
+       result="$result/$(basename $2)"
+       result="${result#/}"
+
+       echo "$result"
+}
+
+
+# "relative" options
+relop_1="--relative"
+relop_2="-r"
+
+# indicates if the "relative" option is used
+relative_option=no
+
+# the "new" command line
+new_cmd=ln
+
+while [ $# -gt 2 ]; do
+       string="$1"
+       if [ "${string#-*}" != "$string" ]; then
+               # argument is an option
+               if [ "$string" = "$relop_1" ] || [ "$string" = "$relop_2" ]; 
then
+                       relative_option=yes
+               else
+                       # add option to new command line
+                       new_cmd=""$new_cmd" "$string""
+               fi
+       fi
+       shift
+done
+
+if [ "$relative_option" = yes ]; then
+       new_cmd=""$new_cmd" $(relative_file "$2" "$1") "$2""
+else
+       new_cmd=""$new_cmd" "$1" "$2""
+fi
+
+eval "$new_cmd"
+
+exit 0
-- 
1.7.10.4

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to