用多个更改替换 Make 变量的值?

Substitute the value of a Make variables with multiple alterations?

#
# Sources are .c and .s files
#
# Append .o to both .c and .s:  
PRJ_OBJ := $(addprefix $(BUILD_PATH)/,$(addsuffix .o, $(PRJ_SRC)))
# Create .c.d from .c.o and .s.d from s.o:
PRJ_DEP_TEMP := $(PRJ_OBJ:.c.o=.c.d)
PRJ_DEP += $(PRJ_DEP_TEMP:.s.o=.s.d)

如何在一行而不是两行中同时替换 .c.o=.c.d.s.o=.s.d

文档:GNU Make Substitution References.

如果您的目的是只为 .c.o.s.o 文件获取 .d 文件,那么您必须执行如下操作:

PRJ_DEP = $(patsubst %.o,%.d,$(filter %.c.o %.s.o,$(PRJ_OBJ)))

$(filter ... 会删除您不想为其创建相应 .d 文件的任何文件,然后您只需将 .o 替换为 .d使用 $(patsubst...

另一方面,如果您知道 PRJ_OBJ 只包含 .c.o.s.o 文件,那么您可以按照@Vroomfondel 或@urcodebetterznow 的建议去做:

PRJ_DEP += $(PRJ_OBJ:%.o=%.d)