summaryrefslogtreecommitdiffstats
path: root/install-sh
diff options
context:
space:
mode:
authorNathanael Nerode <neroden@gcc.gnu.org>2004-02-20 02:01:16 +0000
committerNathanael Nerode <neroden@gcc.gnu.org>2004-02-20 02:01:16 +0000
commit515927826cae27557f9f381dc012203549659b48 (patch)
treecc6b1eecf6b3d385bc2b0d4e08fb6843091e2841 /install-sh
parent* Makefile.direct, alloc.c: Resync to upstream 6.3 alpha 1. (diff)
downloadgcc-515927826cae27557f9f381dc012203549659b48.tar.gz
gcc-515927826cae27557f9f381dc012203549659b48.tar.bz2
gcc-515927826cae27557f9f381dc012203549659b48.tar.xz
re PR bootstrap/11932 (Parallel bootstrap failure with sparc libiberty multilib)
PR bootstrap/11932 * mkinstalldirs, install-sh: Import from automake CVS HEAD. From-SVN: r78143
Diffstat (limited to 'install-sh')
-rwxr-xr-xinstall-sh468
1 files changed, 245 insertions, 223 deletions
diff --git a/install-sh b/install-sh
index 0ec27bcd488..77bc38144f2 100755
--- a/install-sh
+++ b/install-sh
@@ -1,7 +1,8 @@
1#!/bin/sh 1#!/bin/sh
2#
3# install - install a program, script, or datafile 2# install - install a program, script, or datafile
4# 3
4scriptversion=2004-02-15.20
5
5# This originates from X11R5 (mit/util/scripts/install.sh), which was 6# This originates from X11R5 (mit/util/scripts/install.sh), which was
6# later released in X11R6 (xc/config/util/install.sh) with the 7# later released in X11R6 (xc/config/util/install.sh) with the
7# following copyright and license. 8# following copyright and license.
@@ -41,13 +42,11 @@
41# from scratch. It can only install one file at a time, a restriction 42# from scratch. It can only install one file at a time, a restriction
42# shared with many OS's install programs. 43# shared with many OS's install programs.
43 44
44
45# set DOITPROG to echo to test this script 45# set DOITPROG to echo to test this script
46 46
47# Don't use :- since 4.3BSD and earlier shells don't like it. 47# Don't use :- since 4.3BSD and earlier shells don't like it.
48doit="${DOITPROG-}" 48doit="${DOITPROG-}"
49 49
50
51# put in absolute paths if you don't have them in your path; or use env. vars. 50# put in absolute paths if you don't have them in your path; or use env. vars.
52 51
53mvprog="${MVPROG-mv}" 52mvprog="${MVPROG-mv}"
@@ -59,236 +58,259 @@ stripprog="${STRIPPROG-strip}"
59rmprog="${RMPROG-rm}" 58rmprog="${RMPROG-rm}"
60mkdirprog="${MKDIRPROG-mkdir}" 59mkdirprog="${MKDIRPROG-mkdir}"
61 60
62transformbasename="" 61transformbasename=
63transform_arg="" 62transform_arg=
64instcmd="$mvprog" 63instcmd="$mvprog"
65chmodcmd="$chmodprog 0755" 64chmodcmd="$chmodprog 0755"
66chowncmd="" 65chowncmd=
67chgrpcmd="" 66chgrpcmd=
68stripcmd="" 67stripcmd=
69rmcmd="$rmprog -f" 68rmcmd="$rmprog -f"
70mvcmd="$mvprog" 69mvcmd="$mvprog"
71src="" 70src=
72dst="" 71dst=
73dir_arg="" 72dir_arg=
74 73
75while [ x"$1" != x ]; do 74usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
76 case $1 in 75 or: $0 [OPTION]... SRCFILES... DIRECTORY
77 -c) instcmd=$cpprog 76 or: $0 -d DIRECTORIES...
78 shift 77
79 continue;; 78In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
80 79In the second, create the directory path DIR.
81 -d) dir_arg=true 80
82 shift 81Options:
83 continue;; 82-b=TRANSFORMBASENAME
84 83-c copy source (using $cpprog) instead of moving (using $mvprog).
85 -m) chmodcmd="$chmodprog $2" 84-d create directories instead of installing files.
86 shift 85-g GROUP $chgrp installed files to GROUP.
87 shift 86-m MODE $chmod installed files to MODE.
88 continue;; 87-o USER $chown installed files to USER.
89 88-s strip installed files (using $stripprog).
90 -o) chowncmd="$chownprog $2" 89-t=TRANSFORM
91 shift 90--help display this help and exit.
92 shift 91--version display version info and exit.
93 continue;; 92
94 93Environment variables override the default commands:
95 -g) chgrpcmd="$chgrpprog $2" 94 CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
96 shift 95"
97 shift 96
98 continue;; 97while test -n "$1"; do
99 98 case $1 in
100 -s) stripcmd=$stripprog 99 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
101 shift 100 shift
102 continue;; 101 continue;;
103 102
104 -t=*) transformarg=`echo $1 | sed 's/-t=//'` 103 -c) instcmd=$cpprog
105 shift 104 shift
106 continue;; 105 continue;;
107 106
108 -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 107 -d) dir_arg=true
109 shift 108 shift
110 continue;; 109 continue;;
111 110
112 *) if [ x"$src" = x ] 111 -g) chgrpcmd="$chgrpprog $2"
113 then 112 shift
114 src=$1 113 shift
115 else 114 continue;;
116 # this colon is to work around a 386BSD /bin/sh bug 115
117 : 116 --help) echo "$usage"; exit 0;;
118 dst=$1 117
119 fi 118 -m) chmodcmd="$chmodprog $2"
120 shift 119 shift
121 continue;; 120 shift
122 esac 121 continue;;
122
123 -o) chowncmd="$chownprog $2"
124 shift
125 shift
126 continue;;
127
128 -s) stripcmd=$stripprog
129 shift
130 continue;;
131
132 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
133 shift
134 continue;;
135
136 --version) echo "$0 $scriptversion"; exit 0;;
137
138 *) # When -d is used, all remaining arguments are directories to create.
139 test -n "$dir_arg" && break
140 # Otherwise, the last argument is the destination. Remove it from $@.
141 for arg
142 do
143 if test -n "$dstarg"; then
144 # $@ is not empty: it contains at least $arg.
145 set fnord "$@" "$dstarg"
146 shift # fnord
147 fi
148 shift # arg
149 dstarg=$arg
150 done
151 break;;
152 esac
123done 153done
124 154
125if [ x"$src" = x ] 155if test -z "$1"; then
126then 156 if test -z "$dir_arg"; then
127 echo "$0: no input file specified" >&2 157 echo "$0: no input file specified." >&2
128 exit 1 158 exit 1
129else 159 fi
130 : 160 # It's OK to call `install-sh -d' without argument.
161 # This can happen when creating conditional directories.
162 exit 0
131fi 163fi
132 164
133if [ x"$dir_arg" != x ]; then 165for src
134 dst=$src 166do
135 src="" 167 # Protect names starting with `-'.
136 168 case $src in
137 if [ -d "$dst" ]; then 169 -*) src=./$src ;;
138 instcmd=: 170 esac
139 chmodcmd="" 171
140 else 172 if test -n "$dir_arg"; then
141 instcmd=$mkdirprog 173 dst=$src
142 fi 174 src=
143else 175
144 176 if test -d "$dst"; then
145# Waiting for this to be detected by the "$instcmd $src $dsttmp" command 177 instcmd=:
146# might cause directories to be created, which would be especially bad 178 chmodcmd=
147# if $src (and thus $dsttmp) contains '*'. 179 else
148 180 instcmd=$mkdirprog
149 if [ -f "$src" ] || [ -d "$src" ] 181 fi
150 then 182 else
151 : 183 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
152 else 184 # might cause directories to be created, which would be especially bad
153 echo "$0: $src does not exist" >&2 185 # if $src (and thus $dsttmp) contains '*'.
154 exit 1 186 if test ! -f "$src" && test ! -d "$src"; then
155 fi 187 echo "$0: $src does not exist." >&2
156 188 exit 1
157 if [ x"$dst" = x ] 189 fi
158 then 190
159 echo "$0: no destination specified" >&2 191 if test -z "$dstarg"; then
160 exit 1 192 echo "$0: no destination specified." >&2
161 else 193 exit 1
162 : 194 fi
163 fi 195
164 196 dst=$dstarg
165# If destination is a directory, append the input filename; if your system 197 # Protect names starting with `-'.
166# does not like double slashes in filenames, you may need to add some logic 198 case $dst in
167 199 -*) dst=./$dst ;;
168 if [ -d "$dst" ] 200 esac
169 then
170 dst=$dst/`basename "$src"`
171 else
172 :
173 fi
174fi
175
176## this sed command emulates the dirname command
177dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
178
179# Make sure that the destination directory exists.
180# this part is taken from Noah Friedman's mkinstalldirs script
181
182# Skip lots of stat calls in the usual case.
183if [ ! -d "$dstdir" ]; then
184defaultIFS='
185 '
186IFS="${IFS-$defaultIFS}"
187
188oIFS=$IFS
189# Some sh's can't handle IFS=/ for some reason.
190IFS='%'
191set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
192IFS=$oIFS
193
194pathcomp=''
195
196while [ $# -ne 0 ] ; do
197 pathcomp=$pathcomp$1
198 shift
199
200 if [ ! -d "$pathcomp" ] ;
201 then
202 $mkdirprog "$pathcomp"
203 else
204 :
205 fi
206 201
207 pathcomp=$pathcomp/ 202 # If destination is a directory, append the input filename; won't work
203 # if double slashes aren't ignored.
204 if test -d "$dst"; then
205 dst=$dst/`basename "$src"`
206 fi
207 fi
208
209 # This sed command emulates the dirname command.
210 dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
211
212 # Make sure that the destination directory exists.
213
214 # Skip lots of stat calls in the usual case.
215 if test ! -d "$dstdir"; then
216 defaultIFS='
217 '
218 IFS="${IFS-$defaultIFS}"
219
220 oIFS=$IFS
221 # Some sh's can't handle IFS=/ for some reason.
222 IFS='%'
223 set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
224 IFS=$oIFS
225
226 pathcomp=
227
228 while test $# -ne 0 ; do
229 pathcomp=$pathcomp$1
230 shift
231 if test ! -d "$pathcomp"; then
232 $mkdirprog "$pathcomp" || lasterr=$?
233 # mkdir can fail with a `File exist' error in case several
234 # install-sh are creating the directory concurrently. This
235 # is OK.
236 test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
237 fi
238 pathcomp=$pathcomp/
239 done
240 fi
241
242 if test -n "$dir_arg"; then
243 $doit $instcmd "$dst" \
244 && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
245 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
246 && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
247 && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
248
249 else
250 # If we're going to rename the final executable, determine the name now.
251 if test -z "$transformarg"; then
252 dstfile=`basename "$dst"`
253 else
254 dstfile=`basename "$dst" $transformbasename \
255 | sed $transformarg`$transformbasename
256 fi
257
258 # don't allow the sed command to completely eliminate the filename.
259 test -z "$dstfile" && dstfile=`basename "$dst"`
260
261 # Make a couple of temp file names in the proper directory.
262 dsttmp=$dstdir/_inst.$$_
263 rmtmp=$dstdir/_rm.$$_
264
265 # Trap to clean up those temp files at exit.
266 trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
267 trap '(exit $?); exit' 1 2 13 15
268
269 # Move or copy the file name to the temp name
270 $doit $instcmd "$src" "$dsttmp" &&
271
272 # and set any options; do chmod last to preserve setuid bits.
273 #
274 # If any of these fail, we abort the whole thing. If we want to
275 # ignore errors from any of these, just make sure not to ignore
276 # errors from the above "$doit $instcmd $src $dsttmp" command.
277 #
278 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
279 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
280 && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
281 && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
282
283 # Now remove or move aside any old file at destination location. We
284 # try this two ways since rm can't unlink itself on some systems and
285 # the destination file might be busy for other reasons. In this case,
286 # the final cleanup might fail but the new file should still install
287 # successfully.
288 {
289 if test -f "$dstdir/$dstfile"; then
290 $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
291 || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
292 || {
293 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
294 (exit 1); exit
295 }
296 else
297 :
298 fi
299 } &&
300
301 # Now rename the file to the real destination.
302 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
303 fi || { (exit 1); exit; }
208done 304done
209fi
210
211if [ x"$dir_arg" != x ]
212then
213 $doit $instcmd "$dst" &&
214
215 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
216 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
217 if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
218 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
219else
220
221# If we're going to rename the final executable, determine the name now.
222
223 if [ x"$transformarg" = x ]
224 then
225 dstfile=`basename "$dst"`
226 else
227 dstfile=`basename "$dst" $transformbasename |
228 sed $transformarg`$transformbasename
229 fi
230
231# don't allow the sed command to completely eliminate the filename
232
233 if [ x"$dstfile" = x ]
234 then
235 dstfile=`basename "$dst"`
236 else
237 :
238 fi
239
240# Make a couple of temp file names in the proper directory.
241
242 dsttmp=$dstdir/#inst.$$#
243 rmtmp=$dstdir/#rm.$$#
244
245# Trap to clean up temp files at exit.
246
247 trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
248 trap '(exit $?); exit' 1 2 13 15
249
250# Move or copy the file name to the temp name
251
252 $doit $instcmd "$src" "$dsttmp" &&
253
254# and set any options; do chmod last to preserve setuid bits
255
256# If any of these fail, we abort the whole thing. If we want to
257# ignore errors from any of these, just make sure not to ignore
258# errors from the above "$doit $instcmd $src $dsttmp" command.
259
260 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
261 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
262 if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
263 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
264
265# Now remove or move aside any old file at destination location. We try this
266# two ways since rm can't unlink itself on some systems and the destination
267# file might be busy for other reasons. In this case, the final cleanup
268# might fail but the new file should still install successfully.
269
270{
271 if [ -f "$dstdir/$dstfile" ]
272 then
273 $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
274 $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
275 {
276 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
277 (exit 1); exit
278 }
279 else
280 :
281 fi
282} &&
283
284# Now rename the file to the real destination.
285
286 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
287
288fi &&
289 305
290# The final little trick to "correctly" pass the exit status to the exit trap. 306# The final little trick to "correctly" pass the exit status to the exit trap.
291
292{ 307{
293 (exit 0); exit 308 (exit 0); exit
294} 309}
310
311# Local variables:
312# eval: (add-hook 'write-file-hooks 'time-stamp)
313# time-stamp-start: "scriptversion="
314# time-stamp-format: "%:y-%02m-%02d.%02H"
315# time-stamp-end: "$"
316# End: