Skip to main content
  1. Technologies/

make

·173 words·1 min· ·
Technologies notes - This article is part of a series.
Part 9: This Article

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

makefile vars
#

A var in a makefile is defined as follows:

BUILDDIR = ./build

And is referred with the $() notations

mytarget:
  some_long_command $(BUILDDIR)

💡 ENVIRONMENT variables are automatic exposed with the same notation $(), example $(HOME)

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))
Matteo Longhi
Author
Matteo Longhi
I’m a software engineer with a passion for Music, food, dogs, videogames and open source software, i’m currently working as a devops engineer
Technologies notes - This article is part of a series.
Part 9: This Article