Makefile 目标依赖项:如何拼凑一个变量名

Makefile target dependencies: How to piece together a variable name

在我的 Makefile 中,我想做这样的事情

OBJ_sound =\
    sound/soundaiff.o\
    sound/sounddummy.o\
    sound/sounddump.o

OBJ_video =\
    video/render.o\
    video/rendercrt.o\
    video/renderntsc.o

lib_%.a: $(OBJ_%)
    $(AR) rcs $@ $+

我想要,当目标 lib_video.a 生成时,$(OBJ_video) 中的所有目标文件都被打包到 lib_video.a 中,当 lib_sound 生成时,所有$(OBJ_sound) 中的目标文件被打包到 lib_sound.a

但是我上面的 Makefile 片段不起作用($+ 始终为空)。有人知道为什么吗?

一个选项是使用 secondary expansion:

.SECONDEXPANSION:

lib_%.a: $$(OBJ_$$*)
    $(AR) rcs $@ $+