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

all: build

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

%.cpp : %.rl
	ragel -I $(ROOT_DIR) -G1 -o $@ $<

%.dot: %.rl
	ragel -Vp -I $(ROOT_DIR) -o $@ $<

%.png: %.dot
	dot -Tpng $< -o $@

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

asset_build:
	./builddir/icongen

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

tracy_build:
	meson setup --wipe builddir --buildtype debugoptimized -Dtracy_enable=true -Dtracy:on_demand=true
	meson compile -j 10 -C builddir

test: build
	./builddir/runtests -d yes

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

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

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

debug_walk: build test
	gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/zedcaster t

clean:
	meson compile --clean -C builddir

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

win_installer:
	powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'

coverage_report:
	powershell 'scripts/coverage_report.ps1'

money:
	scc --exclude-dir subprojects --exclude-dir .git --exclude-dir wraps --exclude-dir scripts

arena:
	gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/arena

story:
	gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/storyboard

debug_animator:
	gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/animator -s "rat_king_boss" -a "rat_king_boss" -b "test_background"

animator:
	./builddir/animator.exe -s "rat_king_boss" -a "rat_king_boss" -b "test_background"
