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.

259 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://golang.org/cmd/go/#hdr-Environment_variables
  13. # General-purpose environment variables:
  14. unexport \
  15. GCCGO \
  16. GOARCH \
  17. GOBIN \
  18. GOCACHE \
  19. GOMODCACHE \
  20. GODEBUG \
  21. GOENV \
  22. GOFLAGS \
  23. GOOS \
  24. GOPATH \
  25. GOROOT \
  26. GOTMPDIR
  27. # Unmodified:
  28. # GOINSECURE
  29. # GOPRIVATE
  30. # GOPROXY
  31. # GONOPROXY
  32. # GOSUMDB
  33. # GONOSUMDB
  34. # GOVCS
  35. # Environment variables for use with cgo:
  36. unexport \
  37. AR \
  38. CC \
  39. CGO_ENABLED \
  40. CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
  41. CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \
  42. CGO_CXXFLAGS CGO_CXXFLAGS_ALLOW CGO_CXXFLAGS_DISALLOW \
  43. CGO_FFLAGS CGO_FFLAGS_ALLOW CGO_FFLAGS_DISALLOW \
  44. CGO_LDFLAGS CGO_LDFLAGS_ALLOW CGO_LDFLAGS_DISALLOW \
  45. CXX \
  46. FC
  47. # Unmodified:
  48. # PKG_CONFIG
  49. # Architecture-specific environment variables:
  50. unexport \
  51. GOARM \
  52. GO386 \
  53. GOMIPS \
  54. GOMIPS64 \
  55. GOWASM
  56. # Special-purpose environment variables:
  57. unexport \
  58. GCCGOTOOLDIR \
  59. GOROOT_FINAL \
  60. GO_EXTLINK_ENABLED
  61. # Unmodified:
  62. # GIT_ALLOW_PROTOCOL
  63. # From https://golang.org/cmd/go/#hdr-Module_support
  64. unexport \
  65. GO111MODULE
  66. # From https://golang.org/pkg/runtime/#hdr-Environment_Variables
  67. unexport \
  68. GOGC \
  69. GOMAXPROCS \
  70. GORACE \
  71. GOTRACEBACK
  72. # From https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command
  73. unexport \
  74. CC_FOR_TARGET \
  75. CXX_FOR_TARGET
  76. # Todo:
  77. # CC_FOR_${GOOS}_${GOARCH}
  78. # CXX_FOR_${GOOS}_${GOARCH}
  79. # From https://golang.org/doc/install/source#environment
  80. unexport \
  81. GOHOSTOS \
  82. GOHOSTARCH \
  83. GOPPC64
  84. # From https://golang.org/src/make.bash
  85. unexport \
  86. GO_GCFLAGS \
  87. GO_LDFLAGS \
  88. GO_LDSO \
  89. GO_DISTFLAGS \
  90. GOBUILDTIMELOGFILE \
  91. GOROOT_BOOTSTRAP
  92. # From https://golang.org/doc/go1.9#parallel-compile
  93. unexport \
  94. GO19CONCURRENTCOMPILATION
  95. # From https://golang.org/src/cmd/dist/build.go
  96. unexport \
  97. BOOT_GO_GCFLAGS \
  98. BOOT_GO_LDFLAGS
  99. # From https://golang.org/src/cmd/dist/buildruntime.go
  100. unexport \
  101. GOEXPERIMENT
  102. # From https://golang.org/src/cmd/dist/buildtool.go
  103. unexport \
  104. GOBOOTSTRAP_TOOLEXEC
  105. # GOOS / GOARCH
  106. go_arch=$(subst \
  107. aarch64,arm64,$(subst \
  108. i386,386,$(subst \
  109. mipsel,mipsle,$(subst \
  110. mips64el,mips64le,$(subst \
  111. powerpc64,ppc64,$(subst \
  112. x86_64,amd64,$(1)))))))
  113. GO_OS:=linux
  114. GO_ARCH:=$(call go_arch,$(ARCH))
  115. GO_OS_ARCH:=$(GO_OS)_$(GO_ARCH)
  116. GO_HOST_OS:=$(call tolower,$(HOST_OS))
  117. GO_HOST_ARCH:=$(call go_arch,$(subst \
  118. armv6l,arm,$(subst \
  119. armv7l,arm,$(subst \
  120. i686,i386,$(HOST_ARCH)))))
  121. GO_HOST_OS_ARCH:=$(GO_HOST_OS)_$(GO_HOST_ARCH)
  122. ifeq ($(GO_OS_ARCH),$(GO_HOST_OS_ARCH))
  123. GO_HOST_TARGET_SAME:=1
  124. else
  125. GO_HOST_TARGET_DIFFERENT:=1
  126. endif
  127. ifeq ($(GO_ARCH),386)
  128. ifeq ($(CONFIG_TARGET_x86_geode)$(CONFIG_TARGET_x86_legacy),y)
  129. GO_386:=softfloat
  130. else
  131. GO_386:=sse2
  132. endif
  133. # -fno-plt: causes "unexpected GOT reloc for non-dynamic symbol" errors
  134. GO_CFLAGS_TO_REMOVE:=-fno-plt
  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. endif
  161. # Target Go
  162. GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mips64el||mipsel||powerpc64||x86_64)
  163. # ASLR/PIE
  164. GO_PIE_SUPPORTED_OS_ARCH:= \
  165. android_386 android_amd64 android_arm android_arm64 \
  166. linux_386 linux_amd64 linux_arm linux_arm64 \
  167. \
  168. windows_386 windows_amd64 windows_arm \
  169. \
  170. darwin_amd64 darwin_arm64 \
  171. \
  172. freebsd_amd64 \
  173. \
  174. aix_ppc64 \
  175. \
  176. linux_ppc64le linux_riscv64 linux_s390x
  177. go_pie_install_suffix=$(if $(filter $(1),aix_ppc64 windows_386 windows_amd64 windows_arm),,shared)
  178. ifneq ($(filter $(GO_HOST_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  179. GO_HOST_PIE_SUPPORTED:=1
  180. GO_HOST_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_HOST_OS_ARCH))
  181. endif
  182. ifneq ($(filter $(GO_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  183. GO_TARGET_PIE_SUPPORTED:=1
  184. GO_TARGET_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_OS_ARCH))
  185. endif
  186. # Spectre mitigations
  187. GO_SPECTRE_SUPPORTED_ARCH:=amd64
  188. ifneq ($(filter $(GO_HOST_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
  189. GO_HOST_SPECTRE_SUPPORTED:=1
  190. endif
  191. ifneq ($(filter $(GO_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
  192. GO_TARGET_SPECTRE_SUPPORTED:=1
  193. endif
  194. # General build info
  195. GO_BUILD_CACHE_DIR:=$(or $(call qstrip,$(CONFIG_GOLANG_BUILD_CACHE_DIR)),$(TMP_DIR)/go-build)
  196. GO_MOD_CACHE_DIR:=$(DL_DIR)/go-mod-cache
  197. GO_MOD_ARGS= \
  198. -modcacherw
  199. GO_GENERAL_BUILD_CONFIG_VARS= \
  200. CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE="$(CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE)" \
  201. GO_BUILD_CACHE_DIR="$(GO_BUILD_CACHE_DIR)" \
  202. GO_MOD_CACHE_DIR="$(GO_MOD_CACHE_DIR)" \
  203. GO_MOD_ARGS="$(GO_MOD_ARGS)"
  204. define Go/CacheCleanup
  205. $(GO_GENERAL_BUILD_CONFIG_VARS) \
  206. $(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh cache_cleanup
  207. endef