--- config.guess.origin	2017-12-30 17:33:18.000000000 +0800
+++ config.guess	2017-12-30 17:31:17.578160295 +0800
@@ -964,20 +964,45 @@
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
 	#undef CPU
-	#undef ${UNAME_MACHINE}
-	#undef ${UNAME_MACHINE}el
+	#undef MIPS_ENDIAN
+	#undef MIPS_ISA
+	#undef MIPS_BITS_REV
+	#undef ABI64
+	#undef mips
 	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
-	CPU=${UNAME_MACHINE}el
+	  #define MIPS_ENDIAN el
 	#else
-	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
-	CPU=${UNAME_MACHINE}
+	  #define MIPS_ENDIAN
+	#endif
+	#if defined(__mips_isa_rev) && (__mips_isa_rev>=6)
+	  #define MIPS_ISA isa
+	  #if defined(__mips64)
+	    #define MIPS_BITS_REV 64r6
+	  #else
+	    #define MIPS_BITS_REV 32r6
+	  #endif
+	#else
+	  #define MIPS_ISA
+	  #if defined(__mips64)
+	    #define MIPS_BITS_REV 64
+	  #else
+	    #define MIPS_BITS_REV
+	  #endif
+	#endif
+	#if defined(__mips)
+	CPU=mips MIPS_ISA MIPS_BITS_REV MIPS_ENDIAN
 	#else
 	CPU=
 	#endif
+	#if defined(_ABI64)
+	ABI64=abi64
+	#elif defined(_ABIN32)
+	ABI64=abin32
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
-	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU' | sed 's/ //g'`
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^ABI64'`
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}${ABI64}"; exit; }
 	;;
     mips64el:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
