* mips.h (M_ABSU): Removed (absolute value of unsigned number??).
[deliverable/binutils-gdb.git] / install.sh
CommitLineData
bf168768
DZ
1#!/bin/sh
2set -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.
18doit="${DOITPROG-}"
19
20
21# put in absolute paths if you don't have them in your path; or use env. vars.
22
23mvprog="${MVPROG-mv}"
24cpprog="${CPPROG-cp}"
25chmodprog="${CHMODPROG-chmod}"
26chownprog="${CHOWNPROG-chown}"
27chgrpprog="${CHGRPPROG-chgrp}"
28stripprog="${STRIPPROG-strip}"
29rmprog="${RMPROG-rm}"
30mkdirprog="${MKDIRPROG-mkdir}"
31
32tranformbasename=""
33transform_arg=""
34instcmd="$mvprog"
35chmodcmd=""
36chowncmd=""
37chgrpcmd=""
38stripcmd=""
39rmcmd="$rmprog -f"
40mvcmd="$mvprog"
41src=""
42dst=""
43
44while [ 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
f0d7cc29
DZ
81 # this colon is to work around a 386BSD /bin/sh bug
82 :
bf168768
DZ
83 dst=$1
84 fi
85 shift
86 continue;;
87 esac
88done
89
90if [ x"$src" = x ]
91then
92 echo "install: no input file specified"
93 exit 1
94else
95 true
96fi
97
731b0720
JK
98# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
99# might cause directories to be created, which would be especially bad
100# if $src (and thus $dsttmp) contains '*'.
101
102if [ -f $src -o -d $src ]
103then
104 true
105else
106 echo "install: $src does not exist"
107 exit 1
108fi
109
bf168768
DZ
110if [ x"$dst" = x ]
111then
112 echo "install: no destination specified"
113 exit 1
114else
115 true
116fi
117
118# If destination is a directory, append the input filename; if your system
119# does not like double slashes in filenames, you may need to add some logic
120
121if [ -d $dst ]
122then
123 dst="$dst"/`basename $src`
124else
125 true
126fi
127
128
129# Make a temp file name in the proper directory.
130
af864713
DZ
131## this sed command emulates the dirname command
132dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
bf168768
DZ
133dsttmp=$dstdir/#inst.$$#
134
135# Make sure that the destination directory exists.
136# this part is taken from Noah Friedman's mkinstalldirs script
137
138defaultIFS='
139'
140IFS="${IFS-${defaultIFS}}"
141
142oIFS="${IFS}"
143# Some sh's can't handle IFS=/ for some reason.
144IFS='%'
145set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
146IFS="${oIFS}"
147
148pathcomp=''
149
150while [ $# -ne 0 ] ; do
151 pathcomp="${pathcomp}${1}"
152 shift
153
154 if [ ! -d "${pathcomp}" ] ;
155 then
156 $mkdirprog "${pathcomp}"
157 else
158 true
159 fi
160
161 pathcomp="${pathcomp}/"
162done
163
164# If we're going to rename the final executable, determine the name now.
165
166if [ x"$transformarg" = x ]
167then
168 dstfile=`basename $dst`
169else
1a4874f7 170 dstfile=`basename $dst $transformbasename | sed $transformarg`$transformbasename
bf168768
DZ
171fi
172
173# don't allow the sed command to completely eliminate the filename
174
175if [ x"$dstfile" = x ]
176then
177 dstfile=`basename $dst`
178else
179 true
180fi
181
182# Move or copy the file name to the temp name
183
731b0720
JK
184$doit $instcmd $src $dsttmp &&
185
186trap "rm -f ${dsttmp}" 0 &&
bf168768
DZ
187
188# and set any options; do chmod last to preserve setuid bits
189
731b0720
JK
190# If any of these fail, we abort the whole thing. If we want to
191# ignore errors from any of these, just make sure not to ignore
192# errors from the above "$doit $instcmd $src $dsttmp" command.
193
26fac605
DZ
194if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true ; fi &&
195if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true ; fi &&
196if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true ; fi &&
197if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true ; fi &&
bf168768
DZ
198
199# Now rename the file to the real destination.
200
731b0720
JK
201$doit $rmcmd -f $dstdir/$dstfile &&
202$doit $mvcmd $dsttmp $dstdir/$dstfile &&
bf168768
DZ
203
204
205exit 0
This page took 0.038874 seconds and 4 git commands to generate.