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.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. include $(GO_INCLUDE_DIR)/golang-version.mk
  11. # Unset environment variables
  12. # There are more magic variables to track down, but ain't nobody got time for that
  13. # From https://golang.org/cmd/go/#hdr-Environment_variables
  14. # General-purpose environment variables:
  15. unexport \
  16. GCCGO \
  17. GOARCH \
  18. GOBIN \
  19. GOCACHE \
  20. GODEBUG \
  21. GOENV \
  22. GOFLAGS \
  23. GOOS \
  24. GOPATH \
  25. GOROOT \
  26. GOTMPDIR
  27. # Unmodified:
  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. ifeq ($(CONFIG_arm_v7),y)
  132. GO_ARM:=7
  133. else ifeq ($(CONFIG_arm_v6),y)
  134. GO_ARM:=6
  135. else
  136. GO_ARM:=5
  137. endif
  138. else ifneq ($(filter $(GO_ARCH),mips mipsle),)
  139. ifeq ($(CONFIG_HAS_FPU),y)
  140. GO_MIPS:=hardfloat
  141. else
  142. GO_MIPS:=softfloat
  143. endif
  144. # -mips32r2: conflicts with -march=mips32 set by go
  145. GO_CFLAGS_TO_REMOVE:=-mips32r2
  146. else ifneq ($(filter $(GO_ARCH),mips64 mips64le),)
  147. ifeq ($(CONFIG_HAS_FPU),y)
  148. GO_MIPS64:=hardfloat
  149. else
  150. GO_MIPS64:=softfloat
  151. endif
  152. endif
  153. # Target Go
  154. GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mips64el||mipsel||powerpc64||x86_64)
  155. GO_TARGET_PREFIX:=/usr
  156. GO_TARGET_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
  157. GO_TARGET_ROOT:=$(GO_TARGET_PREFIX)/lib/go-$(GO_TARGET_VERSION_ID)
  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