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.

218 lines
4.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. 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.4.0/gcc/ARM-Options.html#index-mfpu-1
  133. # see also https://github.com/gcc-mirror/gcc/blob/releases/gcc-8.4.0/gcc/config/arm/arm-cpus.in
  134. ifeq ($(GO_TARGET_FPU),)
  135. GO_ARM:=5
  136. else ifneq ($(filter $(GO_TARGET_FPU),vfp vfpv2),)
  137. GO_ARM:=6
  138. else
  139. GO_ARM:=7
  140. endif
  141. else ifneq ($(filter $(GO_ARCH),mips mipsle),)
  142. ifeq ($(CONFIG_HAS_FPU),y)
  143. GO_MIPS:=hardfloat
  144. else
  145. GO_MIPS:=softfloat
  146. endif
  147. # -mips32r2: conflicts with -march=mips32 set by go
  148. GO_CFLAGS_TO_REMOVE:=-mips32r2
  149. else ifneq ($(filter $(GO_ARCH),mips64 mips64le),)
  150. ifeq ($(CONFIG_HAS_FPU),y)
  151. GO_MIPS64:=hardfloat
  152. else
  153. GO_MIPS64:=softfloat
  154. endif
  155. endif
  156. # Target Go
  157. GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mips64el||mipsel||powerpc64||x86_64)
  158. # ASLR/PIE
  159. GO_PIE_SUPPORTED_OS_ARCH:= \
  160. android_386 android_amd64 android_arm android_arm64 \
  161. linux_386 linux_amd64 linux_arm linux_arm64 \
  162. \
  163. darwin_amd64 \
  164. freebsd_amd64 \
  165. \
  166. aix_ppc64 \
  167. \
  168. linux_ppc64le linux_s390x
  169. go_pie_install_suffix=$(if $(filter $(1),aix_ppc64),,shared)
  170. ifneq ($(filter $(GO_HOST_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  171. GO_HOST_PIE_SUPPORTED:=1
  172. GO_HOST_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_HOST_OS_ARCH))
  173. endif
  174. ifneq ($(filter $(GO_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
  175. GO_TARGET_PIE_SUPPORTED:=1
  176. GO_TARGET_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_OS_ARCH))
  177. endif