Index: Modules/_ctypes/libffi/configure
===================================================================
--- Modules/_ctypes/libffi/configure	(revision 68358)
+++ Modules/_ctypes/libffi/configure	(working copy)
@@ -936,6 +936,7 @@
 ALLOCA
 HAVE_LONG_DOUBLE
 TARGET
+MKTARGET
 TARGETDIR
 toolexecdir
 toolexeclibdir
@@ -5107,7 +5108,6 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
-
 { echo "$as_me:$LINENO: checking for ANSI C header files" >&5
 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; }
 if test "${ac_cv_header_stdc+set}" = set; then
@@ -20426,10 +20426,10 @@
 	;;
 
   mips-sgi-irix5.* | mips-sgi-irix6.*)
-	TARGET=MIPS; TARGETDIR=mips
+	TARGET=MIPS_IRIX; TARGETDIR=mips
 	;;
   mips*-*-linux*)
-	TARGET=MIPS; TARGETDIR=mips
+	TARGET=MIPS_LINUX; TARGETDIR=mips
 	;;
 
   powerpc*-*-linux* | powerpc-*-sysv*)
@@ -20477,13 +20477,19 @@
 esac
 
 
-
 if test $TARGETDIR = unknown; then
   { { echo "$as_me:$LINENO: error: \"libffi has not been ported to $host.\"" >&5
 echo "$as_me: error: \"libffi has not been ported to $host.\"" >&2;}
    { (exit 1); exit 1; }; }
 fi
 
+MKTARGET=$TARGET
+
+case x$TARGET in
+  xMIPS*) TARGET=MIPS ;;
+  *) ;;
+esac
+
  if test x$TARGET = xMIPS; then
   MIPS_TRUE=
   MIPS_FALSE='#'
@@ -20676,7 +20682,6 @@
   PA64_HPUX_FALSE=
 fi
 
-
 { echo "$as_me:$LINENO: checking for ANSI C header files" >&5
 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; }
 if test "${ac_cv_header_stdc+set}" = set; then
@@ -23783,13 +23788,14 @@
 HAVE_LONG_DOUBLE!$HAVE_LONG_DOUBLE$ac_delim
 TARGET!$TARGET$ac_delim
 TARGETDIR!$TARGETDIR$ac_delim
+MKTARGET!$MKTARGET$ac_delim
 toolexecdir!$toolexecdir$ac_delim
 toolexeclibdir!$toolexeclibdir$ac_delim
 LIBOBJS!$LIBOBJS$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 76; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 77; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
Index: Modules/_ctypes/libffi/fficonfig.py.in
===================================================================
--- Modules/_ctypes/libffi/fficonfig.py.in	(revision 68358)
+++ Modules/_ctypes/libffi/fficonfig.py.in	(working copy)
@@ -29,7 +29,7 @@
 }
 
 ffi_srcdir = '@srcdir@'
-ffi_sources += ffi_platforms['@TARGET@']
+ffi_sources += ffi_platforms['@MKTARGET@']
 ffi_sources = [os.path.join('@srcdir@', f) for f in ffi_sources]
 
 ffi_cflags = '@CFLAGS@'
Index: Modules/_ctypes/libffi/configure.ac
===================================================================
--- Modules/_ctypes/libffi/configure.ac	(revision 68358)
+++ Modules/_ctypes/libffi/configure.ac	(working copy)
@@ -106,10 +106,10 @@
 	;;
 
   mips-sgi-irix5.* | mips-sgi-irix6.*)
-	TARGET=MIPS; TARGETDIR=mips
+	TARGET=MIPS_IRIX; TARGETDIR=mips
 	;;
   mips*-*-linux*)
-	TARGET=MIPS; TARGETDIR=mips
+	TARGET=MIPS_LINUX; TARGETDIR=mips
 	;;
 
   powerpc*-*-linux* | powerpc-*-sysv*)
@@ -162,6 +162,12 @@
   AC_MSG_ERROR(["libffi has not been ported to $host."])
 fi
 
+dnl  libffi changes TARGET for MIPS to define a such macro in the header
+dnl  while MIPS_IRIX or MIPS_LINUX is separatedly used to decide which
+dnl  files will be compiled.  So, we need to keep the original decision
+dnl  of TARGET to use in fficonfig.py.in.
+MKTARGET=$TARGET
+
 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
 AM_CONDITIONAL(X86, test x$TARGET = xX86)
@@ -309,6 +315,7 @@
 
 AC_SUBST(TARGET)
 AC_SUBST(TARGETDIR)
+AC_SUBST(MKTARGET)
 
 AC_SUBST(SHELL)
 
