net/bnxt: fix link during port toggle
[dpdk.git] / buildtools / relpath.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
4
5 #
6 # print the relative path of $1 from $2 directory
7 # $1 and $2 MUST be absolute paths
8 #
9
10 if [ $# -ne 2 ]; then
11         echo "Bad arguments"
12         echo "Usage:"
13         echo "  $0 path1 path2"
14         exit 1
15 fi
16
17 # get the real absolute path, derefencing symlinks
18 ABS1="$(dirname $(readlink -f $1))/$(basename $1)"
19 ABS2=$(readlink -f $2)
20
21 # remove leading slash
22 REL1=${ABS1#/}
23 REL2=${ABS2#/}
24
25 left1=${REL1%%/*}
26 right1=${REL1#*/}
27 prev_right1=$REL1
28 prev_left1=
29
30 left2=${REL2%%/*}
31 right2=${REL2#*/}
32 prev_right2=$REL2
33 prev_left2=
34
35 prefix=
36
37 while [ "${right1}" != "" -a "${right2}" != "" ]; do
38
39         if [ "$left1" != "$left2" ]; then
40                 break
41         fi
42
43         prev_left1=$left1
44         left1=$left1/${right1%%/*}
45         prev_right1=$right1
46         right1=${prev_right1#*/}
47         if [ "$right1" = "$prev_right1" ]; then
48                 right1=""
49         fi
50
51         prev_left2=$left2
52         left2=$left2/${right2%%/*}
53         prev_right2=$right2
54         right2=${prev_right2#*/}
55         if [ "$right2" = "$prev_right2" ]; then
56                 right2=""
57         fi
58 done
59
60 if [ "${left1}" != "${left2}" ]; then
61         right2=${prev_right2}
62         right1=${prev_right1}
63 fi
64
65 while [ "${right2}" != "" ]; do
66         prefix=${prefix}../
67         prev_right2=$right2
68         right2=${right2#*/}
69         if [ "$right2" = "$prev_right2" ]; then
70                 right2=""
71         fi
72 done
73
74 echo ${prefix}${right1}
75
76 exit 0