diff options
author | Dan Gudmundsson <dgud@erlang.org> | 2019-11-11 15:43:49 +0100 |
---|---|---|
committer | Dan Gudmundsson <dgud@erlang.org> | 2019-11-12 07:51:31 +0100 |
commit | 73d3d02d887408e99489a9df3877dd409021cc82 (patch) | |
tree | b06d5d49a43c4f3ab61ab6d11f8a5638816ee91a | |
parent | 3a162745c62b1f46580bdc0851f17ac46937197c (diff) | |
download | erlang-73d3d02d887408e99489a9df3877dd409021cc82.tar.gz |
Setup VC env in otp_build
If there is no cl.exe in path try to setup the paths and the
needed env variables.
Use vcvarsall.bat from VC so we get the correct path and libraries.
Search some default installations paths
-rw-r--r-- | erts/etc/win32/wsl_tools/SetupWSLcross.bat | 60 | ||||
-rwxr-xr-x | otp_build | 27 |
2 files changed, 85 insertions, 2 deletions
diff --git a/erts/etc/win32/wsl_tools/SetupWSLcross.bat b/erts/etc/win32/wsl_tools/SetupWSLcross.bat new file mode 100644 index 0000000000..d29400f133 --- /dev/null +++ b/erts/etc/win32/wsl_tools/SetupWSLcross.bat @@ -0,0 +1,60 @@ +@echo off +rem Setup MCL and echo the environment +rem Usage: eval `cmd.exe /c SetupWSLcross.bat x64` + +IF "%~1"=="x86" GOTO search +IF "%~1"=="x64" GOTO search + +GOTO badarg + +:search +IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat". ( + call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" %~1 > nul + goto continue +) + +IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat". ( + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" %~1 > nul + goto continue +) + +IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat". ( + call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" %~1 > nul + goto continue +) + +IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat". ( + call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %~1 > nul + goto continue +) + +GOTO no_vcvars + +:continue + +FOR /F "delims==" %%F IN ('where cl.exe') DO SET _cl_exec_=%%F +FOR %%F IN ("%_cl_exec_%") DO SET CL_PATH=%%~dpF + +FOR /F "delims==" %%F IN ('where rc.exe') DO SET _rc_exec_=%%F +FOR %%F IN ("%_rc_exec_%") DO SET RC_PATH=%%~dpF + +rem Order is important for some unknown reason +set WSLENV=VCToolsRedistDir/up:CL_PATH/up:RC_PATH/up:LIBPATH/ul:LIB/ul:INCLUDE/ul +wsl.exe echo INCLUDE=\"$INCLUDE\"; +wsl.exe echo LIB=\"$LIB\"; +wsl.exe echo LIBPATH=\"$LIBPATH\"; +wsl.exe echo VCToolsRedistDir=\"$VCToolsRedistDir\"; +wsl.exe echo PATH=\"$CL_PATH\":\"$RC_PATH\":'$PATH'; +wsl.exe echo WSLENV='$WSLENV:LIBPATH/l:LIB/l:INCLUDE/l'; +rem wsl.exe echo export 'INCLUDE LIB LIBPATH VCToolsRedistDir WSLENV PATH'; +wsl.exe echo "# Eval this file eval \`cmd.exe /c SetupWSLcross.bat\`" + +exit + +:badarg +echo "Bad TARGET or not specified: %~1 expected x86 or x64" +exit + +:no_vcvars +echo "Error: SetupWSLcross.bat: Could not find vcvarsall.bat" +exit @@ -777,6 +777,13 @@ echo_env_wsl () WIN32_WRAPPER_PATH="$ERL_TOP/erts/etc/win32/wsl_tools/vc:$ERL_TOP/erts/etc/win32/wsl_tools" + if [ ! -n "`lookup_prog_in_path cl`" ]; then + if [ X"$X64" = X"true" ]; then + setup_win32_cl_env "x64" `wslpath -a -m erts/etc/win32/wsl_tools/SetupWSLcross.bat` + else + setup_win32_cl_env "x86" `wslpath -a -m erts/etc/win32/wsl_tools/SetupWSLcross.bat` + fi + fi echo_setenv OVERRIDE_TARGET win32 ';' if [ X"$X64" = X"true" ]; then echo_setenv CONFIG_SUBTYPE win64 ';' @@ -802,6 +809,17 @@ echo_env_wsl () echo_envinfo } + +setup_win32_cl_env () +{ + eval `cmd.exe /c $2 $1` + echo_setenv INCLUDE "$INCLUDE" ';' + echo_setenv LIB "$LIB" ';' + echo_setenv LIBPATH "$LIBPATH" ';' + echo_setenv VCToolsRedistDir "$VCToolsRedistDir" ';' + echo_setenv WSLENV "$WSLENV" ';' +} + lookup_prog_in_path () { PROG=$1 @@ -1092,8 +1110,13 @@ case $TARGET in 'the command' exit 1 fi;; - *) - ;; + *) + if [ -x /bin/wslpath -a X"$OVERRIDE_TARGET" = X"" \ + -a X"$1" != X"env_win32" -a X"$1" != X"env_msys32" -a X"$1" != X"env_msys64" ]; then + echo "Building linux binary; if you intended to cross build for win32 use" >&2 + echo ' eval `./otp_build env_win32`\n' >&2 + fi + ;; esac if [ ! -z "$OVERRIDE_TARGET" ]; then |