02.5Makefile

Makefile tab checker

Every recipe line in a Makefile must start with a tab. Paste yours to find the lines indented with spaces, the cause of *** missing separator. Stop., and get a fixed copy.

or drop a file on this box

Summary

Recipe prefix
a tab
Rules
4
Recipe lines
7
Inside define
5 lines, left alone
Problems
3 · 3 fixed

Problems

  1. Command with a colon, indented with spacesNo error, but make reads this line as a new rule (it contains a colon), so it never runs as a command and it ends the recipe above.Fixed: now starts with a tab
  2. Recipe line indented with spacesMakefile:16: *** missing separator. Stop.Fixed: now starts with a tab
  3. Recipe line indented with spacesMakefile:24: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.Fixed: now starts with a tab
1CC·····:=·cc↵
2CFLAGS·:=·-O2·-Wall·\↵
3··········-Wextra↵
4SRCS···:=·main.c·util.c↵
5↵
6define·HELP↵
7Targets:↵
8····build···compile·the·program↵
9····clean···remove·build·output↵
10endef↵
11↵
12.PHONY:·build·clean·help↵
13↵
14build:·$(SRCS)↵
15✓→@echo·"Compiling:·$(SRCS)"↵
16✓→$(CC)·$(CFLAGS)·-o·app·$(SRCS)·\↵
17⇥········-lm↵
18ifeq·($(DEBUG),1)↵
19⇥→@echo·"debug·build"↵
20endif↵
21↵
22clean:↵
23⇥→rm·-f·app↵
24✓→rm·-rf·build/↵
25↵
26help:↵
27⇥→$(info·$(HELP))↵

How the check works

make only treats a line as part of a recipe if it starts with a tab and follows a rule such as build: main.c. A recipe line indented with spaces is read as ordinary makefile syntax, which fails with missing separator (GNU make adds “did you mean TAB instead of 8 spaces?” when there are eight). Worse, a space-indented command that contains a colon, like @echo "Done: $@", is silently read as a new rule.

  • Space-indented lines inside a rule become tab-indented; deeper indentation beyond the first recipe line is kept after the tab.
  • Backslash continuation lines belong to the line above, so they are never changed.
  • Text between define and endef is a variable’s value and is left exactly as it is.
  • ifeq, else and endif may be indented with spaces, but not with a tab inside a rule, where make would hand them to the shell; those tabs are removed.
  • If the file sets .RECIPEPREFIX, that character is used instead of a tab from that point on.

Questions

Why did my editor put spaces there?

Most editors insert spaces when you press Tab. Add an [Makefile] section with indent_style = tab to your .editorconfig and they will insert real tabs in Makefiles.

Can a Makefile use spaces instead of tabs?

Not plain spaces. GNU make 3.82 and later let you set .RECIPEPREFIX to another character, such as >, and start recipe lines with that instead.

Is my Makefile uploaded?

No. The check runs in your browser.