-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile.local
More file actions
138 lines (130 loc) · 4.6 KB
/
Makefile.local
File metadata and controls
138 lines (130 loc) · 4.6 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Makefile.local - 本地开发/测试版本配置
# 用于支持本地 replace 模块(frontier, geminio)
#
# 使用方法:
# make -f Makefile.local build-liaison-linux
# make -f Makefile.local build-edge-linux
# make -f Makefile.local build-linux
#
# 注意:此文件需要 ../frontier 和 ../geminio 目录存在
# 继承主 Makefile
include Makefile
# 扩展 Docker volume 以支持本地 replace 模块
# 获取父目录路径
PARENT_DIR := $(shell dirname $(shell pwd))
FRONTIER_DIR := $(PARENT_DIR)/frontier
GEMINIO_DIR := $(PARENT_DIR)/geminio
# 检查本地模块是否存在
check-local-modules:
@if [ ! -d "$(FRONTIER_DIR)" ]; then \
echo "❌ Error: frontier module not found at $(FRONTIER_DIR)"; \
exit 1; \
fi
@if [ ! -d "$(GEMINIO_DIR)" ]; then \
echo "❌ Error: geminio module not found at $(GEMINIO_DIR)"; \
exit 1; \
fi
@echo "✅ Local modules found:"
@echo " - frontier: $(FRONTIER_DIR)"
@echo " - geminio: $(GEMINIO_DIR)"
# 扩展 DOCKER_VOLUME 以包含父目录
# 这样 Docker 容器可以访问 ../frontier 和 ../geminio
DOCKER_VOLUME := -v "$(shell pwd):/build" -v "$(PARENT_DIR):/parent"
DOCKER_BASE := docker run --rm $(DOCKER_VOLUME) $(DOCKER_WORKDIR)
# 重写 GO_BUILD_FLAGS,保留符号表(用于调试)
# 主 Makefile 中使用 -s -w 去除符号表,这里只保留 -trimpath
GO_BUILD_FLAGS = -trimpath
# 重写 docker-build-cgo 函数,在构建前检查本地模块
# 在容器内创建符号链接,使 ../frontier 和 ../geminio 指向正确的位置
define docker-build-cgo
@echo "Building $(4) for $(2)-$(3) using Docker (with local modules)..."
@mkdir -p ./bin
@if [ ! -d "$(FRONTIER_DIR)" ]; then \
echo "❌ Error: frontier module not found at $(FRONTIER_DIR)"; \
exit 1; \
fi
@if [ ! -d "$(GEMINIO_DIR)" ]; then \
echo "❌ Error: geminio module not found at $(GEMINIO_DIR)"; \
exit 1; \
fi
@echo "✅ Local modules found:"
@echo " - frontier: $(FRONTIER_DIR)"
@echo " - geminio: $(GEMINIO_DIR)"
@$(DOCKER_BASE) \
--platform $(1) \
-e CGO_ENABLED=1 \
-e GOOS=$(2) \
-e GOARCH=$(3) \
-e GOTOOLCHAIN=auto \
$(DOCKER_IMAGE) sh -c "\
apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq gcc libc6-dev libsqlite3-dev >/dev/null 2>&1 && \
go env -w GOTOOLCHAIN=auto && \
cd /build && \
ln -sf /parent/frontier ../frontier 2>/dev/null || true && \
ln -sf /parent/geminio ../geminio 2>/dev/null || true && \
go mod download && \
CC=gcc CGO_ENABLED=1 go build $(GO_BUILD_FLAGS) -o ./bin/$(4) $(5)"
@chmod +x ./bin/$(4)
@echo "✅ Built: ./bin/$(4)"
endef
# 重写 docker-build-no-cgo 函数
define docker-build-no-cgo
@echo "Building $(4) for $(2)-$(3) using Docker (with local modules)..."
@mkdir -p ./bin
@if [ ! -d "$(FRONTIER_DIR)" ]; then \
echo "❌ Error: frontier module not found at $(FRONTIER_DIR)"; \
exit 1; \
fi
@if [ ! -d "$(GEMINIO_DIR)" ]; then \
echo "❌ Error: geminio module not found at $(GEMINIO_DIR)"; \
exit 1; \
fi
@echo "✅ Local modules found:"
@echo " - frontier: $(FRONTIER_DIR)"
@echo " - geminio: $(GEMINIO_DIR)"
@$(DOCKER_BASE) \
--platform $(1) \
-e GOOS=$(2) \
-e GOARCH=$(3) \
-e GOTOOLCHAIN=auto \
$(DOCKER_IMAGE) sh -c "\
go env -w GOTOOLCHAIN=auto && \
cd /build && \
ln -sf /parent/frontier ../frontier 2>/dev/null || true && \
ln -sf /parent/geminio ../geminio 2>/dev/null || true && \
go mod download && \
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o ./bin/$(4) $(5)"
@chmod +x ./bin/$(4)
@echo "✅ Built: ./bin/$(4)"
endef
# 重写 Windows 构建目标(它直接使用 DOCKER_BASE,不使用函数)
.PHONY: build-edge-windows-amd64
build-edge-windows-amd64: docker-image
@echo "Building liaison-edge for windows-amd64 (with local modules)..."
@mkdir -p ./bin
@if [ ! -d "$(FRONTIER_DIR)" ]; then \
echo "❌ Error: frontier module not found at $(FRONTIER_DIR)"; \
exit 1; \
fi
@if [ ! -d "$(GEMINIO_DIR)" ]; then \
echo "❌ Error: geminio module not found at $(GEMINIO_DIR)"; \
exit 1; \
fi
@echo "✅ Local modules found:"
@echo " - frontier: $(FRONTIER_DIR)"
@echo " - geminio: $(GEMINIO_DIR)"
@$(DOCKER_BASE) \
--platform linux/amd64 \
-e CGO_ENABLED=1 \
-e GOOS=windows \
-e GOARCH=amd64 \
-e GOTOOLCHAIN=auto \
$(DOCKER_IMAGE) sh -c "\
go env -w GOTOOLCHAIN=auto && \
cd /build && \
ln -sf /parent/frontier ../frontier 2>/dev/null || true && \
ln -sf /parent/geminio ../geminio 2>/dev/null || true && \
go mod download && \
CGO_ENABLED=1 go build $(GO_BUILD_FLAGS) -o ./bin/liaison-edge-windows-amd64.exe cmd/edge/main.go"
@echo "✅ Built: ./bin/liaison-edge-windows-amd64.exe"