Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / support / fixlinks
1 #! /bin/sh
2 #
3 # fixlinks - make symlinks in the bash source tree so that there is
4 #            exactly one version of any given source file.
5 #
6 #
7
8 SRCDIR=.
9 while [ $# -gt 0 ]; do
10         case "$1" in
11         -s)     shift; SRCDIR=$1 ;;
12         -u)     unfix=yes ;;
13         -h)     hardlinks=yes ;;
14         -*)     echo "$0: $1: bad option" 1>&2
15                 echo "$0: usage: $0 [-hu] [-s srcdir] [linkmap]" 1>&2
16                 exit 1;;
17         *)      break ;;
18         esac
19         shift
20 done
21
22 if [ ! -d $SRCDIR/builtins ]; then
23         echo "$0: must be run with valid -s argument or from source directory" 1>&2
24         exit 1
25 fi
26
27 if [ $# -eq 0 ]; then
28         linkfile=$SRCDIR/support/SYMLINKS
29 else
30         linkfile=$1     
31 fi
32
33 if [ ! -f "$linkfile" ]; then
34         echo "$0: symlink map file \`$linkfile' does not exist"
35         exit 1
36 fi
37
38 rm -f /tmp/z
39 # if the user specified hard links, then do that.  otherwise, try to use
40 # symlinks if they're present
41 if [ -n "$hardlinks" ]; then
42         LN=ln
43 elif (ln -s /dev/null /tmp/z) >/dev/null 2>&1; then
44         LN="ln -s"
45 else
46         LN=ln
47 fi
48 rm -f /tmp/z
49
50 while read name target
51 do
52         case "$name" in
53         \#*)    continue;;
54         esac
55
56         rm -f $name
57         case "$unfix" in
58         yes)    dirname=`expr "$name" ':' '^\(.*\)/[^/]*'`
59                 [ -z "$dirname" ] && dirname=.
60                 cp $dirname/$target $name
61                 echo $target copied to $name ;;
62         *)      $LN $target $name ; echo "$name -> $target" ;;
63         esac
64
65 done < $linkfile
66
67 exit 0