Makefile - Rework build system a bit
This commit is contained in:
parent
fb65792e87
commit
8703edbec8
3 changed files with 47 additions and 35 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
|||
/libemu.a
|
||||
/vgbc.test
|
||||
/vgbc.inspect
|
||||
*.d
|
||||
|
|
33
Makeconf
33
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)
|
||||
|
|
48
Makefile
48
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))))
|
||||
|
|
Loading…
Reference in a new issue