#!/bin/sh # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # # The contents of this file are subject to the Mozilla Public License Version # 1.1 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the # License. # # The Original Code is the MSVC wrappificator. # # The Initial Developer of the Original Code is # Timothy Wall . # Portions created by the Initial Developer are Copyright (C) 2009 # the Initial Developer. All Rights Reserved. # # Contributor(s): # Daniel Witte # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** # # GCC-compatible wrapper for cl.exe and ml.exe. Arguments are given in GCC # format and translated into something sensible for cl or ml. # setglobal args_orig = $ifsjoin(Argv) setglobal args = '"-nologo -W3'" setglobal static_crt = '' setglobal debug_crt = '' setglobal cl = '"cl'" setglobal ml = '"ml'" setglobal safeseh = '"-safeseh'" setglobal output = '' while [ $# -gt 0 ] { match $1 { with -fexceptions # Don't enable exceptions for now. #args="$args -EHac" shift 1 with -m32 shift 1 with -m64 setglobal ml = '"ml64'" # "$MSVC/x86_amd64/ml64" setglobal safeseh = '' shift 1 with -clang-cl setglobal cl = '"clang-cl'" setglobal safeseh = '' shift 1 with -O0 setglobal args = ""$args -Od"" shift 1 with -O* # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG # case below) are not compatible with optimization flags and will # cause the build to fail. Therefore, drop the optimization flag if # -DFFI_DEBUG is also set. match $args_orig { with *-DFFI_DEBUG* setglobal args = $args with * # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive # project doesn't support MSVC and therefore ends up trying to # use -O3. Use the equivalent "max optimization" flag for MSVC # instead of erroring out. match $1 { with -O3 setglobal args = ""$args -O2"" with * setglobal args = ""$args $1"" } setglobal opt = '"true'" } shift 1 with -g # Enable debug symbol generation. setglobal args = ""$args -Zi"" shift 1 with -DFFI_DEBUG # Enable runtime error checks. setglobal args = ""$args -RTC1"" setglobal defines = ""$defines $1"" shift 1 with -DUSE_STATIC_RTL # Link against static CRT. setglobal static_crt = '1' shift 1 with -DUSE_DEBUG_RTL # Link against debug CRT. setglobal debug_crt = '1' shift 1 with -c setglobal args = ""$args -c"" setglobal args = $[echo $args | sed 's%/Fe%/Fo%g] setglobal single = '"-c'" shift 1 with -D*=* setglobal name = $[echo $1|sed 's/-D\([^=][^=]*\)=.*/\1/g] setglobal value = $[echo $1|sed 's/-D[^=][^=]*=//g] setglobal args = ""$args -D$(name)='$value'"" setglobal defines = ""$defines -D$(name)='$value'"" shift 1 with -D* setglobal args = ""$args $1"" setglobal defines = ""$defines $1"" shift 1 with -I setglobal args = ""$args -I$2"" setglobal includes = ""$includes -I$2"" shift 2 with -I* setglobal args = ""$args $1"" setglobal includes = ""$includes $1"" shift 1 with -W|-Wextra # TODO map extra warnings shift 1 with -Wall # -Wall on MSVC is overzealous, and we already build with -W3. Nothing # to do here. shift 1 with -pedantic # libffi tests -pedantic with -Wall, so drop it also. shift 1 with -Werror setglobal args = ""$args -WX"" shift 1 with -W* # TODO map specific warnings shift 1 with -S setglobal args = ""$args -FAs"" shift 1 with -o setglobal outdir = $[dirname $2] setglobal base = $[basename $2|sed 's/\.[^.]*//g] if test -n $single { setglobal output = ""-Fo$2"" } else { setglobal output = ""-Fe$2"" } if test -n $assembly { setglobal args = ""$args $output"" } else { setglobal args = ""$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"" } shift 2 with *.S setglobal src = $1 setglobal assembly = '"true'" shift 1 with *.c setglobal args = ""$args $1"" shift 1 with * # Assume it's an MSVC argument, and pass it through. setglobal args = ""$args $1"" shift 1 } } # If -Zi is specified, certain optimizations are implicitly disabled # by MSVC. Add back those optimizations if this is an optimized build. # NOTE: These arguments must come after all others. if test -n $opt { setglobal args = ""$args -link -OPT:REF -OPT:ICF -INCREMENTAL:NO"" } if test -n $static_crt { setglobal md = '-MT' } else { setglobal md = '-MD' } if test -n $debug_crt { setglobal md = ""$(md)d"" } if test -n $assembly { if test -z $outdir { setglobal outdir = '".'" } setglobal ppsrc = ""$outdir/$[basename $src|sed 's/.S$/.asm/g]"" echo "$cl -nologo -EP $includes $defines $src > $ppsrc" $cl -nologo -EP $includes $defines $src > $ppsrc || exit $? setglobal output = $[echo $output | sed 's%/F[dpa][^ ]*%%g] setglobal args = ""-nologo $safeseh $single $output $ppsrc"" echo "$ml $args" eval "\"$ml\" $args" setglobal result = $Status # required to fix ml64 broken output? #mv *.obj $outdir } else { setglobal args = ""$md $args"" echo "$cl $args" # Return an error code of 1 if an invalid command line parameter is passed # instead of just ignoring it. eval "(\"$cl\" $args 2>&1 1>&3 | \ awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1" setglobal result = $Status } exit $result