Thu 15 Sep 2016 11:40:01 PM UTC, comment #3:
I'm not asking for behavioral change -- I figured that would have been a long shot at best. But I still feel like the docs are inconsistent, or at least could be clarified a bit.
Specifically, the sentences "Note that 'ifdef' only tests whether a variable has a value. It does not expand the variable to see if that value is nonempty." are, to my mind, incorrect, and not consistent with the earlier definition, or with the following examples.
In your first example here, FOO has a value, even if it's empty, so according to those sentences, it should evaluate to true. I don't know whether that counts as "expansion", or whether "expansion" only matters when there's another variable for indirection, as in the second example.
Perhaps something like "Note that 'ifdef' only tests the named variable for a non-empty value, and does not further expand any variables it might reference." in place of those two sentences. I'm not positive that would have told me what I needed to know, but I think it's a bit better than what's there now.
That said, I know the answer now, and this bug can be found if people search for ifdef and gnu make, so if you're averse to the change, perhaps that's enough.
|
Wed 14 Sep 2016 10:13:25 PM UTC, comment #1:
What the doc is trying to say is that:
will not print true because FOO has no value.
However, this:
will print true. Even though if you expanded $(BAR) you'd get the empty string, the variable BAR is not empty (it's set to $(FOO)) and so ifdef calls it defined. Probably an example like this would help make the doc more clear.
Yes, it's true that ifdef is badly named. It should be something like "ifset" or whatever instead. However, it works as intended and so does the origin function value "undefined"; they have had these inconsistent meanings for 20+ years now; they're not going to change.
|
Wed 14 Sep 2016 09:57:06 PM UTC, original submission:
The info doc for "ifdef" is inconsistent. It first says
If the value of that variable has a non-empty value, the
TEXT-IF-TRUE is effective
but then later says
Note that 'ifdef' only tests whether a variable has a value.
It does not expand the variable to see if that value is
nonempty.
Perhaps I'm reading one of those two bits wrong?
At any rate, there seems to be a discrepancy in behavior between "ifdef" and $(origin). Again, perhaps there's something I'm missing, but the following makefile demonstrates the issue. If I leave VAR set to empty, then ifdef thinks VAR is undefined, but origin thinks it's defined. If I set VAR to a non-empty value, both think it's defined. If I remove the line entirely or add "undefine VAR", then both think it's undefined. I see this behavior with 4.2.1 and with 3.82.
VAR=
ifdef VAR
$(info ifdef thinks VAR is defined)
else
$(info ifdef thinks VAR is undefined)
endif
ifneq "$(origin VAR)" "undefined"
$(info ifneq/origin thinks VAR is defined)
else
$(info ifneq/origin thinks VAR is undefined)
endif
all:
|