2 # Copyright (C) 2018 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
9 include ..
/golang-version.mk
12 PKG_VERSION
:=$(GO_VERSION_MAJOR_MINOR
)$(if
$(GO_VERSION_PATCH
),.
$(GO_VERSION_PATCH
))
15 GO_SOURCE_URLS
:=https
://dl.google.com
/go
/ \
16 https
://mirrors.ustc.edu.cn
/golang
/ \
17 https
://mirrors.nju.edu.cn
/golang
/
19 PKG_SOURCE
:=go
$(PKG_VERSION
).src.
tar.gz
20 PKG_SOURCE_URL
:=$(GO_SOURCE_URLS
)
21 PKG_HASH
:=2aa5f088cbb332e73fc3def546800616b38d3bfe6b8713b8a6404060f22503e8
23 PKG_LICENSE
:=BSD-3-Clause
24 PKG_LICENSE_FILES
:=LICENSE
25 PKG_MAINTAINER
:=Jeffery To
<jeffery.to@gmail.com
>
27 PKG_BUILD_DEPENDS
:=golang
/host
28 PKG_BUILD_DIR
:=$(BUILD_DIR
)/go-
$(PKG_VERSION
)
32 PKG_GO_WORK_DIR
:=$(PKG_BUILD_DIR
)/.go_work
33 PKG_GO_HOST_CACHE_DIR
:=$(PKG_GO_WORK_DIR
)/host_cache
34 PKG_GO_TARGET_CACHE_DIR
:=$(PKG_GO_WORK_DIR
)/target_cache
35 PKG_GO_TMP_DIR
:=$(PKG_GO_WORK_DIR
)/tmp
37 HOST_BUILD_DIR
:=$(BUILD_DIR_HOST
)/go-
$(PKG_VERSION
)
38 HOST_BUILD_PARALLEL
:=1
40 HOST_GO_PREFIX
:=$(STAGING_DIR_HOSTPKG
)
41 HOST_GO_VERSION_ID
:=cross
42 HOST_GO_ROOT
:=$(HOST_GO_PREFIX
)/lib
/go-
$(HOST_GO_VERSION_ID
)
44 HOST_GO_VALID_OS_ARCH
:= \
46 darwin_386 darwin_amd64 darwin_arm darwin_arm64 \
48 freebsd_386 freebsd_amd64 freebsd_arm \
49 linux_386 linux_amd64 linux_arm linux_arm64 \
50 netbsd_386 netbsd_amd64 netbsd_arm \
51 openbsd_386 openbsd_amd64 openbsd_arm \
52 plan9_386 plan9_amd64 \
54 windows_386 windows_amd64 \
56 linux_ppc64 linux_ppc64le linux_mips linux_mipsle linux_mips64 linux_mips64le
58 BOOTSTRAP_SOURCE
:=go1.4
-bootstrap-20171003.
tar.gz
59 BOOTSTRAP_SOURCE_URL
:=$(GO_SOURCE_URLS
)
60 BOOTSTRAP_HASH
:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
62 BOOTSTRAP_BUILD_DIR
:=$(HOST_BUILD_DIR
)/.go_bootstrap
64 BOOTSTRAP_GO_VALID_OS_ARCH
:= \
65 darwin_386 darwin_amd64 \
66 dragonfly_386 dragonfly_amd64 \
67 freebsd_386 freebsd_amd64 freebsd_arm \
68 linux_386 linux_amd64 linux_arm \
69 netbsd_386 netbsd_amd64 netbsd_arm \
70 openbsd_386 openbsd_amd64 \
71 plan9_386 plan9_amd64 \
73 windows_386 windows_amd64
75 include $(INCLUDE_DIR
)/host-build.mk
76 include $(INCLUDE_DIR
)/package.mk
77 include ..
/golang-compiler.mk
78 include ..
/golang-package.mk
80 PKG_UNPACK
:=$(HOST_TAR
) -C
$(PKG_BUILD_DIR
) --strip-components
=1 -xzf
$(DL_DIR
)/$(PKG_SOURCE
)
81 HOST_UNPACK
:=$(HOST_TAR
) -C
$(HOST_BUILD_DIR
) --strip-components
=1 -xzf
$(DL_DIR
)/$(PKG_SOURCE
)
82 BOOTSTRAP_UNPACK
:=$(HOST_TAR
) -C
$(BOOTSTRAP_BUILD_DIR
) --strip-components
=1 -xzf
$(DL_DIR
)/$(BOOTSTRAP_SOURCE
)
84 # don't strip ELF executables in test data (and go itself)
88 define Package
/golang
/Default
89 $(call GoPackage
/GoSubMenu
)
90 TITLE
:=Go programming language
91 URL
:=https
://golang.org
/
92 DEPENDS
:=$(GO_ARCH_DEPENDS
)
95 define Package
/golang
/Default
/description
96 The Go programming language is an open source project to make
97 programmers more productive.
99 Go is expressive
, concise
, clean, and efficient. Its concurrency
100 mechanisms make it easy to write programs that
get the most out of
101 multicore and networked machines
, while its novel type system enables
102 flexible and modular program construction. Go compiles quickly to
103 machine code yet has the convenience of garbage collection and the power
104 of run-time reflection. It
's a fast, statically typed, compiled language
105 that feels like a dynamically typed, interpreted language.
108 # go tool requires source present:
109 # https://github.com/golang/go/issues/4635
110 define Package/golang
111 $(call Package/golang/Default)
113 DEPENDS+= +golang-src
116 define Package/golang/description
117 $(call Package/golang/Default/description)
119 This package provides an assembler, compiler, linker, and compiled
120 libraries for the Go programming language.
123 define Package/golang-doc
124 $(call Package/golang/Default)
125 TITLE+= (documentation)
128 define Package/golang-doc/description
129 $(call Package/golang/Default/description)
131 This package provides the documentation for the Go programming language.
134 define Package/golang-src
135 $(call Package/golang/Default)
136 TITLE+= (source files)
139 define Package/golang-src/description
140 $(call Package/golang/Default/description)
142 This package provides the Go programming language source files needed
143 for cross-compilation.
146 define Download/golang-bootstrap
147 FILE:=$(BOOTSTRAP_SOURCE)
148 URL:=$(BOOTSTRAP_SOURCE_URL)
149 HASH:=$(BOOTSTRAP_HASH)
151 $(eval $(call Download,golang-bootstrap))
153 $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
154 $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH)))
155 $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(GO_TARGET_PREFIX),$(GO_TARGET_VERSION_ID),$(GO_OS_ARCH)))
158 $(call Host/Prepare/Default)
159 mkdir -p $(BOOTSTRAP_BUILD_DIR)
164 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
165 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
167 $(call GoCompiler/Bootstrap/Make, \
168 CC=$(HOSTCC_NOCACHE) \
169 CXX=$(HOSTCXX_NOCACHE) \
172 $(call GoCompiler/Host/Make, \
173 GOROOT_BOOTSTRAP=$(BOOTSTRAP_BUILD_DIR) \
174 CC=$(HOSTCC_NOCACHE) \
175 CXX=$(HOSTCXX_NOCACHE) \
179 # if host and target os/arch are the same,
180 # when go compiles a program, it will use the host std lib
181 # so remove it now and force go to rebuild std for target later
183 $(call Host/Uninstall)
185 $(call GoCompiler/Host/Install/Bin,)
186 $(call GoCompiler/Host/Install/Src,)
188 $(call GoCompiler/Host/Install/BinLinks,)
190 rm -rf $(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)
192 $(INSTALL_DIR) $(HOST_GO_ROOT)/openwrt
193 $(INSTALL_BIN) ./files/go-gcc-helper $(HOST_GO_ROOT)/openwrt/
194 $(LN) go-gcc-helper $(HOST_GO_ROOT)/openwrt/gcc
195 $(LN) go-gcc-helper $(HOST_GO_ROOT)/openwrt/g++
198 define Host/Uninstall
199 rm -rf $(HOST_GO_ROOT)/openwrt
201 $(call GoCompiler/Host/Uninstall/BinLinks,)
203 $(call GoCompiler/Host/Uninstall,)
208 $(PKG_GO_HOST_CACHE_DIR) \
209 $(PKG_GO_TARGET_CACHE_DIR) \
212 @echo "Building target Go first stage"
214 $(call GoCompiler/Package/Make, \
215 GOROOT_BOOTSTRAP=$(HOST_GO_ROOT) \
216 GOCACHE=$(PKG_GO_HOST_CACHE_DIR) \
217 GOTMPDIR=$(PKG_GO_TMP_DIR) \
218 GO_GCC_HELPER_CC="$(HOSTCC)" \
219 GO_GCC_HELPER_CXX="$(HOSTCXX)" \
220 GO_GCC_HELPER_PATH=$$$$PATH \
223 PKG_CONFIG=pkg-config \
224 PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
227 @echo "Building target Go second stage"
230 cd $(PKG_BUILD_DIR)/bin ; \
232 GOROOT_FINAL=$(GO_TARGET_ROOT) \
233 GOCACHE=$(PKG_GO_TARGET_CACHE_DIR) \
234 GOTMPDIR=$(PKG_GO_TMP_DIR) \
235 GO_GCC_HELPER_CC="$(TARGET_CC)" \
236 GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
237 GO_GCC_HELPER_PATH=$$$$PATH \
240 PKG_CONFIG=pkg-config \
241 PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
242 $(call GoPackage/Environment) \
243 ./go-host install -a -v std cmd ; \
250 define Package/golang/install
251 $(call GoCompiler/Package/Install/Bin,$(1)$(GO_TARGET_PREFIX))
252 $(call GoCompiler/Package/Install/BinLinks,$(1)$(GO_TARGET_PREFIX))
255 define Package/golang-doc/install
256 $(call GoCompiler/Package/Install/Doc,$(1)$(GO_TARGET_PREFIX))
259 define Package/golang-src/install
260 $(call GoCompiler/Package/Install/Src,$(1)$(GO_TARGET_PREFIX))
263 # src/debug contains ELF executables as test data
264 # and they reference these libraries
265 # we need to call this in Package/$(1)/extra_provides
266 # to pass CheckDependencies in include/package-ipkg.mk
267 define Package/golang-src/extra_provides
271 $(eval $(call HostBuild))
272 $(eval $(call BuildPackage,golang))
273 $(eval $(call BuildPackage,golang-doc))
274 $(eval $(call BuildPackage,golang-src))