跳到正文
cccskills
免费在 GitHub 公开

make

Use when writing or debugging Makefiles, understanding pattern rules and automatic dependency generation, managing CFLAGS/LDFLAGS, or diagnosing incremental build, phony targets, or recursive make.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(3)

  • SKILL.md5.7 KB
  • agents/openai.yaml255 B
  • references/cheatsheet.md3.6 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

GNU Make

Idiomatic Makefile patterns for C/C++ projects: phony targets, pattern rules, automatic dependency generation, and incremental-build hygiene. Grounded against GNU Make 4.4.

Contract

FieldBound contract
TriggerThe task writes or debugs a Makefile, sets up pattern rules or automatic dependency generation, manages CFLAGS/LDFLAGS, converts ad-hoc compile commands into a Makefile, or diagnoses incremental build failures.
AuthorityReversible local: writes only Makefile/*.mk files and local build outputs; rollback is version control plus make clean. No remote mutation.
Side effectmake runs the compiler and writes objects and binaries into the tree or build directory.
Donemake builds the target incrementally (a second run reports nothing to do) and make clean removes the outputs.

Inputs

  • Source layout (required): where .c/.cpp files and headers live.
  • Compiler and flags (required if not inferrable): CC, CFLAGS, LDFLAGS, LDLIBS.
  • Build variants (optional): debug/release split, install prefix.

Procedure

  1. Write the minimal correct Makefile. Recipes start with a tab, not spaces. Done when: make builds and make clean removes outputs.
CC      := gcc
CFLAGS  := -std=c23 -Wall -Wextra -g -O2
LDFLAGS :=
LDLIBS  :=

SRCS    := $(wildcard src/*.c)
OBJS    := $(SRCS:src/%.c=build/%.o)
TARGET  := build/prog

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

build/%.o: src/%.c | build
	$(CC) $(CFLAGS) -c -o $@ $<

build:
	mkdir -p build

clean:
	rm -rf build

Automatic variables: $@ is the target, $< the first prerequisite, $^ all prerequisites deduplicated, $* the pattern stem, $(@D) the target's directory part.

  1. Add automatic dependency generation. Without it, editing a header rebuilds nothing. -MMD writes a .d file per object; -MP adds phony targets for headers so deleting one does not break the build. Done when: touching a header rebuilds exactly its dependents.
DEPFLAGS = -MMD -MP
DEPS    := $(OBJS:.o=.d)

build/%.o: src/%.c | build
	$(CC) $(CFLAGS) $(DEPFLAGS) -MF $(@:.o=.d) -c -o $@ $<

-include $(DEPS)   # leading - ignores missing .d files on first build
  1. Use pattern rules for repeated transforms. Done when: one rule covers each source-to-output shape.
%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

%.s: %.c
	$(CC) $(CFLAGS) -S -o $@ $<
  1. Add build variants and quiet output. Done when: make BUILD=debug switches flags and make V=1 shows full commands.
BUILD ?= release
ifeq ($(BUILD),debug)
  CFLAGS += -g -Og -DDEBUG
else
  CFLAGS += -O2 -DNDEBUG
endif

Q := $(if $(V),,@)
build/%.o: src/%.c | build
	@echo "  CC  $<"
	$(Q)$(CC) $(CFLAGS) -c -o $@ $<
  1. Add an install target with DESTDIR and PREFIX. Done when: make install DESTDIR=/tmp/stage stages the tree.
PREFIX ?= /usr/local

install: $(TARGET)
	install -d $(DESTDIR)$(PREFIX)/bin
	install -m 0755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/
  1. Structure multi-directory projects with included .mk files, not recursive make. Recursive make fragments the dependency graph and breaks parallelism. Done when: one top-level Makefile sees every prerequisite.
# Makefile
include lib/module.mk
include src/app.mk
# lib/module.mk
LIB_SRCS := $(wildcard lib/*.c)
LIB_OBJS := $(LIB_SRCS:lib/%.c=build/lib_%.o)
OBJS     += $(LIB_OBJS)

build/lib_%.o: lib/%.c
	$(CC) $(CFLAGS) -c -o $@ $<
  1. Diagnose failures against this table. Done when: the error maps to a cause and a fix.
ErrorCauseFix
No rule to make target 'foo.o'Missing source or ruleCheck the source path and pattern rule
Nothing to be done for 'all'Targets up to dateTouch a source or run make clean
Circular dependency droppedTarget depends on itselfTrace the prerequisite chain
missing separatorSpaces where a tab belongsRecipes need a literal tab
multiple target patternsBad pattern rule syntaxCheck % placement
Rebuilds everythingWrong timestamps or missing .PHONYCheck date; mark all and clean phony
Header edit rebuilds nothingNo dependency trackingAdd -MMD -MP and -include $(DEPS)

Useful flags: make -j"$(nproc)" parallel, make -O synchronizes output, make -n dry run, make -B force rebuild, make -k keep going, make -p print the rule database, make --warn-undefined-variables catch typos.

For the full variable, function, and special-target reference see references/cheatsheet.md.

Failure and recovery

  • make does nothing after a header edit: dependency files are missing; add -MMD -MP and -include $(DEPS).
  • Parallel build races: a missing order-only prerequisite or an undeclared generated header; declare the real dependency, never serialize to hide it.
  • missing separator: convert the recipe's leading spaces to a tab.
  • Variable expands empty: = defers expansion to use time, := expands at definition; pick := unless late expansion is the point. ::= is the POSIX immediate form, available in GNU Make 4.4 and later.
  • Recursive make is already present: include the child .mk files from the top Makefile instead of $(MAKE) -C.

Output

A Makefile that builds incrementally, tracks header dependencies, supports clean and install, and survives make -j. For debugging tasks, the diagnosed cause and the minimal fix.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Use when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Not for the Rust FFI binding layer: use rust-ffi.

中文简介正在准备中。当前显示原文说明。

OutlineDriven/odin-claude-plugin372026年9月29日 更新

Use when configuring ADC sampling time, DMA-driven ADC, calibration, or DAC channel setup on bare-metal MCUs. Not for the DMA stream itself: use dma-baremetal.

中文简介正在准备中。当前显示原文说明。

OutlineDriven/odin-claude-plugin372026年9月29日 更新

af-xdp

免费

Use when creating AF_XDP sockets, configuring UMEM and XSK rings, writing an XDP redirect program, or choosing copy versus zero-copy mode. Not for full kernel bypass: use dpdk.

中文简介正在准备中。当前显示原文说明。

OutlineDriven/odin-claude-plugin372026年9月29日 更新

Use when a completed session needs an agent-environment retrospective. Not for an engineering retrospective from telemetry: use engineering-retrospective.

中文简介正在准备中。当前显示原文说明。

OutlineDriven/odin-claude-plugin372026年9月29日 更新

Use when a redacted, trimmed agent transcript must be appended to a GitHub PR or issue body, with human approval and preview. Not for automated or model-initiated insertion.

中文简介正在准备中。当前显示原文说明。

OutlineDriven/odin-claude-plugin372026年9月29日 更新

agents-md

免费

Use when a repo needs agent setup, AGENTS.md added or made lean, CLAUDE.md audited, or agent instructions scored or pruned. Not for remote, credential, publish, deploy, or irreversible changes.

中文简介正在准备中。当前显示原文说明。

OutlineDriven/odin-claude-plugin372026年9月29日 更新

查看 OutlineDriven 的全部技能

报告此技能的问题