blob: c6c83601719a275d9422e2f080a0867511a6fb81 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
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
8ifeq ($(origin GO_INCLUDE_DIR),undefined)
9 GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
10endif
11
12include $(GO_INCLUDE_DIR)/golang-values.mk
13
14
15# $(1) valid GOOS_GOARCH combinations
16# $(2) go version id
17define GoCompiler/Default/CheckHost
18 $(if $(filter $(GO_HOST_OS_ARCH),$(1)),,$(error go-$(2) cannot be installed on $(GO_HOST_OS)/$(GO_HOST_ARCH)))
19endef
20
21# $(1) source go root
22# $(2) destination prefix
23# $(3) go version id
24# $(4) additional environment variables (optional)
25define GoCompiler/Default/Make
26 ( \
27 cd "$(1)/src" ; \
28 $(if $(2),GOROOT_FINAL="$(2)/lib/go-$(3)") \
29 $(4) \
30 $(BASH) make.bash --no-banner ; \
31 )
32endef
33
34# $(1) destination prefix
35# $(2) go version id
36define GoCompiler/Default/Install/make-dirs
37 $(INSTALL_DIR) "$(1)/lib/go-$(2)"
38 $(INSTALL_DIR) "$(1)/share/go-$(2)"
39endef
40
41# $(1) source go root
42# $(2) destination prefix
43# $(3) go version id
44# $(4) file/directory name
45define GoCompiler/Default/Install/install-share-data
46 $(CP) "$(1)/$(4)" "$(2)/share/go-$(3)/"
47 $(LN) "../../share/go-$(3)/$(4)" "$(2)/lib/go-$(3)/"
48endef
49
50# $(1) source go root
51# $(2) destination prefix
52# $(3) go version id
53# $(4) GOOS_GOARCH
54# $(5) install suffix (optional)
55define GoCompiler/Default/Install/Bin
56 $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
57
58 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),api)
59
60 $(INSTALL_DATA) -p "$(1)/VERSION" "$(2)/lib/go-$(3)/"
61
62 for file in AUTHORS CONTRIBUTING.md CONTRIBUTORS LICENSE PATENTS README.md SECURITY.md; do \
63 if [ -f "$(1)/$$$$file" ]; then \
64 $(INSTALL_DATA) -p "$(1)/$$$$file" "$(2)/share/go-$(3)/" ; \
65 fi ; \
66 done
67
68 $(INSTALL_DIR) "$(2)/lib/go-$(3)/bin"
69
70 ifeq ($(4),$(GO_HOST_OS_ARCH))
71 $(INSTALL_BIN) -p "$(1)/bin"/* "$(2)/lib/go-$(3)/bin/"
72 else
73 $(INSTALL_BIN) -p "$(1)/bin/$(4)"/* "$(2)/lib/go-$(3)/bin/"
74 endif
75
76 $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg"
77 $(CP) "$(1)/pkg/$(4)$(if $(5),_$(5))" "$(2)/lib/go-$(3)/pkg/"
78
79 $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg/tool/$(4)"
80 $(INSTALL_BIN) -p "$(1)/pkg/tool/$(4)"/* "$(2)/lib/go-$(3)/pkg/tool/$(4)/"
81endef
82
83# $(1) destination prefix
84# $(2) go version id
85define GoCompiler/Default/Install/BinLinks
86 $(INSTALL_DIR) "$(1)/bin"
87 $(LN) "../lib/go-$(2)/bin/go" "$(1)/bin/go"
88 $(LN) "../lib/go-$(2)/bin/gofmt" "$(1)/bin/gofmt"
89endef
90
91# $(1) source go root
92# $(2) destination prefix
93# $(3) go version id
94define GoCompiler/Default/Install/Doc
95 $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
96
97 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),doc)
98endef
99
100# $(1) source go root
101# $(2) destination prefix
102# $(3) go version id
103define GoCompiler/Default/Install/Src
104 $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
105
106 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),lib)
107 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),misc)
108 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),src)
109 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),test)
110
111 $(FIND) \
112 "$(2)/share/go-$(3)/src/" \
113 \! -type d -a \( -name "*.bat" -o -name "*.rc" \) \
114 -delete
115
116 if [ -d "$(1)/pkg/include" ]; then \
117 $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg" ; \
118 $(INSTALL_DIR) "$(2)/share/go-$(3)/pkg" ; \
119 $(CP) "$(1)/pkg/include" "$(2)/share/go-$(3)/pkg/" ; \
120 $(LN) "../../../share/go-$(3)/pkg/include" "$(2)/lib/go-$(3)/pkg/" ; \
121 fi
122endef
123
124# $(1) destination prefix
125# $(2) go version id
126define GoCompiler/Default/Uninstall
127 rm -rf "$(1)/lib/go-$(2)"
128 rm -rf "$(1)/share/go-$(2)"
129endef
130
131# $(1) destination prefix
132define GoCompiler/Default/Uninstall/BinLinks
133 rm -f "$(1)/bin/go"
134 rm -f "$(1)/bin/gofmt"
135endef
136
137
138# $(1) profile name
139# $(2) source go root
140# $(3) destination prefix
141# $(4) go version id
142# $(5) GOOS_GOARCH
143# $(6) install suffix (optional)
144define GoCompiler/AddProfile
145
146 # $$(1) valid GOOS_GOARCH combinations
147 define GoCompiler/$(1)/CheckHost
148 $$(call GoCompiler/Default/CheckHost,$$(1),$(4))
149 endef
150
151 # $$(1) additional environment variables (optional)
152 define GoCompiler/$(1)/Make
153 $$(call GoCompiler/Default/Make,$(2),$(3),$(4),$$(1))
154 endef
155
156 # $$(1) override install prefix (optional)
157 define GoCompiler/$(1)/Install/Bin
158 $$(call GoCompiler/Default/Install/Bin,$(2),$$(or $$(1),$(3)),$(4),$(5),$(6))
159 endef
160
161 # $$(1) override install prefix (optional)
162 define GoCompiler/$(1)/Install/BinLinks
163 $$(call GoCompiler/Default/Install/BinLinks,$$(or $$(1),$(3)),$(4))
164 endef
165
166 # $$(1) override install prefix (optional)
167 define GoCompiler/$(1)/Install/Doc
168 $$(call GoCompiler/Default/Install/Doc,$(2),$$(or $$(1),$(3)),$(4))
169 endef
170
171 # $$(1) override install prefix (optional)
172 define GoCompiler/$(1)/Install/Src
173 $$(call GoCompiler/Default/Install/Src,$(2),$$(or $$(1),$(3)),$(4))
174 endef
175
176 # $$(1) override install prefix (optional)
177 define GoCompiler/$(1)/Uninstall
178 $$(call GoCompiler/Default/Uninstall,$$(or $$(1),$(3)),$(4))
179 endef
180
181 # $$(1) override install prefix (optional)
182 define GoCompiler/$(1)/Uninstall/BinLinks
183 $$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3)))
184 endef
185
186endef