2019-08-28 23:18:30 +02:00
|
|
|
@echo off
|
|
|
|
|
2019-08-29 23:13:53 +02:00
|
|
|
echo Building V
|
2019-08-28 23:18:30 +02:00
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
REM default tcc
|
|
|
|
set tcc_url=https://github.com/vlang/tccbin_win
|
|
|
|
set tcc_dir=%~dp0thirdparty\tcc
|
|
|
|
|
|
|
|
REM let a particular environment specify their own tcc
|
|
|
|
if "%TCC_GIT%" =="" goto :init
|
|
|
|
set tcc_url="%TCC_GIT%"
|
|
|
|
|
|
|
|
:init
|
|
|
|
REM initialize the log file with the failure message
|
2020-07-10 21:50:29 +02:00
|
|
|
set log_file=%TEMP%\v_make.bat.log
|
2020-07-16 18:33:26 +02:00
|
|
|
echo Failed to compile - Create an issue at 'https://github.com/vlang/v' with the following info:>%log_file%
|
|
|
|
echo.>>%log_file%
|
|
|
|
|
|
|
|
REM alleviate weird issues with this var
|
|
|
|
set cloned_tcc=
|
|
|
|
set ERRORLEVEL=
|
|
|
|
|
2020-03-20 16:40:49 +01:00
|
|
|
pushd %~dp0
|
|
|
|
|
2020-06-04 14:07:02 +02:00
|
|
|
if "%~1"=="-local" goto :compile
|
|
|
|
if "%~2"=="-local" goto :compile
|
|
|
|
|
2019-08-28 23:18:30 +02:00
|
|
|
if exist "vc" (
|
2020-05-22 10:46:55 +02:00
|
|
|
echo Updating vc...
|
|
|
|
cd vc
|
2020-05-22 16:42:34 +02:00
|
|
|
git pull --quiet
|
2020-05-22 10:46:55 +02:00
|
|
|
cd ..
|
|
|
|
) else (
|
|
|
|
echo Cloning vc...
|
|
|
|
git clone --depth 1 --quiet https://github.com/vlang/vc
|
2019-08-28 23:18:30 +02:00
|
|
|
)
|
|
|
|
|
2020-06-04 14:07:02 +02:00
|
|
|
:compile
|
2020-06-19 12:54:56 +02:00
|
|
|
REM option to force msvc, gcc or tcc
|
2020-07-16 18:33:26 +02:00
|
|
|
if "%~1"=="-gcc" set force_gcc=1 & goto :gcc_strap
|
|
|
|
if "%~2"=="-gcc" set force_gcc=1 & goto :gcc_strap
|
|
|
|
if "%~1"=="-msvc" set force_msvc=1 & goto :msvc_strap
|
|
|
|
if "%~2"=="-msvc" set force_msvc=1 & goto :msvc_strap
|
|
|
|
if "%~1"=="-tcc" set force_tcc=1 & goto :tcc_strap
|
|
|
|
if "%~2"=="-tcc" set force_tcc=1 & goto :tcc_strap
|
|
|
|
if "%~1"=="-fresh_tcc" set force_tcc=1 & goto :fresh_tcc
|
|
|
|
if "%~2"=="-fresh_tcc" set force_tcc=1 & goto :fresh_tcc
|
2019-08-29 23:13:53 +02:00
|
|
|
|
2020-03-18 18:15:33 +01:00
|
|
|
:gcc_strap
|
2020-06-19 12:54:56 +02:00
|
|
|
echo.
|
2019-09-01 15:43:40 +02:00
|
|
|
echo Attempting to build v.c with GCC...
|
2019-08-29 23:13:53 +02:00
|
|
|
|
2020-06-19 12:54:56 +02:00
|
|
|
where /q gcc
|
|
|
|
if %ERRORLEVEL% NEQ 0 (
|
|
|
|
echo ^> GCC not found
|
|
|
|
if "%force_gcc%" NEQ "" goto :error
|
2020-03-18 18:15:33 +01:00
|
|
|
goto :msvc_strap
|
2019-08-29 23:13:53 +02:00
|
|
|
)
|
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
gcc -std=c99 -municode -w -o v.exe .\vc\v_win.c>>%log_file% 2>>&1
|
2020-07-10 21:50:29 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 (
|
|
|
|
rem In most cases, compile errors happen because the version of GCC installed is too old
|
|
|
|
gcc --version>>%log_file% 2>>&1
|
|
|
|
goto :compile_error
|
|
|
|
)
|
2019-08-29 23:13:53 +02:00
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
echo ^> Compiling with .\v.exe self
|
2020-07-10 21:50:29 +02:00
|
|
|
v.exe self>>%log_file% 2>>&1
|
2020-06-19 12:54:56 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
2019-08-29 23:13:53 +02:00
|
|
|
goto :success
|
|
|
|
|
2020-03-18 18:15:33 +01:00
|
|
|
:msvc_strap
|
2020-06-19 12:54:56 +02:00
|
|
|
echo.
|
|
|
|
echo Attempting to build v.c with MSVC...
|
2019-10-16 01:54:35 +02:00
|
|
|
set VsWhereDir=%ProgramFiles(x86)%
|
|
|
|
set HostArch=x64
|
|
|
|
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
|
2020-03-18 18:15:33 +01:00
|
|
|
echo Using x86 Build Tools...
|
|
|
|
set VsWhereDir=%ProgramFiles%
|
|
|
|
set HostArch=x86
|
2019-10-16 01:54:35 +02:00
|
|
|
)
|
2020-06-19 12:54:56 +02:00
|
|
|
|
|
|
|
if not exist "%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" (
|
|
|
|
echo ^> MSVC not found
|
|
|
|
if "%force_msvc%" NEQ "" goto :error
|
|
|
|
goto :tcc_strap
|
|
|
|
)
|
|
|
|
|
2019-10-16 01:54:35 +02:00
|
|
|
for /f "usebackq tokens=*" %%i in (`"%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
|
2020-03-18 18:15:33 +01:00
|
|
|
set InstallDir=%%i
|
2019-08-28 23:38:09 +02:00
|
|
|
)
|
2019-08-28 23:18:30 +02:00
|
|
|
|
2019-08-29 23:13:53 +02:00
|
|
|
if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
|
2020-06-19 12:54:56 +02:00
|
|
|
call "%InstallDir%\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo > NUL
|
2020-05-06 12:05:52 +02:00
|
|
|
) else if exist "%VsWhereDir%\Microsoft Visual Studio 14.0\Common7\Tools\vsdevcmd.bat" (
|
2020-06-19 12:54:56 +02:00
|
|
|
call "%VsWhereDir%\Microsoft Visual Studio 14.0\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo > NUL
|
2019-08-29 23:13:53 +02:00
|
|
|
)
|
|
|
|
|
2019-12-22 20:59:51 +01:00
|
|
|
set ObjFile=.v.c.obj
|
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
cl.exe /volatile:ms /Fo%ObjFile% /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /nologo /out:v.exe /incremental:no>>%log_file% 2>>&1
|
2020-06-19 12:54:56 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
2019-08-29 23:13:53 +02:00
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
echo ^> Compiling with .\v.exe self
|
2020-07-10 21:50:29 +02:00
|
|
|
v.exe -cc msvc self>>%log_file% 2>>&1
|
2020-07-16 18:33:26 +02:00
|
|
|
del %ObjFile%>>%log_file% 2>>&1
|
2020-06-19 12:54:56 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
|
|
|
goto :success
|
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
:fresh_tcc
|
|
|
|
rd /s /q %tcc_dir%
|
|
|
|
|
2020-06-19 12:54:56 +02:00
|
|
|
:clone_tcc
|
2020-07-16 18:33:26 +02:00
|
|
|
git clone --depth 1 --quiet %tcc_url% %tcc_dir%
|
2020-06-19 12:54:56 +02:00
|
|
|
set cloned_tcc=1
|
|
|
|
goto :tcc_strap
|
|
|
|
|
|
|
|
:tcc_strap
|
|
|
|
echo.
|
|
|
|
echo Attempting to build v.c with TCC...
|
|
|
|
|
|
|
|
where /q tcc
|
2019-09-17 13:56:32 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 (
|
2020-07-16 18:33:26 +02:00
|
|
|
if exist "%tcc_dir%" (
|
|
|
|
set tcc_exe=%tcc_dir%\tcc.exe
|
2020-06-19 12:54:56 +02:00
|
|
|
) else if "%cloned_tcc%"=="" (
|
|
|
|
echo ^> TCC not found
|
2020-07-16 18:33:26 +02:00
|
|
|
echo ^> Downloading TCC from %tcc_url%
|
2020-06-19 12:54:56 +02:00
|
|
|
goto :clone_tcc
|
|
|
|
) else (
|
2020-07-16 18:33:26 +02:00
|
|
|
echo ^> TCC not found, even after cloning %cloned_tcc%
|
2020-06-19 12:54:56 +02:00
|
|
|
goto :error
|
|
|
|
)
|
|
|
|
) else (
|
|
|
|
for /f "delims=" %%i in ('where tcc') do set tcc_exe=%%i
|
2019-08-29 23:13:53 +02:00
|
|
|
)
|
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
if exist "%tcc_dir%" (
|
2020-06-19 12:54:56 +02:00
|
|
|
if "%cloned_tcc%"=="" (
|
|
|
|
echo ^> Updating prebuilt TCC...
|
2020-07-16 18:33:26 +02:00
|
|
|
pushd "%tcc_dir%"\
|
2020-07-10 21:50:29 +02:00
|
|
|
git pull -q
|
2020-06-19 12:54:56 +02:00
|
|
|
popd
|
|
|
|
)
|
|
|
|
)
|
2020-07-16 18:33:26 +02:00
|
|
|
|
|
|
|
%tcc_exe% -std=c99 -municode -lws2_32 -lshell32 -ladvapi32 -bt10 -w -o v.exe vc\v_win.c
|
2020-06-19 12:54:56 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
2019-08-28 23:18:30 +02:00
|
|
|
|
2020-07-16 18:33:26 +02:00
|
|
|
echo ^> Compiling with .\v.exe self
|
2020-07-10 21:50:29 +02:00
|
|
|
v.exe -cc "%tcc_exe%" self>>%log_file% 2>>&1
|
2020-06-19 12:54:56 +02:00
|
|
|
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
|
|
|
goto :success
|
2019-08-29 23:13:53 +02:00
|
|
|
|
2020-03-18 18:15:33 +01:00
|
|
|
:compile_error
|
2020-07-10 21:50:29 +02:00
|
|
|
echo.
|
|
|
|
echo.
|
|
|
|
type %log_file%
|
|
|
|
del %log_file%
|
2019-08-29 23:13:53 +02:00
|
|
|
goto :error
|
|
|
|
|
|
|
|
:error
|
2020-06-19 12:54:56 +02:00
|
|
|
echo.
|
2019-08-29 23:13:53 +02:00
|
|
|
echo Exiting from error
|
2020-03-20 16:40:49 +01:00
|
|
|
popd
|
2019-08-29 23:13:53 +02:00
|
|
|
exit /b 1
|
|
|
|
|
|
|
|
:success
|
2020-06-19 12:54:56 +02:00
|
|
|
echo ^> V built successfully!
|
2020-07-16 18:33:26 +02:00
|
|
|
echo ^> To add V to your PATH, run `.\v.exe symlink`.
|
|
|
|
del v_old.exe >>%log_file% 2>>&1
|
2020-07-10 21:50:29 +02:00
|
|
|
del %log_file%
|
2020-06-19 12:54:56 +02:00
|
|
|
|
|
|
|
:version
|
|
|
|
echo.
|
|
|
|
echo | set /p="V version: "
|
2020-07-16 18:33:26 +02:00
|
|
|
.\v.exe version
|
2020-06-19 12:54:56 +02:00
|
|
|
if "%cloned_tcc%" NEQ "" (
|
2020-07-16 18:33:26 +02:00
|
|
|
if "%force_tcc%" == "" (
|
|
|
|
echo.
|
|
|
|
echo WARNING: No C compiler was detected in your PATH. `tcc` was used temporarily
|
|
|
|
echo to build V, but it may have some bugs and may not work in all cases.
|
|
|
|
echo A more advanced C compiler like GCC or MSVC is recommended.
|
|
|
|
echo https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows
|
|
|
|
echo.
|
|
|
|
)
|
2020-06-19 12:54:56 +02:00
|
|
|
)
|
|
|
|
|
2020-03-20 16:40:49 +01:00
|
|
|
popd
|