gomog/Makefile

111 lines
2.7 KiB
Makefile

.PHONY: build test clean run docker lint fmt
# 变量
BINARY_NAME=gomog
GO=go
GOFLAGS=-v
# 默认目标
all: build
# 构建
build:
@echo "Building $(BINARY_NAME)..."
$(GO) build $(GOFLAGS) -o bin/$(BINARY_NAME) ./cmd/server
# 开发模式构建(包含调试信息)
build-dev:
@echo "Building $(BINARY_NAME) in development mode..."
$(GO) build $(GOFLAGS) -gcflags="all=-N -l" -o bin/$(BINARY_NAME) ./cmd/server
# 交叉编译
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(GOFLAGS) -o bin/$(BINARY_NAME)-linux ./cmd/server
build-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build $(GOFLAGS) -o bin/$(BINARY_NAME)-darwin ./cmd/server
build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GO) build $(GOFLAGS) -o bin/$(BINARY_NAME).exe ./cmd/server
# 运行
run:
$(GO) run ./cmd/server -config config.yaml
# 测试
test:
@echo "Running tests..."
$(GO) test -v ./...
# 测试覆盖率
test-coverage:
@echo "Running tests with coverage..."
$(GO) test -v -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# 基准测试
bench:
@echo "Running benchmarks..."
$(GO) test -bench=. -benchmem ./internal/engine/...
# 代码格式化
fmt:
@echo "Formatting code..."
$(GO) fmt ./...
gofmt -w -s .
# 代码检查
lint:
@echo "Running linter..."
@if command -v golint >/dev/null 2>&1; then \
golint ./...; \
else \
echo "golint not installed, skipping..."; \
fi
# 清理
clean:
@echo "Cleaning..."
rm -rf bin/
rm -f coverage.out coverage.html
$(GO) clean
# 下载依赖
deps:
@echo "Downloading dependencies..."
$(GO) mod download
$(GO) mod tidy
# 初始化 Go 模块
init:
@echo "Initializing Go module..."
$(GO) mod init git.kingecg.top/kingecg/gomog
# Docker 相关
docker-build:
docker build -t gomog:latest .
docker-run:
docker run -p 8080:8080 -p 27017:27017 -v $(PWD)/data:/data gomog:latest
docker-clean:
docker rmi gomog:latest || true
# 帮助
help:
@echo "Gomog Makefile Commands:"
@echo " make build - Build the server"
@echo " make build-dev - Build in development mode"
@echo " make run - Run the server"
@echo " make test - Run tests"
@echo " make test-coverage - Run tests with coverage report"
@echo " make bench - Run benchmarks"
@echo " make fmt - Format code"
@echo " make lint - Run linter"
@echo " make clean - Clean build artifacts"
@echo " make deps - Download dependencies"
@echo " make docker-build - Build Docker image"
@echo " make docker-run - Run Docker container"
@echo " make help - Show this help message"