#! /bin/bash

CACHE=/tmp/fggl/
LOG=$CACHE/demo.log

BUILD_PATH="builds/cli"
DEMO_EXE="$PWD/$BUILD_PATH/demo/FgglDemo"

# check cmake exists
if [ ! -x "$(command -v cmake)" ]; then
	sudo dnf install -y cmake extra-cmake-modules
	sudo dnf install -y wayland-devel libxkbcommon-devel wayland-protocols-devel
	sudo dnf install -y glew-devel glm-devel
fi

# if doing shader development, disable the cache to make sure changes take affect
rm -rf builds/cli
rm -rf $CACHE

#
# build step
#
cmake -S . -B $BUILD_PATH -DCMAKE_BUILD_TYPE=debug
cmake --build $BUILD_PATH

#
# additional stuff
#

#EXE="gdb $EXE"

# gamemoderun
if [ -x "$(command -v gamemoderun)" ]; then
    DEMO_EXE="gamemoderun $DEMO_EXE"
fi

# mangohud
if [ -x "$(command -v mangohud)" ]; then
    DEMO_EXE="mangohud --dlsym $DEMO_EXE"
fi

pushd demo
$DEMO_EXE
popd
