configure-makefile

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/configure:makefile

/configure:makefile

Check and configure project Makefile against project standards.
检查并配置项目Makefile,使其符合项目规范。

Context

背景

This command validates and creates Makefiles with standard targets for consistent development workflows across projects.
Required Makefile targets:
help
,
test
,
build
,
clean
,
start
,
stop
,
lint
本命令可验证并创建带有标准目标的Makefile,以确保跨项目的开发工作流一致性。
必填Makefile目标
help
,
test
,
build
,
clean
,
start
,
stop
,
lint

Workflow

工作流程

Phase 1: Detection

阶段1:检测

  1. Check for
    Makefile
    in project root
  2. If exists, analyze current targets and structure
  3. Detect project type (python, node, rust, go, generic)
  1. 检查项目根目录下是否存在
    Makefile
  2. 若存在,分析当前目标和结构
  3. 检测项目类型(Python、Node.js、Rust、Go、通用型)

Phase 2: Target Analysis

阶段2:目标分析

Required targets for all projects:
TargetPurpose
help
Display available targets (default goal)
test
Run test suite
build
Build project artifacts
clean
Remove temporary files and build artifacts
lint
Run linters
Additional targets (context-dependent):
TargetWhen Required
start
If project has runnable service
stop
If project has background service
format
If project uses auto-formatters
所有项目的必填目标:
Target用途
help
显示可用目标(默认目标)
test
运行测试套件
build
构建项目产物
clean
删除临时文件和构建产物
lint
运行代码检查工具
附加目标(视场景而定):
Target适用场景
start
若项目包含可运行服务
stop
若项目包含后台服务
format
若项目使用自动格式化工具

Phase 3: Compliance Checks

阶段3:合规性检查

CheckStandardSeverity
File existsMakefile presentFAIL if missing
Default goal
.DEFAULT_GOAL := help
WARN if missing
PHONY declarationsAll targets marked
.PHONY
WARN if missing
Colored outputColor variables definedINFO
Help targetAuto-generated from commentsWARN if missing
Language-specificCommands match project typeFAIL if mismatched
检查项标准严重程度
文件存在存在Makefile缺失则失败
默认目标配置
.DEFAULT_GOAL := help
缺失则警告
PHONY声明所有目标均标记为
.PHONY
缺失则警告
彩色输出定义颜色变量提示信息
Help目标从注释自动生成缺失则警告
语言适配命令与项目类型匹配不匹配则失败

Phase 4: Report Generation

阶段4:生成报告

Makefile Compliance Report
==============================
Project Type: python (detected)
Makefile: Found

Target Status:
  help    ✅ PASS
  test    ✅ PASS (uv run pytest)
  build   ✅ PASS (docker build)
  clean   ✅ PASS
  lint    ✅ PASS (uv run ruff check)
  format  ✅ PASS (uv run ruff format)
  start   ❌ FAIL (missing)
  stop    ❌ FAIL (missing)

Makefile Checks:
  Default goal        ✅ PASS (.DEFAULT_GOAL := help)
  PHONY declarations  ✅ PASS
  Colored output      ✅ PASS
  Help target         ✅ PASS (auto-generated)

Missing Targets: start, stop
Issues: 2 found
Makefile合规性报告
==============================
项目类型:python(已检测)
Makefile:已找到

目标状态:
  help    ✅ 通过
  test    ✅ 通过(uv run pytest)
  build   ✅ 通过(docker build)
  clean   ✅ 通过
  lint    ✅ 通过(uv run ruff check)
  format  ✅ 通过(uv run ruff format)
  start   ❌ 失败(缺失)
  stop    ❌ 失败(缺失)

Makefile检查:
  默认目标        ✅ 通过(.DEFAULT_GOAL := help)
  PHONY声明       ✅ 通过
  彩色输出        ✅ 通过
  Help目标        ✅ 通过(自动生成)

缺失目标:start、stop
问题:发现2处

Phase 5: Configuration (If Requested)

阶段5:配置(若用户要求)

If
--fix
flag or user confirms:
  1. Missing Makefile: Create from standard template based on project type
  2. Missing targets: Add targets with appropriate commands
  3. Missing defaults: Add
    .DEFAULT_GOAL
    ,
    .PHONY
    , colors
  4. Missing help: Add auto-generated help target
若使用
--fix
参数或用户确认:
  1. 缺失Makefile:根据项目类型从标准模板创建
  2. 缺失目标:添加带有合适命令的目标
  3. 缺失默认配置:添加
    .DEFAULT_GOAL
    .PHONY
    和颜色变量
  4. 缺失Help目标:添加自动生成的Help目标

Phase 6: Standards Tracking

阶段6:规范跟踪

Update
.project-standards.yaml
:
yaml
components:
  makefile: "2025.1"
更新
.project-standards.yaml
文件:
yaml
components:
  makefile: "2025.1"

Standard Makefile Template

标准Makefile模板

Universal Structure

通用结构

makefile
undefined
makefile
undefined

Makefile for {{PROJECT_NAME}}

Makefile for {{PROJECT_NAME}}

Provides common commands for development, testing, and building.

提供开发、测试和构建相关的通用命令。

Colors for console output

控制台输出颜色

BLUE := \033[0;34m GREEN := \033[0;32m YELLOW := \033[1;33m RED := \033[0;31m NC := \033[0m # No Color
.DEFAULT_GOAL := help .PHONY: help test build clean lint format start stop
##@ Help
help: ## Display this help message @awk 'BEGIN {FS = ":.##"; printf "\n$(BLUE)Usage:$(NC)\n make $(GREEN)<target>$(NC)\n"}
/^[a-zA-Z_0-9-]+:.
?##/ { printf " $(BLUE)%-15s$(NC) %s\n", $$1, $$2 }
/^##@/ { printf "\n$(YELLOW)%s$(NC)\n", substr($$0, 5) } ' $(MAKEFILE_LIST) @echo ""
##@ Development
lint: ## Run linters @echo "$(BLUE)Running linters...$(NC)" {{LINT_COMMAND}}
format: ## Format code @echo "$(BLUE)Formatting code...$(NC)" {{FORMAT_COMMAND}}
test: ## Run tests @echo "$(BLUE)Running tests...$(NC)" {{TEST_COMMAND}}
##@ Build & Deploy
build: ## Build project @echo "$(BLUE)Building project...$(NC)" {{BUILD_COMMAND}}
clean: ## Clean up temporary files and build artifacts @echo "$(BLUE)Cleaning up...$(NC)" {{CLEAN_COMMAND}}
start: ## Start service @echo "$(BLUE)Starting service...$(NC)" {{START_COMMAND}}
stop: ## Stop service @echo "$(BLUE)Stopping service...$(NC)" {{STOP_COMMAND}}
undefined
BLUE := \033[0;34m GREEN := \033[0;32m YELLOW := \033[1;33m RED := \033[0;31m NC := \033[0m # 无颜色
.DEFAULT_GOAL := help .PHONY: help test build clean lint format start stop
##@ 帮助
help: ## 显示此帮助信息 @awk 'BEGIN {FS = ":.##"; printf "\n$(BLUE)使用方法:$(NC)\n make $(GREEN)<目标>$(NC)\n"}
/^[a-zA-Z_0-9-]+:.
?##/ { printf " $(BLUE)%-15s$(NC) %s\n", $$1, $$2 }
/^##@/ { printf "\n$(YELLOW)%s$(NC)\n", substr($$0, 5) } ' $(MAKEFILE_LIST) @echo ""
##@ 开发
lint: ## 运行代码检查工具 @echo "$(BLUE)正在运行代码检查工具...$(NC)" {{LINT_COMMAND}}
format: ## 格式化代码 @echo "$(BLUE)正在格式化代码...$(NC)" {{FORMAT_COMMAND}}
test: ## 运行测试 @echo "$(BLUE)正在运行测试...$(NC)" {{TEST_COMMAND}}
##@ 构建与部署
build: ## 构建项目 @echo "$(BLUE)正在构建项目...$(NC)" {{BUILD_COMMAND}}
clean: ## 清理临时文件和构建产物 @echo "$(BLUE)正在清理...$(NC)" {{CLEAN_COMMAND}}
start: ## 启动服务 @echo "$(BLUE)正在启动服务...$(NC)" {{START_COMMAND}}
stop: ## 停止服务 @echo "$(BLUE)正在停止服务...$(NC)" {{STOP_COMMAND}}
undefined

Language-Specific Commands

语言专属命令

Python (uv-based):
makefile
lint:
	@uv run ruff check .

format:
	@uv run ruff format .

test:
	@uv run pytest

build:
	@docker build -t {{PROJECT_NAME}} .

clean:
	@find . -type f -name "*.pyc" -delete
	@find . -type d -name "__pycache__" -delete
	@rm -rf .pytest_cache .ruff_cache dist/ build/
Node.js:
makefile
lint:
	@npm run lint

format:
	@npm run format

test:
	@npm test

build:
	@npm run build
	@docker build -t {{PROJECT_NAME}} .

clean:
	@rm -rf node_modules/ dist/ .next/ .turbo/
Rust:
makefile
lint:
	@cargo clippy -- -D warnings

format:
	@cargo fmt

test:
	@cargo nextest run

build:
	@cargo build --release
	@docker build -t {{PROJECT_NAME}} .

clean:
	@cargo clean
Go:
makefile
lint:
	@golangci-lint run

format:
	@gofmt -s -w .

test:
	@go test ./...

build:
	@go build -o bin/{{PROJECT_NAME}}
	@docker build -t {{PROJECT_NAME}} .

clean:
	@rm -rf bin/ dist/
	@go clean
Python(基于uv):
makefile
lint:
	@uv run ruff check .

format:
	@uv run ruff format .

test:
	@uv run pytest

build:
	@docker build -t {{PROJECT_NAME}} .

clean:
	@find . -type f -name "*.pyc" -delete
	@find . -type d -name "__pycache__" -delete
	@rm -rf .pytest_cache .ruff_cache dist/ build/
Node.js:
makefile
lint:
	@npm run lint

format:
	@npm run format

test:
	@npm test

build:
	@npm run build
	@docker build -t {{PROJECT_NAME}} .

clean:
	@rm -rf node_modules/ dist/ .next/ .turbo/
Rust:
makefile
lint:
	@cargo clippy -- -D warnings

format:
	@cargo fmt

test:
	@cargo nextest run

build:
	@cargo build --release
	@docker build -t {{PROJECT_NAME}} .

clean:
	@cargo clean
Go:
makefile
lint:
	@golangci-lint run

format:
	@gofmt -s -w .

test:
	@go test ./...

build:
	@go build -o bin/{{PROJECT_NAME}}
	@docker build -t {{PROJECT_NAME}} .

clean:
	@rm -rf bin/ dist/
	@go clean

Detection Logic

检测逻辑

Project type detection (in order):
  1. Python:
    pyproject.toml
    or
    requirements.txt
    present
  2. Node:
    package.json
    present
  3. Rust:
    Cargo.toml
    present
  4. Go:
    go.mod
    present
  5. Generic: None of the above
Service detection (start/stop needed):
  • Has
    docker-compose.yml
    → Docker Compose service
  • Has
    Dockerfile
    + HTTP server code → Container service
  • Has
    src/server.*
    or
    src/main.*
    → Application service
项目类型检测顺序:
  1. Python:存在
    pyproject.toml
    requirements.txt
    文件
  2. Node.js:存在
    package.json
    文件
  3. Rust:存在
    Cargo.toml
    文件
  4. Go:存在
    go.mod
    文件
  5. 通用型:以上均不满足
服务检测(是否需要start/stop目标):
  • 存在
    docker-compose.yml
    → Docker Compose服务
  • 存在
    Dockerfile
    且包含HTTP服务器代码 → 容器化服务
  • 存在
    src/server.*
    src/main.*
    文件 → 应用服务

Flags

参数

FlagDescription
--check-only
Report status without offering fixes
--fix
Apply fixes automatically
参数说明
--check-only
仅报告状态,不提供修复选项
--fix
自动应用修复

Examples

示例

bash
undefined
bash
undefined

Check current Makefile compliance

检查当前Makefile的合规性

/configure:makefile --check-only
/configure:makefile --check-only

Create/update Makefile for Python project

为Python项目创建/更新Makefile

/configure:makefile --fix
/configure:makefile --fix

Check compliance and prompt for fixes

检查合规性并提示是否修复

/configure:makefile
undefined
/configure:makefile
undefined

See Also

另请参阅

  • /configure:all
    - Run all compliance checks
  • /configure:workflows
    - GitHub Actions workflows
  • /configure:dockerfile
    - Docker configuration
  • /configure:all
    - 运行所有合规性检查
  • /configure:workflows
    - GitHub Actions工作流
  • /configure:dockerfile
    - Docker配置