1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1989-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 <gsf@research.att.com> # 18# # 19######################################################################## 20: make abstract machine executor with state 21 22# 23# NOTE: variables defined in this script may conflict with mamfile variables 24# 25 26_command_=mamexec 27case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in 280123) ARGV0="-a $_command_" 29 USAGE=$' 30[-? 31@(#)$Id: mamexec (AT&T Labs Research) 1994-04-17 $ 32] 33'$USAGE_LICENSE$' 34[+NAME?mamexec - make abstract machine executor] 35[+DESCRIPTION?\bmamexec\b reads MAM (Make Abstract Machine) target and 36 prerequisite file descriptions from the standard input and executes 37 actions to update targets that are older than their prerequisites. 38 Mamfiles are generated by the \b--mam\b option of \bnmake\b(1) and 39 \bgmake\b(1) and are portable to environments that only have 40 \bsh\b(1) and \bcc\b(1).] 41[+?A separate \bmamstate\b(1) program is used to compare current and state 42 file target times. \bmamexec\b is a \bksh\b(1) script implementation 43 that has been replaced by the standalone \bmamake\b(1). New 44 applications should use \bmamake\b.] 45[d:debug?Set the debug trace level to \alevel\a. Higher levels produce 46 more output.] 47[f:force?Force all targets to be out of date.] 48[i:ignore?Ignore shell action errors.] 49[n!:exec?Enable shell action execution.] 50[s:silent?Do not trace shell actions as they are executed.] 51 52[ target ... ] 53 54[+SEE ALSO?\bmamake\b(1), \bmamstate\b(1), \bnmake\b(1)] 55' 56 ;; 57*) ARGV0="" 58 USAGE="dfins" 59 ;; 60esac 61 62usage() 63{ 64 OPTIND=0 65 getopts $ARGV0 "$USAGE" OPT '-?' 66 exit 2 67} 68 69_debug_=: 70_diff_=. 71_error_='exit 1' 72_exec_=eval 73_force_= 74_list_= 75_same_=. 76_set_= 77_silent_= 78_state_list_=MAMlist 79_state_time_=MAMtime 80_tmp_=/tmp/mam.$$.mam 81 82trap 'rm -f $_tmp_' 0 83trap 'exit 2' 1 2 84 85while getopts $ARGV0 "$USAGE" OPT 86do case $OPT in 87 d) _debug_=$OPT ;; 88 f) _force_=1 ;; 89 i) _error_=: ;; 90 n) _exec_=echo ;; 91 s) _silent_=1 ;; 92 *) usage ;; 93 esac 94done 95 96_select_= 97while : 98do case $# in 99 0) break ;; 100 esac 101 case $1 in 102 *=*) eval $1 103 ;; 104 *) case $_select_ in 105 "") _select_=$1 ;; 106 *) _select_="$_select_|$1" ;; 107 esac 108 ;; 109 esac 110 shift 111done 112case $_select_ in 113"") _select_="*" ;; 114esac 115(set -e; false || true) && _set_=e || echo $_command_: command errors ignored because of shell botch >&2 116case $_silent_ in 117"") _set_=x$_set_ 118 ;; 119*) case $_exec_ in 120 "echo") _exec_=: ;; 121 esac 122 ;; 123esac 124case $_exec_ in 125"eval") _begin_="(" 126 _end_=") </dev/null" 127 case $_set_ in 128 ?*) _set_="set -$_set_;" ;; 129 esac 130 ;; 131*) _set_= 132 ;; 133esac 134 135if test -f $_state_list_ -a -f $_state_time_ 136then mamstate $_state_list_ < $_state_list_ | sort > $_tmp_ 137 for _i_ in `comm -12 $_state_time_ $_tmp_ | sed 's/ .*//'` 138 do case $_same_ in 139 .) _same_=$_i_ ;; 140 *) _same_="$_same_|$_i_" ;; 141 esac 142 done 143fi 144 145_index_=_ 146_match_= 147case `(echo ok | (read -r a; echo $a) 2>/dev/null)` in 148ok) _read_='read -r' 149 ;; 150*) # read strips \ -- thanks a lot 151 # tmp file avoids char at a time read 152 _read_=read 153 sed 's/\\/\\\\/g' > $_tmp_ 154 exec < $_tmp_ 155 rm -f $_tmp_ 156 ;; 157esac 158_old_=1 159_ifs_=$IFS 160while IFS=' '; $_read_ _op_ _arg_ _val_ 161do IFS=$_ifs_ 162 case $_op_ in 163 "note") continue 164 ;; 165 "info") case $_arg_ in 166 "mam") _old_= ;; 167 esac 168 continue 169 ;; 170 "setv") eval _data_='$'$_arg_ 171 case $_index_:$_data_ in 172 __*:*|*:) 173 case $_exec_ in 174 "eval") ;; 175 *) echo "$_arg_=$_val_" ;; 176 esac 177 eval $_arg_="$_val_" "</dev/null" 178 ;; 179 esac 180 case $_arg_:$mam_cc_L in 181 "CC:") ( 182 set - 183 mkdir /tmp/mam$$ 184 cd /tmp/mam$$ 185 echo 'main(){return 0;}' > main.c 186 code=1 187 if $CC -c main.c 2>/dev/null 188 then if $CC -L. main.o -lc 2>/dev/null 189 then $CC -L. main.o -lc > libc.a 2>/dev/null || code=0 190 fi 191 fi 192 cd /tmp 193 rm -rf /tmp/mam$$ 194 exit $code 195 ) </dev/null && mam_cc_L=' ' 196 ;; 197 esac 198 continue 199 ;; 200 "make") eval _name_$_index_=$_name_ 201 eval _prev_$_index_=$_prev_ 202 eval _cmds_$_index_='"$_cmds_"' 203 eval _attr_$_index_=$_attr_ 204 eval _name_=$_arg_ 205 _prev_=$_index_ 206 case " $_val_ " in 207 *" metarule "*) _attr_=m$_attr_ ;; 208 esac 209 _cmds_= 210 eval " case \"$_name_\" in 211 $_select_) 212 case \"$_select_\" in 213 \"*\") _select_=$_name_ ;; 214 esac 215 _match_=1 216 _attr_=x$_attr_ 217 ;; 218 esac" 219 case $_force_ in 220 "") eval " case \"$_name_\" in 221 $_diff_)_attr_=u$_attr_ ;; 222 $_same_);; 223 *) _attr_=u$_attr_ ;; 224 esac" 225 ;; 226 *) _attr_=u$_attr_ 227 ;; 228 esac 229 case $_attr_ in 230 *u*) case $_diff_ in 231 .) _diff_=$_name_ ;; 232 *) _diff_="$_diff_|$_name_" ;; 233 esac 234 ;; 235 esac 236 _index_=_$_index_ 237 eval _name_$_index_=$_name_ 238 eval _prev_$_index_=$_prev_ 239 eval _cmds_$_index_=$_cmds_ 240 eval _attr_$_index_=$_attr_ 241 eval _list_='"'"$_list_"' 242'$_name_'"' 243 continue 244 ;; 245 "prev") case $_force_ in 246 "") eval " case \"$_arg_\" in 247 $_diff_)_attr_=u$_attr_ ;; 248 $_same_) ;; 249 *) _attr_=u$_attr_ ;; 250 esac" 251 ;; 252 *) _attr_=u$_attr_ 253 ;; 254 esac 255 continue 256 ;; 257 esac 258 case $_index_ in 259 _) echo $_op_: missing make op >&2; continue ;; 260 esac 261 case $_op_ in 262 "attr") case $_val_ in 263 "meta"|"suff") _attr_=m$_attr_ ;; 264 esac 265 ;; 266 "exec"|"....") 267 case $_old_ in 268 "") _arg_=$_val_ 269 ;; 270 *) case $_val_ in 271 ?*) _arg_="$_arg_ $_val_" ;; 272 esac 273 ;; 274 esac 275 case $_cmds_ in 276 "") _cmds_=$_arg_ 277 ;; 278 *) _cmds_="$_cmds_ 279$_arg_" 280 ;; 281 esac 282 ;; 283 "done") eval _arg_=$_arg_ 284 _prop_= 285 case $_arg_ in 286 $_name_)case $_attr_ in 287 *m*) ;; 288 *x*u*|*u*x*) 289 case $_cmds_ in 290 "") case $_attr_ in 291 *u*) _prop_=u ;; 292 esac 293 ;; 294 *) $_exec_ "$_begin_$_set_$_cmds_$_end_" || 295 { 296 _code_=$? 297 case $_set_ in 298 *-*e*) ;; 299 *) case $_cmds_ in 300 *if*then*fi*|"||") _code_=0 ;; 301 esac 302 ;; 303 esac 304 case $_code_ in 305 0) ;; 306 *) echo "*** exit code $_code_ making $_name_" >&2 307 $_error_ 308 ;; 309 esac 310 } 311 _prop_=u 312 ;; 313 esac 314 ;; 315 esac 316 _index_=$_prev_ 317 eval _name_='$'_name_$_index_ 318 eval _prev_='$'_prev_$_index_ 319 eval _cmds_='$'_cmds_$_index_ 320 eval _attr_=$_prop_'$'_attr_$_index_ 321 ;; 322 *) echo $_val_: $_op_ $_name_ expected >&2 323 ;; 324 esac 325 ;; 326 esac 327done 328IFS=$_ifs_ 329case $_match_ in 330"") echo "$_command_: don't know how to make $_select_" >&2; $_error_ ;; 331esac 332case $_exec_ in 333"eval") echo "$_list_" > $_state_list_ 334 mamstate $_state_list_ < $_state_list_ | sort > $_state_time_ 335 ;; 336esac 337