* elflink.h (elf_link_add_object_symbols): Don't issue a warning
[deliverable/binutils-gdb.git] / install.sh
CommitLineData
bf168768 1#!/bin/sh
bf168768 2#
843115fa
GI
3# install - install a program, script, or datafile
4# This comes from X11R5 (mit/util/scripts/install.sh).
5#
5d95c474
GI
6# Copyright 1991 by the Massachusetts Institute of Technology
7#
8# Permission to use, copy, modify, distribute, and sell this software and its
9# documentation for any purpose is hereby granted without fee, provided that
10# the above copyright notice appear in all copies and that both that
11# copyright notice and this permission notice appear in supporting
12# documentation, and that the name of M.I.T. not be used in advertising or
13# publicity pertaining to distribution of the software without specific,
14# written prior permission. M.I.T. makes no representations about the
15# suitability of this software for any purpose. It is provided "as is"
16# without express or implied warranty.
17#
bf168768
DZ
18# This script is compatible with the BSD install script, but was written
19# from scratch.
20#
21
22
23# set DOITPROG to echo to test this script
24
25# Don't use :- since 4.3BSD and earlier shells don't like it.
26doit="${DOITPROG-}"
27
28
29# put in absolute paths if you don't have them in your path; or use env. vars.
30
31mvprog="${MVPROG-mv}"
32cpprog="${CPPROG-cp}"
33chmodprog="${CHMODPROG-chmod}"
34chownprog="${CHOWNPROG-chown}"
35chgrpprog="${CHGRPPROG-chgrp}"
36stripprog="${STRIPPROG-strip}"
37rmprog="${RMPROG-rm}"
38mkdirprog="${MKDIRPROG-mkdir}"
39
c0914b6e 40transformbasename=""
bf168768
DZ
41transform_arg=""
42instcmd="$mvprog"
98e67c34 43chmodcmd="$chmodprog 0755"
bf168768
DZ
44chowncmd=""
45chgrpcmd=""
46stripcmd=""
47rmcmd="$rmprog -f"
48mvcmd="$mvprog"
49src=""
50dst=""
24170039 51dir_arg=""
bf168768
DZ
52
53while [ x"$1" != x ]; do
54 case $1 in
55 -c) instcmd="$cpprog"
56 shift
57 continue;;
58
24170039
JM
59 -d) dir_arg=true
60 shift
61 continue;;
62
bf168768
DZ
63 -m) chmodcmd="$chmodprog $2"
64 shift
65 shift
66 continue;;
67
68 -o) chowncmd="$chownprog $2"
69 shift
70 shift
71 continue;;
72
73 -g) chgrpcmd="$chgrpprog $2"
74 shift
75 shift
76 continue;;
77
78 -s) stripcmd="$stripprog"
79 shift
80 continue;;
81
82 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
83 shift
84 continue;;
85
86 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
87 shift
88 continue;;
89
90 *) if [ x"$src" = x ]
91 then
92 src=$1
93 else
f0d7cc29
DZ
94 # this colon is to work around a 386BSD /bin/sh bug
95 :
bf168768
DZ
96 dst=$1
97 fi
98 shift
99 continue;;
100 esac
101done
102
103if [ x"$src" = x ]
104then
105 echo "install: no input file specified"
106 exit 1
107else
108 true
109fi
110
24170039
JM
111if [ x"$dir_arg" != x ]; then
112 dst=$src
113 src=""
114
115 if [ -d $dst ]; then
116 instcmd=:
965c73c5 117 chmodcmd=""
24170039
JM
118 else
119 instcmd=mkdir
120 fi
121else
122
731b0720
JK
123# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
124# might cause directories to be created, which would be especially bad
125# if $src (and thus $dsttmp) contains '*'.
126
24170039
JM
127 if [ -f $src -o -d $src ]
128 then
129 true
130 else
131 echo "install: $src does not exist"
132 exit 1
133 fi
134
135 if [ x"$dst" = x ]
136 then
137 echo "install: no destination specified"
138 exit 1
139 else
140 true
141 fi
bf168768
DZ
142
143# If destination is a directory, append the input filename; if your system
144# does not like double slashes in filenames, you may need to add some logic
145
24170039
JM
146 if [ -d $dst ]
147 then
148 dst="$dst"/`basename $src`
149 else
150 true
151 fi
bf168768
DZ
152fi
153
af864713
DZ
154## this sed command emulates the dirname command
155dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
bf168768
DZ
156
157# Make sure that the destination directory exists.
158# this part is taken from Noah Friedman's mkinstalldirs script
159
835578f3
DM
160# Skip lots of stat calls in the usual case.
161if [ ! -d "$dstdir" ]; then
bf168768
DZ
162defaultIFS='
163'
164IFS="${IFS-${defaultIFS}}"
165
166oIFS="${IFS}"
167# Some sh's can't handle IFS=/ for some reason.
168IFS='%'
169set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
170IFS="${oIFS}"
171
172pathcomp=''
173
174while [ $# -ne 0 ] ; do
175 pathcomp="${pathcomp}${1}"
176 shift
177
178 if [ ! -d "${pathcomp}" ] ;
179 then
180 $mkdirprog "${pathcomp}"
181 else
182 true
183 fi
184
185 pathcomp="${pathcomp}/"
186done
835578f3 187fi
bf168768 188
24170039 189if [ x"$dir_arg" != x ]
bf168768 190then
24170039
JM
191 $doit $instcmd $dst &&
192
193 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
194 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
195 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
196 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
bf168768 197else
24170039
JM
198
199# If we're going to rename the final executable, determine the name now.
200
201 if [ x"$transformarg" = x ]
202 then
203 dstfile=`basename $dst`
204 else
205 dstfile=`basename $dst $transformbasename |
206 sed $transformarg`$transformbasename
207 fi
bf168768
DZ
208
209# don't allow the sed command to completely eliminate the filename
210
24170039
JM
211 if [ x"$dstfile" = x ]
212 then
213 dstfile=`basename $dst`
214 else
215 true
216 fi
217
218# Make a temp file name in the proper directory.
219
220 dsttmp=$dstdir/#inst.$$#
bf168768
DZ
221
222# Move or copy the file name to the temp name
223
24170039 224 $doit $instcmd $src $dsttmp &&
731b0720 225
24170039 226 trap "rm -f ${dsttmp}" 0 &&
bf168768
DZ
227
228# and set any options; do chmod last to preserve setuid bits
229
731b0720
JK
230# If any of these fail, we abort the whole thing. If we want to
231# ignore errors from any of these, just make sure not to ignore
232# errors from the above "$doit $instcmd $src $dsttmp" command.
233
24170039
JM
234 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
235 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
236 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
237 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
bf168768
DZ
238
239# Now rename the file to the real destination.
240
24170039
JM
241 $doit $rmcmd -f $dstdir/$dstfile &&
242 $doit $mvcmd $dsttmp $dstdir/$dstfile
243
244fi &&
bf168768
DZ
245
246
247exit 0
This page took 0.138808 seconds and 4 git commands to generate.