Files
AUTO-MAS-test/Go_Updater/Makefile
AoXuan 228e66315c feat(Go_Updater): 添加全新 Go 语言实现的自动更新器
- 新增多个源文件和目录,包括 app.rc、assets、build 脚本等
- 实现了与 MirrorChyan API 交互的客户端逻辑
- 添加了版本检查、更新检测和下载 URL 生成等功能
- 嵌入了配置模板和资源文件系统
- 提供了完整的构建和发布流程
2025-07-20 16:30:14 +08:00

116 lines
3.2 KiB
Makefile

# AUTO_MAA_Go_Updater Makefile
# Build variables
VERSION ?= 1.0.0
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
OUTPUT_NAME := AUTO_MAA_Go_Updater
BUILD_DIR := build
DIST_DIR := dist
# Go build flags
LDFLAGS := -s -w -X lightweight-updater/version.Version=$(VERSION) -X lightweight-updater/version.BuildTime=$(BUILD_TIME) -X lightweight-updater/version.GitCommit=$(GIT_COMMIT)
# Default target
.PHONY: all
all: clean build
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@mkdir -p $(BUILD_DIR) $(DIST_DIR)
# Build for Windows 64-bit
.PHONY: build
build: clean
@echo "========================================="
@echo "Building AUTO_MAA_Go_Updater"
@echo "========================================="
@echo "Version: $(VERSION)"
@echo "Build Time: $(BUILD_TIME)"
@echo "Git Commit: $(GIT_COMMIT)"
@echo "Target: Windows 64-bit"
@echo ""
@echo "Building application..."
@GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(OUTPUT_NAME).exe .
@echo "Build completed successfully!"
@echo ""
@echo "Build Results:"
@ls -lh $(BUILD_DIR)/$(OUTPUT_NAME).exe
@cp $(BUILD_DIR)/$(OUTPUT_NAME).exe $(DIST_DIR)/$(OUTPUT_NAME).exe
@echo "Copied to: $(DIST_DIR)/$(OUTPUT_NAME).exe"
# Build with UPX compression
.PHONY: build-compressed
build-compressed: build
@echo ""
@echo "Compressing with UPX..."
@if command -v upx >/dev/null 2>&1; then \
upx --best $(BUILD_DIR)/$(OUTPUT_NAME).exe; \
echo "Compression completed!"; \
ls -lh $(BUILD_DIR)/$(OUTPUT_NAME).exe; \
cp $(BUILD_DIR)/$(OUTPUT_NAME).exe $(DIST_DIR)/$(OUTPUT_NAME).exe; \
else \
echo "UPX not found. Skipping compression."; \
fi
# Run tests
.PHONY: test
test:
@echo "Running tests..."
@go test -v ./...
# Run with version flag
.PHONY: version
version: build
@echo ""
@echo "Testing version information:"
@$(BUILD_DIR)/$(OUTPUT_NAME).exe -version
# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
@go mod tidy
@go mod download
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
@go fmt ./...
# Lint code
.PHONY: lint
lint:
@echo "Linting code..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found. Install it with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Development build (faster, no optimizations)
.PHONY: dev
dev:
@echo "Building development version..."
@go build -o $(BUILD_DIR)/$(OUTPUT_NAME)-dev.exe .
@echo "Development build completed: $(BUILD_DIR)/$(OUTPUT_NAME)-dev.exe"
# Help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean and build (default)"
@echo " build - Build for Windows 64-bit"
@echo " build-compressed - Build and compress with UPX"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " version - Build and show version"
@echo " deps - Install dependencies"
@echo " fmt - Format code"
@echo " lint - Lint code"
@echo " dev - Development build"
@echo " help - Show this help"