INIT.2014-12-24
[INIT.git] / src / cmd / INIT / mamprobe.sh
blobea8c5be6dfa505924d421ec1c1f6228d23af9bd4
1 ########################################################################
2 # #
3 # This software is part of the ast package #
4 # Copyright (c) 1994-2016 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Eclipse Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
8 # #
9 # A copy of the License is available at #
10 # http://www.eclipse.org/org/documents/epl-v10.html #
11 # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12 # #
13 # Information and Software Systems Research #
14 # AT&T Research #
15 # Florham Park NJ #
16 # #
17 # Glenn Fowler <glenn.s.fowler@gmail.com> #
18 # #
19 ########################################################################
20 ########################################################################
21 # #
22 # This software is part of the ast package #
23 # Copyright (c) 1994-2011 AT&T Intellectual Property #
24 # and is licensed under the #
25 # Eclipse Public License, Version 1.0 #
26 # by AT&T Intellectual Property #
27 # #
28 # A copy of the License is available at #
29 # http://www.eclipse.org/org/documents/epl-v10.html #
30 # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
31 # #
32 # Information and Software Systems Research #
33 # AT&T Research #
34 # Florham Park NJ #
35 # #
36 # Glenn Fowler <glenn.s.fowler@gmail.com> #
37 # #
38 ########################################################################
39 ### this script contains archaic constructs that work with all sh variants ###
40 # mamprobe - generate MAM cc probe info
41 # Glenn Fowler <gsf@research.att.com>
43 case $-:$BASH_VERSION in
44 *x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
45 esac
47 command=mamprobe
49 # check the options
51 opt=
53 case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
54 0123) USAGE=$'
55 [-?
56 @(#)$Id: mamprobe (AT&T Labs Research) 2011-02-11 $
58 [+NAME?mamprobe - generate MAM cc probe info]
59 [+DESCRIPTION?\bmamprobe\b generates MAM (make abstract machine) \bcc\b(1)
60 probe information for use by \bmamake\b(1). \acc-path\a is the
61 absolute path of the probed compiler and \ainfo-file\a is where
62 the information is placed. \ainfo-file\a is usually
63 \b$INSTALLROOT/lib/probe/C/mam/\b\ahash\a, where \ahash\a is a hash
64 of \acc-path\a. Any \ainfo-file\a directories are created if needed.
65 If \ainfo-file\a is \b-\b then the probe information is written to
66 the standard output.]
67 [+?\bmamprobe\b and \bmamake\b are used in the bootstrap phase of
68 \bpackage\b(1) installation before \bnmake\b(1) is built. The
69 probed variable names are the \bnmake\b(1) names with a \bmam_\b
70 prefix, \bCC\b converted to \bcc\b, and \b.\b converted to \b_\b.
71 Additional variables are:]{
72 [+_hosttype_?the \bpackage\b(1) host type]
73 [+mam_cc_L?\b-L\b\adir\a supported]
74 [+STDCAT?command to execute for \bcat\b(1); prefixed by
75 \bexecrate\b(1) on \b.exe\b challenged systems]
76 [+STDCHMOD?command to execute for \bchmod\b(1); prefixed by
77 \bexecrate\b(1) on \b.exe\b challenged systems]
78 [+STDCMP?command to execute for \bcmp\b(1); prefixed by
79 \bexecrate\b(1) on \b.exe\b challenged systems]
80 [+STDCP?command to execute for \bcp\b(1); prefixed by
81 \bexecrate\b(1) on \b.exe\b challenged systems]
82 [+STDED?command to execute for \bed\b(1) or \bex\b(1)]
83 [+STDEDFLAGS?flags for \bSTDED\b]
84 [+STDLN?command to execute for \bln\b(1); prefixed by
85 \bexecrate\b(1) on \b.exe\b challenged systems]
86 [+STDMV?command to execute for \bmv\b(1); prefixed by
87 \bexecrate\b(1) on \b.exe\b challenged systems]
88 [+STDRM?command to execute for \brm\b(1); prefixed by
89 \bexecrate\b(1) on \b.exe\b challenged systems]
91 [d:debug?Enable probe script debug trace.]
93 info-file cc-path
95 [+SEE ALSO?\bexecrate\b(1), \bpackage\b(1), \bmamake\b(1), \bnmake\b(1),
96 \bprobe\b(1)]
98 while getopts -a "$command" "$USAGE" OPT
99 do case $OPT in
100 d) opt=-d ;;
101 esac
102 done
103 shift `expr $OPTIND - 1`
105 *) while :
106 do case $# in
107 0) break ;;
108 esac
109 case $1 in
110 --) shift
111 break
113 -) break
115 -d) opt=-d
117 -*) echo $command: $1: unknown option >&2
119 *) break
121 esac
122 set ''
123 break
124 done
126 esac
128 # check the args
130 case $1 in
131 -) ;;
132 /*) ;;
133 *) set '' ;;
134 esac
135 case $2 in
136 /*) ;;
137 *) set '' ;;
138 esac
139 case $# in
140 0|1) echo "Usage: $command info-file cc-path" >&2; exit 2 ;;
141 esac
142 info=$1
143 shift
144 cc=$*
146 # find the make probe script
148 ifs=${IFS-'
150 IFS=:
151 set $PATH
152 IFS=$ifs
153 script=lib/probe/C/make/probe
154 while :
155 do case $# in
156 0) echo "$0: ../$script: probe script not found on PATH" >&2
157 exit 1
159 esac
160 case $1 in
161 '') continue ;;
162 esac
163 makeprobe=`echo $1 | sed 's,[^/]*$,'$script,`
164 if test -x $makeprobe
165 then break
167 shift
168 done
170 # create the info dir if necessary
172 case $info in
173 /*) i=X$info
174 ifs=${IFS-'
176 IFS=/
177 set $i
178 IFS=$ifs
179 while :
180 do i=$1
181 shift
182 case $i in
183 X) break ;;
184 esac
185 done
186 case $info in
187 //*) path=/ ;;
188 *) path= ;;
189 esac
190 while :
191 do case $# in
192 0|1) break ;;
193 esac
194 comp=$1
195 shift
196 case $comp in
197 '') continue ;;
198 esac
199 path=$path/$comp
200 if test ! -d $path
201 then mkdir $path || exit
203 done
205 esac
207 # generate info in a tmp file and rename when finished
209 case $info in
210 -) ;;
211 *) tmp=/tmp/mam$$
212 trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15
213 exec > $tmp
214 echo "probing C language processor $cc for mam information" >&2
216 esac
218 echo "note generated by $0 for $cc"
221 set '' $opt $cc
222 shift
223 . $makeprobe "$@"
225 case " $CC_DIALECT " in
226 *" -L "*) echo "CC.L = 1" ;;
227 esac
229 ) | sed \
230 -e '/^CC\./!d' \
231 -e 's/^CC./setv mam_cc_/' \
232 -e 's/^\([^=.]*\)\./\1_/' \
233 -e 's/^\([^=.]*\)\./\1_/' \
234 -e 's/ =//' \
235 -e 's/\$("\([^"]*\)")/\1/g' \
236 -e 's/\$(\([^)]*\))/${\1}/g' \
237 -e 's/\${CC\./${mam_cc_}/g'
239 echo 'setv _hosttype_ ${mam_cc_HOSTTYPE}'
241 # STD* are standard commands/flags with possible execrate(1)
243 if (
244 ed <<!
247 ) < /dev/null > /dev/null 2>&1
248 then STDED=ed
249 else STDED=ex
251 STDEDFLAGS=-
252 set STDCAT cat STDCHMOD chmod STDCMP cmp STDCP cp STDLN ln STDMV mv STDRM rm
253 while :
254 do case $# in
255 0|1) break ;;
256 esac
257 p=$2
258 for d in /bin /usr/bin /usr/sbin
259 do if test -x $d/$p
260 then p=$d/$p
261 break
263 done
264 eval $1=\$p
265 shift
266 shift
267 done
268 if execrate
269 then for n in STDCAT STDCHMOD STDCMP STDCP STDLN STDMV STDRM
270 do eval $n=\"execrate \$$n\"
271 done
273 for n in STDCAT STDCHMOD STDCMP STDCP STDED STDEDFLAGS STDLN STDMV STDRM
274 do eval echo setv \$n \$$n
275 done
277 # all done
279 case $info in
280 -) ;;
281 *) exec >/dev/null
282 test -f $info && rm -f $info
283 cp $tmp $info
284 chmod -w $info
286 esac