appname := ZeldaNSQ

CXX := g++

BUILD ?= release

ifeq ($(BUILD),debug)
    CXXFLAGS := -g -O0 -Wall -Wextra -I/usr/include/SDL2 -D_REENTRANT
else
    CXXFLAGS := -O3 -DNDEBUG -I/usr/include/SDL2 -D_REENTRANT
endif

LDFLAGS :=
LDLIBS := -lSDL2 -lSDL2main -lSDL2_image -lSDL2_mixer

srcfiles := $(shell find . -name "*.cpp")
objects := $(srcfiles:.cpp=.o)
depends := $(objects:.o=.d)

all: $(appname)

$(appname): $(objects)
	@echo "Linking $(appname)..."
	@$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

%.o: %.cpp
	@echo "Compiling $<"
	@$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@

clean:
	@rm -f $(objects) $(depends)

dist-clean: clean
	@rm -f $(appname)

run: $(appname)
	@./$(appname)

-include $(depends)
