diff --git a/.gitignore b/.gitignore index b7a2d4f..8b80bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /libemu.a /vgbc.test /vgbc.inspect +*.d diff --git a/Makeconf b/Makeconf index ac8fd84..48f99c4 100644 --- a/Makeconf +++ b/Makeconf @@ -1,12 +1,25 @@ -modules := memory/device \ - memory/bus \ - memory/ram \ - memory/bootrom_overlay \ - memory/register \ - memory/bank \ - memory/mbc/mbc1 \ - cpu/cpu \ - cpu/decoder \ - cartridge/cartridge +TARGETS := libemu.a vgbc vgbc.test vgbc.inspect + +cmd_libemu.a = ar -rc $@ $^ +verb_libemu.a = pack +modules_libemu.a := memory/device.o \ + memory/bus.o \ + memory/ram.o \ + memory/bootrom_overlay.o \ + memory/register.o \ + memory/bank.o \ + memory/mbc/mbc1.o \ + cpu/cpu.o \ + cpu/decoder.o \ + cartridge/cartridge.o + +modules_vgbc := main.o libemu.a +verb_vgbc := link + +modules_vgbc.test := $(patsubst %.cpp,%.o,$(wildcard tests/*.cpp)) libemu.a +verb_vgbc.test := link + +modules_vgbc.inspect := cartridge/inspector.o libemu.a +verb_vgbc.inspect := link CXX_FLAGS := -I $(CURDIR) diff --git a/Makefile b/Makefile index 73d0448..d5860fd 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,38 @@ include Makeconf -test-srcs := $(wildcard tests/*.cpp) +# Auto tracking of headers +CXX_FLAGS += -MMD +depfiles := $(wildcard *.d **/*.d) -emu-objs := $(addsuffix .o,$(modules)) -test-objs := $(patsubst %.cpp,%.o,$(test-srcs)) -clean-objs := $(emu-objs) $(test-objs) libemu.a vgbc vgbc.test vgbc.inspect main.o +clean-objs := $(foreach t,$(TARGETS),$(modules_$(t))) $(depfiles) +cmd = $(VERBOSE)g++ $(CXX_FLAGS) -o $@ $^ +msg = $(or $(verb_$@),finalize) $@ -headers := $(wildcard */*.h) +ifneq ($V,1) +VERBOSE := @ +endif .PHONY: all test clean -all: vgbc +all: $(or $(DEFAULT_TARGETS),$(TARGETS)) + +-include $(depfiles) clean: rm -rf $(clean-objs) test: vgbc.test - @echo " ... run test $<"; \ - ./$< $(if $(V),-s,) + @echo " ... run test $<" + $(VERBOSE)./$< $(if $(V),-s) -%.o: %.cpp $(headers) - @echo " ... build $@"; \ - g++ $(CXX_FLAGS) -c -o $@ $< +%.o: %.cpp + @echo " ... build $@" + $(VERBOSE)g++ $(CXX_FLAGS) -c -o $@ $< -libemu.a: $(emu-objs) - @echo " ... pack $@"; \ - ar -rc $@ $^ +define target_rule +$(1): $$(modules_$(1)) + @echo " ..." $$(or $$(msg_$(1)),$$(msg)) + $$(VERBOSE)$$(or $$(cmd_$(1)),$$(cmd)) +endef -vgbc: main.o libemu.a - @echo " ==> link $@"; \ - g++ $(CXX_FLAGS) -o $@ $^ - -vgbc.test: $(test-objs) libemu.a - @echo " ==> link $@"; \ - g++ $(CXX_FLAGS) -o $@ $^ - -vgbc.inspect: cartridge/inspector.o libemu.a - @echo " ==> link $@"; \ - g++ $(CXX_FLAGS) -o $@ $^ +$(foreach t,$(TARGETS),$(eval $(call target_rule,$(t))))