开发者

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

开发者 https://www.devze.com 2023-03-01 21:49 出处:网络
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:

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

精彩评论

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

关注公众号