root/tags/gdal_1_3_2/install-sh

Revision 2338, 5.6 kB (checked in by warmerda, 7 years ago)

added cygwin hack to install .exe files

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