xref: /illumos-gate/usr/src/contrib/ast/src/cmd/INIT/probe.win32 (revision 82d0151a507442720a3aea34c8925041894ab173)
1:
2# @(#)probe.win32 (AT&T Research) 2010-01-01
3#
4# win32 specific make C probe initialization
5# wrapped cc's are easy on uwin
6#
7# 2> easy.err to avoid mysterious hang with bcc
8
9# begin preamble shared with the pp probe.ini
10
11IFS=$'\n'
12
13chmod 777 . # cl.exe setuid workaround
14
15typeset -A header version
16
17# we are probing on behalf of libpp and nmake
18# so the native preprocessor must be forced in
19# order to bootstrap libpp and nmake
20
21nativepp=-1
22export nativepp
23
24probe_header="
25stddef.h
26"
27for inc in syslimits.h winerror.h ostream bits/ctype_base.h stream.h
28do	echo 	"#include <$inc>" > easy.c
29	if	$cc -E easy.c > /dev/null 2> easy.err
30	then	probe_header="$probe_header
31$inc
32"
33	fi
34done
35
36{
37for i in $probe_header
38do	echo "#include <$i>"
39done
40echo '#ifdef __cplusplus'
41echo "int _Pr0b3_cplus=__cplusplus;"
42echo '#endif'
43echo '#ifdef _UWIN'
44echo "int _Pr0b3_uwin=_UWIN;"
45echo '#endif'
46echo '#ifdef __BORLANDC__'
47echo "int _Pr0b3_version_BORLAND=__BORLANDC__;"
48echo '#endif'
49echo '#ifdef __DMC__'
50echo "int _Pr0b3_version_DM=__DMC__;"
51echo '#endif'
52echo '#ifdef _MSC_VER'
53echo "int _Pr0b3_version_MS=_MSC_VER;"
54echo '#endif'
55echo '#ifdef __ICL'
56echo "int _Pr0b3_version_ICL=__ICL;"
57echo '#endif'
58echo '#ifdef __LCC__'
59echo "int _Pr0b3_version_LCC=0+__LCC__;"
60echo '#endif'
61echo '#ifdef __MINGW32__'
62echo "int _Pr0b3_version_MINGW=__MINGW32__;"
63echo '#endif'
64echo '#ifdef __INTERIX'
65echo "int _Pr0b3_version_INTERIX=__INTERIX;"
66echo '#endif'
67echo '#ifdef __WATCOMC__'
68echo "int _Pr0b3_version_WATCOM=__WATCOMC__;"
69echo '#endif'
70} > easy.c
71
72include=
73uwin=
74cplus=
75
76$cc -E easy.c 2>&1 |
77egrep -i '^(#(line)? 1 .*\.[hH]| *int +_Pr0b3_[a-zA-Z_]* *= *[0-9])' |
78sed	-e 's,_Pr0b3_,,' \
79	-e 's/.*"\(.*\)".*/\1/' \
80	-e 's,^  *,,' \
81	-e 's,  *$,,' \
82	-e 's, *= *,=,' \
83	-e 's,^\(.\):[\\/]*,/\1/,' \
84	-e 's,[\\/][\\/]*,/,g' \
85	-e 's,^\(/.*\)/\(.*\)$,header[\2]="\1",' \
86	-e 's, *int *\(.*\);.*,\1,' \
87	-e 's,^version_\(.*\)=,version[\1]=,' \
88	> easy.sh
89. ./easy.sh
90
91include=
92for i in $probe_header
93do	d=${header[$i]}
94	if	[[ $d ]]
95	then	include="$include
96$d"
97	elif	[[ $i == */* ]]
98	then	d=${header[${i##*/}]}
99		if	[[ $d == */${i%/*} ]]
100		then	include="$include
101${d%/${i%/*}}"
102		fi
103	fi
104done
105
106i=$($cc -V 2> easy.err)
107if	test "" != "$i" -a -d "$i/include"
108then	include="$i/include
109$include"
110fi
111
112stdinclude=
113for inc in $include
114do	if	[[ ${inc%/*} -ef /msdev/platformsdk ]]
115	then	inc=/msdev/platformsdk/${inc##*/}
116	elif	[[ ${inc%/*} -ef /platformsdk ]]
117	then	inc=/platformsdk/${inc##*/}
118	fi
119	for dup in $stdinclude
120	do	[[ $inc -ef $dup ]] && continue 2
121	done
122	stdinclude="$stdinclude
123$inc"
124done
125
126# end preamble shared with the pp probe.ini
127
128if	[[ ${version[@]} == [0-9]* && $stdinclude ]]
129then	: the payoff
130	set -- $cc
131	cmd=$1
132	shift
133	set -- $(whence $cmd) "$@"
134	typ=$(package)
135	dialect="ANSI CLOSURE DYNAMIC EXPORT=DLL LIBPP -I-"
136	case ${cc##*/} in
137	*CC*)	dialect="$dialect C++"
138		cplus=1
139		;;
140	esac
141	ld=${cc%cc}ld
142	if	[[ ! -x $ld ]]
143	then	ld=${cc%/*}/ld
144		if	[[ ! -x $ld ]]
145		then	case $cc in
146			*/ncc)	ld=/usr/bin/nld ;;
147			*)	ld=/usr/bin/ld ;;
148			esac
149		fi
150	fi
151	{
152		if	$cc -v >/dev/null 2>&1
153		then	v=$($cc -v 2>/dev/null)
154			if	[[ $v ]]
155			then	print "# ;VERSION;-v;$v;PATH;$cc"
156			fi
157		else	v=
158		fi
159		cat <<!
160CC.CC = $*
161CC.NATIVE = $*
162CC.EXECTYPE = $typ
163CC.HOSTTYPE = $typ
164CC.ALTPP.FLAGS = -Yp,\$(CPP:D)
165CC.ALTPP.ENV =
166CC.AR = ar
167CC.ARFLAGS =
168CC.DEBUG = -g
169CC.DIALECT = $dialect
170CC.DLL = -D_BLD_DLL
171CC.DLLBIG = -D_BLD_DLL
172CC.DLL.DEF = -D_BLD_DLL
173CC.DLL.DIR = \$(BINDIR)
174CC.DLL.LIBRARIES =
175CC.DLL.VARIANTS =
176CC.DYNAMIC =
177CC.EXPORT.DYNAMIC =
178CC.LD = $ld
179CC.LD.DYNAMIC = -Bdynamic
180CC.LD.LAZY =
181CC.LD.NOLAZY =
182CC.LD.ORIGIN =
183CC.LD.RECORD =
184CC.LD.NORECORD =
185CC.LD.RUNPATH =
186CC.LD.STATIC = -Bstatic
187CC.LD.STRIP =
188CC.LIB.DLL = option
189CC.LIB.ALL = -Bwhole-archive
190CC.LIB.UNDEF = -Bno-whole-archive
191CC.MAKE.OPTIONS = nativepp=0
192CC.NM = nm
193CC.NMEDIT =
194CC.NMFLAGS =
195CC.OPTIMIZE = -O
196CC.PIC =
197CC.PICBIG =
198CC.READONLY =
199CC.REPOSITORY =
200CC.SHARED = -G
201CC.SHARED.LD = $ld
202CC.SHARED.REGISTRY =
203CC.SHARED.REGISTRY.PATH =
204CC.SHELLMAGIC =
205CC.SIZE = size
206CC.STATIC = -Bstatic
207!
208		inc=
209		lib=
210		if	[[ ${version[LCC]} ]]
211		then	lib=/lcc
212		fi
213		if	[[ $stdinclude == *' '* ]]
214		then	stdinclude=${stdinclude//' '/''}
215		fi
216		stdinc=
217		stdlib=
218		for inc in $stdinclude
219		do	stdinc="$stdinc $inc"
220			d=${inc%/*}/lib
221			if	[[ -d $d ]]
222			then	stdlib="$stdlib $d"
223			fi
224		done
225		case $uwin in
226		[0-9]*)	cat <<!
227CC.STDINCLUDE = /usr/include $stdinc
228CC.STDLIB = /usr/lib$lib $stdlib
229!
230			;;
231		*)	cat <<!
232CC.STDINCLUDE = $stdinc
233CC.STDLIB = $stdlib
234!
235			;;
236		esac
237		cat <<!
238CC.STRICT =
239CC.STRIP = strip
240CC.STRIP.FLAGS =
241CC.PREFIX.ARCHIVE = lib
242CC.PREFIX.DYNAMIC =
243CC.PREFIX.SHARED =
244CC.PREFIX.SYMBOL = _
245CC.SUFFIX.ARCHIVE = .a
246CC.SUFFIX.COMMAND =
247CC.SUFFIX.DEBUG = .pdb
248CC.SUFFIX.DYNAMIC = .dll
249CC.SUFFIX.LD = .def .exp .ign .res
250CC.SUFFIX.OBJECT = .o
251CC.SUFFIX.SHARED = .lib
252CC.SUFFIX.SOURCE = .c
253CC.SUFFIX.STATIC =
254!
255		if	[[ $v ]]
256		then	case $v in
257			*\"*)	v=$(print -r -- | sed -e 's,",\\",g' -e 's,^ ,,' -e 's,.*,"&",') ;;
258			*\'*)	v=\"$v\" ;;
259			esac
260			cat <<!
261CC.VERSION = -v
262CC.VERSION.STRING = $v
263!
264		else	cat <<!
265CC.VERSION =
266CC.VERSION.STRING =
267!
268		fi
269		if	[[ ${version[MINGW]} || ${version[MS]} ]]
270		then	cat <<!
271CC.WARN = -Wall
272!
273		else	cat <<!
274CC.WARN =
275!
276		fi
277		cat <<!
278CC.PREROOT =
279CC.UNIVERSE = att
280!
281	} >&3
282	exit 0
283fi
284