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.

234 lines
5.2 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. GODEBUG \
  20. GOENV \
  21. GOFLAGS \
  22. GOOS \
  23. GOPATH \
  24. GOROOT \
  25. GOTMPDIR
  26. # Unmodified:
  27. # GOPRIVATE
  28. # GOPROXY
  29. # GONOPROXY
  30. # GOSUMDB
  31. # GONOSUMDB
  32. # Environment variables for use with cgo:
  33. unexport \
  34. AR \
  35. CC \
  36. CGO_ENABLED \
  37. CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
  38. CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \
  39. CGO_CXXFLAGS CGO_CXXFLAGS_ALLOW CGO_CXXFLAGS_DISALLOW \
  40. CGO_FFLAGS CGO_FFLAGS_ALLOW CGO_FFLAGS_DISALLOW \
  41. CGO_LDFLAGS CGO_LDFLAGS_ALLOW CGO_LDFLAGS_DISALLOW \
  42. CXX \
  43. FC
  44. # Unmodified:
  45. # PKG_CONFIG
  46. # Architecture-specific environment variables:
  47. unexport \
  48. GOARM \
  49. GO386 \
  50. GOMIPS \
  51. GOMIPS64 \
  52. GOWASM
  53. # Special-purpose environment variables:
  54. unexport \
  55. GCCGOTOOLDIR \
  56. GOROOT_FINAL \
  57. GO_EXTLINK_ENABLED
  58. # Unmodified:
  59. # GIT_ALLOW_PROTOCOL
  60. # From https://golang.org/cmd/go/#hdr-Module_support
  61. unexport \
  62. GO111MODULE
  63. # From https://golang.org/pkg/runtime/#hdr-Environment_Variables
  64. unexport \
  65. GOGC \
  66. GOMAXPROCS \
  67. GORACE \
  68. GOTRACEBACK
  69. # From https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command
  70. unexport \
  71. CC_FOR_TARGET \
  72. CXX_FOR_TARGET
  73. # Todo:
  74. # CC_FOR_${GOOS}_${GOARCH}
  75. # CXX_FOR_${GOOS}_${GOARCH}
  76. # From https://golang.org/doc/install/source#environment
  77. unexport \
  78. GOHOSTOS \
  79. GOHOSTARCH \
  80. GOPPC64
  81. # From https://golang.org/src/make.bash
  82. unexport \
  83. GO_GCFLAGS \
  84. GO_LDFLAGS \
  85. GO_LDSO \
  86. GO_DISTFLAGS \
  87. GOBUILDTIMELOGFILE \
  88. GOROOT_BOOTSTRAP
  89. # From https://golang.org/doc/go1.9#parallel-compile
  90. unexport \
  91. GO19CONCURRENTCOMPILATION
  92. # From https://golang.org/src/cmd/dist/build.go
  93. unexport \
  94. BOOT_GO_GCFLAGS \
  95. BOOT_GO_LDFLAGS
  96. # From https://golang.org/src/cmd/dist/buildtool.go
  97. unexport \
  98. GOBOOTSTRAP_TOOLEXEC
  99. # From https://golang.org/src/cmd/internal/objabi/util.go
  100. unexport \
  101. GOEXPERIMENT
  102. # GOOS / GOARCH
  103. go_arch=$(subst \
  104. aarch64,arm64,$(subst \
  105. i386,386,$(subst \
  106. mipsel,mipsle,$(subst \
  107. mips64el,mips64le,$(subst \
  108. powerpc64,ppc64,$(subst \
  109. x86_64,amd64,$(1)))))))
  110. GO_OS:=linux
  111. GO_ARCH:=$(call go_arch,$(ARCH))
  112. GO_OS_ARCH:=$(GO_OS)_$(GO_ARCH)
  113. GO_HOST_OS:=$(call tolower,$(HOST_OS))
  114. GO_HOST_ARCH:=$(call go_arch,$(subst \
  115. armv6l,arm,$(subst \
  116. armv7l,arm,$(subst \
  117. i686,i386,$(HOST_ARCH)))))
  118. GO_HOST_OS_ARCH:=$(GO_HOST_OS)_$(GO_HOST_ARCH)
  119. ifeq ($(GO_OS_ARCH),$(GO_HOST_OS_ARCH))
  120. GO_HOST_TARGET_SAME:=1
  121. else
  122. GO_HOST_TARGET_DIFFERENT:=1
  123. endif
  124. ifeq ($(GO_ARCH),386)
  125. # ensure binaries can run on older CPUs
  126. GO_386:=387
  127. # -fno-plt: causes "unexpected GOT reloc for non-dynamic symbol" errors
  128. GO_CFLAGS_TO_REMOVE:=-fno-plt
  129. else ifeq ($(GO_ARCH),arm)
  130. GO_TARGET_FPU:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
  131. # FPU names from https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/ARM-Options.html#index-mfpu-1
  132. # see also https://github.com/gcc-mirror/gcc/blob/gcc-8_3_0-release/gcc/config/arm/arm-cpus.in
  133. #
  134. # Assumptions:
  135. #
  136. # * -d16 variants (16 instead of 32 double-precision registers) acceptable
  137. # Go doesn't appear to check the HWCAP_VFPv3D16 flag in
  138. # https://github.com/golang/go/blob/release-branch.go1.13/src/runtime/os_linux_arm.go
  139. #
  140. # * Double-precision required
  141. # Based on no evidence(!)
  142. # Excludes vfpv3xd, vfpv3xd-fp16, fpv4-sp-d16, fpv5-sp-d16
  143. GO_ARM_7_FPUS:= \
  144. vfpv3 vfpv3-fp16 vfpv3-d16 vfpv3-d16-fp16 neon neon-vfpv3 neon-fp16 \
  145. vfpv4 vfpv4-d16 neon-vfpv4 \
  146. fpv5-d16 fp-armv8 neon-fp-armv8 crypto-neon-fp-armv8
  147. GO_ARM_6_FPUS:=vfp vfpv2
  148. ifneq ($(filter $(GO_TARGET_FPU),$(GO_ARM_7_FPUS)),)
  149. GO_ARM:=7
  150. else ifneq ($(filter $(GO_TARGET_FPU),$(GO_ARM_6_FPUS)),)
  151. GO_ARM:=6
  152. else
  153. GO_ARM:=5
  154. endif
  155. else ifneq ($(filter $(GO_ARCH),mips mipsle),)
  156. ifeq ($(CONFIG_HAS_FPU),y)
  157. GO_MIPS:=hardfloat
  158. else
  159. GO_MIPS:=softfloat
  160. endif
  161. # -mips32r2: conflicts with -march=mips32 set by go
  162. GO_CFLAGS_TO_REMOVE:=-mips32r2
  163. else ifneq ($(filter $(GO_ARCH),mips64 mips64le),)
  164. ifeq ($(CONFIG_HAS_FPU),y)
  165. GO_MIPS64:=hardfloat
  166. else
  167. GO_MIPS64:=softfloat
  168. endif
  169. endif
  170. # Target Go
  171. GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mips64el||mipsel||powerpc64||x86_64)
  172. # ASLR/PIE
  173. GO_PIE_SUPPORTED_OS_ARCH:= \
  174. android_386 android_amd64 android_arm android_arm64 \
  175. linux_386 linux_amd64 linux_arm linux_arm64 \
  176. \
  177. darwin_amd64 \
  178. freebsd_amd64 \
  179. \
  180. aix_ppc64 \
  181. \
  182. linux_ppc64le linux_s390x
  183. go_pie_install_suffix=$(if $(filter $(1),aix_ppc64),,shared)
  184. ifneq ($(filter $(GO_HOST_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  185. GO_HOST_PIE_SUPPORTED:=1
  186. GO_HOST_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_HOST_OS_ARCH))
  187. endif
  188. ifneq ($(filter $(GO_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  189. GO_TARGET_PIE_SUPPORTED:=1
  190. GO_TARGET_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_OS_ARCH))
  191. endif