golang: Update to 1.20.5
[feed/packages.git] / lang / golang / golang / Makefile
1 #
2 # Copyright (C) 2018, 2020 Jeffery To
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 include $(TOPDIR)/rules.mk
9
10 GO_VERSION_MAJOR_MINOR:=1.20
11 GO_VERSION_PATCH:=5
12
13 PKG_NAME:=golang
14 PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
15 PKG_RELEASE:=1
16
17 GO_SOURCE_URLS:=https://dl.google.com/go/ \
18 https://mirrors.ustc.edu.cn/golang/ \
19 https://mirrors.nju.edu.cn/golang/
20
21 PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz
22 PKG_SOURCE_URL:=$(GO_SOURCE_URLS)
23 PKG_HASH:=9a15c133ba2cfafe79652f4815b62e7cfc267f68df1b9454c6ab2a3ca8b96a88
24
25 PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
26 PKG_LICENSE:=BSD-3-Clause
27 PKG_LICENSE_FILES:=LICENSE
28 PKG_CPE_ID:=cpe:/a:golang:go
29
30 PKG_BUILD_DEPENDS:=golang/host
31 PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION)
32 PKG_BUILD_PARALLEL:=1
33 PKG_BUILD_FLAGS:=no-mips16
34
35 PKG_GO_PREFIX:=/usr
36 PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
37 PKG_GO_ROOT:=$(PKG_GO_PREFIX)/lib/go-$(PKG_GO_VERSION_ID)
38
39 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
40 HOST_BUILD_PARALLEL:=1
41
42 HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG)
43 HOST_GO_VERSION_ID:=cross
44 HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID)
45
46 HOST_GO_VALID_OS_ARCH:= \
47 android_386 android_amd64 android_arm android_arm64 \
48 freebsd_386 freebsd_amd64 freebsd_arm freebsd_arm64 \
49 linux_386 linux_amd64 linux_arm linux_arm64 \
50 openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 \
51 netbsd_386 netbsd_amd64 netbsd_arm netbsd_arm64 \
52 windows_386 windows_amd64 windows_arm windows_arm64 \
53 \
54 plan9_386 plan9_amd64 plan9_arm \
55 \
56 darwin_amd64 darwin_arm64 \
57 ios_amd64 ios_arm64 \
58 \
59 dragonfly_amd64 \
60 illumos_amd64 \
61 solaris_amd64 \
62 \
63 aix_ppc64 \
64 js_wasm \
65 \
66 freebsd_riscv64 \
67 \
68 linux_ppc64 linux_ppc64le \
69 linux_mips linux_mipsle linux_mips64 linux_mips64le \
70 linux_loong64 linux_riscv64 linux_s390x \
71 \
72 openbsd_mips64
73
74 BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz
75 BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS)
76 BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
77
78 BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap
79
80 BOOTSTRAP_GO_VALID_OS_ARCH:= \
81 darwin_386 darwin_amd64 \
82 dragonfly_386 dragonfly_amd64 \
83 freebsd_386 freebsd_amd64 freebsd_arm \
84 linux_386 linux_amd64 linux_arm \
85 netbsd_386 netbsd_amd64 netbsd_arm \
86 openbsd_386 openbsd_amd64 \
87 plan9_386 plan9_amd64 \
88 solaris_amd64 \
89 windows_386 windows_amd64
90
91 BOOTSTRAP_1_17_SOURCE:=go1.17.13.src.tar.gz
92 BOOTSTRAP_1_17_SOURCE_URL:=$(GO_SOURCE_URLS)
93 BOOTSTRAP_1_17_HASH:=a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd
94
95 BOOTSTRAP_1_17_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.17
96
97 include $(INCLUDE_DIR)/host-build.mk
98 include $(INCLUDE_DIR)/package.mk
99 include ../golang-compiler.mk
100 include ../golang-package.mk
101
102 PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
103 HOST_UNPACK:=$(HOST_TAR) -C "$(HOST_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
104 BOOTSTRAP_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_SOURCE)"
105 BOOTSTRAP_1_17_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_17_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_17_SOURCE)"
106
107 # don't strip ELF executables in test data
108 RSTRIP:=:
109 STRIP:=:
110
111 ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
112 PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
113 endif
114
115 define Package/golang/Default
116 $(call GoPackage/GoSubMenu)
117 TITLE:=Go programming language
118 URL:=https://go.dev/
119 DEPENDS:=$(GO_ARCH_DEPENDS)
120 endef
121
122 define Package/golang/Default/description
123 The Go programming language is an open source project to make
124 programmers more productive.
125
126 Go is expressive, concise, clean, and efficient. Its concurrency
127 mechanisms make it easy to write programs that get the most out of
128 multicore and networked machines, while its novel type system enables
129 flexible and modular program construction. Go compiles quickly to
130 machine code yet has the convenience of garbage collection and the power
131 of run-time reflection. It's a fast, statically typed, compiled language
132 that feels like a dynamically typed, interpreted language.
133 endef
134
135 # go tool requires source present:
136 # https://github.com/golang/go/issues/4635
137 define Package/golang
138 $(call Package/golang/Default)
139 TITLE+= (compiler)
140 DEPENDS+= +golang-src
141 endef
142
143 define Package/golang/description
144 $(call Package/golang/Default/description)
145
146 This package provides an assembler, compiler, linker, and compiled
147 libraries for the Go programming language.
148 endef
149
150 define Package/golang/config
151 source "$(SOURCE)/Config.in"
152 endef
153
154 define Package/golang-doc
155 $(call Package/golang/Default)
156 TITLE+= (documentation)
157 endef
158
159 define Package/golang-doc/description
160 $(call Package/golang/Default/description)
161
162 This package provides the documentation for the Go programming language.
163 endef
164
165 define Package/golang-src
166 $(call Package/golang/Default)
167 TITLE+= (source files)
168 endef
169
170 define Package/golang-src/description
171 $(call Package/golang/Default/description)
172
173 This package provides the Go programming language source files needed
174 for cross-compilation.
175 endef
176
177
178 # Bootstrap
179
180 BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
181
182 ifeq ($(BOOTSTRAP_ROOT_DIR),)
183 BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR)
184
185 define Download/golang-bootstrap
186 FILE:=$(BOOTSTRAP_SOURCE)
187 URL:=$(BOOTSTRAP_SOURCE_URL)
188 HASH:=$(BOOTSTRAP_HASH)
189 endef
190 $(eval $(call Download,golang-bootstrap))
191
192 define Bootstrap/Prepare
193 mkdir -p "$(BOOTSTRAP_BUILD_DIR)" && $(BOOTSTRAP_UNPACK) ;
194 endef
195 Hooks/HostPrepare/Post+=Bootstrap/Prepare
196
197 $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
198 endif
199
200
201 # Bootstrap 1.17
202
203 define Download/golang-bootstrap-1.17
204 FILE:=$(BOOTSTRAP_1_17_SOURCE)
205 URL:=$(BOOTSTRAP_1_17_SOURCE_URL)
206 HASH:=$(BOOTSTRAP_1_17_HASH)
207 endef
208 $(eval $(call Download,golang-bootstrap-1.17))
209
210 define Bootstrap-1.17/Prepare
211 mkdir -p "$(BOOTSTRAP_1_17_BUILD_DIR)" && $(BOOTSTRAP_1_17_UNPACK) ;
212 endef
213 Hooks/HostPrepare/Post+=Bootstrap-1.17/Prepare
214
215 $(eval $(call GoCompiler/AddProfile,Bootstrap-1.17,$(BOOTSTRAP_1_17_BUILD_DIR),,bootstrap-1.17,$(GO_HOST_OS_ARCH)))
216
217
218 # Host
219
220 ifeq ($(GO_HOST_PIE_SUPPORTED),1)
221 HOST_GO_ENABLE_PIE:=1
222 endif
223
224 # when using GO_LDFLAGS to set buildmode=pie, the PIE install suffix
225 # does not apply (we also delete the std lib during Host/Install)
226
227 $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX)))
228
229 HOST_GO_VARS= \
230 GOHOSTARCH="$(GO_HOST_ARCH)" \
231 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
232 GOENV=off \
233 CC="$(HOSTCC_NOCACHE)" \
234 CXX="$(HOSTCXX_NOCACHE)"
235
236 define Host/Configure
237 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
238 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
239
240 mkdir -p "$(GO_BUILD_CACHE_DIR)"
241 endef
242
243 define Host/Compile
244 $(call GoCompiler/Bootstrap/Make, \
245 $(HOST_GO_VARS) \
246 )
247
248 $(call GoCompiler/Bootstrap-1.17/Make, \
249 GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \
250 $(HOST_GO_VARS) \
251 )
252
253 $(call GoCompiler/Host/Make, \
254 GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_17_BUILD_DIR)" \
255 $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
256 $(HOST_GO_VARS) \
257 )
258 endef
259
260 # if host and target os/arch are the same,
261 # when go compiles a program, it will use the host std lib
262 # so remove it now and force go to rebuild std for target later
263 define Host/Install
264 $(call Host/Uninstall)
265
266 $(call GoCompiler/Host/Install/Bin,)
267 $(call GoCompiler/Host/Install/Src,)
268
269 $(call GoCompiler/Host/Install/BinLinks,)
270
271 rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)$(if $(HOST_GO_INSTALL_SUFFIX),_$(HOST_GO_INSTALL_SUFFIX))"
272
273 $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
274 $(INSTALL_BIN) ./files/go-gcc-helper "$(HOST_GO_ROOT)/openwrt/"
275 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
276 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
277 endef
278
279 define Host/Uninstall
280 rm -rf "$(HOST_GO_ROOT)/openwrt"
281
282 $(call GoCompiler/Host/Uninstall/BinLinks,)
283
284 $(call GoCompiler/Host/Uninstall,)
285 endef
286
287
288 # Target
289
290 ifeq ($(GO_PKG_ENABLE_PIE),1)
291 PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX)
292 endif
293
294 $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
295
296 PKG_GO_ZBOOTSTRAP_MODS:= \
297 s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \
298 s/defaultGOAMD64 = `[^`]*`/defaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \
299 s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),5)`/; \
300 s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \
301 s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \
302 s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `$(or $(GO_PPC64),power8)`/;
303
304 PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go
305
306 PKG_GO_VARS= \
307 GOHOSTARCH="$(GO_HOST_ARCH)" \
308 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
309 GOENV=off \
310 GO_GCC_HELPER_PATH="$$$$PATH" \
311 CC=gcc \
312 CXX=g++ \
313 PKG_CONFIG=pkg-config \
314 PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH"
315
316 PKG_GO_GCFLAGS= \
317 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
318
319 PKG_GO_ASMFLAGS= \
320 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
321
322 PKG_GO_LDFLAGS= \
323 -buildid '$(SOURCE_DATE_EPOCH)' \
324 -linkmode external \
325 -extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \
326 $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
327
328 PKG_GO_INSTALL_ARGS= \
329 -buildvcs=false \
330 -trimpath \
331 -ldflags "all=$(PKG_GO_LDFLAGS)" \
332 $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \
333 $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \
334 $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie)
335
336 define Build/Configure
337 mkdir -p "$(GO_BUILD_CACHE_DIR)"
338 endef
339
340 define Build/Compile
341 @echo "Building target Go first stage"
342
343 $(call GoCompiler/Package/Make, \
344 GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \
345 GO_GCC_HELPER_CC="$(HOSTCC)" \
346 GO_GCC_HELPER_CXX="$(HOSTCXX)" \
347 $(PKG_GO_VARS) \
348 )
349
350 $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' "$(PKG_GO_ZBOOTSTRAP_PATH)"
351
352 ( \
353 if echo 'int main() { return 0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \
354 LDSO=$$$$( \
355 readelf -l $(PKG_BUILD_DIR)/test-ldso | \
356 sed -n -e 's/^.*interpreter: \(.*\)[]]/\1/p' \
357 ) ; \
358 fi ; \
359 $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" ; \
360 )
361
362 @echo "Building target Go second stage"
363
364 ( \
365 cd "$(PKG_BUILD_DIR)/bin" ; \
366 export $(GO_PKG_TARGET_VARS) ; \
367 $(CP) go go-host ; \
368 GOROOT_FINAL="$(PKG_GO_ROOT)" \
369 GO_GCC_HELPER_CC="$(TARGET_CC)" \
370 GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
371 $(PKG_GO_VARS) \
372 ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
373 retval="$$$$?" ; \
374 rm -f go-host ; \
375 exit "$$$$retval" ; \
376 )
377 endef
378
379 define Package/golang/install
380 $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX))
381 $(call GoCompiler/Package/Install/BinLinks,$(1)$(PKG_GO_PREFIX))
382 endef
383
384 define Package/golang-doc/install
385 $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX))
386 endef
387
388 define Package/golang-src/install
389 $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX))
390 endef
391
392 # src/debug contains ELF executables as test data
393 # and they reference these libraries
394 # we need to call this in Package/$(1)/extra_provides
395 # to pass CheckDependencies in include/package-ipkg.mk
396 define Package/golang-src/extra_provides
397 echo 'libc.so.6'
398 endef
399
400
401 $(eval $(call HostBuild))
402 $(eval $(call BuildPackage,golang))
403 $(eval $(call BuildPackage,golang-doc))
404 $(eval $(call BuildPackage,golang-src))