summaryrefslogtreecommitdiff
path: root/src/cmd/INIT/probe.win32
blob: 7939fccad50389c94fbc187658b060c1c40d562c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
:
# @(#)probe.win32 (AT&T Research) 2010-01-01
#
# win32 specific make C probe initialization
# wrapped cc's are easy on uwin
#
# 2> easy.err to avoid mysterious hang with bcc

# begin preamble shared with the pp probe.ini

IFS=$'\n'

chmod 777 . # cl.exe setuid workaround

typeset -A header version

# we are probing on behalf of libpp and nmake
# so the native preprocessor must be forced in
# order to bootstrap libpp and nmake

nativepp=-1
export nativepp

probe_header="
stddef.h
"
for inc in syslimits.h winerror.h ostream bits/ctype_base.h stream.h
do	echo 	"#include <$inc>" > easy.c
	if	$cc -E easy.c > /dev/null 2> easy.err 
	then	probe_header="$probe_header
$inc
"
	fi
done

{
for i in $probe_header
do	echo "#include <$i>"
done
echo '#ifdef __cplusplus'
echo "int _Pr0b3_cplus=__cplusplus;"
echo '#endif'
echo '#ifdef _UWIN'
echo "int _Pr0b3_uwin=_UWIN;"
echo '#endif'
echo '#ifdef __BORLANDC__'
echo "int _Pr0b3_version_BORLAND=__BORLANDC__;"
echo '#endif'
echo '#ifdef __DMC__'
echo "int _Pr0b3_version_DM=__DMC__;"
echo '#endif'
echo '#ifdef _MSC_VER'
echo "int _Pr0b3_version_MS=_MSC_VER;"
echo '#endif'
echo '#ifdef __ICL'
echo "int _Pr0b3_version_ICL=__ICL;"
echo '#endif'
echo '#ifdef __LCC__'
echo "int _Pr0b3_version_LCC=0+__LCC__;"
echo '#endif'
echo '#ifdef __MINGW32__'
echo "int _Pr0b3_version_MINGW=__MINGW32__;"
echo '#endif'
echo '#ifdef __INTERIX'
echo "int _Pr0b3_version_INTERIX=__INTERIX;"
echo '#endif'
echo '#ifdef __WATCOMC__'
echo "int _Pr0b3_version_WATCOM=__WATCOMC__;"
echo '#endif'
} > easy.c

include=
uwin=
cplus=

$cc -E easy.c 2>&1 |
egrep -i '^(#(line)? 1 .*\.[hH]| *int +_Pr0b3_[a-zA-Z_]* *= *[0-9])' |
sed	-e 's,_Pr0b3_,,' \
	-e 's/.*"\(.*\)".*/\1/' \
	-e 's,^  *,,' \
	-e 's,  *$,,' \
	-e 's, *= *,=,' \
	-e 's,^\(.\):[\\/]*,/\1/,' \
	-e 's,[\\/][\\/]*,/,g' \
	-e 's,^\(/.*\)/\(.*\)$,header[\2]="\1",' \
	-e 's, *int *\(.*\);.*,\1,' \
	-e 's,^version_\(.*\)=,version[\1]=,' \
	> easy.sh
. ./easy.sh

include=
for i in $probe_header
do	d=${header[$i]}
	if	[[ $d ]]
	then	include="$include
$d"
	elif	[[ $i == */* ]]
	then	d=${header[${i##*/}]}
		if	[[ $d == */${i%/*} ]]
		then	include="$include
${d%/${i%/*}}"
		fi
	fi
done

i=$($cc -V 2> easy.err)
if	test "" != "$i" -a -d "$i/include"
then	include="$i/include
$include"
fi

stdinclude=
for inc in $include
do	if	[[ ${inc%/*} -ef /msdev/platformsdk ]]
	then	inc=/msdev/platformsdk/${inc##*/}
	elif	[[ ${inc%/*} -ef /platformsdk ]]
	then	inc=/platformsdk/${inc##*/}
	fi
	for dup in $stdinclude
	do	[[ $inc -ef $dup ]] && continue 2
	done
	stdinclude="$stdinclude
$inc"
done

# end preamble shared with the pp probe.ini

if	[[ ${version[@]} == [0-9]* && $stdinclude ]]
then	: the payoff
	set -- $cc
	cmd=$1
	shift
	set -- $(whence $cmd) "$@"
	typ=$(package)
	dialect="ANSI CLOSURE DYNAMIC EXPORT=DLL LIBPP -I-"
	case ${cc##*/} in
	*CC*)	dialect="$dialect C++"
		cplus=1
		;;
	esac
	ld=${cc%cc}ld
	if	[[ ! -x $ld ]]
	then	ld=${cc%/*}/ld
		if	[[ ! -x $ld ]]
		then	case $cc in
			*/ncc)	ld=/usr/bin/nld ;;
			*)	ld=/usr/bin/ld ;;
			esac
		fi
	fi
	{
		if	$cc -v >/dev/null 2>&1
		then	v=$($cc -v 2>/dev/null)
			if	[[ $v ]]
			then	print "# ;VERSION;-v;$v;PATH;$cc"
			fi
		else	v=
		fi
		cat <<!
CC.CC = $*
CC.NATIVE = $*
CC.EXECTYPE = $typ
CC.HOSTTYPE = $typ
CC.ALTPP.FLAGS = -Yp,\$(CPP:D)
CC.ALTPP.ENV =
CC.AR = ar
CC.ARFLAGS =
CC.DEBUG = -g
CC.DIALECT = $dialect
CC.DLL = -D_BLD_DLL
CC.DLLBIG = -D_BLD_DLL
CC.DLL.DEF = -D_BLD_DLL
CC.DLL.DIR = \$(BINDIR)
CC.DLL.LIBRARIES =
CC.DLL.VARIANTS =
CC.DYNAMIC =
CC.EXPORT.DYNAMIC =
CC.LD = $ld
CC.LD.DYNAMIC = -Bdynamic
CC.LD.LAZY =
CC.LD.NOLAZY =
CC.LD.ORIGIN =
CC.LD.RECORD =
CC.LD.NORECORD =
CC.LD.RUNPATH =
CC.LD.STATIC = -Bstatic
CC.LD.STRIP =
CC.LIB.DLL = option
CC.LIB.ALL = -Bwhole-archive
CC.LIB.UNDEF = -Bno-whole-archive
CC.MAKE.OPTIONS = nativepp=0
CC.NM = nm
CC.NMEDIT =
CC.NMFLAGS =
CC.OPTIMIZE = -O
CC.PIC =
CC.PICBIG =
CC.READONLY =
CC.REPOSITORY =
CC.SHARED = -G
CC.SHARED.LD = $ld
CC.SHARED.REGISTRY =
CC.SHARED.REGISTRY.PATH =
CC.SHELLMAGIC =
CC.SIZE = size
CC.STATIC = -Bstatic
!
		inc=
		lib=
		if	[[ ${version[LCC]} ]]
		then	lib=/lcc
		fi
		if	[[ $stdinclude == *' '* ]]
		then	stdinclude=${stdinclude//' '/''}
		fi
		stdinc=
		stdlib=
		for inc in $stdinclude
		do	stdinc="$stdinc $inc"
			d=${inc%/*}/lib
			if	[[ -d $d ]]
			then	stdlib="$stdlib $d"
			fi
		done
		case $uwin in
		[0-9]*)	cat <<!
CC.STDINCLUDE = /usr/include $stdinc
CC.STDLIB = /usr/lib$lib $stdlib
!
			;;
		*)	cat <<!
CC.STDINCLUDE = $stdinc
CC.STDLIB = $stdlib
!
			;;
		esac
		cat <<!
CC.STRICT =
CC.STRIP = strip
CC.STRIP.FLAGS =
CC.PREFIX.ARCHIVE = lib
CC.PREFIX.DYNAMIC =
CC.PREFIX.SHARED =
CC.PREFIX.SYMBOL = _
CC.SUFFIX.ARCHIVE = .a
CC.SUFFIX.COMMAND =
CC.SUFFIX.DEBUG = .pdb
CC.SUFFIX.DYNAMIC = .dll
CC.SUFFIX.LD = .def .exp .ign .res
CC.SUFFIX.OBJECT = .o
CC.SUFFIX.SHARED = .lib
CC.SUFFIX.SOURCE = .c
CC.SUFFIX.STATIC =
!
		if	[[ $v ]]
		then	case $v in
			*\"*)	v=$(print -r -- | sed -e 's,",\\",g' -e 's,^ ,,' -e 's,.*,"&",') ;;
			*\'*)	v=\"$v\" ;;
			esac
			cat <<!
CC.VERSION = -v
CC.VERSION.STRING = $v
!
		else	cat <<!
CC.VERSION =
CC.VERSION.STRING =
!
		fi
		if	[[ ${version[MINGW]} || ${version[MS]} ]]
		then	cat <<!
CC.WARN = -Wall
!
		else	cat <<!
CC.WARN =
!
		fi
		cat <<!
CC.PREROOT =
CC.UNIVERSE = att
!
	} >&3
	exit 0
fi