125 lines
3.8 KiB
Batchfile
125 lines
3.8 KiB
Batchfile
@echo off
|
|
setlocal
|
|
cd /D "%~dp0"
|
|
|
|
:: -- Useage Notes (July 25th, 2024) ----------------------------------------------------------
|
|
::
|
|
:: This is a central build script for use in a windows development environment with support
|
|
:: for msvc(default) and clang, specifically for C/C++ projects. It takes simple alphanumeric
|
|
:: arguments which controls (1) what compiler & linker is used, (2) what mode the the
|
|
:: application is built in.
|
|
::
|
|
:: By default if no options are passed, everything is built in debug mode with the MSVC
|
|
:: compiler
|
|
::
|
|
:: Possible ways to use:
|
|
::
|
|
:: `build debug`
|
|
:: `build debug msvc`
|
|
:: `build release clang`
|
|
:: `build debug tracy`
|
|
::
|
|
|
|
:: Unpack Arguments
|
|
for %%a in (%*) do set "%%a=1"
|
|
|
|
if not "%msvc%"=="1" set msvc=1
|
|
if not "%release%"=="1" set debug=1
|
|
|
|
if "%debug%"=="1" set release=0 && echo [debug mode]
|
|
if "%release%"=="1" set debug=0 && echo [release mode]
|
|
|
|
if "%msvc%"=="1" set clang=0 && echo [msvc compile]
|
|
if "%clang%"=="1" set msvc=0 && echo [clang compile]
|
|
|
|
:: Fix
|
|
if "%~1"=="" echo [default mode] && set ragar=1
|
|
if "%~1"=="release" if "%~2"=="" echo [default release mode] && set ragar=1
|
|
|
|
:: Unpack Command Line Build arguments
|
|
set auto_compile_flags=
|
|
if "%tracy%"=="1" set auto_compile_flags=%auto_compile_flags% /DTRACY_ENABLE && echo [tracy profiling enabled]
|
|
|
|
:: Third Party libraries
|
|
set third_party_includes="%~dp0\third_party\\SDL2\\include"
|
|
set third_party_lib="%~dp0\third_party\\SDL2\\lib\\x64"
|
|
|
|
:: MSVC
|
|
set cl_common= /I..\src\ /nologo /FC /Z7 /I%third_party_includes%
|
|
set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common%
|
|
set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common%
|
|
set cl_link= /link /INCREMENTAL:NO resource.res /LIBPATH:%third_party_lib% SDL2.lib SDL2main.lib shell32.lib
|
|
set cl_out= /out:
|
|
|
|
:: Clang NOTE(tijani): Coming soon
|
|
|
|
:: Per-Build Setting
|
|
|
|
:: --- Per-Build Settings -----------------------------------------------------
|
|
set link_dll=-DLL
|
|
|
|
:: MSVC
|
|
if "%msvc%"=="1" set only_compile=/c
|
|
if "%msvc%"=="1" set EHsc=/EHsc
|
|
if "%msvc%"=="1" set no_aslr=/DYNAMICBASE:NO
|
|
if "%msvc%"=="1" set rc=call rc
|
|
|
|
:: Clang
|
|
if "%clang%"=="1" set only_compile=-c
|
|
if "%clang%"=="1" set EHsc=
|
|
if "%clang%"=="1" set no_aslr=-Wl,/DYNAMICBASE:NO
|
|
if "%clang%"=="1" set rc=call llvm-rc
|
|
|
|
:: --- Choose Compile/Link Lines ----------------------------------------------
|
|
if "%msvc%"=="1" set compile_debug=%cl_debug%
|
|
if "%msvc%"=="1" set compile_release=%cl_release%
|
|
if "%msvc%"=="1" set compile_link=%cl_link%
|
|
if "%msvc%"=="1" set out=%cl_out%
|
|
|
|
rem if "%clang%"=="1" set compile_debug=%clang_debug%
|
|
rem if "%clang%"=="1" set compile_release=%clang_release%
|
|
rem if "%clang%"=="1" set compile_link=%clang_link%
|
|
rem if "%clang%"=="1" set out=%clang_out%
|
|
|
|
if "%debug%"=="1" set compile=%compile_debug%
|
|
if "%release%"=="1" set compile=%compile_release%
|
|
|
|
:: Prep Directory
|
|
if not exist run_tree (
|
|
mkdir run_tree
|
|
echo "[WARNING] creating run_tree, data files may not exist."
|
|
)
|
|
|
|
:: Process rc Files
|
|
pushd run_tree
|
|
%rc% /nologo /fo resource.res data\resource.rc || exit /b 1
|
|
popd
|
|
|
|
:: Get Current SVN/Git Commit ID
|
|
:: SVN
|
|
:: for /f "tokens=2 delims==" %%i in ('svn info --show-item revision') do set compile=%compile% -DBUILD_SVN_REVISION=\"%%i\"
|
|
:: Git
|
|
:: for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\"
|
|
|
|
:: Build
|
|
pushd run_tree
|
|
if "%ragar%"=="1" %compile% ..\src\ragar\ragar_main.c %compile_link% %out%ragar.exe /SUBSYSTEM:WINDOWS || exit /b 1
|
|
popd
|
|
|
|
:: Unset
|
|
for %%a in (%*) do set "%%a=0"
|
|
set ragar=
|
|
set compile=
|
|
set compile_link=
|
|
set out=
|
|
set msvc=
|
|
set debug=
|
|
set release=
|
|
|
|
rem :: Warning
|
|
rem if "%didbuild%"=="" (
|
|
rem echo [WARNING] no valid build target specified; must use build target names as arguments to this script, like `build debug` or `build release`.
|
|
rem exit /b 1
|
|
rem )
|
|
|