diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2012-04-07 22:10:11 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2012-12-17 15:13:42 +0100 |
commit | 391daa2727f7b4c1631d1607bd66c39db47715a9 (patch) | |
tree | d97e9458d0fe20d854862b95bdf06fd5e074fc28 | |
parent | 98002fb28048d96366d4b41400e271ebf5054039 (diff) | |
download | ptxdist-391daa2727f7b4c1631d1607bd66c39db47715a9.tar.gz ptxdist-391daa2727f7b4c1631d1607bd66c39db47715a9.tar.xz |
move ptxd_abs2rel to libptxdist.sh
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rwxr-xr-x | scripts/install_copy_toolchain.sh | 42 | ||||
-rw-r--r-- | scripts/libptxdist.sh | 44 |
2 files changed, 44 insertions, 42 deletions
diff --git a/scripts/install_copy_toolchain.sh b/scripts/install_copy_toolchain.sh index 791a83ea5..93606e869 100755 --- a/scripts/install_copy_toolchain.sh +++ b/scripts/install_copy_toolchain.sh @@ -3,48 +3,6 @@ . ${PTXDIST_TOPDIR}/scripts/ptxdist_vars.sh . ${SCRIPTSDIR}/libptxdist.sh -# -# $1 = from -# $2 = to -# -# out: relative path -# -ptxd_abs2rel() { - local from from_parts to to_parts max orig_IFS - - [ ${#} -eq 2 ] || ptxd_bailout "supply exactly two paths" - - from="${1}" - to="${2}" - - orig_IFS="${IFS}" - IFS="/" - from_parts=(${from#/}) - to_parts=(${to#/}) - - if [ ${#from_parts[@]} -gt ${#to_parts[@]} ]; then - max=${#from_parts[@]} - else - max=${#to_parts[@]} - fi - - for ((i = 0; i < ${max}; i++)); do - from="${from_parts[i]}" - to="${to_parts[i]}" - - if [ "${from}" = "${to}" ]; then - unset from_parts[$i] - unset to_parts[$i] - elif [ -n "${from}" ]; then - from_parts[$i]=".." - fi - done - - echo "${from_parts[*]}${from_parts[*]:+/}${to_parts[*]}" - IFS="${orig_IFS}" -} - - # $1: lib # # out: $lib_path diff --git a/scripts/libptxdist.sh b/scripts/libptxdist.sh index 42b9965ce..6c93e57f5 100644 --- a/scripts/libptxdist.sh +++ b/scripts/libptxdist.sh @@ -585,6 +585,50 @@ export -f ptxd_abspath # +# calculate the relative path from one absolute path to another +# +# $1 from path +# $2 to path +# +ptxd_abs2rel() { + local from from_parts to to_parts max orig_IFS + if [ $# -ne 2 ]; then + ptxd_bailout "usage: ptxd_abs2rel <from> <to>" + fi + + from="${1}" + to="${2}" + + orig_IFS="${IFS}" + IFS="/" + from_parts=(${from#/}) + to_parts=(${to#/}) + + if [ ${#from_parts[@]} -gt ${#to_parts[@]} ]; then + max=${#from_parts[@]} + else + max=${#to_parts[@]} + fi + + for ((i = 0; i < ${max}; i++)); do + from="${from_parts[i]}" + to="${to_parts[i]}" + + if [ "${from}" = "${to}" ]; then + unset from_parts[$i] + unset to_parts[$i] + elif [ -n "${from}" ]; then + from_parts[$i]=".." + fi + done + + echo "${from_parts[*]}${from_parts[*]:+/}${to_parts[*]}" + IFS="${orig_IFS}" +} +export -f ptxd_abs2rel + + +# # prints a path but removes non interesting prefixes # ptxd_print_path() { |