2013-01-25 96 views
3

我想用libswscale.so(分別稱爲$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)的變量)替換字符串libswscale.so.2。這是我在Makefile嘗試: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)也由變量組成?

回答

5

發現:$(SHFLAGS)被定義爲

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

,並使用它的任何替換,直到$$(@F)是行不通的實際評估(在我的情況下libswscale.so.2)。

我解決它通過替換可變基準:

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

上分配小暗示:使用時VAR = $(OTHERVAR)進行評價時,VAR := $(OTHERVAR)立即評估。