我想用libswscale.so.2
替换字符串libswscale.so
(分别称为$(SLIBNAME_WITH_MAJOR)
和$(SLIBNAME)
的变量)。这是我在Makefile中尝试的:
$(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)
也是由变量组成的吗?
答案 0 :(得分:5)
找到它:$(SHFLAGS)
被定义为
SHFLAGS=-shared -Wl,-soname,$$(@F) blablafoo
并在其上使用任何替换在$$(@F)
实际评估之前无效(在我的情况下为libswscale.so.2
)。
我通过替换变量引用来解决它:
@echo $(subst $$(@F),$(SLIBNAME),$(SHFLAGS))
分配的小提示:VAR = $(OTHERVAR)
在使用时进行评估,立即评估VAR := $(OTHERVAR)
。