3 ms·
While it is not so important in simple cases, '=' allows to not depend on the order of definitions, so you can group variables in logical order, not as statemen
by wruza 9y ago
While it is not so important in simple cases, '=' allows to not depend on the order of definitions, so you can group variables in logical order, not as statements. You can look at := as variable definition and = as semi-function definition. Penalty of delayed-but-many variable expansion that doesn't contain shell code is questionable. Also, with := half of them may not be used by 'maked' rule at all, actually losing performance.
There is also ?= which only sets a variable that was not set before or via command line or environment (make inherits current environment variables iirc).
- dom0 9y ago> and = as semi-function definition. Variable binding.
- klodolph 9y agoWell, = doesn't really behave like traditional variable binding, since you can do stuff like: build = cc -c -o $@ $< file1.o: file1.c $(build) file2.o: file2.c $(build) (This is meant to illustrate the difference, this isn't a good makefile.) To reinforce the notion that variables are really functions, you can even supply arguments when you call them: # reverse is a function reverse = $(2) $(1) # eventually expands to 2 1 a = $(call reverse,1,2)
- KSteffensen 9y agoPlease don't rely on environment variables. It plays havoc with reproducibility.
- wruza 9y agoI'm usually adding 'vars' target to my makefiles that simply echoes them to see if anything is wrong or simply to see defaults. There is also command-line option to do that (and of course -n), but it prints too much to comprehend.