msvcc.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #!/bin/sh
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. #
  5. # The contents of this file are subject to the Mozilla Public License Version
  6. # 1.1 (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. # http://www.mozilla.org/MPL/
  9. #
  10. # Software distributed under the License is distributed on an "AS IS" basis,
  11. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. # for the specific language governing rights and limitations under the
  13. # License.
  14. #
  15. # The Original Code is the MSVC wrappificator.
  16. #
  17. # The Initial Developer of the Original Code is
  18. # Timothy Wall <twalljava@dev.java.net>.
  19. # Portions created by the Initial Developer are Copyright (C) 2009
  20. # the Initial Developer. All Rights Reserved.
  21. #
  22. # Contributor(s):
  23. # Daniel Witte <dwitte@mozilla.com>
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either the GNU General Public License Version 2 or later (the "GPL"), or
  27. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38. #
  39. # GCC-compatible wrapper for cl.exe and ml.exe. Arguments are given in GCC
  40. # format and translated into something sensible for cl or ml.
  41. #
  42. args_orig=$@
  43. args="-nologo -W3"
  44. linkargs=
  45. static_crt=
  46. debug_crt=
  47. cl="cl"
  48. ml="ml"
  49. safeseh="-safeseh"
  50. output=
  51. libpaths=
  52. libversion=8
  53. verbose=
  54. while [ $# -gt 0 ]
  55. do
  56. case $1
  57. in
  58. --verbose)
  59. verbose=1
  60. shift 1
  61. ;;
  62. --version)
  63. args="-help"
  64. shift 1
  65. ;;
  66. -fexceptions)
  67. # Don't enable exceptions for now.
  68. #args="$args -EHac"
  69. shift 1
  70. ;;
  71. -m32)
  72. shift 1
  73. ;;
  74. -m64)
  75. ml="ml64" # "$MSVC/x86_amd64/ml64"
  76. safeseh=
  77. shift 1
  78. ;;
  79. -marm)
  80. ml='armasm'
  81. safeseh=
  82. shift 1
  83. ;;
  84. -marm64)
  85. ml='armasm64'
  86. safeseh=
  87. shift 1
  88. ;;
  89. -clang-cl)
  90. cl="clang-cl"
  91. shift 1
  92. ;;
  93. -O0)
  94. args="$args -Od"
  95. shift 1
  96. ;;
  97. -O*)
  98. # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG
  99. # case below) are not compatible with optimization flags and will
  100. # cause the build to fail. Therefore, drop the optimization flag if
  101. # -DFFI_DEBUG is also set.
  102. case $args_orig in
  103. *-DFFI_DEBUG*)
  104. args="$args"
  105. ;;
  106. *)
  107. # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive
  108. # project doesn't support MSVC and therefore ends up trying to
  109. # use -O3. Use the equivalent "max optimization" flag for MSVC
  110. # instead of erroring out.
  111. case $1 in
  112. -O3)
  113. args="$args -O2"
  114. ;;
  115. *)
  116. args="$args $1"
  117. ;;
  118. esac
  119. opt="true"
  120. ;;
  121. esac
  122. shift 1
  123. ;;
  124. -g)
  125. # Enable debug symbol generation.
  126. args="$args -Zi"
  127. shift 1
  128. ;;
  129. -DFFI_DEBUG)
  130. # Enable runtime error checks.
  131. args="$args -RTC1"
  132. defines="$defines $1"
  133. shift 1
  134. ;;
  135. -DUSE_STATIC_RTL)
  136. # Link against static CRT.
  137. static_crt=1
  138. shift 1
  139. ;;
  140. -DUSE_DEBUG_RTL)
  141. # Link against debug CRT.
  142. debug_crt=1
  143. shift 1
  144. ;;
  145. -c)
  146. args="$args -c"
  147. args="$(echo $args | sed 's%/Fe%/Fo%g')"
  148. single="-c"
  149. shift 1
  150. ;;
  151. -D*=*)
  152. name="$(echo $1|sed 's/-D\([^=][^=]*\)=.*/\1/g')"
  153. value="$(echo $1|sed 's/-D[^=][^=]*=//g')"
  154. args="$args -D${name}='$value'"
  155. defines="$defines -D${name}='$value'"
  156. shift 1
  157. ;;
  158. -D*)
  159. args="$args $1"
  160. defines="$defines $1"
  161. shift 1
  162. ;;
  163. -I)
  164. p=$(cygpath -ma "$2")
  165. args="$args -I\"$p\""
  166. includes="$includes -I\"$p\""
  167. shift 2
  168. ;;
  169. -I*)
  170. p=$(cygpath -ma "${1#-I}")
  171. args="$args -I\"$p\""
  172. includes="$includes -I\"$p\""
  173. shift 1
  174. ;;
  175. -L)
  176. p=$(cygpath -ma $2)
  177. linkargs="$linkargs -LIBPATH:$p"
  178. shift 2
  179. ;;
  180. -L*)
  181. p=$(cygpath -ma ${1#-L})
  182. linkargs="$linkargs -LIBPATH:$p"
  183. shift 1
  184. ;;
  185. -link)
  186. # add next argument verbatim to linker args
  187. linkargs="$linkargs $2"
  188. shift 2
  189. ;;
  190. -l*)
  191. case $1
  192. in
  193. -lffi)
  194. linkargs="$linkargs lib${1#-l}-${libversion}.lib"
  195. ;;
  196. *)
  197. # ignore other libraries like -lm, hope they are
  198. # covered by MSVCRT
  199. # linkargs="$linkargs ${1#-l}.lib"
  200. ;;
  201. esac
  202. shift 1
  203. ;;
  204. -W|-Wextra)
  205. # TODO map extra warnings
  206. shift 1
  207. ;;
  208. -Wall)
  209. # -Wall on MSVC is overzealous, and we already build with -W3. Nothing
  210. # to do here.
  211. shift 1
  212. ;;
  213. -pedantic)
  214. # libffi tests -pedantic with -Wall, so drop it also.
  215. shift 1
  216. ;;
  217. -warn)
  218. # ignore -warn all from libtool as well.
  219. if test "$2" = "all"; then
  220. shift 2
  221. else
  222. args="$args -warn"
  223. shift 1
  224. fi
  225. ;;
  226. -Werror)
  227. args="$args -WX"
  228. shift 1
  229. ;;
  230. -W*)
  231. # TODO map specific warnings
  232. shift 1
  233. ;;
  234. -S)
  235. args="$args -FAs"
  236. shift 1
  237. ;;
  238. -o)
  239. outdir="$(dirname $2)"
  240. base="$(basename $2|sed 's/\.[^.]*//g')"
  241. if [ -n "$single" ]; then
  242. output="-Fo$2"
  243. else
  244. output="-Fe$2"
  245. fi
  246. armasm_output="-o $2"
  247. if [ -n "$assembly" ]; then
  248. args="$args $output"
  249. else
  250. args="$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"
  251. fi
  252. shift 2
  253. ;;
  254. *.S)
  255. src="$(cygpath -ma $1)"
  256. assembly="true"
  257. shift 1
  258. ;;
  259. *.c)
  260. args="$args $(cygpath -ma $1)"
  261. shift 1
  262. ;;
  263. *)
  264. # Assume it's an MSVC argument, and pass it through.
  265. args="$args $1"
  266. shift 1
  267. ;;
  268. esac
  269. done
  270. if [ -n "$linkargs" ]; then
  271. # If -Zi is specified, certain optimizations are implicitly disabled
  272. # by MSVC. Add back those optimizations if this is an optimized build.
  273. # NOTE: These arguments must come after all others.
  274. if [ -n "$opt" ]; then
  275. linkargs="$linkargs -OPT:REF -OPT:ICF -INCREMENTAL:NO"
  276. fi
  277. args="$args -link $linkargs"
  278. fi
  279. if [ -n "$static_crt" ]; then
  280. md=-MT
  281. else
  282. md=-MD
  283. fi
  284. if [ -n "$debug_crt" ]; then
  285. md="${md}d"
  286. fi
  287. if [ -n "$assembly" ]; then
  288. if [ -z "$outdir" ]; then
  289. outdir="."
  290. fi
  291. ppsrc="$outdir/$(basename $src|sed 's/.S$/.asm/g')"
  292. if [ $ml = "armasm" ]; then
  293. defines="$defines -D_M_ARM"
  294. fi
  295. if [ $ml = "armasm64" ]; then
  296. defines="$defines -D_M_ARM64"
  297. fi
  298. if test -n "$verbose"; then
  299. echo "$cl -nologo -EP $includes $defines $src > $ppsrc"
  300. fi
  301. eval "\"$cl\" -nologo -EP $includes $defines $src" > $ppsrc || exit $?
  302. output="$(echo $output | sed 's%/F[dpa][^ ]*%%g')"
  303. if [ $ml = "armasm" ]; then
  304. args="-nologo -g -oldit $armasm_output $ppsrc -errorReport:prompt"
  305. elif [ $ml = "armasm64" ]; then
  306. args="-nologo -g $armasm_output $ppsrc -errorReport:prompt"
  307. else
  308. args="-nologo $safeseh $single $output $ppsrc"
  309. fi
  310. if test -n "$verbose"; then
  311. echo "$ml $args"
  312. fi
  313. eval "\"$ml\" $args"
  314. result=$?
  315. # required to fix ml64 broken output?
  316. #mv *.obj $outdir
  317. else
  318. args="$md $args"
  319. if test -n "$verbose"; then
  320. echo "$cl $args"
  321. fi
  322. # Return an error code of 1 if an invalid command line parameter is passed
  323. # instead of just ignoring it. Any output that is not a warning or an
  324. # error is filtered so this command behaves more like gcc. cl.exe prints
  325. # the name of the compiled file otherwise, which breaks the dejagnu checks
  326. # for excess warnings and errors.
  327. eval "(\"$cl\" $args 2>&1 1>&3 | \
  328. awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1 | \
  329. awk '/warning|error/'"
  330. result=$?
  331. fi
  332. exit $result
  333. # vim: noai:ts=4:sw=4