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