ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

all: build test

reset:
ifeq '$(OS)' 'Windows_NT'
	powershell -executionpolicy bypass .\scripts\reset_build.ps1
else
	sh -x ./scripts/reset_build.sh
endif

build:
	meson compile -j 10 -C $(ROOT_DIR)/builddir

release_build:
	meson --wipe builddir -Db_ndebug=true --buildtype release
	meson compile -j 10 -C builddir

debug_build:
	meson setup --wipe builddir -Db_ndebug=true --buildtype debugoptimized
	meson compile -j 10 -C builddir

test: build
	./builddir/runtests -d yes

run: build test
ifeq '$(OS)' 'Windows_NT'
	powershell "cp ./builddir/sfmldemo.exe ."
	./sfmldemo
else
	./builddir/sfmldemo
endif

debug: build
	gdb --nx -x .gdbinit --ex run --args builddir/sfmldemo

debug_run: build
	gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/sfmldemo

clean:
	meson compile --clean -C builddir

debug_test: build
	gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests -e
