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