libre2: fix pkgconfig paths
[feed/packages.git] / lang / golang / golang-compiler.mk
1 #
2 # Copyright (C) 2018, 2020-2021, 2023 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)/go.env" "$(2)/lib/go-$(3)/"
64 $(INSTALL_DATA) -p "$(1)/VERSION" "$(2)/lib/go-$(3)/"
65
66 for file in CONTRIBUTING.md LICENSE PATENTS README.md SECURITY.md; do \
67 if [ -f "$(1)/$$$$file" ]; then \
68 $(INSTALL_DATA) -p "$(1)/$$$$file" "$(2)/share/go-$(3)/" ; \
69 fi ; \
70 done
71
72 $(INSTALL_DIR) "$(2)/lib/go-$(3)/bin"
73
74 ifeq ($(4),$(GO_HOST_OS_ARCH))
75 $(INSTALL_BIN) -p "$(1)/bin"/* "$(2)/lib/go-$(3)/bin/"
76 else
77 $(INSTALL_BIN) -p "$(1)/bin/$(4)"/* "$(2)/lib/go-$(3)/bin/"
78 endif
79
80 if [ -d "$(1)/pkg/$(4)$(if $(5),_$(5))" ]; then \
81 $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg" ; \
82 $(CP) "$(1)/pkg/$(4)$(if $(5),_$(5))" "$(2)/lib/go-$(3)/pkg/" ; \
83 fi
84
85 $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg/tool/$(4)"
86 $(INSTALL_BIN) -p "$(1)/pkg/tool/$(4)"/* "$(2)/lib/go-$(3)/pkg/tool/$(4)/"
87 endef
88
89 # $(1) destination prefix
90 # $(2) go version id
91 define GoCompiler/Default/Install/BinLinks
92 $(INSTALL_DIR) "$(1)/bin"
93 $(LN) "../lib/go-$(2)/bin/go" "$(1)/bin/go"
94 $(LN) "../lib/go-$(2)/bin/gofmt" "$(1)/bin/gofmt"
95 endef
96
97 # $(1) source go root
98 # $(2) destination prefix
99 # $(3) go version id
100 define GoCompiler/Default/Install/Doc
101 $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
102
103 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),doc)
104 endef
105
106 # $(1) source go root
107 # $(2) destination prefix
108 # $(3) go version id
109 define GoCompiler/Default/Install/Src
110 $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
111
112 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),lib)
113 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),misc)
114 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),src)
115 $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),test)
116
117 $(FIND) \
118 "$(2)/share/go-$(3)/src/" \
119 \! -type d -a \( -name "*.bat" -o -name "*.rc" \) \
120 -delete
121
122 if [ -d "$(1)/pkg/include" ]; then \
123 $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg" ; \
124 $(INSTALL_DIR) "$(2)/share/go-$(3)/pkg" ; \
125 $(CP) "$(1)/pkg/include" "$(2)/share/go-$(3)/pkg/" ; \
126 $(LN) "../../../share/go-$(3)/pkg/include" "$(2)/lib/go-$(3)/pkg/" ; \
127 fi
128 endef
129
130 # $(1) destination prefix
131 # $(2) go version id
132 define GoCompiler/Default/Uninstall
133 rm -rf "$(1)/lib/go-$(2)"
134 rm -rf "$(1)/share/go-$(2)"
135 endef
136
137 # $(1) destination prefix
138 define GoCompiler/Default/Uninstall/BinLinks
139 rm -f "$(1)/bin/go"
140 rm -f "$(1)/bin/gofmt"
141 endef
142
143
144 # $(1) profile name
145 # $(2) source go root
146 # $(3) destination prefix
147 # $(4) go version id
148 # $(5) GOOS_GOARCH
149 # $(6) install suffix (optional)
150 define GoCompiler/AddProfile
151
152 # $$(1) valid GOOS_GOARCH combinations
153 define GoCompiler/$(1)/CheckHost
154 $$(call GoCompiler/Default/CheckHost,$$(1),$(4))
155 endef
156
157 # $$(1) additional environment variables (optional)
158 define GoCompiler/$(1)/Make
159 $$(call GoCompiler/Default/Make,$(2),$(3),$(4),$$(1))
160 endef
161
162 # $$(1) override install prefix (optional)
163 define GoCompiler/$(1)/Install/Bin
164 $$(call GoCompiler/Default/Install/Bin,$(2),$$(or $$(1),$(3)),$(4),$(5),$(6))
165 endef
166
167 # $$(1) override install prefix (optional)
168 define GoCompiler/$(1)/Install/BinLinks
169 $$(call GoCompiler/Default/Install/BinLinks,$$(or $$(1),$(3)),$(4))
170 endef
171
172 # $$(1) override install prefix (optional)
173 define GoCompiler/$(1)/Install/Doc
174 $$(call GoCompiler/Default/Install/Doc,$(2),$$(or $$(1),$(3)),$(4))
175 endef
176
177 # $$(1) override install prefix (optional)
178 define GoCompiler/$(1)/Install/Src
179 $$(call GoCompiler/Default/Install/Src,$(2),$$(or $$(1),$(3)),$(4))
180 endef
181
182 # $$(1) override install prefix (optional)
183 define GoCompiler/$(1)/Uninstall
184 $$(call GoCompiler/Default/Uninstall,$$(or $$(1),$(3)),$(4))
185 endef
186
187 # $$(1) override install prefix (optional)
188 define GoCompiler/$(1)/Uninstall/BinLinks
189 $$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3)))
190 endef
191
192 endef