diff -Naur a/bfd/acinclude.m4 b/bfd/acinclude.m4
--- a/bfd/acinclude.m4	2012-12-17 20:55:37.000000000 +0400
+++ b/bfd/acinclude.m4	2013-10-24 16:05:08.340400000 +0400
@@ -23,7 +23,7 @@
 [AC_REQUIRE([AC_CANONICAL_TARGET])
 case "${host}" in
 changequote(,)dnl
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 changequote([,])dnl
   AC_DEFINE(USE_BINARY_FOPEN, 1, [Use b modifier when opening binary files?]) ;;
 esac])dnl
diff -Naur a/bfd/config.bfd b/bfd/config.bfd
--- a/bfd/config.bfd	2013-06-26 14:41:41.000000000 +0400
+++ b/bfd/config.bfd	2013-10-24 16:05:08.340400000 +0400
@@ -673,7 +673,7 @@
     targ_archs="$targ_archs bfd_arm_arch"
     want64=true
     ;;
-  x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin | x86_64-*-midipix*)
+  x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin | x86_64-*-msys | x86_64-*-midipix*)
     targ_defvec=x86_64_pe_vec
     targ_selvecs="x86_64_pe_vec x86_64_pei_vec x86_64_pe_be_vec x86_64_elf64_vec l1om_elf64_vec k1om_elf64_vec i386_pe_vec i386_pei_vec i386_elf32_vec"
     want64=true
@@ -725,7 +725,7 @@
     targ_defvec=i386_elf32_vec
     targ_selvecs=i386_coff_vec
     ;;
-  i[3-7]86-*-mingw32* | i[3-7]86-*-cygwin* | i[3-7]86-*-winnt | i[3-7]86-*-pe | i[3-7]86-*-midipix*)
+  i[3-7]86-*-mingw32* | i[3-7]86-*-cygwin* | i[3-7]86-*-msys* | i[3-7]86-*-winnt | i[3-7]86-*-pe | i[3-7]86-*-midipix*)
     targ_defvec=i386_pe_vec
     targ_selvecs="i386_pe_vec i386_pei_vec i386_elf32_vec"
     targ_underscore=yes
diff -Naur a/bfd/configure b/bfd/configure
--- a/bfd/configure	2013-10-04 02:02:45.000000000 +0400
+++ b/bfd/configure	2013-10-24 16:05:08.356000000 +0400
@@ -5990,7 +5990,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -6332,7 +6332,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -6912,7 +6912,7 @@
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8496,7 +8496,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -8578,7 +8578,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       lt_prog_compiler_pic='-DDLL_EXPORT'
@@ -9040,7 +9040,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -9155,7 +9155,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
       # as there is no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -9586,7 +9586,7 @@
       export_dynamic_flag_spec=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -10487,14 +10487,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -10518,6 +10518,13 @@
 
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
       ;;
+
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -11154,7 +11161,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13661,7 +13668,7 @@
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
@@ -14938,7 +14945,7 @@
 
 LIBM=
 case $host in
-*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-msys* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
   # These system don't have libm, or don't need it
   ;;
 *-ncr-sysv4.3*)
@@ -15088,8 +15095,12 @@
     SHARED_LDFLAGS="-no-undefined"
     SHARED_LIBADD="-L`pwd`/../libiberty -liberty -L`pwd`/../intl -lintl -lcygwin -lkernel32"
   ;;
+  *-*-msys*)
+    SHARED_LDFLAGS="-no-undefined"
+    SHARED_LIBADD="-L`pwd`/../libiberty -liberty -L`pwd`/../intl -lintl -lmsys-2.0 -lkernel32"
+  ;;
   esac
-
+  
   if test -n "$SHARED_LIBADD"; then
     if test -n "$LIBM"; then
       if test x"$bfd_cv_ld_as_needed" = xyes; then
diff -Naur a/binutils/configure b/binutils/configure
--- a/binutils/configure	2013-09-20 13:51:24.000000000 +0400
+++ b/binutils/configure	2013-10-24 16:11:49.932400000 +0400
@@ -672,6 +672,7 @@
 am__fastdepCC_FALSE
 am__fastdepCC_TRUE
 CCDEPMODE
+am__nodep
 AMDEPBACKSLASH
 AMDEP_FALSE
 AMDEP_TRUE
@@ -3707,6 +3708,7 @@
 if test "x$enable_dependency_tracking" != xno; then
   am_depcomp="$ac_aux_dir/depcomp"
   AMDEPBACKSLASH='\'
+  am__nodep='_no'
 fi
  if test "x$enable_dependency_tracking" != xno; then
   AMDEP_TRUE=
@@ -3769,11 +3771,11 @@
 
 # We need awk for the "check" target.  The system "awk" is bad on
 # some platforms.
-# Always define AMTAR for backward compatibility.
+# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AMTAR='$${TAR-tar}'
 
-AMTAR=${AMTAR-"${am_missing_run}tar"}
-
-am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
 
 
 
@@ -3791,6 +3793,7 @@
   # instance it was reported that on HP-UX the gcc test will end up
   # making a dummy file named `D' -- because `-MD' means `put the output
   # in D'.
+  rm -rf conftest.dir
   mkdir conftest.dir
   # Copy depcomp to subdir because otherwise we won't find it if we're
   # using a relative directory.
@@ -3850,7 +3853,7 @@
 	break
       fi
       ;;
-    msvisualcpp | msvcmsys)
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
       # This compiler won't grok `-c -o', but also, the minuso test has
       # not run yet.  These depmodes are late enough in the game, and
       # so weak that their functioning should not be impacted.
@@ -5756,7 +5759,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -6098,7 +6101,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -6678,7 +6681,7 @@
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8293,7 +8296,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -8375,7 +8378,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       lt_prog_compiler_pic='-DDLL_EXPORT'
@@ -8837,7 +8840,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -8952,7 +8955,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
       # as there is no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -9383,7 +9386,7 @@
       export_dynamic_flag_spec=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -10284,14 +10287,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -10315,6 +10318,12 @@
 
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
       ;;
+	msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -10951,7 +10960,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13201,7 +13210,7 @@
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
@@ -14012,7 +14021,7 @@
 	  BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)'
 	  BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	  ;;
-	x86_64-*-mingw* | x86_64-*-midipix* | x86_64-*-cygwin*)
+	x86_64-*-mingw* | x86_64-*-midipix* | x86_64-*-cygwin* | x86_64-*-msys*)
   	  BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	  if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_MX86_64"
@@ -14022,7 +14031,7 @@
 	  BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	  BUILD_DLLWRAP='$(DLLWRAP_PROG)$(EXEEXT)'
 	  ;;
-	i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-mingw32** | i[3-7]86-*-netbsdpe*)
+	i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-msys* | i[3-7]86-*-mingw** | i[3-7]86-*-netbsdpe*)
   	  BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	  if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_I386"
diff -Naur a/binutils/dllwrap.c b/binutils/dllwrap.c
--- a/binutils/dllwrap.c	2012-02-09 08:51:44.000000000 +0400
+++ b/binutils/dllwrap.c	2013-10-24 16:05:08.387200000 +0400
@@ -79,6 +79,7 @@
 typedef enum {
   UNKNOWN_TARGET,
   CYGWIN_TARGET,
+  MSYS_TARGET,
   MINGW_TARGET
 }
 target_type;
@@ -830,6 +831,8 @@
   /* Set the target platform.  */
   if (strstr (target, "cygwin"))
     which_target = CYGWIN_TARGET;
+  else if (strstr (target, "msys"))
+    which_target = MSYS_TARGET;
   else if (strstr (target, "mingw"))
     which_target = MINGW_TARGET;
   else
@@ -881,6 +884,10 @@
 	  driver_flags = cygwin_driver_flags;
 	  break;
 
+	case MSYS_TARGET:
+	  driver_flags = cygwin_driver_flags;
+	  break;
+
 	case MINGW_TARGET:
 	  driver_flags = mingw32_driver_flags;
 	  break;
@@ -914,6 +921,10 @@
 	  name_entry = "_cygwin_dll_entry";
 	  break;
 
+	case MSYS_TARGET:
+	  name_entry = "_msys_dll_entry";
+	  break;
+
 	case MINGW_TARGET:
 	  name_entry = "DllMainCRTStartup";
 	  break;
@@ -977,7 +988,7 @@
 	{
 	  dyn_string_append_cstr (step_pre1, " --export-all --exclude-symbol=");
 	  dyn_string_append_cstr (step_pre1,
-	  "_cygwin_dll_entry@12,DllMainCRTStartup@12,DllMain@12,DllEntryPoint@12");
+	  "_cygwin_dll_entry@12,_msys_dll_entry@12,DllMainCRTStartup@12,DllMain@12,DllEntryPoint@12");
 	}
       dyn_string_append_cstr (step_pre1, " --output-def ");
       dyn_string_append_cstr (step_pre1, def_file_name);
diff -Naur a/binutils/testsuite/binutils-all/copy-3.d b/binutils/testsuite/binutils-all/copy-3.d
--- a/binutils/testsuite/binutils-all/copy-3.d	2012-10-29 14:09:31.000000000 +0400
+++ b/binutils/testsuite/binutils-all/copy-3.d	2013-10-24 16:05:08.387200000 +0400
@@ -3,7 +3,7 @@
 #objcopy: --set-section-flags .text=alloc,data
 #name: copy with setting section flags 3
 #source: bintest.s
-#not-target: *-*-*aout *-*-*pe *-*-*coff hppa*-*-hpux* *-*-cygwin* *-*-mingw* m68k-*-netbsd m68k-*-openbsd* ns32k-*-netbsd rs6000-*-*
+#not-target: *-*-*aout *-*-*pe *-*-*coff hppa*-*-hpux* *-*-cygwin* *-*-msys* *-*-mingw* m68k-*-netbsd m68k-*-openbsd* ns32k-*-netbsd rs6000-*-*
 # The .text # section in PE/COFF has a fixed set of flags and these
 # cannot be changed.  We skip it for them.
 
diff -Naur a/binutils/testsuite/binutils-all/dlltool.exp b/binutils/testsuite/binutils-all/dlltool.exp
--- a/binutils/testsuite/binutils-all/dlltool.exp	2012-02-14 06:40:39.000000000 +0400
+++ b/binutils/testsuite/binutils-all/dlltool.exp	2013-10-24 16:05:08.387200000 +0400
@@ -22,6 +22,7 @@
 
 if {![istarget "i*86-*-*pe*"] \
     && ![istarget "i*86-*-cygwin*"] \
+    && ![istarget "i*86-*-msys*"] \
     && ![istarget "i*86-*-mingw32*"] \
     && ![istarget "arm-*-pe*"] \
     && ![istarget "x86_64-*-mingw*"] } {
diff -Naur a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
--- a/binutils/testsuite/binutils-all/objcopy.exp	2012-03-13 04:41:22.000000000 +0400
+++ b/binutils/testsuite/binutils-all/objcopy.exp	2013-10-24 16:05:08.402800000 +0400
@@ -548,7 +548,7 @@
 
 # Build a final executable.
 
-if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
+if { [istarget *-*-cygwin] || [istarget *-*-mingw*] || [istarget *-*-msys*] } {
     set test_prog "testprog.exe"
 } else {
     set test_prog "testprog"
@@ -654,6 +654,7 @@
 	setup_xfail "arm*-*-pe"
 	setup_xfail "*-*-mingw*"
 	setup_xfail "*-*-cygwin*"
+	setup_xfail "*-*-msys*"
     
 	fail $test1
     }
diff -Naur a/binutils/testsuite/binutils-all/windres/windres.exp b/binutils/testsuite/binutils-all/windres/windres.exp
--- a/binutils/testsuite/binutils-all/windres/windres.exp	2012-03-13 04:41:22.000000000 +0400
+++ b/binutils/testsuite/binutils-all/windres/windres.exp	2013-10-24 16:05:08.402800000 +0400
@@ -19,7 +19,7 @@
 
 # Written by DJ Delorie <dj@redhat.com>
 
-if {![istarget "i*86-*-*"] && ![istarget "x86_64-*-mingw*"] && ![istarget "x86_64-*-cygwin"] } {
+if {![istarget "i*86-*-*"] && ![istarget "x86_64-*-mingw*"] && ![istarget "x86_64-*-cygwin"]  && ![istarget "x86_64-*-msys"] } {
     verbose "Not a Cygwin/Mingw target" 1
     return
 }
diff -Naur a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
--- a/binutils/testsuite/lib/binutils-common.exp	2013-05-01 21:27:46.000000000 +0400
+++ b/binutils/testsuite/lib/binutils-common.exp	2013-10-24 16:05:08.402800000 +0400
@@ -120,6 +120,7 @@
 proc is_pecoff_format {} {
     if { ![istarget *-*-mingw*]
 	 && ![istarget *-*-cygwin*]
+	 && ![istarget *-*-msys*]
 	 && ![istarget *-*-cegcc*]
 	 && ![istarget *-*-pe*] } {
 	return 0
diff -Naur a/binutils/testsuite/lib/utils-lib.exp b/binutils/testsuite/lib/utils-lib.exp
--- a/binutils/testsuite/lib/utils-lib.exp	2012-11-27 21:26:08.000000000 +0400
+++ b/binutils/testsuite/lib/utils-lib.exp	2013-10-24 16:05:08.402800000 +0400
@@ -129,7 +129,7 @@
 #	Returns target executable extension, if any.
 #
 proc exe_ext {} {
-    if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
+    if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] || [istarget *-*-msys*] } {
         return ".exe"
     } else {
         return ""
diff -Naur a/config/dfp.m4 b/config/dfp.m4
--- a/config/dfp.m4	2013-04-30 16:40:42.000000000 +0400
+++ b/config/dfp.m4	2013-10-24 16:05:08.418400000 +0400
@@ -23,7 +23,8 @@
     powerpc*-*-linux* | i?86*-*-linux* | x86_64*-*-linux* | s390*-*-linux* | \
     i?86*-*-gnu* | \
     i?86*-*-mingw* | x86_64*-*-mingw* | \
-    i?86*-*-cygwin* | x86_64*-*-cygwin*)
+    i?86*-*-cygwin* | x86_64*-*-cygwin* | \
+    i?86*-*-msys* | x86_64*-*-msys*)
       enable_decimal_float=yes
       ;;
     *)
diff -Naur a/config/elf.m4 b/config/elf.m4
--- a/config/elf.m4	2011-07-18 14:15:06.000000000 +0400
+++ b/config/elf.m4	2013-10-24 16:05:08.418400000 +0400
@@ -13,7 +13,7 @@
 
 target_elf=no
 case $target in
-  *-darwin* | *-aix* | *-cygwin* | *-mingw* | *-aout* | *-*coff* | \
+  *-darwin* | *-aix* | *-cygwin* | *-msys* | *-mingw* | *-aout* | *-*coff* | \
   *-msdosdjgpp* | *-vms* | *-wince* | *-*-pe* | \
   alpha*-dec-osf* | *-interix* | hppa[[12]]*-*-hpux*)
     target_elf=no
diff -Naur a/config/lthostflags.m4 b/config/lthostflags.m4
--- a/config/lthostflags.m4	2010-12-06 04:40:20.000000000 +0300
+++ b/config/lthostflags.m4	2013-10-24 16:05:08.418400000 +0400
@@ -13,7 +13,7 @@
 AC_REQUIRE([AC_CANONICAL_SYSTEM])
 
 case $host in
-  *-cygwin* | *-mingw*)
+  *-cygwin* | *-mingw* | *-msys*)
     # 'host' will be top-level target in the case of a target lib,
     # we must compare to with_cross_host to decide if this is a native
     # or cross-compiler and select where to install dlls appropriately.
diff -Naur a/config/mmap.m4 b/config/mmap.m4
--- a/config/mmap.m4	2012-05-29 19:58:15.000000000 +0400
+++ b/config/mmap.m4	2013-10-24 16:05:08.418400000 +0400
@@ -42,7 +42,7 @@
    # Systems known to be in this category are Windows (all variants),
    # VMS, and Darwin.
    case "$host_os" in
-     *vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
+     *vms* | cygwin* | msys* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
         gcc_cv_func_mmap_dev_zero=no ;;
      *)
         gcc_cv_func_mmap_dev_zero=yes;;
@@ -74,7 +74,7 @@
    # above for use of /dev/zero.
    # Systems known to be in this category are Windows, VMS, and SCO Unix.
    case "$host_os" in
-     *vms* | cygwin* | pe | mingw* | sco* | udk* )
+     *vms* | cygwin* | msys* | pe | mingw* | sco* | udk* )
         gcc_cv_func_mmap_anon=no ;;
      *)
         gcc_cv_func_mmap_anon=yes;;
diff -Naur a/config/picflag.m4 b/config/picflag.m4
--- a/config/picflag.m4	2013-04-30 16:40:42.000000000 +0400
+++ b/config/picflag.m4	2013-10-24 16:05:08.418400000 +0400
@@ -19,6 +19,8 @@
 	;;
     i[[34567]]86-*-cygwin* | x86_64-*-cygwin*)
 	;;
+    i[[34567]]86-*-msys* | x86_64-*-msys*)
+	;;
     i[[34567]]86-*-mingw* | x86_64-*-mingw*)
 	;;
     i[[34567]]86-*-interix[[3-9]]*)
diff -Naur a/config/tcl.m4 b/config/tcl.m4
--- a/config/tcl.m4	2012-05-29 19:58:15.000000000 +0400
+++ b/config/tcl.m4	2013-10-24 16:05:08.434000000 +0400
@@ -33,7 +33,7 @@
 
 	    # First check to see if --with-tcl was specified.
 	    case "${host}" in
-		*-*-cygwin*) platDir="win" ;;
+		*-*-cygwin* | *-*-msys*) platDir="win" ;;
 		*) platDir="unix" ;;
 	    esac
 	    if test x"${with_tclconfig}" != x ; then
@@ -165,7 +165,7 @@
 
 	    # then check for a private Tk library
 	    case "${host}" in
-		*-*-cygwin*) platDir="win" ;;
+		*-*-cygwin* | *-*-msys*) platDir="win" ;;
 		*) platDir="unix" ;;
 	    esac
 	    if test x"${ac_cv_c_tkconfig}" = x ; then
diff -Naur a/config.guess b/config.guess
--- a/config.guess	2013-04-29 19:13:53.000000000 +0400
+++ b/config.guess	2013-10-24 16:05:08.434000000 +0400
@@ -845,6 +845,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 a/config.rpath b/config.rpath
--- a/config.rpath	2011-02-14 00:00:08.000000000 +0300
+++ b/config.rpath	2013-10-24 16:05:08.434000000 +0400
@@ -109,7 +109,7 @@
 hardcode_minus_L=no
 
 case "$host_os" in
-  cygwin* | mingw* | pw32*)
+  cygwin* | mingw* | msys* | pw32*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -149,7 +149,7 @@
         ld_shlibs=no
       fi
       ;;
-    cygwin* | mingw* | pw32*)
+    cygwin* | mingw* | msys* | pw32*)
       # hardcode_libdir_flag_spec is actually meaningless, as there is
       # no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -268,7 +268,7 @@
       ;;
     bsdi4*)
       ;;
-    cygwin* | mingw* | pw32*)
+    cygwin* | mingw* | msys* | pw32*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -437,7 +437,7 @@
     ;;
   bsdi4*)
     ;;
-  cygwin* | mingw* | pw32*)
+  cygwin* | mingw* | msys* | pw32*)
     shrext=.dll
     ;;
   darwin* | rhapsody*)
diff -Naur a/configure b/configure
--- a/configure	2013-10-17 00:36:39.000000000 +0400
+++ b/configure	2013-10-24 16:05:08.449600000 +0400
@@ -3017,7 +3017,7 @@
 # Configure extra directories which are host specific
 
 case "${host}" in
-  *-cygwin*)
+  *-cygwin* | *-msys*)
     configdirs="$configdirs libtermcap" ;;
 esac
 
@@ -3446,7 +3446,7 @@
 	# PR 46986
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
-    *-*-cygwin* | *-*-mingw*)
+    *-*-cygwin* | *-*-msys* | *-*-mingw*)
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
     *-*-aix*)
@@ -3702,7 +3702,7 @@
   i[3456789]86-*-mingw*)
     target_configdirs="$target_configdirs target-winsup"
     ;;
-  *-*-cygwin*)
+  *-*-cygwin* | *-msys*)
     target_configdirs="$target_configdirs target-libtermcap target-winsup"
     noconfigdirs="$noconfigdirs target-libgloss"
     # always build newlib if winsup directory is present.
@@ -3837,7 +3837,7 @@
   i[3456789]86-*-msdosdjgpp*)
     host_makefile_frag="config/mh-djgpp"
     ;;
-  *-cygwin*)
+  *-cygwin* | *-msys*)
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking to see if cat works as expected" >&5
 $as_echo_n "checking to see if cat works as expected... " >&6; }
@@ -6252,7 +6252,7 @@
 
 target_elf=no
 case $target in
-  *-darwin* | *-aix* | *-cygwin* | *-mingw* | *-midipix* | *-aout* | *-*coff* | \
+  *-darwin* | *-aix* | *-cygwin* | *-mingw* | *-midipix* | *-msys* | *-aout* | *-*coff* | \
   *-msdosdjgpp* | *-vms* | *-wince* | *-*-pe* | \
   alpha*-dec-osf* | *-interix* | hppa[12]*-*-hpux*)
     target_elf=no
@@ -6269,7 +6269,7 @@
 else
   if test x"$default_enable_lto" = x"yes" ; then
     case $target in
-      *-apple-darwin9* | *-cygwin* | *-mingw*) ;;
+      *-apple-darwin9* | *-cygwin* | *-mingw* | *-msys*) ;;
       # On other non-ELF platforms, LTO has yet to be validated.
       *) enable_lto=no ;;
     esac
@@ -6280,7 +6280,7 @@
   # warn during gcc/ subconfigure; unless you're bootstrapping with
   # -flto it won't be needed until after installation anyway.
     case $target in
-      *-cygwin* | *-mingw* | *-apple-darwin*) ;;
+      *-cygwin* | *-mingw* | *-msys* | *-apple-darwin*) ;;
       *) if test x"$enable_lto" = x"yes"; then
 	as_fn_error "LTO support is not enabled for this target." "$LINENO" 5
         fi
@@ -6290,7 +6290,7 @@
   # Among non-ELF, only Windows platforms support the lto-plugin so far.
   # Build it unless LTO was explicitly disabled.
   case $target in
-    *-cygwin* | *-mingw*) build_lto_plugin=$enable_lto ;;
+    *-cygwin* | *-mingw* | *-msys*) build_lto_plugin=$enable_lto ;;
     *) ;;
   esac
 
@@ -7076,7 +7076,7 @@
 case "${host}" in
   *-*-hpux*) RPATH_ENVVAR=SHLIB_PATH ;;
   *-*-darwin*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
-  *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
+  *-*-mingw* | *-*-cygwin  | *-msys*) RPATH_ENVVAR=PATH ;;
   *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
 esac
 
@@ -7528,7 +7528,7 @@
   case " $target_configargs " in
   *" --with-newlib "*)
    case "$target" in
-    *-cygwin*)
+    *-cygwin* | *-msys*)
       FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -L$$r/$(TARGET_SUBDIR)/winsup/cygwin -isystem $$s/winsup/cygwin/include'
       ;;
    esac
diff -Naur a/configure.ac b/configure.ac
--- a/configure.ac	2013-10-22 09:39:40.000000000 +0400
+++ b/configure.ac	2013-10-24 16:05:08.449600000 +0400
@@ -376,7 +376,7 @@
 # Configure extra directories which are host specific
 
 case "${host}" in
-  *-cygwin*)
+  *-cygwin* | *-msys*)
     configdirs="$configdirs libtermcap" ;;
 esac
 
@@ -779,7 +779,7 @@
 	# PR 46986
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
-    *-*-cygwin* | *-*-mingw*)
+    *-*-cygwin* | *-*-msys* | *-*-mingw*)
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
     *-*-aix*)
@@ -1035,7 +1035,7 @@
   i[[3456789]]86-*-mingw*)
     target_configdirs="$target_configdirs target-winsup"
     ;;
-  *-*-cygwin*)
+  *-*-cygwin* | *-msys*)
     target_configdirs="$target_configdirs target-libtermcap target-winsup"
     noconfigdirs="$noconfigdirs target-libgloss"
     # always build newlib if winsup directory is present.
@@ -1170,7 +1170,7 @@
   i[[3456789]]86-*-msdosdjgpp*)
     host_makefile_frag="config/mh-djgpp"
     ;;
-  *-cygwin*)
+  *-cygwin* | *-msys*)
     ACX_CHECK_CYGWIN_CAT_WORKS
     host_makefile_frag="config/mh-cygwin"
     ;;
@@ -1705,7 +1705,7 @@
   build_lto_plugin=yes
 ],[if test x"$default_enable_lto" = x"yes" ; then
     case $target in
-      *-apple-darwin9* | *-cygwin* | *-mingw*) ;;
+      *-apple-darwin9* | *-cygwin* | *-mingw* | *-msys*) ;;
       # On other non-ELF platforms, LTO has yet to be validated.
       *) enable_lto=no ;;
     esac
@@ -1716,7 +1716,7 @@
   # warn during gcc/ subconfigure; unless you're bootstrapping with
   # -flto it won't be needed until after installation anyway.
     case $target in
-      *-cygwin* | *-mingw* | *-apple-darwin*) ;;
+      *-cygwin* | *-mingw* | *-msys* | *-apple-darwin*) ;;
       *) if test x"$enable_lto" = x"yes"; then
 	AC_MSG_ERROR([LTO support is not enabled for this target.])
         fi
@@ -1726,7 +1726,7 @@
   # Among non-ELF, only Windows platforms support the lto-plugin so far.
   # Build it unless LTO was explicitly disabled.
   case $target in
-    *-cygwin* | *-mingw*) build_lto_plugin=$enable_lto ;;
+    *-cygwin* | *-mingw* | *-msys*) build_lto_plugin=$enable_lto ;;
     *) ;;
   esac
 ])
@@ -2459,7 +2459,7 @@
 case "${host}" in
   *-*-hpux*) RPATH_ENVVAR=SHLIB_PATH ;;
   *-*-darwin*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
-  *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
+  *-*-mingw* | *-*-cygwin  | *-msys*) RPATH_ENVVAR=PATH ;;
   *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
 esac
 
@@ -2910,7 +2910,7 @@
   case " $target_configargs " in
   *" --with-newlib "*)
    case "$target" in
-    *-cygwin*)
+    *-cygwin* | *-msys*)
       FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -L$$r/$(TARGET_SUBDIR)/winsup/cygwin -isystem $$s/winsup/cygwin/include'
       ;;
    esac
diff -Naur a/gas/configure b/gas/configure
--- a/gas/configure	2013-09-20 13:51:24.000000000 +0400
+++ b/gas/configure	2013-10-24 16:05:08.465200000 +0400
@@ -5739,7 +5739,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -6081,7 +6081,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -6661,7 +6661,7 @@
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8276,7 +8276,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | msys* | cygwin* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -8358,7 +8358,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | msys* | cygwin* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       lt_prog_compiler_pic='-DDLL_EXPORT'
@@ -8820,7 +8820,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -8935,7 +8935,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
       # as there is no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -9366,7 +9366,7 @@
       export_dynamic_flag_spec=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -10267,14 +10267,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -10298,6 +10298,12 @@
 
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
       ;;
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -10934,7 +10940,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13521,7 +13527,7 @@
 yes)
   LIBM=
 case $host in
-*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-msys* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
   # These system don't have libm, or don't need it
   ;;
 *-ncr-sysv4.3*)
@@ -14103,7 +14109,7 @@
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
diff -Naur a/gas/configure.tgt b/gas/configure.tgt
--- a/gas/configure.tgt	2013-06-22 20:44:14.000000000 +0400
+++ b/gas/configure.tgt	2013-10-24 16:05:08.465200000 +0400
@@ -254,7 +254,7 @@
   i386-*-msdos*)			fmt=aout ;;
   i386-*-moss*)				fmt=elf ;;
   i386-*-pe)				fmt=coff em=pe ;;
-  i386-*-cygwin*)
+  i386-*-cygwin* | i386-*-msys*)
    case ${cpu} in
      x86_64*)				fmt=coff em=pep ;;
      i*)				fmt=coff em=pe ;;
diff -Naur a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
--- a/gas/testsuite/gas/all/gas.exp	2013-06-22 20:44:15.000000000 +0400
+++ b/gas/testsuite/gas/all/gas.exp	2013-10-24 16:05:08.480800000 +0400
@@ -165,7 +165,7 @@
 	# failures such as or32-elf.
 	setup_xfail "bfin-*-*" "i\[3-7\]86-*-*coff" \
 	    "i\[3-7\]86-*-*pe" "i\[3-7\]86-*-go32*" \
-	    "i\[3-7\]86-*-cygwin*" "i\[3-7\]86-*-mingw*" "x86_64-*-mingw*"
+	    "i\[3-7\]86-*-cygwin*" "i\[3-7\]86-*-msys*" "i\[3-7\]86-*-mingw*" "x86_64-*-mingw*"
 	run_dump_test redef3
 	gas_test_error "redef4.s" "" ".set for symbol already used as label"
 	gas_test_error "redef5.s" "" ".set for symbol already defined through .comm"
@@ -317,6 +317,7 @@
      || [istarget i*86-*-isc*] \
      || [istarget i*86-*-go32*] \
      || [istarget i*86-*-cygwin*] \
+     || [istarget i*86-*-msys*] \
      || [istarget x86_64-*-mingw*] \
      || [istarget i*86-*-*nt] \
      || [istarget i*86-*-interix*] \
@@ -362,6 +363,7 @@
 
 if {  ([istarget "i*86-*-*pe*"] && ![istarget "i*86-*-openbsd*"]) \
     || [istarget "i*86-*-cygwin*"] \
+    || [istarget "i*86-*-msys*"] \
     || [istarget "i*86-*-mingw32*"] } {
   gas_test "fastcall.s" ""   "" "fastcall labels"
 }
diff -Naur a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
--- a/gas/testsuite/gas/i386/i386.exp	2013-09-30 21:02:07.000000000 +0400
+++ b/gas/testsuite/gas/i386/i386.exp	2013-10-24 16:05:08.480800000 +0400
@@ -324,7 +324,7 @@
 
     # This is a PE specific test.
     if { [istarget "*-*-cygwin*"] || [istarget "*-*-pe"]
-	 || [istarget "*-*-mingw*"]
+	  || [istarget "*-*-msys*"] || [istarget "*-*-mingw*"]
     } then {
 	run_dump_test "secrel"
     }
diff -Naur a/gprof/configure b/gprof/configure
--- a/gprof/configure	2013-09-20 13:51:25.000000000 +0400
+++ b/gprof/configure	2013-10-24 16:05:08.496400000 +0400
@@ -5669,7 +5669,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -6011,7 +6011,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -6591,7 +6591,7 @@
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8206,7 +8206,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -8288,7 +8288,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       lt_prog_compiler_pic='-DDLL_EXPORT'
@@ -8750,7 +8750,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -8865,7 +8865,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
       # as there is no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -9296,7 +9296,7 @@
       export_dynamic_flag_spec=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -10197,14 +10197,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -10228,6 +10228,12 @@
 
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
       ;;
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -10864,7 +10870,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
diff -Naur a/ld/configure b/ld/configure
--- a/ld/configure	2013-09-20 13:51:25.000000000 +0400
+++ b/ld/configure	2013-10-24 16:05:08.512000000 +0400
@@ -6729,7 +6729,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -7071,7 +7071,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -7651,7 +7651,7 @@
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -9267,7 +9267,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | msys* | cygwin* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -9349,7 +9349,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       lt_prog_compiler_pic='-DDLL_EXPORT'
@@ -9811,7 +9811,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -9926,7 +9926,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
       # as there is no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -10357,7 +10357,7 @@
       export_dynamic_flag_spec=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -11258,14 +11258,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -11289,6 +11289,12 @@
 
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
       ;;
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -11925,7 +11931,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13147,7 +13153,7 @@
         esac
         ;;
 
-      cygwin* | mingw* | pw32* | cegcc*)
+      cygwin* | msys* | mingw* | pw32* | cegcc*)
         # _LT_TAGVAR(hardcode_libdir_flag_spec, CXX) is actually meaningless,
         # as there is no search path for DLLs.
         hardcode_libdir_flag_spec_CXX='-L$libdir'
@@ -14116,7 +14122,7 @@
     beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
       # PIC is the default for these OSes.
       ;;
-    mingw* | cygwin* | os2* | pw32* | cegcc*)
+    mingw* | msys* | cygwin* | os2* | pw32* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -14656,7 +14662,7 @@
   pw32*)
     export_symbols_cmds_CXX="$ltdll_cmds"
   ;;
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;/^.*[ ]__nm__/s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols'
   ;;
   *)
@@ -14920,14 +14926,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -14950,6 +14956,11 @@
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
       ;;
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -16645,7 +16656,7 @@
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
diff -Naur a/ld/configure.host b/ld/configure.host
--- a/ld/configure.host	2013-03-05 15:54:28.000000000 +0400
+++ b/ld/configure.host	2013-10-24 16:05:08.512000000 +0400
@@ -175,6 +175,10 @@
   HOSTING_LIBS="$HOSTING_LIBS"' -lcygwin -L/usr/lib/w32api -luser32 -lkernel32 -ladvapi32 -lshell32 `if [ -f ../gcc/libgcc.a ] ; then echo ../gcc/libgcc.a ; else ${CC} -print-libgcc-file-name; fi`'
   ;;
 
+i[3-7]86-*-msys* | x86_64-*-msys*)
+  HOSTING_LIBS="$HOSTING_LIBS"' -lmsys-2.0 -L/usr/lib/w32api -luser32 -lkernel32 -ladvapi32 -lshell32 `if [ -f ../gcc/libgcc.a ] ; then echo ../gcc/libgcc.a ; else ${CC} -print-libgcc-file-name; fi`'
+  ;;
+
 i[3-7]86-*-mingw*)
   #We only support msvcrt.dll, crtid == 2.
   HOSTING_CRT0='/mingw/lib/crt2.o'
diff -Naur a/ld/configure.tgt b/ld/configure.tgt
--- a/ld/configure.tgt	2013-10-24 16:08:08.692000000 +0400
+++ b/ld/configure.tgt	2013-10-24 16:05:08.527600000 +0400
@@ -310,7 +310,8 @@
 			targ_extra_ofiles="deffilep.o pe-dll.o" ;;
 i[3-7]86-*-pe)		targ_emul=i386pe ;
 			targ_extra_ofiles="deffilep.o pe-dll.o" ;;
-i[3-7]86-*-cygwin*)	targ_emul=i386pe ;
+i[3-7]86-*-cygwin* | i[3-7]86-*-msys*)
+			targ_emul=i386pe ;
 			targ_extra_ofiles="deffilep.o pe-dll.o" ;
 			test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api' ;;
 i[3-7]86-*-mingw32*)	targ_emul=i386pe ;
@@ -318,7 +319,8 @@
 x86_64-*-pe | x86_64-*-pep) targ_emul=i386pep ;
 			targ_extra_emuls=i386pe ;
 			targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o" ;;
-x86_64-*-cygwin)	targ_emul=i386pep ;
+x86_64-*-cygwin* | x86_64-*-msys*)
+			targ_emul=i386pep ;
 			targ_extra_emuls=i386pe
 			targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o"
 			test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api:=/usr/lib/w32api' ;;
@@ -810,6 +812,10 @@
   NATIVE_LIB_DIRS='/usr/lib /usr/lib/w32api'
   ;;
 
+i[03-9x]86-*-msys* | x86_64-*-msys*)
+  NATIVE_LIB_DIRS='/usr/lib /usr/lib/w32api'
+  ;;
+
 *-*-linux*)
   ;;
 
diff -Naur a/ld/emultempl/pe.em b/ld/emultempl/pe.em
--- a/ld/emultempl/pe.em	2013-08-22 19:28:42.000000000 +0400
+++ b/ld/emultempl/pe.em	2013-10-24 16:05:08.527600000 +0400
@@ -172,7 +172,7 @@
 # merge_rdata defaults to 0 for cygwin:
 #  http://cygwin.com/ml/cygwin-apps/2013-04/msg00187.html
 case ${target} in
-  *-*-cygwin*)
+  *-*-cygwin* | *-*-msys)
     default_auto_import=1
     default_merge_rdata=0
     ;;
diff -Naur a/ld/emultempl/pep.em b/ld/emultempl/pep.em
--- a/ld/emultempl/pep.em	2013-03-05 15:54:29.000000000 +0400
+++ b/ld/emultempl/pep.em	2013-10-24 16:05:08.527600000 +0400
@@ -7,7 +7,7 @@
 fi
 
 case ${target} in
-  *-*-cygwin*)
+  *-*-cygwin* | *-*-msys*)
     move_default_addr_high=1
     ;;
   *)
diff -Naur a/ld/pe-dll.c b/ld/pe-dll.c
--- a/ld/pe-dll.c	2013-03-21 18:05:29.000000000 +0400
+++ b/ld/pe-dll.c	2013-10-24 16:05:08.527600000 +0400
@@ -208,6 +208,7 @@
   { STRING_COMMA_LEN ("_NULL_IMPORT_DESCRIPTOR") },
   /* Entry point symbols, and entry hooks.  */
   { STRING_COMMA_LEN ("cygwin_crt0") },
+  { STRING_COMMA_LEN ("msys_crt0") },
 #ifdef pe_use_x86_64
   { STRING_COMMA_LEN ("DllMain") },
   { STRING_COMMA_LEN ("DllEntryPoint") },
@@ -215,6 +216,9 @@
   { STRING_COMMA_LEN ("_cygwin_dll_entry") },
   { STRING_COMMA_LEN ("_cygwin_crt0_common") },
   { STRING_COMMA_LEN ("_cygwin_noncygwin_dll_entry") },
+  { STRING_COMMA_LEN ("_msys_dll_entry") },
+  { STRING_COMMA_LEN ("_msys_crt0_common") },
+  { STRING_COMMA_LEN ("_msys_nonmsys_dll_entry") },
 #else
   { STRING_COMMA_LEN ("DllMain@12") },
   { STRING_COMMA_LEN ("DllEntryPoint@0") },
@@ -223,6 +227,10 @@
   { STRING_COMMA_LEN ("_cygwin_crt0_common@8") },
   { STRING_COMMA_LEN ("_cygwin_noncygwin_dll_entry@12") },
   { STRING_COMMA_LEN ("cygwin_attach_dll") },
+  { STRING_COMMA_LEN ("_msys_dll_entry@12") },
+  { STRING_COMMA_LEN ("_msys_crt0_common@8") },
+  { STRING_COMMA_LEN ("_msys_nonmsys_dll_entry@12") },
+  { STRING_COMMA_LEN ("msys_attach_dll") },
 #endif
   { STRING_COMMA_LEN ("cygwin_premain0") },
   { STRING_COMMA_LEN ("cygwin_premain1") },
@@ -324,6 +332,7 @@
 {
   { STRING_COMMA_LEN ("libcegcc") },
   { STRING_COMMA_LEN ("libcygwin") },
+  { STRING_COMMA_LEN ("libmsys-2.0") },
   { STRING_COMMA_LEN ("libgcc") },
   { STRING_COMMA_LEN ("libgcc_s") },
   { STRING_COMMA_LEN ("libstdc++") },
diff -Naur a/ld/testsuite/ld-auto-import/auto-import.exp b/ld/testsuite/ld-auto-import/auto-import.exp
--- a/ld/testsuite/ld-auto-import/auto-import.exp	2009-09-02 11:25:38.000000000 +0400
+++ b/ld/testsuite/ld-auto-import/auto-import.exp	2013-10-24 16:05:08.543200000 +0400
@@ -57,7 +57,8 @@
 
 # This test can only be run on a couple of platforms.
 # Square bracket expressions seem to confuse istarget.
-if { ![istarget *-pc-cygwin]    
+if { ![istarget *-pc-cygwin]  
+     && ![istarget *-pc-msys]  
      && ![istarget *-pc-mingw*] } {
     return
 }
@@ -114,17 +115,26 @@
 set tmpdir tmpdir
 set SHCFLAG ""
 
-if [istarget *-pc-cygwin] {
+if [istarget *-pc-cygwin || istarget *-pc-msys] {
     # Set some libs needed for cygwin.
+	if [istarget *-pc-cygwin] {
     set MYLIBS "-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32"
+	} else {
+    set MYLIBS "-L/usr/lib -lmsys-2.0 -L/usr/lib/w32api -lkernel32"	
+	}
     
     # Compile the dll.
     if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o] {
 	fail "compiling shared lib"
     }
+	if [istarget *-pc-cygwin] {
     if ![ld_special_link "$ld -shared --enable-auto-import -e __cygwin_dll_entry@12 --out-implib=$tmpdir/libstandard.dll.a" $tmpdir/dll.dll "$tmpdir/dll.o $MYLIBS"] {
 	fail "linking shared lib"
     }
+    } else {
+    if ![ld_special_link "$ld -shared --enable-auto-import -e __msys_dll_entry@12 --out-implib=$tmpdir/libstandard.dll.a" $tmpdir/dll.dll "$tmpdir/dll.o $MYLIBS"] {
+	fail "linking shared lib	
+	}
 
     # Create symbolic link.
     catch "exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
diff -Naur a/ld/testsuite/ld-bootstrap/bootstrap.exp b/ld/testsuite/ld-bootstrap/bootstrap.exp
--- a/ld/testsuite/ld-bootstrap/bootstrap.exp	2011-12-03 21:13:01.000000000 +0400
+++ b/ld/testsuite/ld-bootstrap/bootstrap.exp	2013-10-24 16:05:08.543200000 +0400
@@ -107,7 +107,7 @@
 
     # On Cygwin, -lintl may require -liconv when linking statically.
     set extralibs ""
-    if { [istarget "*-*-cygwin*"]} {
+    if { [istarget "*-*-cygwin*"] || [istarget "*-*-msys*"] } {
 	if {"$flags" == "--static"} {
 	    set extralibs "-liconv"
 	}
@@ -175,6 +175,7 @@
     if {[istarget "*-*-pe"]
 	|| [istarget "*-*-wince"]
 	|| [istarget "*-*-cygwin*"]
+	|| [istarget "*-*-msys*"]
 	|| [istarget "*-*-winnt*"]
 	|| [istarget "*-*-mingw*"]
 	|| [istarget "*-*-interix*"]
diff -Naur a/ld/testsuite/ld-cygwin/exe-export.exp b/ld/testsuite/ld-cygwin/exe-export.exp
--- a/ld/testsuite/ld-cygwin/exe-export.exp	2009-09-02 11:25:38.000000000 +0400
+++ b/ld/testsuite/ld-cygwin/exe-export.exp	2013-10-24 16:10:15.204200000 +0400
@@ -24,7 +24,7 @@
 #
  
 # This test can only be run on a cygwin platforms.
-if {![istarget *-pc-cygwin]} {
+if {![istarget *-pc-cygwin] && ![istarget *-pc-msys]} {
     verbose "Not a cygwin target."
     return
 }
diff -Naur a/ld/testsuite/ld-fastcall/fastcall.exp b/ld/testsuite/ld-fastcall/fastcall.exp
--- a/ld/testsuite/ld-fastcall/fastcall.exp	2009-09-02 11:25:39.000000000 +0400
+++ b/ld/testsuite/ld-fastcall/fastcall.exp	2013-10-24 16:05:08.543200000 +0400
@@ -26,6 +26,7 @@
 
 if {  !([istarget "i*86-*-*pe*"] && ![istarget "i*86-*-opensd*"]) \
     && ![istarget "i*86-*-cygwin*"] \
+    && ![istarget "i*86-*-msys*"] \
     && ![istarget "x86_64-*-mingw*"] \
     && ![istarget "i*86-*-mingw*"] } {
     return
diff -Naur a/ld/testsuite/ld-pe/export_dynamic_warning.d b/ld/testsuite/ld-pe/export_dynamic_warning.d
--- a/ld/testsuite/ld-pe/export_dynamic_warning.d	2009-04-02 20:44:23.000000000 +0400
+++ b/ld/testsuite/ld-pe/export_dynamic_warning.d	2013-10-24 16:05:08.543200000 +0400
@@ -1,5 +1,5 @@
 #name: PE-COFF --export-dynamic warning
-#target: *-*-mingw32 *-*-cygwin *-*-pe
+#target: *-*-mingw32 *-*-cygwin *-*-msys *-*-pe
 #ld: --export-dynamic
 #warning: warning: --export-dynamic is not supported for PE\+? targets, did you mean --export-all-symbols\?
 
diff -Naur a/ld/testsuite/ld-pe/image_size.d b/ld/testsuite/ld-pe/image_size.d
--- a/ld/testsuite/ld-pe/image_size.d	2009-04-03 13:25:31.000000000 +0400
+++ b/ld/testsuite/ld-pe/image_size.d	2013-10-24 16:05:08.543200000 +0400
@@ -1,7 +1,7 @@
 #name: PE-COFF SizeOfImage
 #ld: -T image_size.t
 #objdump: -p
-#target: *-*-mingw32 *-*-cygwin
+#target: *-*-mingw32 *-*-cygwin *-*-msys
 
 .*:     file format .*
 #...
diff -Naur a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp
--- a/ld/testsuite/ld-pe/pe.exp	2013-02-19 05:10:00.000000000 +0400
+++ b/ld/testsuite/ld-pe/pe.exp	2013-10-24 16:05:08.543200000 +0400
@@ -27,6 +27,7 @@
 
 # This test can only be run on PE/COFF platforms that support .secrel32.
 if {[istarget i*86-*-cygwin*]
+    || [istarget i*86-*-msys*]
     || [istarget i*86-*-pe]
     || [istarget i*86-*-mingw*]
     || [istarget x86_64-*-mingw*]
@@ -41,7 +42,7 @@
 	{"TLS directory entry" "" "" "" "tlssec.s"
 	 {{objdump -p tlssec64.d}} "tlssec.dll"}
       }
-    } elseif {[istarget i*86-*-cygwin*] } {
+    } elseif {[istarget i*86-*-cygwin*] || [istarget i*86-*-msys*] } {
       set pe_tests {
 	{".secrel32" "--disable-auto-import" "" "" {secrel1.s secrel2.s}
 	 {{objdump -s secrel.d}} "secrel.x"}
diff -Naur a/ld/testsuite/ld-pe/pe-compile.exp b/ld/testsuite/ld-pe/pe-compile.exp
--- a/ld/testsuite/ld-pe/pe-compile.exp	2013-02-19 05:10:00.000000000 +0400
+++ b/ld/testsuite/ld-pe/pe-compile.exp	2013-10-24 16:05:08.543200000 +0400
@@ -119,6 +119,7 @@
 run_ver_script_test "vers-script-4"
 
 if {[istarget i*86-*-cygwin*]
+    || [istarget i*86-*-msys*]
     || [istarget i*86-*-pe]
     || [istarget i*86-*-mingw*]
     || [istarget x86_64-*-mingw*] } {
diff -Naur a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
--- a/ld/testsuite/ld-scripts/script.exp	2013-07-22 17:03:30.000000000 +0400
+++ b/ld/testsuite/ld-scripts/script.exp	2013-10-24 16:05:08.558800000 +0400
@@ -97,6 +97,7 @@
 set flags ""
 if {[istarget "*-*-pe*"] \
     || [istarget "*-*-cygwin*"] \
+    || [istarget "*-*-msys*"] \
     || [istarget "*-*-mingw*"] \
     || [istarget "*-*-winnt*"] \
     || [istarget "*-*-nt"] \
diff -Naur a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp
--- a/ld/testsuite/ld-srec/srec.exp	2013-05-03 01:06:15.000000000 +0400
+++ b/ld/testsuite/ld-srec/srec.exp	2013-10-24 16:05:08.558800000 +0400
@@ -382,7 +382,7 @@
 # The S-record linker doesn't support the special PE headers - the PE
 # emulation tries to write pe-specific information to the PE headers
 # in the output bfd, but it's not a PE bfd (it's an srec bfd)
-setup_xfail "*-*-cygwin*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
+setup_xfail "*-*-cygwin*" "*-*-msys*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
 setup_xfail "score-*-*"
 
 # The S-record linker doesn't support Blackfin ELF FDPIC ABI.
@@ -421,7 +421,7 @@
 setup_xfail "alpha*-*-netbsd*"
 setup_xfail "hppa*-*-*" "mep-*-*"
 setup_xfail "ia64-*-*"
-setup_xfail "*-*-cygwin*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
+setup_xfail "*-*-cygwin*" "*-*-msys*" "*-*-mingw*" "*-*-pe*" "*-*-winnt*"
 setup_xfail "score-*-*"
 setup_xfail "bfin-*-linux-uclibc"
 setup_xfail "tile*-*-*"
diff -Naur a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
--- a/ld/testsuite/lib/ld-lib.exp	2013-10-13 14:17:18.000000000 +0400
+++ b/ld/testsuite/lib/ld-lib.exp	2013-10-24 16:05:08.558800000 +0400
@@ -410,7 +410,7 @@
     }
 
     # Windows targets need __main, prefixed with underscore.
-    if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*]} {
+    if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*] || [istarget *-*-msys*]} {
         append flags " --defsym ___main=0"
     }
 
@@ -1532,6 +1532,7 @@
 	    || [istarget mep-*-*]
 	    || [istarget mn10200-*-*]
 	    || [istarget *-*-cygwin]
+	    || [istarget *-*-msys]
 	    || [istarget *-*-mingw*] } {
 	    set gc_sections_available_saved 0
 	    return 0
diff -Naur a/libiberty/configure b/libiberty/configure
--- a/libiberty/configure	2013-10-16 04:29:45.000000000 +0400
+++ b/libiberty/configure	2013-10-24 16:05:08.558800000 +0400
@@ -4896,6 +4896,8 @@
 	;;
     i[34567]86-*-cygwin* | x86_64-*-cygwin*)
 	;;
+    i[34567]86-*-msys* | x86_64-*-msys*)
+	;;
     i[34567]86-*-mingw* | x86_64-*-mingw*)
 	;;
     i[34567]86-*-interix[3-9]*)
@@ -5807,7 +5809,7 @@
 
 
 case "${host}" in
-  *-*-cygwin* | *-*-mingw*)
+  *-*-cygwin* | *-*-msys* | *-*-mingw*)
     $as_echo "#define HAVE_SYS_ERRLIST 1" >>confdefs.h
 
     $as_echo "#define HAVE_SYS_NERR 1" >>confdefs.h
diff -Naur a/libiberty/configure.ac b/libiberty/configure.ac
--- a/libiberty/configure.ac	2013-10-16 04:29:45.000000000 +0400
+++ b/libiberty/configure.ac	2013-10-24 16:05:08.574400000 +0400
@@ -534,7 +534,7 @@
 AC_SUBST(target_header_dir)
 
 case "${host}" in
-  *-*-cygwin* | *-*-mingw*)
+  *-*-cygwin* | *-*-msys* | *-*-mingw*)
     AC_DEFINE(HAVE_SYS_ERRLIST)
     AC_DEFINE(HAVE_SYS_NERR)
     ;;
diff -Naur a/libtool.m4 b/libtool.m4
--- a/libtool.m4	2013-09-20 13:51:24.000000000 +0400
+++ b/libtool.m4	2013-10-24 16:05:08.574400000 +0400
@@ -1491,7 +1491,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -1733,7 +1733,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -2204,14 +2204,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,mingw* | yes,msys* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -2235,6 +2235,12 @@
 m4_if([$1], [],[
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"])
       ;;
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+m4_if([$1], [],[
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"])
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
@@ -3001,7 +3007,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -3285,7 +3291,7 @@
 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
 LIBM=
 case $host in
-*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-msys* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
   # These system don't have libm, or don't need it
   ;;
 *-ncr-sysv4.3*)
@@ -3360,7 +3366,7 @@
 aix*)
   symcode='[[BCDT]]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[[ABCDGISTW]]'
   ;;
 hpux*)
@@ -3607,7 +3613,7 @@
     beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
       # PIC is the default for these OSes.
       ;;
-    mingw* | cygwin* | os2* | pw32* | cegcc*)
+    mingw* | cygwin* | msys* | os2* | pw32* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -3920,7 +3926,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -4003,7 +4009,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       m4_if([$1], [GCJ], [],
@@ -4236,7 +4242,7 @@
   pw32*)
     _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
   ;;
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
   ;;
   *)
@@ -4288,7 +4294,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -4403,7 +4409,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
       # as there is no search path for DLLs.
       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
@@ -4776,7 +4782,7 @@
       _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -5720,7 +5726,7 @@
         esac
         ;;
 
-      cygwin* | mingw* | pw32* | cegcc*)
+      cygwin* | msys* | mingw* | pw32* | cegcc*)
         # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
         # as there is no search path for DLLs.
         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
diff -Naur a/ltmain.sh b/ltmain.sh
--- a/ltmain.sh	2011-01-13 21:52:53.000000000 +0300
+++ b/ltmain.sh	2013-10-24 16:05:08.590000000 +0400
@@ -976,7 +976,7 @@
 
 
   case $host in
-    *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* )
+    *cygwin* | *msys* | *mingw* | *pw32* | *cegcc* | *solaris2* )
       # don't eliminate duplications in $postdeps and $predeps
       opt_duplicate_compiler_generated_deps=:
       ;;
@@ -1453,7 +1453,7 @@
 
     # On Cygwin there's no "real" PIC flag so we must build both object types
     case $host_os in
-    cygwin* | mingw* | pw32* | os2* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | os2* | cegcc*)
       pic_mode=default
       ;;
     esac
@@ -2279,7 +2279,7 @@
 	      'exit $?'
 	  tstripme="$stripme"
 	  case $host_os in
-	  cygwin* | mingw* | pw32* | cegcc*)
+	  cygwin* | msys* | mingw* | pw32* | cegcc*)
 	    case $realname in
 	    *.dll.a)
 	      tstripme=""
@@ -2385,7 +2385,7 @@
 
 	# Do a test to see if this is really a libtool program.
 	case $host in
-	*cygwin* | *mingw*)
+	*cygwin* | *msys* | *mingw*)
 	    if func_ltwrapper_executable_p "$file"; then
 	      func_ltwrapper_scriptname "$file"
 	      wrapper=$func_ltwrapper_scriptname_result
@@ -2460,7 +2460,7 @@
 	# remove .exe since cygwin /usr/bin/install will append another
 	# one anyway
 	case $install_prog,$host in
-	*/usr/bin/install*,*cygwin*)
+	*/usr/bin/install*,*cygwin*|*/usr/bin/install*,*msys*)
 	  case $file:$destfile in
 	  *.exe:*.exe)
 	    # this is ok
@@ -2595,7 +2595,7 @@
 	      $RM $export_symbols
 	      ${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' < "$nlist" > "$export_symbols"
 	      case $host in
-	      *cygwin* | *mingw* | *cegcc* )
+	      *cygwin* | *msys* | *mingw* | *cegcc* )
                 echo EXPORTS > "$output_objdir/$outputname.def"
                 cat "$export_symbols" >> "$output_objdir/$outputname.def"
 	        ;;
@@ -2607,7 +2607,7 @@
 	      $GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T
 	      $MV "$nlist"T "$nlist"
 	      case $host in
-	        *cygwin* | *mingw* | *cegcc* )
+	        *cygwin* | *msys* | *mingw* | *cegcc* )
 	          echo EXPORTS > "$output_objdir/$outputname.def"
 	          cat "$nlist" >> "$output_objdir/$outputname.def"
 	          ;;
@@ -2663,7 +2663,7 @@
 } lt_dlsymlist;
 "
 	  case $host in
-	  *cygwin* | *mingw* | *cegcc* )
+	  *cygwin* | *msys* | *mingw* | *cegcc* )
 	    echo >> "$output_objdir/$my_dlsyms" "\
 /* DATA imports from DLLs on WIN32 con't be const, because
    runtime relocations are performed -- see ld's documentation
@@ -2749,7 +2749,7 @@
 	# Transform the symbol file into the correct name.
 	symfileobj="$output_objdir/${my_outputname}S.$objext"
 	case $host in
-	*cygwin* | *mingw* | *cegcc* )
+	*cygwin* | *msys* | *mingw* | *cegcc* )
 	  if test -f "$output_objdir/$my_outputname.def"; then
 	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
 	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
@@ -3192,7 +3192,7 @@
             func_to_host_path_result=`( cmd //c echo "$1" ) 2>/dev/null |
               $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
             ;;
-          *cygwin* )
+          *cygwin* | *msys* )
             func_to_host_path_result=`cygpath -w "$1" |
 	      $SED -e "$lt_sed_naive_backslashify"`
             ;;
@@ -3265,7 +3265,7 @@
 	      ( cmd //c echo "$func_to_host_pathlist_tmp1" ) 2>/dev/null |
 	      $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
             ;;
-          *cygwin* )
+          *cygwin* | *msys* )
             func_to_host_pathlist_result=`cygpath -w -p "$func_to_host_pathlist_tmp1" |
               $SED -e "$lt_sed_naive_backslashify"`
             ;;
@@ -3571,7 +3571,7 @@
 	{
 EOF
 	    case "$host" in
-	      *mingw* | *cygwin* )
+	      *mingw* | *cygwin* | *msys* )
 		# make stdout use "unix" line endings
 		echo "          setmode(1,_O_BINARY);"
 		;;
@@ -4233,7 +4233,7 @@
 {
     $opt_debug
     case $host in
-    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+    *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
       # It is impossible to link a dll without this setting, and
       # we shouldn't force the makefile maintainer to figure out
       # which system we are compiling for in order to pass an extra
@@ -4713,7 +4713,7 @@
 	  ;;
 	esac
 	case $host in
-	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	*-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
 	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
 	  case :$dllsearchpath: in
 	  *":$dir:"*) ;;
@@ -4733,7 +4733,7 @@
       -l*)
 	if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
 	  case $host in
-	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
+	  *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
 	    # These systems don't actually have a C or math library (as such)
 	    continue
 	    ;;
@@ -4813,7 +4813,7 @@
 
       -no-install)
 	case $host in
-	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
+	*-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
 	  # The PATH hackery in wrapper scripts is required on Windows
 	  # and Darwin in order for the loader to find any dlls it needs.
 	  func_warning "\`-no-install' is ignored for $host"
@@ -5772,7 +5772,7 @@
 	if test -n "$library_names" &&
 	   { test "$use_static_libs" = no || test -z "$old_library"; }; then
 	  case $host in
-	  *cygwin* | *mingw* | *cegcc*)
+	  *cygwin* | *msys* | *mingw* | *cegcc*)
 	      # No point in relinking DLLs because paths are not encoded
 	      notinst_deplibs="$notinst_deplibs $lib"
 	      need_relink=no
@@ -5842,7 +5842,7 @@
 	    elif test -n "$soname_spec"; then
 	      # bleh windows
 	      case $host in
-	      *cygwin* | mingw* | *cegcc*)
+	      *cygwin* | *msys* | mingw* | *cegcc*)
 	        func_arith $current - $age
 		major=$func_arith_result
 		versuffix="-$major"
@@ -6693,7 +6693,7 @@
       if test "$build_libtool_libs" = yes; then
 	if test -n "$rpath"; then
 	  case $host in
-	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
+	  *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
 	    # these systems don't actually have a c library (as such)!
 	    ;;
 	  *-*-rhapsody* | *-*-darwin1.[012])
@@ -7194,7 +7194,7 @@
 
 	orig_export_symbols=
 	case $host_os in
-	cygwin* | mingw* | cegcc*)
+	cygwin* | msys* | mingw* | cegcc*)
 	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
 	    # exporting using user supplied symfile
 	    if test "x`$SED 1q $export_symbols`" != xEXPORTS; then
@@ -7710,7 +7710,7 @@
 
     prog)
       case $host in
-	*cygwin*) func_stripname '' '.exe' "$output"
+	*cygwin* | *msys*) func_stripname '' '.exe' "$output"
 	          output=$func_stripname_result.exe;;
       esac
       test -n "$vinfo" && \
@@ -7823,7 +7823,7 @@
 	  esac
 	fi
 	case $host in
-	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	*-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
 	  testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'`
 	  case :$dllsearchpath: in
 	  *":$libdir:"*) ;;
@@ -7901,7 +7901,7 @@
         # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
         wrappers_required=no
         ;;
-      *cygwin* | *mingw* )
+      *cygwin* | *msys* | *mingw* )
         if test "$build_libtool_libs" != yes; then
           wrappers_required=no
         fi
@@ -8029,14 +8029,14 @@
 	esac
 	# test for cygwin because mv fails w/o .exe extensions
 	case $host in
-	  *cygwin*)
+	  *cygwin* | *msys*)
 	    exeext=.exe
 	    func_stripname '' '.exe' "$outputname"
 	    outputname=$func_stripname_result ;;
 	  *) exeext= ;;
 	esac
 	case $host in
-	  *cygwin* | *mingw* )
+	  *cygwin* | *msys* | *mingw* )
 	    func_dirname_and_basename "$output" "" "."
 	    output_name=$func_basename_result
 	    output_path=$func_dirname_result
@@ -8343,7 +8343,7 @@
 	  # tests/bindir.at for full details.
 	  tdlname=$dlname
 	  case $host,$output,$installed,$module,$dlname in
-	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
+	    *cygwin*,*lai,yes,no,*.dll | *msys*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
 	      # If a -bindir argument was supplied, place the dll there.
 	      if test "x$bindir" != x ;
 	      then
diff -Naur a/ltoptions.m4 b/ltoptions.m4
--- a/ltoptions.m4	2010-01-10 00:11:32.000000000 +0300
+++ b/ltoptions.m4	2013-10-24 16:05:08.590000000 +0400
@@ -126,7 +126,7 @@
 [enable_win32_dll=yes
 
 case $host in
-*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*)
+*-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-cegcc*)
   AC_CHECK_TOOL(AS, as, false)
   AC_CHECK_TOOL(DLLTOOL, dlltool, false)
   AC_CHECK_TOOL(OBJDUMP, objdump, false)
diff -Naur a/opcodes/configure b/opcodes/configure
--- a/opcodes/configure	2013-09-20 13:51:25.000000000 +0400
+++ b/opcodes/configure	2013-10-24 16:05:08.605600000 +0400
@@ -5717,7 +5717,7 @@
     lt_cv_sys_max_cmd_len=-1;
     ;;
 
-  cygwin* | mingw* | cegcc*)
+  cygwin* | msys* | mingw* | cegcc*)
     # On Win9x/ME, this test blows up -- it succeeds, but takes
     # about 5 minutes as the teststring grows exponentially.
     # Worse, since 9x/ME are not pre-emptively multitasking,
@@ -6059,7 +6059,7 @@
   lt_cv_file_magic_test_file=/shlib/libc.so
   ;;
 
-cygwin*)
+cygwin* | msys*)
   # func_win32_libid is a shell function defined in ltmain.sh
   lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
   lt_cv_file_magic_cmd='func_win32_libid'
@@ -6639,7 +6639,7 @@
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8224,7 +8224,7 @@
       # PIC is the default for these OSes.
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | msys* | cygwin* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       # Although the cygwin gcc ignores -fPIC, still need this for old-style
@@ -8306,7 +8306,7 @@
       fi
       ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | msys* | cygwin* | pw32* | os2* | cegcc*)
       # This hack is so that the source file can tell whether it is being
       # built for inclusion in a dll (and should export symbols for example).
       lt_prog_compiler_pic='-DDLL_EXPORT'
@@ -8768,7 +8768,7 @@
   extract_expsyms_cmds=
 
   case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -8883,7 +8883,7 @@
       fi
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
       # as there is no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -9314,7 +9314,7 @@
       export_dynamic_flag_spec=-rdynamic
       ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -10215,14 +10215,14 @@
   # libtool to hard-code these into programs
   ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   version_type=windows
   shrext_cmds=".dll"
   need_version=no
   need_lib_prefix=no
 
   case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+  yes,cygwin* | yes,msys* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
     postinstall_cmds='base_file=`basename \${file}`~
@@ -10246,6 +10246,12 @@
 
       sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
       ;;
+    msys*)
+      # Msys DLLs use 'msys-' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/msys-/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
     mingw* | cegcc*)
       # MinGW DLLs use traditional 'lib' prefix
       soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
@@ -10882,7 +10888,7 @@
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -12253,7 +12259,7 @@
 
 LIBM=
 case $host in
-*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-msys* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
   # These system don't have libm, or don't need it
   ;;
 *-ncr-sysv4.3*)
@@ -12423,6 +12429,10 @@
       SHARED_LDFLAGS="-no-undefined"
       SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty -L`pwd`/../intl -lintl -lcygwin"
       ;;
+    *-*-msys*)
+      SHARED_LDFLAGS="-no-undefined"
+      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty -L`pwd`/../intl -lintl -lmsys-2.0"
+      ;;
    *-*-darwin*)
      SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.dylib ${SHARED_LIBADD}"
      SHARED_DEPENDENCIES="../bfd/libbfd.la"
