summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@gentoo.org>2024-07-09 21:39:11 +0100
committerJames Le Cuirot <chewi@gentoo.org>2024-07-16 10:15:59 +0100
commit29f0721c4bc11ef3b9d94590016c25a190bc0f20 (patch)
tree3bf09ceb37ace56ac76c6938be9582c01933a4c1 /eclass
parentgo-env.eclass: Rewrite the go-env_goarch() logic (diff)
downloadgentoo-29f0721c4bc11ef3b9d94590016c25a190bc0f20.tar.gz
gentoo-29f0721c4bc11ef3b9d94590016c25a190bc0f20.tar.bz2
gentoo-29f0721c4bc11ef3b9d94590016c25a190bc0f20.zip
go-env.eclass: Add the go-env_goos() helper function
This code is taken from dev-lang/go. No other packages have code like this, but some erroneously call `go env GOOS`, which is bad for cross-compiling. They should use this function instead. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r--eclass/go-env.eclass18
1 files changed, 18 insertions, 0 deletions
diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass
index c839c41be0d7..be131133113b 100644
--- a/eclass/go-env.eclass
+++ b/eclass/go-env.eclass
@@ -48,6 +48,24 @@ go-env_set_compile_environment() {
export CGO_LDFLAGS="${CGO_LDFLAGS:-$LDFLAGS}"
}
+# @FUNCTION: go-env_goos
+# @USAGE: [toolchain prefix]
+# @DESCRIPTION:
+# Returns the appropriate GOOS setting for the target operating system.
+go-env_goos() {
+ local target=${1:-${CHOST}}
+ case "${target}" in
+ *-linux*) echo linux ;;
+ *-darwin*) echo darwin ;;
+ *-freebsd*) echo freebsd ;;
+ *-netbsd*) echo netbsd ;;
+ *-openbsd*) echo openbsd ;;
+ *-solaris*) echo solaris ;;
+ *-cygwin*|*-interix*|*-winnt*) echo windows ;;
+ *) die "unknown GOOS for ${target}" ;;
+ esac
+}
+
# @FUNCTION: go-env_goarch
# @USAGE: [toolchain prefix]
# @DESCRIPTION: