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