I guess this makes sense somehow, but I can't grasp why: In the following code, I get both warnings (note that the original code was indented with tabs):
define variable-definition
ifndef $1
$(warning $1 is undefined)
else
$(warning $1 is defined)
endif
endef
PS: I want to check whether the variable with the name passed as $1
exists, not whether $1
was passed.
PPS: Dedenting the entire thing doesn't help.
An undefined variable in the source code of a computer program is a variable that is accessed in the code but has not been declared by that code. In some programming languages, an implicit declaration is provided the first time such a variable is encountered at compile time.
The difference between defined and undefined articles is therefore in the object or person that is designated. If the object or person is known and identified, the definite articles are used. On the contrary, if the object or person is not known and identified, the undefined articles are used.
Undefined: It occurs when a variable has been declared but has not been assigned with any value. Undefined is not a keyword. Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using var or const keyword.
A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .
Beta's analysis of the root cause is correct, you're not escaping your $
on the $(warning)
calls. Here's how I'd fix it:
define variable-def
ifndef $1
$$(warning $1 is undefined)
else
$$(warning $1 is defined)
endif
endef
FOO=bar
$(eval $(call variable-def,FOO))
Note that I am indenting with spaces, not tabs. If you indent with tabs, you get this error: *** commands commence before first target. Stop.
This uses GNUisms, but so does your sample (I think).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With