Optimize Makefile.

Don't do recursive makes for COMPARE and MODERN, use minimal makefile for making tools.
This commit is contained in:
luckytyphlosion 2021-06-01 20:40:11 -04:00
parent 9da2142a39
commit a839463c84
2 changed files with 35 additions and 15 deletions

View file

@ -1,6 +1,11 @@
$(info start $(shell date +%s%3N))
TOOLCHAIN := $(DEVKITARM) TOOLCHAIN := $(DEVKITARM)
COMPARE ?= 0 COMPARE ?= 0
ifeq (compare,$(MAKECMDGOALS))
COMPARE := 1
endif
# don't use dkP's base_tools anymore # don't use dkP's base_tools anymore
# because the redefinition of $(CC) conflicts # because the redefinition of $(CC) conflicts
# with when we want to use $(CC) to preprocess files # with when we want to use $(CC) to preprocess files
@ -36,6 +41,10 @@ MAKER_CODE := 01
REVISION := 0 REVISION := 0
MODERN ?= 0 MODERN ?= 0
ifeq (modern,$(MAKECMDGOALS))
MODERN := 1
endif
# use arm-none-eabi-cpp for macOS # use arm-none-eabi-cpp for macOS
# as macOS's default compiler is clang # as macOS's default compiler is clang
# and clang's preprocessor will warn on \u # and clang's preprocessor will warn on \u
@ -143,9 +152,10 @@ infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst
# Build tools when building the rom # Build tools when building the rom
# Disable dependency scanning for clean/tidy/tools # Disable dependency scanning for clean/tidy/tools
# Don't build tools yet for modern because we perform a recursive make # Use a separate minimal makefile for speed
ifeq (,$(filter-out all rom berry_fix libagbsyscall,$(MAKECMDGOALS))) # Since we don't need to reload most of this makefile
$(call infoshell, $(MAKE) tools) ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS)))
$(call infoshell, $(MAKE) -f make_tools.mk)
else else
NODEP := 1 NODEP := 1
endif endif
@ -154,16 +164,17 @@ endif
ifeq (,$(MAKECMDGOALS)) ifeq (,$(MAKECMDGOALS))
SCAN_DEPS := 1 SCAN_DEPS := 1
else else
# compare and modern perform recursive calls, so don't scan dependencies yet
# clean, tidy, tools, mostlyclean, clean-tools, $(TOOLDIRS), tidymodern, tidynonmodern don't even build the ROM # clean, tidy, tools, mostlyclean, clean-tools, $(TOOLDIRS), tidymodern, tidynonmodern don't even build the ROM
# berry_fix and libagbsyscall do their own thing # berry_fix and libagbsyscall do their own thing
ifeq (,$(filter-out clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall modern tidymodern tidynonmodern,$(MAKECMDGOALS))) ifeq (,$(filter-out clean tidy tools mostlyclean clean-tools $(TOOLDIRS) tidymodern tidynonmodern berry_fix libagbsyscall,$(MAKECMDGOALS)))
SCAN_DEPS := 0 SCAN_DEPS := 0
else else
SCAN_DEPS := 1 SCAN_DEPS := 1
endif endif
endif endif
$(info scanfiles $(shell date +%s%3N))
ifeq ($(SCAN_DEPS),1)
C_SRCS_IN := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c) C_SRCS_IN := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c)
C_SRCS := $(foreach src,$(C_SRCS_IN),$(if $(findstring .inc.c,$(src)),,$(src))) C_SRCS := $(foreach src,$(C_SRCS_IN),$(if $(findstring .inc.c,$(src)),,$(src)))
C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS)) C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS))
@ -193,11 +204,12 @@ OBJS := $(C_OBJS) $(GFLIB_OBJS) $(C_ASM_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS) $
OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS)) OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))
SUBDIRS := $(sort $(dir $(OBJS))) SUBDIRS := $(sort $(dir $(OBJS)))
$(shell mkdir -p $(SUBDIRS))
endif
$(info scanfiles done $(shell date +%s%3N))
AUTO_GEN_TARGETS := AUTO_GEN_TARGETS :=
$(shell mkdir -p $(SUBDIRS))
all: rom all: rom
tools: $(TOOLDIRS) tools: $(TOOLDIRS)
@ -211,7 +223,7 @@ ifeq ($(COMPARE),1)
endif endif
# For contributors to make sure a change didn't affect the contents of the ROM. # For contributors to make sure a change didn't affect the contents of the ROM.
compare: ; @$(MAKE) COMPARE=1 compare: all
clean: mostlyclean clean-tools clean: mostlyclean clean-tools
@ -295,11 +307,8 @@ endif
# As a side effect, they're evaluated immediately instead of when the rule is invoked. # As a side effect, they're evaluated immediately instead of when the rule is invoked.
# It doesn't look like $(shell) can be deferred so there might not be a better way. # It doesn't look like $(shell) can be deferred so there might not be a better way.
# ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS)))
#$(info MAKECMDGOALS - $(MAKECMDGOALS))
ifeq ($(SCAN_DEPS),1) ifeq ($(SCAN_DEPS),1)
$(info Scanning deps start $(shell date +%s%3N))
ifeq ($(NODEP),1) ifeq ($(NODEP),1)
$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c
ifeq (,$(KEEP_TEMPS)) ifeq (,$(KEEP_TEMPS))
@ -324,9 +333,7 @@ else
$$(AS) $$(ASFLAGS) -o $$@ $$(C_BUILDDIR)/$$*.s $$(AS) $$(ASFLAGS) -o $$@ $$(C_BUILDDIR)/$$*.s
endif endif
endef endef
#$(info C_DEP)
$(foreach src, $(C_SRCS), $(eval $(call C_DEP,$(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o, $(src)),$(src)))) $(foreach src, $(C_SRCS), $(eval $(call C_DEP,$(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o, $(src)),$(src))))
#$(error done C_DEP)
endif endif
ifeq ($(NODEP),1) ifeq ($(NODEP),1)
@ -388,6 +395,7 @@ $1: $2 $$(shell $(SCANINC) -I include -I "" $2)
endef endef
$(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) $(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src))))
endif endif
$(info Scanning deps end $(shell date +%s%3N))
endif endif
$(SONG_BUILDDIR)/%.o: $(SONG_SUBDIR)/%.s $(SONG_BUILDDIR)/%.o: $(SONG_SUBDIR)/%.s
@ -422,7 +430,7 @@ $(ROM): $(ELF)
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@
$(FIX) $@ -p --silent $(FIX) $@ -p --silent
modern: ; @$(MAKE) MODERN=1 modern: all
berry_fix/berry_fix.gba: berry_fix berry_fix/berry_fix.gba: berry_fix

12
make_tools.mk Normal file
View file

@ -0,0 +1,12 @@
TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*))
TOOLBASE = $(TOOLDIRS:tools/%=%)
TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE))
.PHONY: all $(TOOLDIRS)
all: $(TOOLDIRS)
@:
$(TOOLDIRS):
@$(MAKE) -C $@