Simple line replacement in Makefile
I want to replace the string libswscale.so.2
with libswscale.so
(variables are named $(SLIBNAME_WITH_MAJOR)
and $(SLIBNAME)
, respectively). This is what I tried in the 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))
Output signal
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
The latter (F) is especially ludicrous. What's wrong here? Is it because it $(SHFLAGS)
also consists of variables?
source to share
Found: $(SHFLAGS)
defined as
SHFLAGS=-shared -Wl,-soname,$$(@F) blablafoo
and using any substitution on it won't work until $$(@F)
it's actually evaluated (in my case - libswscale.so.2
).
I solved it by replacing the variable reference:
@echo $(subst $$(@F),$(SLIBNAME),$(SHFLAGS))
A little hint about assignments: VAR = $(OTHERVAR)
Evaluated when used, VAR := $(OTHERVAR)
Evaluated immediately.
source to share