shipfeature.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. # $XConsortium: shipfeature.sh /main/2 1995/07/19 17:09:46 drk $
  2. :
  3. # Glenn Fowler & Phong Vo
  4. # AT&T Bell Laboratories
  5. #
  6. # C feature test support
  7. # @(#)feature (AT&T Bell Laboratories) 03/01/94
  8. #
  9. # NOTE: .exe a.out suffix and [\\/] in path patterns for dos/nt
  10. command=feature
  11. version=03/01/94
  12. binding="-Bdynamic -Bstatic -Wl,-ashared -Wl,-aarchive -call_shared -non_shared"
  13. occ=cc
  14. debug=
  15. defhdr=
  16. deflib=
  17. executable='test -x'
  18. gothdr=
  19. gotlib=
  20. dir=FEATURE
  21. in=
  22. out=
  23. pragma=
  24. case $RANDOM in
  25. $RANDOM)shell=bsh
  26. $executable . 2>/dev/null || executable='test -r'
  27. ;;
  28. *) shell=ksh
  29. ;;
  30. esac
  31. static=.
  32. statictest=
  33. case $COTEMP in
  34. "") case $HOSTNAME in
  35. ""|?|??|???|????|????)
  36. tmp=${HOSTNAME}
  37. ;;
  38. *) case $shell in
  39. ksh) tmp=${HOSTNAME%${HOSTNAME#????}} ;;
  40. *) eval `echo $HOSTNAME | sed 's/\(....\).*/tmp=\1/'` ;;
  41. esac
  42. ;;
  43. esac
  44. tmp=${tmp}$$
  45. ;;
  46. *) tmp=$COTEMP
  47. ;;
  48. esac
  49. case $tmp in
  50. ??????????*)
  51. case $shell in
  52. ksh) tmp=${tmp%${tmp#?????????}} ;;
  53. *) eval `echo $tmp | sed 's/\(.........\).*/tmp=\1/'` ;;
  54. esac
  55. ;;
  56. ?????????)
  57. ;;
  58. ????????)
  59. tmp=F$tmp
  60. ;;
  61. esac
  62. tmp=./$tmp
  63. # standard error to /dev/null unless debugging
  64. # standard output to the current output file
  65. #
  66. # stdout original standard output
  67. # stderr original standard error
  68. # nullin /dev/null input
  69. # nullout /dev/null output
  70. stdout=5 stderr=6 nullin=7 nullout=8
  71. eval "exec $nullin>/dev/null $nullout>/dev/null $stdout>&1 $stderr>&2 2>&$nullout"
  72. # options -- `-' for output to stdout otherwise usage
  73. while :
  74. do case $# in
  75. 0) in=-
  76. break
  77. ;;
  78. esac
  79. case $1 in
  80. -) out=-
  81. ;;
  82. -*) echo "Usage: $command [-] [op [arg ... [-l* *.a *.sh * ...]] [: op ...]" >&$stderr
  83. exit 2
  84. ;;
  85. *) break
  86. ;;
  87. esac
  88. shift
  89. done
  90. # tmp files cleaned up on exit
  91. # status: 0:success 1:failure 2:interrupt
  92. status=2
  93. trap "rm -f $tmp*.*; exit \$status" 0 1 2
  94. # loop on op [ arg [ ... ] ] [ : op [ arg [ ... ] ] ]
  95. cur=.
  96. while :
  97. do case $in in
  98. "") case $# in
  99. 0) set set out + ;;
  100. esac
  101. ;;
  102. *) read lin || lin="set out +"
  103. set x $lin
  104. shift
  105. ;;
  106. esac
  107. # check if "run xxx" is equivalent to "set in xxx"
  108. case $1 in
  109. run) case $shell in
  110. ksh) x=${2##*[\\/]}
  111. ;;
  112. *) case $2 in
  113. */*) x=`echo $2 | sed -e 's,.*[\\\\/],,'` ;;
  114. *) x=$2 ;;
  115. esac
  116. ;;
  117. esac
  118. case $x in
  119. *.*) ;;
  120. *) set set in $2 ;;
  121. esac
  122. ;;
  123. esac
  124. # set drops out early
  125. case $1 in
  126. ""|\#*) continue
  127. ;;
  128. set) shift
  129. case $1 in
  130. ""|\#*) op=
  131. ;;
  132. *) op=$1
  133. shift
  134. arg=
  135. while :
  136. do case $# in
  137. 0) break ;;
  138. esac
  139. case $1 in
  140. *" "*) shift
  141. continue
  142. ;;
  143. ""|\#*) break
  144. ;;
  145. :) shift
  146. break
  147. ;;
  148. esac
  149. case $arg in
  150. "") arg=$1 ;;
  151. *) arg="$arg $1" ;;
  152. esac
  153. shift
  154. done
  155. ;;
  156. esac
  157. case $op in
  158. cc) occ=
  159. for x in $arg
  160. do case $occ in
  161. "") case $x in
  162. *=*) case $shell in
  163. ksh) export $x
  164. ;;
  165. *) eval $x
  166. export `echo $x | sed -e 's/=.*//'`
  167. ;;
  168. esac
  169. ;;
  170. *) occ=$x
  171. ;;
  172. esac
  173. ;;
  174. *) occ="$occ $x"
  175. ;;
  176. esac
  177. done
  178. continue
  179. ;;
  180. debug) case $arg in
  181. 0) exec 2>&$nullout
  182. set -
  183. debug=
  184. ;;
  185. ""|1) exec 2>&$stderr
  186. set -
  187. debug=
  188. ;;
  189. 2) exec 2>&$stderr
  190. case $shell in
  191. ksh) PS4="${PS4%+*([ ])}+\$LINENO+ "
  192. esac
  193. set -x
  194. debug=-x
  195. ;;
  196. *) echo "$command: $arg: debug levels are 0, 1, 2" >&$stderr
  197. ;;
  198. esac
  199. continue
  200. ;;
  201. "in") case $arg in
  202. "") in=-
  203. ;;
  204. *) in=$arg
  205. if test ! -f $in
  206. then echo "$command: $in: not found" >&$stderr
  207. exit 1
  208. fi
  209. exec < $in
  210. case $out in
  211. "") case $in in
  212. *[.\\/]*)
  213. case $shell in
  214. ksh) out=${in##*[\\/]}
  215. out=${out%.*}
  216. ;;
  217. *) eval `echo $in | sed -e 's,.*[\\\\/],,' -e 's/\.[^.]*//' -e 's/^/out=/'`
  218. ;;
  219. esac
  220. ;;
  221. *) out=$in
  222. ;;
  223. esac
  224. ;;
  225. esac
  226. ;;
  227. esac
  228. continue
  229. ;;
  230. nodebug)exec 2>&$nullout
  231. set -
  232. continue
  233. ;;
  234. out) out=$arg
  235. defhdr=
  236. deflib=
  237. gothdr=
  238. gotlib=
  239. ;;
  240. prototyped|noprototyped)
  241. pragma="$pragma $op"
  242. ;;
  243. pragma) pragma="$pragma $arg"
  244. ;;
  245. shell) shell=$arg
  246. continue
  247. ;;
  248. static) static=$arg
  249. continue
  250. ;;
  251. *) echo "$command: $op: unkown option" >&$stderr
  252. exit 1
  253. ;;
  254. esac
  255. ;;
  256. *) case $1 in
  257. *\{) op=-
  258. ;;
  259. *) op=$1
  260. shift
  261. ;;
  262. esac
  263. arg=
  264. cc=$occ
  265. fail=
  266. hdr=
  267. lib=
  268. lst=hdr
  269. opt=
  270. pass=
  271. run=
  272. src=
  273. tst=
  274. case $# in
  275. 0) ;;
  276. *) case $1 in
  277. \#*) set x
  278. shift
  279. ;;
  280. *) case $op in
  281. ref) ;;
  282. *) case $1 in
  283. *\{) arg=-
  284. ;;
  285. *) arg=$1
  286. shift
  287. esac
  288. ;;
  289. esac
  290. ;;
  291. esac
  292. while :
  293. do case $# in
  294. 0) break ;;
  295. esac
  296. case $1 in
  297. "") ;;
  298. \#*) set x
  299. ;;
  300. [a-z]*\{)
  301. v=$1
  302. x=
  303. shift
  304. while :
  305. do case $# in
  306. 0) case $in in
  307. "") echo "$command: missing }end" >&$stderr
  308. exit 1
  309. ;;
  310. esac
  311. while :
  312. do if read o lin
  313. then case $o in
  314. \}end) set $o $lin
  315. break 2
  316. ;;
  317. ' '*|' '*)
  318. set '' $o
  319. o=$2
  320. ;;
  321. esac
  322. case $lin in
  323. "") x="$x
  324. $o" ;;
  325. *) x="$x
  326. $o $lin" ;;
  327. esac
  328. else echo "$command: missing }end" >&$stderr
  329. exit 1
  330. fi
  331. done
  332. ;;
  333. esac
  334. case $1 in
  335. \}end) break
  336. ;;
  337. *) x="$x
  338. $1"
  339. ;;
  340. esac
  341. shift
  342. done
  343. case $v in
  344. fail\{) fail=$x ;;
  345. pass\{) pass=$x ;;
  346. test\{) tst=$x ;;
  347. *) src=$x run=$v ;;
  348. esac
  349. ;;
  350. :) shift
  351. break
  352. ;;
  353. *[\(\)\{\}\ \ ]*)
  354. tst="$tst $1"
  355. ;;
  356. -) case $lst in
  357. hdr) hdr="$hdr $1" ;;
  358. lib) lib="$lib $1" ;;
  359. esac
  360. ;;
  361. -l*) lib="$lib $1"
  362. lst=lib
  363. ;;
  364. -*|+*) case $op in
  365. ref) occ="$occ $1" ;;
  366. run) opt="$opt $1" ;;
  367. *) cc="$cc $1" ;;
  368. esac
  369. ;;
  370. *.a) lib="$lib $1"
  371. lst=lib
  372. ;;
  373. *[.\\/]*)
  374. hdr="$hdr $1"
  375. lst=hdr
  376. ;;
  377. *) tst="$tst $1"
  378. ;;
  379. esac
  380. shift
  381. done
  382. ;;
  383. esac
  384. ;;
  385. esac
  386. # check the candidate headers
  387. case $hdr in
  388. ?*) z=$hdr
  389. hdr=
  390. hit=0
  391. for x in $z
  392. do case $x in
  393. -) case $hit in
  394. 0) hit=1 ;;
  395. 1) ;;
  396. *) break ;;
  397. esac
  398. continue
  399. ;;
  400. *.h) echo "#include \"$x\"" > $tmp.c
  401. $cc -E $tmp.c <&$nullin >&$nullout || continue
  402. ;;
  403. *) test -r $x || continue
  404. ;;
  405. esac
  406. hdr="$hdr $x"
  407. case $hit in
  408. 0) ;;
  409. 1) hit=2 ;;
  410. esac
  411. done
  412. ;;
  413. esac
  414. # check the candidate libraries
  415. case $lib in
  416. ?*) z=$lib
  417. e=
  418. lib=
  419. echo "int main(){return(0);}" > $tmp.c
  420. for x in $z
  421. do case $x in
  422. -) case $lib in
  423. "") continue ;;
  424. esac
  425. break
  426. ;;
  427. esac
  428. while :
  429. do rm -f $tmp.exe
  430. if $cc -o $tmp.exe $tmp.c $e $x <&$nullin >&$nullout
  431. then lib="$lib $e $x"
  432. e=
  433. break
  434. else case $e in
  435. "") e=$x
  436. break
  437. ;;
  438. *) e=
  439. ;;
  440. esac
  441. fi
  442. done
  443. done
  444. ;;
  445. esac
  446. # precheck some more ops
  447. case $op in
  448. ref) deflib="$deflib $lib"
  449. defhdr="$defhdr $hdr"
  450. continue
  451. ;;
  452. esac
  453. ifs=$IFS
  454. IFS=,
  455. eval op=\"$op\"
  456. eval arg=\"$arg\"
  457. IFS=$ifs
  458. # check for op aliases
  459. x=
  460. for o in $op
  461. do case $o in
  462. def|default) x="$x cmd hdr key lib mth sys typ" ;;
  463. *) x="$x $o" ;;
  464. esac
  465. done
  466. # loop on the ops o and args a
  467. for o in $x
  468. do for a in $arg
  469. do user=
  470. case $a in
  471. *[.\\/]*)
  472. case $o in
  473. hdr|sys)
  474. case $a in
  475. *[\\/]*) x=/ ;;
  476. *) x=. ;;
  477. esac
  478. case $shell in
  479. ksh) p=${a%%${x}*}
  480. v=${a##*${x}}
  481. ;;
  482. *) eval `echo $a | sed -e "s/\\(.*\\)\\\\${x}\\(.*\\)/p=\\1 v=\\2/"`
  483. ;;
  484. esac
  485. ;;
  486. *) case $shell in
  487. ksh) p=${a%.*}
  488. p=${p##*[\\/]}
  489. v=${a##*.}
  490. v=${v##*[\\/]}
  491. ;;
  492. *) eval `echo $a | sed -e 's,.*[\\\\/],,' -e 's/\(.*\)\.\(.*\)/p=\1 v=\2/'`
  493. ;;
  494. esac
  495. ;;
  496. esac
  497. f=${p}/${v}
  498. case $o in
  499. run) v=$p
  500. p=
  501. m=_${v}
  502. ;;
  503. mem) m=_${v}_${p}
  504. ;;
  505. *) m=_${p}_${v}
  506. ;;
  507. esac
  508. ;;
  509. *) p=
  510. v=$a
  511. f=$a
  512. m=_${v}
  513. ;;
  514. esac
  515. # check output redirection
  516. case $out in
  517. $cur) ;;
  518. *) case $cur in
  519. $a|$v) ;;
  520. *) case $cur in
  521. .) ;;
  522. -) echo "#endif"
  523. ;;
  524. *) echo "#endif"
  525. exec >&-
  526. case $cur in
  527. *[\\/]*|*.h) x=$cur ;;
  528. *) x=$dir/$cur ;;
  529. esac
  530. proto -r $tmp.h
  531. sed 's,/\*[^/]*\*/, ,g' $tmp.h > $tmp.c
  532. sed 's,/\*[^/]*\*/, ,g' $x > $tmp.t
  533. if cmp -s $tmp.c $tmp.t
  534. then rm -f $tmp.h
  535. else case $x in
  536. ${dir}[\\/]$cur) test -d $dir || mkdir $dir || exit 1 ;;
  537. esac
  538. mv $tmp.h $x
  539. fi
  540. ;;
  541. esac
  542. case $out in
  543. +) case $status in
  544. 1) ;;
  545. *) status=0 ;;
  546. esac
  547. exit $status
  548. ;;
  549. -) eval "exec >&$stdout"
  550. ;;
  551. *) exec >$tmp.h
  552. ;;
  553. esac
  554. case $out in
  555. "") case $a in
  556. *[\\/]*|???????????????*) cur=$v ;;
  557. *) cur=$a ;;
  558. esac
  559. ;;
  560. *) cur=$out
  561. ;;
  562. esac
  563. case $in in
  564. ""|-|+) case $o in
  565. run) x=" from $a" ;;
  566. *) x= ;;
  567. esac
  568. ;;
  569. *) x=" from $in"
  570. ;;
  571. esac
  572. echo "/* : : generated$x by $command version $version : : */"
  573. for x in $pragma
  574. do echo "#pragma $x"
  575. done
  576. case $out in
  577. ""|-|+) x=$m
  578. ;;
  579. *.*) case $shell in
  580. ksh) i=$out
  581. x=_
  582. while :
  583. do case $i in
  584. *.*) x=$x${i%%.*}_
  585. i=${i#*.}
  586. ;;
  587. *) x=$x$i
  588. break
  589. ;;
  590. esac
  591. done
  592. ;;
  593. *) eval `echo $in | sed -e 's,\.,_,g' -e 's/^/x=/'`
  594. ;;
  595. esac
  596. ;;
  597. *) x=_$out
  598. ;;
  599. esac
  600. case $x in
  601. *-*) echo "#if 1"
  602. ;;
  603. *) case $x in
  604. _cmd|_lib)
  605. case $shell in
  606. ksh) c=${PWD##*[\\/]}
  607. c=${c#lib}
  608. c=${c%%.*}
  609. x=${x}_${c}
  610. ;;
  611. *) x=${x}_`echo $x | sed -e 's,.*[\\\\/],,' -e 's,^lib,,' -e 's,\..*,,'`
  612. ;;
  613. esac
  614. ;;
  615. esac
  616. x=`echo $x | sed -e 's/[^a-zA-Z0-9_]/_/g'`
  617. echo "#ifndef _def${x}"
  618. echo "#define _def${x} 1"
  619. ;;
  620. esac
  621. ;;
  622. esac
  623. ;;
  624. esac
  625. # set up the candidate include list
  626. inc=
  627. for x in $defhdr $hdr
  628. do case $x in
  629. *.h) case $shell in
  630. ksh) c=${x##*[\\/]}
  631. c=${c%%.*}
  632. case $x in
  633. */*) c=${x%%[\\/]*}_${c} ;;
  634. esac
  635. ;;
  636. *) eval `echo $x | sed -e 's,^\([^\\\\/]*\).*[\\\\/]\([^\\\\/]*\)\$,\1_\2,' -e 's/\..*//' -e 's/^/c=/'`
  637. ;;
  638. esac
  639. case " $gothdr " in
  640. *" $x "*)
  641. ;;
  642. *) gothdr="$gothdr $x"
  643. echo "#define _inc_${c} 1 /* candidate header <$x> found */"
  644. ;;
  645. esac
  646. inc="$inc
  647. #include <$x>"
  648. ;;
  649. esac
  650. done
  651. # set up the candidate lib list
  652. for x in $lib $deflib
  653. do case " $gotlib " in
  654. *" $x "*)
  655. ;;
  656. *) gotlib="$gotlib $x"
  657. echo "/* candidate library $x found */"
  658. ;;
  659. esac
  660. done
  661. # src overrides builtin test
  662. case $o in
  663. tst) ;;
  664. *) m=_${o}${m}
  665. ;;
  666. esac
  667. pre="#undef $v"
  668. case $src in
  669. ?*) echo "$inc
  670. $src" > $tmp.c
  671. e=
  672. case $run in
  673. cat*|nocat*)
  674. echo "$src"
  675. ;;
  676. run*|norun*)
  677. (eval "$src") <&$nullin || e=1
  678. ;;
  679. mac*|nomac*)
  680. if $cc -E $tmp.c <&$nullin >$tmp.i
  681. then sed -e '/<<[ ]*".*"[ ]*>>/!d' -e 's/<<[ ]*"//g' -e 's/"[ ]*>>//g' $tmp.i
  682. else e=1
  683. fi
  684. ;;
  685. p*|nop*)$cc -DTEST=$p -DID=$v -E $tmp.c <&$nullin >&$nullout || e=1
  686. ;;
  687. c*|noc*)$cc -DTEST=$p -DID=$v -c $tmp.c <&$nullin >&$nullout || e=1
  688. ;;
  689. *) rm -f $tmp.exe
  690. if $cc -DTEST=$p -DID=$v -o $tmp.exe $tmp.c $lib $deflib <&$nullin >&$nullout && $executable $tmp.exe
  691. then case $run in
  692. l*|nol*);;
  693. o*|noo*)$tmp.exe <&$nullin || e=1 ;;
  694. *) $tmp.exe <&$nullin >&$nullout || e=1 ;;
  695. esac
  696. else e=1
  697. fi
  698. ;;
  699. esac
  700. case $run in
  701. no*) case $e in
  702. "") e=1 ;;
  703. *) e= ;;
  704. esac
  705. ;;
  706. esac
  707. case $e in
  708. "") case $m in
  709. *-*) ;;
  710. *) echo "#define $m 1 /* ${run}} passed */" ;;
  711. esac
  712. (eval "$pass") <&$nullin
  713. ;;
  714. *) (eval "$fail") <&$nullin
  715. ;;
  716. esac
  717. continue
  718. ;;
  719. esac
  720. # initialize common builtin state
  721. case $o in
  722. dat|lib|mth|run)
  723. case $statictest in
  724. "") statictest=FoobaR
  725. echo "#if __cplusplus
  726. extern \"C\" {
  727. #endif
  728. extern int $statictest();
  729. #if __cplusplus
  730. }
  731. #endif
  732. static int ((*i)())=$statictest;main(){return(i==0);}" > $tmp.c
  733. rm -f $tmp.exe
  734. if $cc -o $tmp.exe $tmp.c <&$nullin >&$nullout && $executable $tmp.exe
  735. then case $static in
  736. .) static=
  737. echo '#include <stdio.h>
  738. main(){printf("hello");return(0);}' > $tmp.c
  739. rm -f $tmp.exe
  740. if $cc -c $tmp.c <&$nullin >&$nullout && $cc -o $tmp.exe $tmp.o <&$nullin >&$nullout 2>$tmp.e && $executable $tmp.exe
  741. then e=`wc -l $tmp.e`
  742. set x x $binding
  743. while :
  744. do shift
  745. shift
  746. case $# in
  747. 0) break ;;
  748. esac
  749. rm -f $tmp.exe
  750. $cc -o $tmp.exe $1 $tmp.o <&$nullin >&$nullout 2>$tmp.e && $executable $tmp.exe || continue
  751. case `wc -l $tmp.e` in
  752. $e) ;;
  753. *) continue ;;
  754. esac
  755. d=`ls -s $tmp.exe`
  756. rm -f $tmp.exe
  757. $cc -o $tmp.exe $2 $tmp.o <&$nullin >&$nullout 2>$tmp.e && $executable $tmp.exe || continue
  758. case `wc -l $tmp.e` in
  759. $e) ;;
  760. *) continue ;;
  761. esac
  762. case `ls -s $tmp.exe` in
  763. $d) ;;
  764. *) static=$2
  765. set x
  766. shift
  767. break
  768. ;;
  769. esac
  770. done
  771. fi
  772. ;;
  773. esac
  774. else static=
  775. fi
  776. ;;
  777. esac
  778. ;;
  779. esac
  780. # builtin tests
  781. case $o in
  782. cmd) case $p in
  783. ?*) continue ;;
  784. esac
  785. k=
  786. for j in "" usr
  787. do case $j in
  788. "") d= s= ;;
  789. *) d=/$j s=_$j ;;
  790. esac
  791. for i in bin etc ucb
  792. do if test -f $d/$i/$a
  793. then case $k in
  794. "") k=1
  795. echo "#define $m 1 /* $a in ?(/usr)/(bin|etc|ucb) */"
  796. ;;
  797. esac
  798. echo "#define ${s}_${i}_${v} 1 /* $d/$i/$a found */"
  799. fi
  800. done
  801. done
  802. ;;
  803. dat) case $p in
  804. ?*) continue ;;
  805. esac
  806. {
  807. echo "$pre"
  808. case $inc in
  809. ?*) echo "$inc"
  810. ;;
  811. *) echo "#if __cplusplus
  812. extern \"C\" {
  813. #endif
  814. extern int $v;
  815. #if __cplusplus
  816. }
  817. #endif"
  818. ;;
  819. esac
  820. echo "int main(){char* i = (char*)&$v; return i!=0;}"
  821. } > $tmp.c
  822. $cc -c $tmp.c <&$nullin >&$nullout &&
  823. rm -f $tmp.exe
  824. if $cc $static -o $tmp.exe $tmp.o $lib $deflib <&$nullin >&$nullout && $executable $tmp.exe
  825. then echo "#define $m 1 /* $v in default lib(s) */"
  826. fi
  827. ;;
  828. hdr|lcl|sys)
  829. case $p in
  830. lcl) eval p='$'_lcl_$v
  831. case $p in
  832. ?*) continue ;;
  833. esac
  834. eval _lcl_$v=1
  835. p=
  836. f=$v
  837. ;;
  838. *) case $o in
  839. hdr) echo "#include <$f.h>" > $tmp.c
  840. $cc -E $tmp.c <&$nullin >&$nullout &&
  841. echo "#define $m 1 /* #include <$f.h> ok */"
  842. ;;
  843. sys) echo "#include <sys/$f.h>" > $tmp.c
  844. $cc -E $tmp.c <&$nullin >&$nullout &&
  845. echo "#define $m 1 /* #include <sys/$f.h> ok */"
  846. ;;
  847. esac
  848. continue
  849. ;;
  850. esac
  851. case $p in
  852. ?*) x="$p\\$v" ;;
  853. *) x=$f ;;
  854. esac
  855. case $f in
  856. *[\\/]*)g=$f ;;
  857. *) g="$f sys/$f" ;;
  858. esac
  859. for f in $g
  860. do echo "$pre
  861. $inc
  862. #include <$f.h>" > $tmp.c
  863. if $cc -E $tmp.c <&$nullin >$tmp.i
  864. then i=`sed -e '/^#[line ]*1[ ][ ]*"[\\\\/].*[\\\\/]'$x'\.h"/!d' -e '/[\\\\/]sys[\\\\/]'$x'\.h"/d' -e s'/.*"\(.*\)".*/\1/' $tmp.i`
  865. for i in $i
  866. do break
  867. done
  868. else i=
  869. fi
  870. case $i in
  871. [\\/]*) echo "#if defined(__STDPP__directive)"
  872. echo "__STDPP__directive pragma pp:hosted"
  873. echo "#endif"
  874. echo "#include \"$i\" /* untrusted local <$f.h> */"
  875. echo "#undef $m"
  876. echo "#define $m 1"
  877. break
  878. ;;
  879. *) echo "/* no local <$f.h> */"
  880. ;;
  881. esac
  882. done
  883. ;;
  884. key) case $p in
  885. ?*) continue ;;
  886. esac
  887. echo "$pre
  888. int f(){int $v = 1;return($v);}" > $tmp.c
  889. $cc -c $tmp.c <&$nullin >&$nullout ||
  890. echo "#define $m 1 /* $v is a reserved keyword */"
  891. ;;
  892. lib|mth)case $p in
  893. ?*) continue ;;
  894. esac
  895. echo "$pre
  896. $inc
  897. #if __cplusplus
  898. extern \"C\" {
  899. #endif
  900. extern int $v();
  901. #if __cplusplus
  902. }
  903. #endif
  904. static int ((*i)())=$v;main(){return(i==0);}" > $tmp.c
  905. $cc -c $tmp.c <&$nullin >&$nullout &&
  906. rm -f $tmp.exe
  907. if $cc $static -o $tmp.exe $tmp.o $lib $deflib <&$nullin >&$nullout && $executable $tmp.exe
  908. then case $o in
  909. lib) echo "#define $m 1 /* $v() in default lib(s) */" ;;
  910. esac
  911. else case $o in
  912. mth) rm -f $tmp.exe
  913. $cc $static -o $tmp.exe $tmp.o -lm <&$nullin >&$nullout &&
  914. $executable $tmp.exe &&
  915. echo "#define $m 1 /* $v() in math lib */"
  916. ;;
  917. esac
  918. fi
  919. ;;
  920. mac) case $p in
  921. ?*) continue ;;
  922. esac
  923. echo "$pre
  924. $inc
  925. #ifdef $v
  926. '#define $m 1 /* $v is a macro */'
  927. #endif" > $tmp.c
  928. $cc -E $tmp.c <&$nullin | sed -e "/^'#define/!d" -e "s/'//g"
  929. ;;
  930. mem) case $p in
  931. ?*) for i in "" "struct "
  932. do echo "$pre
  933. $inc
  934. static $i$p i;
  935. int n = sizeof(i.$v);" > $tmp.c
  936. $cc -c $tmp.c <&$nullin >&$nullout &&
  937. echo "#define $m 1 /* $v is member of $i$p */" &&
  938. break
  939. done
  940. ;;
  941. *) echo "$command: $o: <struct>.<member> expected" >&$stderr
  942. status=1
  943. ;;
  944. esac
  945. ;;
  946. nop) ;;
  947. one) for i in $a $hdr
  948. do x="#include <$i>"
  949. echo "$x" > $tmp.c
  950. if $cc -E $tmp.c <&$nullin >&$nullout
  951. then echo "$x"
  952. break
  953. fi
  954. done
  955. ;;
  956. out) ;;
  957. run) if test ! -f $a
  958. then echo "$command: $a: not found" >&$stderr
  959. exit 1
  960. fi
  961. case $a in
  962. *.c) rm -f $tmp.exe
  963. cp $a $tmp.c
  964. $cc -o $tmp.exe $tmp.c $lib $deflib <&$nullin >&$nullout &&
  965. $executable $tmp.exe &&
  966. $tmp.exe $opt <&$nullin
  967. ;;
  968. *.sh) ${SHELL-sh} $debug $a "cc='$cc' executable='$executable' id='$m' static='$static' tmp='$tmp'" $opt $hdr <&$nullin
  969. ;;
  970. *) false
  971. ;;
  972. esac
  973. case $? in
  974. 0) ;;
  975. *) echo "$command: $a: cannot run" >&$stderr
  976. exit 1
  977. ;;
  978. esac
  979. ;;
  980. sym) case $tst in
  981. "") x=$v ;;
  982. *) x=$tst ;;
  983. esac
  984. echo "$pre
  985. $inc
  986. '=' $x '='" > $tmp.c
  987. $cc -E $tmp.c <&$nullin \
  988. | sed \
  989. -e "/'='/!d" \
  990. -e "s/'='//g" \
  991. -e 's/[ ]//g' \
  992. -e 's/((([^()]*)))->/->/g' \
  993. -e 's/(([^()]*))->/->/g' \
  994. -e 's/([^()]*)->/->/g' \
  995. -e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)\[/\
  996. ary \1[/g' \
  997. -e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)(/\
  998. fun \1[/g' \
  999. -e 's/\*->\([a-zA-Z_]\)/->\
  1000. ptr \1/g' \
  1001. -e 's/->\([a-zA-Z_]\)/->\
  1002. reg \1/g' \
  1003. -e "/^$v\$/d" \
  1004. -e 's/^[a-zA-Z_][a-zA-Z_0-9]*$/\
  1005. nam &/g' \
  1006. | sed \
  1007. -e '/^... /!d' \
  1008. | sort \
  1009. -u \
  1010. | sed \
  1011. -e 's/\(...\) \([a-zA-Z_][a-zA-Z_0-9]*\).*/#ifndef _\1_'$v'\
  1012. #define _\1_'$v' \2\
  1013. #define _\1_'$v'_str "\2"\
  1014. #endif/'
  1015. ;;
  1016. typ) case $p in
  1017. "") x= ;;
  1018. *) x="$p " ;;
  1019. esac
  1020. case $typ in
  1021. "") typ="
  1022. #include <sys/types.h>"
  1023. c=
  1024. h=
  1025. for i in time "" times
  1026. do case $i in
  1027. "") c=sys_
  1028. h=sys/
  1029. continue
  1030. ;;
  1031. esac
  1032. c=${c}$i
  1033. h=${h}$i.h
  1034. t="$typ
  1035. #include <$h>"
  1036. echo "$t" > $tmp.c
  1037. if $cc -c $tmp.c <&$nullin >&$nullout
  1038. then typ="$t"
  1039. echo "#define _inc_${c} 1 /* candidate header <$h> found */"
  1040. fi
  1041. c=
  1042. h=
  1043. done
  1044. t=
  1045. for i in stddef stdlib
  1046. do u="$t
  1047. #include <$i.h>"
  1048. echo "$u$typ" > $tmp.c
  1049. if $cc -c $tmp.c <&$nullin >&$nullout
  1050. then t="$u"
  1051. echo "#define _inc_$i 1 /* candidate header <$i.h> found */"
  1052. else break
  1053. fi
  1054. done
  1055. typ="$t$typ"
  1056. ;;
  1057. esac
  1058. {
  1059. case $p in
  1060. long) echo "$pre
  1061. $typ$inc
  1062. static $x$v i;
  1063. $x$v f() {
  1064. $x$v v; v = i;"
  1065. echo "v <<= 4; i = v >> 2; i = v * i; i = i / v; v = v + i; i = i - v; i = 10; i = v % i; i |= v; v ^= i; i = 123; v &= i;
  1066. return v; }"
  1067. ;;
  1068. *) echo "$pre
  1069. $typ$inc
  1070. struct xxx { $x$v mem; };
  1071. static struct xxx v;
  1072. struct xxx* f() { return &v; }"
  1073. ;;
  1074. esac
  1075. echo "int main() { f(); return 0; }"
  1076. } > $tmp.c
  1077. rm -f $tmp.exe
  1078. if $cc -o $tmp.exe $tmp.c <&$nullin >&$nullout &&
  1079. $executable $tmp.exe
  1080. then echo "#define $m 1 /* $x$v is a type */"
  1081. user=$pass
  1082. else user=$fail
  1083. fi
  1084. ;;
  1085. *) echo "$command: $o: unknown feature test" >&$stderr
  1086. status=1
  1087. ;;
  1088. esac
  1089. case $user in
  1090. ?*) (eval "$user") <&$nullin ;;
  1091. esac
  1092. done
  1093. done
  1094. done