xref: /titanic_41/usr/src/lib/libpp/common/pp.probe (revision bd0f52d78d701efcad2c460df61b45677d041c35)
1:
2# Glenn Fowler
3# AT&T Research
4#
5# @(#)pp.probe (AT&T Research) 2006-09-05
6#
7# C probe for libpp
8#
9# NOTE: C.probe must be included or .'d here
10#
11
12ppdef=$dir/pp.def
13ppkey=$dir/pp.key
14ppsym=$dir/ppsym
15for f in $ppdef $ppkey $ppsym
16do	test -f $f || { echo "$0: $f: not found" >&4; exit 1 ;}
17done
18
19sed -e "/^#/d" -e "s/[ 	].*//" < $ppdef > all.pp
20
21system=
22release=
23version=
24architecture=
25cpu=
26model=
27machine=
28
29#
30# path cleanup
31#
32
33for i in stdinclude usrinclude
34do	eval o='$'$i
35	v=$o
36	case $v in
37	*//*)	v=`echo $v | sed 's,///*,/,g'` ;;
38	esac
39	if	(test . -ef "`pwd`")
40	then	k=
41		for x in $v
42		do	case $x in
43			*/../*|*/..)
44				case $x in
45				/*)	a=/ ;;
46				*)	a= ;;
47				esac
48				IFS=/
49				set '' $x
50				IFS=$ifs
51				r=
52				for d
53				do	r="$d $r"
54				done
55				p=
56				g=
57				for d in $r
58				do	case $d in
59					..)	g="$g $d" ;;
60					*)	case $g in
61						'')	case $p in
62							'')	p=$d ;;
63							*)	p=$d/$p ;;
64							esac
65							;;
66						*)	set $g
67							shift
68							g=$*
69							;;
70						esac
71						;;
72					esac
73				done
74				case $a in
75				'')	for d in $g
76					do	p=$d/$p
77					done
78					;;
79				*)	p=$a$p
80					;;
81				esac
82				case $p in
83				/)	continue ;;
84				esac
85				test $x -ef $p && x=$p
86				;;
87			esac
88			k="$k $x"
89		done
90		set '' $k
91		shift
92		v=$1
93		case $# in
94		0)	;;
95		*)	shift
96			while	:
97			do	case $# in
98				0)	break ;;
99				esac
100				k=
101				for d
102				do	for j in $v
103					do	test $d -ef $j && continue 2
104					done
105					k="$k $d"
106				done
107				set '' $k
108				case $# in
109				1)	break ;;
110				esac
111				shift
112				v="$v $1"
113				shift
114			done
115			;;
116		esac
117	fi
118	case $v in
119	$o)	;;
120	*)	eval $i='$'v ;;
121	esac
122done
123
124id="::IDENT::`date`::IDENT::"
125echo '#assert test(ok)
126#if #test(ok)
127#else
128(
129#endif' > assert.$src
130echo '#ifdef __BASE_FILE__
131int ok;
132#else
133(
134#endif' > basefile.$src
135cat > catlit1.i <<'!'
136char test[] = "te"
137"st";
138!
139cat > catlit2.i <<'!'
140char test[] = "te\
141st";
142!
143echo '#define g(a,b) a ## b
144volatile int a;
145const int g(x,y)=1;
146extern int c(int);' > compat.$src
147echo > cpp.$src
148echo "#defincl <x.h>" > defincl.$src
149echo 'int a$b;' > dollar.$src
150echo "#eject" > eject.$src
151echo "#if 0
152(
153#else if 1
154int x;
155#else
156(
157#endif" > elseif.$src
158echo "#define _CAT(a,b,c) a##b##c
159#define hdra	hdrx
160#define hdr	_CAT(<,hdra,.h>)
161#include hdr" > hdra.$src
162echo "#define _XAT(a,b,c) a##b##c
163#define _CAT(a,b,c) _XAT(a,b,c)
164#define hdra	hdrx
165#define hdr	_CAT(<,hdra,.h>)
166#include hdr" > hdrx.$src
167echo "int f(){return 0;}" > hdrx.h
168echo "#ident \"$id\"" > ident.$src
169echo "#import \"import.h\"" > import.$src
170echo "int aaa;" > import.h
171echo "#include <inc_next.h>" > inc_next.$src
172mkdir inc0 inc1
173echo "#include_next <inc_next.h>" > inc0/inc_next.h
174echo 'char s[] = "INCLUDE_NEXT";' > inc1/inc_next.h
175echo '# 1 "linefile.i"
176
177# 1 "linefile.i"
178
179int i;' > linefile1.i
180echo '# 1 "linefile.i"
181
182# 1
183
184int i;' > linefile2.i
185echo "int i = 0;" > lineid1.i
186echo '# 1 "t.c"
187int i = 0;' > lineid2.i
188echo '# 1 "t.c"
189int i = 0;' > lineid3.$src
190echo "#include <stdio.h>" > linetype.$src
191echo '#include <sys/types.h>
192main()
193{
194	return sizeof(LONGLONG) != 8;
195}' > longlong.$src
196echo '#include "once.h"
197#include "once.h"' > once.$src
198echo '#ifdef once
199allmultiple
200#else
201#define once
202#endif' > once.h
203echo "extern int a,b;int f(){return a + = b;}" > opspace.$src
204echo "int f(){return(0);} // ((" > pluscom.$src
205echo "class x {int n;} m;" > plusplus.$src
206echo > preinc.$src
207echo '// splice \
208(
209int x = 1;' > plusspl.$src
210echo "int stdc_default_value = __STDC__ ;" > stdc.$src
211echo 'char xxx[] = "abc
212(";' > span.$src
213echo '#define g(a,b) a\
214b
215int ab,xy;
216#define xy XY
217char* g(x,y);' > splice.$src
218{
219echo 'int a\                        '
220echo 'b = 1;'
221} > splicesp.$src
222echo '#define g(a,b) a/**/b
223int g(x,y)=1;' > trans.$src
224echo '#define m 65
225#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 65
226#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 64
227#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 63
228#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 62
229#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 61
230#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 60
231#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 59
232#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 58
233#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 57
234#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 56
235#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 55
236#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 54
237#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 53
238#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 52
239#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 51
240#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 50
241#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 49
242#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 48
243#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 47
244#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 46
245#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 45
246#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 44
247#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 43
248#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 42
249#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 41
250#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 40
251#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 39
252#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 38
253#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 37
254#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 36
255#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 35
256#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 34
257#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 33
258#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 32
259#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 31
260#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 30
261#define xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 29
262#define xxxxxxxxxxxxxxxxxxxxxxxxxxxx 28
263#define xxxxxxxxxxxxxxxxxxxxxxxxxxx 27
264#define xxxxxxxxxxxxxxxxxxxxxxxxxx 26
265#define xxxxxxxxxxxxxxxxxxxxxxxxx 25
266#define xxxxxxxxxxxxxxxxxxxxxxxx 24
267#define xxxxxxxxxxxxxxxxxxxxxxx 23
268#define xxxxxxxxxxxxxxxxxxxxxx 22
269#define xxxxxxxxxxxxxxxxxxxxx 21
270#define xxxxxxxxxxxxxxxxxxxx 20
271#define xxxxxxxxxxxxxxxxxxx 19
272#define xxxxxxxxxxxxxxxxxx 18
273#define xxxxxxxxxxxxxxxxx 17
274#define xxxxxxxxxxxxxxxx 16
275#define xxxxxxxxxxxxxxx 15
276#define xxxxxxxxxxxxxx 14
277#define xxxxxxxxxxxxx 13
278#define xxxxxxxxxxxx 12
279#define xxxxxxxxxxx 11
280#define xxxxxxxxxx 10
281#define xxxxxxxxx 9
282#define xxxxxxxx 8
283#define xxxxxxx 7
284#define xxxxxx 6
285#define xxxxx 5
286#define xxxx 4
287#define xxx 3
288#define xx 2
289#define x 1
290#if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx != m
291xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
292#endif' > truncate.$src
293cat > zeof.c <<'!'
294char* foo = "az";
295!
296
297allmultiple=
298assert=
299basefile=
300compatibility=1
301defincl=
302dollar=
303eject=
304elseif=
305headerexpand=
306headerexpandall=
307hostedtransition=
308ident=
309import=
310include_next=
311linefile=
312lineid=
313linetype=
314nocatliteral=
315opspace=
316pluscom=
317plusplus=
318plussplice=
319redef=
320reguard=
321reserved=
322spaceout=
323splicecat=
324splicespace=
325strict=
326stringspan=
327transition=
328truncate=
329zeof=
330
331$cc -c assert.$src && assert=1
332
333$cc -c basefile.$src && basefile=__BASE_FILE__
334
335if	$cc -E defincl.$src
336then	case "`$cc -E defincl.$src | grep -c 'defincl'`" in
337	0)	defincl=1 ;;
338	esac
339fi
340
341if	$cc -c catlit1.i 2>e
342then	if	$cc -c catlit2.i 2>f
343	then	if	test `wc -c < f` -gt `wc -c < e`
344		then	nocatliteral=1
345		fi
346	else	nocatliteral=1
347	fi
348fi
349
350$cc -c dollar.$src && dollar=1
351
352$cc -c elseif.$src && elseif=1
353
354if	$cc -I. -c hdra.$src
355then	headerexpandall=1
356elif	$cc -I. -c hdrx.$src
357then	headerexpand=1
358fi
359
360if	$cc -E eject.$src
361then	case "`$cc -E eject.$src | grep -c 'eject'`" in
362	0)	eject=1 ;;
363	esac
364fi
365
366$cc -S ident.$src && grep "$id" ident.s && ident=1
367
368{ $cc -E import.$src | grep aaa ;} && import=1
369
370{ $cc -E -Iinc0 -Iinc1 inc_next.$src | grep INCLUDE_NEXT ;} && include_next=1
371
372if	$cc -c linefile1.i
373then	$cc -c linefile2.i
374	case $? in
375	0)	;;
376	*)	linefile=1 ;;
377	esac
378fi
379
380if	$cc -c lineid1.i 2>b
381then	$cc -c lineid2.i 2>e
382	c=$?
383else	$cc -c lineid3.c 2>e
384	c=$?
385fi
386case $c in
3870)	case `wc -l < b` in
388	`wc -l < e`)	;;
389	*)		lineid=line ;;
390	esac
391	;;
392*)	lineid=line
393	;;
394esac
395
396if	$cc -E linetype.$src | grep '^[ 	]*#[ 	]*[0123456789]*[ 	]*".*"[ 	]*[12]' > linetype
397then	if	grep '^[ 	]*#[ 	]*[0123456789]*[ 	]*".*"[ 	]*[12][ 	][ 	]*3' linetype
398	then	linetype=2
399	else	linetype=1
400	fi
401fi
402
403{ $cc -E once.$src | grep allmultiple ;} && allmultiple=1
404
405$cc -c plusplus.$src && plusplus=1
406
407$cc -c span.$src && stringspan=1
408
409$cc -c splice.$src && splicecat=1
410
411$cc -c splicesp.$src && splicespace=1
412
413exec < $ppkey
414while	read keyword type alternate comment
415do	case $keyword in
416	.)	break ;;
417	""|"#")	continue ;;
418	esac
419	case $type in
420	""|".")	type= ;;
421	*)	type="=$type" ;;
422	esac
423	for pre in '' _ __
424	do	for suf in '' _ __
425		do	case $suf in
426			'')	sep= ;;
427			*)	sep=. ;;
428			esac
429			case ,,$alternate, in
430			*,$pre$sep$suf,*)
431				key=$pre$keyword$suf
432				undef="$undef $key"
433				echo "int f(){
434	int	$key = 0;
435	return $key;
436}
437#undef	$key
438int g(){
439	int	$key = 0;
440	return $key;
441}" > key.$src
442				$cc -c key.$src >/dev/null 2>&1 || reserved="$reserved $key$type"
443				;;
444			esac
445		done
446	done
447done
448
449$cc -c opspace.$src && opspace=1
450
451case $plusplus in
452"")	$cc -c compat.$src && compatibility=
453	$cc -c pluscom.$src && pluscom=1
454	;;
455esac
456case $plusplus$pluscom in
457?*)	$cc -c plusspl.$src || plussplice=1 ;;
458esac
459case $plusplus in
460?*)	mkdir reguard
461	cd reguard
462	echo '#include "ptrone.h"
463#include "ptrdef.h"
464int main () { return gt(2,1) + gt(2.0,1.0); }' > ptr.$src
465	echo '#include "ptrone.h"
466template<class T> int gt(T a, T b) { return a > b; }' > ptrdef.$src
467	echo 'template<class T> int gt(T a, T b);' > ptrdef.h
468	echo '/* empty */' > ptrone.h
469	if	$cc -E ptr.$src > x.i && $cc x.i
470	then	echo '#ifndef _PTRONE_H
471#define _PTRONE_H
472static int xxx;
473#endif' > ptrone.h
474		if	$cc -E ptr.$src > x.i && echo "#define _PTRONE_H" >> x.i && $cc x.i
475		then	reguard=1
476		fi
477	fi
478	cd ..
479	rm -rf reguard
480	;;
481esac
482
483stdc=`$cc -E stdc.$src | sed -e '/stdc_default_value/!d' -e 's/.*=[ 	]*//' -e 's/[ 	]*;.*//'`
484case $stdc in
4850)		$cc -c trans.$src && transition=1 ;;
486[0123456789]*)	;;
487*)		stdc= ;;
488esac
489
490truncate=`$cc -E truncate.$src | grep '^[ 	]*[0123456789]'`
491$cc -c zeof.c || zeof=1
492
493echo "$predef" >> all.pp
494{
495	case $ppopt$ppenv in
496	?*)	ppcmd=cpp
497		ppdir=.
498		eval $ppenv '$'cc -Dmycpp -E '$'ppopt cpp.$src
499		;;
500	esac
501	eval set x $probe_verbose
502	shift
503	x=
504	for o in "$@"
505	do	set x `$cc $o -c cpp.$src 2>&1`
506		while	:
507		do	shift
508			case $# in
509			0)	break ;;
510			esac
511			case $1 in
512			*[\\/]rm)
513				;;
514			[\\/]*)	case " $x " in
515				*" $1 "*)	;;
516				*)		test -x $1 && x="$x $1" ;;
517				esac
518				;;
519			esac
520		done
521		case $x in
522		?*)	for f in $x
523			do	cp $f x && chmod u+w x && strip x && f=x
524				$ppsym < $f
525			done
526			break
527			;;
528		esac
529	done
530} 3>&- 3>&1 >/dev/null |
531	sed -e '/^ppsymbol$/d' -e '/^.$/d' -e '/^..$/d' -e '/[ABCDEFGHIJKLMNOPQRSTUVWXYZ].*[abcdefghijklmnopqrstuvwxyz]/d' -e '/[abcdefghijklmnopqrstuvwxyz].*[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/d' |
532	cat - all.pp |
533	sort -u |
534	{
535	for i in 0 1 2 3 4 5
536	do	echo "struct { char* name; long value; } predef[] = {" > cpp$i.$src
537	done
538	while read sym junk
539	do	case $sym in
540		_*)	set 0 ${sym}
541			;;
542		*_)	continue
543			;;
544		[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]*)
545			set 1 ${sym} 2 _${sym} 3 _${sym}_ 4 __${sym} 5 __${sym}__
546			;;
547		*)	continue
548			;;
549		esac
550		while	:
551		do	case $# in
552			0|1)	break ;;
553			esac
554			{
555			echo "#ifdef $2"
556			echo "\"$2\" , (long) $2 -1,"
557			echo "#endif"
558			} >> cpp$1.$src
559			shift
560			shift
561		done
562	done
563	for i in 0 1 2 3 4 5
564	do	echo "\"\", 0 };" >> cpp$i.$src
565	done
566	}
567preval="`for i in 0 1 2 3 4 5;do $cc -E cpp$i.$src;done | sed -e '/\".*\".*,.*,/!d' -e 's/[^\"]*\"\\([^\"]*\\)\"[ 	]*,[ 	]*([ 	]*long[ 	]*)[ 	]*\\(.*\\)[ 	]*-[ 	]*1[ 	]*,[ 	]*\$/\\1 \\2 =/g'` `$cc -dM -E stdc.$src | sed -e '/[ 	]*#[ 	]*define/!d' -e '/\"/d' -e 's/[ 	]*#[ 	]*define[ 	]*\\([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*\\)[ 	]*\\(.*\\)/\\1 \\2 =/'`"
568
569for i in bufld namei quota reboot utsname vfs
570do	echo "#include <sys/$i.h>" > t.$src
571	if	$cc -E t.$src
572	then	x=1
573	else	x=0
574	fi
575	eval sys_$i=$x
576done
577
578case "`grep -c '__STDC__[-0 	]*[=!]=[ 	]*0' $usrinclude/stdio.h 2>/dev/null`" in
5790)	;;
580*)	hostedtransition=1 ;;
581esac
582
583mapinclude=
584for i in builtins
585do	echo "#include <$i.h>" > t.$src
586	if	$cc -E t.$src
587	then	mapinclude="$mapinclude <$i.h>=\".\""
588	fi
589done
590
591#
592# the payoff
593#
594
595exec >&3
596
597case "$compatibility:$transition:$dollar" in
598::)	strict=1 ;;
599esac
600case $version_stamp in
601?*)	echo "/* $version_stamp" ;;
602*)	echo "/* $cc" ;;
603esac
604echo "*/"
605case $plusplus:$stdc in
6061:?*)	preval="$preval = __STDC__ $stdc ="
607	redef="$redef __STDC__"
608	;;
609esac
610ppbuiltin=0
611set x $preval
612shift
613case $# in
6140)	;;
615*)	echo
616	echo "#pragma pp:predefined"
617	predef=
618	while	:
619	do	case $# in
620		0)	break ;;
621		esac
622		m=$1
623		shift
624		case $m in
625		*'('*)	i=`echo "$m" | sed 's,(.*,,'` ;;
626		*)	i=$m ;;
627		esac
628		predef="$predef
629$i"
630		eval predef_$i=0
631		while	:
632		do	case $1 in
633			'=')	break ;;
634			*)	shift ;;
635			esac
636		done
637		while	:
638		do	case $1 in
639			'=')	shift ;;
640			*)	break ;;
641			esac
642		done
643	done
644	for i in $undef
645	do	case " $redef " in
646		*" $i "*)	;;
647		*)		eval predef_$i=3 ;;
648		esac
649	done
650	set $preval
651	while	:
652	do	case $# in
653		0)	break ;;
654		esac
655		m=$1
656		shift
657		case $m in
658		*'('*)	i=`echo "$m" | sed 's,(.*,,'` ;;
659		*)	i=$m ;;
660		esac
661		case $i in
662		'=')	continue ;;
663		esac
664		v=
665		while	:
666		do	case $1 in
667			'=')	break ;;
668			esac
669			v="$v $1"
670			shift
671		done
672		while	:
673		do	case $1 in
674			'=')	shift ;;
675			*)	break ;;
676			esac
677		done
678		case $i in
679		__LCC__)strict=2 ;;
680		_*)	;;
681		*)	eval j=\$predef_$i
682			case $j in
683			0)	eval predef_$i=1
684				echo "#define $m$v"
685				case $strict in
686				1)	strict= ;;
687				esac
688				;;
689			esac
690			;;
691		esac
692	done
693	nopredef=0
694	while	:
695	do	set $preval
696		while	:
697		do	case $# in
698			0)	break ;;
699			esac
700			m=$1
701			shift
702			case $m in
703			*'('*)	i=`echo "$m" | sed 's,(.*,,'` ;;
704			*)	i=$m ;;
705			esac
706			v=
707			while	:
708			do	case $1 in
709				'=')	break ;;
710				esac
711				v="$v $1"
712				shift
713			done
714			while	:
715			do	case $1 in
716				'=')	shift ;;
717				*)	break ;;
718				esac
719			done
720			case $nopredef in
721			2)	;;
722			*)	case $v in
723				' '*' '*)
724					nopredef=1
725					continue
726					;;
727				' '[0123456789]*|' '"'"*"'"*)
728					;;
729				*)	case $1 in
730					_*)	;;
731					*)	nopredef=1
732						continue
733						;;
734					esac
735					;;
736				esac
737				;;
738			esac
739			eval j=\$predef_$i
740			case $j in
741			0)	case $ppbuiltin in
742				2)	echo "#pragma pp:builtin"
743					ppbuiltin=1
744					;;
745				esac
746				eval predef_$i=2
747				echo "#define $m$v"
748				;;
749			1)	case $m in
750				$i)	eval predef_$i=2
751					eval j=\$predef___${i}__
752					case $j in
753					[12])	;;
754					*)	case $ppbuiltin in
755						2)	echo "#pragma pp:builtin"
756							ppbuiltin=1
757							;;
758						esac
759						eval predef___${i}__=2
760						echo "#define __${i}__$v"
761						;;
762					esac
763					;;
764				esac
765				;;
766			esac
767		done
768		case $nopredef in
769		2)	break ;;
770		esac
771		echo "#pragma pp:nopredefined"
772		case $nopredef in
773		0)	break ;;
774		esac
775		ppbuiltin=2
776		nopredef=2
777	done
778	;;
779esac
780case $basefile in
781?*)	case $ppbuiltin in
782	0|2)	ppbuiltin=1
783		echo "#pragma pp:builtin"
784		;;
785	esac
786	echo "#define $basefile	#(BASE)"
787	;;
788esac
789case $ppbuiltin in
7901)	echo "#pragma pp:nobuiltin" ;;
791esac
792
793eval set x $probe_longlong
794shift
795x=
796for o in "$@"
797do	rm -f longlong.$exe
798	if	$cc -DLONGLONG="$o" -o longlong.$exe longlong.$src &&
799		./longlong.$exe
800	then	x=1
801		break
802	fi
803done
804case $x in
805'')	eval set x $probe_longlong_t
806	shift
807	for o in "$@"
808	do	rm -f longlong.$exe
809		if	$cc -DLONGLONG="$o" -o longlong.$exe longlong.$src &&
810			./longlong.$exe
811		then	echo "#define <long long> $o"
812			break
813		fi
814	done
815	;;
816esac
817
818echo
819for i in `echo "$predef" | sed -e 's/^__*\(.*\)_*\$/\1/' -e '/^[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]*[0123456789][abcdefghijklmnopqrstuvwxyz0123456789]*\$/!d'` `echo "$predef" | sed -e 's/^__*\(.*\)_*\$/\1/' -e '/^[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]*\$/!d'`
820do	case $i in
821	*ix)	;;
822	*)	architecture=$i
823		break
824		;;
825	esac
826done
827for i in `sed -e '/^#/d' -e '/:architecture:/!d' -e 's/[ 	].*//' < $ppdef`
828do	eval j="\" \$predef_$i \$predef__${i} \$predef__${i}_ \$predef___${i} \$predef___${i}__ \""
829	case $j in
830	*" 2 "*)architecture=$i
831		break
832		;;
833	esac
834done
835for i in `sed -e '/^#/d' -e '/:machine:/!d' -e 's/[ 	].*//' < $ppdef`
836do	eval j="\" \$predef_$i \$predef__${i} \$predef__${i}_ \$predef___${i} \$predef___${i}__ \""
837	case $j in
838	*" 2 "*)machine="$machine $i" ;;
839	esac
840done
841case $sys_bufld$sys_reboot$sys_utsname in
8421??)	release=research
843	version=9
844	;;
84501?)	release=bsd
846	case $sys_quota in
847	0)	case $sys_vfs in
848		0)	version=4.1
849			;;
850		esac
851		;;
852	1)	case $sys_namei in
853		0)	version=4.2
854			;;
855		1)	version=4.3
856			;;
857		esac
858		;;
859	esac
860	;;
861001)	release=V
862	;;
863esac
864for i in `sed -e '/^#/d' -e '/:release:/!d' -e 's/[ 	].*//' < $ppdef`
865do	eval j=\$predef_$i
866	case $j in
867	2)	release="$release $i" ;;
868	esac
869done
870for i in `sed -e '/^#/d' -e '/:system:/!d' -e 's/[ 	].*//' < $ppdef`
871do	eval j=\$predef_$i
872	case $j in
873	2)	system="$system $i" ;;
874	esac
875done
876case $release in
877topix)	release="$release V"
878	;;
879esac
880case $assert in
881?*)	for i in $predef
882	do	case $i in
883		_*|*_)	;;
884		*)	for p in architecture cpu machine system
885			do	echo "#if #$p($i)
886eval \"case \\\" \$$p \\\" in *\\\" $i \\\"*) ;; *) $p=\\\"$i \$$p\\\" ;; esac\"
887: avoid string literal concatenation
888#endif"
889			done
890			;;
891		esac
892	done > t.$src
893	eval "`$cc -E t.$src`"
894	set x x $prepred
895	while	:
896	do	shift
897		shift
898		case $# in
899		[01])	break ;;
900		esac
901		eval "
902			case \" \$$1 \" in
903			*\" $2 \"*) ;;
904			*) $1=\"$2 \$$1\" ;;
905			esac
906		"
907	done
908	;;
909esac
910case $system in
911"")	system=unix ;;
912esac
913case $architecture in
914ibm|uts|u370)	model=370
915		architecture=ibm
916		;;
917m*68*)		architecture=m68000
918		for i in $predef
919		do	case $i in
920			m*68*[123456789][0123456789])
921				model=`echo $i | sed 's/.*\(..\)/\1/'`
922				break
923				;;
924			esac
925		done
926		;;
927u3b?*)		model=`echo $architecture | sed 's/u3b//'`
928		architecture=3b
929		;;
930u3b)		case $model in
931		"")	model=20 ;;
932		esac
933		architecture=3b
934		;;
935vax[0123456789]*)
936		model=`echo $architecture | sed 's/vax//'`
937		architecture=vax
938		;;
939hp[0123456789]*s[0123456789])
940		case $release in
941		[abcdefghijklmnopqrstuvwxyz]*.[abcdefghijklmnopqrstuvwxyz]*.*)
942			version=$release
943			release=V
944			;;
945		esac
946		architecture="$architecture `echo $architecture | sed 's/s.*//'`"
947		;;
948esac
949case $hosttype in
950*.*)	i=`echo $hosttype | sed -e 's,.*\.,,'` ;;
951*)	i=$hosttype ;;
952esac
953case $i in
954unknown);;
955?*)	case " $architecture " in
956	*" $i "*) ;;
957	*)	architecture="$architecture $i" ;;
958	esac
959	;;
960esac
961case $architecture in
962"")	echo "$cc: warning: architecture not determined" >&4
963	set x $machine
964	architecture=$2
965	;;
966esac
967echo "#define #hosttype($hosttype)"
968for i in $system
969do	echo "#define #system($i)"
970done
971case $release in
972"")	echo "#define #release()" ;;
973*)	for i in $release
974	do	echo "#define #release($i)"
975		case $i in
976		V)	echo "#define #release(system5)" ;; # compatibility
977		esac
978	done
979	;;
980esac
981echo "#define #version($version)"
982case $architecture in
983"")	echo "#define #architecture()" ;;
984*)	for i in `echo $architecture | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
985	do	echo "#define #architecture($i)"
986	done
987	;;
988esac
989echo "#define #model($model)"
990case $machine in
991"")	case $architecture:$model in
992	?*:?*)	set x $architecture; machine="$2/$model $architecture" ;;
993	*)	machine=$architecture ;;
994	esac
995	;;
996*)	machine="$machine $architecture"
997	;;
998esac
999case $machine in
1000"")	echo "#define #machine()" ;;
1001*)	j=
1002	for i in `echo $machine | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
1003	do	case " $i " in
1004		*" $j "*)
1005			;;
1006		*)	j="$j $i"
1007			echo "#define #machine($i)"
1008			;;
1009		esac
1010	done
1011	;;
1012esac
1013for i in $cpu
1014do	echo "#define #cpu($i)"
1015done
1016echo "#define #addressing()"
1017for i in $ATTRIBUTES
1018do	eval d=\$$i
1019	n=`echo $i | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
1020	echo "#define #$n($d)"
1021done
1022case $stdc in
1023?*)	echo "#define #dialect(ansi)" ;;
1024esac
1025case $plusplus in
1026?*)	echo "#define #dialect(C++)" ;;
1027esac
1028case $hosted in
1029"")	echo "#define #dialect(cross)" ;;
1030esac
1031case $so:$dynamic:$static in
1032::)	;;
1033*)	echo "#define #dialect(dynamic)" ;;
1034esac
1035echo
1036case $plusplus in
1037?*)	echo "#pragma pp:plusplus" ;;
1038esac
1039case $reserved in
1040?*)	echo "#pragma pp:reserved" $reserved ;;
1041esac
1042case $nocatliteral in
1043?*)	echo "#pragma pp:nocatliteral" ;;
1044esac
1045case $opspace in
1046?*)	echo "#pragma pp:opspace" ;;
1047esac
1048case $pluscom in
1049?*)	echo "#pragma pp:pluscomment" ;;
1050esac
1051case $plussplice in
1052?*)	echo "#pragma pp:plussplice" ;;
1053esac
1054case $reguard in
1055?*)	echo "#pragma pp:reguard" ;;
1056esac
1057case $splicecat in
1058?*)	echo "#pragma pp:splicecat" ;;
1059esac
1060case $splicespace in
1061?*)	echo "#pragma pp:splicespace" ;;
1062esac
1063case $stringspan in
1064?*)	echo "#pragma pp:stringspan" ;;
1065esac
1066case $stdc in
1067"")	echo "#pragma pp:compatibility"
1068	;;
10690)	echo "#pragma pp:transition"
1070	;;
10711)	case $strict in
1072	?*)	echo "#pragma pp:strict" ;;
1073	esac
1074	;;
1075esac
1076case $hostedtransition in
10771)	echo "#pragma pp:hostedtransition" ;;
1078esac
1079case $stdc in
1080?*)	case $ppopt$ppenv in
1081	"")	spaceout=1
1082		echo "#pragma pp:spaceout"
1083		;;
1084	esac
1085	;;
1086esac
1087case $truncate in
1088?*)	echo "#pragma pp:truncate $truncate" ;;
1089esac
1090case $zeof in
1091?*)	echo "#pragma pp:zeof" ;;
1092esac
1093case $dollar in
10941)	echo '#pragma pp:id "$"' ;;
1095esac
1096cdir=-I+C
1097hdir=-I+H
1098set x $stdinclude
1099while	:
1100do	shift
1101	case $# in
1102	0)	break ;;
1103	esac
1104	case $1 in
1105	$cdir|$hdir)
1106		;;
1107	-I+C)	cdir=$1
1108		echo "#pragma pp:nocdir"
1109		;;
1110	-I-C)	cdir=$1
1111		echo "#pragma pp:cdir"
1112		;;
1113	-I+H)	hdir=$1
1114		echo "#pragma pp:nohostdir"
1115		;;
1116	-I-H)	hdir=$1
1117		echo "#pragma pp:hostdir"
1118		;;
1119	-I*)	;;
1120	*)	echo "#pragma pp:include \"$1\""
1121		;;
1122	esac
1123done
1124case $usrinclude in
1125/usr/include)
1126	;;
1127?*)	echo "#pragma pp:standard \"$usrinclude\""
1128	;;
1129esac
1130case $plusplus in
1131?*)	case $usrinclude in
1132	?*)	if	grep plusplus $usrinclude/ctype.h >/dev/null 2>&1
1133		then	echo '#pragma pp:nocdir "-"'
1134		fi
1135		;;
1136	esac
1137	;;
1138esac
1139case $mapinclude in
1140?*)	echo "#pragma pp:mapinclude hosted$mapinclude" ;;
1141esac
1142case $linefile in
1143?*)	echo "#pragma pp:linefile" ;;
1144esac
1145case $lineid in
1146?*)	echo "#pragma pp:lineid line" ;;
1147esac
1148case $linetype in
11491)	echo "#pragma pp:linetype" ;;
1150?*)	echo "#pragma pp:linetype $linetype" ;;
1151esac
1152case $allmultiple in
1153"")	echo "#pragma pp:noallmultiple" ;;
1154esac
1155case $defincl in
11561)	echo '#pragma pp:map "/#(pragma )?defincl>/"' ;;
1157esac
1158case $eject in
11591)	echo '#pragma pp:map "/#(pragma )?eject>/"' ;;
1160esac
1161case $elseif in
11621)	echo "#pragma pp:elseif" ;;
1163esac
1164case $headerexpand in
11651)	echo "#pragma pp:headerexpand" ;;
1166esac
1167case $headerexpandall in
11681)	echo "#pragma pp:headerexpandall" ;;
1169esac
1170case $ident in
11711)	echo '#pragma pp:map "/#(pragma )?ident>/" "/#(pragma )?/###/"' ;;
1172*)	echo '#pragma pp:map "/#(pragma )?ident>/"' ;;
1173esac
1174case $import in
11751)	echo '#pragma pp:map "/#(pragma )?import>/" "/#(pragma )?import(.*)/__STDPP__IMPORT__(\2)/"
1176#macdef __STDPP__IMPORT__(x)
1177#pragma pp:noallmultiple
1178#include x
1179#pragma pp:allmultiple
1180#endmac' ;;
1181esac
1182case $include_next in
11831)	echo '#pragma pp:map "/#include_next>/" ",[^\<]*\<,#include <.../,"' ;;
1184esac
1185echo '#pragma pp:map "/#pragma lint:/" ",#pragma lint:(.*),##/*\1*/,u"'
1186echo '#pragma pp:map "/#(pragma )?sccs>/"'
1187
1188case $stdc:$spaceout in
11891:)	case ' '$reserved' ' in
1190	*' 'asm' '*|*' 'asm=*)
1191		echo "#macdef asm"
1192		echo "#pragma pp:spaceout"
1193		echo "#undef asm"
1194		echo "asm"
1195		echo "#endmac"
1196		;;
1197	esac
1198	;;
1199esac
1200
1201if	$cc -E preinc.$src > preinc.out
1202then	for f in `sed -e 's,\\\\,/,g' -e 's,"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:/,"/,g' -e '/^#[line 	]*[0123456789][0123456789]*[ 	][ 	]*"[\\/]/!d' -e 's/^#[line 	]*[0123456789][0123456789]*[ 	][ 	]*".*[\\/]\(.*\)".*/\1/' preinc.out | sort -u`
1203	do	case $f in
1204		*preinc.$src*)
1205			;;
1206		*)	echo "#include <$f>"
1207			;;
1208		esac
1209	done
1210fi
1211