p11-kit: Update to 0.23.16.1
[feed/packages.git] / lang / golang / golang / Makefile
1 #
2 # Copyright (C) 2018 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 include ../golang-version.mk
10
11 PKG_NAME:=golang
12 PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
13 PKG_RELEASE:=1
14
15 GO_SOURCE_URLS:=https://dl.google.com/go/ \
16 https://mirrors.ustc.edu.cn/golang/ \
17 https://mirrors.nju.edu.cn/golang/
18
19 PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz
20 PKG_SOURCE_URL:=$(GO_SOURCE_URLS)
21 PKG_HASH:=2aa5f088cbb332e73fc3def546800616b38d3bfe6b8713b8a6404060f22503e8
22
23 PKG_LICENSE:=BSD-3-Clause
24 PKG_LICENSE_FILES:=LICENSE
25 PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
26
27 PKG_BUILD_DEPENDS:=golang/host
28 PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION)
29 PKG_BUILD_PARALLEL:=1
30 PKG_USE_MIPS16:=0
31
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
36
37 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
38 HOST_BUILD_PARALLEL:=1
39
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)
43
44 HOST_GO_VALID_OS_ARCH:= \
45 android_arm \
46 darwin_386 darwin_amd64 darwin_arm darwin_arm64 \
47 dragonfly_amd64 \
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 \
53 solaris_amd64 \
54 windows_386 windows_amd64 \
55 \
56 linux_ppc64 linux_ppc64le linux_mips linux_mipsle linux_mips64 linux_mips64le
57
58 BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz
59 BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS)
60 BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
61
62 BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap
63
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 \
72 solaris_amd64 \
73 windows_386 windows_amd64
74
75 include $(INCLUDE_DIR)/host-build.mk
76 include $(INCLUDE_DIR)/package.mk
77 include ../golang-compiler.mk
78 include ../golang-package.mk
79
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)
83
84 # don't strip ELF executables in test data (and go itself)
85 RSTRIP:=:
86 STRIP:=:
87
88 define Package/golang/Default
89 $(call GoPackage/GoSubMenu)
90 TITLE:=Go programming language
91 URL:=https://golang.org/
92 DEPENDS:=$(GO_ARCH_DEPENDS)
93 endef
94
95 define Package/golang/Default/description
96 The Go programming language is an open source project to make
97 programmers more productive.
98
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.
106 endef
107
108 # go tool requires source present:
109 # https://github.com/golang/go/issues/4635
110 define Package/golang
111 $(call Package/golang/Default)
112 TITLE+= (compiler)
113 DEPENDS+= +golang-src
114 endef
115
116 define Package/golang/description
117 $(call Package/golang/Default/description)
118
119 This package provides an assembler, compiler, linker, and compiled
120 libraries for the Go programming language.
121 endef
122
123 define Package/golang-doc
124 $(call Package/golang/Default)
125 TITLE+= (documentation)
126 endef
127
128 define Package/golang-doc/description
129 $(call Package/golang/Default/description)
130
131 This package provides the documentation for the Go programming language.
132 endef
133
134 define Package/golang-src
135 $(call Package/golang/Default)
136 TITLE+= (source files)
137 endef
138
139 define Package/golang-src/description
140 $(call Package/golang/Default/description)
141
142 This package provides the Go programming language source files needed
143 for cross-compilation.
144 endef
145
146 define Download/golang-bootstrap
147 FILE:=$(BOOTSTRAP_SOURCE)
148 URL:=$(BOOTSTRAP_SOURCE_URL)
149 HASH:=$(BOOTSTRAP_HASH)
150 endef
151 $(eval $(call Download,golang-bootstrap))
152
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)))
156
157 define Host/Prepare
158 $(call Host/Prepare/Default)
159 mkdir -p $(BOOTSTRAP_BUILD_DIR)
160 $(BOOTSTRAP_UNPACK)
161 endef
162
163 define Host/Compile
164 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
165 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
166
167 $(call GoCompiler/Bootstrap/Make, \
168 CC=$(HOSTCC_NOCACHE) \
169 CXX=$(HOSTCXX_NOCACHE) \
170 )
171
172 $(call GoCompiler/Host/Make, \
173 GOROOT_BOOTSTRAP=$(BOOTSTRAP_BUILD_DIR) \
174 CC=$(HOSTCC_NOCACHE) \
175 CXX=$(HOSTCXX_NOCACHE) \
176 )
177 endef
178
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
182 define Host/Install
183 $(call Host/Uninstall)
184
185 $(call GoCompiler/Host/Install/Bin,)
186 $(call GoCompiler/Host/Install/Src,)
187
188 $(call GoCompiler/Host/Install/BinLinks,)
189
190 rm -rf $(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)
191
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++
196 endef
197
198 define Host/Uninstall
199 rm -rf $(HOST_GO_ROOT)/openwrt
200
201 $(call GoCompiler/Host/Uninstall/BinLinks,)
202
203 $(call GoCompiler/Host/Uninstall,)
204 endef
205
206 define Build/Compile
207 mkdir -p \
208 $(PKG_GO_HOST_CACHE_DIR) \
209 $(PKG_GO_TARGET_CACHE_DIR) \
210 $(PKG_GO_TMP_DIR)
211
212 @echo "Building target Go first stage"
213
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 \
221 CC=gcc \
222 CXX=g++ \
223 PKG_CONFIG=pkg-config \
224 PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
225 )
226
227 @echo "Building target Go second stage"
228
229 ( \
230 cd $(PKG_BUILD_DIR)/bin ; \
231 $(CP) go go-host ; \
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 \
238 CC=gcc \
239 CXX=g++ \
240 PKG_CONFIG=pkg-config \
241 PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
242 $(call GoPackage/Environment) \
243 ./go-host install -a -v std cmd ; \
244 retval=$$$$? ; \
245 rm -f go-host ; \
246 exit $$$$retval ; \
247 )
248 endef
249
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))
253 endef
254
255 define Package/golang-doc/install
256 $(call GoCompiler/Package/Install/Doc,$(1)$(GO_TARGET_PREFIX))
257 endef
258
259 define Package/golang-src/install
260 $(call GoCompiler/Package/Install/Src,$(1)$(GO_TARGET_PREFIX))
261 endef
262
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
268 echo 'libc.so.6'
269 endef
270
271 $(eval $(call HostBuild))
272 $(eval $(call BuildPackage,golang))
273 $(eval $(call BuildPackage,golang-doc))
274 $(eval $(call BuildPackage,golang-src))