C+probe 17 KB

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