diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-09-29 12:17:38 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-09-29 12:17:38 +0000 |
commit | 307a409e5a3cc8c467bbe5d0e0fe9beacf620adf (patch) | |
tree | 77b4d4f00642c3c1c86755e63cd5d2424b058972 /Build/source/build-aux | |
parent | 54b9868277dbd900c93d8b750654b9ed43b51b26 (diff) |
somewhat more general way to create symlinks for linked scripts
using build-aux/relpath
git-svn-id: svn://tug.org/texlive/trunk@24137 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/build-aux')
-rwxr-xr-x | Build/source/build-aux/relpath | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Build/source/build-aux/relpath b/Build/source/build-aux/relpath new file mode 100755 index 00000000000..f448cfcd84e --- /dev/null +++ b/Build/source/build-aux/relpath @@ -0,0 +1,58 @@ +#! /bin/sh +# relpath - compute the relative path FROM -> TO + +# Copyright (C) 2011 Peter Breitenlohner <tex-live@tug.org> +# +# This file is free software; the copyright holder +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# First handle the simple case that FROM is a subdirectory of TO + +case $2 in + "$3"/*) + echo "X$2" | sed 's,^X'$3'/,,; s,[^/][^/]*,..,g' + exit 0;; +esac + +# Now the more general case, mainly for distro builds + +err () { + echo "$*" >&2 + exit 1 +} + +test $# = 3 || err 'relpath PREF FROM TO + compute the relative path FROM -> TO + where FROM and TO are absolute paths, and + prefixed with PREF are existing directories' + +chk () { + case $2 in + *' '* | *'/./'* | *'/../'*) err "'$2' contains ' ', '/./', or '/../'";; + /*) ;; + *) err "'$2' must be an absolute path";; + esac + test -d "$1$2" || err "'$1$2' not a directory" + # Normalize, remove leading and trailing / + res=`echo $2 | sed 's,^//*,,; s,//*$,,; s,///*,/,g'` +} + +chk "$1" "$2"; from=$res +chk "$1" "$3"; to=$res + +test "/$from" = "/$to" && { echo "."; exit 0; } + +# Remove common prefix +while test "/$to" != "/"; do + test "/$from" = "/" && { echo "$to"; exit 0; } + test `echo $from | sed 's,/.*,,'` = `echo $to | sed 's,/.*,,'` || break + from=`echo $from | sed 's,[^/]*/*,,'` + to=`echo $to | sed 's,[^/]*/*,,'` +done + +from=`echo $from | sed 's,[^/][^/]*,..,g'` +test "/$to" = "/" || from="$from/$to" + +echo "$from" +exit 0 |