makefile
Skill2 starsChanged 4 months agoMITView on GitHub
Best practices for authoring clean, maintainable, and portable GNU Make Makefiles. Use when the task involves `creating or editing Makefiles`, `Makefile`, `makefile`, `*.mk`, `GNUmakefile`, `GNU Make patterns`, `build automation`, or `makefile troubleshooting`.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- AnthonyPoschen/agent-skillstheir own version, first seen Aug 25, 2026
- aptitude-stack/registerytheir own version, first seen Apr 1, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- AnthonyPoschen/agent-skills★ 2same name
- aptitude-stack/registery★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository43 other files it gives its agents.
- accessibilitySkill
- best-practicesSkill
- brainstormingSkill
- core-web-vitalsSkill
- cypress-e2eSkill
- docker-expertSkill
- drizzle-ormSkill
- elixir-developmentSkill
- eslint-configSkill
- express-apiSkill
- frontend-designSkill
- github-actionsSkill
- go-developmentSkill
- grafana-dashboardsSkill
- grpc-apiSkill
- helm-chartsSkill
- jest-testingSkill
- kubernetes-orchestrationSkill
- markdown-a11ySkill
- nothing-designSkill
- performanceSkill
- php-developmentSkill
- pinned-tagSkill
- postgresql-developmentSkill
- pr-creatorSkill
- prettier-formattingSkill
- pydanticSkill
- qwik-developmentSkill
- rails-developmentSkill
- ruby-developmentSkill
- rust-async-patternsSkill
- seoSkill
- skill-creatorSkill
- solidjs-developmentSkill
- sqlalchemySkill
- sql-optimization-patternsSkill
- swift-ios-developmentSkill
- tensorflow-mlSkill
- testing-librarySkill
- trpc-type-safetySkill
- webapp-testingSkill
- web-quality-auditSkill
- zig-developmentSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Tabs, Not Spaces: Every recipe line MUST start with a tab character.
- Very specific: line 24
Declare
.PHONY: Always mark non-file targets (e.g., clean, all, test, install) with .PHONY to avoid conflicts with files of the same name. - Very specific: line 26
Use
:=Over=When Possible: Prefer simple expansion (:=) for variables to avoid unexpected recursive expansion and improve performance. - Very specific: line 28
Automatic Variables: Use $@ (target), $< (first prerequisite), $^ (all prerequisites), $?
- Very specific: line 30
Use
$(wildcard ...)Not$(shell ls ...): Never shell out for file lists. - Very specific: line 32
Auto-Generate Dependencies: Use compiler flags like -MMD -MP to generate .d files rather than maintaining header dependencies manually.
- Very specific: line 34
Clean Target: Always provide a clean target and prefix destructive commands with - to ignore errors if files don't exist.
- Very specific: line 38
Avoid Recursive Make: Don't use $(MAKE) -C subdir unless absolutely necessary.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
- Creating a new
Makefilefor any project (C/C++, Go, Node.js, etc.) - Reviewing or refactoring existing makefiles for correctness and maintainability
- Debugging build failures related to make rules, prerequisites, or variables
- Setting up build automation with GNU Make (pattern rules, automatic dependencies, parallel builds)
- Ensuring portability across platforms or compliance with GNU Make conventions
Critical Patterns
- Tabs, Not Spaces: Every recipe line MUST start with a tab character. Spaces will cause a syntax error.
- Declare
.PHONY: Always mark non-file targets (e.g.,clean,all,test,install) with.PHONYto avoid conflicts with files of the same name. - Use
:=Over=When Possible: Prefer simple expansion (:=) for variables to avoid unexpected recursive expansion and improve performance. - Automatic Variables: Use
$@(target),$<(first prerequisite),$^(all prerequisites),$?(newer prerequisites), and$*(stem) in recipes to keep rules generic and reusable. - Use
$(wildcard ...)Not$(shell ls ...): Never shell out for file lists; use Make's built-in$(wildcard *.c)function instead. - Auto-Generate Dependencies: Use compiler flags like
-MMD -MPto generate.dfiles rather than maintaining header dependencies manually. - Clean Target: Always provide a
cleantarget and prefix destructive commands with-to ignore errors if files don't exist. - Variables First, Rules Second: Define all variables at the top, followed by the default goal, then build rules, then phony targets.
- Avoid Recursive Make: Don't use
$(MAKE) -C subdirunless absolutely necessary; prefer includes or non-recursive approaches.
File Structure
# -------------------------------------------------------
# Project: <name>
#
# Usage:
# make - Build the project
# make clean - Remove generated files
# make install - Install to $(PREFIX)
# make test - Run tests
#
# Variables:
# CC - C compiler (default: gcc)
# PREFIX - Installation prefix (default: /usr/local)
# -------------------------------------------------------
# --- Variables ---
CC ?= gcc
CFLAGS := -Wall -Wextra -O2
PREFIX ?= /usr/local
sources := $(wildcard src/*.c)
objects := $(sources:.c=.o)
deps := $(objects:.o=.d)
# --- Default Goal ---
all: program
# --- Build Rules ---
program: $(objects)
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
-include $(deps)
# --- Phony Targets ---
.PHONY: all clean install test
clean:
-rm -f program $(objects) $(deps)
install: program
install -d $(PREFIX)/bin
install -m 755 program $(PREFIX)/bin
test: program
./run-tests.shCode Examples
Variables and Substitution
# Simple expansion (evaluates immediately) - PREFERRED
CC := gcc
# Recursive expansion (evaluates when used)
CFLAGS = -Wall $(EXTRA_FLAGS)
# Conditional assignment (set default, allow override)
PREFIX ?= /usr/local
# Append to variable
CFLAGS += -g
# Always reference with $() - not bare $VAR
objects := $(sources:.c=.o)Pattern Rules and Implicit Rules
# Custom pattern rule for generic transformations
%.pdf: %.md
pandoc $< -o $@
# Compile with auto-dependency generation
%.o: %.c
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@Order-Only Prerequisites
# The directory is created before compiling but does NOT
# trigger recompilation when its timestamp changes.
obj/%.o: %.c | obj
$(CC) $(CFLAGS) -c $< -o $@
obj:
mkdir -p objConditional Directives
ifeq ($(OS),Windows_NT)
EXE_EXT := .exe
else
EXE_EXT :=
endif
program: main.o
$(CC) -o program$(EXE_EXT) main.oSplitting Long Lines
# Use backslash-newline to split for readability
sources := main.c \
utils.c \
parser.c \
handler.c
# In recipes, backslash-newline continues the shell command
install: program
install -d $(PREFIX)/bin && \
install -m 755 program $(PREFIX)/binIncluding Other Makefiles
# Include shared configuration
include config.mk
# Include optional local overrides (no error if missing)
-include local.mkError Handling and Validation
# Validate required tools
ifeq ($(shell which gcc 2>/dev/null),)
$(error gcc is not installed or not in PATH)
endif
# Validate required variables
ifndef VERSION
$(error VERSION is not defined. Usage: make VERSION=1.2.3)
endifSpecial Targets
# Delete targets if recipe fails (recommended)
.DELETE_ON_ERROR:
# Don't delete intermediate files
.SECONDARY:
# Preserve specific intermediate files
.PRECIOUS: %.oManaging Multiple Programs
programs := prog1 prog2 prog3
.PHONY: all clean
all: $(programs)
prog1: prog1.o common.o
$(CC) -o $@ $^
prog2: prog2.o common.o
$(CC) -o $@ $^
clean:
-rm -f $(programs) *.oAnti-Patterns to Avoid
| Anti-Pattern | Why It's Bad | Do Instead |
| Spaces instead of tabs in recipes | Syntax error, hard to debug | Use tab characters |
$(shell ls *.c) for file lists | Creates subprocess, fragile | $(wildcard *.c) |
Missing .PHONY declarations | clean won't run if a file named clean exists | .PHONY: clean |
| Hardcoded file lists | Maintenance burden, easy to forget new files | $(wildcard ...) or auto-discovery |
| Complex shell scripts in recipes | Hard to read and debug | Move to a separate .sh script |
Recursive make $(MAKE) -C subdir | Breaks dependency tracking across dirs | include or non-recursive make |
Using = everywhere | Unexpected recursive expansion, slower | Use := for simple values |
| Circular dependencies | Infinite loop, build failure | Restructure dependency graph |
Commands
# Dry run - see what would execute without running
make -n
# Force rebuild all targets
make -B
# Parallel build (use number of CPU cores)
make -j$(nproc)
# Print the database of rules and variables (debugging)
make -p
# Show which makefile and line number each rule comes from
make -d
# Override a variable from the command line
make CC=clang CFLAGS="-O3"Resources
- GNU Make Manual - The authoritative reference
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

