1################################################################################ 2# 3# go 4# 5################################################################################ 6 7GO_VERSION = 1.17.3 8GO_SITE = https://storage.googleapis.com/golang 9GO_SOURCE = go$(GO_VERSION).src.tar.gz 10 11GO_LICENSE = BSD-3-Clause 12GO_LICENSE_FILES = LICENSE 13GO_CPE_ID_VENDOR = golang 14 15HOST_GO_DEPENDENCIES = host-go-bootstrap 16HOST_GO_GOPATH = $(HOST_DIR)/usr/share/go-path 17HOST_GO_HOST_CACHE = $(HOST_DIR)/usr/share/host-go-cache 18HOST_GO_ROOT = $(HOST_DIR)/lib/go 19HOST_GO_TARGET_CACHE = $(HOST_DIR)/usr/share/go-cache 20 21# We pass an empty GOBIN, otherwise "go install: cannot install 22# cross-compiled binaries when GOBIN is set" 23HOST_GO_COMMON_ENV = \ 24 GO111MODULE=on \ 25 GOFLAGS=-mod=vendor \ 26 GOROOT="$(HOST_GO_ROOT)" \ 27 GOPATH="$(HOST_GO_GOPATH)" \ 28 GOPROXY=off \ 29 PATH=$(BR_PATH) \ 30 GOBIN= \ 31 CGO_ENABLED=$(HOST_GO_CGO_ENABLED) 32 33ifeq ($(BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS),y) 34 35ifeq ($(BR2_arm),y) 36GO_GOARCH = arm 37ifeq ($(BR2_ARM_CPU_ARMV5),y) 38GO_GOARM = 5 39else ifeq ($(BR2_ARM_CPU_ARMV6),y) 40GO_GOARM = 6 41else ifeq ($(BR2_ARM_CPU_ARMV7A),y) 42GO_GOARM = 7 43else ifeq ($(BR2_ARM_CPU_ARMV8A),y) 44# Go doesn't support 32-bit GOARM=8 (https://github.com/golang/go/issues/29373) 45# but can still benefit from armv7 optimisations 46GO_GOARM = 7 47endif 48else ifeq ($(BR2_aarch64),y) 49GO_GOARCH = arm64 50else ifeq ($(BR2_i386),y) 51GO_GOARCH = 386 52# i386: use softfloat if no SSE2: https://golang.org/doc/go1.16#386 53ifneq ($(BR2_X86_CPU_HAS_SSE2),y) 54GO_GO386 = softfloat 55endif 56else ifeq ($(BR2_x86_64),y) 57GO_GOARCH = amd64 58else ifeq ($(BR2_powerpc64),y) 59GO_GOARCH = ppc64 60else ifeq ($(BR2_powerpc64le),y) 61GO_GOARCH = ppc64le 62else ifeq ($(BR2_mips64),y) 63GO_GOARCH = mips64 64else ifeq ($(BR2_mips64el),y) 65GO_GOARCH = mips64le 66else ifeq ($(BR2_s390x),y) 67GO_GOARCH = s390x 68endif 69 70# For the convienience of target packages. 71HOST_GO_TOOLDIR = $(HOST_GO_ROOT)/pkg/tool/linux_$(GO_GOARCH) 72HOST_GO_TARGET_ENV = \ 73 $(HOST_GO_COMMON_ENV) \ 74 GOARCH=$(GO_GOARCH) \ 75 GOCACHE="$(HOST_GO_TARGET_CACHE)" \ 76 CC="$(TARGET_CC)" \ 77 CXX="$(TARGET_CXX)" \ 78 CGO_CFLAGS="$(TARGET_CFLAGS)" \ 79 CGO_CXXFLAGS="$(TARGET_CXXFLAGS)" \ 80 CGO_LDFLAGS="$(TARGET_LDFLAGS)" \ 81 GOTOOLDIR="$(HOST_GO_TOOLDIR)" 82 83# The go compiler's cgo support uses threads. If BR2_TOOLCHAIN_HAS_THREADS is 84# set, build in cgo support for any go programs that may need it. Note that 85# any target package needing cgo support must include 86# 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file. 87ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y) 88HOST_GO_CGO_ENABLED = 1 89else 90HOST_GO_CGO_ENABLED = 0 91endif 92 93HOST_GO_CROSS_ENV = \ 94 CC_FOR_TARGET="$(TARGET_CC)" \ 95 CXX_FOR_TARGET="$(TARGET_CXX)" \ 96 GOARCH=$(GO_GOARCH) \ 97 $(if $(GO_GO386),GO386=$(GO_GO386)) \ 98 $(if $(GO_GOARM),GOARM=$(GO_GOARM)) \ 99 GO_ASSUME_CROSSCOMPILING=1 100 101else # !BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS 102# host-go can still be used to build packages for the host. No need to set all 103# the arch stuff since we will not be cross-compiling. 104HOST_GO_CGO_ENABLED = 1 105endif # BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS 106 107# For the convenience of host golang packages 108HOST_GO_HOST_ENV = \ 109 $(HOST_GO_COMMON_ENV) \ 110 GOARCH="" \ 111 GOCACHE="$(HOST_GO_HOST_CACHE)" \ 112 CC="$(HOSTCC_NOCCACHE)" \ 113 CXX="$(HOSTCXX_NOCCACHE)" \ 114 CGO_CFLAGS="$(HOST_CFLAGS)" \ 115 CGO_CXXFLAGS="$(HOST_CXXFLAGS)" \ 116 CGO_LDFLAGS="$(HOST_LDFLAGS)" 117 118# The go build system is not compatible with ccache, so use 119# HOSTCC_NOCCACHE. See https://github.com/golang/go/issues/11685. 120HOST_GO_MAKE_ENV = \ 121 GO111MODULE=off \ 122 GOCACHE=$(HOST_GO_HOST_CACHE) \ 123 GOROOT_BOOTSTRAP=$(HOST_GO_BOOTSTRAP_ROOT) \ 124 GOROOT_FINAL=$(HOST_GO_ROOT) \ 125 GOROOT="$(@D)" \ 126 GOBIN="$(@D)/bin" \ 127 GOOS=linux \ 128 CC=$(HOSTCC_NOCCACHE) \ 129 CXX=$(HOSTCXX_NOCCACHE) \ 130 CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \ 131 $(HOST_GO_CROSS_ENV) 132 133define HOST_GO_BUILD_CMDS 134 cd $(@D)/src && \ 135 $(HOST_GO_MAKE_ENV) ./make.bash $(if $(VERBOSE),-v) 136endef 137 138define HOST_GO_INSTALL_CMDS 139 $(INSTALL) -D -m 0755 $(@D)/bin/go $(HOST_GO_ROOT)/bin/go 140 $(INSTALL) -D -m 0755 $(@D)/bin/gofmt $(HOST_GO_ROOT)/bin/gofmt 141 142 ln -sf ../lib/go/bin/go $(HOST_DIR)/bin/ 143 ln -sf ../lib/go/bin/gofmt $(HOST_DIR)/bin/ 144 145 cp -a $(@D)/lib $(HOST_GO_ROOT)/ 146 147 mkdir -p $(HOST_GO_ROOT)/pkg 148 cp -a $(@D)/pkg/include $(@D)/pkg/linux_* $(HOST_GO_ROOT)/pkg/ 149 cp -a $(@D)/pkg/tool $(HOST_GO_ROOT)/pkg/ 150 151 # There is a known issue which requires the go sources to be installed 152 # https://golang.org/issue/2775 153 cp -a $(@D)/src $(HOST_GO_ROOT)/ 154 155 # Set all file timestamps to prevent the go compiler from rebuilding any 156 # built in packages when programs are built. 157 find $(HOST_GO_ROOT) -type f -exec touch -r $(@D)/bin/go {} \; 158endef 159 160$(eval $(host-generic-package)) 161