diff -Naur libffi-3.2.1-orig/compile libffi-3.2.1/compile
--- libffi-3.2.1-orig/compile	2014-11-12 14:59:58.000000000 +0300
+++ libffi-3.2.1/compile	2014-11-13 22:47:16.770200000 +0300
@@ -53,7 +53,7 @@
 	  MINGW*)
 	    file_conv=mingw
 	    ;;
-	  CYGWIN*)
+	  CYGWIN*|MSYS*)
 	    file_conv=cygwin
 	    ;;
 	  *)
@@ -67,7 +67,7 @@
 	mingw/*)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
-	cygwin/*)
+	cygwin/*|msys/*)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	wine/*)
diff -Naur libffi-3.2.1-orig/config.guess libffi-3.2.1/config.guess
--- libffi-3.2.1-orig/config.guess	2014-11-12 14:59:58.000000000 +0300
+++ libffi-3.2.1/config.guess	2014-11-13 22:47:48.297800000 +0300
@@ -866,6 +866,9 @@
     amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
 	echo x86_64-unknown-cygwin
 	exit ;;
+    amd64:MSYS*:*:* | x86_64:MSYS*:*:*)
+	echo x86_64-unknown-msys
+	exit ;;
     p*:CYGWIN*:*)
 	echo powerpcle-unknown-cygwin
 	exit ;;
diff -Naur libffi-3.2.1-orig/configure.ac libffi-3.2.1/configure.ac
--- libffi-3.2.1-orig/configure.ac	2014-11-12 14:56:51.000000000 +0300
+++ libffi-3.2.1/configure.ac	2014-11-13 22:48:56.625800000 +0300
@@ -132,9 +132,9 @@
   i?86-*-freebsd* | i?86-*-openbsd*)
 	TARGET=X86_FREEBSD; TARGETDIR=x86
 	;;
-  i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
+  i?86-win32* | i?86-*-cygwin* | i?86-*-msys | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
 	TARGET=X86_WIN32; TARGETDIR=x86
-	# All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
+	# All mingw/cygwin/msys/win32 builds require -no-undefined for sharedlib.
 	# We must also check with_cross_host to decide if this is a native
 	# or cross-build and select where to install dlls appropriately.
 	if test -n "$with_cross_host" &&
@@ -160,9 +160,9 @@
 	TARGET=X86_DARWIN; TARGETDIR=x86
 	;;
 
-  x86_64-*-cygwin* | x86_64-*-mingw*)
+  x86_64-*-cygwin* | x86_64-*-msys | x86_64-*-mingw*)
 	TARGET=X86_WIN64; TARGETDIR=x86
-	# All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
+	# All mingw/cygwin/msys/win32 builds require -no-undefined for sharedlib.
 	# We must also check with_cross_host to decide if this is a native
 	# or cross-build and select where to install dlls appropriately.
 	if test -n "$with_cross_host" &&
diff -Naur libffi-3.2.1-orig/testsuite/lib/target-libpath.exp libffi-3.2.1/testsuite/lib/target-libpath.exp
--- libffi-3.2.1-orig/testsuite/lib/target-libpath.exp	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/lib/target-libpath.exp	2014-11-13 22:49:37.934600000 +0300
@@ -175,7 +175,7 @@
   } else {
     setenv DYLD_LIBRARY_PATH "$ld_library_path"
   }
-  if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
+  if { [istarget *-*-cygwin*] || [istarget *-*-msys*] || [istarget *-*-mingw*] } {
     if { $orig_path_saved } {
       setenv PATH "$ld_library_path:$orig_path"
     } else {
@@ -271,7 +271,7 @@
 
     if { [ istarget *-*-darwin* ] } {
 	set shlib_ext "dylib"
-    } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-mingw* ] } {
+    } elseif { [ istarget *-*-cygwin* ] || [istarget *-*-msys*] || [ istarget *-*-mingw* ] } {
 	set shlib_ext "dll"
     } elseif { [ istarget hppa*-*-hpux* ] } {
 	set shlib_ext "sl"
diff -Naur libffi-3.2.1-orig/testsuite/libffi.call/cls_align_longdouble_split.c libffi-3.2.1/testsuite/libffi.call/cls_align_longdouble_split.c
--- libffi-3.2.1-orig/testsuite/libffi.call/cls_align_longdouble_split.c	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/libffi.call/cls_align_longdouble_split.c	2014-11-13 22:50:14.048600000 +0300
@@ -4,10 +4,10 @@
    PR:		none.
    Originator:	<hos@tamanegi.org> 20031203	 */
 
-/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
-/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 
 #include "ffitest.h"
 
diff -Naur libffi-3.2.1-orig/testsuite/libffi.call/cls_align_longdouble_split2.c libffi-3.2.1/testsuite/libffi.call/cls_align_longdouble_split2.c
--- libffi-3.2.1-orig/testsuite/libffi.call/cls_align_longdouble_split2.c	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/libffi.call/cls_align_longdouble_split2.c	2014-11-13 22:50:37.604600000 +0300
@@ -5,10 +5,10 @@
 	Originator:		Blake Chaffin	6/18/2007
 */
 
-/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*msys* } } */
 /* { dg-do run { xfail strongarm*-*-* } } */
 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
-/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 
 #include "ffitest.h"
 
diff -Naur libffi-3.2.1-orig/testsuite/libffi.call/cls_longdouble.c libffi-3.2.1/testsuite/libffi.call/cls_longdouble.c
--- libffi-3.2.1-orig/testsuite/libffi.call/cls_longdouble.c	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/libffi.call/cls_longdouble.c	2014-11-13 22:51:00.318200000 +0300
@@ -4,12 +4,12 @@
    PR:			none.
    Originator:	Blake Chaffin	*/
 
-/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 /* This test is known to PASS on armv7l-unknown-linux-gnueabihf, so I have
    remove the xfail for arm*-*-* below, until we know more.  */
 /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
-/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 
 #include "ffitest.h"
 
diff -Naur libffi-3.2.1-orig/testsuite/libffi.call/float2.c libffi-3.2.1/testsuite/libffi.call/float2.c
--- libffi-3.2.1-orig/testsuite/libffi.call/float2.c	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/libffi.call/float2.c	2014-11-13 22:51:14.701400000 +0300
@@ -4,8 +4,8 @@
    PR:		none.
    Originator:	From the original ffitest.c  */
 
-/* { dg-excess-errors "fails" { target x86_64-*-mingw* x86_64-*-cygwin* } } */
-/* { dg-do run { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-excess-errors "fails" { target x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
+/* { dg-do run { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 
 #include "ffitest.h"
 #include "float.h"
diff -Naur libffi-3.2.1-orig/testsuite/libffi.call/huge_struct.c libffi-3.2.1/testsuite/libffi.call/huge_struct.c
--- libffi-3.2.1-orig/testsuite/libffi.call/huge_struct.c	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/libffi.call/huge_struct.c	2014-11-13 22:51:25.231400000 +0300
@@ -5,11 +5,11 @@
 	Originator:		Blake Chaffin	6/18/2007
 */
 
-/* { dg-excess-errors "" { target x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-excess-errors "" { target x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
 /* { dg-options -Wformat=0 { target moxie*-*-elf } } */
-/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 
 #include "ffitest.h"
 
diff -Naur libffi-3.2.1-orig/testsuite/libffi.call/return_ldl.c libffi-3.2.1/testsuite/libffi.call/return_ldl.c
--- libffi-3.2.1-orig/testsuite/libffi.call/return_ldl.c	2014-11-08 15:47:24.000000000 +0300
+++ libffi-3.2.1/testsuite/libffi.call/return_ldl.c	2014-11-13 22:51:35.761400000 +0300
@@ -4,7 +4,7 @@
    PR:		none.
    Originator:	<andreast@gcc.gnu.org> 20071113  */
 
-/* { dg-do run { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
+/* { dg-do run { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
 #include "ffitest.h"
 
 static long double return_ldl(long double ldl)
