How to use the Makefile generator
- In the main box, write one task per line as
target: command. Add## descriptionat the end to document it. - To run several commands for one target, repeat the target on new lines; the commands are joined in order.
- Add variables as
NAME = value(also:=,?=or+=) and use them as$(NAME). - Keep Add a self-documenting help target ticked for a
make helpcommand. - Optionally enter a Default target, the one plain
makeruns. Then download the file asMakefile.
What it does and when to use it
A Makefile gives a project short, memorable commands: make test, make build, make docker. It works the same for Node, Python or Go projects, so new team members do not need to learn each tool’s commands. The catch is the syntax, especially the rule that recipe lines need a real tab, which this tool handles for you.
Make sits beside other project setup files. A Procfile lists the processes a platform should run, an .env example file documents the settings, and a Dockerfile is often what a docker target builds.
How it works
Lines that look like variable assignments are copied to the top of the file. Other lines are split at the first colon into a target and a command, and a ## comment becomes the description. Lines starting with # are ignored.
The file then gets .DEFAULT_GOAL := (your choice, else help, else the first target) and one .PHONY: line listing every target, as described in the GNU make manual. The help recipe uses grep and awk to print every documented target. Recipes are indented with a tab character.
Worked examples
The sample project. Six lines produce, among others:
APP = invoice-parser
.DEFAULT_GOAL := help
.PHONY: help install test build clean docker
install: ## Install dependencies
npm ci
The docker target has no description, so make help does not list it.
Two commands for one target. lint: eslint . and lint: prettier --check . with help off become a single target with two tab-indented recipe lines, and .DEFAULT_GOAL := lint.
A Python project with a default. PY ?= python3, a run target and a test target, with default target run. The file keeps the variable, sets .DEFAULT_GOAL := run, and recipes read $(PY) app.py and $(PY) -m pytest.
Limits and tips
- Every target is marked .PHONY. If a target really builds a file, remove it from that line so make can skip work that is up to date.
- Without any
target: commandline, the tool replies “Add at least one “target: command” line.” - In recipes, write
$$when the shell, not make, should see a$.
Frequently asked questions
Why does make say "missing separator"?
What does .PHONY do?
How does make help know what to print?
Can a target depend on another target?
Does this work on Windows?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.