RELEASE_flags=-DNDEBUG -O2 -g0 -s
DEBUG_flags=-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined

.PHONY: all debug dest run debug test install uninstall format clean archive

all: dest

dest:
	@ mkdir -p bin
run: all bin/modal
	@ bin/modal examples/hello.modal 2> /dev/null
debug: bin/modal-debug
	@ bin/modal-debug examples/hello.modal
test: bin/modal-debug bin/modal
	@ bin/modal -v
	@ bin/modal-debug examples/tests.modal
install: bin/modal
	cp bin/modal ~/bin/
uninstall:
	rm -f ~/bin/modal
format:
	@ clang-format -i src/modal.c
clean:
	rm -fr bin
archive: all
	cp src/modal.c ../oscean/etc/modal.c.txt

bin/modal-debug: src/modal.c
	@ cc ${DEBUG_flags} src/modal.c -o bin/modal-debug
bin/modal: src/modal.c
	@ cc ${RELEASE_flags} src/modal.c -o bin/modal