libgo: better error messages for unknown GOARCH/GOOS

For https://gcc.gnu.org/pr113530

Change-Id: I4658739e396a0d0c1e35d4f548a1d25a57995299
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/557655
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index c95dc21..3eccadb 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -497,6 +497,10 @@
 zgoarch.go: s-zgoarch; @true
 s-zgoarch: Makefile goarch.sh
 	rm -f zgoarch.go.tmp
+	if ! $(SHELL) $(srcdir)/goarch.sh $(GOARCH) family >/dev/null 2>/dev/null;  then \
+	  $(SHELL) $(srcdir)/goarch.sh $(GOARCH) family; \
+	  exit 1; \
+	fi
 	echo "package goarch" > zgoarch.go.tmp
 	echo >> zgoarch.go.tmp
 	echo 'const GOARCH = "'$(GOARCH)'"' >> zgoarch.go.tmp
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index 8dcb6d6..0a2b7ee 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -2716,6 +2716,10 @@
 zgoarch.go: s-zgoarch; @true
 s-zgoarch: Makefile goarch.sh
 	rm -f zgoarch.go.tmp
+	if ! $(SHELL) $(srcdir)/goarch.sh $(GOARCH) family >/dev/null 2>/dev/null;  then \
+	  $(SHELL) $(srcdir)/goarch.sh $(GOARCH) family; \
+	  exit 1; \
+	fi
 	echo "package goarch" > zgoarch.go.tmp
 	echo >> zgoarch.go.tmp
 	echo 'const GOARCH = "'$(GOARCH)'"' >> zgoarch.go.tmp
diff --git a/libgo/configure b/libgo/configure
index db371bc..20bff2b 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -14107,6 +14107,10 @@
 
 
 
+if test "${GOOS}" = "unknown"; then
+   as_fn_error $? "\"could not determine GOOS from ${host}\"" "$LINENO" 5
+fi
+
 USE_DEJAGNU=no
 case ${host} in
   *-*-rtems*) USE_DEJAGNU=yes ;;
@@ -14339,6 +14343,10 @@
 
 
 
+if test "${GOARCH}" = "unknown"; then
+   as_fn_error $? "\"could not determine GOARCH from ${host}\"" "$LINENO" 5
+fi
+
  if test "$GOARCH" = "386" -o "$GOARCH" = "amd64" -o "$GOARCH" = "amd64p32"; then
   LIBGO_IS_X86_TRUE=
   LIBGO_IS_X86_FALSE='#'
diff --git a/libgo/configure.ac b/libgo/configure.ac
index e8d66f8..22158ac 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -209,6 +209,10 @@
 AC_SUBST(GOOS)
 AC_SUBST(ALLGOOS)
 
+if test "${GOOS}" = "unknown"; then
+   AC_MSG_ERROR("could not determine GOOS from ${host}")
+fi
+
 dnl Test whether we need to use DejaGNU or whether we can use the
 dnl simpler gotest approach.  We can only use gotest for a native
 dnl build.
@@ -376,6 +380,10 @@
 AC_SUBST(ALLGOARCH)
 AC_SUBST(ALLGOARCHFAMILY)
 
+if test "${GOARCH}" = "unknown"; then
+   AC_MSG_ERROR("could not determine GOARCH from ${host}")
+fi
+
 AM_CONDITIONAL(LIBGO_IS_X86, test "$GOARCH" = "386" -o "$GOARCH" = "amd64" -o "$GOARCH" = "amd64p32")
 
 FUNCTION_DESCRIPTORS=false