Skip to content

Instantly share code, notes, and snippets.

@estysdesu
Last active July 31, 2019 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estysdesu/d1a4fe106f3e6557e9c7dd600472de65 to your computer and use it in GitHub Desktop.
Save estysdesu/d1a4fe106f3e6557e9c7dd600472de65 to your computer and use it in GitHub Desktop.
[Make: variables and assignment] #gnu #make #makefile
##### make/shell VARIABLES #####
# $(<var>): reference make variable
# ${<var>}: reference environment variable
x = `pwd`; echo $(x)
y = ${PATH}
##### `=`/`:=`/`?=`/`+=` (VARIABLE ASSIGNMENT) #####
# https://stackoverflow.com/questions/448910/what-is-the-difference-between-the-gnu-makefile-variable-assignments-a
# `=`: evaluated when used, not declared (lazy set); setting of a variable where values within it are recursively expanded when the variable is used
# `:=`: evaluated immediately (immediate set); setting of a variable with simple expansion of the values inside
# `?=`: setting of a variable only if it doesn't have a value (set if absent)
# `+=`: appending the supplied value to the existing variable value or setting to that value if the variable didn't exist (append or set)
x = `pwd`; cd ..; echo $(x) # --> x is one level up the tree
y := data.csv password.txt report.pdf
y += dog.png # --> y == data.csv password.txt report.pdf dog.png (with space)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment