make.bat: update convention to be consistent and add target support (#6942)
parent
8446433bcf
commit
4e9967a5f1
228
make.bat
228
make.bat
|
@ -1,59 +1,75 @@
|
||||||
@echo off
|
@echo off
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion EnableExtensions
|
||||||
|
|
||||||
REM option flags
|
REM Option flags
|
||||||
set /a valid_cc=0
|
set /a valid_cc=0
|
||||||
set /a use_local=0
|
set /a use_local=0
|
||||||
set /a verbose_log=0
|
set /a verbose_log=0
|
||||||
|
set /a shift_counter=0
|
||||||
|
|
||||||
REM option variables
|
REM Option variables
|
||||||
set log_file="%TEMP%\v_make.log"
|
set log_file="%TEMP%\v_make.log"
|
||||||
set compiler_opt=""
|
set compiler=""
|
||||||
|
set target=""
|
||||||
|
|
||||||
REM tcc variables
|
REM tcc variables
|
||||||
set tcc_url="https://github.com/vlang/tccbin_win.git"
|
set "tcc_url=https://github.com/vlang/tccbin_win.git"
|
||||||
set tcc_dir="%~dp0thirdparty\tcc"
|
set "tcc_dir=%~dp0thirdparty\tcc"
|
||||||
|
set "vc_url=https://github.com/vlang/vc.git"
|
||||||
|
set "vc_dir=%~dp0vc"
|
||||||
|
|
||||||
REM let a particular environment specify their own tcc
|
REM Let a particular environment specify their own tcc repo
|
||||||
if /I not "%TCC_GIT%" == "" (
|
if /I not ["%TCC_GIT%"] == [""] set "tcc_url=%TCC_GIT%"
|
||||||
set tcc_url="%TCC_GIT%"
|
|
||||||
)
|
|
||||||
|
|
||||||
pushd %~dp0
|
pushd %~dp0
|
||||||
|
|
||||||
:verifyopt
|
:verifyopt
|
||||||
REM end at EOL
|
REM Read stdin EOF
|
||||||
if ["%~1"] == [""] goto :init
|
if ["%~1"] == [""] goto :init
|
||||||
|
|
||||||
REM help option
|
REM Target options
|
||||||
if "%~1" == "-h" call :usage& exit /b %ERRORLEVEL%
|
if !shift_counter! LSS 1 (
|
||||||
if "%~1" == "--help" call :usage& exit /b %ERRORLEVEL%
|
if "%~1" == "build" set target="build"& shift& set /a shift_counter+=1& goto :verifyopt
|
||||||
|
if "%~1" == "clean" set target="clean"& shift& set /a shift_counter+=1& goto :verifyopt
|
||||||
|
if "%~1" == "clean-all" set target="clean-all"& shift& set /a shift_counter+=1& goto :verifyopt
|
||||||
|
if "%~1" == "help" (
|
||||||
|
if "%~2" == "build" call :help_build& exit /b %ERRORLEVEL%
|
||||||
|
if "%~2" == "clean" call :help_clean& exit /b %ERRORLEVEL%
|
||||||
|
if "%~2" == "clean-all" call :help_cleanall& exit /b %ERRORLEVEL%
|
||||||
|
if "%~2" == "help" call :help_help& exit /b %ERRORLEVEL%
|
||||||
|
if ["%~2"] == [""] call :usage& exit /b %ERRORLEVEL%
|
||||||
|
shift
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
REM compiler option
|
REM Compiler option
|
||||||
if "%~1" == "-gcc" set compiler_opt="gcc"& shift& goto :verifyopt
|
if "%~1" == "-gcc" set compiler="gcc"& set /a shift_counter+=1& shift& goto :verifyopt
|
||||||
if "%~1" == "-msvc" set compiler_opt="msvc"& shift& goto :verifyopt
|
if "%~1" == "-msvc" set compiler="msvc"& set /a shift_counter+=1& shift& goto :verifyopt
|
||||||
if "%~1" == "-tcc" set compiler_opt="tcc"& shift& goto :verifyopt
|
if "%~1" == "-tcc" set compiler="tcc"& set /a shift_counter+=1& shift& goto :verifyopt
|
||||||
if "%~1" == "-fresh-tcc" set compiler_opt="fresh-tcc"& shift& goto :verifyopt
|
if "%~1" == "-fresh-tcc" set compiler="fresh-tcc"& set /a shift_counter+=1& shift& goto :verifyopt
|
||||||
if "%~1" == "-clang" set compiler_opt="clang"& shift& goto :verifyopt
|
if "%~1" == "-clang" set compiler="clang"& set /a shift_counter+=1& shift& goto :verifyopt
|
||||||
|
|
||||||
REM standard options
|
REM Standard options
|
||||||
if "%~1" == "-local" (
|
if "%~1" == "--local" (
|
||||||
if !use_local! EQU 0 ( set /a use_local=1 )
|
if !use_local! EQU 0 set /a use_local=1
|
||||||
|
set /a shift_counter+=1
|
||||||
shift
|
shift
|
||||||
goto :verifyopt
|
goto :verifyopt
|
||||||
)
|
)
|
||||||
if "%~1" == "-v" (
|
if "%~1" == "-v" (
|
||||||
if !verbose_log! EQU 0 ( set /a verbose_log=1 )
|
if !verbose_log! EQU 0 set /a verbose_log=1
|
||||||
|
set /a shift_counter+=1
|
||||||
shift
|
shift
|
||||||
goto :verifyopt
|
goto :verifyopt
|
||||||
)
|
)
|
||||||
if "%~1" == "--verbose" (
|
if "%~1" == "--verbose" (
|
||||||
if !verbose_log! EQU 0 ( set /a verbose_log=1 )
|
if !verbose_log! EQU 0 set /a verbose_log=1
|
||||||
|
set /a shift_counter+=1
|
||||||
shift
|
shift
|
||||||
goto :verifyopt
|
goto :verifyopt
|
||||||
)
|
)
|
||||||
if "%~1" == "-logfile" (
|
if "%~1" == "--logfile" (
|
||||||
if /I "%~2" == "" (
|
if ["%~2"] == [""] (
|
||||||
echo Log file is not specified for -logfile parameter. 1>&2
|
echo Log file is not specified for -logfile parameter. 1>&2
|
||||||
exit /b 2
|
exit /b 2
|
||||||
)
|
)
|
||||||
|
@ -63,55 +79,62 @@ if "%~1" == "-logfile" (
|
||||||
)
|
)
|
||||||
popd
|
popd
|
||||||
set log_file="%~sf2"
|
set log_file="%~sf2"
|
||||||
|
set /a shift_counter+=2
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
goto :verifyopt
|
goto :verifyopt
|
||||||
)
|
)
|
||||||
echo Ignoring unidentified option: %~1 & shift
|
echo Undefined option: %~1
|
||||||
goto :verifyopt
|
exit /b 2
|
||||||
|
|
||||||
:init
|
:init
|
||||||
echo.
|
if !target! == "build" goto :build
|
||||||
|
if !target! == "clean" echo Cleanup build artifacts& goto :clean
|
||||||
|
if !target! == "clean-all" echo Cleanup all& goto :cleanall
|
||||||
|
if [!target!] == [""] goto :build
|
||||||
|
|
||||||
|
:build
|
||||||
del !log_file!>NUL 2>&1
|
del !log_file!>NUL 2>&1
|
||||||
if !use_local! NEQ 1 (
|
if !use_local! NEQ 1 (
|
||||||
if exist "vc" (
|
pushd "%vc_dir%" 2>NUL&& (
|
||||||
echo Updating vc...
|
echo Updating vc...
|
||||||
echo ^> Sync with remote https://github.com/vlang/vc.git
|
echo ^> Sync with remote !vc_url!
|
||||||
call :buildcmd "cd vc" " "
|
call :buildcmd "cd "%vc_dir%"" " "
|
||||||
call :buildcmd "git pull --quiet" " "
|
call :buildcmd "git pull --quiet" " "
|
||||||
call :buildcmd "cd .." " "
|
call :buildcmd "cd .." " "
|
||||||
) else (
|
) || (
|
||||||
echo Cloning vc...
|
echo Cloning vc...
|
||||||
echo ^> Cloning from remote https://github.com/vlang/vc.git
|
echo ^> Cloning from remote !vc_url!
|
||||||
call :buildcmd "git clone --depth 1 --quiet https://github.com/vlang/vc.git" " "
|
call :buildcmd "git clone --depth 1 --quiet "%vc_url%"" " "
|
||||||
)
|
)
|
||||||
|
popd
|
||||||
)
|
)
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo Building V...
|
echo Building V...
|
||||||
|
|
||||||
if !compiler_opt! == "clang" goto :clang_strap
|
if !compiler! == "clang" goto :clang_strap
|
||||||
if !compiler_opt! == "gcc" goto :gcc_strap
|
if !compiler! == "gcc" goto :gcc_strap
|
||||||
if !compiler_opt! == "msvc" goto :msvc_strap
|
if !compiler! == "msvc" goto :msvc_strap
|
||||||
if !compiler_opt! == "tcc" goto :tcc_strap
|
if !compiler! == "tcc" goto :tcc_strap
|
||||||
if !compiler_opt! == "fresh-tcc" goto :tcc_strap
|
if !compiler! == "fresh-tcc" goto :tcc_strap
|
||||||
if !compiler_opt! == "" goto :gcc_strap
|
if [!compiler!] == [""] goto :clang_strap
|
||||||
|
|
||||||
:clang_strap
|
:clang_strap
|
||||||
where /q clang
|
where /q clang
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
echo ^> Clang not found
|
echo ^> Clang not found
|
||||||
if not !compiler_opt! == "" goto :error
|
if not [!compiler!] == [""] goto :error
|
||||||
goto :gcc_strap
|
goto :gcc_strap
|
||||||
)
|
)
|
||||||
|
|
||||||
set /a valid_cc=1
|
set /a valid_cc=1
|
||||||
|
|
||||||
echo ^> Attempting to build v.c with Clang
|
echo ^> Attempting to build v.c with Clang
|
||||||
call :buildcmd "clang -std=c99 -municode -pedantic -w -o v.exe .\vc\v_win.c" " "
|
call :buildcmd "clang -std=c99 -municode -w -o v.exe .\vc\v_win.c" " "
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
REM In most cases, compile errors happen because the version of Clang installed is too old
|
REM In most cases, compile errors happen because the version of Clang installed is too old
|
||||||
clang --version>>!log_file! 2>>&1
|
call :buildcmd "clang --version" " "
|
||||||
goto :compile_error
|
goto :compile_error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -124,7 +147,7 @@ goto :success
|
||||||
where /q gcc
|
where /q gcc
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
echo ^> GCC not found
|
echo ^> GCC not found
|
||||||
if not !compiler_opt! == "" goto :error
|
if not [!compiler!] == [""] goto :error
|
||||||
goto :msvc_strap
|
goto :msvc_strap
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -133,8 +156,8 @@ set /a valid_cc=1
|
||||||
echo ^> Attempting to build v.c with GCC
|
echo ^> Attempting to build v.c with GCC
|
||||||
call :buildcmd "gcc -std=c99 -municode -w -o v.exe .\vc\v_win.c" " "
|
call :buildcmd "gcc -std=c99 -municode -w -o v.exe .\vc\v_win.c" " "
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
rem In most cases, compile errors happen because the version of GCC installed is too old
|
REM In most cases, compile errors happen because the version of GCC installed is too old
|
||||||
gcc --version>>!log_file! 2>>&1
|
call :buildcmd "gcc --version" " "
|
||||||
goto :compile_error
|
goto :compile_error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -154,7 +177,7 @@ if "%PROCESSOR_ARCHITECTURE%" == "x86" (
|
||||||
|
|
||||||
if not exist "%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" (
|
if not exist "%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" (
|
||||||
echo ^> MSVC not found
|
echo ^> MSVC not found
|
||||||
if not !compiler_opt! == "" goto :error
|
if not [!compiler!] == [""] goto :error
|
||||||
goto :tcc_strap
|
goto :tcc_strap
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -185,29 +208,29 @@ goto :success
|
||||||
:tcc_strap
|
:tcc_strap
|
||||||
where /q tcc
|
where /q tcc
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
if !compiler_opt! == "fresh-tcc" (
|
if !compiler! == "fresh-tcc" (
|
||||||
echo ^> Clean TCC directory
|
echo ^> Clean TCC directory
|
||||||
call :buildcmd "rd /s /q "%tcc_dir%">NUL 2>&1" " "
|
call :buildcmd "rmdir /s /q "%tcc_dir%"" " "
|
||||||
set /a valid_cc=1
|
set /a valid_cc=1
|
||||||
) else if !compiler_opt! == "tcc" ( set /a valid_cc=1 )
|
) else if !compiler! == "tcc" set /a valid_cc=1
|
||||||
if not exist "%tcc_dir%" (
|
if not exist %tcc_dir% (
|
||||||
echo ^> TCC not found
|
echo ^> TCC not found
|
||||||
echo ^> Downloading TCC from %tcc_url%
|
echo ^> Downloading TCC from %tcc_url%
|
||||||
call :buildcmd "git clone --depth 1 --quiet "%tcc_url%" "%tcc_dir%"" " "
|
call :buildcmd "git clone --depth 1 --quiet "!tcc_url!" "%tcc_dir%"" " "
|
||||||
)
|
)
|
||||||
pushd %tcc_dir% || (
|
pushd %tcc_dir% || (
|
||||||
echo ^> TCC not found, even after cloning
|
echo ^> TCC not found, even after cloning
|
||||||
goto :error
|
goto :error
|
||||||
)
|
)
|
||||||
popd
|
popd
|
||||||
set tcc_exe="%tcc_dir%\tcc.exe"
|
set "tcc_exe=%tcc_dir%\tcc.exe"
|
||||||
) else (
|
) else (
|
||||||
for /f "delims=" %%i in ('where tcc') do set "tcc_exe=%%i"
|
for /f "delims=" %%i in ('where tcc') do set "tcc_exe=%%i"
|
||||||
set /a valid_cc=1
|
set /a valid_cc=1
|
||||||
)
|
)
|
||||||
|
|
||||||
echo ^> Updating prebuilt TCC...
|
echo ^> Updating prebuilt TCC...
|
||||||
pushd "%tcc_dir%"\
|
pushd "%tcc_dir%\"
|
||||||
call :buildcmd "git pull -q" " "
|
call :buildcmd "git pull -q" " "
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
@ -220,6 +243,21 @@ call :buildcmd "v.exe -cc "!tcc_exe!" self" " "
|
||||||
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
if %ERRORLEVEL% NEQ 0 goto :compile_error
|
||||||
goto :success
|
goto :success
|
||||||
|
|
||||||
|
:cleanall
|
||||||
|
call :clean
|
||||||
|
echo ^> Purge TCC binaries
|
||||||
|
call :buildcmd "rmdir /s /q "%tcc_dir%"" " "
|
||||||
|
echo ^> Purge vc repository
|
||||||
|
call :buildcmd "rmdir /s /q "%vc_dir%"" " "
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:clean
|
||||||
|
echo ^> Purge debug symbols
|
||||||
|
call :buildcmd "del *.pdb *.lib *.bak *.out *.ilk *.exp *.obj *.o *.a *.so" " "
|
||||||
|
echo ^> Delete old V executable
|
||||||
|
call :buildcmd "del v_old.exe v*.exe" " "
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
:compile_error
|
:compile_error
|
||||||
echo.
|
echo.
|
||||||
type !log_file!>NUL 2>&1
|
type !log_file!>NUL 2>&1
|
||||||
|
@ -228,7 +266,6 @@ goto :error
|
||||||
:error
|
:error
|
||||||
echo.
|
echo.
|
||||||
echo Exiting from error
|
echo Exiting from error
|
||||||
popd
|
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
||||||
:success
|
:success
|
||||||
|
@ -243,15 +280,14 @@ if !valid_cc! EQU 0 (
|
||||||
echo.
|
echo.
|
||||||
)
|
)
|
||||||
|
|
||||||
del v_old.exe>>!log_file! 2>>&1
|
del v_old.exe>>!log_file! 2>NUL
|
||||||
del !log_file!
|
del !log_file! 2>NUL
|
||||||
|
|
||||||
:version
|
:version
|
||||||
echo.
|
echo.
|
||||||
echo | set /p="V version: "
|
echo | set /p="V version: "
|
||||||
.\v.exe version
|
.\v.exe version
|
||||||
popd
|
goto :eof
|
||||||
exit /b 0
|
|
||||||
|
|
||||||
:buildcmd
|
:buildcmd
|
||||||
if !verbose_log! EQU 1 (
|
if !verbose_log! EQU 1 (
|
||||||
|
@ -264,24 +300,70 @@ exit /b %ERRORLEVEL%
|
||||||
:usage
|
:usage
|
||||||
echo.
|
echo.
|
||||||
echo Usage:
|
echo Usage:
|
||||||
echo make.bat [compiler] [options]
|
echo make.bat [target] [compiler] [options]
|
||||||
|
echo.
|
||||||
|
echo Compiler:
|
||||||
|
echo -msvc ^| -gcc ^| -[fresh-]tcc ^| -clang Set C compiler
|
||||||
|
echo.
|
||||||
|
echo Target:
|
||||||
|
echo build[default] Compiles V using the given C compiler
|
||||||
|
echo clean Clean build artifacts and debugging symbols
|
||||||
|
echo clean-all Cleanup entire ALL build artifacts and vc repository
|
||||||
|
echo help Display usage help for the given target
|
||||||
|
echo.
|
||||||
|
echo Examples:
|
||||||
|
echo make.bat -msvc
|
||||||
|
echo make.bat -gcc --local --logpath output.log
|
||||||
|
echo make.bat build -fresh-tcc --local
|
||||||
|
echo make.bat help clean
|
||||||
|
echo.
|
||||||
|
echo Use "make help <target>" for more information about a target, for instance: "make help clean"
|
||||||
|
echo.
|
||||||
|
echo Note: Any undefined options will cause an error
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:help_help
|
||||||
|
echo Usage:
|
||||||
|
echo make.bat help [target]
|
||||||
|
echo.
|
||||||
|
echo Target:
|
||||||
|
echo build ^| clean ^| clean-all ^| help Query given target
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:help_clean
|
||||||
|
echo Usage:
|
||||||
|
echo make.bat clean
|
||||||
|
echo.
|
||||||
|
echo Options:
|
||||||
|
echo --logfile PATH Use the specified PATH as the log
|
||||||
|
echo -v ^| --verbose Output compilation commands to stdout
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:help_cleanall
|
||||||
|
echo Usage:
|
||||||
|
echo make.bat clean-all
|
||||||
|
echo.
|
||||||
|
echo Options:
|
||||||
|
echo --logfile PATH Use the specified PATH as the log
|
||||||
|
echo -v ^| --verbose Output compilation commands to stdout
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:help_build
|
||||||
|
echo Usage:
|
||||||
|
echo make.bat build [compiler] [options]
|
||||||
echo.
|
echo.
|
||||||
echo Compiler:
|
echo Compiler:
|
||||||
echo -msvc ^| -gcc ^| -[fresh-]tcc ^| -clang Set C compiler
|
echo -msvc ^| -gcc ^| -[fresh-]tcc ^| -clang Set C compiler
|
||||||
echo.
|
echo.
|
||||||
echo Options:
|
echo Options:
|
||||||
echo -local Use the local vc repository without
|
echo --local Use the local vc repository without
|
||||||
echo syncing with remote
|
echo syncing with remote
|
||||||
echo -logfile PATH Use the specified PATH as the log
|
echo --logfile PATH Use the specified PATH as the log
|
||||||
echo file
|
echo file
|
||||||
echo -v ^| --verbose Output compilation commands to stdout
|
echo -v ^| --verbose Output compilation commands to stdout
|
||||||
echo -h ^| --help Display this help message and exit
|
exit /b 0
|
||||||
echo.
|
|
||||||
echo Examples:
|
:eof
|
||||||
echo make.bat -msvc
|
popd
|
||||||
echo make.bat -gcc --local --logpath output.log
|
endlocal
|
||||||
echo make.bat -fresh-tcc --local
|
|
||||||
echo make.bat --help
|
|
||||||
echo.
|
|
||||||
echo Note: Any undefined options will be ignored
|
|
||||||
exit /b 0
|
exit /b 0
|
Loading…
Reference in New Issue