Variables in Make
Print a variable to the screen with echo
Curly braces are used to print the contents of a variable.
FOO = bar .PHONY: vars vars: @echo ${FOO}
make vars
bar
Other examples
With shell you can get data from outside and write it to a variable
X = "ABCD" FILES := $(shell ls) .PHONY: files files: @echo ${X} @echo ${FILES}
make files
ABCD GNUmakefile heihei.ru.config
target-specific variables
You can limit the scope of a variable to a particular target.
General syntax
target … : variable-assignment
target name : assigning a value to a variable
test: A = B
Example
X = "ABCD" FILES := $(shell ls) .PHONY: files files: X = "EFGH" files: FILES := $(shell pwd) files: @echo ${X} @echo ${FILES}
make files
EFGH
/home/andrei
As you can see, the values of the local variables are printed, not the global ones.
Article author: Andrei Olegovich