user11809993
user11809993

Reputation: 81

Is there any way to detect if a makefile variable is poisioned without dying?

I'd like in a makefile to find all variables that match a pattern, and print their values. So I have:

$(foreach var,$(filter XX_%,$(.VARIABLES)), \
     $(info $(var)=$($(var))))

Nice and simple. But, in some places people like to poison the variables... i.e.:

XX_FOO = $(error XX_FOO is deprecated, please use XX_FOOBAR instead)

This causes my above snippet to fail as it tries to expand the variable. I'm wondering if there's some way to test if a variable is poisoned before expanding it...

Upvotes: 1

Views: 47

Answers (1)

MadScientist
MadScientist

Reputation: 100836

You can use the value function to avoid interpreting the variable.

BTW, it's helpful if you provide an actual minimal working example: the above has a number of syntax errors.

Try this:

errorpat := $$(error%

$(foreach var,$(filter XX_%,$(.VARIABLES)),\
     $(info $(var) =$(if $(filter $(errorpat),$(value $(var))),\
                         $(value $(var)),\
                         $($(var)))))

Here errorpat is a filter pattern that matches your "poisoned" variables.

Upvotes: 2

Related Questions