INIT.2014-12-24
[INIT.git] / bin / mamprobe
blob28d79fecc46fed042a53d14fa32cc27d69e6006f
1 ########################################################################
2 #                                                                      #
3 #               This software is part of the ast package               #
4 #          Copyright (c) 1994-2011 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 ### this script contains archaic constructs that work with all sh variants ###
21 # mamprobe - generate MAM cc probe info
22 # Glenn Fowler <gsf@research.att.com>
24 case $-:$BASH_VERSION in
25 *x*:[0123456789]*)      : bash set -x is broken :; set +ex ;;
26 esac
28 command=mamprobe
30 # check the options
32 opt=
34 case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
35 0123)   USAGE=$'
36 [-?
37 @(#)$Id: mamprobe (AT&T Labs Research) 2011-02-11 $
39 [+NAME?mamprobe - generate MAM cc probe info]
40 [+DESCRIPTION?\bmamprobe\b generates MAM (make abstract machine) \bcc\b(1)
41         probe information for use by \bmamake\b(1). \acc-path\a is the
42         absolute path of the probed compiler and \ainfo-file\a is where
43         the information is placed. \ainfo-file\a is usually
44         \b$INSTALLROOT/lib/probe/C/mam/\b\ahash\a, where \ahash\a is a hash
45         of \acc-path\a. Any \ainfo-file\a directories are created if needed.
46         If \ainfo-file\a is \b-\b then the probe information is written to
47         the standard output.]
48 [+?\bmamprobe\b and \bmamake\b are used in the bootstrap phase of
49         \bpackage\b(1) installation before \bnmake\b(1) is built. The
50         probed variable names are the \bnmake\b(1) names with a \bmam_\b
51         prefix, \bCC\b converted to \bcc\b,  and \b.\b converted to \b_\b.
52         Additional variables are:]{
53                 [+_hosttype_?the \bpackage\b(1) host type]
54                 [+mam_cc_L?\b-L\b\adir\a supported]
55                 [+STDCAT?command to execute for \bcat\b(1); prefixed by
56                         \bexecrate\b(1) on \b.exe\b challenged systems]
57                 [+STDCHMOD?command to execute for \bchmod\b(1); prefixed by
58                         \bexecrate\b(1) on \b.exe\b challenged systems]
59                 [+STDCMP?command to execute for \bcmp\b(1); prefixed by
60                         \bexecrate\b(1) on \b.exe\b challenged systems]
61                 [+STDCP?command to execute for \bcp\b(1); prefixed by
62                         \bexecrate\b(1) on \b.exe\b challenged systems]
63                 [+STDED?command to execute for \bed\b(1) or \bex\b(1)]
64                 [+STDEDFLAGS?flags for \bSTDED\b]
65                 [+STDLN?command to execute for \bln\b(1); prefixed by
66                         \bexecrate\b(1) on \b.exe\b challenged systems]
67                 [+STDMV?command to execute for \bmv\b(1); prefixed by
68                         \bexecrate\b(1) on \b.exe\b challenged systems]
69                 [+STDRM?command to execute for \brm\b(1); prefixed by
70                         \bexecrate\b(1) on \b.exe\b challenged systems]
72 [d:debug?Enable probe script debug trace.]
74 info-file cc-path
76 [+SEE ALSO?\bexecrate\b(1), \bpackage\b(1), \bmamake\b(1), \bnmake\b(1),
77         \bprobe\b(1)]
79         while   getopts -a "$command" "$USAGE" OPT
80         do      case $OPT in
81                 d)      opt=-d ;;
82                 esac
83         done
84         shift `expr $OPTIND - 1`
85         ;;
86 *)      while   :
87         do      case $# in
88                 0)      break ;;
89                 esac
90                 case $1 in
91                 --)     shift
92                         break
93                         ;;
94                 -)      break
95                         ;;
96                 -d)     opt=-d
97                         ;;
98                 -*)     echo $command: $1: unknown option >&2
99                         ;;
100                 *)      break
101                         ;;
102                 esac
103                 set ''
104                 break
105         done
106         ;;
107 esac
109 # check the args
111 case $1 in
112 -)      ;;
113 /*)     ;;
114 *)      set '' ;;
115 esac
116 case $2 in
117 /*)     ;;
118 *)      set '' ;;
119 esac
120 case $# in
121 0|1)    echo "Usage: $command info-file cc-path" >&2; exit 2 ;;
122 esac
123 info=$1
124 shift
125 cc=$*
127 # find the make probe script
129 ifs=${IFS-'
130          '}
131 IFS=:
132 set $PATH
133 IFS=$ifs
134 script=lib/probe/C/make/probe
135 while   :
136 do      case $# in
137         0)      echo "$0: ../$script: probe script not found on PATH" >&2
138                 exit 1
139                 ;;
140         esac
141         case $1 in
142         '')     continue ;;
143         esac
144         makeprobe=`echo $1 | sed 's,[^/]*$,'$script,`
145         if      test -x $makeprobe
146         then    break
147         fi
148         shift
149 done
151 # create the info dir if necessary
153 case $info in
154 /*)     i=X$info
155         ifs=${IFS-'
156          '}
157         IFS=/
158         set $i
159         IFS=$ifs
160         while   :
161         do      i=$1
162                 shift
163                 case $i in
164                 X)      break ;;
165                 esac
166         done
167         case $info in
168         //*)    path=/ ;;
169         *)      path= ;;
170         esac
171         while   :
172         do      case $# in
173                 0|1)    break ;;
174                 esac
175                 comp=$1
176                 shift
177                 case $comp in
178                 '')     continue ;;
179                 esac
180                 path=$path/$comp
181                 if      test ! -d $path
182                 then    mkdir $path || exit
183                 fi
184         done
185         ;;
186 esac
188 # generate info in a tmp file and rename when finished
190 case $info in
191 -)      ;;
192 *)      tmp=/tmp/mam$$
193         trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15
194         exec > $tmp
195         echo "probing C language processor $cc for mam information" >&2
196         ;;
197 esac
199 echo "note generated by $0 for $cc"
202         set '' $opt $cc
203         shift
204         . $makeprobe "$@"
206         case " $CC_DIALECT " in
207         *" -L "*)       echo "CC.L = 1" ;;
208         esac
210 ) | sed \
211         -e '/^CC\./!d' \
212         -e 's/^CC./setv mam_cc_/' \
213         -e 's/^\([^=.]*\)\./\1_/' \
214         -e 's/^\([^=.]*\)\./\1_/' \
215         -e 's/ =//' \
216         -e 's/\$("\([^"]*\)")/\1/g' \
217         -e 's/\$(\([^)]*\))/${\1}/g' \
218         -e 's/\${CC\./${mam_cc_}/g'
220 echo 'setv _hosttype_ ${mam_cc_HOSTTYPE}'
222 # STD* are standard commands/flags with possible execrate(1)
224 if      (
225 ed <<!
228 ) < /dev/null > /dev/null 2>&1
229 then    STDED=ed
230 else    STDED=ex
232 STDEDFLAGS=-
233 set STDCAT cat STDCHMOD chmod STDCMP cmp STDCP cp STDLN ln STDMV mv STDRM rm
234 while   :
235 do      case $# in
236         0|1)    break ;;
237         esac
238         p=$2
239         for d in /bin /usr/bin /usr/sbin
240         do      if      test -x $d/$p
241                 then    p=$d/$p
242                         break
243                 fi
244         done
245         eval $1=\$p
246         shift
247         shift
248 done
249 if      execrate
250 then    for n in STDCAT STDCHMOD STDCMP STDCP STDLN STDMV STDRM
251         do      eval $n=\"execrate \$$n\"
252         done
254 for n in STDCAT STDCHMOD STDCMP STDCP STDED STDEDFLAGS STDLN STDMV STDRM
255 do      eval echo setv \$n \$$n
256 done
258 # all done
260 case $info in
261 -)      ;;
262 *)      exec >/dev/null
263         test -f $info && rm -f $info
264         cp $tmp $info
265         chmod -w $info
266         ;;
267 esac