2 # Copyright (C) 2018-2023 Jeffery To
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 ifeq ($(origin GO_INCLUDE_DIR
),undefined
)
9 GO_INCLUDE_DIR
:=$(dir $(lastword
$(MAKEFILE_LIST
)))
13 # Unset environment variables
14 # There are more magic variables to track down, but ain't nobody got time for that
16 # From https://pkg.go.dev/cmd/go#hdr-Environment_variables
18 # General-purpose environment variables:
44 # Environment variables for use with cgo:
49 CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
50 CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \
51 CGO_CXXFLAGS CGO_CXXFLAGS_ALLOW CGO_CXXFLAGS_DISALLOW \
52 CGO_FFLAGS CGO_FFLAGS_ALLOW CGO_FFLAGS_DISALLOW \
53 CGO_LDFLAGS CGO_LDFLAGS_ALLOW CGO_LDFLAGS_DISALLOW \
59 # Architecture-specific environment variables:
69 # Environment variables for use with code coverage:
73 # Special-purpose environment variables:
82 # From https://pkg.go.dev/runtime#hdr-Environment_Variables
90 # From https://pkg.go.dev/cmd/cgo#hdr-Using_cgo_with_the_go_command
95 # CC_FOR_${GOOS}_${GOARCH}
96 # CXX_FOR_${GOOS}_${GOARCH}
98 # From https://go.dev/doc/install/source#environment
103 # From https://go.dev/src/make.bash
112 # From https://go.dev/doc/go1.9#parallel-compile
114 GO19CONCURRENTCOMPILATION
116 # From https://go.dev/src/cmd/dist/build.go
121 # From https://go.dev/src/cmd/dist/buildtool.go
129 aarch64
,arm64
,$(subst \
131 loongarch64
,loong64
,$(subst \
132 mipsel
,mipsle
,$(subst \
133 mips64el
,mips64le
,$(subst \
134 powerpc64
,ppc64
,$(subst \
135 x86_64
,amd64
,$(1))))))))
138 GO_ARCH
:=$(call go_arch
,$(ARCH
))
139 GO_OS_ARCH
:=$(GO_OS
)_
$(GO_ARCH
)
141 GO_HOST_OS
:=$(call tolower
,$(HOST_OS
))
142 GO_HOST_ARCH
:=$(call go_arch
,$(subst \
145 i686
,i386
,$(HOST_ARCH
)))))
146 GO_HOST_OS_ARCH
:=$(GO_HOST_OS
)_
$(GO_HOST_ARCH
)
148 ifeq ($(GO_OS_ARCH
),$(GO_HOST_OS_ARCH
))
149 GO_HOST_TARGET_SAME
:=1
151 GO_HOST_TARGET_DIFFERENT
:=1
154 ifeq ($(GO_ARCH
),386)
155 ifeq ($(CONFIG_TARGET_x86_geode
)$(CONFIG_TARGET_x86_legacy
),y
)
161 # -fno-plt: causes "unexpected GOT reloc for non-dynamic symbol" errors
162 GO_CFLAGS_TO_REMOVE
:=-fno-plt
164 else ifeq ($(GO_ARCH
),amd64
)
167 else ifeq ($(GO_ARCH
),arm
)
168 GO_TARGET_FPU
:=$(word 2,$(subst +,$(space
),$(call qstrip
,$(CONFIG_CPU_TYPE
))))
170 # FPU names from https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gcc/ARM-Options.html#index-mfpu-1
171 # see also https://github.com/gcc-mirror/gcc/blob/releases/gcc-8.4.0/gcc/config/arm/arm-cpus.in
173 ifeq ($(GO_TARGET_FPU
),)
175 else ifneq ($(filter $(GO_TARGET_FPU
),vfp vfpv2
),)
181 else ifneq ($(filter $(GO_ARCH
),mips mipsle
),)
182 ifeq ($(CONFIG_HAS_FPU
),y
)
188 # -mips32r2: conflicts with -march=mips32 set by go
189 GO_CFLAGS_TO_REMOVE
:=-mips32r2
191 else ifneq ($(filter $(GO_ARCH
),mips64 mips64le
),)
192 ifeq ($(CONFIG_HAS_FPU
),y
)
198 else ifeq ($(GO_ARCH
),ppc64
)
206 GO_ARCH_DEPENDS
:=@
(aarch64||arm||i386||i686||loongarch64||mips||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64
)
211 # From https://go.dev/src/internal/platform/supported.go
212 GO_PIE_SUPPORTED_OS_ARCH
:= \
213 android_386 android_amd64 android_arm android_arm64 \
214 linux_386 linux_amd64 linux_arm linux_arm64 \
215 windows_386 windows_amd64 windows_arm windows_arm64 \
217 darwin_amd64 darwin_arm64 \
218 ios_amd64 ios_arm64 \
224 linux_loong64 linux_ppc64le linux_riscv64 linux_s390x
226 # From https://go.dev/src/cmd/go/internal/work/init.go
227 go_pie_install_suffix
=$(if
$(filter $(1),aix_ppc64 windows_386 windows_amd64 windows_arm windows_arm64
),,shared
)
229 ifneq ($(filter $(GO_HOST_OS_ARCH
),$(GO_PIE_SUPPORTED_OS_ARCH
)),)
230 GO_HOST_PIE_SUPPORTED
:=1
231 GO_HOST_PIE_INSTALL_SUFFIX
:=$(call go_pie_install_suffix
,$(GO_HOST_OS_ARCH
))
234 ifneq ($(filter $(GO_OS_ARCH
),$(GO_PIE_SUPPORTED_OS_ARCH
)),)
235 GO_TARGET_PIE_SUPPORTED
:=1
236 GO_TARGET_PIE_INSTALL_SUFFIX
:=$(call go_pie_install_suffix
,$(GO_OS_ARCH
))
240 # Spectre mitigations
242 GO_SPECTRE_SUPPORTED_ARCH
:=amd64
244 ifneq ($(filter $(GO_HOST_ARCH
),$(GO_SPECTRE_SUPPORTED_ARCH
)),)
245 GO_HOST_SPECTRE_SUPPORTED
:=1
248 ifneq ($(filter $(GO_ARCH
),$(GO_SPECTRE_SUPPORTED_ARCH
)),)
249 GO_TARGET_SPECTRE_SUPPORTED
:=1
255 GO_BUILD_CACHE_DIR
:=$(or
$(call qstrip
,$(CONFIG_GOLANG_BUILD_CACHE_DIR
)),$(TMP_DIR
)/go-build
)
256 GO_MOD_CACHE_DIR
:=$(DL_DIR
)/go-mod-cache
261 GO_GENERAL_BUILD_CONFIG_VARS
= \
262 CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE
="$(CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE)" \
263 GO_BUILD_CACHE_DIR
="$(GO_BUILD_CACHE_DIR)" \
264 GO_MOD_CACHE_DIR
="$(GO_MOD_CACHE_DIR)" \
265 GO_MOD_ARGS
="$(GO_MOD_ARGS)"
267 define Go
/CacheCleanup
268 $(GO_GENERAL_BUILD_CONFIG_VARS
) \
269 $(SHELL
) $(GO_INCLUDE_DIR
)/golang-build.sh cache_cleanup