make
looks for the file named Makefile
in the CWD.
make
: make the first targetmake all
: make all targetsmake clean
: clean the build-j [num of jobs]
: specify how many threads-d
: show debug info--debug
: show more debug info-p
: show rules and variable values--trace
: trace make (verbose)1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Note: each build cmd runs in a separate shell!
VAR := VALUE
: set variable, expands immediately (at the time of assignment)VAR = VALUE
: set variable, expands lazily (at the time of use)$(VAR)
: get variable1 2 3 |
|
CC
: path to the C compilerCFLAGS
: C compiler flagsLD
: path to the C linkerLDFLAGS
: C linker flagsTARGET
: name of the executableSRC
: list of all source filesOBJ
: list of all object files%.o
: match all .o files$@
: target$<
: first dependency of target$^
: all dependencies of targetFor example:
1 2 3 4 5 |
|
.PHONY: clean all
: make sure that the target always rebuilds.DEFAULT_GOAL := all
: change the default target$(SRC:.c=.o)
: generate list of .o from list of .c$(addprefix $(BUILD_DIR), $(SRC:.c=.o))
$(patsubst %.c, $(BUILD_DIR)/%.o, $(SRC))
gcc
with:-MMD
: generate dependency files (.d)-MP
: avoid errors if header file (.h) is deleted/renamed-include $(OBJ:.o=.d)
in the Makefile to include all dependency files (.d)