makefile - How to correctly escape "%" sign when using pattern rules and patsubst in GNU make? -
i have makefile following:
m1: @echo building m1 m1_: @echo building m1_ m2: @echo building m2 m2_: @echo building m2_ m3_deps = m2 m1 substitute=$(patsubst %,%_,$($@_deps)) .secondexpansion: #%: $$(substitute) %: $$(patsubst \%,\%_,$$($$@_deps)) @echo building $@ @echo dependencies $^ the key line is
%: $$(patsubst \%,\%_,$$($$@_deps)) i using both pattern rule , patsubst, uses percentage signs. thought escape % character \, still not getting expected behaviour. running "make m3" gives output
building m2 building m1 building m3 dependencies m2 m1 however, expect get
building m2_ building m1_ building m3 dependencies m2_ m1_ commenting out line , calling patsubst indirectly through variable in fact produce output.
substitute=$(patsubst %,%_,$($@_deps)) %: $$(substitute) also, have tested using non-pattern rule works, makes me think interaction of pattern rules , percentage signs:
m3: $$(patsubst %,%_,$$($$@_deps))
\ in makefile context line continuation, not "escaping". escape things hide them in variable:
percent := % the idea is, @ time makefile fragment parsed escaped character meaningful, escape it.
so, in situation, have use $$(percent):
$$(patsubst $$(percent),$$(percent)_,$$($$@_deps))
Comments
Post a Comment