Skip various cmp-mem-const tests on lp64 hppa*-*-*
[official-gcc.git] / libffi / msvcc.sh
blob301e2fbd6840feae9944add823a829b1c89bda8f
1 #!/bin/sh
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
14 # License.
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.
23 # Contributor(s):
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.
45 args_orig=$@
46 args="-nologo -W3"
47 linkargs=
48 static_crt=
49 debug_crt=
50 cl="cl"
51 ml="ml"
52 safeseh="-safeseh"
53 output=
54 libpaths=
55 libversion=8
56 verbose=
58 while [ $# -gt 0 ]
60 case $1
62 --verbose)
63 verbose=1
64 shift 1
66 --version)
67 args="-help"
68 shift 1
70 -fexceptions)
71 # Don't enable exceptions for now.
72 #args="$args -EHac"
73 shift 1
75 -m32)
76 shift 1
78 -m64)
79 ml="ml64" # "$MSVC/x86_amd64/ml64"
80 safeseh=
81 shift 1
83 -marm)
84 ml='armasm'
85 safeseh=
86 shift 1
88 -marm64)
89 ml='armasm64'
90 safeseh=
91 shift 1
93 -clang-cl)
94 cl="clang-cl"
95 shift 1
97 -O0)
98 args="$args -Od"
99 shift 1
101 -O*)
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.
106 case $args_orig in
107 *-DFFI_DEBUG*)
108 args="$args"
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.
115 case $1 in
116 -O3)
117 args="$args -O2"
120 args="$args $1"
122 esac
123 opt="true"
125 esac
126 shift 1
129 # Enable debug symbol generation.
130 args="$args -Zi"
131 shift 1
133 -DFFI_DEBUG)
134 # Enable runtime error checks.
135 args="$args -RTC1"
136 defines="$defines $1"
137 shift 1
139 -DUSE_STATIC_RTL)
140 # Link against static CRT.
141 static_crt=1
142 shift 1
144 -DUSE_DEBUG_RTL)
145 # Link against debug CRT.
146 debug_crt=1
147 shift 1
150 args="$args -c"
151 args="$(echo $args | sed 's%/Fe%/Fo%g')"
152 single="-c"
153 shift 1
155 -D*=*)
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'"
160 shift 1
162 -D*)
163 args="$args $1"
164 defines="$defines $1"
165 shift 1
168 p=$(cygpath -ma "$2")
169 args="$args -I\"$p\""
170 includes="$includes -I\"$p\""
171 shift 2
173 -I*)
174 p=$(cygpath -ma "${1#-I}")
175 args="$args -I\"$p\""
176 includes="$includes -I\"$p\""
177 shift 1
180 p=$(cygpath -ma $2)
181 linkargs="$linkargs -LIBPATH:$p"
182 shift 2
184 -L*)
185 p=$(cygpath -ma ${1#-L})
186 linkargs="$linkargs -LIBPATH:$p"
187 shift 1
189 -link)
190 # add next argument verbatim to linker args
191 linkargs="$linkargs $2"
192 shift 2
194 -l*)
195 case $1
197 -lffi)
198 linkargs="$linkargs lib${1#-l}-${libversion}.lib"
201 # ignore other libraries like -lm, hope they are
202 # covered by MSVCRT
203 # linkargs="$linkargs ${1#-l}.lib"
205 esac
206 shift 1
208 -W|-Wextra)
209 # TODO map extra warnings
210 shift 1
212 -Wall)
213 # -Wall on MSVC is overzealous, and we already build with -W3. Nothing
214 # to do here.
215 shift 1
217 -pedantic)
218 # libffi tests -pedantic with -Wall, so drop it also.
219 shift 1
221 -warn)
222 # ignore -warn all from libtool as well.
223 if test "$2" = "all"; then
224 shift 2
225 else
226 args="$args -warn"
227 shift 1
230 -Werror)
231 args="$args -WX"
232 shift 1
234 -W*)
235 # TODO map specific warnings
236 shift 1
239 args="$args -FAs"
240 shift 1
243 outdir="$(dirname $2)"
244 base="$(basename $2|sed 's/\.[^.]*//g')"
245 if [ -n "$single" ]; then
246 output="-Fo$2"
247 else
248 output="-Fe$2"
250 armasm_output="-o $2"
251 if [ -n "$assembly" ]; then
252 args="$args $output"
253 else
254 args="$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"
256 shift 2
258 *.S)
259 src="$(cygpath -ma $1)"
260 assembly="true"
261 shift 1
263 *.c)
264 args="$args $(cygpath -ma $1)"
265 shift 1
268 # Assume it's an MSVC argument, and pass it through.
269 args="$args $1"
270 shift 1
272 esac
273 done
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
288 md=-MT
289 else
290 md=-MD
293 if [ -n "$debug_crt" ]; then
294 md="${md}d"
297 if [ -n "$assembly" ]; then
298 if [ -z "$outdir" ]; then
299 outdir="."
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"
321 else
322 args="-nologo $safeseh $single $output $ppsrc"
325 if test -n "$verbose"; then
326 echo "$ml $args"
329 eval "\"$ml\" $args"
330 result=$?
332 # required to fix ml64 broken output?
333 #mv *.obj $outdir
334 else
335 args="$md $args"
337 if test -n "$verbose"; then
338 echo "$cl $args"
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/'"
348 result=$?
351 exit $result
353 # vim: noai:ts=4:sw=4