2 # Copyright (C) 2018, 2020 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.18
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
:=1f79802305015479e77d8c641530bc54ec994657d5c5271e0172eb7118346a12
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
)
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 \
66 linux_ppc64 linux_ppc64le \
67 linux_mips linux_mipsle linux_mips64 linux_mips64le \
68 linux_riscv64 linux_s390x \
72 BOOTSTRAP_SOURCE
:=go1.4
-bootstrap-20171003.
tar.gz
73 BOOTSTRAP_SOURCE_URL
:=$(GO_SOURCE_URLS
)
74 BOOTSTRAP_HASH
:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
76 BOOTSTRAP_BUILD_DIR
:=$(HOST_BUILD_DIR
)/.go_bootstrap
78 BOOTSTRAP_GO_VALID_OS_ARCH
:= \
79 darwin_386 darwin_amd64 \
80 dragonfly_386 dragonfly_amd64 \
81 freebsd_386 freebsd_amd64 freebsd_arm \
82 linux_386 linux_amd64 linux_arm \
83 netbsd_386 netbsd_amd64 netbsd_arm \
84 openbsd_386 openbsd_amd64 \
85 plan9_386 plan9_amd64 \
87 windows_386 windows_amd64
89 include $(INCLUDE_DIR
)/host-build.mk
90 include $(INCLUDE_DIR
)/package.mk
91 include ..
/golang-compiler.mk
92 include ..
/golang-package.mk
94 PKG_UNPACK
:=$(HOST_TAR
) -C
"$(PKG_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(PKG_SOURCE)"
95 HOST_UNPACK
:=$(HOST_TAR
) -C
"$(HOST_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(PKG_SOURCE)"
96 BOOTSTRAP_UNPACK
:=$(HOST_TAR
) -C
"$(BOOTSTRAP_BUILD_DIR)" --strip-components
=1 -xzf
"$(DL_DIR)/$(BOOTSTRAP_SOURCE)"
98 # don't strip ELF executables in test data
102 ifeq ($(GO_TARGET_SPECTRE_SUPPORTED
),1)
103 PKG_CONFIG_DEPENDS
+=CONFIG_GOLANG_SPECTRE
106 define Package
/golang
/Default
107 $(call GoPackage
/GoSubMenu
)
108 TITLE
:=Go programming language
110 DEPENDS
:=$(GO_ARCH_DEPENDS
)
113 define Package
/golang
/Default
/description
114 The Go programming language is an open source project to make
115 programmers more productive.
117 Go is expressive
, concise
, clean, and efficient. Its concurrency
118 mechanisms make it easy to write programs that
get the most out of
119 multicore and networked machines
, while its novel type system enables
120 flexible and modular program construction. Go compiles quickly to
121 machine code yet has the convenience of garbage collection and the power
122 of run-time reflection. It
's a fast, statically typed, compiled language
123 that feels like a dynamically typed, interpreted language.
126 # go tool requires source present:
127 # https://github.com/golang/go/issues/4635
128 define Package/golang
129 $(call Package/golang/Default)
131 DEPENDS+= +golang-src
134 define Package/golang/description
135 $(call Package/golang/Default/description)
137 This package provides an assembler, compiler, linker, and compiled
138 libraries for the Go programming language.
141 define Package/golang/config
142 source "$(SOURCE)/Config.in"
145 define Package/golang-doc
146 $(call Package/golang/Default)
147 TITLE+= (documentation)
150 define Package/golang-doc/description
151 $(call Package/golang/Default/description)
153 This package provides the documentation for the Go programming language.
156 define Package/golang-src
157 $(call Package/golang/Default)
158 TITLE+= (source files)
161 define Package/golang-src/description
162 $(call Package/golang/Default/description)
164 This package provides the Go programming language source files needed
165 for cross-compilation.
171 BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
173 ifeq ($(BOOTSTRAP_ROOT_DIR),)
174 BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR)
176 define Download/golang-bootstrap
177 FILE:=$(BOOTSTRAP_SOURCE)
178 URL:=$(BOOTSTRAP_SOURCE_URL)
179 HASH:=$(BOOTSTRAP_HASH)
181 $(eval $(call Download,golang-bootstrap))
183 define Bootstrap/Prepare
184 mkdir -p "$(BOOTSTRAP_BUILD_DIR)"
187 Hooks/HostPrepare/Post+=Bootstrap/Prepare
189 $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
195 ifeq ($(GO_HOST_PIE_SUPPORTED),1)
196 HOST_GO_ENABLE_PIE:=1
199 # when using GO_LDFLAGS to set buildmode=pie, the PIE install suffix
200 # does not apply (we also delete the std lib during Host/Install)
202 $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX)))
205 GOHOSTARCH="$(GO_HOST_ARCH)" \
206 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
208 CC="$(HOSTCC_NOCACHE)" \
209 CXX="$(HOSTCXX_NOCACHE)"
211 define Host/Configure
212 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
213 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
215 mkdir -p "$(GO_BUILD_CACHE_DIR)"
219 $(call GoCompiler/Bootstrap/Make, \
223 $(call GoCompiler/Host/Make, \
224 GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \
225 $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
230 # if host and target os/arch are the same,
231 # when go compiles a program, it will use the host std lib
232 # so remove it now and force go to rebuild std for target later
234 $(call Host/Uninstall)
236 $(call GoCompiler/Host/Install/Bin,)
237 $(call GoCompiler/Host/Install/Src,)
239 $(call GoCompiler/Host/Install/BinLinks,)
241 rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)$(if $(HOST_GO_INSTALL_SUFFIX),_$(HOST_GO_INSTALL_SUFFIX))"
243 $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
244 $(INSTALL_BIN) ./files/go-gcc-helper "$(HOST_GO_ROOT)/openwrt/"
245 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
246 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
249 define Host/Uninstall
250 rm -rf "$(HOST_GO_ROOT)/openwrt"
252 $(call GoCompiler/Host/Uninstall/BinLinks,)
254 $(call GoCompiler/Host/Uninstall,)
260 ifeq ($(GO_PKG_ENABLE_PIE),1)
261 PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX)
264 $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
266 PKG_GO_ZBOOTSTRAP_MODS:= \
267 s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \
268 s/defaultGOAMD64 = `[^`]*`/defaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \
269 s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),5)`/; \
270 s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \
271 s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \
272 s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `$(or $(GO_PPC64),power8)`/;
274 PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go
277 GOHOSTARCH="$(GO_HOST_ARCH)" \
278 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
280 GO_GCC_HELPER_PATH="$$$$PATH" \
283 PKG_CONFIG=pkg-config \
284 PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH"
287 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
290 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
293 -buildid '$(SOURCE_DATE_EPOCH
)' \
295 -extldflags '$(patsubst -z
%,-Wl
$(comma
)-z
$(comma
)%,$(TARGET_LDFLAGS
))' \
296 $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
298 # setting -trimpath is not necessary here because the paths inside the
299 # compiler binary are relative to GOROOT_FINAL (PKG_GO_ROOT), which is
300 # static / not dependent on the build environment
301 PKG_GO_INSTALL_ARGS= \
302 -ldflags "all=$(PKG_GO_LDFLAGS)" \
303 $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \
304 $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \
305 $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie)
307 define Build/Configure
308 mkdir -p "$(GO_BUILD_CACHE_DIR)"
312 @echo "Building target Go first stage"
314 $(call GoCompiler/Package/Make, \
315 GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \
316 GO_GCC_HELPER_CC="$(HOSTCC)" \
317 GO_GCC_HELPER_CXX="$(HOSTCXX)" \
321 $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS
)' "$(PKG_GO_ZBOOTSTRAP_PATH)"
324 if echo 'int main
() { return
0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \
326 readelf -l $(PKG_BUILD_DIR)/test-ldso | \
327 sed -n -e 's
/^.
*interpreter
: \
(.
*\
)[]]/\
1/p
' \
330 $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" ; \
333 @echo "Building target Go second stage"
336 cd "$(PKG_BUILD_DIR)/bin" ; \
337 export $(GO_PKG_TARGET_VARS) ; \
339 GOROOT_FINAL="$(PKG_GO_ROOT)" \
340 GO_GCC_HELPER_CC="$(TARGET_CC)" \
341 GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
343 ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
346 exit "$$$$retval" ; \
350 define Package/golang/install
351 $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX))
352 $(call GoCompiler/Package/Install/BinLinks,$(1)$(PKG_GO_PREFIX))
355 define Package/golang-doc/install
356 $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX))
359 define Package/golang-src/install
360 $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX))
363 # src/debug contains ELF executables as test data
364 # and they reference these libraries
365 # we need to call this in Package/$(1)/extra_provides
366 # to pass CheckDependencies in include/package-ipkg.mk
367 define Package/golang-src/extra_provides
372 $(eval $(call HostBuild))
373 $(eval $(call BuildPackage,golang))
374 $(eval $(call BuildPackage,golang-doc))
375 $(eval $(call BuildPackage,golang-src))