Skip to main content

Makefile Formatter

Format and clean up GNU Makefiles. Converts space-indented recipe lines to the tabs Make requires, trims trailing whitespace, collapses extra blank lines, normalizes spacing around assignment operators (= := ?= +=), and optionally aligns consecutive variable assignments. Runs entirely in your browser.

Input

Formatting Options

Output

Formatted Makefile
 
Was this helpful?

Guides

Makefile Formatter

Clean up and standardize GNU Makefiles in your browser. Paste a Makefile and this tool fixes the formatting problems that break builds or make them hard to read — most importantly the one that causes the dreaded *** missing separator. Stop. error: recipe lines indented with spaces instead of a tab.

Everything runs client-side. Your Makefile never leaves your machine.

Why Makefile indentation is special

Unlike most languages, indentation in a Makefile is not cosmetic. Every command line under a target — a recipe line — must begin with a literal tab character. A recipe indented with spaces is a syntax error, not a style preference. This trips up editors that silently convert tabs to spaces, and it is one of the most common mistakes in hand-written and AI-generated Makefiles.

This formatter understands the distinction. It converts leading spaces to tabs only on lines that are genuinely recipe lines — the commands that follow a target: line. Variable assignments, comments, include/ifeq directives and conditional bodies are left alone, because they are not recipes and must not start with a tab.

What it does

  • Recipe tab conversion — space-indented recipe lines become tab-indented. The chosen tab width (8, 4 or 2) tells the tool how many leading spaces make one indent level, so a deeper-nested continuation keeps its extra level.
  • Trailing whitespace — stripped from every line.
  • Blank lines — runs of blank lines are collapsed to a maximum of two.
  • Assignment spacing — normalized to VAR = value (one space on each side) for =, :=, ::=, ?=, += and !=, without touching recipe commands.
  • Assignment alignment (optional) — pads the operator column across a run of consecutive variable assignments so the = signs line up.

Backslash line continuations (\ at end of line) and define … endef blocks are preserved verbatim, so multi-line variables and canned recipes are never broken. Comments (#) are kept exactly as written.

How to use it

  1. Paste your Makefile into the input box (or click Try an example).
  2. Pick a tab width and toggle the formatting options you want.
  3. Copy or download the formatted result.

Why did my spaces not turn into tabs?

Only recipe lines are converted. If a space-indented line is a variable assignment, a comment, or sits inside a conditional block rather than under a target, it is intentionally left as-is — converting it would change the meaning of the Makefile or introduce its own missing separator error.

Does it preserve .PHONY, pattern rules and automatic variables?

Yes. .PHONY, %.o: %.c pattern rules, $@/$</$^ automatic variables and $(VAR) references are all treated as ordinary text and passed through untouched — the tool only adjusts whitespace and assignment spacing, never the build logic.

makefilemakegnu makeformatterbeautifytabsrecipebuild

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.