Remove unnecessary looping for rule generation and unroll macros (#2046)
This commit is contained in:
parent
a0be2cbf7b
commit
253d3dd7ef
1 changed files with 36 additions and 53 deletions
89
Makefile
89
Makefile
|
@ -297,69 +297,52 @@ 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 (Icedude_907: there is soon).
|
# It doesn't look like $(shell) can be deferred so there might not be a better way (Icedude_907: there is soon).
|
||||||
|
|
||||||
# For C dependencies.
|
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c
|
||||||
# Args: $1 = Output file without extension (build/assets/src/data), $2 = Input file (src/data.c)
|
|
||||||
define C_DEP
|
|
||||||
$(call C_DEP_IMPL,$1,$2,$1)
|
|
||||||
endef
|
|
||||||
# Internal implementation details.
|
|
||||||
# $1: Output file without extension, $2 input file, $3 temp path (if keeping)
|
|
||||||
define C_DEP_IMPL
|
|
||||||
$1.o: $2
|
|
||||||
ifneq ($(KEEP_TEMPS),1)
|
ifneq ($(KEEP_TEMPS),1)
|
||||||
@echo "$$(CC1) <flags> -o $$@ $$<"
|
@echo "$(CC1) <flags> -o $@ $<"
|
||||||
@$$(CPP) $$(CPPFLAGS) $$< | $$(PREPROC) -i $$< charmap.txt | $$(CC1) $$(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$(AS) $$(ASFLAGS) -o $$@ -
|
@$(CPP) $(CPPFLAGS) $< | $(PREPROC) -i $< charmap.txt | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ -
|
||||||
else
|
else
|
||||||
@$$(CPP) $$(CPPFLAGS) $$< -o $3.i
|
@$(CPP) $(CPPFLAGS) $< -o $*.i
|
||||||
@$$(PREPROC) $3.i charmap.txt | $$(CC1) $$(CFLAGS) -o $3.s
|
@$(PREPROC) $*.i charmap.txt | $(CC1) $(CFLAGS) -o $*.s
|
||||||
@echo -e ".text\n\t.align\t2, 0\n" >> $3.s
|
@echo -e ".text\n\t.align\t2, 0\n" >> $*.s
|
||||||
$$(AS) $$(ASFLAGS) -o $$@ $3.s
|
$(AS) $(ASFLAGS) -o $@ $*.s
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.c
|
||||||
|
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include $<
|
||||||
|
|
||||||
ifneq ($(NODEP),1)
|
ifneq ($(NODEP),1)
|
||||||
$1.d: $2
|
-include $(addprefix $(OBJ_DIR)/,$(C_SRCS:.c=.d))
|
||||||
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include $2
|
|
||||||
-include $1.d
|
|
||||||
endif
|
|
||||||
endef
|
|
||||||
|
|
||||||
# Create generic rules if no dependency scanning, else create the real rules
|
|
||||||
ifeq ($(NODEP),1)
|
|
||||||
$(eval $(call C_DEP,$(C_BUILDDIR)/%,$(C_SUBDIR)/%.c))
|
|
||||||
else
|
|
||||||
$(foreach src,$(C_SRCS),$(eval $(call C_DEP,$(OBJ_DIR)/$(basename $(src)),$(src))))
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Similar methodology for Assembly files
|
$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s
|
||||||
# $1: Output path without extension, $2: Input file (`*.s`)
|
$(AS) $(ASFLAGS) -o $@ $<
|
||||||
define ASM_DEP
|
|
||||||
$1.o: $2
|
$(ASM_BUILDDIR)/%.d: $(ASM_SUBDIR)/%.s
|
||||||
$$(AS) $$(ASFLAGS) -o $$@ $$<
|
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<
|
||||||
$(call ASM_SCANINC,$1,$2)
|
|
||||||
endef
|
|
||||||
# As above but first doing a preprocessor pass
|
|
||||||
define ASM_DEP_PREPROC
|
|
||||||
$1.o: $2
|
|
||||||
$$(PREPROC) $$< charmap.txt | $$(CPP) $(INCLUDE_SCANINC_ARGS) - | $$(PREPROC) -ie $$< charmap.txt | $$(AS) $$(ASFLAGS) -o $$@
|
|
||||||
$(call ASM_SCANINC,$1,$2)
|
|
||||||
endef
|
|
||||||
|
|
||||||
define ASM_SCANINC
|
|
||||||
ifneq ($(NODEP),1)
|
ifneq ($(NODEP),1)
|
||||||
$1.d: $2
|
-include $(addprefix $(OBJ_DIR)/,$(ASM_SRCS:.s=.d))
|
||||||
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I "" $2
|
|
||||||
-include $1.d
|
|
||||||
endif
|
endif
|
||||||
endef
|
|
||||||
|
|
||||||
# Dummy rules or real rules
|
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s
|
||||||
ifeq ($(NODEP),1)
|
$(PREPROC) $< charmap.txt | $(CPP) $(INCLUDE_SCANINC_ARGS) - | $(PREPROC) -ie $< charmap.txt | $(AS) $(ASFLAGS) -o $@
|
||||||
$(eval $(call ASM_DEP,$(ASM_BUILDDIR)/%,$(ASM_SUBDIR)/%.s))
|
|
||||||
$(eval $(call ASM_DEP_PREPROC,$(C_BUILDDIR)/%,$(C_SUBDIR)/%.s))
|
$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.s
|
||||||
$(eval $(call ASM_DEP_PREPROC,$(DATA_ASM_BUILDDIR)/%,$(DATA_ASM_SUBDIR)/%.s))
|
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<
|
||||||
else
|
|
||||||
$(foreach src, $(ASM_SRCS), $(eval $(call ASM_DEP,$(src:%.s=$(OBJ_DIR)/%),$(src))))
|
ifneq ($(NODEP),1)
|
||||||
$(foreach src, $(C_ASM_SRCS), $(eval $(call ASM_DEP_PREPROC,$(src:%.s=$(OBJ_DIR)/%),$(src))))
|
-include $(addprefix $(OBJ_DIR)/,$(C_ASM_SRCS:.s=.d))
|
||||||
$(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call ASM_DEP_PREPROC,$(src:%.s=$(OBJ_DIR)/%),$(src))))
|
endif
|
||||||
|
|
||||||
|
$(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s
|
||||||
|
$(PREPROC) $< charmap.txt | $(CPP) $(INCLUDE_SCANINC_ARGS) - | $(PREPROC) -ie $< charmap.txt | $(AS) $(ASFLAGS) -o $@
|
||||||
|
|
||||||
|
$(DATA_ASM_BUILDDIR)/%.d: $(DATA_ASM_SUBDIR)/%.s
|
||||||
|
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<
|
||||||
|
|
||||||
|
ifneq ($(NODEP),1)
|
||||||
|
-include $(addprefix $(OBJ_DIR)/,$(REGULAR_DATA_ASM_SRCS:.s=.d))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(OBJ_DIR)/sym_bss.ld: sym_bss.txt
|
$(OBJ_DIR)/sym_bss.ld: sym_bss.txt
|
||||||
|
|
Loading…
Reference in a new issue