diff -Naur swig-4.0.0-orig/configure.ac swig-4.0.0/configure.ac
--- swig-4.0.0-orig/configure.ac	2019-04-26 21:48:33.000000000 +0300
+++ swig-4.0.0/configure.ac	2019-05-27 08:51:18.860675100 +0300
@@ -133,7 +133,7 @@
 	case $host in
 	*-*-hp*) SO=.sl;;
 	*-*-darwin*) SO=.bundle;;
-	*-*-cygwin* | *-*-mingw*) SO=.dll;;
+	*-*-cygwin* | *-*-msys* | *-*-mingw*) SO=.dll;;
 	*) SO=.so;;
 	esac
 fi
@@ -148,7 +148,7 @@
 then
 	case $host in
 	*-*-aix*) LDSHARED="\$(srcdir)/ld_so_aix \$(CC)";;
-	*-*-cygwin* | *-*-mingw*)
+	*-*-cygwin* | *-*-msys* | *-*-mingw*)
             if test "$GCC" = yes; then
                 LDSHARED="$CC -shared"
             else
@@ -214,7 +214,7 @@
              fi;;
         *-*-hp*) TRYLINKINGWITHCXX="CXXSHARED= $CXX +z ";;
         *-*-darwin*) TRYLINKINGWITHCXX="CXXSHARED= $CXX -bundle -undefined suppress -flat_namespace";;
-        *-*-cygwin* | *-*-mingw*)
+        *-*-cygwin* | *-*-msys* | *-*-mingw*)
             if test "$GCC" = yes; then
                 TRYLINKINGWITHCXX="CXXSHARED= $CXX -shared "
             else
@@ -551,7 +551,7 @@
 
 # Cygwin (Windows) needs the library for dynamic linking
 case $host in
-*-*-cygwin* | *-*-mingw*) TCLDYNAMICLINKING="$TCLLIB";;
+*-*-cygwin* | *-*-msys* | *-*-mingw*) TCLDYNAMICLINKING="$TCLLIB";;
 *)TCLDYNAMICLINKING="";;
 esac
 
@@ -705,7 +705,7 @@
 
   # Cygwin (Windows) needs the library for dynamic linking
   case $host in
-  *-*-cygwin* | *-*-mingw*)
+  *-*-cygwin* | *-*-msys* | *-*-mingw*)
     PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK"
     DEFS="-DUSE_DL_IMPORT $DEFS"
     ;;
@@ -873,7 +873,7 @@
 
   # Cygwin (Windows) needs the library for dynamic linking
   case $host in
-  *-*-cygwin* | *-*-mingw*)
+  *-*-cygwin* | *-*-msys* | *-*-mingw*)
     PYTHON3DYNAMICLINKING="-L$PY3LIB $PY3LINK"
     DEFS="-DUSE_DL_IMPORT $DEFS"
     ;;
@@ -1015,7 +1015,7 @@
 
 # Cygwin (Windows) needs the library for dynamic linking
 case $host in
-*-*-cygwin* | *-*-mingw*) PERL5DYNAMICLINKING="-L$PERL5EXT -l$PERL5LIB";;
+*-*-cygwin* | *-*-msys* | *-*-mingw*) PERL5DYNAMICLINKING="-L$PERL5EXT -l$PERL5LIB";;
 *)PERL5DYNAMICLINKING="";;
 esac
 fi
@@ -1247,7 +1247,7 @@
 dnl If JAVA_HOME is defined and contains everything needed, as it's supposed to,
 dnl just use it. Otherwise try to locate the necessary files in the path.
 case $host in
-  *-*-cygwin*)
+  *-*-cygwin* | *-*-msys*)
     dnl Ensure that JAVA_HOME is in the form we can use, it's typically set to Windows path by the installer.
     if test -n "$JAVA_HOME"; then
       JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
@@ -1348,7 +1348,7 @@
 
     # Add in default installation directory on Windows for Cygwin
     case $host in
-    *-*-cygwin* | *-*-mingw*) JAVAINCDIR="c:/Program*Files*/Java/jdk*/include d:/Program*Files*/Java/jdk*/include c:/j2sdk*/include d:/j2sdk*/include c:/jdk*/include d:/jdk*/include $JAVAINCDIR";;
+    *-*-cygwin* | *-*-msys* | *-*-mingw*) JAVAINCDIR="c:/Program*Files*/Java/jdk*/include d:/Program*Files*/Java/jdk*/include c:/j2sdk*/include d:/j2sdk*/include c:/jdk*/include d:/jdk*/include $JAVAINCDIR";;
     *-*-darwin*) JAVAINCDIR="$JAVA_OSX_STD_INCDIR $JAVAINCDIR";;
     *);;
     esac
@@ -1405,7 +1405,7 @@
 fi
 
 case $host in
-*-*-cygwin*)
+*-*-cygwin* | *-*-msys*)
         # TODO: Only use this flag if the compiler supports it, later versions of gcc no longer have it
         GCC_MNO_CYGWIN=" -mno-cygwin"
         ;;
@@ -1416,7 +1416,7 @@
 
 # java.exe on Cygwin requires the Windows standard (Pascal) calling convention as it is a normal Windows executable and not a Cygwin built executable
 case $host in
-*-*-cygwin* | *-*-mingw*)
+*-*-cygwin* | *-*-msys* | *-*-mingw*)
     if test "$GCC" = yes; then
         JAVADYNAMICLINKING="$GCC_MNO_CYGWIN -mthreads -Wl,--add-stdcall-alias"
         JAVACFLAGS="$GCC_MNO_CYGWIN -mthreads"
@@ -1436,7 +1436,7 @@
 
 # Java on Windows platforms including Cygwin doesn't use libname.dll, rather name.dll when loading dlls
 case $host in
-*-*-cygwin* | *-*-mingw*) JAVALIBRARYPREFIX="";;
+*-*-cygwin* | *-*-msys* | *-*-mingw*) JAVALIBRARYPREFIX="";;
 *)JAVALIBRARYPREFIX="lib";;
 esac
 
@@ -1967,7 +1967,7 @@
 fi
 
 case $host in
-*-*-cygwin* | *-*-mingw*)	RUBYDYNAMICLINKING="-L$RUBYLIB $RUBYLINK";;
+*-*-cygwin* | *-*-msys* | *-*-mingw*)	RUBYDYNAMICLINKING="-L$RUBYLIB $RUBYLINK";;
 *)		RUBYDYNAMICLINKING="";;
 esac
 fi
@@ -2092,7 +2092,7 @@
 
 if test -z "$CSHARPCOMPILERBIN" ; then
   case $host in
-  *-*-cygwin* | *-*-mingw*)
+  *-*-cygwin* | *-*-msys* | *-*-mingw*)
     # prefer unified Mono mcs compiler (not to be confused with the ancient .NET 1 mcs) over older/alternative names.
     AC_CHECK_PROGS(CSHARPCOMPILER, csc mcs mono-csc gmcs cscc)
     if test -n "$CSHARPCOMPILER" && test "$CSHARPCOMPILER" = "csc" ; then
@@ -2149,7 +2149,7 @@
 
 # Cygwin requires the Windows standard (Pascal) calling convention as it is a Windows executable and not a Cygwin built executable
 case $host in
-*-*-cygwin* | *-*-mingw*)
+*-*-cygwin* | *-*-msys* | *-*-mingw*)
     if test "$GCC" = yes; then
         CSHARPDYNAMICLINKING="$GCC_MNO_CYGWIN -mthreads -Wl,--add-stdcall-alias"
         CSHARPCFLAGS="$GCC_MNO_CYGWIN -mthreads"
@@ -2165,7 +2165,7 @@
 
 # CSharp on Windows platforms including Cygwin doesn't use libname.dll, rather name.dll when loading dlls
 case $host in
-*-*-cygwin* | *-*-mingw*) CSHARPLIBRARYPREFIX="";;
+*-*-cygwin* | *-*-msys* | *-*-mingw*) CSHARPLIBRARYPREFIX="";;
 *)CSHARPLIBRARYPREFIX="lib";;
 esac
 
@@ -2548,7 +2548,7 @@
 
 # Do not prefix library file names with "lib" on Windows.
 case $host in
-*-*-cygwin* | *-*-mingw*) DLIBPREFIX="";;
+*-*-cygwin* | *-*-msys* | *-*-mingw*) DLIBPREFIX="";;
 *)DLIBPREFIX="lib";;
 esac
 
@@ -2714,7 +2714,7 @@
 # Root directory
 ROOT_DIR=`pwd`
 case $host in
-*-*-cygwin*)
+*-*-cygwin* | *-*-msys*)
   # Translate path for native Windows compilers for use with 'make check'
   if (cygpath --mixed $ROOT_DIR) >/dev/null 2>/dev/null; then
     ROOT_DIR=`cygpath --mixed $ROOT_DIR`
@@ -2723,7 +2723,7 @@
 esac
 
 case $host in
-*-*-cygwin* | *-*-mingw*)
+*-*-cygwin* | *-*-msys* | *-*-mingw*)
   # Extra files generated by some Windows compilers
   EXTRA_CLEAN="*.stackdump *.exp *.lib *.pdb *.ilk"
   ;;
@@ -2744,7 +2744,7 @@
 case $build in
   # Windows does not understand unix directories. Convert into a windows directory with drive letter.
   *-*-mingw*) SWIG_LIB_WIN_UNIX=`${srcdir}/Tools/convertpath -m $SWIG_LIB`;;
-  *-*-cygwin*) SWIG_LIB_WIN_UNIX=`cygpath --mixed "$SWIG_LIB"`;;
+  *-*-cygwin* | *-*-msys*) SWIG_LIB_WIN_UNIX=`cygpath --mixed "$SWIG_LIB"`;;
   *) SWIG_LIB_WIN_UNIX="";;
 esac
 AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, ["$SWIG_LIB_WIN_UNIX"], [Directory for SWIG system-independent libraries (Unix install on native Windows)])
diff -Naur swig-4.0.0-orig/Lib/swiglabels.swg swig-4.0.0/Lib/swiglabels.swg
--- swig-4.0.0-orig/Lib/swiglabels.swg	2019-04-26 21:48:33.000000000 +0300
+++ swig-4.0.0/Lib/swiglabels.swg	2019-05-27 08:49:41.190538400 +0300
@@ -91,7 +91,7 @@
 
 /* calling conventions for Windows */
 #ifndef SWIGSTDCALL
-# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# if defined(_WIN32) || defined(__WIN32__)
 #   define SWIGSTDCALL __stdcall
 # else
 #   define SWIGSTDCALL
diff -Naur swig-4.0.0-orig/Tools/config/compile swig-4.0.0/Tools/config/compile
--- swig-4.0.0-orig/Tools/config/compile	2019-04-28 21:53:59.000000000 +0300
+++ swig-4.0.0/Tools/config/compile	2019-05-27 08:49:41.200538400 +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 swig-4.0.0-orig/Tools/config/config.guess swig-4.0.0/Tools/config/config.guess
--- swig-4.0.0-orig/Tools/config/config.guess	2019-04-28 21:53:59.000000000 +0300
+++ swig-4.0.0/Tools/config/config.guess	2019-05-27 08:52:11.780749200 +0300
@@ -883,6 +883,9 @@
     amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
 	echo x86_64-unknown-cygwin
 	exit ;;
+    amd64:MSYS*:*:* | x86_64:MSYS*:*:*)
+	echo x86_64-unknown-msys
+	exit ;;
     prep*:SunOS:5.*:*)
 	echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
 	exit ;;
diff -Naur swig-4.0.0-orig/Tools/mkwindows.sh swig-4.0.0/Tools/mkwindows.sh
--- swig-4.0.0-orig/Tools/mkwindows.sh	2019-04-26 21:48:33.000000000 +0300
+++ swig-4.0.0/Tools/mkwindows.sh	2019-05-27 08:49:41.200538400 +0300
@@ -33,6 +33,7 @@
 mingw=`echo "$uname" | grep -i mingw`
 linux=`echo "$uname" | grep -i linux`
 cygwin=`echo "$uname" | grep -i cygwin`
+msys=`echo "$uname" | grep -i msys`
 if test "$mingw"; then
   echo "Building native Windows executable on MinGW";
   if test x$zip = x; then
@@ -64,7 +65,7 @@
       echo "Could not detect mingw gcc - please install mingw-w64 package."
       exit 1;
     fi
-  else 
+  else
     if test "$cygwin"; then
       echo "Building native Windows executable on Cygwin"
       if test x$zip = x; then
@@ -72,8 +73,16 @@
       fi
       compileflags="$compileflags -mno-cygwin"
     else
-      echo "Unknown platform. Requires either Linux or MinGW."
-      exit 1;
+      if test "$msys"; then
+        echo "Building native Windows executable on MSYS"
+        if test x$zip = x; then
+          zip=zip
+        fi
+        compileflags="-O2 -mno-cygwin"
+      else
+        echo "Unknown platform. Requires either Linux or MinGW."
+        exit 1;
+      fi
     fi
   fi
 fi
