You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
5.7 KiB

  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. ifeq ($(origin GO_INCLUDE_DIR),undefined)
  8. GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
  9. endif
  10. # Unset environment variables
  11. # There are more magic variables to track down, but ain't nobody got time for that
  12. # From https://pkg.go.dev/cmd/go#hdr-Environment_variables
  13. # General-purpose environment variables:
  14. unexport \
  15. GO111MODULE \
  16. GCCGO \
  17. GOARCH \
  18. GOBIN \
  19. GOCACHE \
  20. GOMODCACHE \
  21. GODEBUG \
  22. GOENV \
  23. GOFLAGS \
  24. GOOS \
  25. GOPATH \
  26. GOROOT \
  27. GOTMPDIR \
  28. GOWORK
  29. # Unmodified:
  30. # GOINSECURE
  31. # GOPRIVATE
  32. # GOPROXY
  33. # GONOPROXY
  34. # GOSUMDB
  35. # GONOSUMDB
  36. # GOVCS
  37. # Environment variables for use with cgo:
  38. unexport \
  39. AR \
  40. CC \
  41. CGO_ENABLED \
  42. CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
  43. CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \
  44. CGO_CXXFLAGS CGO_CXXFLAGS_ALLOW CGO_CXXFLAGS_DISALLOW \
  45. CGO_FFLAGS CGO_FFLAGS_ALLOW CGO_FFLAGS_DISALLOW \
  46. CGO_LDFLAGS CGO_LDFLAGS_ALLOW CGO_LDFLAGS_DISALLOW \
  47. CXX \
  48. FC
  49. # Unmodified:
  50. # PKG_CONFIG
  51. # Architecture-specific environment variables:
  52. unexport \
  53. GOARM \
  54. GO386 \
  55. GOAMD64 \
  56. GOMIPS \
  57. GOMIPS64 \
  58. GOPPC64 \
  59. GOWASM
  60. # Special-purpose environment variables:
  61. unexport \
  62. GCCGOTOOLDIR \
  63. GOEXPERIMENT \
  64. GOROOT_FINAL \
  65. GO_EXTLINK_ENABLED
  66. # Unmodified:
  67. # GIT_ALLOW_PROTOCOL
  68. # From https://pkg.go.dev/runtime#hdr-Environment_Variables
  69. unexport \
  70. GOGC \
  71. GOMAXPROCS \
  72. GORACE \
  73. GOTRACEBACK
  74. # From https://pkg.go.dev/cmd/cgo#hdr-Using_cgo_with_the_go_command
  75. unexport \
  76. CC_FOR_TARGET \
  77. CXX_FOR_TARGET
  78. # Todo:
  79. # CC_FOR_${GOOS}_${GOARCH}
  80. # CXX_FOR_${GOOS}_${GOARCH}
  81. # From https://go.dev/doc/install/source#environment
  82. unexport \
  83. GOHOSTOS \
  84. GOHOSTARCH
  85. # From https://go.dev/src/make.bash
  86. unexport \
  87. GO_GCFLAGS \
  88. GO_LDFLAGS \
  89. GO_LDSO \
  90. GO_DISTFLAGS \
  91. GOBUILDTIMELOGFILE \
  92. GOROOT_BOOTSTRAP
  93. # From https://go.dev/doc/go1.9#parallel-compile
  94. unexport \
  95. GO19CONCURRENTCOMPILATION
  96. # From https://go.dev/src/cmd/dist/build.go
  97. unexport \
  98. BOOT_GO_GCFLAGS \
  99. BOOT_GO_LDFLAGS
  100. # From https://go.dev/src/cmd/dist/buildtool.go
  101. unexport \
  102. GOBOOTSTRAP_TOOLEXEC
  103. # GOOS / GOARCH
  104. go_arch=$(subst \
  105. aarch64,arm64,$(subst \
  106. i386,386,$(subst \
  107. mipsel,mipsle,$(subst \
  108. mips64el,mips64le,$(subst \
  109. powerpc64,ppc64,$(subst \
  110. x86_64,amd64,$(1)))))))
  111. GO_OS:=linux
  112. GO_ARCH:=$(call go_arch,$(ARCH))
  113. GO_OS_ARCH:=$(GO_OS)_$(GO_ARCH)
  114. GO_HOST_OS:=$(call tolower,$(HOST_OS))
  115. GO_HOST_ARCH:=$(call go_arch,$(subst \
  116. armv6l,arm,$(subst \
  117. armv7l,arm,$(subst \
  118. i686,i386,$(HOST_ARCH)))))
  119. GO_HOST_OS_ARCH:=$(GO_HOST_OS)_$(GO_HOST_ARCH)
  120. ifeq ($(GO_OS_ARCH),$(GO_HOST_OS_ARCH))
  121. GO_HOST_TARGET_SAME:=1
  122. else
  123. GO_HOST_TARGET_DIFFERENT:=1
  124. endif
  125. ifeq ($(GO_ARCH),386)
  126. ifeq ($(CONFIG_TARGET_x86_geode)$(CONFIG_TARGET_x86_legacy),y)
  127. GO_386:=softfloat
  128. else
  129. GO_386:=sse2
  130. endif
  131. # -fno-plt: causes "unexpected GOT reloc for non-dynamic symbol" errors
  132. GO_CFLAGS_TO_REMOVE:=-fno-plt
  133. else ifeq ($(GO_ARCH),amd64)
  134. GO_AMD64:=v1
  135. else ifeq ($(GO_ARCH),arm)
  136. GO_TARGET_FPU:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
  137. # FPU names from https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gcc/ARM-Options.html#index-mfpu-1
  138. # see also https://github.com/gcc-mirror/gcc/blob/releases/gcc-8.4.0/gcc/config/arm/arm-cpus.in
  139. ifeq ($(GO_TARGET_FPU),)
  140. GO_ARM:=5
  141. else ifneq ($(filter $(GO_TARGET_FPU),vfp vfpv2),)
  142. GO_ARM:=6
  143. else
  144. GO_ARM:=7
  145. endif
  146. else ifneq ($(filter $(GO_ARCH),mips mipsle),)
  147. ifeq ($(CONFIG_HAS_FPU),y)
  148. GO_MIPS:=hardfloat
  149. else
  150. GO_MIPS:=softfloat
  151. endif
  152. # -mips32r2: conflicts with -march=mips32 set by go
  153. GO_CFLAGS_TO_REMOVE:=-mips32r2
  154. else ifneq ($(filter $(GO_ARCH),mips64 mips64le),)
  155. ifeq ($(CONFIG_HAS_FPU),y)
  156. GO_MIPS64:=hardfloat
  157. else
  158. GO_MIPS64:=softfloat
  159. endif
  160. else ifeq ($(GO_ARCH),ppc64)
  161. GO_PPC64:=power8
  162. endif
  163. # Target Go
  164. GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mips64el||mipsel||powerpc64||x86_64)
  165. # ASLR/PIE
  166. # From https://go.dev/src/cmd/internal/sys/supported.go
  167. GO_PIE_SUPPORTED_OS_ARCH:= \
  168. android_386 android_amd64 android_arm android_arm64 \
  169. linux_386 linux_amd64 linux_arm linux_arm64 \
  170. \
  171. windows_386 windows_amd64 windows_arm \
  172. \
  173. darwin_amd64 darwin_arm64 \
  174. ios_amd64 ios_arm64 \
  175. \
  176. freebsd_amd64 \
  177. \
  178. aix_ppc64 \
  179. \
  180. linux_ppc64le linux_riscv64 linux_s390x
  181. # From https://go.dev/src/cmd/go/internal/work/init.go
  182. go_pie_install_suffix=$(if $(filter $(1),aix_ppc64 windows_386 windows_amd64 windows_arm),,shared)
  183. ifneq ($(filter $(GO_HOST_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  184. GO_HOST_PIE_SUPPORTED:=1
  185. GO_HOST_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_HOST_OS_ARCH))
  186. endif
  187. ifneq ($(filter $(GO_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  188. GO_TARGET_PIE_SUPPORTED:=1
  189. GO_TARGET_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_OS_ARCH))
  190. endif
  191. # Spectre mitigations
  192. GO_SPECTRE_SUPPORTED_ARCH:=amd64
  193. ifneq ($(filter $(GO_HOST_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
  194. GO_HOST_SPECTRE_SUPPORTED:=1
  195. endif
  196. ifneq ($(filter $(GO_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
  197. GO_TARGET_SPECTRE_SUPPORTED:=1
  198. endif
  199. # General build info
  200. GO_BUILD_CACHE_DIR:=$(or $(call qstrip,$(CONFIG_GOLANG_BUILD_CACHE_DIR)),$(TMP_DIR)/go-build)
  201. GO_MOD_CACHE_DIR:=$(DL_DIR)/go-mod-cache
  202. GO_MOD_ARGS= \
  203. -modcacherw
  204. GO_GENERAL_BUILD_CONFIG_VARS= \
  205. CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE="$(CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE)" \
  206. GO_BUILD_CACHE_DIR="$(GO_BUILD_CACHE_DIR)" \
  207. GO_MOD_CACHE_DIR="$(GO_MOD_CACHE_DIR)" \
  208. GO_MOD_ARGS="$(GO_MOD_ARGS)"
  209. define Go/CacheCleanup
  210. $(GO_GENERAL_BUILD_CONFIG_VARS) \
  211. $(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh cache_cleanup
  212. endef