Overview
Makefile template generation and validation tool. Supports two modes:
- Generate — Generate a standardized Makefile template based on the project type
- Validate — Check whether an existing Makefile conforms to the specification
Core principles:Comments are documentation,make is the entry point.
Mode Selection
用户说 "创建/生成 Makefile" → Generate 模式
用户说 "validate/检查/lint Makefile" → Validate 模式
用户未明确 → 询问选择
Generate mode
Template Selection
Select a template based on the project type. If the user does not specify one, auto-detect by the following means:
- Check
go.mod→ Go template - Check
package.json→ Node template - Check
pyproject.tomlorsetup.py→ Python template - Check
docker-compose.yml→ Docker template - Check
pnpm-workspace.yamlorlerna.json→ Monorepo template - Cannot detect → ask the user to choose
Available Templates
| Template | File | Applicable scenario |
|---|---|---|
| Go | assets/Makefile.go.tmpl |
Go project, includes build/test/lint/docker |
| Node | assets/Makefile.node.tmpl |
Node.js/TypeScript, auto-detects the package manager |
| Python | assets/Makefile.python.tmpl |
Python project, includes venv/pytest/ruff |
| Docker | assets/Makefile.docker.tmpl |
Docker Compose project, includes up/down/logs |
| Monorepo | assets/Makefile.monorepo.tmpl |
Multi-package repository, supports filter for single-package operations |
Generate Workflow
- Detect or ask for the project type
- Read the corresponding template
assets/Makefile.<type>.tmpl - Adjust variables according to the project's actual situation (APP_NAME, ports, etc.)
- Write to
Makefile - Prompt the user to run
maketo verify the help output
Convention
## 描述 is written on the same line as the target,make(no arguments) automatically outputs all targets and descriptions.
.DEFAULT_GOAL := help
help: ## 显示帮助信息
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | sed 's/:.*##/:/' | awk -F: '{gsub(/^ /, "", $$2); printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## 编译项目
go build ./...
Rules
.DEFAULT_GOAL := help— no argumentsmakeis equivalent tomake help.PHONYDeclare all non-file targets##The comment must be on the same line as the target, format:target: deps ## 描述- Use Chinese or English for descriptions, keep it consistent within the project
helpDo not change the grep/awk pipeline at will- Targets with dependencies:
setup-db: create-network ## 启动数据库
Validate mode
Trigger
用户说: "validate Makefile" / "检查 Makefile" / "lint Makefile"
Workflow
- Read the target Makefile (default is the current directory, or a user-specified path)
- Check item by item according to
references/validation-rules.mdrules - Output a formatted report
Validation Rules Summary
ERROR (must be fixed):
- E01:
.DEFAULT_GOAL := helpexists - E02:
helptarget exists - E03:
helpuses##parsing - E04: every non-file target has a
##comment - E05:
##comment is on the same line - E06:
##has a space after - E07:
.PHONYdeclaration is complete - E08: indentation uses Tab
WARNING (recommended to fix):
- W01: explicitly declare
SHELL - W02:
cleantarget exists - W03: variables use
:= - W04: long commands are reasonably wrapped
- W05:
helppipeline includes ANSI highlighting - W06: targets grouped by function
INFO (best practices):
- I01: common target coverage (build/test/lint/clean)
- I02: VERSION obtained from git
- I03: Docker target naming is consistent
- I04: avoid hardcoded paths
Output Format
Makefile Validation Report
══════════════════════════
ERROR (2)
E01 .DEFAULT_GOAL := help 未设置
E04 target 'deploy' 缺少 ## 注释
WARNING (1)
W01 未声明 SHELL 变量
INFO (1)
I01 建议添加 lint target
Result: FAIL (2 errors, 1 warning, 1 info)
Validate Completion
After Validate completes:
- Display the report
- If there are ERRORs, ask the user whether to auto-fix
- After auto-fixing, re-validate to confirm it passes
Common Mistakes
| Error | Correct |
|---|---|
## Comment on a separate line above the target |
## Written on the same line as the target |
Missing .DEFAULT_GOAL := help |
must be set |
## no space after |
## 描述,## there must be a space after |
help pipeline uses awk -F: split into 3 fields |
use sed 's/:.*##/:/' normalize first |
| recipe indented with spaces | must use Tab |
.PHONY missing target |
all non-file targets must be declared |