开发者

How can I dump a filtered list of Makefile variables to a file?

I'd like to dump all Makefile variables that start with MYLIB_ and their values to a file called config.h as preprocessor definitions. This is what I have tried:

config:
    @echo "// AUTO-GENERATED - DO NOT EDIT!" > config.h
    $(foreach V, $(filter MYLIB_%, $(.VARIABLES)),
        $(shell echo "#define $(V) $($V)" >> config.h))

Unfortunately, $(filter) doesn't return any values, even though $(.VARIABLES) contains items that begin with MYLIB_.

What am I doing wrong开发者_StackOverflow中文版?


Your $(filter) looks correct. Possibly the cause may be the evaluation order between @echo command and $(foreach). Does replacing @echo with $(shell echo ...) like the following solve the problem?

config:
    $(shell echo "// AUTO-GENERATED - DO NOT EDIT!" > config.h) \
    $(foreach V, $(filter MYLIB_%, $(.VARIABLES)), \
        $(shell echo "#define $(V) $($V)" >> config.h))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜