Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (54 loc) · 2.53 KB
/
Copy pathMakefile
File metadata and controls
67 lines (54 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
BINARY_NAME ?= hideck
GO_TAGS ?= with_utls nomsgpack
GOOS ?= linux
CGO_ENABLED ?= 0
VERSION ?= $(shell git describe --tags --always 2>/dev/null || echo "unknown")
VERSION_TAG = $(if $(filter v%,$(VERSION)),$(VERSION),v$(VERSION))
BUILD_TIME ?= $(shell date "+%Y-%m-%d %H:%M:%S")
DIST_DIR ?= dist
MAIN_PACKAGE ?= ./cmd/hideck
LDFLAGS = -s -w -X 'github.com/yibaiba/hideck/internal/global.Version=$(VERSION)' -X 'github.com/yibaiba/hideck/internal/global.BuildTime=$(BUILD_TIME)'
GO_BUILD = go build -trimpath -buildvcs=false -tags "$(GO_TAGS)" -ldflags "$(LDFLAGS)"
AMD64_OUT = $(DIST_DIR)/$(BINARY_NAME)_$(VERSION_TAG)_linux_amd64
ARM64_OUT = $(DIST_DIR)/$(BINARY_NAME)_$(VERSION_TAG)_linux_arm64
ARMV7_OUT = $(DIST_DIR)/$(BINARY_NAME)_$(VERSION_TAG)_linux_armv7
OPENWRT_AMD64_OUT = $(DIST_DIR)/$(BINARY_NAME)_$(VERSION_TAG)_openwrt_amd64
UPX ?= $(shell command -v upx || command -v upx-ucl)
UPX_FLAGS ?= --best --lzma
OPENWRT_IMAGE ?= golang:1.26-alpine
.PHONY: all build build-amd64 build-arm64 build-armv7 build-all frontend-dist clean \
build-openwrt build-openwrt-amd64
all: build-all
build: build-amd64
build-all: build-amd64 build-arm64 build-armv7
frontend-dist:
npm ci --prefix web
npm run build --prefix web
rm -rf internal/web/dist
mkdir -p internal/web
cp -R web/dist internal/web/dist
build-amd64: frontend-dist
@test -n "$(UPX)" || { echo "错误: 需要安装 upx"; exit 1; }
mkdir -p $(DIST_DIR)
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=amd64 $(GO_BUILD) -o $(AMD64_OUT) $(MAIN_PACKAGE)
$(UPX) $(UPX_FLAGS) $(AMD64_OUT)
build-arm64: frontend-dist
@test -n "$(UPX)" || { echo "错误: 需要安装 upx"; exit 1; }
mkdir -p $(DIST_DIR)
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=arm64 $(GO_BUILD) -o $(ARM64_OUT) $(MAIN_PACKAGE)
$(UPX) $(UPX_FLAGS) $(ARM64_OUT)
build-armv7: frontend-dist
@test -n "$(UPX)" || { echo "错误: 需要安装 upx"; exit 1; }
mkdir -p $(DIST_DIR)
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=arm GOARM=7 $(GO_BUILD) -o $(ARMV7_OUT) $(MAIN_PACKAGE)
$(UPX) $(UPX_FLAGS) $(ARMV7_OUT)
# OpenWrt: musl-static, no UPX. Local docker target is host amd64.
# arm64/armv7 OpenWrt packages are built in GitHub Actions with a musl cross toolchain.
build-openwrt: build-openwrt-amd64
build-openwrt-amd64: frontend-dist
mkdir -p $(DIST_DIR)
docker run --rm -v "$(CURDIR)":/src -w /src $(OPENWRT_IMAGE) sh -c \
'apk add --no-cache gcc musl-dev >/dev/null && VERSION=$(VERSION) BUILD_TIME="$(BUILD_TIME)" GOARCH=amd64 OUT=$(OPENWRT_AMD64_OUT) CC=gcc sh packaging/openwrt/build.sh'
clean:
go clean
rm -rf $(DIST_DIR)