126 lines
5.8 KiB
Batchfile
126 lines
5.8 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
cd /D "%~dp0"
|
|
|
|
:: --- Usage Notes -------------------------------------------------------------
|
|
::
|
|
:: Central build script for Juliet modular architecture.
|
|
:: Takes alphanumeric arguments to control target, compiler, and build configuration.
|
|
::
|
|
:: Examples:
|
|
:: new_build
|
|
:: new_build julietapp
|
|
:: new_build julietapp clang
|
|
:: new_build julietapp release
|
|
:: new_build julietapp msvc debug asan
|
|
:: new_build clean
|
|
::
|
|
|
|
:: --- Unpack Arguments -------------------------------------------------------
|
|
for %%a in (%*) do set "%%~a=1"
|
|
|
|
if "%clean%"=="1" (
|
|
if exist build (
|
|
echo [clean] Removing build directory...
|
|
rmdir /s /q build
|
|
)
|
|
exit /b 0
|
|
)
|
|
|
|
:: --- Compiler Selection & Auto-Detection -------------------------------------
|
|
if not "%msvc%"=="1" if not "%clang%"=="1" set clang=1
|
|
|
|
if "%msvc%"=="1" (
|
|
where cl.exe >nul 2>nul
|
|
if errorlevel 1 (
|
|
if exist "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" (
|
|
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 >nul 2>&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 "%clang%"=="1" set msvc=0 && echo [clang compile]
|
|
if "%msvc%"=="1" set clang=0 && echo [msvc compile]
|
|
|
|
:: Default target: julietapp
|
|
if "%~1"=="" echo [default mode, assuming `julietapp` build] && set julietapp=1
|
|
if "%~1"=="release" if "%~2"=="" echo [default mode, assuming `julietapp` build] && set julietapp=1
|
|
if "%~1"=="debug" if "%~2"=="" echo [default mode, assuming `julietapp` build] && set julietapp=1
|
|
if "%~1"=="clang" if "%~2"=="" echo [default mode, assuming `julietapp` build] && set julietapp=1
|
|
if "%~1"=="msvc" if "%~2"=="" echo [default mode, assuming `julietapp` build] && set julietapp=1
|
|
|
|
:: --- Unpack Command Line Build Arguments ------------------------------------
|
|
set auto_compile_flags=
|
|
if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=address && echo [asan enabled]
|
|
if "%ubsan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=undefined && echo [ubsan enabled]
|
|
|
|
:: --- Natvis Options ---------------------------------------------------------
|
|
set natvis_flags=
|
|
if exist "%~dp0Natvis\Juliet.natvis" (
|
|
if "%msvc%"=="1" set natvis_flags=%natvis_flags% /NATVIS:"%~dp0Natvis\Juliet.natvis"
|
|
if "%clang%"=="1" set natvis_flags=%natvis_flags% -Xlinker /NATVIS:"%~dp0Natvis\Juliet.natvis"
|
|
)
|
|
if exist "%~dp0Natvis\String.natvis" (
|
|
if "%msvc%"=="1" set natvis_flags=%natvis_flags% /NATVIS:"%~dp0Natvis\String.natvis"
|
|
if "%clang%"=="1" set natvis_flags=%natvis_flags% -Xlinker /NATVIS:"%~dp0Natvis\String.natvis"
|
|
)
|
|
|
|
:: --- Compile/Link Line Definitions ------------------------------------------
|
|
set cl_common= /I..\Juliet\ /nologo /FC /Z7 /Zc:preprocessor /utf-8
|
|
set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% %auto_compile_flags%
|
|
set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common% %auto_compile_flags%
|
|
set cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /pdbaltpath:%%%%_PDB%%%% /DEBUG %natvis_flags% /opt:ref /opt:icf
|
|
set cl_out= /out:
|
|
set cl_obj_out= /Fo:
|
|
set cl_linker=
|
|
|
|
set clang_common= -mcx16 -I..\Juliet\ -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -Wno-writable-strings -Wno-missing-field-initializers -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 -ferror-limit=10000
|
|
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 /pdbaltpath:%%%%_PDB%%%% -Xlinker /DEBUG %natvis_flags% -Xlinker /opt:ref -Xlinker /opt:noicf
|
|
set clang_out= -o
|
|
set clang_obj_out= -o
|
|
set clang_linker= -Xlinker
|
|
|
|
:: --- Per-Build Settings -----------------------------------------------------
|
|
if "%msvc%"=="1" set linker=%cl_linker%
|
|
if "%clang%"=="1" set linker=%clang_linker%
|
|
if "%msvc%"=="1" set only_compile=/c
|
|
if "%clang%"=="1" set only_compile=-c
|
|
if "%msvc%"=="1" set link_dll=/link /DLL
|
|
if "%clang%"=="1" set link_dll=-Xlinker -DLL
|
|
|
|
:: --- 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%
|
|
if "%msvc%"=="1" set obj_out=%cl_obj_out%
|
|
if "%clang%"=="1" set compile_debug=%clang_debug%
|
|
if "%clang%"=="1" set compile_release=%clang_release%
|
|
if "%clang%"=="1" set compile_link=%clang_link%
|
|
if "%clang%"=="1" set out=%clang_out%
|
|
if "%clang%"=="1" set obj_out=%clang_obj_out%
|
|
if "%debug%"=="1" set compile=%compile_debug%
|
|
if "%release%"=="1" set compile=%compile_release%
|
|
|
|
:: --- Prep Directories -------------------------------------------------------
|
|
if not exist build mkdir build
|
|
|
|
:: --- Build Targets (@build_targets) -----------------------------------------
|
|
pushd build
|
|
if "%julietapp%"=="1" set didbuild=1 && %compile% ..\Juliet\julietapp\julietapp_main.c %compile_link% %out%julietapp.exe || exit /b 1
|
|
popd
|
|
|
|
:: --- Warn On No Builds ------------------------------------------------------
|
|
if "%didbuild%"=="" (
|
|
echo [WARNING] no valid build target specified; must use build target names like `new_build julietapp`.
|
|
exit /b 1
|
|
)
|
|
|
|
echo [build success]
|
|
exit /b 0
|