Makefile¶
Variables¶
Spaces at the beginning are stripped away
Immediate Assignment ::= (Recommended)¶
index
- Simply Expanded
:=historical GNU extension. Is not POSIX compliant, use::=instead
EMAIL = "foo@example.com"
AUTHOR ::= foo <$(EMAIL)>
EMAIL = "bar@example.com"
# AUTHOR = foo <foo@example.com>
Recursively Expanded (=)¶
EMAIL = "foo@example.com"
AUTHOR = foo <$(EMAIL)>
EMAIL = "bar@example.com"
# AUTHOR = foo <bar@example.com>
Conditional Assignment¶
index
- read from env
- set it not defined
- safe assignment
Shell Assignment¶
Automatic Variables¶
index: magic variables
parent/foo.c: one two
# Outputs target name: "parent/foo.c"
echo $@
# Outputs first prerequisite: `one`
echo $<
# Outputs all prerequisites: `one two`
echo $^
# Outputs all prerequisites newer than the target
echo $?
# Outputs target directory: parent/
$(@D)
# Outputs target filepath only: foo.c
$(@F)
Snippets¶
Enums¶
index: oneOf
ALLOWED_ENVS := dev prd
# Default env
ENV ?= dev
ifeq ($(filter $(ENV),$(ALLOWED_ENVS)),)
$(error Invalid ENV '$(ENV)'. Must be one of: $(ALLOWED_ENVS))
endif
Options¶
Resources¶
- GNU Make Manual
- Makefile cheatsheet
- Makefile tutorial (a bit outdated)
- Make intro