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: , , , , , ,
helptestbuildcleanstartstoplint本命令可验证并创建带有标准目标的Makefile,以确保跨项目的开发工作流一致性。
必填Makefile目标:, , , , , ,
helptestbuildcleanstartstoplintWorkflow
工作流程
Phase 1: Detection
阶段1:检测
- Check for in project root
Makefile - If exists, analyze current targets and structure
- Detect project type (python, node, rust, go, generic)
- 检查项目根目录下是否存在
Makefile - 若存在,分析当前目标和结构
- 检测项目类型(Python、Node.js、Rust、Go、通用型)
Phase 2: Target Analysis
阶段2:目标分析
Required targets for all projects:
| Target | Purpose |
|---|---|
| Display available targets (default goal) |
| Run test suite |
| Build project artifacts |
| Remove temporary files and build artifacts |
| Run linters |
Additional targets (context-dependent):
| Target | When Required |
|---|---|
| If project has runnable service |
| If project has background service |
| If project uses auto-formatters |
所有项目的必填目标:
| Target | 用途 |
|---|---|
| 显示可用目标(默认目标) |
| 运行测试套件 |
| 构建项目产物 |
| 删除临时文件和构建产物 |
| 运行代码检查工具 |
附加目标(视场景而定):
| Target | 适用场景 |
|---|---|
| 若项目包含可运行服务 |
| 若项目包含后台服务 |
| 若项目使用自动格式化工具 |
Phase 3: Compliance Checks
阶段3:合规性检查
| Check | Standard | Severity |
|---|---|---|
| File exists | Makefile present | FAIL if missing |
| Default goal | | WARN if missing |
| PHONY declarations | All targets marked | WARN if missing |
| Colored output | Color variables defined | INFO |
| Help target | Auto-generated from comments | WARN if missing |
| Language-specific | Commands match project type | FAIL if mismatched |
| 检查项 | 标准 | 严重程度 |
|---|---|---|
| 文件存在 | 存在Makefile | 缺失则失败 |
| 默认目标 | 配置 | 缺失则警告 |
| 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 foundMakefile合规性报告
==============================
项目类型: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 flag or user confirms:
--fix- Missing Makefile: Create from standard template based on project type
- Missing targets: Add targets with appropriate commands
- Missing defaults: Add ,
.DEFAULT_GOAL, colors.PHONY - Missing help: Add auto-generated help target
若使用参数或用户确认:
--fix- 缺失Makefile:根据项目类型从标准模板创建
- 缺失目标:添加带有合适命令的目标
- 缺失默认配置:添加、
.DEFAULT_GOAL和颜色变量.PHONY - 缺失Help目标:添加自动生成的Help目标
Phase 6: Standards Tracking
阶段6:规范跟踪
Update :
.project-standards.yamlyaml
components:
makefile: "2025.1"更新文件:
.project-standards.yamlyaml
components:
makefile: "2025.1"Standard Makefile Template
标准Makefile模板
Universal Structure
通用结构
makefile
undefinedmakefile
undefinedMakefile 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 ""
/^[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}}
undefinedBLUE := \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 ""
/^[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}}
undefinedLanguage-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 cleanGo:
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 cleanPython(基于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 cleanGo:
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 cleanDetection Logic
检测逻辑
Project type detection (in order):
- Python: or
pyproject.tomlpresentrequirements.txt - Node: present
package.json - Rust: present
Cargo.toml - Go: present
go.mod - Generic: None of the above
Service detection (start/stop needed):
- Has → Docker Compose service
docker-compose.yml - Has + HTTP server code → Container service
Dockerfile - Has or
src/server.*→ Application servicesrc/main.*
项目类型检测顺序:
- Python:存在或
pyproject.toml文件requirements.txt - Node.js:存在文件
package.json - Rust:存在文件
Cargo.toml - Go:存在文件
go.mod - 通用型:以上均不满足
服务检测(是否需要start/stop目标):
- 存在→ Docker Compose服务
docker-compose.yml - 存在且包含HTTP服务器代码 → 容器化服务
Dockerfile - 存在或
src/server.*文件 → 应用服务src/main.*
Flags
参数
| Flag | Description |
|---|---|
| Report status without offering fixes |
| Apply fixes automatically |
| 参数 | 说明 |
|---|---|
| 仅报告状态,不提供修复选项 |
| 自动应用修复 |
Examples
示例
bash
undefinedbash
undefinedCheck 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
undefinedSee Also
另请参阅
- - Run all compliance checks
/configure:all - - GitHub Actions workflows
/configure:workflows - - Docker configuration
/configure:dockerfile
- - 运行所有合规性检查
/configure:all - - GitHub Actions工作流
/configure:workflows - - Docker配置
/configure:dockerfile