Make is a powerful build system with the simple concept of transforming files in other files based on a recipe
flowchart LR A[source files] B(( recipe )) C[output files] A --> B --> C
Special chars #
The makefile syntax involves some character that expands to specific files when make is executed, such as:
$%
the target member name$@
expands to the target file$<
expands to the first requisite$^
expands to all requisites
PHONY targets #
Phony targets are targets that doesn’t generate any file, they are a useful way to group other targets together
.PHONY: build clean
Examples #
- makefile with build directory that generates png from mermaid graph files
BUILDDIR = ./build
%.png: %.mmd
mkdir -p $(BUILDDIR)
mmdc -i $< -o $(BUILDDIR)/$@
clean:
rm -rf $(BUILDDIR)
build: $(patsubst %.mmd,%.png,$(wildcard *.mmd))