4
# Copyright (C) 2002 Free Software Foundation, Inc.
6
# Author: Nicola Pero <n.pero@mi.flashnet.it>
9
# This file is part of the GNUstep Makefile Package.
11
# This library is free software; you can redistribute it and/or
12
# modify it under the terms of the GNU General Public License
13
# as published by the Free Software Foundation; either version 2
14
# of the License, or (at your option) any later version.
16
# You should have received a copy of the GNU General Public
17
# License along with this library; see the file COPYING.LIB.
18
# If not, write to the Free Software Foundation,
19
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
# This script gets two paths as argument - and outputs a relative path
22
# which, when appended to the first one, gives the second one ... more
23
# precisely, the path of minimum length with this property.
25
# <NB: the paths must be absolute.>
29
# $GNUSTEP_MAKEFILES/relative_path.sh /usr/GNUstep/Local /usr/GNUstep/System
31
# returns ../System (and not ../../GNUstep/System which is not the minimum).
33
# This is needed by `ln -s' to properly create symlinks between
34
# directories which are related ... but we don't know how. We only
35
# need this for frameworks, which are particularly complex and
36
# delicate. For example, to create the link
38
# /usr/GNUstep/System/Library/Libraries/ix86/linux-gnu/gnu-gnu-gnu/libnicola.so
39
# --> ../../../../Frameworks/nicola.framework/Versions/Current/ix86/linux-gnu/gnu-gnu-gnu/libnicola.so
41
# (and where the paths are actually computed by make variables which
42
# might depend on variables in user makefiles outside our control, so
43
# it's not obvious what the relationship is between the two paths, and
44
# you only have the absolute paths) we do -
46
# cd /usr/GNUstep/System/Library/Libraries/ix86/linux-gnu/gnu-gnu-gnu/
47
# $(LN_S) `$(RELATIVE_PATH_SCRIPT) /usr/GNUstep/System/Frameworks/nicola.framework/Versions/Current/ix86/linux-gnu/gnu-gnu-gnu/libnicola.so /usr/GNUstep/System/Library/Libraries/ix86/linux-gnu/gnu-gnu-gnu/` libnicola.so
49
# which creates the link. We need to use the minimum path because
50
# that is the most relocatable possible path. I consider all this a
51
# trick and a hack and recommend to use libraries and bundles instead
52
# of frameworks, since libraries and bundles are much more portable
53
# and stable, anyway here we are.
57
if [ "$#" != 2 ]; then
64
if [ "$a" = "" ]; then
68
if [ "$b" = "" ]; then
74
# Our first argument is a path like /xxx/yyy/zzz/ccc/ttt
75
# Our second argument is a path like /xxx/yyy/kkk/nnn/ppp
78
# Step zero is normalizing the paths by removing any /./ component
79
# inside the given paths (these components can occur for example when
80
# enable-flattened is used).
84
# Normalize a by removing any '.' path component.
86
for component in $a; do
87
if [ -n "$component" ]; then
88
if [ "$component" != "." ]; then
89
normalized_a="$normalized_a/$component"
95
# Normalize b by removing any '.' path component.
97
for component in $b; do
98
if [ -n "$component" ]; then
99
if [ "$component" != "." ]; then
100
normalized_b="$normalized_b/$component"
110
# Step one: we first want to remove the common root -- we want to get
111
# into having /zzz/ccc/tt and /kkk/nnn/ppp.
113
# We first try to match as much as possible between the first and the second
114
# So we loop on the fields in the second. The common root must not contain
115
# empty path components (/./) for this to work, but we have already filtered
116
# those out at step zero.
121
for component in $b; do
122
if [ -n "$component" ]; then
123
partial_b="$partial_b/$component"
125
"$partial_b"*) partial_match="$partial_b";;
132
if [ "$partial_match" != "" ]; then
133
# Now partial_match is the substring which matches (/xxx/yyy/) in the
134
# example. Remove it from both a and b.
135
a=`echo $a | sed -e "s#$partial_match##"`
136
b=`echo $b | sed -e "s#$partial_match##"`
139
# Ok - now ready to build the result
142
# First add as many ../ as there are components in a
145
for component in $a; do
146
if [ -n "$component" -a "$component" != "." ]; then
147
if [ -z "$result" ]; then
157
if [ -n "$result" ]; then