ldso: Use single rtld_flags interpretation through all the calls
[uclibc-ng.git] / extra / scripts / relative_path.sh
blob4dddefac143814eab5d8258408626bc2909cc6e8
1 #! /bin/sh
3 # Copyright 2003 Alexandre Oliva <aoliva@redhat.com>
4 # Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
6 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
9 # This script computes a relative pathname from $1 to $2
10 # They are assumed to not contain . or .. pathname components,
11 # but if both directories exist and cd/pwd canonicalizes pathnames,
12 # this shouldn't matter. PWD_CMD may be set to some pwd command that does.
14 from=`(cd $1 > /dev/null && ${PWD_CMD-pwd} || echo $1) 2>/dev/null | sed 's,//*,/,g;s,/*$,,'`
15 target=`(cd $2 > /dev/null && ${PWD_CMD-pwd} || echo $2) 2>/dev/null | sed 's,//*,/,g;s,/*$,,'`
17 case $from in /* | "") ;; *) from=`${PWD_CMD-pwd}`/$from ;; esac
18 case $target in /* | "") ;; *) target=`${PWD_CMD-pwd}`/$target ;; esac
20 case $target in
21 "$from" | "$from/"*)
22 dots=`echo $from | sed s,.,.,g`
23 echo $target | sed "s,^$dots/*,,;s,[^/]$,&/,"
24 exit 0
26 esac
28 case $from in
29 "$target/"*)
30 dots=`echo $target | sed s,.,.,g`
31 echo $from/ | sed "s,^$dots/*,,;s,[^/]$,&/,;s,[^/]*/*,../,g;s,[^/]$,&/,"
32 exit 0
34 esac
36 # Without trailing slash, from=/usr/lib and target=/uclibc/lib
37 # mistakenly concludes that prefix=/u
38 #prefix=`echo $from///$target | sed 's,\(\(/[^/]*\)*\).*///\1.*,\1,'`
39 prefix=`echo $from///$target | sed 's,\(\(/[^/]*\)*/\).*///\1.*,\1,'`
40 dots=`echo $prefix | sed s,.,.,g`
41 from=`echo $from | sed "s,^$dots,,"`
42 target=`echo $target | sed "s,^$dots,,"`
44 from=`echo $from | sed 's,[^/][^/]*,..,g;s,.$,&/,'`
45 echo ${from}$target/
47 exit 0