CC      := cc
CFLAGS  := -std=c99 -Wall -Wpedantic -Werror=implicit -Wmissing-prototypes -O2 -g -Isrc
LDFLAGS :=

GEN_SRC := $(wildcard src/gen/*.c)
GEN_OBJ := $(GEN_SRC:src/%.c=obj/%.o)

.PHONY: all clean genesis test stress godot godot-clean
all: genesis

test: bin/genesis
	@bash test/run_tests.sh

stress: bin/genesis
	@./bin/genesis --stress 5000

godot:
	@cd godot && scons -j$$(nproc) platform=linux target=template_debug

godot-clean:
	@rm -rf godot/build godot/godot-cpp/bin demo/addons/brogue_gen

genesis: bin/genesis

bin/genesis: $(GEN_OBJ) obj/genesis_main.o obj/json_emit.o
	@mkdir -p bin
	$(CC) $(LDFLAGS) -o $@ $^ -lm

obj/%.o: src/%.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -c $< -o $@

obj/genesis_main.o: src/genesis_main.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -c $< -o $@

obj/json_emit.o: src/json_emit.c src/json_emit.h
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -rf obj bin
