xref: /illumos-gate/usr/src/contrib/ast/src/cmd/ksh93/mamexec (revision 8226594fdd4479be135127f43632f1f995074654)
1:
2#
3# Glenn Fowler
4# AT&T Bell Laboratories
5#
6# make abstract machine executor with state
7#
8# @(#)mamexec (gsf@research.att.com) 07/17/94
9#
10# mamexec [ -dfins ] [ target ... ] < mam-file
11#
12# NOTE: variables defined in this script may conflict with
13#	mam-file variables
14#
15
16_command_=mamexec
17_debug_=:
18_diff_=.
19_error_='exit 1'
20_exec_=eval
21_force_=
22_list_=
23_same_=.
24_set_=
25_silent_=
26_state_list_=MAMlist
27_state_time_=MAMtime
28_tmp_=/tmp/mam.$$.mam
29
30trap 'rm -f $_tmp_' 0
31trap 'exit 2' 1 2
32while	:
33do	case $# in
34	0)	break ;;
35	esac
36	case $1 in
37	--)	shift
38		break
39		;;
40	-*)	case $1 in
41		-*[abceghjklmopqrtuvwxyz_A-Z0-9]*) # [!...] not portable
42			echo "Usage: $_command_ [ -dfins ] [ target ... ] < mam-file" >&2; exit 2
43			;;
44		*)	case $1 in
45			*d*)	_debug_="eval echo $_command_: debug: >&2" ;;
46			esac
47			case $1 in
48			*f*)	_force_=1 ;;
49			esac
50			case $1 in
51			*i*)	_error_=: ;;
52			esac
53			case $1 in
54			*n*)	_exec_=echo ;;
55			esac
56			case $1 in
57			*s*)	_silent_=1 ;;
58			esac
59			;;
60		esac
61		;;
62	*)	break
63		;;
64	esac
65	shift
66done
67_select_=
68while	:
69do	case $# in
70	0)	break ;;
71	esac
72	case $1 in
73	*=*)	eval $1
74		;;
75	*)	case $_select_ in
76		"")	_select_=$1 ;;
77		*)	_select_="$_select_|$1" ;;
78		esac
79		;;
80	esac
81	shift
82done
83case $_select_ in
84"")	_select_="*" ;;
85esac
86(set -e; false || true) && _set_=e || echo $_command_: command errors ignored because of shell botch >&2
87case $_silent_ in
88"")	_set_=x$_set_
89	;;
90*)	case $_exec_ in
91	"echo")	_exec_=: ;;
92	esac
93	;;
94esac
95case $_exec_ in
96"eval")	_begin_="("
97	_end_=") </dev/null"
98	case $_set_ in
99	?*)	_set_="set -$_set_;" ;;
100	esac
101	;;
102*)	_set_=
103	;;
104esac
105
106if	test -f $_state_list_ -a -f $_state_time_
107then	mamstate $_state_list_ < $_state_list_ | sort > $_tmp_
108	for _i_ in `comm -12 $_state_time_ $_tmp_ | sed 's/ .*//'`
109	do	case $_same_ in
110		.)	_same_=$_i_ ;;
111		*)	_same_="$_same_|$_i_" ;;
112		esac
113	done
114fi
115
116_index_=_
117_match_=
118case `(echo ok | (read -r a; echo $a) 2>/dev/null)` in
119ok)	_read_='read -r'
120	;;
121*)	# read strips \ -- thanks a lot
122	# tmp file avoids char at a time read
123	_read_=read
124	sed 's/\\/\\\\/g' > $_tmp_
125	exec < $_tmp_
126	rm -f $_tmp_
127	;;
128esac
129_old_=1
130_ifs_=$IFS
131while	IFS=' '; $_read_ _op_ _arg_ _val_
132do	IFS=$_ifs_
133	case $_op_ in
134	"note")	continue
135		;;
136	"info")	case $_arg_ in
137		"mam")	_old_= ;;
138		esac
139		continue
140		;;
141	"setv") eval _data_='$'$_arg_
142		case $_index_:$_data_ in
143		__*:*|*:)
144			case $_exec_ in
145			"eval")	;;
146			*)	echo "$_arg_=$_val_" ;;
147			esac
148			eval $_arg_="$_val_" "</dev/null"
149			;;
150		esac
151		case $_arg_:$mam_cc_L in
152		"CC:")	(
153			set -
154			mkdir /tmp/mam$$
155			cd /tmp/mam$$
156			echo 'main(){return 0;}' > main.c
157			code=1
158			if	$CC -c main.c 2>/dev/null
159			then	if	$CC -L. main.o -lc 2>/dev/null
160				then	$CC -L. main.o -lc > libc.a 2>/dev/null || code=0
161				fi
162			fi
163			cd /tmp
164			rm -rf /tmp/mam$$
165			exit $code
166			) </dev/null && mam_cc_L=' '
167			;;
168		esac
169		continue
170		;;
171	"make")	eval _name_$_index_=$_name_
172		eval _prev_$_index_=$_prev_
173		eval _cmds_$_index_='"$_cmds_"'
174		eval _attr_$_index_=$_attr_
175		eval _name_=$_arg_
176		_prev_=$_index_
177		case " $_val_ " in
178		*" metarule "*)	_attr_=m$_attr_ ;;
179		esac
180		_cmds_=
181		eval "	case \"$_name_\" in
182			$_select_)
183				case \"$_select_\" in
184				\"*\")	_select_=$_name_ ;;
185				esac
186				_match_=1
187				_attr_=x$_attr_
188				;;
189			esac"
190		case $_force_ in
191		"")	eval "	case \"$_name_\" in
192				$_diff_)_attr_=u$_attr_ ;;
193				$_same_);;
194				*)	_attr_=u$_attr_ ;;
195				esac"
196			;;
197		*)	_attr_=u$_attr_
198			;;
199		esac
200		case $_attr_ in
201		*u*)	case $_diff_ in
202			.)	_diff_=$_name_ ;;
203			*)	_diff_="$_diff_|$_name_" ;;
204			esac
205			;;
206		esac
207		_index_=_$_index_
208		eval _name_$_index_=$_name_
209		eval _prev_$_index_=$_prev_
210		eval _cmds_$_index_=$_cmds_
211		eval _attr_$_index_=$_attr_
212		eval _list_='"'"$_list_"'
213'$_name_'"'
214		continue
215		;;
216	"prev")	case $_force_ in
217		"")	eval "	case \"$_arg_\" in
218				$_diff_)_attr_=u$_attr_ ;;
219				$_same_)	;;
220				*)	_attr_=u$_attr_ ;;
221				esac"
222			;;
223		*)	_attr_=u$_attr_
224			;;
225		esac
226		continue
227		;;
228	esac
229	case $_index_ in
230	_)	echo $_op_: missing make op >&2; continue ;;
231	esac
232	case $_op_ in
233	"attr")	case $_val_ in
234		"meta"|"suff")	_attr_=m$_attr_ ;;
235		esac
236		;;
237	"exec"|"....")
238		case $_old_ in
239		"")	_arg_=$_val_
240			;;
241		*)	case $_val_ in
242			?*)	_arg_="$_arg_ $_val_" ;;
243			esac
244			;;
245		esac
246		case $_cmds_ in
247		"")	_cmds_=$_arg_
248			;;
249		*)	_cmds_="$_cmds_
250$_arg_"
251			;;
252		esac
253		;;
254	"done")	eval _arg_=$_arg_
255		_prop_=
256		case $_arg_ in
257		$_name_)case $_attr_ in
258			*m*)	;;
259			*x*u*|*u*x*)
260				case $_cmds_ in
261				"")	case $_attr_ in
262					*u*)	_prop_=u ;;
263					esac
264					;;
265				*)	$_exec_ "$_begin_$_set_$_cmds_$_end_" ||
266					{
267					_code_=$?
268					case $_set_ in
269					*-*e*)	;;
270					*)	case $_cmds_ in
271						*if*then*fi*|"||")	_code_=0 ;;
272						esac
273						;;
274					esac
275					case $_code_ in
276					0)	;;
277					*)	echo "*** exit code $_code_ making $_name_" >&2
278						$_error_
279						;;
280					esac
281					}
282					_prop_=u
283					;;
284				esac
285				;;
286			esac
287			_index_=$_prev_
288			eval _name_='$'_name_$_index_
289			eval _prev_='$'_prev_$_index_
290			eval _cmds_='$'_cmds_$_index_
291			eval _attr_=$_prop_'$'_attr_$_index_
292			;;
293		*)	echo $_val_: $_op_ $_name_ expected >&2
294			;;
295		esac
296		;;
297	esac
298done
299IFS=$_ifs_
300case $_match_ in
301"")	echo "$_command_: don't know how to make $_select_" >&2; $_error_ ;;
302esac
303case $_exec_ in
304"eval")	echo "$_list_" > $_state_list_
305	mamstate $_state_list_ < $_state_list_ | sort > $_state_time_
306	;;
307esac
308