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.

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