3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is the MSVC wrappificator.
18 # The Initial Developer of the Original Code is
19 # Timothy Wall <twalljava@dev.java.net>.
20 # Portions created by the Initial Developer are Copyright (C) 2009
21 # the Initial Developer. All Rights Reserved.
24 # Daniel Witte <dwitte@mozilla.com>
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
41 # GCC-compatible wrapper for cl.exe and ml.exe. Arguments are given in GCC
42 # format and translated into something sensible for cl or ml.
71 # Don't enable exceptions for now.
79 ml
="ml64" # "$MSVC/x86_amd64/ml64"
102 # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG
103 # case below) are not compatible with optimization flags and will
104 # cause the build to fail. Therefore, drop the optimization flag if
105 # -DFFI_DEBUG is also set.
111 # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive
112 # project doesn't support MSVC and therefore ends up trying to
113 # use -O3. Use the equivalent "max optimization" flag for MSVC
114 # instead of erroring out.
129 # Enable debug symbol generation.
134 # Enable runtime error checks.
136 defines
="$defines $1"
140 # Link against static CRT.
145 # Link against debug CRT.
151 args
="$(echo $args | sed 's%/Fe%/Fo%g')"
156 name
="$(echo $1|sed 's/-D\([^=][^=]*\)=.*/\1/g')"
157 value
="$(echo $1|sed 's/-D[^=][^=]*=//g')"
158 args
="$args -D${name}='$value'"
159 defines
="$defines -D${name}='$value'"
164 defines
="$defines $1"
168 p
=$
(cygpath
-ma "$2")
169 args
="$args -I\"$p\""
170 includes
="$includes -I\"$p\""
174 p
=$
(cygpath
-ma "${1#-I}")
175 args
="$args -I\"$p\""
176 includes
="$includes -I\"$p\""
181 linkargs
="$linkargs -LIBPATH:$p"
185 p
=$
(cygpath
-ma ${1#-L})
186 linkargs
="$linkargs -LIBPATH:$p"
190 # add next argument verbatim to linker args
191 linkargs
="$linkargs $2"
198 linkargs
="$linkargs lib${1#-l}-${libversion}.lib"
201 # ignore other libraries like -lm, hope they are
203 # linkargs="$linkargs ${1#-l}.lib"
209 # TODO map extra warnings
213 # -Wall on MSVC is overzealous, and we already build with -W3. Nothing
218 # libffi tests -pedantic with -Wall, so drop it also.
222 # ignore -warn all from libtool as well.
223 if test "$2" = "all"; then
235 # TODO map specific warnings
243 outdir
="$(dirname $2)"
244 base
="$(basename $2|sed 's/\.[^.]*//g')"
245 if [ -n "$single" ]; then
250 armasm_output
="-o $2"
251 if [ -n "$assembly" ]; then
254 args
="$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"
259 src
="$(cygpath -ma $1)"
264 args
="$args $(cygpath -ma $1)"
268 # Assume it's an MSVC argument, and pass it through.
275 if [ -n "$linkargs" ]; then
277 # If -Zi is specified, certain optimizations are implicitly disabled
278 # by MSVC. Add back those optimizations if this is an optimized build.
279 # NOTE: These arguments must come after all others.
280 if [ -n "$opt" ]; then
281 linkargs
="$linkargs -OPT:REF -OPT:ICF -INCREMENTAL:NO"
284 args
="$args -link $linkargs"
287 if [ -n "$static_crt" ]; then
293 if [ -n "$debug_crt" ]; then
297 if [ -n "$assembly" ]; then
298 if [ -z "$outdir" ]; then
301 ppsrc
="$outdir/$(basename $src|sed 's/.S$/.asm/g')"
303 if [ $ml = "armasm" ]; then
304 defines
="$defines -D_M_ARM"
307 if [ $ml = "armasm64" ]; then
308 defines
="$defines -D_M_ARM64"
311 if test -n "$verbose"; then
312 echo "$cl -nologo -EP $includes $defines $src > $ppsrc"
315 eval "\"$cl\" -nologo -EP $includes $defines $src" > $ppsrc ||
exit $?
316 output
="$(echo $output | sed 's%/F[dpa][^ ]*%%g')"
317 if [ $ml = "armasm" ]; then
318 args
="-nologo -g -oldit $armasm_output $ppsrc -errorReport:prompt"
319 elif [ $ml = "armasm64" ]; then
320 args
="-nologo -g $armasm_output $ppsrc -errorReport:prompt"
322 args
="-nologo $safeseh $single $output $ppsrc"
325 if test -n "$verbose"; then
332 # required to fix ml64 broken output?
337 if test -n "$verbose"; then
340 # Return an error code of 1 if an invalid command line parameter is passed
341 # instead of just ignoring it. Any output that is not a warning or an
342 # error is filtered so this command behaves more like gcc. cl.exe prints
343 # the name of the compiled file otherwise, which breaks the dejagnu checks
344 # for excess warnings and errors.
345 eval "(\"$cl\" $args 2>&1 1>&3 | \
346 awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1 | \
347 awk '/warning|error/'"
353 # vim: noai:ts=4:sw=4