3

我想libswscale.so.2用(分别称为和的libswscale.so变量)替换字符串。这是我在 Makefile 中尝试的:$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)

$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver
    [...]
    @echo SHFLAGS=$(SHFLAGS)
    @echo SLIBNAME_WITH_MAJOR=$(SLIBNAME_WITH_MAJOR)
    @echo SLIBNAME=$(SLIBNAME)
    @echo A $(patsubst $(SLIBNAME_WITH_MAJOR),$(SLIBNAME),$(SHFLAGS))
    @echo B $(SHFLAGS:$(SLIBNAME_WITH_MAJOR)=$(SLIBNAME))
    @echo C $($(SHFLAGS):$(SLIBNAME_WITH_MAJOR)=$(SLIBNAME))
    @echo D $(SHFLAGS:$(SLIBNAME_WITH_MAJOR)=$(SLIBNAME))
    @echo E $(subst $(SLIBNAME_WITH_MAJOR),$(SLIBNAME),$(SHFLAGS))
    @echo F $(subst l,L,$(SHFLAGS))

输出是

SHFLAGS=-shared -Wl,-soname,libswscale.so.2 -Wl,-Bsymbolic -Wl,--version-script,libswscale/libswscale.ver
SLIBNAME_WITH_MAJOR=libswscale.so.2
SLIBNAME=libswscale.so
A -shared -Wl,-soname,libswscale.so.2 -Wl,-Bsymbolic -Wl,--version-script,libswscale/libswscale.ver
B -shared -Wl,-soname,libswscale.so.2 -Wl,-Bsymbolic -Wl,--version-script,libswscale/libswscale.ver
C
D -shared -Wl,-soname,libswscale.so.2 -Wl,-Bsymbolic -Wl,--version-script,libswscale/libswscale.ver
E -shared -Wl,-soname,libswscale.so.2 -Wl,-Bsymbolic -Wl,--version-script,libswscale/libswscale.ver
F -shared -WL,-soname,libswscale.so.2 -WL,-BsymboLic -WL,--version-script,LibswscaLe/LibswscaLe.ver

最后一个(F)特别荒谬。这里有什么问题?是因为它$(SHFLAGS)也是由变量组成的吗?

4

1 回答 1

8

找到它:$(SHFLAGS)被定义为

SHFLAGS=-shared -Wl,-soname,$$(@F) blablafoo

$$(@F)并且在实际评估之前使用任何替换都不起作用(在我的情况下libswscale.so.2)。

我通过替换变量引用解决了它:

@echo $(subst $$(@F),$(SLIBNAME),$(SHFLAGS))

关于分配的小提示:VAR = $(OTHERVAR)使用时VAR := $(OTHERVAR)评估,立即评估。

于 2013-01-25T13:30:16.453 回答