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