2 # Copyright (C) 2018-2023 Jeffery To
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 include $(TOPDIR
)/rules.mk
10 GO_VERSION_MAJOR_MINOR
:=1.22
14 PKG_VERSION
:=$(GO_VERSION_MAJOR_MINOR
)$(if
$(GO_VERSION_PATCH
),.
$(GO_VERSION_PATCH
))
17 GO_SOURCE_URLS
:=https
://dl.google.com
/go
/ \
18 https
://mirrors.ustc.edu.cn
/golang
/ \
19 https
://mirrors.nju.edu.cn
/golang
/
21 PKG_SOURCE
:=go
$(PKG_VERSION
).src.
tar.gz
22 PKG_SOURCE_URL
:=$(GO_SOURCE_URLS
)
23 PKG_HASH
:=374ea82b289ec738e968267cac59c7d5ff180f9492250254784b2044e90df5a9
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
30 PKG_BUILD_DEPENDS
:=golang
/host
31 PKG_BUILD_DIR
:=$(BUILD_DIR
)/go-
$(PKG_VERSION
)
33 PKG_BUILD_FLAGS
:=no-mips16
36 PKG_GO_VERSION_ID
:=$(GO_VERSION_MAJOR_MINOR
)
37 PKG_GO_ROOT
:=$(PKG_GO_PREFIX
)/lib
/go-
$(PKG_GO_VERSION_ID
)
39 HOST_BUILD_DIR
:=$(BUILD_DIR_HOST
)/go-
$(PKG_VERSION
)
40 HOST_BUILD_PARALLEL
:=1
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
)
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 \
54 plan9_386 plan9_amd64 plan9_arm \
56 darwin_amd64 darwin_arm64 \
69 linux_ppc64 linux_ppc64le \
70 linux_mips linux_mipsle linux_mips64 linux_mips64le \
71 linux_loong64 linux_riscv64 linux_s390x \
75 BOOTSTRAP_SOURCE
:=go1.4
-bootstrap-20171003.
tar.gz
76 BOOTSTRAP_SOURCE_URL
:=$(GO_SOURCE_URLS
)
77 BOOTSTRAP_HASH
:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
79 BOOTSTRAP_BUILD_DIR
:=$(HOST_BUILD_DIR
)/.go_bootstrap
81 BOOTSTRAP_GO_VALID_OS_ARCH
:= \
82 darwin_386 darwin_amd64 \
83 dragonfly_386 dragonfly_amd64 \
84 freebsd_386 freebsd_amd64 freebsd_arm \
85 linux_386 linux_amd64 linux_arm \
86 netbsd_386 netbsd_amd64 netbsd_arm \
87 openbsd_386 openbsd_amd64 \
88 plan9_386 plan9_amd64 \
90 windows_386 windows_amd64
92 BOOTSTRAP_1_17_SOURCE
:=go1.17
.13.src.
tar.gz
93 BOOTSTRAP_1_17_SOURCE_URL
:=$(GO_SOURCE_URLS
)
94 BOOTSTRAP_1_17_HASH
:=a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd
96 BOOTSTRAP_1_17_BUILD_DIR
:=$(HOST_BUILD_DIR
)/.go_bootstrap_1.17
98 BOOTSTRAP_1_20_SOURCE
:=go1.20
.14.src.
tar.gz
99 BOOTSTRAP_1_20_SOURCE_URL
:=$(GO_SOURCE_URLS
)
100 BOOTSTRAP_1_20_HASH
:=1aef321a0e3e38b7e91d2d7eb64040666cabdcc77d383de3c9522d0d69b67f4e
102 BOOTSTRAP_1_20_BUILD_DIR
:=$(HOST_BUILD_DIR
)/.go_bootstrap_1.20
104 include $(INCLUDE_DIR
)/host-build.mk
105 include $(INCLUDE_DIR
)/package.mk
106 include ..
/golang-compiler.mk
107 include ..
/golang-package.mk
109 PKG_UNPACK
:=$(HOST_TAR
) -C
"$(PKG_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(PKG_SOURCE)"
110 HOST_UNPACK
:=$(HOST_TAR
) -C
"$(HOST_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(PKG_SOURCE)"
111 BOOTSTRAP_UNPACK
:=$(HOST_TAR
) -C
"$(BOOTSTRAP_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(BOOTSTRAP_SOURCE)"
112 BOOTSTRAP_1_17_UNPACK
:=$(HOST_TAR
) -C
"$(BOOTSTRAP_1_17_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(BOOTSTRAP_1_17_SOURCE)"
113 BOOTSTRAP_1_20_UNPACK
:=$(HOST_TAR
) -C
"$(BOOTSTRAP_1_20_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(BOOTSTRAP_1_20_SOURCE)"
115 # don't strip ELF executables in test data
119 ifeq ($(GO_TARGET_SPECTRE_SUPPORTED
),1)
120 PKG_CONFIG_DEPENDS
+=CONFIG_GOLANG_SPECTRE
123 define Package
/golang
/Default
124 $(call GoPackage
/GoSubMenu
)
125 TITLE
:=Go programming language
127 DEPENDS
:=$(GO_ARCH_DEPENDS
)
130 define Package
/golang
/Default
/description
131 The Go programming language is an open source project to make
132 programmers more productive.
134 Go is expressive
, concise
, clean, and efficient. Its concurrency
135 mechanisms make it easy to write programs that
get the most out of
136 multicore and networked machines
, while its novel type system enables
137 flexible and modular program construction. Go compiles quickly to
138 machine code yet has the convenience of garbage collection and the power
139 of run-time reflection. It
's a fast, statically typed, compiled language
140 that feels like a dynamically typed, interpreted language.
143 # go tool requires source present:
144 # https://github.com/golang/go/issues/4635
145 define Package/golang
146 $(call Package/golang/Default)
148 DEPENDS+= +golang-src
151 define Package/golang/description
152 $(call Package/golang/Default/description)
154 This package provides an assembler, compiler, linker, and compiled
155 libraries for the Go programming language.
158 define Package/golang/config
159 source "$(SOURCE)/Config.in"
162 define Package/golang-doc
163 $(call Package/golang/Default)
164 TITLE+= (documentation)
167 define Package/golang-doc/description
168 $(call Package/golang/Default/description)
170 This package provides the documentation for the Go programming language.
173 define Package/golang-src
174 $(call Package/golang/Default)
175 TITLE+= (source files)
178 define Package/golang-src/description
179 $(call Package/golang/Default/description)
181 This package provides the Go programming language source files needed
182 for cross-compilation.
188 BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
190 ifeq ($(BOOTSTRAP_ROOT_DIR),)
191 BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR)
193 define Download/golang-bootstrap
194 FILE:=$(BOOTSTRAP_SOURCE)
195 URL:=$(BOOTSTRAP_SOURCE_URL)
196 HASH:=$(BOOTSTRAP_HASH)
198 $(eval $(call Download,golang-bootstrap))
200 define Bootstrap/Prepare
201 mkdir -p "$(BOOTSTRAP_BUILD_DIR)" && $(BOOTSTRAP_UNPACK) ;
203 Hooks/HostPrepare/Post+=Bootstrap/Prepare
205 $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
211 define Download/golang-bootstrap-1.17
212 FILE:=$(BOOTSTRAP_1_17_SOURCE)
213 URL:=$(BOOTSTRAP_1_17_SOURCE_URL)
214 HASH:=$(BOOTSTRAP_1_17_HASH)
216 $(eval $(call Download,golang-bootstrap-1.17))
218 define Bootstrap-1.17/Prepare
219 mkdir -p "$(BOOTSTRAP_1_17_BUILD_DIR)" && $(BOOTSTRAP_1_17_UNPACK) ;
221 Hooks/HostPrepare/Post+=Bootstrap-1.17/Prepare
223 $(eval $(call GoCompiler/AddProfile,Bootstrap-1.17,$(BOOTSTRAP_1_17_BUILD_DIR),,bootstrap-1.17,$(GO_HOST_OS_ARCH)))
228 define Download/golang-bootstrap-1.20
229 FILE:=$(BOOTSTRAP_1_20_SOURCE)
230 URL:=$(BOOTSTRAP_1_20_SOURCE_URL)
231 HASH:=$(BOOTSTRAP_1_20_HASH)
233 $(eval $(call Download,golang-bootstrap-1.20))
235 define Bootstrap-1.20/Prepare
236 mkdir -p "$(BOOTSTRAP_1_20_BUILD_DIR)" && $(BOOTSTRAP_1_20_UNPACK) ;
238 Hooks/HostPrepare/Post+=Bootstrap-1.20/Prepare
240 $(eval $(call GoCompiler/AddProfile,Bootstrap-1.20,$(BOOTSTRAP_1_20_BUILD_DIR),,bootstrap-1.20,$(GO_HOST_OS_ARCH)))
244 ifeq ($(GO_HOST_PIE_SUPPORTED),1)
245 HOST_GO_ENABLE_PIE:=1
248 # when using GO_LDFLAGS to set buildmode=pie, the PIE install suffix
249 # does not apply (we also delete the std lib during Host/Install)
251 $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX)))
254 GOHOSTARCH="$(GO_HOST_ARCH)" \
255 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
257 CC="$(HOSTCC_NOCACHE)" \
258 CXX="$(HOSTCXX_NOCACHE)"
260 define Host/Configure
261 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
262 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
264 mkdir -p "$(GO_BUILD_CACHE_DIR)"
268 $(call GoCompiler/Bootstrap/Make, \
272 $(call GoCompiler/Bootstrap-1.17/Make, \
273 GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \
277 $(call GoCompiler/Bootstrap-1.20/Make, \
278 GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_17_BUILD_DIR)" \
282 $(call GoCompiler/Host/Make, \
283 GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_20_BUILD_DIR)" \
284 $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
289 # if host and target os/arch are the same,
290 # when go compiles a program, it will use the host std lib
291 # so remove it now and force go to rebuild std for target later
293 $(call Host/Uninstall)
295 $(call GoCompiler/Host/Install/Bin,)
296 $(call GoCompiler/Host/Install/Src,)
298 $(call GoCompiler/Host/Install/BinLinks,)
300 rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)$(if $(HOST_GO_INSTALL_SUFFIX),_$(HOST_GO_INSTALL_SUFFIX))"
302 $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
303 $(INSTALL_BIN) ./files/go-gcc-helper "$(HOST_GO_ROOT)/openwrt/"
304 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
305 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
308 define Host/Uninstall
309 rm -rf "$(HOST_GO_ROOT)/openwrt"
311 $(call GoCompiler/Host/Uninstall/BinLinks,)
313 $(call GoCompiler/Host/Uninstall,)
319 ifeq ($(GO_PKG_ENABLE_PIE),1)
320 PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX)
323 $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
325 PKG_GO_ZBOOTSTRAP_MODS:= \
326 s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \
327 s/defaultGOAMD64 = `[^`]*`/defaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \
328 s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),7)`/; \
329 s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \
330 s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \
331 s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `$(or $(GO_PPC64),power8)`/;
333 PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go
336 GOHOSTARCH="$(GO_HOST_ARCH)" \
337 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
339 GO_GCC_HELPER_PATH="$$$$PATH" \
342 PKG_CONFIG=pkg-config \
343 PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH"
346 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
349 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
352 -buildid '$(SOURCE_DATE_EPOCH
)' \
354 -extldflags '$(patsubst -z
%,-Wl
$(comma
)-z
$(comma
)%,$(TARGET_LDFLAGS
))' \
355 $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
357 PKG_GO_INSTALL_ARGS= \
360 -ldflags "all=$(PKG_GO_LDFLAGS)" \
361 $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \
362 $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \
363 $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie)
365 define Build/Configure
366 mkdir -p "$(GO_BUILD_CACHE_DIR)"
370 @echo "Building target Go first stage"
372 $(call GoCompiler/Package/Make, \
373 GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \
374 GO_GCC_HELPER_CC="$(HOSTCC)" \
375 GO_GCC_HELPER_CXX="$(HOSTCXX)" \
379 $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS
)' "$(PKG_GO_ZBOOTSTRAP_PATH)"
382 if echo 'int main
() { return
0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \
384 readelf -l $(PKG_BUILD_DIR)/test-ldso | \
385 sed -n -e 's
/^.
*interpreter
: \
(.
*\
)[]]/\
1/p
' \
388 $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" ; \
391 @echo "Building target Go second stage"
394 cd "$(PKG_BUILD_DIR)/bin" ; \
395 export $(GO_PKG_TARGET_VARS) ; \
397 GOROOT_FINAL="$(PKG_GO_ROOT)" \
398 GO_GCC_HELPER_CC="$(TARGET_CC)" \
399 GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
401 ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
404 exit "$$$$retval" ; \
408 define Package/golang/install
409 $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX))
410 $(call GoCompiler/Package/Install/BinLinks,$(1)$(PKG_GO_PREFIX))
413 define Package/golang-doc/install
414 $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX))
417 define Package/golang-src/install
418 $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX))
421 # src/debug contains ELF executables as test data
422 # and they reference these libraries
423 # we need to call this in Package/$(1)/extra_provides
424 # to pass CheckDependencies in include/package-ipkg.mk
425 define Package/golang-src/extra_provides
430 $(eval $(call HostBuild))
431 $(eval $(call BuildPackage,golang))
432 $(eval $(call BuildPackage,golang-doc))
433 $(eval $(call BuildPackage,golang-src))