mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-11 02:44:57 +08:00
🎈 Sync 2026-06-17 11:53:25
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2018, 2020 Jeffery To
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
me=go-gcc-helper
|
||||
name="${0##*/}"
|
||||
|
||||
log() {
|
||||
local IFS=" "
|
||||
printf '%s\n' "$me: $*"
|
||||
}
|
||||
|
||||
case "$name" in
|
||||
gcc)
|
||||
if [ -z "$GO_GCC_HELPER_CC" ]; then
|
||||
log "missing GO_GCC_HELPER_CC"
|
||||
exit 1
|
||||
fi
|
||||
cmd="$GO_GCC_HELPER_CC"
|
||||
;;
|
||||
g++)
|
||||
if [ -z "$GO_GCC_HELPER_CXX" ]; then
|
||||
log "missing GO_GCC_HELPER_CXX"
|
||||
exit 1
|
||||
fi
|
||||
cmd="$GO_GCC_HELPER_CXX"
|
||||
;;
|
||||
*)
|
||||
log "unknown command \"$name\""
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$GO_GCC_HELPER_PATH" ]; then
|
||||
export PATH="$GO_GCC_HELPER_PATH"
|
||||
else
|
||||
log "missing GO_GCC_HELPER_PATH"
|
||||
fi
|
||||
|
||||
log "running $cmd $*"
|
||||
|
||||
$cmd "$@"
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2026 George Sapkin
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
for last; do :; done
|
||||
|
||||
case "$last" in
|
||||
*-doc|*-misc|*-src|*-tests)
|
||||
echo "Not stripping: $last"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
"$@"
|
||||
@@ -0,0 +1,47 @@
|
||||
menu "Configuration"
|
||||
|
||||
config GOLANG_EXTERNAL_BOOTSTRAP_ROOT
|
||||
string "External bootstrap Go root directory"
|
||||
default ""
|
||||
help
|
||||
Path to a working Go tree (>= Go 1.4), with bin, pkg, and src
|
||||
subdirectories and the Go compiler in bin/go.
|
||||
|
||||
If set, the existing Go installation will be used to compile host
|
||||
(buildroot) Go.
|
||||
|
||||
Leave blank to compile the default bootstrap Go.
|
||||
|
||||
config GOLANG_BUILD_BOOTSTRAP
|
||||
bool "Build bootstrap instead of using an external one"
|
||||
default y
|
||||
help
|
||||
When enabled, build the local bootstrap instead of using an external one
|
||||
for host Go. If 'External bootstrap Go root directory' is set, skip the
|
||||
initial 1.4 step.
|
||||
|
||||
When disabled, let Go auto-detect the toolchain or use the toolchain
|
||||
specified in 'External bootstrap Go root directory' to skip building the
|
||||
bootstrap and build host Go using that toolchain directly. Configured
|
||||
toolchain must be compatible with the current version of Go.
|
||||
|
||||
config GOLANG_BUILD_CACHE_DIR
|
||||
string "Go build cache directory"
|
||||
default ""
|
||||
help
|
||||
Path where Go should store its build cache.
|
||||
|
||||
If not set, uses '$(TMP_DIR)/go-build'.
|
||||
|
||||
config GOLANG_MOD_CACHE_WORLD_READABLE
|
||||
bool "Ensure Go module cache is world-readable"
|
||||
default n
|
||||
|
||||
config GOLANG_SPECTRE
|
||||
bool "Enable Spectre mitigations"
|
||||
default n
|
||||
depends on x86_64
|
||||
help
|
||||
Currently only available for x86-64 (amd64).
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,341 @@
|
||||
#
|
||||
# Copyright (C) 2018-2023 Jeffery To
|
||||
# Copyright (C) 2025-2026 George Sapkin
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
GO_VERSION_MAJOR_MINOR:=1.24
|
||||
GO_VERSION_PATCH:=13
|
||||
PKG_HASH:=639a6204c2486b137df1eb6e78ee3ed038f9877d0e4b5a465e796a2153f858d7
|
||||
|
||||
PKG_NAME:=golang-bootstrap
|
||||
PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
|
||||
PKG_RELEASE:=1
|
||||
|
||||
GO_SOURCE_URLS:=https://go.dev/dl/ \
|
||||
https://golang.google.cn/dl/ \
|
||||
https://mirrors.nju.edu.cn/golang/ \
|
||||
https://mirrors.ustc.edu.cn/golang/
|
||||
|
||||
PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz
|
||||
PKG_SOURCE_URL:=$(GO_SOURCE_URLS)
|
||||
|
||||
PKG_MAINTAINER:=George Sapkin <george@sapk.in>
|
||||
PKG_LICENSE:=BSD-3-Clause
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_CPE_ID:=cpe:/a:golang:go
|
||||
|
||||
PKG_HOST_ONLY:=1
|
||||
|
||||
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
|
||||
HOST_BUILD_PARALLEL:=1
|
||||
|
||||
HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG)
|
||||
HOST_GO_VERSION_ID:=bootstrap
|
||||
HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID)
|
||||
|
||||
# From go tool dist list
|
||||
HOST_GO_VALID_OS_ARCH:= \
|
||||
aix/ppc64 \
|
||||
android/386 \
|
||||
android/amd64 \
|
||||
android/arm \
|
||||
android/arm64 \
|
||||
darwin/amd64 \
|
||||
darwin/arm64 \
|
||||
dragonfly/amd64 \
|
||||
freebsd/386 \
|
||||
freebsd/amd64 \
|
||||
freebsd/arm \
|
||||
freebsd/arm64 \
|
||||
freebsd/riscv64 \
|
||||
illumos/amd64 \
|
||||
ios/amd64 \
|
||||
ios/arm64 \
|
||||
js/wasm \
|
||||
linux/386 \
|
||||
linux/amd64 \
|
||||
linux/arm \
|
||||
linux/arm64 \
|
||||
linux/loong64 \
|
||||
linux/mips \
|
||||
linux/mips64 \
|
||||
linux/mips64le \
|
||||
linux/mipsle \
|
||||
linux/ppc64 \
|
||||
linux/ppc64le \
|
||||
linux/riscv64 \
|
||||
linux/s390x \
|
||||
netbsd/386 \
|
||||
netbsd/amd64 \
|
||||
netbsd/arm \
|
||||
netbsd/arm64 \
|
||||
openbsd/386 \
|
||||
openbsd/amd64 \
|
||||
openbsd/arm \
|
||||
openbsd/arm64 \
|
||||
openbsd/ppc64 \
|
||||
openbsd/riscv64 \
|
||||
plan9/386 \
|
||||
plan9/amd64 \
|
||||
plan9/arm \
|
||||
solaris/amd64 \
|
||||
wasip1/wasm \
|
||||
windows/386 \
|
||||
windows/amd64 \
|
||||
windows/arm64
|
||||
|
||||
BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz
|
||||
BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS)
|
||||
BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
|
||||
|
||||
BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap
|
||||
|
||||
BOOTSTRAP_GO_VALID_OS_ARCH:= \
|
||||
darwin/386 \
|
||||
darwin/amd64 \
|
||||
dragonfly/386 \
|
||||
dragonfly/amd64 \
|
||||
freebsd/386 \
|
||||
freebsd/amd64 \
|
||||
freebsd/arm \
|
||||
linux/386 \
|
||||
linux/amd64 \
|
||||
linux/arm \
|
||||
netbsd/386 \
|
||||
netbsd/amd64 \
|
||||
netbsd/arm \
|
||||
openbsd/386 \
|
||||
openbsd/amd64 \
|
||||
plan9/386 \
|
||||
plan9/amd64 \
|
||||
solaris/amd64 \
|
||||
windows/386 \
|
||||
windows/amd64
|
||||
|
||||
BOOTSTRAP_1_17_SOURCE:=go1.17.13.src.tar.gz
|
||||
BOOTSTRAP_1_17_SOURCE_URL:=$(GO_SOURCE_URLS)
|
||||
BOOTSTRAP_1_17_HASH:=a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd
|
||||
|
||||
BOOTSTRAP_1_17_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.17
|
||||
|
||||
BOOTSTRAP_1_20_SOURCE:=go1.20.14.src.tar.gz
|
||||
BOOTSTRAP_1_20_SOURCE_URL:=$(GO_SOURCE_URLS)
|
||||
BOOTSTRAP_1_20_HASH:=1aef321a0e3e38b7e91d2d7eb64040666cabdcc77d383de3c9522d0d69b67f4e
|
||||
|
||||
BOOTSTRAP_1_20_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.20
|
||||
|
||||
BOOTSTRAP_1_22_SOURCE:=go1.22.12.src.tar.gz
|
||||
BOOTSTRAP_1_22_SOURCE_URL:=$(GO_SOURCE_URLS)
|
||||
BOOTSTRAP_1_22_HASH:=012a7e1f37f362c0918c1dfa3334458ac2da1628c4b9cf4d9ca02db986e17d71
|
||||
|
||||
BOOTSTRAP_1_22_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.22
|
||||
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../golang-compiler.mk
|
||||
include ../golang-package.mk
|
||||
|
||||
PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
|
||||
HOST_UNPACK:=$(HOST_TAR) -C "$(HOST_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
|
||||
BOOTSTRAP_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_SOURCE)"
|
||||
BOOTSTRAP_1_17_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_17_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_17_SOURCE)"
|
||||
BOOTSTRAP_1_20_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_20_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_20_SOURCE)"
|
||||
BOOTSTRAP_1_22_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_22_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_22_SOURCE)"
|
||||
|
||||
# Don't strip ELF executables in test data
|
||||
RSTRIP:=:
|
||||
|
||||
ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
|
||||
PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
|
||||
endif
|
||||
|
||||
define Package/golang-bootstrap
|
||||
$(call GoPackage/GoSubMenu)
|
||||
TITLE:=Go programming language (bootstrap)
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
define Package/golang-bootstrap/description
|
||||
The Go programming language is an open source project to make programmers more
|
||||
productive.
|
||||
|
||||
Go is expressive, concise, clean, and efficient. Its concurrency mechanisms
|
||||
make it easy to write programs that get the most out of multicore and
|
||||
networked machines, while its novel type system enables flexible and modular
|
||||
program construction. Go compiles quickly to machine code yet has the
|
||||
convenience of garbage collection and the power of run-time reflection. It's a
|
||||
fast, statically typed, compiled language that feels like a dynamically typed,
|
||||
interpreted language.
|
||||
endef
|
||||
|
||||
define Package/golang-bootstrap/config
|
||||
source "$(SOURCE)/Config.in"
|
||||
endef
|
||||
|
||||
BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
|
||||
|
||||
ifeq ($(BOOTSTRAP_ROOT_DIR),)
|
||||
BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR)
|
||||
|
||||
define Download/golang-bootstrap
|
||||
FILE:=$(BOOTSTRAP_SOURCE)
|
||||
URL:=$(BOOTSTRAP_SOURCE_URL)
|
||||
HASH:=$(BOOTSTRAP_HASH)
|
||||
endef
|
||||
$(eval $(call Download,golang-bootstrap))
|
||||
|
||||
define Bootstrap/Prepare
|
||||
mkdir -p "$(BOOTSTRAP_BUILD_DIR)" && $(BOOTSTRAP_UNPACK) ;
|
||||
endef
|
||||
Hooks/HostPrepare/Post+=Bootstrap/Prepare
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
|
||||
endif
|
||||
|
||||
# Skip configuring and downloading stages when building is not configured
|
||||
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
|
||||
|
||||
# Bootstrap 1.17
|
||||
|
||||
define Download/golang-bootstrap-1.17
|
||||
FILE:=$(BOOTSTRAP_1_17_SOURCE)
|
||||
URL:=$(BOOTSTRAP_1_17_SOURCE_URL)
|
||||
HASH:=$(BOOTSTRAP_1_17_HASH)
|
||||
endef
|
||||
$(eval $(call Download,golang-bootstrap-1.17))
|
||||
|
||||
define Bootstrap-1.17/Prepare
|
||||
mkdir -p "$(BOOTSTRAP_1_17_BUILD_DIR)" && $(BOOTSTRAP_1_17_UNPACK) ;
|
||||
endef
|
||||
Hooks/HostPrepare/Post+=Bootstrap-1.17/Prepare
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,Bootstrap-1.17,$(BOOTSTRAP_1_17_BUILD_DIR),,bootstrap-1.17,$(GO_HOST_OS_ARCH)))
|
||||
|
||||
# Bootstrap 1.20
|
||||
|
||||
define Download/golang-bootstrap-1.20
|
||||
FILE:=$(BOOTSTRAP_1_20_SOURCE)
|
||||
URL:=$(BOOTSTRAP_1_20_SOURCE_URL)
|
||||
HASH:=$(BOOTSTRAP_1_20_HASH)
|
||||
endef
|
||||
$(eval $(call Download,golang-bootstrap-1.20))
|
||||
|
||||
define Bootstrap-1.20/Prepare
|
||||
mkdir -p "$(BOOTSTRAP_1_20_BUILD_DIR)" && $(BOOTSTRAP_1_20_UNPACK) ;
|
||||
endef
|
||||
Hooks/HostPrepare/Post+=Bootstrap-1.20/Prepare
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,Bootstrap-1.20,$(BOOTSTRAP_1_20_BUILD_DIR),,bootstrap-1.20,$(GO_HOST_OS_ARCH)))
|
||||
|
||||
# Bootstrap 1.22
|
||||
|
||||
define Download/golang-bootstrap-1.22
|
||||
FILE:=$(BOOTSTRAP_1_22_SOURCE)
|
||||
URL:=$(BOOTSTRAP_1_22_SOURCE_URL)
|
||||
HASH:=$(BOOTSTRAP_1_22_HASH)
|
||||
endef
|
||||
$(eval $(call Download,golang-bootstrap-1.22))
|
||||
|
||||
define Bootstrap-1.22/Prepare
|
||||
mkdir -p "$(BOOTSTRAP_1_22_BUILD_DIR)" && $(BOOTSTRAP_1_22_UNPACK) ;
|
||||
endef
|
||||
Hooks/HostPrepare/Post+=Bootstrap-1.22/Prepare
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,Bootstrap-1.22,$(BOOTSTRAP_1_22_BUILD_DIR),,bootstrap-1.22,$(GO_HOST_OS_ARCH)))
|
||||
|
||||
endif
|
||||
|
||||
|
||||
# Host
|
||||
|
||||
ifeq ($(GO_HOST_PIE_SUPPORTED),1)
|
||||
HOST_GO_ENABLE_PIE:=1
|
||||
endif
|
||||
|
||||
# When using GO_LDFLAGS to set buildmode=pie, the PIE install suffix does not
|
||||
# apply (we also delete the std lib during Host/Install)
|
||||
|
||||
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
|
||||
$(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH)))
|
||||
endif
|
||||
|
||||
HOST_GO_VARS= \
|
||||
GOHOSTARCH="$(GO_HOST_ARCH)" \
|
||||
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
|
||||
GOENV=off \
|
||||
CC="$(HOSTCC_NOCACHE)" \
|
||||
CXX="$(HOSTCXX_NOCACHE)"
|
||||
|
||||
define Host/Configure
|
||||
$(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
|
||||
$(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
|
||||
|
||||
mkdir -p "$(GO_BUILD_CACHE_DIR)"
|
||||
endef
|
||||
|
||||
define Host/Compile
|
||||
$(call GoCompiler/Bootstrap/Make, \
|
||||
$(HOST_GO_VARS) \
|
||||
CC="$(HOSTCC_NOCACHE) -std=gnu17" \
|
||||
)
|
||||
|
||||
$(call GoCompiler/Bootstrap-1.17/Make, \
|
||||
GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \
|
||||
$(HOST_GO_VARS) \
|
||||
)
|
||||
|
||||
$(call GoCompiler/Bootstrap-1.20/Make, \
|
||||
GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_17_BUILD_DIR)" \
|
||||
$(HOST_GO_VARS) \
|
||||
)
|
||||
|
||||
$(call GoCompiler/Bootstrap-1.22/Make, \
|
||||
GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_20_BUILD_DIR)" \
|
||||
$(HOST_GO_VARS) \
|
||||
)
|
||||
|
||||
$(call GoCompiler/Host/Make, \
|
||||
GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_22_BUILD_DIR)" \
|
||||
$(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
|
||||
$(HOST_GO_VARS) \
|
||||
)
|
||||
endef
|
||||
|
||||
# If host and target OS/arch are the same, # when go compiles a program, it will
|
||||
# use the host std lib, so remove it now and force go to rebuild std for target
|
||||
# later
|
||||
define Host/Install
|
||||
$(call Host/Uninstall)
|
||||
|
||||
$(call GoCompiler/Host/Install/Bin)
|
||||
$(call GoCompiler/Host/Install/Src)
|
||||
|
||||
rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)"
|
||||
|
||||
$(INSTALL_DIR) "$(STAGING_DIR_HOSTPKG)/bin"
|
||||
$(INSTALL_BIN) ../go-strip-helper "$(STAGING_DIR_HOSTPKG)/bin"
|
||||
|
||||
$(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
|
||||
$(INSTALL_BIN) ../go-gcc-helper "$(HOST_GO_ROOT)/openwrt"
|
||||
$(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
|
||||
$(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
|
||||
endef
|
||||
|
||||
define Host/Uninstall
|
||||
rm -f "$(STAGING_DIR_HOSTPKG)/bin/go-strip-helper"
|
||||
rm -rf "$(HOST_GO_ROOT)/openwrt"
|
||||
|
||||
$(call GoCompiler/Host/Uninstall)
|
||||
endef
|
||||
|
||||
# Skip downloading and building final bootstrap when building is not configured
|
||||
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
|
||||
$(eval $(call HostBuild))
|
||||
else
|
||||
host-compile:
|
||||
endif
|
||||
|
||||
$(eval $(call BuildPackage,golang-bootstrap))
|
||||
@@ -0,0 +1,201 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2020, 2022 Jeffery To
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
nl="
|
||||
"
|
||||
|
||||
log() {
|
||||
local IFS=" "
|
||||
printf '%s\n' "$*"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
local IFS=" "
|
||||
printf 'Error: %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
link_contents() {
|
||||
local src="$1" dest="$2" IFS="$nl" dirs dir base
|
||||
|
||||
if [ -n "$(find "$src" -mindepth 1 -maxdepth 1 -name "*.go" -not -type d)" ]; then
|
||||
log_error "$src is already a Go library"
|
||||
return 1
|
||||
fi
|
||||
|
||||
dirs="$(find "$src" -mindepth 1 -maxdepth 1 -type d)"
|
||||
for dir in $dirs; do
|
||||
base="${dir##*/}"
|
||||
if [ -d "$dest/$base" ]; then
|
||||
case "$dir" in
|
||||
*$GO_BUILD_DEPENDS_SRC/$GO_PKG)
|
||||
log "$GO_PKG is already installed. Please check for circular dependencies."
|
||||
;;
|
||||
*)
|
||||
link_contents "$src/$base" "$dest/$base"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
log "...${src#$GO_BUILD_DEPENDS_SRC}/$base"
|
||||
ln -sf "$src/$base" "$dest/$base"
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configure() {
|
||||
local files code testdata gomod pattern extra IFS file dest
|
||||
|
||||
cd "$BUILD_DIR" || return 1
|
||||
|
||||
files="$(find ./ -path "*/.*" -prune -o -not -type d -print)"
|
||||
|
||||
if [ "$GO_INSTALL_ALL" != 1 ]; then
|
||||
code="$(printf '%s\n' "$files" | grep '\.\(c\|cc\|cpp\|go\|h\|hh\|hpp\|proto\|s\)$')"
|
||||
testdata="$(printf '%s\n' "$files" | grep '/testdata/')"
|
||||
gomod="$(printf '%s\n' "$files" | grep '/go\.\(mod\|sum\|work\)$')"
|
||||
|
||||
for pattern in $GO_INSTALL_EXTRA; do
|
||||
extra="$(printf '%s\n' "$extra"; printf '%s\n' "$files" | grep -e "$pattern")"
|
||||
done
|
||||
|
||||
files="$(printf '%s\n%s\n%s\n%s\n' "$code" "$testdata" "$gomod" "$extra" | grep -v '^[[:space:]]*$' | sort -u)"
|
||||
fi
|
||||
|
||||
IFS="$nl"
|
||||
|
||||
log "Copying files from $BUILD_DIR into $GO_BUILD_DIR/src/$GO_PKG"
|
||||
mkdir -p "$GO_BUILD_DIR/src"
|
||||
for file in $files; do
|
||||
log "${file#./}"
|
||||
dest="$GO_BUILD_DIR/src/$GO_PKG/${file#./}"
|
||||
mkdir -p "${dest%/*}"
|
||||
cp -fpR "$file" "$dest"
|
||||
done
|
||||
log
|
||||
|
||||
if [ "$GO_SOURCE_ONLY" != 1 ]; then
|
||||
if [ -d "$GO_BUILD_DEPENDS_SRC" ]; then
|
||||
log "Symlinking directories from $GO_BUILD_DEPENDS_SRC into $GO_BUILD_DIR/src"
|
||||
link_contents "$GO_BUILD_DEPENDS_SRC" "$GO_BUILD_DIR/src"
|
||||
else
|
||||
log "$GO_BUILD_DEPENDS_SRC does not exist, skipping symlinks"
|
||||
fi
|
||||
else
|
||||
log "Not building binaries, skipping symlinks"
|
||||
fi
|
||||
log
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
build() {
|
||||
local modargs pattern targets retval
|
||||
|
||||
cd "$GO_BUILD_DIR" || return 1
|
||||
|
||||
if [ -f "$BUILD_DIR/go.mod" ] ; then
|
||||
mkdir -p "$GO_MOD_CACHE_DIR"
|
||||
modargs="$GO_MOD_ARGS"
|
||||
fi
|
||||
|
||||
log "Finding targets"
|
||||
# shellcheck disable=SC2086
|
||||
targets="$(go list $modargs $GO_BUILD_PKG)"
|
||||
for pattern in $GO_EXCLUDES; do
|
||||
targets="$(printf '%s\n' "$targets" | grep -v "$pattern")"
|
||||
done
|
||||
log
|
||||
|
||||
if [ "$GO_GO_GENERATE" = 1 ]; then
|
||||
log "Calling go generate"
|
||||
# shellcheck disable=SC2086
|
||||
GOOS='' GOARCH='' GO386='' GOARM='' GOARM64='' GOMIPS='' GOMIPS64='' GORISCV64=''\
|
||||
go generate -v $targets
|
||||
log
|
||||
fi
|
||||
|
||||
if [ "$GO_SOURCE_ONLY" = 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "Building targets"
|
||||
mkdir -p "$GO_BUILD_DIR/bin" "$GO_BUILD_CACHE_DIR"
|
||||
# shellcheck disable=SC2086
|
||||
go install $modargs "$@" $targets
|
||||
retval="$?"
|
||||
log
|
||||
|
||||
if [ "$retval" -eq 0 ] && [ -z "$(find "$GO_BUILD_BIN_DIR" -maxdepth 0 -type d -not -empty 2>/dev/null)" ]; then
|
||||
log_error "No binaries were built"
|
||||
retval=1
|
||||
fi
|
||||
|
||||
if [ "$retval" -ne 0 ]; then
|
||||
cache_cleanup
|
||||
fi
|
||||
|
||||
return "$retval"
|
||||
}
|
||||
|
||||
install_bin() {
|
||||
local dest="$1"
|
||||
install -d -m0755 "$dest/$GO_INSTALL_BIN_PATH"
|
||||
install -m0755 "$GO_BUILD_BIN_DIR"/* "$dest/$GO_INSTALL_BIN_PATH/"
|
||||
}
|
||||
|
||||
install_src() {
|
||||
local dest="$1" dir="${GO_PKG%/*}"
|
||||
install -d -m0755 "$dest/$GO_BUILD_DEPENDS_PATH/src/$dir"
|
||||
cp -fpR "$GO_BUILD_DIR/src/$GO_PKG" "$dest/$GO_BUILD_DEPENDS_PATH/src/$dir/"
|
||||
}
|
||||
|
||||
cache_cleanup() {
|
||||
if ! [ -d "$GO_MOD_CACHE_DIR" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# in case go is called without -modcacherw
|
||||
find "$GO_MOD_CACHE_DIR" -type d -not -perm -u+w -exec chmod u+w '{}' +
|
||||
|
||||
if [ -n "$CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE" ]; then
|
||||
find "$GO_MOD_CACHE_DIR" -type d -not -perm -go+rx -exec chmod go+rx '{}' +
|
||||
find "$GO_MOD_CACHE_DIR" -not -type d -not -perm -go+r -exec chmod go+r '{}' +
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
if [ "$#" -lt 1 ]; then
|
||||
log_error "Missing command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
command="$1"
|
||||
shift 1
|
||||
|
||||
case "$command" in
|
||||
configure)
|
||||
configure
|
||||
;;
|
||||
build)
|
||||
build "$@"
|
||||
;;
|
||||
install_bin)
|
||||
install_bin "$@"
|
||||
;;
|
||||
install_src)
|
||||
install_src "$@"
|
||||
;;
|
||||
cache_cleanup)
|
||||
cache_cleanup
|
||||
;;
|
||||
*)
|
||||
log_error "Invalid command \"$command\""
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,224 @@
|
||||
#
|
||||
# Copyright (C) 2018, 2020-2021, 2023 Jeffery To
|
||||
# Copyright (C) 2025-2026 George Sapkin
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
ifeq ($(origin GO_INCLUDE_DIR),undefined)
|
||||
GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
endif
|
||||
|
||||
include $(GO_INCLUDE_DIR)/golang-values.mk
|
||||
|
||||
|
||||
# 1: valid GOOS_GOARCH combinations
|
||||
# 2: go version id
|
||||
define GoCompiler/Default/CheckHost
|
||||
$(if $(filter $(GO_HOST_OS_ARCH),$(1)),,$(error go-$(2) cannot be installed on $(GO_HOST_OS)/$(GO_HOST_ARCH)))
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: additional environment variables (optional)
|
||||
define GoCompiler/Default/Make
|
||||
cd "$(1)/src" ; \
|
||||
$(2) $(BASH) make.bash \
|
||||
$(if $(findstring s,$(OPENWRT_VERBOSE)),-v) \
|
||||
--no-banner
|
||||
endef
|
||||
|
||||
# 1: destination prefix
|
||||
# 2: go version id
|
||||
define GoCompiler/Default/Install/make-dirs
|
||||
$(INSTALL_DIR) "$(1)/lib/go-$(2)"
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: destination prefix
|
||||
# 3: go version id
|
||||
# 4: file/directory name
|
||||
# 5: filter (optional)
|
||||
define GoCompiler/Default/Install/install-lib-data
|
||||
|
||||
ifeq ($(5),)
|
||||
$(CP) "$(1)/$(4)" "$(2)/lib/go-$(3)/"
|
||||
else
|
||||
$(INSTALL_DIR) "$(2)/lib/go-$(3)/$(4)"; \
|
||||
cd "$(1)/$(4)" && \
|
||||
$(FIND) . ! -type d -a \( $(5) \) -print0 | \
|
||||
cpio \
|
||||
--make-directories \
|
||||
--null \
|
||||
--pass-through \
|
||||
--unconditional \
|
||||
"$(2)/lib/go-$(3)/$(4)/"
|
||||
endif
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: destination prefix
|
||||
# 3: go version id
|
||||
# 4: GOOS_GOARCH with / as a separator
|
||||
# 5: install suffix (optional)
|
||||
# 6: if target, package architecture-specific sources
|
||||
define GoCompiler/Default/Install/Bin
|
||||
$(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
|
||||
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),api)
|
||||
|
||||
$(INSTALL_DATA) -p "$(1)/go.env" "$(2)/lib/go-$(3)/"
|
||||
$(INSTALL_DATA) -p "$(1)/VERSION" "$(2)/lib/go-$(3)/"
|
||||
|
||||
for file in $(strip $(if $(filter target,$(6)),$(GO_BIN_FILES),$(GO_LEGAL_FILES))); do \
|
||||
if [ -f "$(1)/$$$$file" ]; then \
|
||||
$(INSTALL_DATA) -p "$(1)/$$$$file" "$(2)/lib/go-$(3)/" ; \
|
||||
fi ; \
|
||||
done
|
||||
|
||||
$(INSTALL_DIR) "$(2)/lib/go-$(3)/bin"
|
||||
|
||||
$(eval GO_HOST_OS_ARCH_PATH:=$(subst /,_,$(4)))
|
||||
|
||||
ifeq ($(4),$(GO_HOST_OS_ARCH))
|
||||
$(INSTALL_BIN) -p "$(1)/bin"/* "$(2)/lib/go-$(3)/bin/"
|
||||
else
|
||||
$(INSTALL_BIN) -p "$(1)/bin/$(GO_HOST_OS_ARCH_PATH)"/* "$(2)/lib/go-$(3)/bin/"
|
||||
endif
|
||||
|
||||
if [ -d "$(1)/pkg/$(GO_HOST_OS_ARCH_PATH)$(if $(5),_$(5))" ]; then \
|
||||
$(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg" ; \
|
||||
$(CP) "$(1)/pkg/$(GO_HOST_OS_ARCH_PATH)$(if $(5),_$(5))" "$(2)/lib/go-$(3)/pkg/" ; \
|
||||
fi
|
||||
|
||||
$(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg/tool/$(GO_HOST_OS_ARCH_PATH)"
|
||||
$(INSTALL_BIN) -p "$(1)/pkg/tool/$(GO_HOST_OS_ARCH_PATH)"/* "$(2)/lib/go-$(3)/pkg/tool/$(GO_HOST_OS_ARCH_PATH)/"
|
||||
endef
|
||||
|
||||
# 1: destination prefix
|
||||
# 2: go version id
|
||||
define GoCompiler/Default/Install/BinLinks
|
||||
$(INSTALL_DIR) "$(1)/bin"
|
||||
$(LN) "../lib/go-$(2)/bin/go" "$(1)/bin/go$(2)"
|
||||
$(LN) "../lib/go-$(2)/bin/gofmt" "$(1)/bin/gofmt$(2)"
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: destination prefix
|
||||
# 3: go version id
|
||||
define GoCompiler/Default/Install/Doc
|
||||
$(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
|
||||
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),doc)
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: destination prefix
|
||||
# 3: go version id
|
||||
define GoCompiler/Default/Install/Misc
|
||||
$(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),misc)
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: destination prefix
|
||||
# 3: go version id
|
||||
# 4: if target, package architecture-specific sources
|
||||
define GoCompiler/Default/Install/Src
|
||||
$(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),src,$(strip \
|
||||
$(if $(filter target,$(4)), \
|
||||
$(GO_TARGET_SRC_FILTERS), \
|
||||
$(GO_HOST_SRC_FILTERS) \
|
||||
) \
|
||||
))
|
||||
|
||||
if [ -d "$(1)/pkg/include" ]; then \
|
||||
$(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg" ; \
|
||||
$(CP) "$(1)/pkg/include" "$(2)/lib/go-$(3)/pkg/" ; \
|
||||
fi
|
||||
endef
|
||||
|
||||
# 1: source go root
|
||||
# 2: destination prefix
|
||||
# 3: go version id
|
||||
define GoCompiler/Default/Install/Tests
|
||||
$(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),lib)
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),src,$(GO_TARGET_TEST_FILTERS))
|
||||
$(call GoCompiler/Default/Install/install-lib-data,$(1),$(2),$(3),test)
|
||||
endef
|
||||
|
||||
# 1: destination prefix
|
||||
# 2: go version id
|
||||
define GoCompiler/Default/Uninstall
|
||||
rm -rf "$(1)/lib/go-$(2)"
|
||||
endef
|
||||
|
||||
# 1: destination prefix
|
||||
# 2: go version id
|
||||
define GoCompiler/Default/Uninstall/BinLinks
|
||||
rm -f "$(1)/bin/go$(2)"
|
||||
rm -f "$(1)/bin/gofmt$(2)"
|
||||
endef
|
||||
|
||||
|
||||
# 1: profile name
|
||||
# 2: source go root
|
||||
# 3: destination prefix
|
||||
# 4: go version id
|
||||
# 5: GOOS_GOARCH with / as a separator
|
||||
# 6: install suffix (optional)
|
||||
define GoCompiler/AddProfile
|
||||
|
||||
# 1: valid GOOS_GOARCH combinations
|
||||
define GoCompiler/$(1)/CheckHost
|
||||
$$(call GoCompiler/Default/CheckHost,$$(1),$(4))
|
||||
endef
|
||||
|
||||
# 1: additional environment variables (optional)
|
||||
define GoCompiler/$(1)/Make
|
||||
$$(call GoCompiler/Default/Make,$(2),$$(1))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
# 2: if target, package architecture-specific sources
|
||||
define GoCompiler/$(1)/Install/Bin
|
||||
$$(call GoCompiler/Default/Install/Bin,$(2),$$(or $$(1),$(3)),$(4),$(5),$(6),$$(2))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
define GoCompiler/$(1)/Install/BinLinks
|
||||
$$(call GoCompiler/Default/Install/BinLinks,$$(or $$(1),$(3)),$(4))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
define GoCompiler/$(1)/Install/Doc
|
||||
$$(call GoCompiler/Default/Install/Doc,$(2),$$(or $$(1),$(3)),$(4))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
define GoCompiler/$(1)/Install/Misc
|
||||
$$(call GoCompiler/Default/Install/Misc,$(2),$$(or $$(1),$(3)),$(4))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
# 2: if target, package architecture-specific sources
|
||||
define GoCompiler/$(1)/Install/Src
|
||||
$$(call GoCompiler/Default/Install/Src,$(2),$$(or $$(1),$(3)),$(4),$$(2))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
define GoCompiler/$(1)/Install/Tests
|
||||
$$(call GoCompiler/Default/Install/Tests,$(2),$$(or $$(1),$(3)),$(4),$$(2))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
define GoCompiler/$(1)/Uninstall
|
||||
$$(call GoCompiler/Default/Uninstall,$$(or $$(1),$(3)),$(4))
|
||||
endef
|
||||
|
||||
# 1: override install prefix (optional)
|
||||
define GoCompiler/$(1)/Uninstall/BinLinks
|
||||
$$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3)),$(4))
|
||||
endef
|
||||
|
||||
endef
|
||||
@@ -0,0 +1,218 @@
|
||||
#
|
||||
# Copyright (C) 2020, 2022 Jeffery To
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
ifeq ($(origin GO_INCLUDE_DIR),undefined)
|
||||
GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
endif
|
||||
|
||||
include $(GO_INCLUDE_DIR)/golang-values.mk
|
||||
|
||||
|
||||
# these variables have the same meanings as in golang-package.mk
|
||||
GO_HOST_INSTALL_EXTRA?=$(GO_PKG_INSTALL_EXTRA)
|
||||
GO_HOST_INSTALL_ALL?=$(GO_PKG_INSTALL_ALL)
|
||||
GO_HOST_SOURCE_ONLY?=$(GO_PKG_SOURCE_ONLY)
|
||||
GO_HOST_BUILD_PKG?=$(GO_PKG_BUILD_PKG)
|
||||
GO_HOST_EXCLUDES?=$(GO_PKG_EXCLUDES)
|
||||
GO_HOST_GO_GENERATE?=$(GO_PKG_GO_GENERATE)
|
||||
GO_HOST_GCFLAGS?=$(GO_PKG_GCFLAGS)
|
||||
GO_HOST_LDFLAGS?=$(GO_PKG_LDFLAGS)
|
||||
GO_HOST_LDFLAGS_X?=$(GO_PKG_LDFLAGS_X)
|
||||
GO_HOST_TAGS?=$(GO_PKG_TAGS)
|
||||
GO_HOST_INSTALL_BIN_PATH?=/bin
|
||||
|
||||
|
||||
# need to repeat this here in case golang-package.mk is not included
|
||||
GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/...
|
||||
|
||||
GO_HOST_WORK_DIR_NAME:=.go_work
|
||||
GO_HOST_BUILD_DIR=$(HOST_BUILD_DIR)/$(GO_HOST_WORK_DIR_NAME)/build
|
||||
GO_HOST_BUILD_BIN_DIR=$(GO_HOST_BUILD_DIR)/bin
|
||||
|
||||
GO_HOST_BUILD_DEPENDS_PATH:=/share/gocode
|
||||
GO_HOST_BUILD_DEPENDS_SRC=$(STAGING_DIR_HOSTPKG)$(GO_HOST_BUILD_DEPENDS_PATH)/src
|
||||
|
||||
GO_HOST_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
|
||||
GO_HOST_STAGING_DIR:=$(TMP_DIR)/host-stage-$(GO_HOST_DIR_NAME)
|
||||
GO_HOST_STAGING_FILES_LIST_DIR:=$(HOST_BUILD_PREFIX)/stamp
|
||||
GO_HOST_BIN_STAGING_FILES_LIST:=$(GO_HOST_STAGING_FILES_LIST_DIR)/$(GO_HOST_DIR_NAME)-bin.list
|
||||
GO_HOST_SRC_STAGING_FILES_LIST:=$(GO_HOST_STAGING_FILES_LIST_DIR)/$(GO_HOST_DIR_NAME)-src.list
|
||||
|
||||
ifeq ($(GO_HOST_PIE_SUPPORTED),1)
|
||||
GO_HOST_ENABLE_PIE:=1
|
||||
endif
|
||||
|
||||
GO_HOST_BUILD_CONFIG_VARS= \
|
||||
GO_PKG="$(strip $(GO_PKG))" \
|
||||
GO_INSTALL_EXTRA="$(strip $(GO_HOST_INSTALL_EXTRA))" \
|
||||
GO_INSTALL_ALL="$(strip $(GO_HOST_INSTALL_ALL))" \
|
||||
GO_SOURCE_ONLY="$(strip $(GO_HOST_SOURCE_ONLY))" \
|
||||
GO_BUILD_PKG="$(strip $(GO_HOST_BUILD_PKG))" \
|
||||
GO_EXCLUDES="$(strip $(GO_HOST_EXCLUDES))" \
|
||||
GO_GO_GENERATE="$(strip $(GO_HOST_GO_GENERATE))" \
|
||||
GO_INSTALL_BIN_PATH="$(strip $(GO_HOST_INSTALL_BIN_PATH))" \
|
||||
BUILD_DIR="$(HOST_BUILD_DIR)" \
|
||||
GO_BUILD_DIR="$(GO_HOST_BUILD_DIR)" \
|
||||
GO_BUILD_BIN_DIR="$(GO_HOST_BUILD_BIN_DIR)" \
|
||||
GO_BUILD_DEPENDS_PATH="$(GO_HOST_BUILD_DEPENDS_PATH)" \
|
||||
GO_BUILD_DEPENDS_SRC="$(GO_HOST_BUILD_DEPENDS_SRC)"
|
||||
|
||||
GO_HOST_MORE_CFLAGS?= \
|
||||
-Wformat -Werror=format-security \
|
||||
-fstack-protector-strong \
|
||||
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
|
||||
-Wl,-z,now -Wl,-z,relro \
|
||||
$(if $(GO_HOST_ENABLE_PIE),$(FPIC))
|
||||
|
||||
GO_HOST_MORE_LDFLAGS?= \
|
||||
-znow -zrelro \
|
||||
$(if $(GO_HOST_ENABLE_PIE),$(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs)
|
||||
|
||||
GO_HOST_TARGET_VARS= \
|
||||
CGO_ENABLED=1 \
|
||||
CC=gcc \
|
||||
CXX=g++ \
|
||||
PKG_CONFIG=pkg-config \
|
||||
CGO_CFLAGS="$(HOST_CFLAGS) $(GO_HOST_MORE_CFLAGS)" \
|
||||
CGO_CPPFLAGS="$(HOST_CPPFLAGS) $(GO_HOST_MORE_CPPFLAGS)" \
|
||||
CGO_CXXFLAGS="$(HOST_CFLAGS) $(GO_HOST_MORE_CFLAGS)" \
|
||||
CGO_LDFLAGS="$(HOST_LDFLAGS) $(GO_HOST_MORE_LDFLAGS)" \
|
||||
GO_GCC_HELPER_CC="$(HOSTCC)" \
|
||||
GO_GCC_HELPER_CXX="$(HOSTCXX)" \
|
||||
GO_GCC_HELPER_PATH="$$$$PATH" \
|
||||
PATH="$(STAGING_DIR_HOSTPKG)/lib/go-cross/openwrt:$$$$PATH"
|
||||
|
||||
GO_HOST_BUILD_VARS= \
|
||||
GOPATH="$(GO_HOST_BUILD_DIR)" \
|
||||
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
|
||||
GOMODCACHE="$(GO_MOD_CACHE_DIR)" \
|
||||
GOENV=off
|
||||
|
||||
GO_HOST_VARS= \
|
||||
$(GO_HOST_TARGET_VARS) \
|
||||
$(GO_HOST_BUILD_VARS)
|
||||
|
||||
GO_HOST_DEFAULT_LDFLAGS= \
|
||||
-linkmode external \
|
||||
-extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(HOST_LDFLAGS) $(GO_HOST_MORE_LDFLAGS))'
|
||||
|
||||
GO_HOST_CUSTOM_LDFLAGS= \
|
||||
$(GO_HOST_LDFLAGS) \
|
||||
$(patsubst %,-X %,$(GO_HOST_LDFLAGS_X))
|
||||
|
||||
GO_HOST_INSTALL_ARGS= \
|
||||
-v \
|
||||
-ldflags "all=$(GO_HOST_DEFAULT_LDFLAGS)" \
|
||||
$(if $(GO_HOST_ENABLE_PIE),-buildmode pie) \
|
||||
$(if $(strip $(GO_HOST_GCFLAGS)),-gcflags "$(GO_HOST_GCFLAGS)") \
|
||||
$(if $(strip $(GO_HOST_CUSTOM_LDFLAGS)),-ldflags "$(GO_HOST_CUSTOM_LDFLAGS) $(GO_HOST_DEFAULT_LDFLAGS)") \
|
||||
$(if $(strip $(GO_HOST_TAGS)),-tags "$(GO_HOST_TAGS)")
|
||||
|
||||
define GoHost/Host/Configure
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_HOST_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh configure
|
||||
endef
|
||||
|
||||
# $(1) additional arguments for go command line (optional)
|
||||
define GoHost/Host/Compile
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_HOST_BUILD_CONFIG_VARS) \
|
||||
$(GO_HOST_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh build $(GO_HOST_INSTALL_ARGS) $(1)
|
||||
endef
|
||||
|
||||
define GoHost/Host/Install/Bin
|
||||
rm -rf "$(GO_HOST_STAGING_DIR)"
|
||||
mkdir -p "$(GO_HOST_STAGING_DIR)" "$(GO_HOST_STAGING_FILES_LIST_DIR)"
|
||||
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_HOST_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh install_bin "$(GO_HOST_STAGING_DIR)"
|
||||
|
||||
if [ -f "$(GO_HOST_BIN_STAGING_FILES_LIST)" ]; then \
|
||||
"$(SCRIPT_DIR)/clean-package.sh" \
|
||||
"$(GO_HOST_BIN_STAGING_FILES_LIST)" \
|
||||
"$(1)" ; \
|
||||
fi
|
||||
|
||||
cd "$(GO_HOST_STAGING_DIR)" && find ./ > "$(GO_HOST_STAGING_DIR).files"
|
||||
|
||||
$(call locked, \
|
||||
mv "$(GO_HOST_STAGING_DIR).files" "$(GO_HOST_BIN_STAGING_FILES_LIST)" && \
|
||||
$(CP) "$(GO_HOST_STAGING_DIR)"/* "$(1)/", \
|
||||
host-staging-dir \
|
||||
)
|
||||
|
||||
rm -rf "$(GO_HOST_STAGING_DIR)"
|
||||
endef
|
||||
|
||||
define GoHost/Host/Install/Src
|
||||
rm -rf "$(GO_HOST_STAGING_DIR)"
|
||||
mkdir -p "$(GO_HOST_STAGING_DIR)" "$(GO_HOST_STAGING_FILES_LIST_DIR)"
|
||||
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_HOST_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh install_src "$(GO_HOST_STAGING_DIR)"
|
||||
|
||||
if [ -f "$(GO_HOST_SRC_STAGING_FILES_LIST)" ]; then \
|
||||
"$(SCRIPT_DIR)/clean-package.sh" \
|
||||
"$(GO_HOST_SRC_STAGING_FILES_LIST)" \
|
||||
"$(1)" ; \
|
||||
fi
|
||||
|
||||
cd "$(GO_HOST_STAGING_DIR)" && find ./ > "$(GO_HOST_STAGING_DIR).files"
|
||||
|
||||
$(call locked, \
|
||||
mv "$(GO_HOST_STAGING_DIR).files" "$(GO_HOST_SRC_STAGING_FILES_LIST)" && \
|
||||
$(CP) "$(GO_HOST_STAGING_DIR)"/* "$(1)/", \
|
||||
host-staging-dir \
|
||||
)
|
||||
|
||||
rm -rf "$(GO_HOST_STAGING_DIR)"
|
||||
endef
|
||||
|
||||
define GoHost/Host/Install
|
||||
$(if $(filter $(GO_HOST_SOURCE_ONLY),1),, \
|
||||
$(call GoHost/Host/Install/Bin,$(1)) \
|
||||
)
|
||||
$(call GoHost/Host/Install/Src,$(1))
|
||||
endef
|
||||
|
||||
define GoHost/Host/Uninstall
|
||||
if [ -f "$(GO_HOST_BIN_STAGING_FILES_LIST)" ]; then \
|
||||
"$(SCRIPT_DIR)/clean-package.sh" \
|
||||
"$(GO_HOST_BIN_STAGING_FILES_LIST)" \
|
||||
"$(HOST_BUILD_PREFIX)" ; \
|
||||
rm -f "$(GO_HOST_BIN_STAGING_FILES_LIST)" ; \
|
||||
fi
|
||||
|
||||
if [ -f "$(GO_HOST_SRC_STAGING_FILES_LIST)" ]; then \
|
||||
"$(SCRIPT_DIR)/clean-package.sh" \
|
||||
"$(GO_HOST_SRC_STAGING_FILES_LIST)" \
|
||||
"$(HOST_BUILD_PREFIX)" ; \
|
||||
rm -f "$(GO_HOST_SRC_STAGING_FILES_LIST)" ; \
|
||||
fi
|
||||
endef
|
||||
|
||||
|
||||
ifneq ($(strip $(GO_PKG)),)
|
||||
Host/Configure=$(call GoHost/Host/Configure)
|
||||
Host/Compile=$(call GoHost/Host/Compile)
|
||||
Hooks/HostCompile/Post+=Go/CacheCleanup
|
||||
Host/Uninstall=$(call GoHost/Host/Uninstall,$(1))
|
||||
endif
|
||||
|
||||
define GoHostBuild
|
||||
Host/Install=$$(call GoHost/Host/Install,$$(1))
|
||||
endef
|
||||
|
||||
define GoBinHostBuild
|
||||
Host/Install=$$(call GoHost/Host/Install/Bin,$$(1))
|
||||
endef
|
||||
|
||||
define GoSrcHostBuild
|
||||
Host/Install=$$(call GoHost/Host/Install/Src,$$(1))
|
||||
endef
|
||||
@@ -0,0 +1,327 @@
|
||||
#
|
||||
# Copyright (C) 2018-2022 Jeffery To
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
ifeq ($(origin GO_INCLUDE_DIR),undefined)
|
||||
GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
endif
|
||||
|
||||
include $(GO_INCLUDE_DIR)/golang-values.mk
|
||||
|
||||
|
||||
# Variables (all optional, except GO_PKG) to be set in package
|
||||
# Makefiles:
|
||||
#
|
||||
# GO_PKG (required) - name of Go package
|
||||
#
|
||||
# Go name of the package.
|
||||
#
|
||||
# e.g. GO_PKG:=golang.org/x/text
|
||||
#
|
||||
#
|
||||
# GO_PKG_INSTALL_EXTRA - list of regular expressions, default empty
|
||||
#
|
||||
# Additional files/directories to install. By default, only these
|
||||
# files are installed:
|
||||
#
|
||||
# * Files with one of these extensions:
|
||||
# .go, .c, .cc, .cpp, .h, .hh, .hpp, .proto, .s
|
||||
#
|
||||
# * Files in any 'testdata' directory
|
||||
#
|
||||
# * go.mod, go.sum and go.work, in any directory
|
||||
#
|
||||
# e.g. GO_PKG_INSTALL_EXTRA:=example.toml marshal_test.toml
|
||||
#
|
||||
#
|
||||
# GO_PKG_INSTALL_ALL - boolean (0 or 1), default false
|
||||
#
|
||||
# If true, install all files regardless of extension or directory.
|
||||
#
|
||||
# e.g. GO_PKG_INSTALL_ALL:=1
|
||||
#
|
||||
#
|
||||
# GO_PKG_SOURCE_ONLY - boolean (0 or 1), default false
|
||||
#
|
||||
# If true, 'go install' will not be called. If the package does not
|
||||
# (or should not) build any binaries, then specifying this option will
|
||||
# save build time.
|
||||
#
|
||||
# e.g. GO_PKG_SOURCE_ONLY:=1
|
||||
#
|
||||
#
|
||||
# GO_PKG_BUILD_PKG - list of build targets, default GO_PKG/...
|
||||
#
|
||||
# Build targets for compiling this Go package, i.e. arguments passed
|
||||
# to 'go install'.
|
||||
#
|
||||
# e.g. GO_PKG_BUILD_PKG:=github.com/debian/ratt/cmd/...
|
||||
#
|
||||
#
|
||||
# GO_PKG_EXCLUDES - list of regular expressions, default empty
|
||||
#
|
||||
# Patterns to exclude from the build targets expanded from
|
||||
# GO_PKG_BUILD_PKG.
|
||||
#
|
||||
# e.g. GO_PKG_EXCLUDES:=examples/
|
||||
#
|
||||
#
|
||||
# GO_PKG_GO_GENERATE - boolean (0 or 1), default false
|
||||
#
|
||||
# If true, 'go generate' will be called on all build targets (as
|
||||
# determined by GO_PKG_BUILD_PKG and GO_PKG_EXCLUDES). This is usually
|
||||
# not necessary.
|
||||
#
|
||||
# e.g. GO_PKG_GO_GENERATE:=1
|
||||
#
|
||||
#
|
||||
# GO_PKG_GCFLAGS - list of options, default empty
|
||||
#
|
||||
# Additional go tool compile options to use when building targets.
|
||||
#
|
||||
# e.g. GO_PKG_GCFLAGS:=-N -l
|
||||
#
|
||||
#
|
||||
# GO_PKG_LDFLAGS - list of options, default empty
|
||||
#
|
||||
# Additional go tool link options to use when building targets.
|
||||
#
|
||||
# Note that the OpenWrt build system has an option to strip binaries
|
||||
# (enabled by default), so -s (Omit the symbol table and debug
|
||||
# information) and -w (Omit the DWARF symbol table) flags are not
|
||||
# necessary.
|
||||
#
|
||||
# e.g. GO_PKG_LDFLAGS:=-r dir1:dir2 -u
|
||||
#
|
||||
#
|
||||
# GO_PKG_LDFLAGS_X - list of string variable definitions, default empty
|
||||
#
|
||||
# Each definition will be passed as the parameter to the -X go tool
|
||||
# link option, i.e. -ldflags "-X importpath.name=value".
|
||||
#
|
||||
# e.g. GO_PKG_LDFLAGS_X:=main.Version=$(PKG_VERSION) main.BuildStamp=$(SOURCE_DATE_EPOCH)
|
||||
#
|
||||
#
|
||||
# GO_PKG_TAGS - list of build tags, default empty
|
||||
#
|
||||
# Build tags to consider satisfied during the build, passed as the
|
||||
# parameter to the -tags option for 'go install'.
|
||||
#
|
||||
# e.g. GO_PKG_TAGS:=release,noupgrade
|
||||
#
|
||||
#
|
||||
# GO_PKG_INSTALL_BIN_PATH - target directory path, default /usr/bin
|
||||
#
|
||||
# Directory path under "dest_dir" where binaries will be installed by
|
||||
# '$(call GoPackage/Package/Install/Bin,dest_dir)'.
|
||||
#
|
||||
# e.g. GO_PKG_INSTALL_BIN_PATH:=/sbin
|
||||
|
||||
# Credit for this package build process (GoPackage/Build/Configure and
|
||||
# GoPackage/Build/Compile) belong to Debian's dh-golang completely.
|
||||
# https://salsa.debian.org/go-team/packages/dh-golang
|
||||
|
||||
|
||||
GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/...
|
||||
GO_PKG_INSTALL_BIN_PATH?=/usr/bin
|
||||
|
||||
GO_PKG_WORK_DIR_NAME:=.go_work
|
||||
GO_PKG_BUILD_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)/build
|
||||
GO_PKG_BUILD_BIN_DIR=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(subst /,_,$(GO_OS_ARCH)))
|
||||
|
||||
GO_PKG_BUILD_DEPENDS_PATH:=/usr/share/gocode
|
||||
GO_PKG_BUILD_DEPENDS_SRC=$(STAGING_DIR)$(GO_PKG_BUILD_DEPENDS_PATH)/src
|
||||
|
||||
ifdef CONFIG_PKG_ASLR_PIE_ALL
|
||||
ifeq ($(strip $(PKG_ASLR_PIE)),1)
|
||||
ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
|
||||
GO_PKG_ENABLE_PIE:=1
|
||||
else
|
||||
$(warning PIE buildmode is not supported for $(GO_OS)/$(GO_ARCH))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef CONFIG_PKG_ASLR_PIE_REGULAR
|
||||
ifeq ($(strip $(PKG_ASLR_PIE_REGULAR)),1)
|
||||
ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
|
||||
GO_PKG_ENABLE_PIE:=1
|
||||
else
|
||||
$(warning PIE buildmode is not supported for $(GO_OS)/$(GO_ARCH))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef CONFIG_GOLANG_SPECTRE
|
||||
ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
|
||||
GO_PKG_ENABLE_SPECTRE:=1
|
||||
else
|
||||
$(warning Spectre mitigations are not supported for $(GO_ARCH))
|
||||
endif
|
||||
endif
|
||||
|
||||
# sstrip causes corrupted section header size
|
||||
ifneq ($(CONFIG_USE_SSTRIP),)
|
||||
ifneq ($(CONFIG_DEBUG),)
|
||||
GO_PKG_STRIP_ARGS:=--strip-unneeded --remove-section=.comment --remove-section=.note
|
||||
else
|
||||
GO_PKG_STRIP_ARGS:=--strip-all
|
||||
endif
|
||||
STRIP:=$(TARGET_CROSS)strip $(GO_PKG_STRIP_ARGS)
|
||||
endif
|
||||
|
||||
define GoPackage/GoSubMenu
|
||||
SUBMENU:=Go
|
||||
SECTION:=lang
|
||||
CATEGORY:=Languages
|
||||
endef
|
||||
|
||||
# Some packages like docker use go directly and don't process vars like GO, so
|
||||
# just add selected version to path and insert it into several used vars.
|
||||
GO_BIN_PATH:= \
|
||||
PATH=$(STAGING_DIR_HOSTPKG)/lib/go-$(GO_HOST_VERSION)/bin:$(PATH)
|
||||
|
||||
GO_PKG_BUILD_CONFIG_VARS= \
|
||||
$(GO_BIN_PATH) \
|
||||
GO_PKG="$(strip $(GO_PKG))" \
|
||||
GO_INSTALL_EXTRA="$(strip $(GO_PKG_INSTALL_EXTRA))" \
|
||||
GO_INSTALL_ALL="$(strip $(GO_PKG_INSTALL_ALL))" \
|
||||
GO_SOURCE_ONLY="$(strip $(GO_PKG_SOURCE_ONLY))" \
|
||||
GO_BUILD_PKG="$(strip $(GO_PKG_BUILD_PKG))" \
|
||||
GO_EXCLUDES="$(strip $(GO_PKG_EXCLUDES))" \
|
||||
GO_GO_GENERATE="$(strip $(GO_PKG_GO_GENERATE))" \
|
||||
GO_INSTALL_BIN_PATH="$(strip $(GO_PKG_INSTALL_BIN_PATH))" \
|
||||
BUILD_DIR="$(PKG_BUILD_DIR)" \
|
||||
GO_BUILD_DIR="$(GO_PKG_BUILD_DIR)" \
|
||||
GO_BUILD_BIN_DIR="$(GO_PKG_BUILD_BIN_DIR)" \
|
||||
GO_BUILD_DEPENDS_PATH="$(GO_PKG_BUILD_DEPENDS_PATH)" \
|
||||
GO_BUILD_DEPENDS_SRC="$(GO_PKG_BUILD_DEPENDS_SRC)"
|
||||
|
||||
GO_PKG_TARGET_VARS= \
|
||||
GOOS="$(GO_OS)" \
|
||||
GOARCH="$(GO_ARCH)" \
|
||||
GO386="$(GO_386)" \
|
||||
GOAMD64="$(GO_AMD64)" \
|
||||
GOARM="$(GO_ARM)" \
|
||||
GOARM64="$(GO_ARM64)" \
|
||||
GOMIPS="$(GO_MIPS)" \
|
||||
GOMIPS64="$(GO_MIPS64)" \
|
||||
GOPPC64="$(GO_PPC64)" \
|
||||
CGO_ENABLED=1 \
|
||||
CC="$(TARGET_CC)" \
|
||||
CXX="$(TARGET_CXX)" \
|
||||
CGO_CFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CFLAGS))" \
|
||||
CGO_CPPFLAGS="$(TARGET_CPPFLAGS)" \
|
||||
CGO_CXXFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CXXFLAGS))" \
|
||||
CGO_LDFLAGS="$(TARGET_LDFLAGS)"
|
||||
|
||||
GO_PKG_BUILD_VARS= \
|
||||
GOPATH="$(GO_PKG_BUILD_DIR)" \
|
||||
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
|
||||
GOMODCACHE="$(GO_MOD_CACHE_DIR)" \
|
||||
GOENV=off \
|
||||
GOTOOLCHAIN=local
|
||||
|
||||
GO_PKG_VARS= \
|
||||
$(GO_BIN_PATH) \
|
||||
$(GO_PKG_TARGET_VARS) \
|
||||
$(GO_PKG_BUILD_VARS)
|
||||
|
||||
GO_PKG_DEFAULT_GCFLAGS= \
|
||||
$(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
|
||||
|
||||
GO_PKG_DEFAULT_ASMFLAGS= \
|
||||
$(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
|
||||
|
||||
GO_PKG_DEFAULT_LDFLAGS= \
|
||||
-linkmode external \
|
||||
-extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))'
|
||||
|
||||
GO_PKG_CUSTOM_LDFLAGS= \
|
||||
$(GO_PKG_LDFLAGS) \
|
||||
$(patsubst %,-X %,$(GO_PKG_LDFLAGS_X))
|
||||
|
||||
GO_PKG_INSTALL_ARGS= \
|
||||
-v \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-ldflags "all=$(GO_PKG_DEFAULT_LDFLAGS)" \
|
||||
$(if $(strip $(GO_PKG_DEFAULT_GCFLAGS)),-gcflags "all=$(GO_PKG_DEFAULT_GCFLAGS)") \
|
||||
$(if $(strip $(GO_PKG_DEFAULT_ASMFLAGS)),-asmflags "all=$(GO_PKG_DEFAULT_ASMFLAGS)") \
|
||||
$(if $(GO_PKG_ENABLE_PIE),-buildmode pie) \
|
||||
$(if $(filter $(GO_ARCH),366),-installsuffix "$(GO_386)") \
|
||||
$(if $(filter $(GO_ARCH),arm),-installsuffix "v$(GO_ARM)") \
|
||||
$(if $(filter $(GO_ARCH),arm64),-installsuffix "$(GO_ARM64)") \
|
||||
$(if $(filter $(GO_ARCH),mips mipsle),-installsuffix "$(GO_MIPS)") \
|
||||
$(if $(filter $(GO_ARCH),mips64 mips64le),-installsuffix "$(GO_MIPS64)") \
|
||||
$(if $(strip $(GO_PKG_GCFLAGS)),-gcflags "$(GO_PKG_GCFLAGS) $(GO_PKG_DEFAULT_GCFLAGS)") \
|
||||
$(if $(strip $(GO_PKG_CUSTOM_LDFLAGS)),-ldflags "$(GO_PKG_CUSTOM_LDFLAGS) $(GO_PKG_DEFAULT_LDFLAGS)") \
|
||||
$(if $(strip $(GO_PKG_TAGS)),-tags "$(GO_PKG_TAGS)")
|
||||
|
||||
define GoPackage/Build/Configure
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)golang-build.sh configure
|
||||
endef
|
||||
|
||||
# 1: additional arguments for go command line (optional)
|
||||
define GoPackage/Build/Compile
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)golang-build.sh build $(GO_PKG_INSTALL_ARGS) $(1)
|
||||
endef
|
||||
|
||||
define GoPackage/Build/InstallDev
|
||||
$(call GoPackage/Package/Install/Src,$(1))
|
||||
endef
|
||||
|
||||
define GoPackage/Package/Install/Bin
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)golang-build.sh install_bin "$(1)"
|
||||
endef
|
||||
|
||||
define GoPackage/Package/Install/Src
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)golang-build.sh install_src "$(1)"
|
||||
endef
|
||||
|
||||
define GoPackage/Package/Install
|
||||
$(if $(filter $(GO_PKG_SOURCE_ONLY),1),, \
|
||||
$(call GoPackage/Package/Install/Bin,$(1)) \
|
||||
)
|
||||
$(call GoPackage/Package/Install/Src,$(1))
|
||||
endef
|
||||
|
||||
|
||||
ifneq ($(strip $(GO_PKG)),)
|
||||
ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
|
||||
PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
|
||||
endif
|
||||
|
||||
Build/Configure=$(call GoPackage/Build/Configure)
|
||||
Build/Compile=$(call GoPackage/Build/Compile)
|
||||
Hooks/Compile/Post+=Go/CacheCleanup
|
||||
Build/InstallDev=$(call GoPackage/Build/InstallDev,$(1))
|
||||
endif
|
||||
|
||||
define GoPackage
|
||||
ifndef Package/$(1)/install
|
||||
Package/$(1)/install=$$(call GoPackage/Package/Install,$$(1))
|
||||
endif
|
||||
endef
|
||||
|
||||
define GoBinPackage
|
||||
ifndef Package/$(1)/install
|
||||
Package/$(1)/install=$$(call GoPackage/Package/Install/Bin,$$(1))
|
||||
endif
|
||||
endef
|
||||
|
||||
define GoSrcPackage
|
||||
ifndef Package/$(1)/install
|
||||
Package/$(1)/install=$$(call GoPackage/Package/Install/Src,$$(1))
|
||||
endif
|
||||
endef
|
||||
@@ -0,0 +1,356 @@
|
||||
#
|
||||
# Copyright (C) 2018-2023 Jeffery To
|
||||
# Copyright (C) 2025-2026 George Sapkin
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
ifeq ($(origin GO_INCLUDE_DIR),undefined)
|
||||
GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
endif
|
||||
|
||||
|
||||
# Unset environment variables
|
||||
# There are more magic variables to track down, but ain't nobody got time for that
|
||||
|
||||
# From https://pkg.go.dev/cmd/go#hdr-Environment_variables
|
||||
|
||||
# General-purpose environment variables:
|
||||
unexport \
|
||||
GO111MODULE \
|
||||
GCCGO \
|
||||
GOARCH \
|
||||
GOBIN \
|
||||
GOCACHE \
|
||||
GOMODCACHE \
|
||||
GODEBUG \
|
||||
GOENV \
|
||||
GOFLAGS \
|
||||
GOOS \
|
||||
GOPATH \
|
||||
GOROOT \
|
||||
GOTOOLCHAIN \
|
||||
GOTMPDIR \
|
||||
GOWORK
|
||||
# Unmodified:
|
||||
# GOINSECURE
|
||||
# GOPRIVATE
|
||||
# GOPROXY
|
||||
# GONOPROXY
|
||||
# GOSUMDB
|
||||
# GONOSUMDB
|
||||
# GOVCS
|
||||
|
||||
# Environment variables for use with cgo:
|
||||
unexport \
|
||||
AR \
|
||||
CC \
|
||||
CGO_ENABLED \
|
||||
CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
|
||||
CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \
|
||||
CGO_CXXFLAGS CGO_CXXFLAGS_ALLOW CGO_CXXFLAGS_DISALLOW \
|
||||
CGO_FFLAGS CGO_FFLAGS_ALLOW CGO_FFLAGS_DISALLOW \
|
||||
CGO_LDFLAGS CGO_LDFLAGS_ALLOW CGO_LDFLAGS_DISALLOW \
|
||||
CXX \
|
||||
FC
|
||||
# Unmodified:
|
||||
# PKG_CONFIG
|
||||
|
||||
# Architecture-specific environment variables:
|
||||
unexport \
|
||||
GOARM \
|
||||
GOARM64 \
|
||||
GO386 \
|
||||
GOAMD64 \
|
||||
GOMIPS \
|
||||
GOMIPS64 \
|
||||
GOPPC64 \
|
||||
GORISCV64 \
|
||||
GOWASM
|
||||
|
||||
# Environment variables for use with code coverage:
|
||||
unexport \
|
||||
GOCOVERDIR
|
||||
|
||||
# Special-purpose environment variables:
|
||||
unexport \
|
||||
GCCGOTOOLDIR \
|
||||
GOEXPERIMENT \
|
||||
GOROOT_FINAL \
|
||||
GO_EXTLINK_ENABLED
|
||||
# Unmodified:
|
||||
# GIT_ALLOW_PROTOCOL
|
||||
|
||||
# From https://pkg.go.dev/runtime#hdr-Environment_Variables
|
||||
unexport \
|
||||
GOGC \
|
||||
GOMEMLIMIT \
|
||||
GOMAXPROCS \
|
||||
GORACE \
|
||||
GOTRACEBACK
|
||||
|
||||
# From https://pkg.go.dev/cmd/cgo#hdr-Using_cgo_with_the_go_command
|
||||
unexport \
|
||||
CC_FOR_TARGET \
|
||||
CXX_FOR_TARGET
|
||||
# Todo:
|
||||
# CC_FOR_${GOOS}_${GOARCH}
|
||||
# CXX_FOR_${GOOS}_${GOARCH}
|
||||
|
||||
# From https://go.dev/doc/install/source#environment
|
||||
unexport \
|
||||
GOHOSTOS \
|
||||
GOHOSTARCH
|
||||
|
||||
# From https://go.dev/src/make.bash
|
||||
unexport \
|
||||
GO_GCFLAGS \
|
||||
GO_LDFLAGS \
|
||||
GO_LDSO \
|
||||
GO_DISTFLAGS \
|
||||
GOBUILDTIMELOGFILE \
|
||||
GOROOT_BOOTSTRAP
|
||||
|
||||
# From https://go.dev/doc/go1.9#parallel-compile
|
||||
unexport \
|
||||
GO19CONCURRENTCOMPILATION
|
||||
|
||||
# From https://go.dev/src/cmd/dist/build.go
|
||||
unexport \
|
||||
BOOT_GO_GCFLAGS \
|
||||
BOOT_GO_LDFLAGS
|
||||
|
||||
# From https://go.dev/src/cmd/dist/buildtool.go
|
||||
unexport \
|
||||
GOBOOTSTRAP_TOOLEXEC
|
||||
|
||||
|
||||
GO_DEFAULT_VERSION:=1.26
|
||||
GO_HOST_VERSION:=$(patsubst golang%/host,%,$(filter golang%/host,$(PKG_BUILD_DEPENDS)))
|
||||
ifeq ($(GO_HOST_VERSION),)
|
||||
GO_HOST_VERSION:=$(GO_DEFAULT_VERSION)
|
||||
endif
|
||||
|
||||
# GOOS / GOARCH
|
||||
|
||||
go_arch=$(subst \
|
||||
aarch64,arm64,$(subst \
|
||||
i386,386,$(subst \
|
||||
loongarch64,loong64,$(subst \
|
||||
mipsel,mipsle,$(subst \
|
||||
mips64el,mips64le,$(subst \
|
||||
powerpc64,ppc64,$(subst \
|
||||
x86_64,amd64,$(1))))))))
|
||||
|
||||
GO_OS:=linux
|
||||
GO_ARCH:=$(call go_arch,$(ARCH))
|
||||
GO_OS_ARCH:=$(GO_OS)/$(GO_ARCH)
|
||||
|
||||
GO_HOST_OS:=$(call tolower,$(HOST_OS))
|
||||
GO_HOST_ARCH:=$(call go_arch,$(subst \
|
||||
armv6l,arm,$(subst \
|
||||
armv7l,arm,$(subst \
|
||||
i686,i386,$(HOST_ARCH)))))
|
||||
GO_HOST_OS_ARCH:=$(GO_HOST_OS)/$(GO_HOST_ARCH)
|
||||
|
||||
# Filter lists for ARM64 cores
|
||||
# See https://en.wikipedia.org/wiki/ARM_architecture_family#Cores
|
||||
GO_ARM64_V8_0_CORES= \
|
||||
cortex-a34 \
|
||||
cortex-a35 \
|
||||
cortex-a53 \
|
||||
cortex-a57 \
|
||||
cortex-a72 \
|
||||
cortex-a73
|
||||
GO_ARM64_V8_2_CORES= \
|
||||
cortex-a55 \
|
||||
cortex-a65 \
|
||||
cortex-a75 \
|
||||
cortex-a76 \
|
||||
cortex-a77 \
|
||||
cortex-a78 \
|
||||
cortex-x1
|
||||
GO_ARM64_V9_0_CORES= \
|
||||
cortex-a510 \
|
||||
cortex-a710 \
|
||||
cortex-a715 \
|
||||
cortex-x2 \
|
||||
cortex-x3
|
||||
GO_ARM64_V9_2_CORES= \
|
||||
cortex-a520 \
|
||||
cortex-a720 \
|
||||
cortex-x4
|
||||
|
||||
ifeq ($(GO_OS_ARCH),$(GO_HOST_OS_ARCH))
|
||||
GO_HOST_TARGET_SAME:=1
|
||||
else
|
||||
GO_HOST_TARGET_DIFFERENT:=1
|
||||
endif
|
||||
|
||||
ifeq ($(GO_ARCH),386)
|
||||
ifeq ($(CONFIG_TARGET_x86_geode)$(CONFIG_TARGET_x86_legacy),y)
|
||||
GO_386:=softfloat
|
||||
else
|
||||
GO_386:=sse2
|
||||
endif
|
||||
|
||||
# -fno-plt: causes "unexpected GOT reloc for non-dynamic symbol" errors
|
||||
GO_CFLAGS_TO_REMOVE:=-fno-plt
|
||||
|
||||
else ifeq ($(GO_ARCH),amd64)
|
||||
GO_AMD64:=v1
|
||||
|
||||
else ifeq ($(GO_ARCH),arm)
|
||||
GO_TARGET_FPU:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
|
||||
|
||||
# FPU names from https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gcc/ARM-Options.html#index-mfpu-1
|
||||
# see also https://github.com/gcc-mirror/gcc/blob/releases/gcc-8.4.0/gcc/config/arm/arm-cpus.in
|
||||
|
||||
ifeq ($(GO_TARGET_FPU),)
|
||||
GO_ARM:=5
|
||||
else ifneq ($(filter $(GO_TARGET_FPU),vfp vfpv2),)
|
||||
GO_ARM:=6
|
||||
else
|
||||
GO_ARM:=7
|
||||
endif
|
||||
|
||||
else ifeq ($(GO_ARCH),arm64)
|
||||
GO_TARGET_CPU:=$(call qstrip,$(CONFIG_CPU_TYPE))
|
||||
|
||||
ifneq ($(filter $(GO_TARGET_CPU),$(GO_ARM64_V8_0_CORES)),)
|
||||
GO_ARM64:=v8.0
|
||||
else ifneq ($(filter $(GO_TARGET_CPU),$(GO_ARM64_V8_2_CORES)),)
|
||||
GO_ARM64:=v8.2
|
||||
else ifneq ($(filter $(GO_TARGET_CPU),$(GO_ARM64_V9_0_CORES)),)
|
||||
GO_ARM64:=v9.0
|
||||
else ifneq ($(filter $(GO_TARGET_CPU),$(GO_ARM64_V9_2_CORES)),)
|
||||
GO_ARM64:=v9.2
|
||||
else
|
||||
# Unknown CPU, assume baseline
|
||||
GO_ARM64:=v8.0
|
||||
endif
|
||||
|
||||
else ifneq ($(filter $(GO_ARCH),mips mipsle),)
|
||||
ifeq ($(CONFIG_HAS_FPU),y)
|
||||
GO_MIPS:=hardfloat
|
||||
else
|
||||
GO_MIPS:=softfloat
|
||||
endif
|
||||
|
||||
# -mips32r2: conflicts with -march=mips32 set by go
|
||||
GO_CFLAGS_TO_REMOVE:=-mips32r2
|
||||
|
||||
else ifneq ($(filter $(GO_ARCH),mips64 mips64le),)
|
||||
ifeq ($(CONFIG_HAS_FPU),y)
|
||||
GO_MIPS64:=hardfloat
|
||||
else
|
||||
GO_MIPS64:=softfloat
|
||||
endif
|
||||
|
||||
else ifeq ($(GO_ARCH),ppc64)
|
||||
GO_PPC64:=power8
|
||||
|
||||
endif
|
||||
|
||||
GO_GENERATED_FILES := \
|
||||
src/cmd/cgo/zdefaultcc.go \
|
||||
src/cmd/go/internal/cfg/zdefaultcc.go \
|
||||
src/cmd/internal/objabi/zbootstrap.go \
|
||||
src/go/build/zcgo.go \
|
||||
src/internal/buildcfg/zbootstrap.go \
|
||||
src/internal/runtime/sys/zversion.go \
|
||||
src/time/tzdata/zzipdata.go
|
||||
|
||||
GO_LEGAL_FILES := \
|
||||
CONTRIBUTING.md \
|
||||
LICENSE \
|
||||
PATENTS \
|
||||
README.md \
|
||||
SECURITY.md
|
||||
|
||||
GO_BIN_FILES := \
|
||||
$(GO_GENERATED_FILES) \
|
||||
$(GO_LEGAL_FILES)
|
||||
|
||||
GO_HOST_SRC_FILTERS := ! -name '*.bat' -a ! -name '*.rc'
|
||||
GO_TARGET_SRC_FILTERS := ! -ipath '*/testdata/*' -a ! -name '*_test.go' -a ! -name '*.bat' -a ! -name '*.rc'
|
||||
GO_TARGET_TEST_FILTERS := -ipath '*/testdata/*' -o -name '*_test.go'
|
||||
|
||||
|
||||
# Target Go
|
||||
|
||||
GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||loongarch64||mips||mips64||mips64el||mipsel||riscv64||x86_64)
|
||||
|
||||
|
||||
# ASLR/PIE
|
||||
|
||||
# From https://go.dev/src/internal/platform/supported.go
|
||||
GO_PIE_SUPPORTED_OS_ARCH:= \
|
||||
aix/ppc64 \
|
||||
android/386 \
|
||||
android/amd64 \
|
||||
android/arm \
|
||||
android/arm64 \
|
||||
darwin/amd64 \
|
||||
darwin/arm64 \
|
||||
freebsd/amd64 \
|
||||
ios/amd64 \
|
||||
ios/arm64 \
|
||||
linux/386 \
|
||||
linux/amd64 \
|
||||
linux/arm \
|
||||
linux/arm64 \
|
||||
linux/loong64 \
|
||||
linux/ppc64le \
|
||||
linux/riscv64 \
|
||||
linux/s390x \
|
||||
openbsd/arm64 \
|
||||
windows/386 \
|
||||
windows/amd64 \
|
||||
windows/arm \
|
||||
windows/arm64
|
||||
|
||||
# From https://go.dev/src/cmd/go/internal/work/init.go
|
||||
go_pie_install_suffix=$(if $(filter $(1),aix/ppc64 windows/386 windows/amd64 windows/arm64),,shared)
|
||||
|
||||
ifneq ($(filter $(GO_HOST_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
|
||||
GO_HOST_PIE_SUPPORTED:=1
|
||||
GO_HOST_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_HOST_OS_ARCH))
|
||||
endif
|
||||
|
||||
ifneq ($(filter $(GO_OS_ARCH),$(GO_PIE_SUPPORTED_OS_ARCH)),)
|
||||
GO_TARGET_PIE_SUPPORTED:=1
|
||||
GO_TARGET_PIE_INSTALL_SUFFIX:=$(call go_pie_install_suffix,$(GO_OS_ARCH))
|
||||
endif
|
||||
|
||||
|
||||
# Spectre mitigations
|
||||
|
||||
GO_SPECTRE_SUPPORTED_ARCH:=amd64
|
||||
|
||||
ifneq ($(filter $(GO_HOST_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
|
||||
GO_HOST_SPECTRE_SUPPORTED:=1
|
||||
endif
|
||||
|
||||
ifneq ($(filter $(GO_ARCH),$(GO_SPECTRE_SUPPORTED_ARCH)),)
|
||||
GO_TARGET_SPECTRE_SUPPORTED:=1
|
||||
endif
|
||||
|
||||
|
||||
# General build info
|
||||
|
||||
GO_BUILD_CACHE_DIR:=$(or $(call qstrip,$(CONFIG_GOLANG_BUILD_CACHE_DIR)),$(TMP_DIR)/go-build)
|
||||
GO_MOD_CACHE_DIR:=$(DL_DIR)/go-mod-cache
|
||||
|
||||
GO_MOD_ARGS= \
|
||||
-modcacherw
|
||||
|
||||
GO_GENERAL_BUILD_CONFIG_VARS= \
|
||||
CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE="$(CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE)" \
|
||||
GO_BUILD_CACHE_DIR="$(GO_BUILD_CACHE_DIR)" \
|
||||
GO_MOD_CACHE_DIR="$(GO_MOD_CACHE_DIR)" \
|
||||
GO_MOD_ARGS="$(GO_MOD_ARGS)"
|
||||
|
||||
define Go/CacheCleanup
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh cache_cleanup
|
||||
endef
|
||||
@@ -0,0 +1,299 @@
|
||||
#
|
||||
# Copyright (C) 2018-2023 Jeffery To
|
||||
# Copyright (C) 2025-2026 George Sapkin
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG)
|
||||
HOST_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
|
||||
HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID)
|
||||
|
||||
ifeq ($(CONFIG_GOLANG_BUILD_BOOTSTRAP),y)
|
||||
BOOTSTRAP_DIR:=$(HOST_GO_PREFIX)/lib/go-$(GO_BOOTSTRAP_VERSION)
|
||||
else
|
||||
BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
|
||||
endif
|
||||
|
||||
include ../golang-compiler.mk
|
||||
include ../golang-package.mk
|
||||
include ../golang-values.mk
|
||||
|
||||
PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
|
||||
HOST_UNPACK:=$(HOST_TAR) -C "$(HOST_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
|
||||
|
||||
# Don't strip ELF executables in test data
|
||||
RSTRIP:=$(subst $(SCRIPT_DIR)/rstrip.sh,go-strip-helper $(SCRIPT_DIR)/rstrip.sh,$(RSTRIP))
|
||||
|
||||
ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
|
||||
PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
|
||||
endif
|
||||
|
||||
define Package/$(PKG_NAME)/Default
|
||||
$(call GoPackage/GoSubMenu)
|
||||
TITLE:=Go programming language
|
||||
URL:=https://go.dev/
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/Default/description
|
||||
The Go programming language is an open source project to make programmers more
|
||||
productive.
|
||||
|
||||
Go is expressive, concise, clean, and efficient. Its concurrency mechanisms
|
||||
make it easy to write programs that get the most out of multi-core and
|
||||
networked machines, while its novel type system enables flexible and modular
|
||||
program construction. Go compiles quickly to machine code yet has the
|
||||
convenience of garbage collection and the power of run-time reflection. It's
|
||||
a fast, statically typed, compiled language that feels like a dynamically
|
||||
typed, interpreted language.
|
||||
endef
|
||||
|
||||
ifeq ($(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR))
|
||||
ALT_PRIORITY:=500
|
||||
else
|
||||
ALT_PRIORITY:=100
|
||||
endif
|
||||
|
||||
# go tool requires source present:
|
||||
# https://github.com/golang/go/issues/4635
|
||||
define Package/$(PKG_NAME)
|
||||
$(call Package/$(PKG_NAME)/Default)
|
||||
TITLE+= (compiler)
|
||||
DEPENDS+= +golang$(GO_VERSION_MAJOR_MINOR)-src
|
||||
EXTRA_DEPENDS:=golang$(GO_VERSION_MAJOR_MINOR)-src (=$(PKG_VERSION)-r$(PKG_RELEASE))
|
||||
MDEPENDS:=+golang-bootstrap
|
||||
PROVIDES:=@golang
|
||||
$(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1)
|
||||
ALTERNATIVES:=\
|
||||
$(ALT_PRIORITY):/usr/bin/go:/usr/lib/go-$(GO_VERSION_MAJOR_MINOR)/bin/go \
|
||||
$(ALT_PRIORITY):/usr/bin/gofmt:/usr/lib/go-$(GO_VERSION_MAJOR_MINOR)/bin/gofmt
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
$(call Package/$(PKG_NAME)/Default/description)
|
||||
|
||||
This package provides an assembler, compiler, linker, and compiled libraries
|
||||
for the Go programming language.
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-doc
|
||||
$(call Package/$(PKG_NAME)/Default)
|
||||
TITLE+= (documentation)
|
||||
PKGARCH:=all
|
||||
PROVIDES:=@golang-doc
|
||||
$(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-doc/description
|
||||
$(call Package/$(PKG_NAME)/Default/description)
|
||||
|
||||
This package provides the documentation for the Go programming language.
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-misc
|
||||
$(call Package/$(PKG_NAME)/Default)
|
||||
TITLE+= (misc source files)
|
||||
PKGARCH:=all
|
||||
PROVIDES:=@golang-misc
|
||||
$(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-misc/description
|
||||
$(call Package/$(PKG_NAME)/Default/description)
|
||||
|
||||
This package provides the Go compiler miscellaneous sources.
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-src
|
||||
$(call Package/$(PKG_NAME)/Default)
|
||||
TITLE+= (source files)
|
||||
PKGARCH:=all
|
||||
PROVIDES:=@golang-src
|
||||
$(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-src/description
|
||||
$(call Package/$(PKG_NAME)/Default/description)
|
||||
|
||||
This package provides the Go programming language source files needed for
|
||||
cross-compilation.
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-tests
|
||||
$(call Package/$(PKG_NAME)/Default)
|
||||
TITLE+= (compiler tests)
|
||||
DEPENDS+= +golang$(GO_VERSION_MAJOR_MINOR)-src
|
||||
EXTRA_DEPENDS:=golang$(GO_VERSION_MAJOR_MINOR)-src (=$(PKG_VERSION)-r$(PKG_RELEASE))
|
||||
PKGARCH:=all
|
||||
PROVIDES:=@golang-tests
|
||||
$(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-tests/description
|
||||
$(call Package/$(PKG_NAME)/Default/description)
|
||||
|
||||
This package provides the Go compiler tests for stdlib.
|
||||
endef
|
||||
|
||||
|
||||
# Host
|
||||
|
||||
ifeq ($(GO_HOST_PIE_SUPPORTED),1)
|
||||
HOST_GO_ENABLE_PIE:=1
|
||||
endif
|
||||
|
||||
# When using GO_LDFLAGS to set buildmode=pie, the PIE install suffix does not
|
||||
# apply (we also delete the std lib during Host/Install)
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,$(HOST_GO_PROFILE_ID),$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH)))
|
||||
|
||||
HOST_GO_VARS?= \
|
||||
GOHOSTARCH="$(GO_HOST_ARCH)" \
|
||||
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
|
||||
GOENV=off \
|
||||
CC="$(HOSTCC_NOCACHE)" \
|
||||
CXX="$(HOSTCXX_NOCACHE)"
|
||||
|
||||
define Host/Configure
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/CheckHost,$(HOST_GO_VALID_OS_ARCH))
|
||||
|
||||
mkdir -p "$(GO_BUILD_CACHE_DIR)"
|
||||
endef
|
||||
|
||||
define Host/Compile
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/Make, \
|
||||
GOROOT_BOOTSTRAP="$(BOOTSTRAP_DIR)" \
|
||||
$(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
|
||||
$(HOST_GO_VARS) \
|
||||
)
|
||||
endef
|
||||
|
||||
# If host and target OS/arch are the same, when go compiles a program, it will
|
||||
# use the host std lib, so remove it now and force go to rebuild std for target
|
||||
# later
|
||||
define Host/Install
|
||||
$(call Host/Uninstall)
|
||||
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/Install/Bin)
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/Install/Src)
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/Install/BinLinks)
|
||||
|
||||
rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)"
|
||||
|
||||
$(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
|
||||
$(INSTALL_BIN) ../go-gcc-helper "$(HOST_GO_ROOT)/openwrt"
|
||||
$(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
|
||||
$(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
|
||||
endef
|
||||
|
||||
define Host/Uninstall
|
||||
rm -rf "$(HOST_GO_ROOT)/openwrt"
|
||||
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/Uninstall/BinLinks)
|
||||
$(call GoCompiler/$(HOST_GO_PROFILE_ID)/Uninstall)
|
||||
endef
|
||||
|
||||
|
||||
# Target
|
||||
|
||||
ifeq ($(GO_PKG_ENABLE_PIE),1)
|
||||
PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX)
|
||||
endif
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
|
||||
|
||||
PKG_GO_ZBOOTSTRAP_MODS?= \
|
||||
s/DefaultGO386 = `[^`]*`/DefaultGO386 = `$(or $(GO_386),sse2)`/; \
|
||||
s/DefaultGOAMD64 = `[^`]*`/DefaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \
|
||||
s/DefaultGOARM = `[^`]*`/DefaultGOARM = `$(or $(GO_ARM),7)`/; \
|
||||
s/DefaultGOARM64 = `[^`]*`/DefaultGOARM64 = `$(or $(GO_ARM64),v8.0)`/; \
|
||||
s/DefaultGOMIPS = `[^`]*`/DefaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \
|
||||
s/DefaultGOMIPS64 = `[^`]*`/DefaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \
|
||||
s/DefaultGOPPC64 = `[^`]*`/DefaultGOPPC64 = `$(or $(GO_PPC64),power8)`/;
|
||||
|
||||
PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go
|
||||
|
||||
PKG_GO_VARS?= \
|
||||
GOHOSTARCH="$(GO_HOST_ARCH)" \
|
||||
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
|
||||
GOENV=off \
|
||||
GO_GCC_HELPER_PATH="$$$$PATH" \
|
||||
CC=gcc \
|
||||
CXX=g++ \
|
||||
PKG_CONFIG=pkg-config \
|
||||
PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH"
|
||||
|
||||
PKG_GO_GCFLAGS?= \
|
||||
$(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
|
||||
|
||||
PKG_GO_ASMFLAGS?= \
|
||||
$(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
|
||||
|
||||
PKG_GO_LDFLAGS?= \
|
||||
-linkmode external \
|
||||
-extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \
|
||||
$(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
|
||||
|
||||
PKG_GO_INSTALL_ARGS?= \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-ldflags "all=$(PKG_GO_LDFLAGS)" \
|
||||
$(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \
|
||||
$(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \
|
||||
$(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie)
|
||||
|
||||
define Build/Configure
|
||||
mkdir -p "$(GO_BUILD_CACHE_DIR)"
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
@echo "Building target Go first stage"
|
||||
|
||||
$(call GoCompiler/Package/Make, \
|
||||
GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \
|
||||
GO_GCC_HELPER_CC="$(HOSTCC)" \
|
||||
GO_GCC_HELPER_CXX="$(HOSTCXX)" \
|
||||
$(PKG_GO_VARS) \
|
||||
)
|
||||
|
||||
$(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' "$(PKG_GO_ZBOOTSTRAP_PATH)"
|
||||
|
||||
@echo "Building target Go second stage"
|
||||
|
||||
cd "$(PKG_BUILD_DIR)/bin" ; \
|
||||
export $(GO_PKG_TARGET_VARS) ; \
|
||||
$(CP) go go-host ; \
|
||||
GO_GCC_HELPER_CC="$(TARGET_CC)" \
|
||||
GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
|
||||
$(PKG_GO_VARS) \
|
||||
./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd; \
|
||||
retval=$$$$? ; \
|
||||
rm -f go-host ; \
|
||||
exit $$$$retval
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX),target)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-doc/install
|
||||
$(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX))
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-misc/install
|
||||
$(call GoCompiler/Package/Install/Misc,$(1)$(PKG_GO_PREFIX))
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-src/install
|
||||
$(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX),target)
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)-tests/install
|
||||
$(call GoCompiler/Package/Install/Tests,$(1)$(PKG_GO_PREFIX))
|
||||
endef
|
||||
|
||||
# src/debug contains ELF executables as test data and they reference these
|
||||
# libraries we need to call this to pass CheckDependencies in package-pack.mk
|
||||
define Package/$(PKG_NAME)-tests/extra_provides
|
||||
echo 'libc.so.6' libstdc++.so.6' libtiff.so.6' | tr ' ' '\n'
|
||||
endef
|
||||
@@ -0,0 +1,34 @@
|
||||
# This is a dummy go package that allows packages to use default go version by
|
||||
# setting PKG_BUILD_DEPENDS:=golang/host, instead of specifying a concrete
|
||||
# version, e.g. PKG_BUILD_DEPENDS:=golang1.25/host
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include ../golang-values.mk
|
||||
|
||||
PKG_NAME:=golang
|
||||
PKG_VERSION:=$(GO_DEFAULT_VERSION)
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_MAINTAINER:=George Sapkin <george@sapk.in>
|
||||
|
||||
HOST_BUILD_DEPENDS:=golang$(PKG_VERSION)/host
|
||||
PKG_HOST_ONLY:=1
|
||||
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/golang
|
||||
TITLE:=Go programming language (dummy package)
|
||||
BUILDONLY:=1
|
||||
endef
|
||||
|
||||
define Host/Compile
|
||||
endef
|
||||
|
||||
define Host/Install
|
||||
endef
|
||||
|
||||
$(eval $(call HostBuild))
|
||||
$(eval $(call BuildPackage,golang))
|
||||
@@ -0,0 +1,104 @@
|
||||
#
|
||||
# Copyright (C) 2018-2023 Jeffery To
|
||||
# Copyright (C) 2025-2026 George Sapkin
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=golang1.26
|
||||
GO_VERSION_MAJOR_MINOR:=1.26
|
||||
GO_VERSION_PATCH:=4
|
||||
GO_VERSION_RC:=
|
||||
GO_BOOTSTRAP_VERSION:=bootstrap
|
||||
PKG_HASH:=4f668a32fbfc1132e6a881fb968c2f1dada631492a339211735fbb255a42602d
|
||||
|
||||
PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_RC),.0)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
|
||||
PKG_FILE_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_RC),rc$(GO_VERSION_RC))$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
|
||||
PKG_RELEASE:=1
|
||||
|
||||
GO_SOURCE_URLS:=https://go.dev/dl/ \
|
||||
https://golang.google.cn/dl/ \
|
||||
https://mirrors.nju.edu.cn/golang/ \
|
||||
https://mirrors.ustc.edu.cn/golang/
|
||||
|
||||
PKG_SOURCE:=go$(PKG_FILE_VERSION).src.tar.gz
|
||||
PKG_SOURCE_URL:=$(GO_SOURCE_URLS)
|
||||
|
||||
PKG_MAINTAINER:=George Sapkin <george@sapk.in>
|
||||
PKG_LICENSE:=BSD-3-Clause
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_CPE_ID:=cpe:/a:golang:go
|
||||
|
||||
PKG_BUILD_DEPENDS:=$(PKG_NAME)/host
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION)
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
PKG_GO_PREFIX:=/usr
|
||||
PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
|
||||
|
||||
HOST_BUILD_DEPENDS:=golang$(if $(filter bootstrap,$(GO_BOOTSTRAP_VERSION)),-)$(GO_BOOTSTRAP_VERSION)/host
|
||||
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
|
||||
HOST_BUILD_PARALLEL:=1
|
||||
|
||||
# From go tool dist list
|
||||
HOST_GO_VALID_OS_ARCH:= \
|
||||
aix/ppc64 \
|
||||
android/386 \
|
||||
android/amd64 \
|
||||
android/arm \
|
||||
android/arm64 \
|
||||
darwin/amd64 \
|
||||
darwin/arm64 \
|
||||
dragonfly/amd64 \
|
||||
freebsd/386 \
|
||||
freebsd/amd64 \
|
||||
freebsd/arm \
|
||||
freebsd/arm64 \
|
||||
illumos/amd64 \
|
||||
ios/amd64 \
|
||||
ios/arm64 \
|
||||
js/wasm \
|
||||
linux/386 \
|
||||
linux/amd64 \
|
||||
linux/arm \
|
||||
linux/arm64 \
|
||||
linux/loong64 \
|
||||
linux/mips \
|
||||
linux/mips64 \
|
||||
linux/mips64le \
|
||||
linux/mipsle \
|
||||
linux/ppc64 \
|
||||
linux/ppc64le \
|
||||
linux/riscv64 \
|
||||
linux/s390x \
|
||||
netbsd/386 \
|
||||
netbsd/amd64 \
|
||||
netbsd/arm \
|
||||
netbsd/arm64 \
|
||||
openbsd/386 \
|
||||
openbsd/amd64 \
|
||||
openbsd/arm \
|
||||
openbsd/arm64 \
|
||||
openbsd/ppc64 \
|
||||
openbsd/riscv64 \
|
||||
plan9/386 \
|
||||
plan9/amd64 \
|
||||
plan9/arm \
|
||||
solaris/amd64 \
|
||||
wasip1/wasm \
|
||||
windows/386 \
|
||||
windows/amd64 \
|
||||
windows/arm64
|
||||
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../golang-version.mk
|
||||
|
||||
$(eval $(call HostBuild))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)-doc))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)-misc))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)-src))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)-tests))
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
# shellcheck shell=busybox
|
||||
|
||||
case "$PKG_NAME" in
|
||||
golang?.??-doc|\
|
||||
golang?.??-misc|\
|
||||
golang?.??-src|\
|
||||
golang?.??-tests)
|
||||
exit 0
|
||||
;;
|
||||
|
||||
golang?.??)
|
||||
go version | grep -F " go$PKG_VERSION "
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Untested package: $PKG_NAME" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
case "$1" in
|
||||
golang*doc|golang*misc|golang*src|golang*tests) exit ;;
|
||||
esac
|
||||
|
||||
cat <<'EOF' > hello.go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
}
|
||||
|
||||
EOF
|
||||
|
||||
go run hello.go
|
||||
rm hello.go
|
||||
Reference in New Issue
Block a user