#!/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="-g" echo "[Release Mode]" fi if [ -v debug ]; build_mode="-O2" 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" linker_flags="-lGL -Lbuild -l:libSDL3.a" flags="-std=c++23 ${build_mode} ${compiler_flags} -Iinclude -fuse-ld=${linker} -o${out}" $compiler $src $linker_flags $flags