From fa7d9c5eb0e16bb6162b4f22bbe5ddeb2ca7da86 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Tue, 10 Dec 2024 18:12:00 +0800 Subject: [PATCH] fixup! Makefile: start moving to macro based Makefile target generation --- scripts/helpers/rules.mk | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/helpers/rules.mk b/scripts/helpers/rules.mk index 379d370..ad8e187 100644 --- a/scripts/helpers/rules.mk +++ b/scripts/helpers/rules.mk @@ -4,32 +4,33 @@ # # Generate build rules for files in variable _SRCS. Use _CFLAGS, # _CXXFLAGS, _ASFLAGS to control build flags. +# Object files will be put into $BUILDDIR # E.g: # $(eval $(call COMPILE_RULES,AM_)) define COMPILE_RULES -AM_OBJS := $(addprefix $(DST_DIR)/, $(addsuffix .o, $(AM_SRCS))) +$(1)OBJS := $$(addprefix $$(BUILDDIR)/, $$(addsuffix .o, $$($(1)SRCS))) ### Rule (compile): a single `.c` -> `.c.o` (gcc) -$$(filter %.c.o, $$($(1)OBJS)): $$(DST_DIR)/%.c.o: %.c +$$(filter %.c.o, $$($(1)OBJS)): $$(BUILDDIR)/%.c.o: %.c @mkdir -p $$(dir $$@) && echo + CC $$< @$$(CC) $$($(1)CFLAGS) -c -o $$@ $$(realpath $$<) ### Rule (compile): a single `.cc` -> `.cc.o` (g++) -$$(filter %.cc.o, $$($(1)OBJS)): $$(DST_DIR)/%.cc.o: %.cc +$$(filter %.cc.o, $$($(1)OBJS)): $$(BUILDDIR)/%.cc.o: %.cc @mkdir -p $$(dir $$@) && echo + CXX $$< @$$(CXX) $$($(1)CXXFLAGS) -c -o $$@ $$(realpath $$<) ### Rule (compile): a single `.cpp` -> `.cpp.o` (g++) -$$(filter %.cpp.o, $$($(1)OBJS)): $$(DST_DIR)/%.cpp.o: %.cpp +$$(filter %.cpp.o, $$($(1)OBJS)): $$(BUILDDIR)/%.cpp.o: %.cpp @mkdir -p $$(dir $$@) && echo + CXX $$< @$$(CXX) $$($(1)CXXFLAGS) -c -o $$@ $$(realpath $$<) ### Rule (compile): a single `.S` -> `.S.o` (gcc, which preprocesses and calls as) -$$(filter %.S.o, $$($(1)OBJS)): $$(DST_DIR)/%.S.o: %.S +$$(filter %.S.o, $$($(1)OBJS)): $$(BUILDDIR)/%.S.o: %.S @mkdir -p $$(dir $$@) && echo + AS $$< @$$(AS) $$($(1)ASFLAGS) -c -o $$@ $$(realpath $$<) ### Rule (`#include` dependencies): paste in `.d` files generated by gcc on `-MMD` --include $$(addprefix $$(DST_DIR)/, $$(addsuffix .d, $$(filter %.c %.cc, $$(AM_SRCS)))) +-include $$(addprefix $$(BUILDDIR)/, $$(addsuffix .d, $$(filter %.c %.cc, $$($(1)SRCS)))) endef # Usage: