alpha: Purge __ASSUME_STAT64_SYSCALL
[glibc.git] / scripts / rellns-sh
blob64e8cd971cd44e9de5da484c13390d4e20f8162b
1 #! /bin/sh
2 # rellns-sh - Simplified ln program to generate relative symbolic link.
3 # Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 # Written by Ulrich Drepper <drepper@cygnus.com>, October 1996
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>.
19 if test $# -ne 2; then
20 echo "Usage: rellns SOURCE DEST" >&2
21 exit 1
24 if test -x /bin/pwd; then
25 pwd=/bin/pwd
26 elif test -x /usr/bin/pwd; then
27 pwd=/usr/bin/pwd
28 else
29 pwd='pwd'
32 # Make both paths absolute.
33 if test -d $1; then
34 to=`cd $1 && $pwd`
35 else
36 temp=`echo $1 | sed 's%/*[^/]*$%%'`
37 if test -z "$temp"; then
38 to=`$pwd`
39 else
40 to=`cd $temp && $pwd`
42 to="$to/`echo $1 | sed 's%.*/\([^/][^/]*\)$%\1%'`"
44 to=`echo $to | sed 's%^/%%'`
46 if test -d $2; then
47 from=`echo $2 | sed 's%/*$%%'`
48 else
49 from=`echo $2 | sed 's%/*[^/]*$%%'`
52 if test -z "$from"; then
53 from=`$pwd | sed 's%^/%%'`
54 else
55 from=`cd $from && $pwd | sed 's%^/%%'`
58 while test -n "$to" && test -n "$from"; do
59 preto=`echo $to | sed 's%^\([^/]*\)/.*%\1%'`
60 prefrom=`echo $from | sed 's%^\([^/]*\)/.*%\1%'`
62 test "$preto" != "$prefrom" && break
64 to=`echo $to | sed 's%^[^/]*/*\(.*\)$%\1%'`
65 from=`echo $from | sed 's%^[^/]*/*\(.*\)$%\1%'`
66 done
68 while test -n "$from"; do
69 rfrom="../$rfrom"
70 from=`echo $from | sed 's%^[^/]*/*%%'`
71 done
73 ln -s $rfrom$to $2