CXX ?= c++
CC ?= cc
BUILD ?= build/host
PLATFORM ?= $(if $(wildcard ../../platform/fdoom.h),../../platform,../../../lvgl-screen-flappy-bird-demo/doom/src)
OPT ?= -O2
CPPFLAGS += -I$(PLATFORM)
CFLAGS += $(OPT) -std=gnu99 -Wall -Wextra -MMD -MP
CXXFLAGS += $(OPT) -std=c++17 -Wall -Wextra -Werror -MMD -MP
RUNTIME_LIBS ?=
OBJECTS = $(addprefix $(BUILD)/,main.o platform.o game.o render.o fdoom_fb.o fdoom_touch.o fdoom_sandbox.o)
-include $(OBJECTS:.o=.d)
.DEFAULT_GOAL := all
all: $(BUILD)/fusion-flappy
$(BUILD):
	mkdir -p "$@"
$(BUILD)/%.o: %.cpp | $(BUILD)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c "$<" -o "$@"
$(BUILD)/%.o: $(PLATFORM)/%.c | $(BUILD)
	$(CC) $(CPPFLAGS) $(CFLAGS) -c "$<" -o "$@"
$(BUILD)/render.o: render.hpp build/assets.hpp
$(BUILD)/main.o: game.hpp platform.hpp render.hpp
$(BUILD)/platform.o: platform.hpp
$(BUILD)/game.o: game.hpp
$(BUILD)/fusion-flappy: $(OBJECTS)
	$(CXX) $(OPT) $(OBJECTS) $(RUNTIME_LIBS) -lm -o "$@"
test: | $(BUILD)
	$(CXX) -std=c++17 -Wall -Wextra -Werror -O2 game.cpp game_test.cpp -o $(BUILD)/game_test
	$(BUILD)/game_test
controls-test: $(BUILD)/platform.o $(BUILD)/fdoom_fb.o $(BUILD)/fdoom_touch.o $(BUILD)/fdoom_sandbox.o
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) controls_test.cpp $^ $(RUNTIME_LIBS) -lm -o $(BUILD)/controls_test
	$(BUILD)/controls_test
replay-test: | $(BUILD)
	$(CXX) -std=c++17 -Wall -Wextra -Werror -O2 game.cpp replay-test.cpp -o $(BUILD)/replay-test
.PHONY: all test controls-test replay-test
