-case "$machine" in
-mips64*) base_machine=mips64
- case "$CC $CFLAGS $CPPFLAGS " in
- *" -mabi=n32 "*) mips_cc_abi=n32 ;;
- *" -mabi=64 "*|*" -mabi=n64 "*) mips_cc_abi=64 ;;
- *" -mabi=32 "*|*" -mabi=o32 "*) mips_cc_abi=32 ;;
- *) mips_cc_abi=default ;;
- esac
- case $config_os in
- *abin32*) mips_config_abi=n32 ;;
- *abi64*|*abin64*) mips_config_abi=64 ;;
- *abi32*|*abio32*) mips_config_abi=32 ;;
- *) mips_config_abi=$mips_cc_abi ;;
- esac
- case $mips_config_abi in
- default) machine=mips/mips64/n32 mips_config_abi=n32 ;;
- n32) machine=mips/mips64/n32 ;;
- 64) machine=mips/mips64/n64 ;;
- 32) machine=mips/mips32/kern64 ;;
- esac
- machine=$machine/$config_machine
- if test $mips_config_abi != $mips_cc_abi; then
- # This won't make it to config.make, but we want to
- # set this in case configure tests depend on it.
- CPPFLAGS="$CPPFLAGS -mabi=$mips_config_abi"
- fi
- ;;
-mips*) base_machine=mips
- case "$CC $CFLAGS $CPPFLAGS " in
- *" -mips16 "*) machine=mips/mips32/mips16/$machine ;;
- *) machine=mips/mips32/$machine ;;
- esac
- ;;
-esac
+abiflag=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define _MIPS_SIM \(.*\)/\1/p'`
+mips16flag=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __mips16 \(.*\)/\1/p'`
+
+base_machine=mips
+if test "$abiflag" = "_ABIO32" ; then
+ if test "$mips16flag" = "1" ; then
+ machine=mips/mips32/mips16
+ else
+ machine=mips/mips32
+ fi
+elif test "$abiflag" = "_ABIN32" ; then
+ machine=mips/mips64/n32
+elif test "$abiflag" = "_ABI64" ; then
+ machine=mips/mips64/n64
+else
+ as_fn_error $? "Unable to determine ABI." "$LINENO" 5
+fi
+# $config_machine is not really needed here but the slash after $machine is
+# needed by the case statement in sysdeps/unix/sysv/linux/mips/configure.ac.
+machine=$machine/$config_machine
+
+if test "$abiflag" != "_ABIO32" -a "$mips16flag" = "1"; then
+ as_fn_error $? "mips16 is only supported with the O32 ABI." "$LINENO" 5
+fi