From cee3930e5ecce3ec45680c5c791ef173c858f59c Mon Sep 17 00:00:00 2001
From: Bob Dubner <rdubner@symas.com>
Date: Tue, 11 Feb 2025 15:18:37 -0500
Subject: [PATCH] configure.ac allows COBOL only for x86_64 and aarch64
 architectures.

---
 configure           | 50 +++++++++++++++++++++++++++++++++++++++++++++
 configure.ac        | 30 +++++++++++++++++++++++++++
 gcc/cobol/ChangeLog |  5 +++++
 3 files changed, 85 insertions(+)

diff --git a/configure b/configure
index 2180bff9da43..39c65a56eda3 100755
--- a/configure
+++ b/configure
@@ -3513,6 +3513,26 @@ $as_echo "yes" >&6; }
     fi
 fi
 
+# Disable libgcobol on unsupported systems.
+# For testing, you can override this with --enable-libgcobol.
+if test -d ${srcdir}/libgcobol; then
+    if test x$enable_libgcobol = x; then
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libgcobol support" >&5
+$as_echo_n "checking for libgcobol support... " >&6; }
+	if (srcdir=${srcdir}/libgcobol; \
+		. ${srcdir}/configure.tgt; \
+		test "$LIBGCOBOL_SUPPORTED" != "yes")
+	then
+	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	    noconfigdirs="$noconfigdirs target-libgcobol"
+	else
+	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	fi
+    fi
+fi
+
 # Disable Fortran for some systems.
 case "${target}" in
   mmix-*-*)
@@ -10214,6 +10234,36 @@ fi
   stage1_languages=`echo "$stage1_languages" | sed -e "s/^,//" -e "s/,$//"`
   new_enable_languages=`echo "$new_enable_languages" | sed -e "s/^,//" -e "s/,$//"`
 
+# It's early days for COBOL, and it is known to compile on only some host and
+# target systems.  We remove COBOL from other builds with a warning.
+
+cobol_is_okay_host="no"
+cobol_is_okay_target="no"
+
+case "${host}" in
+  x86_64-*-*)
+    cobol_is_okay_host="yes"
+    ;;
+  aarch64-*-*)
+    cobol_is_okay_host="yes"
+    ;;
+esac
+case "${target}" in
+  x86_64-*-*)
+    cobol_is_okay_target="yes"
+    ;;
+  aarch64-*-*)
+    cobol_is_okay_target="yes"
+    ;;
+esac
+
+if test "$cobol_is_okay_host" = "no" || test "$cobol_is_okay_target" = "no"; then
+   if echo "${new_enable_languages}" | grep "cobol" >/dev/null 2>&1; then
+   echo "WARNING: cobol is not available on this host or target"
+   new_enable_languages=`echo "${new_enable_languages}" | sed s/,cobol//g`
+   fi
+fi
+
   if test "x$missing_languages" != x; then
     as_fn_error $? "
 The following requested languages could not be built: ${missing_languages}
diff --git a/configure.ac b/configure.ac
index 4182de3d65a6..f521fd410ec0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2543,6 +2543,36 @@ directories, to avoid imposing the performance cost of
   missing_languages=`echo "$missing_languages" | sed -e "s/^,//" -e "s/,$//"`
   stage1_languages=`echo "$stage1_languages" | sed -e "s/^,//" -e "s/,$//"`
   new_enable_languages=`echo "$new_enable_languages" | sed -e "s/^,//" -e "s/,$//"`
+  
+# It's early days for COBOL, and it is known to compile on only some host and
+# target systems.  We remove COBOL from other builds with a warning.
+
+cobol_is_okay_host="no"
+cobol_is_okay_target="no"
+
+case "${host}" in
+  x86_64-*-*)
+    cobol_is_okay_host="yes"
+    ;;
+  aarch64-*-*)
+    cobol_is_okay_host="yes"
+    ;;
+esac
+case "${target}" in
+  x86_64-*-*)
+    cobol_is_okay_target="yes"
+    ;;
+  aarch64-*-*)
+    cobol_is_okay_target="yes"
+    ;;
+esac
+
+if test "$cobol_is_okay_host" = "no" || test "$cobol_is_okay_target" = "no"; then
+   if echo "${new_enable_languages}" | grep "cobol" >/dev/null 2>&1; then
+   echo "WARNING: cobol is not available on this host or target"
+   new_enable_languages=`echo "${new_enable_languages}" | sed s/,cobol//g`
+   fi
+fi
 
   if test "x$missing_languages" != x; then
     AC_MSG_ERROR([
diff --git a/gcc/cobol/ChangeLog b/gcc/cobol/ChangeLog
index e79d0eb02af2..f977050f2408 100644
--- a/gcc/cobol/ChangeLog
+++ b/gcc/cobol/ChangeLog
@@ -1,3 +1,8 @@
+2025-02-11  Robert Dubner <rdubner@symas.com>
+	* libgcobol quietly is not built for -m32 systems in a multi-lib build
+	* configure.ac allows COBOL only for x86_64 and aarch64 architectures.
+    Other systems get a warning and the COBOL language is suppressed.
+
 2024-12-22  Robert Dubner <rdubner@symas.com>
 
 	* Reorganized libgcobol and gcc/cobol
-- 
GitLab