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.

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