Mon 03 May 2010 06:42:21 PM UTC, original submission:
I encountered this problem when writing a complex Makefile, so at the beginning I didn't figured out where the problem was. But then I managed to isolate it, and I was astonished. Here a simple Makefile:
deferred_var = $(wildcard *)
static_var := some text
foo: static_var += $(deferred_var)
deferred_var = nothing
foo:
@echo "$(static_var)"
If I place it in an empty directory, I would expect the output of make to be:
some text Makefile
But, instead of that, I get:
some text nothing
I think this is wrong, static_var is a simply-expanded variable, and:
"When you add to a variable's value with `+=', make acts essentially as if you had included the extra text in the initial definition of the variable. If you defined it first with `:=', making it a simply-expanded variable, `+=' adds to that simply-expanded definition, and expands the new text before appending it to the old value just as `:=' does"
If I replace
foo: static_var += $(deferred_var)
with
foo: static_var := $(static_var) $(deferred_var)
it works as expected, but it's an ugly workaround.
This happens of course only when doing a target-specific assignment, but it's quite annoying.
|