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.

254 lines
5.5 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. # Environment variables for use with cgo:
  35. unexport \
  36. AR \
  37. CC \
  38. CGO_ENABLED \
  39. CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
  40. CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \
  41. CGO_CXXFLAGS CGO_CXXFLAGS_ALLOW CGO_CXXFLAGS_DISALLOW \
  42. CGO_FFLAGS CGO_FFLAGS_ALLOW CGO_FFLAGS_DISALLOW \
  43. CGO_LDFLAGS CGO_LDFLAGS_ALLOW CGO_LDFLAGS_DISALLOW \
  44. CXX \
  45. FC
  46. # Unmodified:
  47. # PKG_CONFIG
  48. # Architecture-specific environment variables:
  49. unexport \
  50. GOARM \
  51. GO386 \
  52. GOMIPS \
  53. GOMIPS64 \
  54. GOWASM
  55. # Special-purpose environment variables:
  56. unexport \
  57. GCCGOTOOLDIR \
  58. GOROOT_FINAL \
  59. GO_EXTLINK_ENABLED
  60. # Unmodified:
  61. # GIT_ALLOW_PROTOCOL
  62. # From https://golang.org/cmd/go/#hdr-Module_support
  63. unexport \
  64. GO111MODULE
  65. # From https://golang.org/pkg/runtime/#hdr-Environment_Variables
  66. unexport \
  67. GOGC \
  68. GOMAXPROCS \
  69. GORACE \
  70. GOTRACEBACK
  71. # From https://golang.org/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/buildruntime.go
  99. unexport \
  100. GOEXPERIMENT
  101. # From https://golang.org/src/cmd/dist/buildtool.go
  102. unexport \
  103. GOBOOTSTRAP_TOOLEXEC
  104. # GOOS / GOARCH
  105. go_arch=$(subst \
  106. aarch64,arm64,$(subst \
  107. i386,386,$(subst \
  108. mipsel,mipsle,$(subst \
  109. mips64el,mips64le,$(subst \
  110. powerpc64,ppc64,$(subst \
  111. x86_64,amd64,$(1)))))))
  112. GO_OS:=linux
  113. GO_ARCH:=$(call go_arch,$(ARCH))
  114. GO_OS_ARCH:=$(GO_OS)_$(GO_ARCH)
  115. GO_HOST_OS:=$(call tolower,$(HOST_OS))
  116. GO_HOST_ARCH:=$(call go_arch,$(subst \
  117. armv6l,arm,$(subst \
  118. armv7l,arm,$(subst \
  119. i686,i386,$(HOST_ARCH)))))
  120. GO_HOST_OS_ARCH:=$(GO_HOST_OS)_$(GO_HOST_ARCH)
  121. ifeq ($(GO_OS_ARCH),$(GO_HOST_OS_ARCH))
  122. GO_HOST_TARGET_SAME:=1
  123. else
  124. GO_HOST_TARGET_DIFFERENT:=1
  125. endif
  126. ifeq ($(GO_ARCH),386)
  127. # ensure binaries can run on older CPUs
  128. GO_386:=387
  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. GO_PIE_SUPPORTED_OS_ARCH:= \
  161. android_386 android_amd64 android_arm android_arm64 \
  162. linux_386 linux_amd64 linux_arm linux_arm64 \
  163. \
  164. windows_386 windows_amd64 windows_arm \
  165. \
  166. darwin_amd64 \
  167. freebsd_amd64 \
  168. \
  169. aix_ppc64 \
  170. \
  171. linux_ppc64le linux_s390x
  172. go_pie_install_suffix=$(if $(filter $(1),aix_ppc64 windows_386 windows_amd64 windows_arm),,shared)
  173. ifneq ($(filter $(GO_HOST_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  174. GO_HOST_PIE_SUPPORTED:=1
  175. GO_HOST_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_HOST_OS_ARCH))
  176. endif
  177. ifneq ($(filter $(GO_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  178. GO_TARGET_PIE_SUPPORTED:=1
  179. GO_TARGET_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_OS_ARCH))
  180. endif
  181. # Spectre mitigations
  182. GO_SPECTRE_SUPPORTED_ARCH:=amd64
  183. ifneq ($(filter $(GO_HOST_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
  184. GO_HOST_SPECTRE_SUPPORTED:=1
  185. endif
  186. ifneq ($(filter $(GO_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
  187. GO_TARGET_SPECTRE_SUPPORTED:=1
  188. endif
  189. # General build info
  190. GO_BUILD_CACHE_DIR:=$(or $(call qstrip,$(CONFIG_GOLANG_BUILD_CACHE_DIR)),$(TMP_DIR)/go-build)
  191. GO_MOD_CACHE_DIR:=$(DL_DIR)/go-mod-cache
  192. GO_MOD_ARGS= \
  193. -modcacherw
  194. GO_GENERAL_BUILD_CONFIG_VARS= \
  195. CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE="$(CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE)" \
  196. GO_BUILD_CACHE_DIR="$(GO_BUILD_CACHE_DIR)" \
  197. GO_MOD_CACHE_DIR="$(GO_MOD_CACHE_DIR)" \
  198. GO_MOD_ARGS="$(GO_MOD_ARGS)"
  199. define Go/CacheCleanup
  200. $(GO_GENERAL_BUILD_CONFIG_VARS) \
  201. $(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh cache_cleanup
  202. endef