golang: Set/reset default platform options for target Go compiler
authorJeffery To <redacted>
Thu, 14 May 2020 09:45:18 +0000 (17:45 +0800)
committerJeffery To <redacted>
Thu, 14 May 2020 09:45:18 +0000 (17:45 +0800)
Because the first stage for building target Go is actually a host build,
the default platform options (GO386, GOARM, etc.) are detected from the
host. These values are written to a source file and kept when building
the second stage.

This modifies this source file to set the appropriate values for the
target platform, and reset values for other platforms to their
cross-compiling / most compatible defaults.

Signed-off-by: Jeffery To <redacted>
lang/golang/golang/Makefile

index 54091398ef2ba64f6fb89ad03643bee134db391a..51020253b4f1860937043a7eda2601a7ed26072f 100644 (file)
@@ -197,6 +197,13 @@ endef
 EXTERNAL_BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
 USE_DEFAULT_BOOTSTRAP:=$(if $(EXTERNAL_BOOTSTRAP_DIR),,1)
 
+PKG_GO_ZBOOTSTRAP_MODS:= \
+       s/defaultGO386 = `[^`]*`/defaultGO386 = `$(if $(GO_386),$(GO_386),387)`/; \
+       s/defaultGOARM = `[^`]*`/defaultGOARM = `$(if $(GO_ARM),$(GO_ARM),5)`/; \
+       s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(if $(GO_MIPS),$(GO_MIPS),hardfloat)`/; \
+       s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(if $(GO_MIPS64),$(GO_MIPS64),hardfloat)`/; \
+       s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `power8`/;
+
 PKG_GO_LDFLAGS= \
        -buildid '$(SOURCE_DATE_EPOCH)'
 
@@ -323,6 +330,11 @@ define Build/Compile
                PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
        )
 
+  ifneq ($(PKG_GO_ZBOOTSTRAP_MODS),)
+       $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' \
+               $(PKG_BUILD_DIR)/src/cmd/internal/objabi/zbootstrap.go
+  endif
+
        @echo "Building target Go second stage"
 
        ( \
git clone https://git.99rst.org/PROJECT