OSDN Git Service

testcase for recent unroll.c fix
[pf3gnuchains/gcc-fork.git] / libffi / install-sh
1 #!/bin/sh
2 #
3 # install - install a program, script, or datafile
4 # This comes from X11R5 (mit/util/scripts/install.sh).
5 #
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 #
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.
26 doit="${DOITPROG-}"
27
28
29 # put in absolute paths if you don't have them in your path; or use env. vars.
30
31 mvprog="${MVPROG-mv}"
32 cpprog="${CPPROG-cp}"
33 chmodprog="${CHMODPROG-chmod}"
34 chownprog="${CHOWNPROG-chown}"
35 chgrpprog="${CHGRPPROG-chgrp}"
36 stripprog="${STRIPPROG-strip}"
37 rmprog="${RMPROG-rm}"
38 mkdirprog="${MKDIRPROG-mkdir}"
39
40 transformbasename=""
41 transform_arg=""
42 instcmd="$mvprog"
43 chmodcmd="$chmodprog 0755"
44 chowncmd=""
45 chgrpcmd=""
46 stripcmd=""
47 rmcmd="$rmprog -f"
48 mvcmd="$mvprog"
49 src=""
50 dst=""
51 dir_arg=""
52
53 while [ x"$1" != x ]; do
54     case $1 in
55         -c) instcmd="$cpprog"
56             shift
57             continue;;
58
59         -d) dir_arg=true
60             shift
61             continue;;
62
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
94                 # this colon is to work around a 386BSD /bin/sh bug
95                 :
96                 dst=$1
97             fi
98             shift
99             continue;;
100     esac
101 done
102
103 if [ x"$src" = x ]
104 then
105         echo "install:  no input file specified"
106         exit 1
107 else
108         true
109 fi
110
111 if [ x"$dir_arg" != x ]; then
112         dst=$src
113         src=""
114         
115         if [ -d $dst ]; then
116                 instcmd=:
117         else
118                 instcmd=mkdir
119         fi
120 else
121
122 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
123 # might cause directories to be created, which would be especially bad 
124 # if $src (and thus $dsttmp) contains '*'.
125
126         if [ -f $src -o -d $src ]
127         then
128                 true
129         else
130                 echo "install:  $src does not exist"
131                 exit 1
132         fi
133         
134         if [ x"$dst" = x ]
135         then
136                 echo "install:  no destination specified"
137                 exit 1
138         else
139                 true
140         fi
141
142 # If destination is a directory, append the input filename; if your system
143 # does not like double slashes in filenames, you may need to add some logic
144
145         if [ -d $dst ]
146         then
147                 dst="$dst"/`basename $src`
148         else
149                 true
150         fi
151 fi
152
153 ## this sed command emulates the dirname command
154 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
155
156 # Make sure that the destination directory exists.
157 #  this part is taken from Noah Friedman's mkinstalldirs script
158
159 # Skip lots of stat calls in the usual case.
160 if [ ! -d "$dstdir" ]; then
161 defaultIFS='    
162 '
163 IFS="${IFS-${defaultIFS}}"
164
165 oIFS="${IFS}"
166 # Some sh's can't handle IFS=/ for some reason.
167 IFS='%'
168 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
169 IFS="${oIFS}"
170
171 pathcomp=''
172
173 while [ $# -ne 0 ] ; do
174         pathcomp="${pathcomp}${1}"
175         shift
176
177         if [ ! -d "${pathcomp}" ] ;
178         then
179                 $mkdirprog "${pathcomp}"
180         else
181                 true
182         fi
183
184         pathcomp="${pathcomp}/"
185 done
186 fi
187
188 if [ x"$dir_arg" != x ]
189 then
190         $doit $instcmd $dst &&
191
192         if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
193         if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
194         if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
195         if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
196 else
197
198 # If we're going to rename the final executable, determine the name now.
199
200         if [ x"$transformarg" = x ] 
201         then
202                 dstfile=`basename $dst`
203         else
204                 dstfile=`basename $dst $transformbasename | 
205                         sed $transformarg`$transformbasename
206         fi
207
208 # don't allow the sed command to completely eliminate the filename
209
210         if [ x"$dstfile" = x ] 
211         then
212                 dstfile=`basename $dst`
213         else
214                 true
215         fi
216
217 # Make a temp file name in the proper directory.
218
219         dsttmp=$dstdir/#inst.$$#
220
221 # Move or copy the file name to the temp name
222
223         $doit $instcmd $src $dsttmp &&
224
225         trap "rm -f ${dsttmp}" 0 &&
226
227 # and set any options; do chmod last to preserve setuid bits
228
229 # If any of these fail, we abort the whole thing.  If we want to
230 # ignore errors from any of these, just make sure not to ignore
231 # errors from the above "$doit $instcmd $src $dsttmp" command.
232
233         if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
234         if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
235         if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
236         if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
237
238 # Now rename the file to the real destination.
239
240         $doit $rmcmd -f $dstdir/$dstfile &&
241         $doit $mvcmd $dsttmp $dstdir/$dstfile 
242
243 fi &&
244
245
246 exit 0