Renderer/build.sh
2026-02-15 17:53:50 +11:00

73 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -eu
for arg in "$@"; do declare $arg="1"; done
if [ ! -v release ]; then debug=1; fi
if [ ! -v clang ]; then gcc=1; fi
if [ -v release ]; then
build_mode="-02"
mode_flags="-DBUILD_RELEASE"
echo "[Release Mode]"
fi
if [ -v debug ];
build_mode="-g -O0"
mode_flags="-DBUILD_DEBUG"
then echo "[Debug Mode]"
fi
script_dir="$(dirname -- "${BASH_SOURCE[0]}" )"
cd $script_dir
mkdir -p build
mkdir -p include
# SDL
if ! [ -f "build/libSDL3.a" ]; then
cmake -S SDL -B SDL/build -DSDL_STATIC=ON -DSDL_SHARED=OFF
cd SDL/build
make
cd ../..
cp SDL/build/libSDL3.a build
cp -r SDL/include/SDL3 include
fi
if [ -v gcc ]; then
if ! [ -x "$(command -v g++)" ]; then
echo "Unable to find gcc compiler, try again with the clang flag or install gcc."
exit 1
fi
compiler_flags="-fzero-init-padding-bits=unions"
compiler="g++"
elif [ -v clang ]; then
if ! [ -x "$(command -v clang++)" ]; then
echo "Unable to find clang compiler, try again with the gcc flag or install clang"
exit 1
fi
compiler_flags=""
compiler="clang++"
fi
if [ -x "$(command -v mold)" ]; then
linker="mold";
elif [ -x "$(command -v lld)" ]; then
linker="lld";
elif [ -x "$(command -v ld)" ]; then
linker="ld"
else
echo "Unable to find a linker, please install mold, lld or ld"
exit 1
fi
src="main.cpp"
out="build/Renderer"
flags="-std=c++23 -D_USE_MATH_DEFINES ${build_mode} ${compiler_flags} ${mode_flags} -Iexternal/include -fuse-ld=${linker} -Wno-pointer-arith -o${out}"
linker_flags="-lGL -lpthread -Lbuild -l:libSDL3.a"
$compiler $src $linker_flags $flags