CC      ?= gcc
CFLAGS  ?= -std=c99 -O2 -Wall -Wextra -Wpedantic -D_POSIX_C_SOURCE=200809L
LDLIBS_CURSES = -lncursesw
LDLIBS_WEB    = -lpthread

CORE = src/rng.c src/balance.c src/dungeon.c src/fov.c src/engine.c \
       src/screen.c src/render.c src/save.c src/auth.c src/sha256.c \
       src/sha1.c src/b64.c
BOT  = src/bot.c
HDRS = $(wildcard src/*.h) src/content.def

all: bin/urthfall bin/urthfall-web bin/urthfall-sim bin/urthfall-test

bin:
	mkdir -p bin

bin/urthfall: src/term_main.c src/wsproto.c src/b64.c $(HDRS) | bin
	$(CC) $(CFLAGS) -o $@ $(filter %.c,$^) $(LDLIBS_CURSES)

bin/urthfall-web: $(CORE) src/web_main.c src/wsproto.c $(HDRS) | bin
	$(CC) $(CFLAGS) -o $@ $(filter %.c,$^) $(LDLIBS_WEB)

bin/urthfall-sim: $(CORE) $(BOT) src/sim_main.c $(HDRS) | bin
	$(CC) $(CFLAGS) -o $@ $(filter %.c,$^)

bin/urthfall-test: $(CORE) $(BOT) tests/test_main.c $(HDRS) | bin
	$(CC) $(CFLAGS) -Isrc -o $@ $(filter %.c,$^)

test: bin/urthfall-test
	./bin/urthfall-test

sim: bin/urthfall-sim
	./bin/urthfall-sim --games 30 --seed 500

clean:
	rm -rf bin

.PHONY: all test sim clean
