Debian Codegraph @

js/src/ctypes/libffi/msvcc.sh

raw
1 #!/bin/sh
2
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 <[email protected]>.
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 <[email protected]>
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 #
38 # GCC-compatible wrapper for cl.exe and ml.exe. Arguments are given in GCC
39 # format and translated into something sensible for cl or ml.
40 #
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=7
53 verbose=
54
55 while [ $# -gt 0 ]
56 do
57 case $1
58 in
59 --verbose)
60 verbose=1
61 shift 1
62 ;;
63 --version)
64 args="-help"
65 shift 1
66 ;;
67 -fexceptions)
68 # Don't enable exceptions for now.
69 #args="$args -EHac"
70 shift 1
71 ;;
72 -m32)
73 shift 1
74 ;;
75 -m64)
76 ml="ml64" # "$MSVC/x86_amd64/ml64"
77 safeseh=
78 shift 1
79 ;;
80 -marm)
81 ml='armasm'
82 safeseh=
83 shift 1
84 ;;
85 -marm64)
86 ml='armasm64'
87 safeseh=
88 shift 1
89 ;;
90 -clang-cl)
91 cl="clang-cl"
92 shift 1
93 ;;
94 -O0)
95 args="$args -Od"
96 shift 1
97 ;;
98 -O*)
99 # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG
100 # case below) are not compatible with optimization flags and will
101 # cause the build to fail. Therefore, drop the optimization flag if
102 # -DFFI_DEBUG is also set.
103 case $args_orig in
104 *-DFFI_DEBUG*)
105 args="$args"
106 ;;
107 *)
108 # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive
109 # project doesn't support MSVC and therefore ends up trying to
110 # use -O3. Use the equivalent "max optimization" flag for MSVC
111 # instead of erroring out.
112 case $1 in
113 -O3)
114 args="$args -O2"
115 ;;
116 *)
117 args="$args $1"
118 ;;
119 esac
120 opt="true"
121 ;;
122 esac
123 shift 1
124 ;;
125 -g)
126 # Enable debug symbol generation.
127 args="$args -Zi"
128 shift 1
129 ;;
130 -DFFI_DEBUG)
131 # Enable runtime error checks.
132 args="$args -RTC1"
133 defines="$defines $1"
134 shift 1
135 ;;
136 -DUSE_STATIC_RTL)
137 # Link against static CRT.
138 static_crt=1
139 shift 1
140 ;;
141 -DUSE_DEBUG_RTL)
142 # Link against debug CRT.
143 debug_crt=1
144 shift 1
145 ;;
146 -c)
147 args="$args -c"
148 args="$(echo $args | sed 's%/Fe%/Fo%g')"
149 single="-c"
150 shift 1
151 ;;
152 -D*=*)
153 name="$(echo $1|sed 's/-D\([^=][^=]*\)=.*/\1/g')"
154 value="$(echo $1|sed 's/-D[^=][^=]*=//g')"
155 args="$args -D${name}='$value'"
156 defines="$defines -D${name}='$value'"
157 shift 1
158 ;;
159 -D*)
160 args="$args $1"
161 defines="$defines $1"
162 shift 1
163 ;;
164 -I)
165 p=$(cygpath -m $2)
166 args="$args -I$p"
167 includes="$includes -I$p"
168 shift 2
169 ;;
170 -I*)
171 p=$(cygpath -m ${1#-I})
172 args="$args -I$p"
173 includes="$includes -I$p"
174 shift 1
175 ;;
176 -L)
177 p=$(cygpath -m $2)
178 linkargs="$linkargs -LIBPATH:$p"
179 shift 2
180 ;;
181 -L*)
182 p=$(cygpath -m ${1#-L})
183 linkargs="$linkargs -LIBPATH:$p"
184 shift 1
185 ;;
186 -link)
187 # add next argument verbatim to linker args
188 linkargs="$linkargs $2"
189 shift 2
190 ;;
191 -l*)
192 case $1
193 in
194 -lffi)
195 linkargs="$linkargs lib${1#-l}-${libversion}.lib"
196 ;;
197 *)
198 # ignore other libraries like -lm, hope they are
199 # covered by MSVCRT
200 # linkargs="$linkargs ${1#-l}.lib"
201 ;;
202 esac
203 shift 1
204 ;;
205 -W|-Wextra)
206 # TODO map extra warnings
207 shift 1
208 ;;
209 -Wall)
210 # -Wall on MSVC is overzealous, and we already build with -W3. Nothing
211 # to do here.
212 shift 1
213 ;;
214 -pedantic)
215 # libffi tests -pedantic with -Wall, so drop it also.
216 shift 1
217 ;;
218 -warn)
219 # ignore -warn all from libtool as well.
220 if test "$2" = "all"; then
221 shift 2
222 else
223 args="$args -warn"
224 shift 1
225 fi
226 ;;
227 -Werror)
228 args="$args -WX"
229 shift 1
230 ;;
231 -W*)
232 # TODO map specific warnings
233 shift 1
234 ;;
235 -S)
236 args="$args -FAs"
237 shift 1
238 ;;
239 -o)
240 outdir="$(dirname $2)"
241 base="$(basename $2|sed 's/\.[^.]*//g')"
242 if [ -n "$single" ]; then
243 output="-Fo$2"
244 else
245 output="-Fe$2"
246 fi
247 armasm_output="-o $2"
248 if [ -n "$assembly" ]; then
249 args="$args $output"
250 else
251 args="$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"
252 fi
253 shift 2
254 ;;
255 *.S)
256 src=$1
257 assembly="true"
258 shift 1
259 ;;
260 *.c)
261 args="$args $1"
262 shift 1
263 ;;
264 *)
265 # Assume it's an MSVC argument, and pass it through.
266 args="$args $1"
267 shift 1
268 ;;
269 esac
270 done
271
272 if [ -n "$linkargs" ]; then
273
274 # If -Zi is specified, certain optimizations are implicitly disabled
275 # by MSVC. Add back those optimizations if this is an optimized build.
276 # NOTE: These arguments must come after all others.
277 if [ -n "$opt" ]; then
278 linkargs="$linkargs -OPT:REF -OPT:ICF -INCREMENTAL:NO"
279 fi
280
281 args="$args -link $linkargs"
282 fi
283
284 if [ -n "$static_crt" ]; then
285 md=-MT
286 else
287 md=-MD
288 fi
289
290 if [ -n "$debug_crt" ]; then
291 md="${md}d"
292 fi
293
294 if [ -n "$assembly" ]; then
295 if [ -z "$outdir" ]; then
296 outdir="."
297 fi
298 ppsrc="$outdir/$(basename $src|sed 's/.S$/.asm/g')"
299
300 if [ $ml = "armasm" ]; then
301 defines="$defines -D_M_ARM"
302 fi
303
304 if [ $ml = "armasm64" ]; then
305 defines="$defines -D_M_ARM64"
306 fi
307
308 if test -n "$verbose"; then
309 echo "$cl -nologo -EP $includes $defines $src > $ppsrc"
310 fi
311
312 "$cl" -nologo -EP $includes $defines $src > $ppsrc || exit $?
313 output="$(echo $output | sed 's%/F[dpa][^ ]*%%g')"
314 if [ $ml = "armasm" ]; then
315 args="-nologo -g -oldit $armasm_output $ppsrc -errorReport:prompt"
316 elif [ $ml = "armasm64" ]; then
317 args="-nologo -g $armasm_output $ppsrc -errorReport:prompt"
318 else
319 args="-nologo $safeseh $single $output $ppsrc"
320 fi
321
322 if test -n "$verbose"; then
323 echo "$ml $args"
324 fi
325
326 eval "\"$ml\" $args"
327 result=$?
328
329 # required to fix ml64 broken output?
330 #mv *.obj $outdir
331 else
332 args="$md $args"
333
334 if test -n "$verbose"; then
335 echo "$cl $args"
336 fi
337 # Return an error code of 1 if an invalid command line parameter is passed
338 # instead of just ignoring it. Any output that is not a warning or an
339 # error is filtered so this command behaves more like gcc. cl.exe prints
340 # the name of the compiled file otherwise, which breaks the dejagnu checks
341 # for excess warnings and errors.
342 eval "(\"$cl\" $args 2>&1 1>&3 | \
343 awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1 | \
344 awk '/warning|error/'"
345 result=$?
346 fi
347
348 exit $result
349
350 # vim: noai:ts=4:sw=4