Makefile - Rework build system a bit

This commit is contained in:
madmaurice 2023-09-01 09:18:32 +02:00
parent fb65792e87
commit 8703edbec8
3 changed files with 47 additions and 35 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
/libemu.a /libemu.a
/vgbc.test /vgbc.test
/vgbc.inspect /vgbc.inspect
*.d

View file

@ -1,12 +1,25 @@
modules := memory/device \ TARGETS := libemu.a vgbc vgbc.test vgbc.inspect
memory/bus \
memory/ram \ cmd_libemu.a = ar -rc $@ $^
memory/bootrom_overlay \ verb_libemu.a = pack
memory/register \ modules_libemu.a := memory/device.o \
memory/bank \ memory/bus.o \
memory/mbc/mbc1 \ memory/ram.o \
cpu/cpu \ memory/bootrom_overlay.o \
cpu/decoder \ memory/register.o \
cartridge/cartridge 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) CXX_FLAGS := -I $(CURDIR)

View file

@ -1,40 +1,38 @@
include Makeconf include Makeconf
test-srcs := $(wildcard tests/*.cpp) # Auto tracking of headers
CXX_FLAGS += -MMD
depfiles := $(wildcard *.d **/*.d)
emu-objs := $(addsuffix .o,$(modules)) clean-objs := $(foreach t,$(TARGETS),$(modules_$(t))) $(depfiles)
test-objs := $(patsubst %.cpp,%.o,$(test-srcs)) cmd = $(VERBOSE)g++ $(CXX_FLAGS) -o $@ $^
clean-objs := $(emu-objs) $(test-objs) libemu.a vgbc vgbc.test vgbc.inspect main.o msg = $(or $(verb_$@),finalize) $@
headers := $(wildcard */*.h) ifneq ($V,1)
VERBOSE := @
endif
.PHONY: all test clean .PHONY: all test clean
all: vgbc all: $(or $(DEFAULT_TARGETS),$(TARGETS))
-include $(depfiles)
clean: clean:
rm -rf $(clean-objs) rm -rf $(clean-objs)
test: vgbc.test test: vgbc.test
@echo " ... run test $<"; \ @echo " ... run test $<"
./$< $(if $(V),-s,) $(VERBOSE)./$< $(if $(V),-s)
%.o: %.cpp $(headers) %.o: %.cpp
@echo " ... build $@"; \ @echo " ... build $@"
g++ $(CXX_FLAGS) -c -o $@ $< $(VERBOSE)g++ $(CXX_FLAGS) -c -o $@ $<
libemu.a: $(emu-objs) define target_rule
@echo " ... pack $@"; \ $(1): $$(modules_$(1))
ar -rc $@ $^ @echo " ..." $$(or $$(msg_$(1)),$$(msg))
$$(VERBOSE)$$(or $$(cmd_$(1)),$$(cmd))
endef
vgbc: main.o libemu.a $(foreach t,$(TARGETS),$(eval $(call target_rule,$(t))))
@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 $@ $^