1*906afcb8SAndy Fiddaman: 2*906afcb8SAndy Fiddaman### this script contains archaic constructs that work with all sh variants ### 3*906afcb8SAndy Fiddaman# Glenn Fowler 4*906afcb8SAndy Fiddaman# AT&T Research 5*906afcb8SAndy Fiddaman# 6*906afcb8SAndy Fiddaman# @(#)C probe (AT&T Research) 2012-02-29 7*906afcb8SAndy Fiddaman# 8*906afcb8SAndy Fiddaman# probe [ -d ] c-compiler-path [ attributes ] 9*906afcb8SAndy Fiddaman# 10*906afcb8SAndy Fiddaman# common C probe preamble for the tool specific probes 11*906afcb8SAndy Fiddaman# 12*906afcb8SAndy Fiddaman# NOTE: some cc -E's do syntax analysis! 13*906afcb8SAndy Fiddaman 14*906afcb8SAndy Fiddaman# 15*906afcb8SAndy Fiddaman# probe_* are first eval'd and then attempted from left to right 16*906afcb8SAndy Fiddaman# 17*906afcb8SAndy Fiddaman 18*906afcb8SAndy Fiddamanprobe_binding="-dy -dn -Bdynamic -Bstatic '-Wl,-ashared -Wl,+s' -Wl,-aarchive -call_shared -non_shared -dynamic -static -bshared -bstatic '' -static" 19*906afcb8SAndy Fiddamanprobe_env="CC_OPTIONS CCOPTS LD_OPTIONS LDOPTS LIBPATH LPATH" 20*906afcb8SAndy Fiddamanprobe_include="stdio.h iostream.h complex.h ctype.h plot.h stdarg.h varargs.h ranlib.h hash.h sys/types.h stab.h cmath cstdio iostream string" 21*906afcb8SAndy Fiddamanprobe_longlong="long 'long long'" 22*906afcb8SAndy Fiddamanprobe_longlong_t="__int64_t _int64_t __int64 _int64 int64" 23*906afcb8SAndy Fiddamanprobe_l="l yyreject m sin mopt sin" 24*906afcb8SAndy Fiddamanprobe_lxx="C exit ++ exit g++ exit" 25*906afcb8SAndy Fiddamanprobe_ppprefix="a n" 26*906afcb8SAndy Fiddamanprobe_size="size" 27*906afcb8SAndy Fiddamanprobe_src="cxx C cc c" 28*906afcb8SAndy Fiddamanprobe_sa=".sa" 29*906afcb8SAndy Fiddamanprobe_sd=".dll .lib .dll .x" 30*906afcb8SAndy Fiddamanprobe_sdb=".pdb" 31*906afcb8SAndy Fiddamanprobe_so=".dylib .so .sl" 32*906afcb8SAndy Fiddamanprobe_symprefix="_" 33*906afcb8SAndy Fiddamanprobe_verbose="'-v -v' '-# -#' '-d -d' -dryrun '-V -V'" 34*906afcb8SAndy Fiddamanprobe_version="--version -V -version -v" 35*906afcb8SAndy Fiddaman 36*906afcb8SAndy Fiddaman# 37*906afcb8SAndy Fiddaman# the following are set by the preamble for the tool specific probe 38*906afcb8SAndy Fiddaman# 39*906afcb8SAndy Fiddaman 40*906afcb8SAndy Fiddamancc=cc 41*906afcb8SAndy Fiddamandebug= 42*906afcb8SAndy Fiddamandir=. 43*906afcb8SAndy Fiddamandll=.dll 44*906afcb8SAndy Fiddamandynamic= 45*906afcb8SAndy Fiddamanexe=exe 46*906afcb8SAndy Fiddamanexecutable="test -x" 47*906afcb8SAndy Fiddamanhosted= 48*906afcb8SAndy Fiddamanifs=${IFS-' 49*906afcb8SAndy Fiddaman '} 50*906afcb8SAndy Fiddamanobj=o 51*906afcb8SAndy Fiddamanppenv= 52*906afcb8SAndy Fiddamanppopt= 53*906afcb8SAndy Fiddamanpredef= 54*906afcb8SAndy Fiddamanprepred= 55*906afcb8SAndy Fiddamansa= 56*906afcb8SAndy Fiddamansd= 57*906afcb8SAndy Fiddamansdb= 58*906afcb8SAndy Fiddamanso= 59*906afcb8SAndy Fiddamansov= 60*906afcb8SAndy Fiddamanstatic= 61*906afcb8SAndy Fiddamanstdlib= 62*906afcb8SAndy Fiddamanstdpp= 63*906afcb8SAndy Fiddamansuffix_command= 64*906afcb8SAndy Fiddamanif test "" != "$TMPDIR" -a -d "$TMPDIR" 65*906afcb8SAndy Fiddamanthen tmpdir=$TMPDIR 66*906afcb8SAndy Fiddamanelse tmpdir=/tmp 67*906afcb8SAndy Fiddamanfi 68*906afcb8SAndy Fiddamantmpdir=$tmpdir/probe$$ 69*906afcb8SAndy Fiddamanundef="define defined elif else endif error if ifdef ifndef include line pragma undef __STDC__ __STDPP__ __ARGC__ __BASE__ __BASE_FILE__ __DATE__ __FILE__ __FUNCTION__ __INCLUDE_LEVEL__ __LINE__ __PATH__ __TIME__ __TIMESTAMP__ __VERSION__" 70*906afcb8SAndy Fiddamanversion_flags= 71*906afcb8SAndy Fiddamanversion_stamp= 72*906afcb8SAndy Fiddamanversion_string= 73*906afcb8SAndy Fiddaman 74*906afcb8SAndy Fiddaman# 75*906afcb8SAndy Fiddaman# constrain the environment 76*906afcb8SAndy Fiddaman# 77*906afcb8SAndy Fiddaman 78*906afcb8SAndy FiddamanDISPLAY= 79*906afcb8SAndy FiddamanLC_ALL=C 80*906afcb8SAndy Fiddamanexport DISPLAY LC_ALL 81*906afcb8SAndy Fiddaman 82*906afcb8SAndy Fiddaman# 83*906afcb8SAndy Fiddaman# now the common probes 84*906afcb8SAndy Fiddaman# 85*906afcb8SAndy Fiddaman 86*906afcb8SAndy Fiddamanwhile : 87*906afcb8SAndy Fiddamando case $1 in 88*906afcb8SAndy Fiddaman -d) debug=1 ;; 89*906afcb8SAndy Fiddaman -*) set ''; break ;; 90*906afcb8SAndy Fiddaman *) break ;; 91*906afcb8SAndy Fiddaman esac 92*906afcb8SAndy Fiddaman shift 93*906afcb8SAndy Fiddamandone 94*906afcb8SAndy Fiddaman 95*906afcb8SAndy Fiddamancc=$1 96*906afcb8SAndy Fiddamancase $cc in 97*906afcb8SAndy Fiddaman[\\/]*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:\\*) 98*906afcb8SAndy Fiddaman ;; 99*906afcb8SAndy Fiddaman*) echo "Usage: $0 [ -d ] c-compiler-path [ attributes ]" >&2 100*906afcb8SAndy Fiddaman exit 1 101*906afcb8SAndy Fiddaman ;; 102*906afcb8SAndy Fiddamanesac 103*906afcb8SAndy FiddamanATTRIBUTES= 104*906afcb8SAndy Fiddamaneval $2 105*906afcb8SAndy Fiddaman_probe_PATH=$PATH 106*906afcb8SAndy FiddamanPATH=/usr/bin:/bin:$PATH 107*906afcb8SAndy Fiddaman 108*906afcb8SAndy Fiddamancase $0 in 109*906afcb8SAndy Fiddaman*[\\/]*) dir=`echo $0 | sed -e 's,[\\/][\\/]*[^\\/]*\$,,'` ;; 110*906afcb8SAndy Fiddamanesac 111*906afcb8SAndy Fiddaman 112*906afcb8SAndy Fiddaman$executable . 2>/dev/null || executable='test -r' 113*906afcb8SAndy Fiddaman 114*906afcb8SAndy Fiddamancase $SHELL in 115*906afcb8SAndy Fiddaman[\\/]*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:\\*) 116*906afcb8SAndy Fiddaman sh=$SHELL 117*906afcb8SAndy Fiddaman ;; 118*906afcb8SAndy Fiddaman*) sh=/bin/sh 119*906afcb8SAndy Fiddaman ;; 120*906afcb8SAndy Fiddamanesac 121*906afcb8SAndy Fiddaman 122*906afcb8SAndy Fiddamantrap 'code=$?; cd ..; rm -rf $tmpdir; exit $code' 0 1 2 3 123*906afcb8SAndy Fiddamanmkdir $tmpdir 124*906afcb8SAndy Fiddamancd $tmpdir 125*906afcb8SAndy Fiddaman 126*906afcb8SAndy Fiddamanexec 3>&1 4>&2 </dev/null 127*906afcb8SAndy Fiddamancase $debug in 128*906afcb8SAndy Fiddaman"") exec >/dev/null 2>&1 129*906afcb8SAndy Fiddaman (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0 130*906afcb8SAndy Fiddaman ;; 131*906afcb8SAndy Fiddaman*) PS4='+$LINENO+ ' 132*906afcb8SAndy Fiddaman set -x 133*906afcb8SAndy Fiddaman ;; 134*906afcb8SAndy Fiddamanesac 135*906afcb8SAndy Fiddaman 136*906afcb8SAndy Fiddamanif (xxx=xxx; unset xxx) 137*906afcb8SAndy Fiddamanthen UNSET=1 138*906afcb8SAndy Fiddamanelse UNSET= 139*906afcb8SAndy Fiddamanfi 140*906afcb8SAndy Fiddamaneval set x $probe_env 141*906afcb8SAndy Fiddamanwhile : 142*906afcb8SAndy Fiddamando shift 143*906afcb8SAndy Fiddaman case $# in 144*906afcb8SAndy Fiddaman 0) break ;; 145*906afcb8SAndy Fiddaman esac 146*906afcb8SAndy Fiddaman eval x='$'$1 147*906afcb8SAndy Fiddaman case $x in 148*906afcb8SAndy Fiddaman '') continue ;; 149*906afcb8SAndy Fiddaman esac 150*906afcb8SAndy Fiddaman case $1 in 151*906afcb8SAndy Fiddaman *PATH) _probe_export="$_probe_export $1='$x'" ;; 152*906afcb8SAndy Fiddaman esac 153*906afcb8SAndy Fiddaman case $UNSET in 154*906afcb8SAndy Fiddaman '') eval $1= 155*906afcb8SAndy Fiddaman export $1 156*906afcb8SAndy Fiddaman ;; 157*906afcb8SAndy Fiddaman *) unset $1 158*906afcb8SAndy Fiddaman ;; 159*906afcb8SAndy Fiddaman esac 160*906afcb8SAndy Fiddamandone 161*906afcb8SAndy Fiddaman 162*906afcb8SAndy Fiddamanif test -f "$dir/probe.ini" 163*906afcb8SAndy Fiddamanthen . "$dir/probe.ini" 164*906afcb8SAndy Fiddaman IFS=$ifs 165*906afcb8SAndy Fiddamanfi 166*906afcb8SAndy Fiddaman 167*906afcb8SAndy Fiddamanmkdir suffix 168*906afcb8SAndy Fiddamancd suffix 169*906afcb8SAndy Fiddamanfor src in $probe_src 170*906afcb8SAndy Fiddamando echo "int main(){return 0;}" > ../test.$src 171*906afcb8SAndy Fiddaman rm -f test* 172*906afcb8SAndy Fiddaman if $cc -c ../test.$src 173*906afcb8SAndy Fiddaman then set test.* 174*906afcb8SAndy Fiddaman if test -f "$1" 175*906afcb8SAndy Fiddaman then o="$*" 176*906afcb8SAndy Fiddaman mv $* .. 177*906afcb8SAndy Fiddaman for i in $o 178*906afcb8SAndy Fiddaman do if $cc -o test.exe ../$i 179*906afcb8SAndy Fiddaman then obj=`echo "$i" | sed -e 's,test.,,'` 180*906afcb8SAndy Fiddaman $executable test.exe || executable="test -r" 181*906afcb8SAndy Fiddaman set test* 182*906afcb8SAndy Fiddaman rm * 183*906afcb8SAndy Fiddaman if $cc -o test ../$i 184*906afcb8SAndy Fiddaman then rm $* 185*906afcb8SAndy Fiddaman set test.* 186*906afcb8SAndy Fiddaman if $executable "$1" 187*906afcb8SAndy Fiddaman then exe=`echo "$1" | sed -e 's,test.,,'` 188*906afcb8SAndy Fiddaman suffix_command=.$exe 189*906afcb8SAndy Fiddaman fi 190*906afcb8SAndy Fiddaman fi 191*906afcb8SAndy Fiddaman break 2 192*906afcb8SAndy Fiddaman fi 193*906afcb8SAndy Fiddaman done 194*906afcb8SAndy Fiddaman fi 195*906afcb8SAndy Fiddaman fi 196*906afcb8SAndy Fiddamandone 197*906afcb8SAndy Fiddamancd .. 198*906afcb8SAndy Fiddaman 199*906afcb8SAndy Fiddamancase $src in 200*906afcb8SAndy Fiddamanc) ;; 201*906afcb8SAndy Fiddaman*) echo '// ( 202*906afcb8SAndy Fiddamanint 203*906afcb8SAndy Fiddamanmain() 204*906afcb8SAndy Fiddaman{ 205*906afcb8SAndy Fiddaman class { public: int i; } j; 206*906afcb8SAndy Fiddaman j.i = 0; 207*906afcb8SAndy Fiddaman int k = j.i + 1; 208*906afcb8SAndy Fiddaman return k; 209*906afcb8SAndy Fiddaman}' > dialect.$src 210*906afcb8SAndy Fiddaman if $cc -c dialect.$src && $cc -o dialect.$exe dialect.$obj && $executable dialect.$exe 211*906afcb8SAndy Fiddaman then mv dialect.$src dialect.c 212*906afcb8SAndy Fiddaman rm -f dialect.$obj dialect.$exe 213*906afcb8SAndy Fiddaman if $cc -c dialect.c && $cc -o dialect.$exe dialect.$obj && $executable dialect.$exe 214*906afcb8SAndy Fiddaman then src=c 215*906afcb8SAndy Fiddaman else set x $cc 216*906afcb8SAndy Fiddaman while : 217*906afcb8SAndy Fiddaman do shift 218*906afcb8SAndy Fiddaman case $# in 219*906afcb8SAndy Fiddaman 0) break ;; 220*906afcb8SAndy Fiddaman esac 221*906afcb8SAndy Fiddaman case $1 in 222*906afcb8SAndy Fiddaman *=*) continue ;; 223*906afcb8SAndy Fiddaman esac 224*906afcb8SAndy Fiddaman case `echo $1 | sed -e 's,.*/,,'` in 225*906afcb8SAndy Fiddaman *CC*|*++*|*[xX][xX]*|*[pP][lL][uU][sS]*) ;; 226*906afcb8SAndy Fiddaman *) src=c ;; 227*906afcb8SAndy Fiddaman esac 228*906afcb8SAndy Fiddaman break 229*906afcb8SAndy Fiddaman done 230*906afcb8SAndy Fiddaman fi 231*906afcb8SAndy Fiddaman else src=c 232*906afcb8SAndy Fiddaman fi 233*906afcb8SAndy Fiddaman ;; 234*906afcb8SAndy Fiddamanesac 235*906afcb8SAndy Fiddaman 236*906afcb8SAndy Fiddamanset x x '(' 1 'int x;' 0 237*906afcb8SAndy Fiddamanwhile : 238*906afcb8SAndy Fiddamando shift 239*906afcb8SAndy Fiddaman shift 240*906afcb8SAndy Fiddaman case $# in 241*906afcb8SAndy Fiddaman [01]) break ;; 242*906afcb8SAndy Fiddaman esac 243*906afcb8SAndy Fiddaman rm -f test.$obj 244*906afcb8SAndy Fiddaman echo "$1" > test.$src 245*906afcb8SAndy Fiddaman $cc -c test.$src 246*906afcb8SAndy Fiddaman r=$? 247*906afcb8SAndy Fiddaman case $r in 248*906afcb8SAndy Fiddaman 0) test -f test.$obj || r=1 ;; 249*906afcb8SAndy Fiddaman *) r=1 ;; 250*906afcb8SAndy Fiddaman esac 251*906afcb8SAndy Fiddaman case $2:$r in 252*906afcb8SAndy Fiddaman 0:0) ;; 253*906afcb8SAndy Fiddaman 0:1) echo "$cc: not a C compiler: failed to compile \`\`$1''" >&4 254*906afcb8SAndy Fiddaman exit 1 255*906afcb8SAndy Fiddaman ;; 256*906afcb8SAndy Fiddaman 1:0) echo "$cc: not a C compiler: successfully compiled \`\`$1''" >&4 257*906afcb8SAndy Fiddaman exit 1 258*906afcb8SAndy Fiddaman ;; 259*906afcb8SAndy Fiddaman esac 260*906afcb8SAndy Fiddamandone 261*906afcb8SAndy Fiddaman 262*906afcb8SAndy Fiddamanhosttype=`package CC="$cc" || $SHELL -c "package CC='$cc'"` 263*906afcb8SAndy Fiddamancase $hosttype in 264*906afcb8SAndy Fiddaman*[Uu][Ss][Aa][Gg][Ee]:*) 265*906afcb8SAndy Fiddaman hosttype=`PATH=$_probe_PATH; export PATH; package CC="$cc" || $SHELL -c "package CC='$cc'"` 266*906afcb8SAndy Fiddaman ;; 267*906afcb8SAndy Fiddamanesac 268*906afcb8SAndy Fiddaman 269*906afcb8SAndy Fiddamanecho '#include <stdio.h> 270*906afcb8SAndy Fiddamanint main(){printf("hello");return 0;}' > dynamic.$src 271*906afcb8SAndy Fiddamanecho 'extern int sfclose() { return 0; }' > fun.$src 272*906afcb8SAndy Fiddamanif $cc -c dynamic.$src && $cc -c fun.$src 273*906afcb8SAndy Fiddamanthen eval set x $probe_so 274*906afcb8SAndy Fiddaman while : 275*906afcb8SAndy Fiddaman do shift 276*906afcb8SAndy Fiddaman case $# in 277*906afcb8SAndy Fiddaman 0) break ;; 278*906afcb8SAndy Fiddaman esac 279*906afcb8SAndy Fiddaman for i in foo junk 280*906afcb8SAndy Fiddaman do rm -f dynamic.$exe 281*906afcb8SAndy Fiddaman if $cc -L. -o dynamic.$exe dynamic.$obj -l$i 282*906afcb8SAndy Fiddaman then : "there's really a -l$i"? 283*906afcb8SAndy Fiddaman else rm -f dynamic.$exe 284*906afcb8SAndy Fiddaman cat fun.$obj > lib$i$1 285*906afcb8SAndy Fiddaman $cc -L. -o dynamic.$exe dynamic.$obj -l$i && $executable dynamic.$exe 286*906afcb8SAndy Fiddaman x=$? 287*906afcb8SAndy Fiddaman rm lib$i$1 288*906afcb8SAndy Fiddaman case $x in 289*906afcb8SAndy Fiddaman 0) so=$1 290*906afcb8SAndy Fiddaman rm -f dynamic.$exe > lib$i$1.1 291*906afcb8SAndy Fiddaman $cc -L. -o dynamic.$exe dynamic.$obj -l$i && $executable dynamic.$exe 292*906afcb8SAndy Fiddaman x=$? 293*906afcb8SAndy Fiddaman rm lib$i$1.1 294*906afcb8SAndy Fiddaman case $x in 295*906afcb8SAndy Fiddaman 0) sov=1 ;; 296*906afcb8SAndy Fiddaman esac 297*906afcb8SAndy Fiddaman break 2 298*906afcb8SAndy Fiddaman ;; 299*906afcb8SAndy Fiddaman *) break 300*906afcb8SAndy Fiddaman ;; 301*906afcb8SAndy Fiddaman esac 302*906afcb8SAndy Fiddaman fi 303*906afcb8SAndy Fiddaman done 304*906afcb8SAndy Fiddaman k= 305*906afcb8SAndy Fiddaman for i in "" .1 .2 .3 .4 .5 .6 .7 .8 .9 306*906afcb8SAndy Fiddaman do rm -f dynamic.$exe > libc$1$i 307*906afcb8SAndy Fiddaman $cc -L. -o dynamic.$exe dynamic.$obj && $executable dynamic.$exe 308*906afcb8SAndy Fiddaman x=$? 309*906afcb8SAndy Fiddaman (cd ..; rm $tmpdir/libc$1$i) 310*906afcb8SAndy Fiddaman case $x in 311*906afcb8SAndy Fiddaman 0) ;; 312*906afcb8SAndy Fiddaman *) k=X$k 313*906afcb8SAndy Fiddaman case $k in 314*906afcb8SAndy Fiddaman XXX) break ;; 315*906afcb8SAndy Fiddaman esac 316*906afcb8SAndy Fiddaman ;; 317*906afcb8SAndy Fiddaman esac 318*906afcb8SAndy Fiddaman done 319*906afcb8SAndy Fiddaman case $k in 320*906afcb8SAndy Fiddaman XXX) so=$1 321*906afcb8SAndy Fiddaman sov=1 322*906afcb8SAndy Fiddaman break 323*906afcb8SAndy Fiddaman ;; 324*906afcb8SAndy Fiddaman ?*) so=$1 325*906afcb8SAndy Fiddaman break 326*906afcb8SAndy Fiddaman ;; 327*906afcb8SAndy Fiddaman esac 328*906afcb8SAndy Fiddaman done 329*906afcb8SAndy Fiddaman rm -f dynamic.$exe 330*906afcb8SAndy Fiddaman if $cc -o dynamic.$exe dynamic.$obj 2>e && $executable dynamic.$exe 331*906afcb8SAndy Fiddaman then e=`wc -l e` 332*906afcb8SAndy Fiddaman maybe= 333*906afcb8SAndy Fiddaman eval set x x $probe_binding 334*906afcb8SAndy Fiddaman while : 335*906afcb8SAndy Fiddaman do shift 336*906afcb8SAndy Fiddaman shift 337*906afcb8SAndy Fiddaman case $# in 338*906afcb8SAndy Fiddaman 0) break ;; 339*906afcb8SAndy Fiddaman esac 340*906afcb8SAndy Fiddaman rm -f dynamic.$exe 341*906afcb8SAndy Fiddaman $cc -o dynamic.$exe $1 dynamic.$obj 2>e && $executable dynamic.$exe || continue 342*906afcb8SAndy Fiddaman case $1 in 343*906afcb8SAndy Fiddaman ?*) case $maybe in 344*906afcb8SAndy Fiddaman "") maybe=$1 ;; 345*906afcb8SAndy Fiddaman *) maybe=-- ;; 346*906afcb8SAndy Fiddaman esac 347*906afcb8SAndy Fiddaman ;; 348*906afcb8SAndy Fiddaman esac 349*906afcb8SAndy Fiddaman case `wc -l e` in 350*906afcb8SAndy Fiddaman $e) ;; 351*906afcb8SAndy Fiddaman *) continue ;; 352*906afcb8SAndy Fiddaman esac 353*906afcb8SAndy Fiddaman d=`ls -s dynamic.$exe` 354*906afcb8SAndy Fiddaman rm -f dynamic.$exe 355*906afcb8SAndy Fiddaman $cc -o dynamic.$exe $2 dynamic.$obj 2>e && $executable dynamic.$exe || continue 356*906afcb8SAndy Fiddaman case `wc -l e` in 357*906afcb8SAndy Fiddaman $e) ;; 358*906afcb8SAndy Fiddaman *) continue ;; 359*906afcb8SAndy Fiddaman esac 360*906afcb8SAndy Fiddaman case `ls -s dynamic.$exe` in 361*906afcb8SAndy Fiddaman $d) ;; 362*906afcb8SAndy Fiddaman *) dynamic=$1 363*906afcb8SAndy Fiddaman static=$2 364*906afcb8SAndy Fiddaman maybe= 365*906afcb8SAndy Fiddaman break 366*906afcb8SAndy Fiddaman ;; 367*906afcb8SAndy Fiddaman esac 368*906afcb8SAndy Fiddaman done 369*906afcb8SAndy Fiddaman case $maybe in 370*906afcb8SAndy Fiddaman ""|--) ;; 371*906afcb8SAndy Fiddaman *) rm -f dynamic.$exe 372*906afcb8SAndy Fiddaman if $cc -o dynamic.$exe $maybe dynamic.$obj 2>e && $executable dynamic.$exe 373*906afcb8SAndy Fiddaman then e=`wc -l e` 374*906afcb8SAndy Fiddaman if $cc -o dynamic.$exe $maybe-bogus-bogus-bogus dynamic.$obj 2>e && $executable dynamic.$exe 375*906afcb8SAndy Fiddaman then case `wc -l e` in 376*906afcb8SAndy Fiddaman $e) ;; 377*906afcb8SAndy Fiddaman *) dynamic=$maybe ;; 378*906afcb8SAndy Fiddaman esac 379*906afcb8SAndy Fiddaman else dynamic=$maybe 380*906afcb8SAndy Fiddaman fi 381*906afcb8SAndy Fiddaman fi 382*906afcb8SAndy Fiddaman ;; 383*906afcb8SAndy Fiddaman esac 384*906afcb8SAndy Fiddaman fi 385*906afcb8SAndy Fiddamanfi 386*906afcb8SAndy Fiddaman 387*906afcb8SAndy Fiddamaneval set x $probe_version 388*906afcb8SAndy Fiddamanshift 389*906afcb8SAndy Fiddamanfor o in "$@" 390*906afcb8SAndy Fiddamando if $cc $o > version.out 2>&1 391*906afcb8SAndy Fiddaman then version_string=`sed -e '/ is /d' -e 's/;/ /g' version.out | sed -e 1q` 392*906afcb8SAndy Fiddaman case $version_string in 393*906afcb8SAndy Fiddaman ''|*[Ee][Rr][Rr][Oo][Rr]*|*[Ff][Aa][Tt][Aa][Ll]*|*[Ww][Aa][Rr][Nn][Ii][Nn][Gg]*|*[Oo][Pp][Tt][Ii][Oo][Nn]*) 394*906afcb8SAndy Fiddaman ;; 395*906afcb8SAndy Fiddaman *) version_flags=$o 396*906afcb8SAndy Fiddaman version_stamp=";VERSION;$o;$version_string;PATH;$cc" 397*906afcb8SAndy Fiddaman break 398*906afcb8SAndy Fiddaman ;; 399*906afcb8SAndy Fiddaman esac 400*906afcb8SAndy Fiddaman fi 401*906afcb8SAndy Fiddamandone 402*906afcb8SAndy Fiddamancase $version_stamp in 403*906afcb8SAndy Fiddaman'') eval set x $probe_version 404*906afcb8SAndy Fiddaman shift 405*906afcb8SAndy Fiddaman echo 'int main() { return 0; }' > version.i 406*906afcb8SAndy Fiddaman for o in "$@" 407*906afcb8SAndy Fiddaman do if $cc -c $o version.i > version.out 2>&1 408*906afcb8SAndy Fiddaman then version_string=`sed -e '/ is /d' -e 's/;/ /g' version.out | sed -e 1q` 409*906afcb8SAndy Fiddaman case $version_string in 410*906afcb8SAndy Fiddaman ''|*[Ee][Rr][Rr][Oo][Rr]*|*[Ff][Aa][Tt][Aa][Ll]*|*[Ww][Aa][Rr][Nn][Ii][Nn][Gg]*|*[Oo][Pp][Tt][Ii][Oo][Nn]*) 411*906afcb8SAndy Fiddaman ;; 412*906afcb8SAndy Fiddaman *) version_flags=$o 413*906afcb8SAndy Fiddaman break 414*906afcb8SAndy Fiddaman ;; 415*906afcb8SAndy Fiddaman esac 416*906afcb8SAndy Fiddaman fi 417*906afcb8SAndy Fiddaman done 418*906afcb8SAndy Fiddaman ;; 419*906afcb8SAndy Fiddamanesac 420*906afcb8SAndy Fiddaman 421*906afcb8SAndy Fiddamanecho 'int main(){return 0;}' > hosted.$src 422*906afcb8SAndy Fiddaman$cc -o hosted.$exe hosted.$src && ./hosted.$exe && hosted=1 423*906afcb8SAndy Fiddaman 424*906afcb8SAndy Fiddamanecho '#!'$sh' 425*906afcb8SAndy Fiddamanecho "" $@' > cpp 426*906afcb8SAndy Fiddamanchmod +x cpp 427*906afcb8SAndy Fiddamancase `./cpp -Dprobe` in 428*906afcb8SAndy Fiddaman*-Dprobe*) 429*906afcb8SAndy Fiddaman ;; 430*906afcb8SAndy Fiddaman*) cp /bin/echo cpp 431*906afcb8SAndy Fiddaman chmod u+w cpp 432*906afcb8SAndy Fiddaman ;; 433*906afcb8SAndy Fiddamanesac 434*906afcb8SAndy Fiddamanfor prefix in $probe_ppprefix `echo $cc | sed -e '/cc\$/!d' -e 's,cc\$,,' -e 's,.*/,,'` 435*906afcb8SAndy Fiddamando cp cpp ${prefix}cpp 436*906afcb8SAndy Fiddamandone 437*906afcb8SAndy Fiddaman 438*906afcb8SAndy Fiddamanecho "" > flags.$src 439*906afcb8SAndy Fiddamanecho '#pragma pp:version' > libpp.$src 440*906afcb8SAndy Fiddaman 441*906afcb8SAndy Fiddamanif test `realcppC=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 442*906afcb8SAndy Fiddamanthen ppenv='realcppC=${ppcmd}' 443*906afcb8SAndy Fiddamanelif test `cppC=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 444*906afcb8SAndy Fiddamanthen ppenv='cppC=${ppcmd}' 445*906afcb8SAndy Fiddamanelif test `_CPPNAME=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 446*906afcb8SAndy Fiddamanthen ppenv='_CPPNAME=${ppcmd}' 447*906afcb8SAndy Fiddamanelif test `_CPP=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 448*906afcb8SAndy Fiddamanthen ppenv='_CPP=${ppcmd}' 449*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -%p+. flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 && test `$cc -Dprobe -E -%p+. flags.$src | wc -l` -eq 1 450*906afcb8SAndy Fiddamanthen ppopt='-%p+${ppdir}' 451*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -Yp,. flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 452*906afcb8SAndy Fiddamanthen ppopt='-Yp,${ppdir}' 453*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -Qpath $tmpdir flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 454*906afcb8SAndy Fiddamanthen ppopt='-Qpath ${ppdir}' 455*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -tp -B./ flags.$src 2>err.out | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 -a ! -s err.out 456*906afcb8SAndy Fiddamanthen ppopt='-tp -B${ppdir}/' 457*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -B./ flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 458*906afcb8SAndy Fiddamanthen ppopt='-B${ppdir}/' 459*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -tp -h./ -B flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 460*906afcb8SAndy Fiddamanthen ppopt='-tp -h${ppdir}/ -B' 461*906afcb8SAndy Fiddamanelif test `$cc -Dprobe -E -t p,./cpp flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 462*906afcb8SAndy Fiddamanthen ppopt='-t p,${ppcmd}' 463*906afcb8SAndy Fiddamanelse { 464*906afcb8SAndy Fiddaman eval set x $probe_verbose 465*906afcb8SAndy Fiddaman shift 466*906afcb8SAndy Fiddaman for o in "$@" 467*906afcb8SAndy Fiddaman do $cc -E $o flags.$src 468*906afcb8SAndy Fiddaman done 469*906afcb8SAndy Fiddaman } 2>&1 | sed -e "s/['\"]//g" > cpp.out 470*906afcb8SAndy Fiddamanfi 471*906afcb8SAndy Fiddaman 472*906afcb8SAndy Fiddamanset x `sed -e 's,[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:\\\\,/,g' -e 's,\\\\,/,g' cpp.out` 473*906afcb8SAndy Fiddamandef= 474*906afcb8SAndy Fiddamandefinclude="-I+C -I-H" 475*906afcb8SAndy Fiddamanstdinclude=$definclude 476*906afcb8SAndy Fiddamancase $hosted in 477*906afcb8SAndy Fiddaman"") usrinclude= ;; 478*906afcb8SAndy Fiddamanesac 479*906afcb8SAndy Fiddamancmdinclude= 480*906afcb8SAndy Fiddamanwhile : 481*906afcb8SAndy Fiddamando case $# in 482*906afcb8SAndy Fiddaman 0|1) break ;; 483*906afcb8SAndy Fiddaman esac 484*906afcb8SAndy Fiddaman shift 485*906afcb8SAndy Fiddaman case $1 in 486*906afcb8SAndy Fiddaman -A) case $2 in 487*906afcb8SAndy Fiddaman *\(*\)) shift 488*906afcb8SAndy Fiddaman prepred="$prepred `echo $1 | sed 's/\(.*\)(\(.*\))/\1 \2/'`" 489*906afcb8SAndy Fiddaman ;; 490*906afcb8SAndy Fiddaman esac 491*906afcb8SAndy Fiddaman ;; 492*906afcb8SAndy Fiddaman -A\(*\)) 493*906afcb8SAndy Fiddaman prepred="$prepred `echo $1 | sed 's/-A\(.*\)(\(.*\))/\1 \2/'`" 494*906afcb8SAndy Fiddaman ;; 495*906afcb8SAndy Fiddaman -[DI][-+][ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) 496*906afcb8SAndy Fiddaman stdpp=1 497*906afcb8SAndy Fiddaman case $1 in 498*906afcb8SAndy Fiddaman -I?[CH]) case $def in 499*906afcb8SAndy Fiddaman ?*) definclude="$definclude $1" ;; 500*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $1" ;; 501*906afcb8SAndy Fiddaman esac 502*906afcb8SAndy Fiddaman ;; 503*906afcb8SAndy Fiddaman -I-S*|-YI,*) usrinclude="`echo $1 | sed 's/....//'`" ;; 504*906afcb8SAndy Fiddaman -Y?,*) ;; 505*906afcb8SAndy Fiddaman -Y*) usrinclude="`echo $1 | sed 's/..//'`" ;; 506*906afcb8SAndy Fiddaman esac 507*906afcb8SAndy Fiddaman ;; 508*906afcb8SAndy Fiddaman -D) shift 509*906afcb8SAndy Fiddaman case $1 in 510*906afcb8SAndy Fiddaman [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*=*) 511*906afcb8SAndy Fiddaman predef="$predef 512*906afcb8SAndy Fiddaman`echo $1 | sed -e 's/=.*//'`" 513*906afcb8SAndy Fiddaman ;; 514*906afcb8SAndy Fiddaman [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*) 515*906afcb8SAndy Fiddaman predef="$predef 516*906afcb8SAndy Fiddaman$1" 517*906afcb8SAndy Fiddaman ;; 518*906afcb8SAndy Fiddaman esac 519*906afcb8SAndy Fiddaman ;; 520*906afcb8SAndy Fiddaman -Dprobe);; 521*906afcb8SAndy Fiddaman -D*) case $1 in 522*906afcb8SAndy Fiddaman -D[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*=*) 523*906afcb8SAndy Fiddaman predef="$predef 524*906afcb8SAndy Fiddaman`echo $1 | sed -e 's/^-D//' -e 's/=.*//'`" 525*906afcb8SAndy Fiddaman ;; 526*906afcb8SAndy Fiddaman -D[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*) 527*906afcb8SAndy Fiddaman predef="$predef 528*906afcb8SAndy Fiddaman`echo $1 | sed -e 's/^-D//'`" 529*906afcb8SAndy Fiddaman ;; 530*906afcb8SAndy Fiddaman esac 531*906afcb8SAndy Fiddaman ;; 532*906afcb8SAndy Fiddaman -I) shift 533*906afcb8SAndy Fiddaman case $1 in 534*906afcb8SAndy Fiddaman /*) case $def in 535*906afcb8SAndy Fiddaman ?*) definclude="$definclude $1" ;; 536*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $1" ;; 537*906afcb8SAndy Fiddaman esac 538*906afcb8SAndy Fiddaman cmdinclude="$cmdinclude $1" 539*906afcb8SAndy Fiddaman ;; 540*906afcb8SAndy Fiddaman esac 541*906afcb8SAndy Fiddaman ;; 542*906afcb8SAndy Fiddaman -I/*) f=`echo X$1 | sed 's/X-I//'` 543*906afcb8SAndy Fiddaman case $def in 544*906afcb8SAndy Fiddaman ?*) definclude="$definclude $f" ;; 545*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $f" ;; 546*906afcb8SAndy Fiddaman esac 547*906afcb8SAndy Fiddaman cmdinclude="$cmdinclude $f" 548*906afcb8SAndy Fiddaman ;; 549*906afcb8SAndy Fiddaman -U) shift 550*906afcb8SAndy Fiddaman undef="$undef $1" 551*906afcb8SAndy Fiddaman ;; 552*906afcb8SAndy Fiddaman -U*) undef="$undef `echo $1 | sed 's/^-U//'`" 553*906afcb8SAndy Fiddaman ;; 554*906afcb8SAndy Fiddaman flags.$src)def= 555*906afcb8SAndy Fiddaman ;; 556*906afcb8SAndy Fiddaman esac 557*906afcb8SAndy Fiddamandone 558*906afcb8SAndy Fiddamanstdinclude="$stdinclude $definclude" 559*906afcb8SAndy Fiddamancase " $stdinclude " in 560*906afcb8SAndy Fiddaman*\ $usrinclude\ *) 561*906afcb8SAndy Fiddaman case $usrinclude in 562*906afcb8SAndy Fiddaman /usr/include) 563*906afcb8SAndy Fiddaman usrinclude= 564*906afcb8SAndy Fiddaman ;; 565*906afcb8SAndy Fiddaman *) case " $stdinclude " in 566*906afcb8SAndy Fiddaman *\ /usr/include\ *) 567*906afcb8SAndy Fiddaman usrinclude= 568*906afcb8SAndy Fiddaman ;; 569*906afcb8SAndy Fiddaman *) usrinclude=/usr/include 570*906afcb8SAndy Fiddaman ;; 571*906afcb8SAndy Fiddaman esac 572*906afcb8SAndy Fiddaman ;; 573*906afcb8SAndy Fiddaman esac 574*906afcb8SAndy Fiddaman ;; 575*906afcb8SAndy Fiddamanesac 576*906afcb8SAndy Fiddaman 577*906afcb8SAndy Fiddamantstinclude=`$cc -v -E flags.$src 2>&1 | sed -e '1,/[iI][nN][cC][lL][uU][dD][eE][ ]*<[.][.][.]>/d' -e '/^[eE][nN][dD] [oO][fF] [sS][eE][aA][rR][cC][hH]/,\$d'` 578*906afcb8SAndy Fiddamanj=$tstinclude 579*906afcb8SAndy Fiddamancase $j in 580*906afcb8SAndy Fiddaman*/*) ;; 581*906afcb8SAndy Fiddaman*) j=$cmdinclude ;; 582*906afcb8SAndy Fiddamanesac 583*906afcb8SAndy Fiddamantstinclude= 584*906afcb8SAndy Fiddamangood= 585*906afcb8SAndy Fiddamannogood= 586*906afcb8SAndy Fiddamanc_hdr="stdio.h ctype.h" 587*906afcb8SAndy FiddamanC_hdr="libc.h" 588*906afcb8SAndy Fiddamanfor i in $j 589*906afcb8SAndy Fiddamando if test -d "$i" 590*906afcb8SAndy Fiddaman then tstinclude="$tstinclude $i" 591*906afcb8SAndy Fiddaman h= 592*906afcb8SAndy Fiddaman for f in $c_hdr 593*906afcb8SAndy Fiddaman do if test -f "$i/$f" 594*906afcb8SAndy Fiddaman then case $i in 595*906afcb8SAndy Fiddaman */CC) nogood=1 ;; 596*906afcb8SAndy Fiddaman *) good=1 ;; 597*906afcb8SAndy Fiddaman esac 598*906afcb8SAndy Fiddaman else h="$h $f" 599*906afcb8SAndy Fiddaman fi 600*906afcb8SAndy Fiddaman done 601*906afcb8SAndy Fiddaman c_hdr=$h 602*906afcb8SAndy Fiddaman h= 603*906afcb8SAndy Fiddaman for f in $C_hdr 604*906afcb8SAndy Fiddaman do if test -f "$i/$f" 605*906afcb8SAndy Fiddaman then case $i in 606*906afcb8SAndy Fiddaman */CC) nogood=1 ;; 607*906afcb8SAndy Fiddaman *) good=1 ;; 608*906afcb8SAndy Fiddaman esac 609*906afcb8SAndy Fiddaman else h="$h $f" 610*906afcb8SAndy Fiddaman fi 611*906afcb8SAndy Fiddaman done 612*906afcb8SAndy Fiddaman C_hdr=$h 613*906afcb8SAndy Fiddaman fi 614*906afcb8SAndy Fiddamandone 615*906afcb8SAndy Fiddamancase $nogood in 616*906afcb8SAndy Fiddaman1) good=0 ;; 617*906afcb8SAndy Fiddamanesac 618*906afcb8SAndy Fiddamancase $good in 619*906afcb8SAndy Fiddaman1) case $c_hdr in 620*906afcb8SAndy Fiddaman ?*) bad=1 621*906afcb8SAndy Fiddaman usrinclude=/usr/include 622*906afcb8SAndy Fiddaman set '' $tstinclude /usr/include 623*906afcb8SAndy Fiddaman ;; 624*906afcb8SAndy Fiddaman *) set '' $tstinclude 625*906afcb8SAndy Fiddaman ;; 626*906afcb8SAndy Fiddaman esac 627*906afcb8SAndy Fiddaman shift 628*906afcb8SAndy Fiddaman stdinclude=$* 629*906afcb8SAndy Fiddaman echo "#include <sys/types.h>" > include.$src 630*906afcb8SAndy Fiddaman $cc -E include.$src | sed -e '/# 1 "[\\/]/!d' -e 's,[^"]*",,' -e 's,[\\/][^\\/]*".*,,' -e 's,[\\/]sys,,' > include.out 631*906afcb8SAndy Fiddaman for f in `cat include.out` 632*906afcb8SAndy Fiddaman do if test -d "$f" 633*906afcb8SAndy Fiddaman then g=`echo $f | sed -e 's,[\\/][\\/]*[^\\/]*$,,'` 634*906afcb8SAndy Fiddaman case " $stdinclude " in 635*906afcb8SAndy Fiddaman *\ $f\ *|*\ $g\ *) 636*906afcb8SAndy Fiddaman ;; 637*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $f" 638*906afcb8SAndy Fiddaman case $f in 639*906afcb8SAndy Fiddaman /usr/include) usrinclude=$f ;; 640*906afcb8SAndy Fiddaman esac 641*906afcb8SAndy Fiddaman bad=1 642*906afcb8SAndy Fiddaman ;; 643*906afcb8SAndy Fiddaman esac 644*906afcb8SAndy Fiddaman fi 645*906afcb8SAndy Fiddaman done 646*906afcb8SAndy Fiddaman ;; 647*906afcb8SAndy Fiddaman*) case $ppopt$ppenv in 648*906afcb8SAndy Fiddaman ?*) echo '#!'$sh' 649*906afcb8SAndy Fiddaman echo $VIRTUAL_ROOT | sed "s/:.*//"' > cpp 650*906afcb8SAndy Fiddaman chmod +x cpp 651*906afcb8SAndy Fiddaman ppcmd=cpp 652*906afcb8SAndy Fiddaman ppdir=. 653*906afcb8SAndy Fiddaman eval x='`'$ppenv '$'cc -E $ppopt flags.$src'`' 654*906afcb8SAndy Fiddaman case $x in 655*906afcb8SAndy Fiddaman ?*) tstinclude=$x/usr/include 656*906afcb8SAndy Fiddaman ;; 657*906afcb8SAndy Fiddaman esac 658*906afcb8SAndy Fiddaman cp /bin/echo cpp 659*906afcb8SAndy Fiddaman chmod u+w cpp 660*906afcb8SAndy Fiddaman ;; 661*906afcb8SAndy Fiddaman esac 662*906afcb8SAndy Fiddaman 663*906afcb8SAndy Fiddaman eval set x $probe_include 664*906afcb8SAndy Fiddaman while : 665*906afcb8SAndy Fiddaman do shift 666*906afcb8SAndy Fiddaman case $# in 667*906afcb8SAndy Fiddaman 0) break ;; 668*906afcb8SAndy Fiddaman esac 669*906afcb8SAndy Fiddaman echo "#include <$1>" > include.$src 670*906afcb8SAndy Fiddaman $cc -E include.$src 671*906afcb8SAndy Fiddaman done > include.out 672*906afcb8SAndy Fiddaman 673*906afcb8SAndy Fiddaman ccinclude= 674*906afcb8SAndy Fiddaman x=$stdinclude 675*906afcb8SAndy Fiddaman stdinclude= 676*906afcb8SAndy Fiddaman subinclude= 677*906afcb8SAndy Fiddaman for f in $x $tstinclude `sed -e 's,\\\\,/,g' -e 's,///*,/,g' -e 's,"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:/,"/,g' -e '/^#[line ]*[0123456789][0123456789]*[ ][ ]*"[\\/]/!d' -e 's/^#[line ]*[0123456789][0123456789]*[ ][ ]*"\(.*\)[\\/].*".*/\1/' include.out | sort -u` 678*906afcb8SAndy Fiddaman do case $f in 679*906afcb8SAndy Fiddaman -*) ;; 680*906afcb8SAndy Fiddaman */) f=`echo $f | sed -e 's,//*\$,,'` ;; 681*906afcb8SAndy Fiddaman */.) f=`echo $f | sed -e 's,//*.\$,,'` ;; 682*906afcb8SAndy Fiddaman esac 683*906afcb8SAndy Fiddaman case $f in 684*906afcb8SAndy Fiddaman -I*) ;; 685*906afcb8SAndy Fiddaman */cc) ccinclude=1 686*906afcb8SAndy Fiddaman ;; 687*906afcb8SAndy Fiddaman */sys) continue 688*906afcb8SAndy Fiddaman ;; 689*906afcb8SAndy Fiddaman */include/*/*) 690*906afcb8SAndy Fiddaman ;; 691*906afcb8SAndy Fiddaman */include/*) 692*906afcb8SAndy Fiddaman subinclude="$subinclude $f" 693*906afcb8SAndy Fiddaman continue 694*906afcb8SAndy Fiddaman ;; 695*906afcb8SAndy Fiddaman esac 696*906afcb8SAndy Fiddaman if test -d "$f" 697*906afcb8SAndy Fiddaman then case " $stdinclude " in 698*906afcb8SAndy Fiddaman *\ $f\ *) ;; 699*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $f" ;; 700*906afcb8SAndy Fiddaman esac 701*906afcb8SAndy Fiddaman fi 702*906afcb8SAndy Fiddaman done 703*906afcb8SAndy Fiddaman rm include.out 704*906afcb8SAndy Fiddaman case $ccinclude in 705*906afcb8SAndy Fiddaman ?*) eval set x $probe_include 706*906afcb8SAndy Fiddaman while : 707*906afcb8SAndy Fiddaman do shift 708*906afcb8SAndy Fiddaman case $# in 709*906afcb8SAndy Fiddaman 0) break ;; 710*906afcb8SAndy Fiddaman esac 711*906afcb8SAndy Fiddaman echo "#include <cc/$1>" > include.$src 712*906afcb8SAndy Fiddaman if $cc -E include.$src > /dev/null 713*906afcb8SAndy Fiddaman then break 714*906afcb8SAndy Fiddaman fi 715*906afcb8SAndy Fiddaman done 716*906afcb8SAndy Fiddaman case $# in 717*906afcb8SAndy Fiddaman 0) ;; 718*906afcb8SAndy Fiddaman *) x=$stdinclude 719*906afcb8SAndy Fiddaman stdinclude= 720*906afcb8SAndy Fiddaman for f in $x 721*906afcb8SAndy Fiddaman do case $f in 722*906afcb8SAndy Fiddaman */cc) ;; 723*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $f" ;; 724*906afcb8SAndy Fiddaman esac 725*906afcb8SAndy Fiddaman done 726*906afcb8SAndy Fiddaman ;; 727*906afcb8SAndy Fiddaman esac 728*906afcb8SAndy Fiddaman ;; 729*906afcb8SAndy Fiddaman esac 730*906afcb8SAndy Fiddaman case $subinclude in 731*906afcb8SAndy Fiddaman ?*) for i in $subinclude 732*906afcb8SAndy Fiddaman do for j in $stdinclude 733*906afcb8SAndy Fiddaman do case $i in 734*906afcb8SAndy Fiddaman $j/*/*) ;; 735*906afcb8SAndy Fiddaman $j/*) both= 736*906afcb8SAndy Fiddaman eval set x $probe_include 737*906afcb8SAndy Fiddaman while : 738*906afcb8SAndy Fiddaman do shift 739*906afcb8SAndy Fiddaman case $# in 740*906afcb8SAndy Fiddaman 0) for k in $both 741*906afcb8SAndy Fiddaman do echo "#include <$k>" > include.$src 742*906afcb8SAndy Fiddaman $cc -E include.$src > include.out 743*906afcb8SAndy Fiddaman I=`grep -c $i/$k < include.out` 744*906afcb8SAndy Fiddaman J=`grep -c $j/$k < include.out` 745*906afcb8SAndy Fiddaman case $I:$J in 746*906afcb8SAndy Fiddaman 0:*) ;; 747*906afcb8SAndy Fiddaman *:0) stdinclude="$i $stdinclude" 748*906afcb8SAndy Fiddaman break 749*906afcb8SAndy Fiddaman ;; 750*906afcb8SAndy Fiddaman esac 751*906afcb8SAndy Fiddaman done 752*906afcb8SAndy Fiddaman continue 3 753*906afcb8SAndy Fiddaman ;; 754*906afcb8SAndy Fiddaman esac 755*906afcb8SAndy Fiddaman if test -f $i/$1 756*906afcb8SAndy Fiddaman then if test ! -f $j/$1 757*906afcb8SAndy Fiddaman then break 2 758*906afcb8SAndy Fiddaman fi 759*906afcb8SAndy Fiddaman both="$both $1" 760*906afcb8SAndy Fiddaman fi 761*906afcb8SAndy Fiddaman done 762*906afcb8SAndy Fiddaman ;; 763*906afcb8SAndy Fiddaman $j) continue 2 764*906afcb8SAndy Fiddaman ;; 765*906afcb8SAndy Fiddaman esac 766*906afcb8SAndy Fiddaman done 767*906afcb8SAndy Fiddaman stdinclude="$i $stdinclude" 768*906afcb8SAndy Fiddaman done 769*906afcb8SAndy Fiddaman ;; 770*906afcb8SAndy Fiddaman esac 771*906afcb8SAndy Fiddaman 772*906afcb8SAndy Fiddaman { 773*906afcb8SAndy Fiddaman 774*906afcb8SAndy Fiddaman for i in $stdinclude 775*906afcb8SAndy Fiddaman do 776*906afcb8SAndy Fiddaman case $i in 777*906afcb8SAndy Fiddaman $usrinclude) ;; 778*906afcb8SAndy Fiddaman *) echo $i $i ;; 779*906afcb8SAndy Fiddaman esac 780*906afcb8SAndy Fiddaman done 781*906afcb8SAndy Fiddaman 782*906afcb8SAndy Fiddaman eval set x $probe_include 783*906afcb8SAndy Fiddaman while : 784*906afcb8SAndy Fiddaman do shift 785*906afcb8SAndy Fiddaman case $# in 786*906afcb8SAndy Fiddaman 0) break ;; 787*906afcb8SAndy Fiddaman esac 788*906afcb8SAndy Fiddaman echo "#include <$1>" > t.c 789*906afcb8SAndy Fiddaman p= 790*906afcb8SAndy Fiddaman for j in `$cc -E t.c | grep "$1" | sed -e 's,\\\\,/,g' -e 's,"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:/,"/,g' -e '/^#[line ]*1[ ][ ]*"[\\/]/!d' -e 's/^#[line ]*1[ ][ ]*"\(.*\)[\\/].*".*/\1/'` 791*906afcb8SAndy Fiddaman do j=`echo $j | sed -e 's,///*,/,g' -e 's,/$,,'` 792*906afcb8SAndy Fiddaman case $p in 793*906afcb8SAndy Fiddaman ?*) echo $p $j ;; 794*906afcb8SAndy Fiddaman esac 795*906afcb8SAndy Fiddaman p=$j 796*906afcb8SAndy Fiddaman done 797*906afcb8SAndy Fiddaman done 798*906afcb8SAndy Fiddaman 799*906afcb8SAndy Fiddaman case $usrinclude in 800*906afcb8SAndy Fiddaman ?*) echo $usrinclude $usrinclude ;; 801*906afcb8SAndy Fiddaman esac 802*906afcb8SAndy Fiddaman 803*906afcb8SAndy Fiddaman } | tsort > tmp.tmp 804*906afcb8SAndy Fiddaman tstinclude=`cat tmp.tmp` 805*906afcb8SAndy Fiddaman bad= 806*906afcb8SAndy Fiddaman for i in $stdinclude 807*906afcb8SAndy Fiddaman do case " 808*906afcb8SAndy Fiddaman$tstinclude 809*906afcb8SAndy Fiddaman" in 810*906afcb8SAndy Fiddaman *" 811*906afcb8SAndy Fiddaman$i 812*906afcb8SAndy Fiddaman"*) ;; 813*906afcb8SAndy Fiddaman *) bad=1 814*906afcb8SAndy Fiddaman break 815*906afcb8SAndy Fiddaman ;; 816*906afcb8SAndy Fiddaman esac 817*906afcb8SAndy Fiddaman done 818*906afcb8SAndy Fiddaman ;; 819*906afcb8SAndy Fiddamanesac 820*906afcb8SAndy Fiddaman 821*906afcb8SAndy Fiddamancase $bad in 822*906afcb8SAndy Fiddaman"") x=$stdinclude 823*906afcb8SAndy Fiddaman stdinclude= 824*906afcb8SAndy Fiddaman z= 825*906afcb8SAndy Fiddaman for i in $tstinclude 826*906afcb8SAndy Fiddaman do case " $x " in 827*906afcb8SAndy Fiddaman *" $i "*) 828*906afcb8SAndy Fiddaman stdinclude="$stdinclude $i" 829*906afcb8SAndy Fiddaman z=$i 830*906afcb8SAndy Fiddaman ;; 831*906afcb8SAndy Fiddaman esac 832*906afcb8SAndy Fiddaman done 833*906afcb8SAndy Fiddaman case $usrinclude in 834*906afcb8SAndy Fiddaman '') usrinclude=$z ;; 835*906afcb8SAndy Fiddaman esac 836*906afcb8SAndy Fiddaman ;; 837*906afcb8SAndy Fiddamanesac 838*906afcb8SAndy Fiddamancase $hosted in 839*906afcb8SAndy Fiddaman"") case $usrinclude in 840*906afcb8SAndy Fiddaman /usr/include) usrinclude= ;; 841*906afcb8SAndy Fiddaman esac 842*906afcb8SAndy Fiddaman ;; 843*906afcb8SAndy Fiddamanesac 844*906afcb8SAndy Fiddaman 845*906afcb8SAndy Fiddamancase $usrinclude in 846*906afcb8SAndy Fiddaman?*) case " $stdinclude " in 847*906afcb8SAndy Fiddaman *\ $usrinclude\ *) 848*906afcb8SAndy Fiddaman x=$stdinclude 849*906afcb8SAndy Fiddaman stdinclude= 850*906afcb8SAndy Fiddaman for f in $x 851*906afcb8SAndy Fiddaman do case $f in 852*906afcb8SAndy Fiddaman $usrinclude) ;; 853*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $f" ;; 854*906afcb8SAndy Fiddaman esac 855*906afcb8SAndy Fiddaman done 856*906afcb8SAndy Fiddaman ;; 857*906afcb8SAndy Fiddaman esac 858*906afcb8SAndy Fiddaman ;; 859*906afcb8SAndy Fiddamanesac 860*906afcb8SAndy Fiddaman 861*906afcb8SAndy Fiddaman# drop dups -- they creep in somehow 862*906afcb8SAndy Fiddaman 863*906afcb8SAndy Fiddamanx=$stdinclude 864*906afcb8SAndy Fiddamanstdinclude= 865*906afcb8SAndy Fiddamanfor f in $x 866*906afcb8SAndy Fiddamando case " $stdinclude $usrinclude " in 867*906afcb8SAndy Fiddaman *" $f "*) ;; 868*906afcb8SAndy Fiddaman *) stdinclude="$stdinclude $f" ;; 869*906afcb8SAndy Fiddaman esac 870*906afcb8SAndy Fiddamandone 871