How to correctly escape “%” sign when using pattern rules and patsubst in GNU make?

妖精的绣舞 提交于 2019-12-05 00:14:58

\ in makefile context is for line continuation, not for "escaping". To escape things you hide them in a variable:

PERCENT := %

The idea is, at the time a makefile fragment is parsed where the escaped character is meaningful, you escape it.

So, in your situation, you have to use $$(PERCENT):

$$(patsubst $$(PERCENT),$$(PERCENT)_,$$($$@_DEPS))

I don't know of a way to hide '%' from the pattern rule, but in this case you can work around it:

%: $$(addsuffix _,$$($$*_DEPS))
    @echo Building $@
    @echo Dependencies are $^

This does not appear to be possible.

For a few workarounds, see the question and Beta's answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!