include Makeconf

test-srcs := $(wildcard tests/*.cpp)

emu-objs := $(addsuffix .o,$(modules))
test-objs := $(patsubst %.cpp,%.o,$(test-srcs))
clean-objs := $(emu-objs) $(test-objs) libemu.a vgbc vgbc.test

headers := $(wildcard */*.h)

.PHONY: all test clean

all: vgbc

clean:
	rm -rf $(clean-objs)

test: vgbc.test
	@./$<

%.o: %.cpp $(headers)
	g++ $(CXX_FLAGS) -c -o $@ $<

libemu.a: $(emu-objs)
	ar -rc $@ $^

vgbc: main.c libemu.a
	g++ $(CXX_FLAGS) -o $@ $^

vgbc.test: $(test-objs) libemu.a
	g++ $(CXX_FLAGS) -o $@ $^