mamprobe 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. ########################################################################
  2. # #
  3. # This software is part of the ast package #
  4. # Copyright (c) 1994-2011 AT&T Intellectual Property #
  5. # and is licensed under the #
  6. # Eclipse Public License, Version 1.0 #
  7. # by AT&T Intellectual Property #
  8. # #
  9. # A copy of the License is available at #
  10. # http://www.eclipse.org/org/documents/epl-v10.html #
  11. # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
  12. # #
  13. # Information and Software Systems Research #
  14. # AT&T Research #
  15. # Florham Park NJ #
  16. # #
  17. # Glenn Fowler <gsf@research.att.com> #
  18. # #
  19. ########################################################################
  20. ### this script contains archaic constructs that work with all sh variants ###
  21. # mamprobe - generate MAM cc probe info
  22. # Glenn Fowler <gsf@research.att.com>
  23. (command set -o posix) 2>/dev/null && set -o posix
  24. command=mamprobe
  25. bins=`
  26. (
  27. userPATH=$PATH
  28. PATH=/run/current-system/sw/bin:/usr/xpg7/bin:/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin:$PATH
  29. getconf PATH 2>/dev/null && echo "$userPATH" || echo /bin:/usr/bin:/sbin:/usr/sbin:"$userPATH"
  30. ) | sed 's/:/ /g'
  31. ` || exit
  32. # check the options
  33. opt=
  34. case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
  35. 0123) USAGE=$'
  36. [-?
  37. @(#)$Id: mamprobe (AT&T Labs Research) 2011-02-11 $
  38. ]
  39. [+NAME?mamprobe - generate MAM cc probe info]
  40. [+DESCRIPTION?\bmamprobe\b generates MAM (make abstract machine) \bcc\b(1)
  41. probe information for use by \bmamake\b(1). \acc-path\a is the
  42. absolute path of the probed compiler and \ainfo-file\a is where
  43. the information is placed. \ainfo-file\a is usually
  44. \b$INSTALLROOT/lib/probe/C/mam/\b\ahash\a, where \ahash\a is a hash
  45. of \acc-path\a. Any \ainfo-file\a directories are created if needed.
  46. If \ainfo-file\a is \b-\b then the probe information is written to
  47. the standard output.]
  48. [+?\bmamprobe\b and \bmamake\b are used in the bootstrap phase of
  49. \bpackage\b(1) installation before \bnmake\b(1) is built. The
  50. probed variable names are the \bnmake\b(1) names with a \bmam_\b
  51. prefix, \bCC\b converted to \bcc\b, and \b.\b converted to \b_\b.
  52. Additional variables are:]{
  53. [+_hosttype_?the \bpackage\b(1) host type]
  54. [+mam_cc_L?\b-L\b\adir\a supported]
  55. [+STDCAT?command to execute for \bcat\b(1); prefixed by
  56. \bexecrate\b(1) on \b.exe\b challenged systems]
  57. [+STDCHMOD?command to execute for \bchmod\b(1); prefixed by
  58. \bexecrate\b(1) on \b.exe\b challenged systems]
  59. [+STDCMP?command to execute for \bcmp\b(1); prefixed by
  60. \bexecrate\b(1) on \b.exe\b challenged systems]
  61. [+STDCP?command to execute for \bcp\b(1); prefixed by
  62. \bexecrate\b(1) on \b.exe\b challenged systems]
  63. [+STDED?command to execute for \bed\b(1) or \bex\b(1)]
  64. [+STDEDFLAGS?flags for \bSTDED\b]
  65. [+STDLN?command to execute for \bln\b(1); prefixed by
  66. \bexecrate\b(1) on \b.exe\b challenged systems]
  67. [+STDMV?command to execute for \bmv\b(1); prefixed by
  68. \bexecrate\b(1) on \b.exe\b challenged systems]
  69. [+STDRM?command to execute for \brm\b(1); prefixed by
  70. \bexecrate\b(1) on \b.exe\b challenged systems]
  71. }
  72. [d:debug?Enable probe script debug trace.]
  73. info-file cc-path
  74. [+SEE ALSO?\bexecrate\b(1), \bpackage\b(1), \bmamake\b(1), \bnmake\b(1),
  75. \bprobe\b(1)]
  76. '
  77. while getopts -a "$command" "$USAGE" OPT
  78. do case $OPT in
  79. d) opt=-d ;;
  80. esac
  81. done
  82. shift `expr $OPTIND - 1`
  83. ;;
  84. *) while :
  85. do case $# in
  86. 0) break ;;
  87. esac
  88. case $1 in
  89. --) shift
  90. break
  91. ;;
  92. -) break
  93. ;;
  94. -d) opt=-d
  95. ;;
  96. -*) echo $command: $1: unknown option >&2
  97. ;;
  98. *) break
  99. ;;
  100. esac
  101. set ''
  102. break
  103. done
  104. ;;
  105. esac
  106. # check the args
  107. case $1 in
  108. -) ;;
  109. /*) ;;
  110. *) set '' ;;
  111. esac
  112. case $2 in
  113. /*) ;;
  114. *) set '' ;;
  115. esac
  116. case $# in
  117. 0|1) echo "Usage: $command info-file cc-path" >&2; exit 2 ;;
  118. esac
  119. info=$1
  120. shift
  121. cc=$*
  122. # find the make probe script
  123. ifs=${IFS-'
  124. '}
  125. IFS=:
  126. set $PATH
  127. IFS=$ifs
  128. script=lib/probe/C/make/probe
  129. while :
  130. do case $# in
  131. 0) echo "$0: ../$script: probe script not found on PATH" >&2
  132. exit 1
  133. ;;
  134. esac
  135. case $1 in
  136. '') continue ;;
  137. esac
  138. makeprobe=`echo $1 | sed 's,[^/]*$,'$script,`
  139. if test -x $makeprobe
  140. then break
  141. fi
  142. shift
  143. done
  144. # create the info dir if necessary
  145. case $info in
  146. /*) i=X$info
  147. ifs=${IFS-'
  148. '}
  149. IFS=/
  150. set $i
  151. IFS=$ifs
  152. while :
  153. do i=$1
  154. shift
  155. case $i in
  156. X) break ;;
  157. esac
  158. done
  159. case $info in
  160. //*) path=/ ;;
  161. *) path= ;;
  162. esac
  163. while :
  164. do case $# in
  165. 0|1) break ;;
  166. esac
  167. comp=$1
  168. shift
  169. case $comp in
  170. '') continue ;;
  171. esac
  172. path=$path/$comp
  173. if test ! -d $path
  174. then mkdir $path || exit
  175. fi
  176. done
  177. ;;
  178. esac
  179. # generate info in a tmp file and rename when finished
  180. case $info in
  181. -) ;;
  182. *) tmp=${TMPDIR:-/tmp}/mam$$
  183. trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15
  184. exec > $tmp
  185. echo "probing C language processor $cc for mam information" >&2
  186. ;;
  187. esac
  188. echo "note generated by $0 for $cc"
  189. (
  190. set '' $opt $cc
  191. shift
  192. . $makeprobe "$@"
  193. case " $CC_DIALECT " in
  194. *" -L "*) echo "CC.L = 1" ;;
  195. esac
  196. ) | sed \
  197. -e '/^CC\./!d' \
  198. -e 's/^CC./setv mam_cc_/' \
  199. -e 's/^\([^=.]*\)\./\1_/' \
  200. -e 's/^\([^=.]*\)\./\1_/' \
  201. -e 's/ =//' \
  202. -e 's/\$("\([^"]*\)")/\1/g' \
  203. -e 's/\$(\([^)]*\))/${\1}/g' \
  204. -e 's/\${CC\./${mam_cc_}/g'
  205. echo 'setv _hosttype_ ${mam_cc_HOSTTYPE}'
  206. # STD* are standard commands/flags with possible execrate(1)
  207. if (
  208. ed <<!
  209. q
  210. !
  211. ) < /dev/null > /dev/null 2>&1
  212. then STDED=ed
  213. else STDED=ex
  214. fi
  215. STDEDFLAGS=-
  216. set STDCAT cat STDCHMOD chmod STDCMP cmp STDCP cp STDLN ln STDMV mv STDRM rm
  217. while :
  218. do case $# in
  219. 0|1) break ;;
  220. esac
  221. p=$2
  222. for d in $bins
  223. do if test -x $d/$p
  224. then p=$d/$p
  225. break
  226. fi
  227. done
  228. eval $1=\$p
  229. shift
  230. shift
  231. done
  232. if execrate
  233. then for n in STDCAT STDCHMOD STDCMP STDCP STDLN STDMV STDRM
  234. do eval $n=\"execrate \$$n\"
  235. done
  236. fi
  237. for n in STDCAT STDCHMOD STDCMP STDCP STDED STDEDFLAGS STDLN STDMV STDRM
  238. do eval echo setv \$n \$$n
  239. done
  240. # all done
  241. case $info in
  242. -) ;;
  243. *) exec >/dev/null
  244. test -f "$info" && rm -f "$info"
  245. cp "$tmp" "$info"
  246. chmod -w "$info"
  247. ;;
  248. esac