append transformbasename to transformed name
[binutils-gdb.git] / install.sh
1 #!/bin/sh
2 set -e
3
4 #
5 # install - install a program, script, or datafile
6 # This comes from X11R5; it is not part of GNU.
7 #
8 # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
9 #
10 # This script is compatible with the BSD install script, but was written
11 # from scratch.
12 #
13
14
15 # set DOITPROG to echo to test this script
16
17 # Don't use :- since 4.3BSD and earlier shells don't like it.
18 doit="${DOITPROG-}"
19
20
21 # put in absolute paths if you don't have them in your path; or use env. vars.
22
23 mvprog="${MVPROG-mv}"
24 cpprog="${CPPROG-cp}"
25 chmodprog="${CHMODPROG-chmod}"
26 chownprog="${CHOWNPROG-chown}"
27 chgrpprog="${CHGRPPROG-chgrp}"
28 stripprog="${STRIPPROG-strip}"
29 rmprog="${RMPROG-rm}"
30 mkdirprog="${MKDIRPROG-mkdir}"
31
32 tranformbasename=""
33 transform_arg=""
34 instcmd="$mvprog"
35 chmodcmd=""
36 chowncmd=""
37 chgrpcmd=""
38 stripcmd=""
39 rmcmd="$rmprog -f"
40 mvcmd="$mvprog"
41 src=""
42 dst=""
43
44 while [ x"$1" != x ]; do
45 case $1 in
46 -c) instcmd="$cpprog"
47 shift
48 continue;;
49
50 -m) chmodcmd="$chmodprog $2"
51 shift
52 shift
53 continue;;
54
55 -o) chowncmd="$chownprog $2"
56 shift
57 shift
58 continue;;
59
60 -g) chgrpcmd="$chgrpprog $2"
61 shift
62 shift
63 continue;;
64
65 -s) stripcmd="$stripprog"
66 shift
67 continue;;
68
69 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
70 shift
71 continue;;
72
73 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
74 shift
75 continue;;
76
77 *) if [ x"$src" = x ]
78 then
79 src=$1
80 else
81 dst=$1
82 fi
83 shift
84 continue;;
85 esac
86 done
87
88 if [ x"$src" = x ]
89 then
90 echo "install: no input file specified"
91 exit 1
92 else
93 true
94 fi
95
96 if [ x"$dst" = x ]
97 then
98 echo "install: no destination specified"
99 exit 1
100 else
101 true
102 fi
103
104 # If destination is a directory, append the input filename; if your system
105 # does not like double slashes in filenames, you may need to add some logic
106
107 if [ -d $dst ]
108 then
109 dst="$dst"/`basename $src`
110 else
111 true
112 fi
113
114
115 # Make a temp file name in the proper directory.
116
117 dstdir=`dirname $dst`
118 dsttmp=$dstdir/#inst.$$#
119
120 # Make sure that the destination directory exists.
121 # this part is taken from Noah Friedman's mkinstalldirs script
122
123 defaultIFS='
124 '
125 IFS="${IFS-${defaultIFS}}"
126
127 oIFS="${IFS}"
128 # Some sh's can't handle IFS=/ for some reason.
129 IFS='%'
130 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
131 IFS="${oIFS}"
132
133 pathcomp=''
134
135 while [ $# -ne 0 ] ; do
136 pathcomp="${pathcomp}${1}"
137 shift
138
139 if [ ! -d "${pathcomp}" ] ;
140 then
141 $mkdirprog "${pathcomp}"
142 else
143 true
144 fi
145
146 pathcomp="${pathcomp}/"
147 done
148
149 # If we're going to rename the final executable, determine the name now.
150
151 if [ x"$transformarg" = x ]
152 then
153 dstfile=`basename $dst`
154 else
155 dstfile=`basename $dst $transformbasename | sed $transformarg`$transformbasename
156 fi
157
158 # don't allow the sed command to completely eliminate the filename
159
160 if [ x"$dstfile" = x ]
161 then
162 dstfile=`basename $dst`
163 else
164 true
165 fi
166
167 # Move or copy the file name to the temp name
168
169 $doit $instcmd $src $dsttmp
170
171 # and set any options; do chmod last to preserve setuid bits
172
173 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
174 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
175 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
176 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
177
178 # Now rename the file to the real destination.
179
180 $doit $rmcmd $dstdir/$dstfile
181 $doit $mvcmd $dsttmp $dstdir/$dstfile
182
183
184 exit 0