commit: 29f0721c4bc11ef3b9d94590016c25a190bc0f20
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 9 20:39:11 2024 +0000
Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Tue Jul 16 09:15:59 2024 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=29f0721c
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 <AT> gentoo.org>
eclass/go-env.eclass | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
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: