bluez-tools: Add package bluezetools
[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.17
11 GO_VERSION_PATCH:=3
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:=705c64251e5b25d5d55ede1039c6aa22bea40a7a931d14c370339853643c3df0
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_USE_MIPS16:=0
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 linux_ppc64 linux_ppc64le \
67 linux_mips linux_mipsle linux_mips64 linux_mips64le \
68 linux_riscv64 linux_s390x \
69 \
70 openbsd_mips64
71
72 BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz
73 BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS)
74 BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
75
76 BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap
77
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 \
86 solaris_amd64 \
87 windows_386 windows_amd64
88
89 include $(INCLUDE_DIR)/host-build.mk
90 include $(INCLUDE_DIR)/package.mk
91 include ../golang-compiler.mk
92 include ../golang-package.mk
93
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)"
97
98 # don't strip ELF executables in test data
99 RSTRIP:=:
100 STRIP:=:
101
102 ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
103 PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
104 endif
105
106 define Package/golang/Default
107 $(call GoPackage/GoSubMenu)
108 TITLE:=Go programming language
109 URL:=https://golang.org/
110 DEPENDS:=$(GO_ARCH_DEPENDS)
111 endef
112
113 define Package/golang/Default/description
114 The Go programming language is an open source project to make
115 programmers more productive.
116
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.
124 endef
125
126 # go tool requires source present:
127 # https://github.com/golang/go/issues/4635
128 define Package/golang
129 $(call Package/golang/Default)
130 TITLE+= (compiler)
131 DEPENDS+= +golang-src
132 endef
133
134 define Package/golang/description
135 $(call Package/golang/Default/description)
136
137 This package provides an assembler, compiler, linker, and compiled
138 libraries for the Go programming language.
139 endef
140
141 define Package/golang/config
142 source "$(SOURCE)/Config.in"
143 endef
144
145 define Package/golang-doc
146 $(call Package/golang/Default)
147 TITLE+= (documentation)
148 endef
149
150 define Package/golang-doc/description
151 $(call Package/golang/Default/description)
152
153 This package provides the documentation for the Go programming language.
154 endef
155
156 define Package/golang-src
157 $(call Package/golang/Default)
158 TITLE+= (source files)
159 endef
160
161 define Package/golang-src/description
162 $(call Package/golang/Default/description)
163
164 This package provides the Go programming language source files needed
165 for cross-compilation.
166 endef
167
168
169 # Bootstrap
170
171 BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
172
173 ifeq ($(BOOTSTRAP_ROOT_DIR),)
174 BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR)
175
176 define Download/golang-bootstrap
177 FILE:=$(BOOTSTRAP_SOURCE)
178 URL:=$(BOOTSTRAP_SOURCE_URL)
179 HASH:=$(BOOTSTRAP_HASH)
180 endef
181 $(eval $(call Download,golang-bootstrap))
182
183 define Bootstrap/Prepare
184 mkdir -p "$(BOOTSTRAP_BUILD_DIR)"
185 $(BOOTSTRAP_UNPACK)
186 endef
187 Hooks/HostPrepare/Post+=Bootstrap/Prepare
188
189 $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
190 endif
191
192
193 # Host
194
195 ifeq ($(GO_HOST_PIE_SUPPORTED),1)
196 HOST_GO_ENABLE_PIE:=1
197 endif
198
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)
201
202 $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX)))
203
204 HOST_GO_VARS= \
205 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
206 GOENV=off \
207 CC="$(HOSTCC_NOCACHE)" \
208 CXX="$(HOSTCXX_NOCACHE)"
209
210 define Host/Compile
211 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
212 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
213
214 mkdir -p "$(GO_BUILD_CACHE_DIR)"
215
216 $(call GoCompiler/Bootstrap/Make, \
217 $(HOST_GO_VARS) \
218 )
219
220 $(call GoCompiler/Host/Make, \
221 GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \
222 $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
223 $(HOST_GO_VARS) \
224 )
225 endef
226
227 # if host and target os/arch are the same,
228 # when go compiles a program, it will use the host std lib
229 # so remove it now and force go to rebuild std for target later
230 define Host/Install
231 $(call Host/Uninstall)
232
233 $(call GoCompiler/Host/Install/Bin,)
234 $(call GoCompiler/Host/Install/Src,)
235
236 $(call GoCompiler/Host/Install/BinLinks,)
237
238 rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)$(if $(HOST_GO_INSTALL_SUFFIX),_$(HOST_GO_INSTALL_SUFFIX))"
239
240 $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
241 $(INSTALL_BIN) ./files/go-gcc-helper "$(HOST_GO_ROOT)/openwrt/"
242 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
243 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
244 endef
245
246 define Host/Uninstall
247 rm -rf "$(HOST_GO_ROOT)/openwrt"
248
249 $(call GoCompiler/Host/Uninstall/BinLinks,)
250
251 $(call GoCompiler/Host/Uninstall,)
252 endef
253
254
255 # Target
256
257 ifeq ($(GO_PKG_ENABLE_PIE),1)
258 PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX)
259 endif
260
261 $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
262
263 PKG_GO_ZBOOTSTRAP_MODS:= \
264 s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \
265 s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),5)`/; \
266 s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \
267 s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \
268 s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `power8`/;
269
270 PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go
271
272 PKG_GO_VARS= \
273 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
274 GOENV=off \
275 GO_GCC_HELPER_PATH="$$$$PATH" \
276 CC=gcc \
277 CXX=g++ \
278 PKG_CONFIG=pkg-config \
279 PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH"
280
281 PKG_GO_GCFLAGS= \
282 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
283
284 PKG_GO_ASMFLAGS= \
285 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
286
287 PKG_GO_LDFLAGS= \
288 -buildid '$(SOURCE_DATE_EPOCH)' \
289 -linkmode external \
290 -extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \
291 $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
292
293 # setting -trimpath is not necessary here because the paths inside the
294 # compiler binary are relative to GOROOT_FINAL (PKG_GO_ROOT), which is
295 # static / not dependent on the build environment
296 PKG_GO_INSTALL_ARGS= \
297 -ldflags "all=$(PKG_GO_LDFLAGS)" \
298 $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \
299 $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \
300 $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie)
301
302 define Build/Compile
303 mkdir -p "$(GO_BUILD_CACHE_DIR)"
304
305 @echo "Building target Go first stage"
306
307 $(call GoCompiler/Package/Make, \
308 GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \
309 GO_GCC_HELPER_CC="$(HOSTCC)" \
310 GO_GCC_HELPER_CXX="$(HOSTCXX)" \
311 $(PKG_GO_VARS) \
312 )
313
314 $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' "$(PKG_GO_ZBOOTSTRAP_PATH)"
315
316 ( \
317 if echo 'int main() { return 0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \
318 LDSO=$$$$( \
319 readelf -l $(PKG_BUILD_DIR)/test-ldso | \
320 sed -n -e 's/^.*interpreter: \(.*\)[]]/\1/p' \
321 ) ; \
322 fi ; \
323 $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" ; \
324 )
325
326 @echo "Building target Go second stage"
327
328 ( \
329 cd "$(PKG_BUILD_DIR)/bin" ; \
330 export $(GO_PKG_TARGET_VARS) ; \
331 $(CP) go go-host ; \
332 GOROOT_FINAL="$(PKG_GO_ROOT)" \
333 GO_GCC_HELPER_CC="$(TARGET_CC)" \
334 GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
335 $(PKG_GO_VARS) \
336 ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
337 retval="$$$$?" ; \
338 rm -f go-host ; \
339 exit "$$$$retval" ; \
340 )
341 endef
342
343 define Package/golang/install
344 $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX))
345 $(call GoCompiler/Package/Install/BinLinks,$(1)$(PKG_GO_PREFIX))
346 endef
347
348 define Package/golang-doc/install
349 $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX))
350 endef
351
352 define Package/golang-src/install
353 $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX))
354 endef
355
356 # src/debug contains ELF executables as test data
357 # and they reference these libraries
358 # we need to call this in Package/$(1)/extra_provides
359 # to pass CheckDependencies in include/package-ipkg.mk
360 define Package/golang-src/extra_provides
361 echo 'libc.so.6'
362 endef
363
364
365 $(eval $(call HostBuild))
366 $(eval $(call BuildPackage,golang))
367 $(eval $(call BuildPackage,golang-doc))
368 $(eval $(call BuildPackage,golang-src))