Define FFI_SIZEOF_JAVA_RAW for aarch64 ILP32
[libffi.git] / msvcc.sh
1 #!/bin/sh
2
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 #
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/
10 #
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.
15 #
16 # The Original Code is the MSVC wrappificator.
17 #
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.
22 #
23 # Contributor(s):
24 # Daniel Witte <dwitte@mozilla.com>
25 #
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.
37 #
38 # ***** END LICENSE BLOCK *****
39
40 #
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.
43 #
44
45 args_orig=$@
46 args="-nologo -W3"
47 static_crt=
48 debug_crt=
49 cl="cl"
50 ml="ml"
51 safeseh="-safeseh"
52 output=
53
54 while [ $# -gt 0 ]
55 do
56 case $1
57 in
58 --version)
59 args="-help"
60 shift 1
61 ;;
62 -fexceptions)
63 # Don't enable exceptions for now.
64 #args="$args -EHac"
65 shift 1
66 ;;
67 -m32)
68 shift 1
69 ;;
70 -m64)
71 ml="ml64" # "$MSVC/x86_amd64/ml64"
72 safeseh=
73 shift 1
74 ;;
75 -clang-cl)
76 cl="clang-cl"
77 shift 1
78 ;;
79 -O0)
80 args="$args -Od"
81 shift 1
82 ;;
83 -O*)
84 # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG
85 # case below) are not compatible with optimization flags and will
86 # cause the build to fail. Therefore, drop the optimization flag if
87 # -DFFI_DEBUG is also set.
88 case $args_orig in
89 *-DFFI_DEBUG*)
90 args="$args"
91 ;;
92 *)
93 # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive
94 # project doesn't support MSVC and therefore ends up trying to
95 # use -O3. Use the equivalent "max optimization" flag for MSVC
96 # instead of erroring out.
97 case $1 in
98 -O3)
99 args="$args -O2"
100 ;;
101 *)
102 args="$args $1"
103 ;;
104 esac
105 opt="true"
106 ;;
107 esac
108 shift 1
109 ;;
110 -g)
111 # Enable debug symbol generation.
112 args="$args -Zi"
113 shift 1
114 ;;
115 -DFFI_DEBUG)
116 # Enable runtime error checks.
117 args="$args -RTC1"
118 defines="$defines $1"
119 shift 1
120 ;;
121 -DUSE_STATIC_RTL)
122 # Link against static CRT.
123 static_crt=1
124 shift 1
125 ;;
126 -DUSE_DEBUG_RTL)
127 # Link against debug CRT.
128 debug_crt=1
129 shift 1
130 ;;
131 -c)
132 args="$args -c"
133 args="$(echo $args | sed 's%/Fe%/Fo%g')"
134 single="-c"
135 shift 1
136 ;;
137 -D*=*)
138 name="$(echo $1|sed 's/-D\([^=][^=]*\)=.*/\1/g')"
139 value="$(echo $1|sed 's/-D[^=][^=]*=//g')"
140 args="$args -D${name}='$value'"
141 defines="$defines -D${name}='$value'"
142 shift 1
143 ;;
144 -D*)
145 args="$args $1"
146 defines="$defines $1"
147 shift 1
148 ;;
149 -I)
150 args="$args -I$2"
151 includes="$includes -I$2"
152 shift 2
153 ;;
154 -I*)
155 args="$args $1"
156 includes="$includes $1"
157 shift 1
158 ;;
159 -W|-Wextra)
160 # TODO map extra warnings
161 shift 1
162 ;;
163 -Wall)
164 # -Wall on MSVC is overzealous, and we already build with -W3. Nothing
165 # to do here.
166 shift 1
167 ;;
168 -pedantic)
169 # libffi tests -pedantic with -Wall, so drop it also.
170 shift 1
171 ;;
172 -Werror)
173 args="$args -WX"
174 shift 1
175 ;;
176 -W*)
177 # TODO map specific warnings
178 shift 1
179 ;;
180 -S)
181 args="$args -FAs"
182 shift 1
183 ;;
184 -o)
185 outdir="$(dirname $2)"
186 base="$(basename $2|sed 's/\.[^.]*//g')"
187 if [ -n "$single" ]; then
188 output="-Fo$2"
189 else
190 output="-Fe$2"
191 fi
192 if [ -n "$assembly" ]; then
193 args="$args $output"
194 else
195 args="$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"
196 fi
197 shift 2
198 ;;
199 *.S)
200 src=$1
201 assembly="true"
202 shift 1
203 ;;
204 *.c)
205 args="$args $1"
206 shift 1
207 ;;
208 *)
209 # Assume it's an MSVC argument, and pass it through.
210 args="$args $1"
211 shift 1
212 ;;
213 esac
214 done
215
216 # If -Zi is specified, certain optimizations are implicitly disabled
217 # by MSVC. Add back those optimizations if this is an optimized build.
218 # NOTE: These arguments must come after all others.
219 if [ -n "$opt" ]; then
220 args="$args -link -OPT:REF -OPT:ICF -INCREMENTAL:NO"
221 fi
222
223 if [ -n "$static_crt" ]; then
224 md=-MT
225 else
226 md=-MD
227 fi
228
229 if [ -n "$debug_crt" ]; then
230 md="${md}d"
231 fi
232
233 if [ -n "$assembly" ]; then
234 if [ -z "$outdir" ]; then
235 outdir="."
236 fi
237 ppsrc="$outdir/$(basename $src|sed 's/.S$/.asm/g')"
238 echo "$cl -nologo -EP $includes $defines $src > $ppsrc"
239 "$cl" -nologo -EP $includes $defines $src > $ppsrc || exit $?
240 output="$(echo $output | sed 's%/F[dpa][^ ]*%%g')"
241 args="-nologo $safeseh $single $output $ppsrc"
242
243 echo "$ml $args"
244 eval "\"$ml\" $args"
245 result=$?
246
247 # required to fix ml64 broken output?
248 #mv *.obj $outdir
249 else
250 args="$md $args"
251 echo "$cl $args"
252 # Return an error code of 1 if an invalid command line parameter is passed
253 # instead of just ignoring it.
254 eval "(\"$cl\" $args 2>&1 1>&3 | \
255 awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1"
256 result=$?
257 fi
258
259 exit $result
260