Files
lmvpn_client/Makefile
T
kevin 65a5932eba feat: 支持 Windows x86_64 平台编译
- 新增 WinTun TUN 设备实现(tun_windows.go),无需安装驱动,
  wintun.dll 嵌入 exe 运行时自动释放
- 新增 Windows 路由管理(route_windows.go),使用 route/netsh 命令
- 新增 Windows 路径(paths_windows.go),使用 %APPDATA%/%LOCALAPPDATA%
- 拆分 daemon 启动逻辑:launch_unix.go(Setsid) / launch_windows.go
  (CREATE_NEW_PROCESS_GROUP),公共代码提取到 launch_common.go
- 拆分提权逻辑:elevation_darwin.go(osascript) / elevation_windows.go
  (ShellExecute UAC) / elevation_other.go(pkexec)
- IPCSocketPath 按平台分散,Windows 用 %TEMP%\lmvpn.sock
- daemon 二进制名用编译时常量(daemonBinaryName),按平台选定 .exe 后缀
- Makefile 新增 build-windows 目标
- 重新标记 !darwin 文件为 !darwin && !windows
2026-07-07 16:50:42 +08:00

92 lines
3.2 KiB
Makefile

# LMVPN Client — Makefile
APP_NAME = LMVPN
BUNDLE_ID = com.lmvpn.client
GUI_BIN = lmvpn
DAEMON_BIN = lmvpnd
BUILD_DIR = build
APP_BUNDLE = $(APP_NAME).app
GO = go
CGO_ENABLED = 1
GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
VERSION = 0.3.4-$(GIT_HASH)
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
.PHONY: all build app run daemon clean vet tidy fmt icon build-windows
## all: build the .app bundle (default)
all: app
## build: compile both the GUI and daemon binaries
build:
mkdir -p $(BUILD_DIR)
CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(GUI_BIN) ./cmd/lmvpn
CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(DAEMON_BIN) ./cmd/lmvpnd
## app: build binaries and assemble .app bundle
app: build
rm -rf $(APP_BUNDLE)
mkdir -p $(APP_BUNDLE)/Contents/MacOS
mkdir -p $(APP_BUNDLE)/Contents/Resources
cp $(BUILD_DIR)/$(GUI_BIN) $(APP_BUNDLE)/Contents/MacOS/$(GUI_BIN)
cp $(BUILD_DIR)/$(DAEMON_BIN) $(APP_BUNDLE)/Contents/MacOS/$(DAEMON_BIN)
cp resources/Info.plist $(APP_BUNDLE)/Contents/Info.plist
@if [ -f resources/icon.icns ]; then \
cp resources/icon.icns $(APP_BUNDLE)/Contents/Resources/icon.icns; \
else echo " (no icon.icns found, skipping icon)"; fi
@echo "Built $(APP_BUNDLE)"
## icon: generate icon.icns from resources/icon.png (or resources/logo.svg)
icon:
@if [ -f resources/logo.svg ] && [ ! -f resources/icon.png -o resources/logo.svg -nt resources/icon.png ]; then \
echo "Converting resources/logo.svg -> resources/icon.png"; \
sips -z 1024 1024 -s format png resources/logo.svg --out resources/icon.png >/dev/null 2>&1; \
fi
@if [ ! -f resources/icon.png ]; then echo "resources/icon.png not found"; exit 1; fi
mkdir -p resources/icon.iconset
@for size in 16 32 64 128 256 512 1024; do \
sips -z $$size $$size resources/icon.png --out resources/icon.iconset/icon_$${size}x$${size}.png >/dev/null 2>&1; \
done
@for pair in "16 32" "32 64" "128 256" "256 512"; do \
set -- $$pair; \
sips -z $$2 $$2 resources/icon.png --out resources/icon.iconset/icon_$${1}x$${1}@2x.png >/dev/null 2>&1; \
done
cp resources/icon.png resources/icon.iconset/icon_512x512@2x.png
iconutil -c icns resources/icon.iconset -o resources/icon.icns
rm -rf resources/icon.iconset
@echo "Generated resources/icon.icns"
## run: build and run the GUI
run: build
./$(BUILD_DIR)/$(GUI_BIN)
## daemon: run the daemon directly (needs root)
daemon: build
sudo ./$(BUILD_DIR)/$(DAEMON_BIN)
## vet: run go vet
vet:
$(GO) vet ./...
## tidy: run go mod tidy
tidy:
$(GO) mod tidy
## fmt: format Go code
fmt:
$(GO) fmt ./...
## clean: remove build artifacts
clean:
rm -rf $(BUILD_DIR) $(APP_BUNDLE)
## build-windows: cross-compile Windows x86_64 exes (requires mingw-w64)
build-windows:
mkdir -p $(BUILD_DIR)
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc \
$(GO) build -ldflags "$(LDFLAGS) -H windowsgui" -o $(BUILD_DIR)/$(GUI_BIN).exe ./cmd/lmvpn
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc \
$(GO) build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(DAEMON_BIN).exe ./cmd/lmvpnd
@echo "Built $(BUILD_DIR)/$(GUI_BIN).exe and $(BUILD_DIR)/$(DAEMON_BIN).exe"