File: rel-ln

package info (click to toggle)
swi-prolog 6.6.6-1~bpo70+1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 82,312 kB
  • sloc: ansic: 322,250; perl: 245,822; sh: 6,651; java: 5,254; makefile: 4,423; cpp: 4,153; ruby: 1,594; yacc: 843; xml: 82; sed: 12; sql: 6
file content (78 lines) | stat: -rwxr-xr-x 1,896 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# Author: Stepan Kasal <kasal@suse.cz>
#
# Version: 0.1
#	this shell script is public domain ;-)
# Modified: Thu Feb 17 2000 (JW)
#	Avoid use of ln -sf (GNU specific)
#	Avoid use of GNU sed extensions
#	If all fails due to other links, make an absolute link.
# Modified: Thu Mar  9 2000 (JW)
#	Avoid using grep -q (GNU specific)
#
# Purpose: Make relative links between the binary and lib directory to
# achieve a relocatable object.  Notably useful for generating RPM files.

check_path()
{ case "$1" in
    /*) ;;
    *)  echo "Error: $1 isn't absolute path" >&2
        exit 1
        ;;
  esac
}

compare()
{ test $# = 4 && test "$1" = "$3" && from=$2 && to=$4
}

if test $# != 2 ; then
  echo "usage:  $0 from to
	creates relative symbolic link from \$1 to \$2" >&2
  exit 1
fi

from=$1
to=$2

check_path $from
check_path $to

# Make sure $to points to destination file instead of dir

if [ -d $to ]; then
  to=$to/`basename $from`;
fi

abs_to="$to"
abs_from="$from"

# Remove leading / and replace repeated // into a single /

from=`echo $from | sed -e 's,//*,/,g' -e 's,/,,'`
to=`echo $to | sed -e 's,//*,/,g' -e 's,/,,'`

# Now get rid of the common start.

while compare `echo $from|sed "s,/, ,"` `echo $to|sed "s,/, ,"`
do test a = a
done

# Remove all but the last segment of $to into .. and put the from after this

relf="`echo $to | sed -e 's,[^/][^/]*/,../,g' -e 's,[^/][^/]*$,,'`$from"

rm -f "$abs_to"
# Cygwin specific test to find out if a symlink exists with a .exe suffix.
# Newer ln(1) create symlinks to executables also with a .exe suffix.
[ -s "$abs_to".exe ] && rm -f "$abs_to".exe

# Now, all can be in vain due to other symbolic links.  If this is the case,
# link absolute after all.

if (cd `dirname $abs_to` && test -e $relf); then
   ln -s "$relf" "$abs_to"
else
   echo "`basename $0`: Making abolute link to $abs_from"
   ln -s "$abs_from" "$abs_to"
fi