1: 2# @(#)probe.win32 (AT&T Research) 2009-03-19 3# 4# win32 specific pp 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 make probe.ini 10 11IFS=$'\n' 12 13chmod 777 . 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 make probe.ini 127 128pragexpand='#pragma pp:pragmaexpand' 129 130if [[ ${version[BORLAND]} ]] 131then version=${version[BORLAND]} VERSION=__BORLANDC__ 132 reserved="#pragma pp:reserved __asm=GROUP __based=GROUP __cdecl __declspec=GROUP __except __export __far __fastcall __finally __huge __inline __int16 __int32 __int64 __int8 __leave __near __novtordisp __pascal __restrict __stdcall __syscall __try __unaligned __wchar_t 133#pragma pp:reserved _asm=GROUP _based=GROUP _cdecl _declspec=GROUP _except _export _far _fastcall _finally _fortran _huge _int16 _int32 _int64 _int8 _leave _near _pascal _stdcall _syscall _try 134#pragma pp:reserved cdecl const enum far fortran huge near pascal signed void volatile" 135 specific="#define <long long> __int64 136#define <__int64 int> __int64 137#define <__int64 unsigned> unsigned __int64" 138 pragexpand='#pragma pp:nopragmaexpand' 139 pragmas="#pragma pp:nocatliteral 140#pragma pp:stringsplit 141#pragma pp:lineid line" 142elif [[ ${version[DM]} ]] 143then version=${version[DM]} VERSION=__DMC__ 144 reserved="#pragma pp:reserved _Bool _Complex _Imaginary asm=GROUP _asm=GROUP __asm=GROUP const enum _fortran __inline _int64 __int64 __restrict signed void volatile _based=GROUP __based=GROUP cdecl _cdecl __cdecl _declspec=GROUP __declspec=GROUP _except __except _export __export far _far __far _fastcall __fastcall _finally __finally huge _huge __huge _interrupt __interrupt _leave __leave _loadds __loadds near _near __near pascal _pascal __pascal _saveregs __saveregs _segname __segname _stdcall __stdcall _syscall __syscall _try __try _cs __cs _ss __ss _unaligned __unaligned" 145 specific="#define __TIMESTAMP__ __DATE__ \" \" __TIME__" 146 pragmas="#pragma pp:transition 147#pragma pp:elseif 148#pragma pp:lineid line" 149elif [[ ${version[MS]} ]] 150then version=${version[MS]} VERSION=_MSC_VER 151 reserved="#pragma pp:reserved __asm=GROUP __based=GROUP __cdecl __declspec=GROUP __except __export __far __fastcall __finally __huge __inline __int16 __int32 __int64 __int8 __leave __near __novtordisp __pascal __restrict __stdcall __syscall __try __unaligned __wchar_t 152#pragma pp:reserved _asm=GROUP _based=GROUP _cdecl _declspec=GROUP _except _export _far _fastcall _finally _fortran _huge _int16 _int32 _int64 _int8 _leave _near _pascal _stdcall _syscall _try 153#pragma pp:reserved cdecl const enum far fortran huge near pascal signed void volatile" 154 specific="#define <long long> __int64 155#define <__int64 int> __int64 156#define <__int64 unsigned> unsigned __int64" 157 pragmas="#pragma pp:lineid line" 158elif [[ ${version[LCC]} ]] 159then version=${version[LCC]} VERSION=__LCC__ 160 reserved="#pragma pp:reserved _Bool _Complex _asm=GROUP const enum inline __inline __int64 restrict signed void volatile _cdecl __cdecl __declspec=GROUP __except _huge _stdcall __stdcall __try" 161 specific="#pragma pp:map \"/#(pragma )?import>/\" \"/#(pragma )?import(.*)/__STDPP__IMPORT__(\2)/\" 162#macdef __STDPP__IMPORT__(x) 163#pragma pp:noallmultiple 164#include x 165#pragma pp:allmultiple 166#endmac 167" 168 pragmas="#pragma pp:hostedtransition 169#pragma pp:strict 170#pragma pp:spaceout 171#pragma pp:elseif 172" 173elif [[ ${version[MINGW]} ]] 174then version=${version[MINGW]} VERSION=__MINGW32__ 175 reserved="#pragma pp:reserved __declspec=GROUP __alignof=GROUP __alignof__=GROUP __attribute=GROUP __attribute__=GROUP __extension__=GROUP asm=GROUP __asm=GROUP __asm__=GROUP const __const __const__ enum inline __inline __inline__ __restrict __restrict__ signed __signed __signed__ typeof=GROUP __typeof=GROUP __typeof__=GROUP void volatile __volatile __volatile__ __cdecl _stdcall __stdcall" 176 specific="#define __declspec(x) __attribute__((x))" 177 pragexpand='#pragma pp:nopragmaexpand' 178 pragmas='#pragma pp:map "/#include_next>/" ",[^\<]*\<,#include <.../," 179#pragma pp:lineid 180#pragma pp:linetype 2' 181fi 182 183undef_predef= 184echo "char* fun() { return (char*)__FUNCTION__; } 185int main() { return !fun(); }" > easy.c 186rm -f easy.exe 187if $cc -o easy.exe easy.c && test -x easy.exe 188then undef_predef="$undef_predef 189#undef __FUNCTION__" 190fi 191 192dialect=ansi 193if [[ $cplus ]] 194then dialect=C++ 195fi 196 197if [[ $version == [0-9]* && $stdinclude ]] 198then hosttype=$(package) 199 machine=${hosttype#*.} 200 case $uwin in 201 [0-9]*) standard=" 202#pragma pp:include \"/usr/include\"" 203 assert=" 204#define #system(unix) 205#define #release(V) 206#define #release(system5) 207#define #version(${version})" 208 ;; 209 *) predefined="" 210 standard="" 211 assert="" 212 ;; 213 esac 214 for inc in $stdinclude 215 do standard="$standard 216#pragma pp:include \"$inc\"" 217 done 218 : the payoff 219 set -- $cc 220 cmd=$1 221 shift 222 set -- $(whence $cmd) "$@" 223 if "$@" -v >/dev/null 2>&1 224 then v=$("$@" -v 2>/dev/null) 225 if [[ $v ]] 226 then v=";VERSION;-v;$v;PATH;$*" 227 fi 228 else v= 229 fi 230 if [[ ! $v ]] 231 then v="$*" 232 fi 233 cat >&3 <<! 234/* $v 235*/ 236 237#pragma pp:predefined 238#define _STD_INCLUDE_DIR ... 239#define _${machine}_ 1 240! 241 { 242 cat <<'!' 243#ifdef unix 244char* str_unix = "#define unix" unix ; 245char* str___unix__ = "#define __unix__" 1 ; 246#else 247#ifdef __unix__ 248char* str___unix__ = "#define __unix__" __unix__ ; 249#endif 250#endif 251! 252 premac=" 253M_I86 254M_I386 255M_I386CM 256M_I386LM 257M_I386MM 258M_I386SM 259MSDOS 260NO_EXT_KEYS 261_ALPHA_ 262_AXP64_ 263_CPPUNWIND 264_GENIA64_ 265_INTEGRAL_MAX_BITS 266_MSC_EXTENSIONS 267_MSC_VER 268_M_ALPHA 269_M_ALPHA_ 270_M_AMD64 271_M_IA64 272_M_IX86 273_M_MRX000 274_M_PPC 275_NTSYSTEM_ 276_POSIX_ 277_PUSHPOP_SUPPORTED 278_STDCALL_SUPPORTED 279_UWIN 280_WIN32 281_WIN64 282_X64_ 283_X86_ 284_stdcall 285__BORLANDC__ 286__CHAR_SIGNED__ 287__CHAR_UNSIGNED__ 288__COMPACT__ 289__DEFALIGN 290__DMC__ 291__DOS__ 292__ECL__ 293__EDG__ 294__FLAT__ 295__FPCE__ 296__FPI__ 297__GNUC__ 298__GNUC_MINOR__ 299__GNUG__ 300__HUGE__ 301__I86__ 302__ICL 303__INITIAL_POINTER_SIZE 304__INLINE_8087 305__INLINE__FUNCTIONS__ 306__INTEL_COMPILER 307__INTERIX 308__INTSIZE 309__LARGE__ 310__LCCDEBUGLEVEL 311__LCCOPTIMLEVEL 312__LCC__ 313__MEDIUM__ 314__MINGW32__ 315__MSVCRT__ 316__NT__ 317__OPENNT 318__OS2__ 319__QNX__ 320__SC__ 321__SMALL__ 322__STATIC__ 323__STDC__ 324__STDC_HOSTED__ 325__STDC_IEC_559__ 326__STDC_IEC_559_COMPLEX__ 327__STDC_ISO_10646__ 328__STDC_VERSION__ 329__STRLEN 330__TURBOC__ 331__WATCOMC__ 332__WIN32__ 333__WINDOWS__ 334__WINDOWS_386__ 335__WINVER__ 336__ZTC__ 337__cdecl 338__cplusplus 339__i386 340__i386__ 341__i486 342__i486__ 343__i586 344__i586__ 345__i686 346__i686__ 347__k6 348__k6__ 349__pentium 350__pentium__ 351__pentiumpro 352__pentiumpro__ 353__stdcall 354" 355 echo "#define s(x) #x" 356 echo "#define q(x) s(x)" 357 for i in $premac 358 do echo "#ifdef $i" 359 echo "char* str_$i = \"#define $i\" q(:$i:);" 360 echo "#endif" 361 done 362 } > easy.c 363 $cc -E easy.c > easy.out 2>&1 364 sed -e '/=/!d' -e 's,[^"]*,echo ,' -e 's/":/"/' -e 's/:"/"/' easy.out > easy.sh 365 . ./easy.sh >&3 366 if [[ $cc == *CC ]] 367 then src=cpp 368 else src=c 369 fi 370 print 'typedef char wchar_t;' > easy.$src 371 if ! $cc -c easy.$src >/dev/null 2>&1 372 then print -u3 '#define _WCHAR_T_DEFINED 1' 373 print -u3 '#define _NATIVE_WCHAR_T_DEFINED 1' 374 if [[ ! $reserved ]] 375 then reserved="#pragma pp:reserved" 376 fi 377 reserved="$reserved wchar_t" 378 fi 379 cat >&3 <<! 380#pragma pp:nopredefined 381 382$specific 383 384#define #hosttype(${hosttype})${assert} 385#define #architecture(${machine}) 386#define #model() 387#define #machine(${machine}) 388#define #addressing() 389#define #preroot() 390#define #universe(att) 391#define #dialect(${dialect}) 392$undef_predef 393 394$reserved 395 396$pragmas 397 398#pragma pp:pluscomment 399$pragexpand 400#pragma pp:zeof 401#pragma pp:id "$"${standard} 402#pragma pp:nocatliteral 403#pragma pp:stringsplit 404#pragma pp:headerexpand 405#pragma pp:map "/#(pragma )?ident>/" 406#pragma pp:map "/#pragma lint:/" ",#pragma lint:(.*),##/*\1*/,u" 407#pragma pp:map "/#(pragma )?sccs>/" 408#pragma pp:map "/#pragma once/" ",#pragma once,#pragma pp:nomultiple," 409#pragma pp:map "/#pragma comment.*linker.*manifest/" 410! 411 exit 0 412fi 413