build_macos.sh

C++ software renderer

build_macos.sh

1.01 KB
#!/bin/bash
set -e

ROOT="$(dirname "$(realpath "$0")")"
SRC_FILES="src/*.cpp"

# =====================
# ==== Parse flags ====
# =====================
for arg in "$@"; do
    if [[ "$arg" == "-r" ]]; then
        BUILD="Release"
    fi
done


# ===================
# === Directories ===
# ===================
[ ! -d "build" ] && mkdir build
#[ ! -d "external" ] && mkdir external


# ====================
# === Dependencies ===
# ====================
# brew sdl2
SDL_CFLAGS=$(sdl2-config --cflags)
SDL_LDFLAGS=$(sdl2-config --libs)


# =========================
# === Compilation Flags ===
# =========================
if [ "$BUILD" == "Release" ]; then
    CFLAGS="-std=c++20 -O2 -o renderer"
    LFLAGS=""
else
    CFLAGS="-std=c++20 -g -O0 -o renderer"
    LFLAGS=""
fi


# ===================
# === Compilation ===
# ===================
#clang++ $CFLAGS $SDL_CFLAGS "$SRC_FILES" -o "$" $SDL_LDFLAGS

pushd build > /dev/null
clang++ \
  $CFLAGS \
  $SDL_CFLAGS \
  $ROOT/$SRC_FILES \
  $LFLAGS \
  $SDL_LDFLAGS
popd > /dev/null