feat(config): 添加 JSON/TOML 配置读取与 YAML/JSON/TOML 导出功能, 优化部分内部代码结构, 更新 Makefile:添加 Zig 外链检测、可选 UPX 压缩、构建流程优化
This commit is contained in:
65
Makefile
65
Makefile
@@ -1,23 +1,64 @@
|
||||
APP_NAME = netctl
|
||||
SRC = .
|
||||
OUTPUT = ./bin/$(APP_NAME).exe
|
||||
GO = go
|
||||
APP_NAME := netctl
|
||||
SRC := .
|
||||
OUTPUT := ./bin/$(APP_NAME).exe
|
||||
GO := go
|
||||
|
||||
# 获取 Git commit
|
||||
# Version info
|
||||
VERSION := 1.0.1
|
||||
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
|
||||
# 获取当前时间 UTC
|
||||
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
.PHONY: build run clean
|
||||
# Detect tools
|
||||
DETECTED_ZIG := $(shell command -v zig 2>/dev/null)
|
||||
DETECTED_UPX := $(shell command -v upx 2>/dev/null)
|
||||
|
||||
# User config
|
||||
ZIG ?= 1 # auto enable zig linker if exists
|
||||
BRUTE ?= 0 # UPX brute mode disabled by default
|
||||
|
||||
.PHONY: all build run clean
|
||||
|
||||
all: build
|
||||
|
||||
# 编译命令
|
||||
build:
|
||||
$(GO) build -ldflags "-X 'netcli/cmd.Version=1.0.0' -X 'netcli/cmd.Commit=$(GIT_COMMIT)' -X 'netcli/cmd.BuildTime=$(BUILD_TIME)'" -o $(OUTPUT) $(SRC)
|
||||
@mkdir -p ./bin
|
||||
|
||||
@if [ "$(ZIG)" = "1" ] && [ -n "$(DETECTED_ZIG)" ]; then \
|
||||
echo "Zig detected -> Using Zig as Go external linker"; \
|
||||
export CGO_ENABLED=0; \
|
||||
export CC="zig cc"; \
|
||||
export CXX="zig c++"; \
|
||||
$(GO) build -trimpath -ldflags "-s -w \
|
||||
-X 'netcli/cmd.Version=$(VERSION)' \
|
||||
-X 'netcli/cmd.Commit=$(GIT_COMMIT)' \
|
||||
-X 'netcli/cmd.BuildTime=$(BUILD_TIME)'" \
|
||||
-o $(OUTPUT) $(SRC); \
|
||||
else \
|
||||
echo "Zig not used → Using Go native linker"; \
|
||||
$(GO) build -trimpath -ldflags "-s -w \
|
||||
-X 'netcli/cmd.Version=$(VERSION)' \
|
||||
-X 'netcli/cmd.Commit=$(GIT_COMMIT)' \
|
||||
-X 'netcli/cmd.BuildTime=$(BUILD_TIME)'" \
|
||||
-o $(OUTPUT) $(SRC); \
|
||||
fi
|
||||
|
||||
@if [ -n "$(DETECTED_UPX)" ]; then \
|
||||
if [ "$(BRUTE)" = "1" ]; then \
|
||||
echo "UPX brute mode enabled (--ultra-brute)..."; \
|
||||
upx --ultra-brute $(OUTPUT); \
|
||||
else \
|
||||
echo "UPX detected → Applying normal compression (--best --lzma)..."; \
|
||||
upx --best --lzma $(OUTPUT); \
|
||||
fi \
|
||||
else \
|
||||
echo "UPX not found → Skipping compression"; \
|
||||
fi
|
||||
|
||||
# 直接运行
|
||||
run:
|
||||
$(GO) run -ldflags "-X 'netcli/cmd.Version=1.0.0' -X 'netcli/cmd.Commit=$(GIT_COMMIT)' -X 'netcli/cmd.BuildTime=$(BUILD_TIME)'" $(SRC)
|
||||
$(GO) run -ldflags "-s -w \
|
||||
-X 'netcli/cmd.Version=$(VERSION)' \
|
||||
-X 'netcli/cmd.Commit=$(GIT_COMMIT)' \
|
||||
-X 'netcli/cmd.BuildTime=$(BUILD_TIME)'" $(SRC)
|
||||
|
||||
# 清理编译文件
|
||||
clean:
|
||||
rm -f $(OUTPUT)
|
||||
|
||||
Reference in New Issue
Block a user