2024-07-25 12:25:05 -05:00
|
|
|
@echo off
|
|
|
|
setlocal
|
|
|
|
cd /D "%~dp0"
|
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
:: -- 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`
|
|
|
|
::
|
|
|
|
|
|
|
|
:: Unpack Arguments
|
|
|
|
for %%a in (%*) do in set "%%a=1"
|
2024-07-25 12:25:05 -05:00
|
|
|
if not "%msvc%"=="1" if not "%clang%"=="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]
|
2024-07-27 00:36:41 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
:: Third Party libraries
|
|
|
|
set third_party_includes="%~dp0\src\\third_party\\SDL2\\include"
|
|
|
|
set third_party_lib="%~dp0\src\\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
|
|
|
|
set clang_common= -I..\src\ -I..\local\ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf
|
|
|
|
set clang_debug= call clang -g -O0 -DBUILD_DEBUG=1 %clang_common% %auto_compile_flags%
|
|
|
|
set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 %clang_common% %auto_compile_flags%
|
|
|
|
set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker logo.res
|
|
|
|
set clang_out= -o
|
|
|
|
|
|
|
|
:: Per-Build Setting
|
|
|
|
|
|
|
|
:: --- Per-Build Settings -----------------------------------------------------
|
|
|
|
set link_dll=-DLL
|
|
|
|
|
|
|
|
:: MSVC
|
2024-07-25 12:25:05 -05:00
|
|
|
if "%msvc%"=="1" set only_compile=/c
|
|
|
|
if "%msvc%"=="1" set EHsc=/EHsc
|
2024-07-27 00:36:41 -05:00
|
|
|
if "%msvc%"=="1" set no_aslr=/DYNAMICBASE:NO
|
|
|
|
if "%msvc%"=="1" set rc=call rc
|
2024-07-25 12:25:05 -05:00
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
:: Clang
|
2024-07-25 12:25:05 -05:00
|
|
|
if "%clang%"=="1" set only_compile=-c
|
2024-07-27 00:36:41 -05:00
|
|
|
if "%clang%"=="1" set EHsc=
|
|
|
|
if "%clang%"=="1" set no_aslr=-Wl,/DYNAMICBASE:NO
|
|
|
|
if "%clang%"=="1" set rc=call llvm-rc
|
2024-07-25 12:25:05 -05:00
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
:: --- 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%
|
2024-07-25 12:25:05 -05:00
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
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%
|
2024-07-25 12:25:05 -05:00
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
if "%debug%"=="1" set compile=%compile_debug%
|
|
|
|
if "%release%"=="1" set compile=%compile_release%
|
|
|
|
|
|
|
|
:: Prep Directory
|
2024-07-25 12:25:05 -05:00
|
|
|
if not exist run_tree (
|
|
|
|
mkdir run_tree
|
|
|
|
echo "[WARNING] creating run_tree, data files may not exist."
|
|
|
|
)
|
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
:: Process rc Files
|
2024-07-25 12:25:05 -05:00
|
|
|
pushd run_tree
|
|
|
|
%rc% /nologo /fo resource.res data\resource.rc || exit /b 1
|
|
|
|
popd
|
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
:: 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
|
2024-07-25 12:25:05 -05:00
|
|
|
pushd run_tree
|
2024-07-27 00:36:41 -05:00
|
|
|
if "%ragar%"=="1" %compile% ..\src\ragar\ragar_main.c %compile_link% %out%ragar.exe /SUBSYSTEM:WINDOWS || exit /b 1
|
2024-07-25 12:25:05 -05:00
|
|
|
popd
|
|
|
|
|
2024-07-27 00:36:41 -05:00
|
|
|
:: Unset
|
2024-07-25 12:25:05 -05:00
|
|
|
for %%a in (%*) do set "%%a=0"
|
2024-07-27 00:36:41 -05:00
|
|
|
set ragar=
|
2024-07-25 12:25:05 -05:00
|
|
|
set compile=
|
|
|
|
set compile_link=
|
|
|
|
set out=
|
|
|
|
set msvc=
|
|
|
|
set debug=
|
2024-07-27 00:36:41 -05:00
|
|
|
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 )
|
2024-07-25 12:25:05 -05:00
|
|
|
|