Puzzling variables behaviour in make(1)

Jeremie Le Hen jeremie at le-hen.org
Sun Nov 5 20:04:19 UTC 2006


Hello,

I wrote the following piece of Makefile:

% .warning "VAR contains: ${VAR}"
%
% VAR_BACKUP:= ${VAR}
% VAR:= value2
% 
% .if ${VAR} == "value2"
% .warning "VAR is overwritable: ${VAR}"
% .else
% .warning "VAR is NOT overwritable: ${VAR}"
% .endif
% 
% VAR:= ${VAR_BACKUP}
%
% all:

If I define VAR within the Makefile (VAR:= value1), I get:
% jarjarbinks:~/test/makevars:230# make
% "Makefile", line 3: warning: "VAR contains: value1"
% "Makefile", line 7: warning: "VAR is overwritable: value2"

If I remove the VAR assignment in the Makefile and define it from
the command -line, I get:
% jarjarbinks:~/test/makevars:232# make VAR=value1
% "Makefile", line 3: warning: "VAR contains: value1"
% "Makefile", line 9: warning: "VAR is NOT overwritable: value2"

Note that this behaviour is puzzling since it follows the path as if
{VAR} didn't contain "value2" but the warning message shows it does
contains "value2".

Finally, if I define VAR both from the command-line and within the
Makefile:
% jarjarbinks:~/test/makevars:242# make VAR=value1
% "Makefile", line 3: warning: "VAR contains: value1"
% "Makefile", line 11: warning: "VAR is NOT overwritable: value2"

Same weird behaviour.


Actually I am trying to find a way to tell whether a variable has
been defined from make.conf(5) or src.conf(5) or from the command-line.
According to the code path this method appears to work, but the
value of ${VAR} isn't "correct".


If this is the expected behaviour, I'd be glad to understand the magic
behind this.

Thank you.
Best regards,
-- 
Jeremie Le Hen
< jeremie at le-hen dot org >< ttz at chchile dot org >


More information about the freebsd-hackers mailing list