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?
Your
$(filter)looks correct.Possibly the cause may be the evaluation order between
@echocommandand
$(foreach).Does replacing
@echowith$(shell echo ...)like the followingsolve the problem?