#! /bin/sh -e
 
# DP: disable all libraries except libstdc++ for biarch
 
dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p1 < $0
        #cd ${dir}gcc && autoconf
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
        #rm ${dir}gcc/configure
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- src/config-ml.in.bak	2002-11-12 15:32:40.000000000 +0100
+++ src/config-ml.in	2002-11-12 15:38:55.000000000 +0100
@@ -516,6 +516,48 @@
 	  ;;
 	esac
 	;;
+s390-*-*)
+	ac_configure_args="${ac_configure_args} --host=s390x-linux"
+
+	case " $multidirs " in
+	*" 64 "*)
+	  # We will not be able to create libraries with -m64 if
+	  # we cannot even link a trivial program.  It usually
+	  # indicates the 64bit libraries are missing.
+	  if echo 'main() {}' > conftest.c &&
+	     ${CC-gcc} -m64 conftest.c -o conftest; then
+	    echo Enable only libstdc++.
+	    old_multidirs="${multidirs}"
+	    multidirs=""
+	    for x in ${old_multidirs}; do
+	      case "$x" in
+	      *64* ) case ${ml_realsrcdir} in
+			*"libstdc++-v3" ) multidirs="${multidirs} ${x}" ;;
+			*"libf2c" ) multidirs="${multidirs} ${x}" ;;
+			*"libobjc" ) multidirs="${multidirs} ${x}" ;;
+			*"libiberty" ) multidirs="${multidirs} ${x}" ;;
+			*"zlib" ) multidirs="${multidirs} ${x}" ;;
+			*) : ;;
+		     esac 
+		     ;;
+	      *) multidirs="${multidirs} ${x}" ;;
+	      esac
+	    done
+	  else
+	    echo Could not link program with -m64, disabling it.
+	    old_multidirs="${multidirs}"
+	    multidirs=""
+	    for x in ${old_multidirs}; do
+	      case "$x" in
+	      *64* ) : ;;
+	      *) multidirs="${multidirs} ${x}" ;;
+	      esac
+	    done
+	  fi
+	  rm -f conftest.c conftest
+	  ;;
+	esac
+	;;
 esac
 
 # Remove extraneous blanks from multidirs.
@@ -898,9 +900,20 @@
 	fi
     fi
 
+    ml_configure_args=
+    for arg in ${ac_configure_args}
+    do
+      case $arg in
+      *CC=*)  ml_configure_args=${ml_config_env} ;;
+      *CXX=*) ml_configure_args=${ml_config_env} ;;
+      *GCJ=*) ml_configure_args=${ml_config_env} ;;
+      *) ;;
+      esac
+    done
+
     if eval ${ml_config_env} ${ml_config_shell} ${ml_recprog} \
 	--with-multisubdir=${ml_dir} --with-multisrctop=${multisrctop} \
-	${ac_configure_args} ${ml_srcdiroption} ; then
+	${ac_configure_args} ${ml_configure_args} ${ml_srcdiroption} ; then
       true
     else
       exit 1

