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