annotate src/libmad-0.15.1b/install-sh @ 87:dde06ec3df43

Add OS/X 64-bit builds
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Mar 2013 20:33:28 +0000
parents 545efbb81310
children
rev   line source
cannam@85 1 #!/bin/sh
cannam@85 2 #
cannam@85 3 # install - install a program, script, or datafile
cannam@85 4 # This comes from X11R5 (mit/util/scripts/install.sh).
cannam@85 5 #
cannam@85 6 # Copyright 1991 by the Massachusetts Institute of Technology
cannam@85 7 #
cannam@85 8 # Permission to use, copy, modify, distribute, and sell this software and its
cannam@85 9 # documentation for any purpose is hereby granted without fee, provided that
cannam@85 10 # the above copyright notice appear in all copies and that both that
cannam@85 11 # copyright notice and this permission notice appear in supporting
cannam@85 12 # documentation, and that the name of M.I.T. not be used in advertising or
cannam@85 13 # publicity pertaining to distribution of the software without specific,
cannam@85 14 # written prior permission. M.I.T. makes no representations about the
cannam@85 15 # suitability of this software for any purpose. It is provided "as is"
cannam@85 16 # without express or implied warranty.
cannam@85 17 #
cannam@85 18 # Calling this script install-sh is preferred over install.sh, to prevent
cannam@85 19 # `make' implicit rules from creating a file called install from it
cannam@85 20 # when there is no Makefile.
cannam@85 21 #
cannam@85 22 # This script is compatible with the BSD install script, but was written
cannam@85 23 # from scratch. It can only install one file at a time, a restriction
cannam@85 24 # shared with many OS's install programs.
cannam@85 25
cannam@85 26
cannam@85 27 # set DOITPROG to echo to test this script
cannam@85 28
cannam@85 29 # Don't use :- since 4.3BSD and earlier shells don't like it.
cannam@85 30 doit="${DOITPROG-}"
cannam@85 31
cannam@85 32
cannam@85 33 # put in absolute paths if you don't have them in your path; or use env. vars.
cannam@85 34
cannam@85 35 mvprog="${MVPROG-mv}"
cannam@85 36 cpprog="${CPPROG-cp}"
cannam@85 37 chmodprog="${CHMODPROG-chmod}"
cannam@85 38 chownprog="${CHOWNPROG-chown}"
cannam@85 39 chgrpprog="${CHGRPPROG-chgrp}"
cannam@85 40 stripprog="${STRIPPROG-strip}"
cannam@85 41 rmprog="${RMPROG-rm}"
cannam@85 42 mkdirprog="${MKDIRPROG-mkdir}"
cannam@85 43
cannam@85 44 transformbasename=""
cannam@85 45 transform_arg=""
cannam@85 46 instcmd="$mvprog"
cannam@85 47 chmodcmd="$chmodprog 0755"
cannam@85 48 chowncmd=""
cannam@85 49 chgrpcmd=""
cannam@85 50 stripcmd=""
cannam@85 51 rmcmd="$rmprog -f"
cannam@85 52 mvcmd="$mvprog"
cannam@85 53 src=""
cannam@85 54 dst=""
cannam@85 55 dir_arg=""
cannam@85 56
cannam@85 57 while [ x"$1" != x ]; do
cannam@85 58 case $1 in
cannam@85 59 -c) instcmd=$cpprog
cannam@85 60 shift
cannam@85 61 continue;;
cannam@85 62
cannam@85 63 -d) dir_arg=true
cannam@85 64 shift
cannam@85 65 continue;;
cannam@85 66
cannam@85 67 -m) chmodcmd="$chmodprog $2"
cannam@85 68 shift
cannam@85 69 shift
cannam@85 70 continue;;
cannam@85 71
cannam@85 72 -o) chowncmd="$chownprog $2"
cannam@85 73 shift
cannam@85 74 shift
cannam@85 75 continue;;
cannam@85 76
cannam@85 77 -g) chgrpcmd="$chgrpprog $2"
cannam@85 78 shift
cannam@85 79 shift
cannam@85 80 continue;;
cannam@85 81
cannam@85 82 -s) stripcmd=$stripprog
cannam@85 83 shift
cannam@85 84 continue;;
cannam@85 85
cannam@85 86 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
cannam@85 87 shift
cannam@85 88 continue;;
cannam@85 89
cannam@85 90 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
cannam@85 91 shift
cannam@85 92 continue;;
cannam@85 93
cannam@85 94 *) if [ x"$src" = x ]
cannam@85 95 then
cannam@85 96 src=$1
cannam@85 97 else
cannam@85 98 # this colon is to work around a 386BSD /bin/sh bug
cannam@85 99 :
cannam@85 100 dst=$1
cannam@85 101 fi
cannam@85 102 shift
cannam@85 103 continue;;
cannam@85 104 esac
cannam@85 105 done
cannam@85 106
cannam@85 107 if [ x"$src" = x ]
cannam@85 108 then
cannam@85 109 echo "$0: no input file specified" >&2
cannam@85 110 exit 1
cannam@85 111 else
cannam@85 112 :
cannam@85 113 fi
cannam@85 114
cannam@85 115 if [ x"$dir_arg" != x ]; then
cannam@85 116 dst=$src
cannam@85 117 src=""
cannam@85 118
cannam@85 119 if [ -d "$dst" ]; then
cannam@85 120 instcmd=:
cannam@85 121 chmodcmd=""
cannam@85 122 else
cannam@85 123 instcmd=$mkdirprog
cannam@85 124 fi
cannam@85 125 else
cannam@85 126
cannam@85 127 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
cannam@85 128 # might cause directories to be created, which would be especially bad
cannam@85 129 # if $src (and thus $dsttmp) contains '*'.
cannam@85 130
cannam@85 131 if [ -f "$src" ] || [ -d "$src" ]
cannam@85 132 then
cannam@85 133 :
cannam@85 134 else
cannam@85 135 echo "$0: $src does not exist" >&2
cannam@85 136 exit 1
cannam@85 137 fi
cannam@85 138
cannam@85 139 if [ x"$dst" = x ]
cannam@85 140 then
cannam@85 141 echo "$0: no destination specified" >&2
cannam@85 142 exit 1
cannam@85 143 else
cannam@85 144 :
cannam@85 145 fi
cannam@85 146
cannam@85 147 # If destination is a directory, append the input filename; if your system
cannam@85 148 # does not like double slashes in filenames, you may need to add some logic
cannam@85 149
cannam@85 150 if [ -d "$dst" ]
cannam@85 151 then
cannam@85 152 dst=$dst/`basename "$src"`
cannam@85 153 else
cannam@85 154 :
cannam@85 155 fi
cannam@85 156 fi
cannam@85 157
cannam@85 158 ## this sed command emulates the dirname command
cannam@85 159 dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
cannam@85 160
cannam@85 161 # Make sure that the destination directory exists.
cannam@85 162 # this part is taken from Noah Friedman's mkinstalldirs script
cannam@85 163
cannam@85 164 # Skip lots of stat calls in the usual case.
cannam@85 165 if [ ! -d "$dstdir" ]; then
cannam@85 166 defaultIFS='
cannam@85 167 '
cannam@85 168 IFS="${IFS-$defaultIFS}"
cannam@85 169
cannam@85 170 oIFS=$IFS
cannam@85 171 # Some sh's can't handle IFS=/ for some reason.
cannam@85 172 IFS='%'
cannam@85 173 set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
cannam@85 174 IFS=$oIFS
cannam@85 175
cannam@85 176 pathcomp=''
cannam@85 177
cannam@85 178 while [ $# -ne 0 ] ; do
cannam@85 179 pathcomp=$pathcomp$1
cannam@85 180 shift
cannam@85 181
cannam@85 182 if [ ! -d "$pathcomp" ] ;
cannam@85 183 then
cannam@85 184 $mkdirprog "$pathcomp"
cannam@85 185 else
cannam@85 186 :
cannam@85 187 fi
cannam@85 188
cannam@85 189 pathcomp=$pathcomp/
cannam@85 190 done
cannam@85 191 fi
cannam@85 192
cannam@85 193 if [ x"$dir_arg" != x ]
cannam@85 194 then
cannam@85 195 $doit $instcmd "$dst" &&
cannam@85 196
cannam@85 197 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
cannam@85 198 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
cannam@85 199 if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
cannam@85 200 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
cannam@85 201 else
cannam@85 202
cannam@85 203 # If we're going to rename the final executable, determine the name now.
cannam@85 204
cannam@85 205 if [ x"$transformarg" = x ]
cannam@85 206 then
cannam@85 207 dstfile=`basename "$dst"`
cannam@85 208 else
cannam@85 209 dstfile=`basename "$dst" $transformbasename |
cannam@85 210 sed $transformarg`$transformbasename
cannam@85 211 fi
cannam@85 212
cannam@85 213 # don't allow the sed command to completely eliminate the filename
cannam@85 214
cannam@85 215 if [ x"$dstfile" = x ]
cannam@85 216 then
cannam@85 217 dstfile=`basename "$dst"`
cannam@85 218 else
cannam@85 219 :
cannam@85 220 fi
cannam@85 221
cannam@85 222 # Make a couple of temp file names in the proper directory.
cannam@85 223
cannam@85 224 dsttmp=$dstdir/#inst.$$#
cannam@85 225 rmtmp=$dstdir/#rm.$$#
cannam@85 226
cannam@85 227 # Trap to clean up temp files at exit.
cannam@85 228
cannam@85 229 trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
cannam@85 230 trap '(exit $?); exit' 1 2 13 15
cannam@85 231
cannam@85 232 # Move or copy the file name to the temp name
cannam@85 233
cannam@85 234 $doit $instcmd "$src" "$dsttmp" &&
cannam@85 235
cannam@85 236 # and set any options; do chmod last to preserve setuid bits
cannam@85 237
cannam@85 238 # If any of these fail, we abort the whole thing. If we want to
cannam@85 239 # ignore errors from any of these, just make sure not to ignore
cannam@85 240 # errors from the above "$doit $instcmd $src $dsttmp" command.
cannam@85 241
cannam@85 242 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
cannam@85 243 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
cannam@85 244 if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
cannam@85 245 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
cannam@85 246
cannam@85 247 # Now remove or move aside any old file at destination location. We try this
cannam@85 248 # two ways since rm can't unlink itself on some systems and the destination
cannam@85 249 # file might be busy for other reasons. In this case, the final cleanup
cannam@85 250 # might fail but the new file should still install successfully.
cannam@85 251
cannam@85 252 {
cannam@85 253 if [ -f "$dstdir/$dstfile" ]
cannam@85 254 then
cannam@85 255 $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
cannam@85 256 $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
cannam@85 257 {
cannam@85 258 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
cannam@85 259 (exit 1); exit
cannam@85 260 }
cannam@85 261 else
cannam@85 262 :
cannam@85 263 fi
cannam@85 264 } &&
cannam@85 265
cannam@85 266 # Now rename the file to the real destination.
cannam@85 267
cannam@85 268 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
cannam@85 269
cannam@85 270 fi &&
cannam@85 271
cannam@85 272 # The final little trick to "correctly" pass the exit status to the exit trap.
cannam@85 273
cannam@85 274 {
cannam@85 275 (exit 0); exit
cannam@85 276 }