Renderer/build.sh

82 lines
1.9 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
imgui_src="external/include/imgui/imgui_main.cpp"
imgui_out="-obuild/imgui.o"
imgui_flags="-std=c++23 -D_USE_MATH_DEFINES -g -c -fmax-errors=5 ${compiler_flags} -Iexternal/include/imgui"
imgui_linker_flags="-lGL -lpthread -Lbuild -l:libSDL3.a"
if ! [ -f "build/imgui.o" ]; then
$compiler $imgui_src $imgui_linker_flags $imgui_flags $imgui_out
fi
src="main.cpp build/imgui.o"
out="build/Renderer"
flags="-std=c++23 -D_USE_MATH_DEFINES ${build_mode} ${compiler_flags} ${mode_flags} -Iexternal/include -Iexternal/include/imgui -fuse-ld=${linker} -Wno-pointer-arith -o${out}"
linker_flags="-lGL -lpthread -Lbuild -l:libSDL3.a"
$compiler $src $linker_flags $flags