Support MSYS platform

Message ID 20240303075907.1188-1-orgad.shaneh@audiocodes.com
State New
Headers
Series Support MSYS platform |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Orgad Shaneh March 3, 2024, 7:58 a.m. UTC
  From: Orgad Shaneh <orgads@gmail.com>

Apply MSYS patches upstream.
---
 ar-lib                                      |   4 +-
 bfd/acinclude.m4                            |   2 +-
 bfd/config.bfd                              |   4 +-
 bfd/configure                               |  36 ++++---
 bfd/configure.ac                            |   4 +
 binutils/configure                          |  36 ++++---
 binutils/configure.ac                       |   6 +-
 binutils/dllwrap.c                          |  13 ++-
 binutils/testsuite/binutils-all/dlltool.exp |   1 +
 compile                                     |   4 +-
 config.guess                                |   3 +
 config.rpath                                |   8 +-
 config/dfp.m4                               |   3 +-
 config/elf.m4                               |   2 +-
 config/lthostflags.m4                       |   2 +-
 config/mmap.m4                              |   4 +-
 config/picflag.m4                           |   2 +
 config/tcl.m4                               |   4 +-
 configure                                   | 109 ++++++++++----------
 configure.ac                                |  20 ++--
 gas/configure                               |  32 +++---
 gas/configure.tgt                           |   2 +-
 gas/testsuite/gas/all/gas.exp               |   6 +-
 gdb/configure                               |  50 ++++-----
 gdb/configure.ac                            |   6 +-
 gdb/configure.host                          |   2 +
 gdb/configure.nat                           |   7 +-
 gdb/configure.tgt                           |   7 +-
 gdb/testsuite/gdb.base/bigcore.exp          |   3 +-
 gdb/testsuite/gdb.base/fileio.exp           |   2 +-
 gdb/testsuite/gdb.base/maint.exp            |   2 +-
 gdb/testsuite/gdb.base/shreloc.exp          |   4 +-
 gdb/testsuite/gdb.base/solib-weak.exp       |   3 +-
 gdb/testsuite/gdb.dwarf2/dw2-dos-drive.exp  |   3 +-
 gdb/testsuite/gdb.server/wrapper.exp        |   3 +-
 gdb/testsuite/lib/gdb.exp                   |  22 ++--
 gdb/windows-nat.c                           |   8 ++
 gdbserver/configure.srv                     |   4 +-
 gnulib/configure                            |   8 +-
 gnulib/import/m4/double-slash-root.m4       |   2 +-
 gnulib/import/m4/dup2.m4                    |   2 +-
 gnulib/import/m4/fcntl.m4                   |   2 +-
 gprof/configure                             |  28 +++--
 intl/configure                              |   2 +
 ld/configure                                |  45 +++++---
 ld/configure.tgt                            |   6 +-
 ld/emultempl/pe.em                          |   4 +-
 ld/emultempl/pep.em                         |   2 +-
 ld/pe-dll.c                                 |   9 ++
 ld/testsuite/ld-auto-import/auto-import.exp |  62 +++++++++++
 ld/testsuite/ld-fastcall/fastcall.exp       |   1 +
 ld/testsuite/ld-pe/pe-compile.exp           |   1 +
 ld/testsuite/ld-pe/pe.exp                   |   5 +-
 ld/testsuite/ld-pe/weakdef-1.d              |   2 +-
 libctf/configure                            |  32 ++++--
 libctf/configure.ac                         |   4 +
 libdecnumber/configure                      |   3 +-
 libiberty/configure                         |   4 +-
 libiberty/configure.ac                      |   2 +-
 libtool.m4                                  |  36 ++++---
 ltmain.sh                                   |  52 +++++-----
 ltoptions.m4                                |   2 +-
 opcodes/configure                           |  34 +++---
 opcodes/configure.ac                        |   4 +
 readline/readline/configure                 |   2 +-
 readline/readline/configure.ac              |   2 +-
 readline/readline/support/config.guess      |   3 +
 readline/readline/support/config.rpath      |  10 +-
 readline/readline/support/shlib-install     |   4 +-
 readline/readline/support/shobj-conf        |  18 ++++
 sim/configure                               |  28 +++--
 zlib/configure                              |  28 +++--
 72 files changed, 561 insertions(+), 321 deletions(-)
  

Comments

Eli Zaretskii March 3, 2024, 8:56 a.m. UTC | #1
> From: Orgad Shaneh <orgads@gmail.com>
> Cc: Orgad Shaneh <orgads@gmail.com>
> Date: Sun,  3 Mar 2024 09:58:58 +0200
> 
> From: Orgad Shaneh <orgads@gmail.com>
> 
> Apply MSYS patches upstream.

Thanks.  Please find a few comments below.

But before that: what exactly is the MSYS target, and how does it
differ from MinGW and Cygwin targets?

In addition, I think this warrants a NEWS entry (both for Binutils and
for GDB).

> diff --git a/configure b/configure
> index dd743c58663..51c7d7b0b20 100755
> --- a/configure
> +++ b/configure
> @@ -1534,12 +1534,12 @@ Optional Features:
>    --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
>    --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
>    --enable-as-accelerator-for=ARG
> -                          build as offload target compiler. Specify offload
> +                          build as offload target compiler.
 Specify offload
>                            host triple by ARG
>    --enable-offload-targets=LIST
>                            enable offloading to devices from comma-separated
> -                          LIST of TARGET[=DIR]. Use optional path to find
> -                          offload target compiler during the build
> +                          LIST of
 TARGET[=DIR]. Use optional path to find
> +                          offload target compiler
 during the build
>    --enable-offload-defaulted

What are those ^M (CR) characters, here and elsewhere?  Looks like
some artifact of the way you produced the diffs?

> @@ -4502,7 +4503,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
>  /* end confdefs.h.  */
>  
>  int
> -main ()
> +main (void)
>  {

Why is this needed?  Did you use some version of Autotools that
produces these differences?

General comment: some of the sources patched in this series are
maintained elsewhere: Readline is maintained by Bash, Libtool is
maintained by its own project, etc.  So I expect you will need to
submit the relevant parts to their upstream projects.
  
Orgad Shaneh March 3, 2024, 9:46 a.m. UTC | #2
On Sun, Mar 3, 2024 at 10:56 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Orgad Shaneh <orgads@gmail.com>
> > Cc: Orgad Shaneh <orgads@gmail.com>
> > Date: Sun,  3 Mar 2024 09:58:58 +0200
> >
> > From: Orgad Shaneh <orgads@gmail.com>
> >
> > Apply MSYS patches upstream.
>
> Thanks.  Please find a few comments below.
>

Thanks for the review.

But before that: what exactly is the MSYS target, and how does it
> differ from MinGW and Cygwin targets?
>

See https://www.msys2.org/docs/what-is-msys2/

It is based on Cygwin, but focuses on support for native Windows apps.

It also features a decent package manager, which Cygwin doesn't.

In addition, I think this warrants a NEWS entry (both for Binutils and
> for GDB).
>

Done.

> diff --git a/configure b/configure
> > index dd743c58663..51c7d7b0b20 100755
> > --- a/configure
> > +++ b/configure
> > @@ -1534,12 +1534,12 @@ Optional Features:
> >    --disable-FEATURE       do not include FEATURE (same as
> --enable-FEATURE=no)
> >    --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
> >    --enable-as-accelerator-for=ARG
> > -                          build as offload target compiler. Specify
> offload
> > +                          build as offload target compiler.
>  Specify offload
> >                            host triple by ARG
> >    --enable-offload-targets=LIST
> >                            enable offloading to devices from
> comma-separated
> > -                          LIST of TARGET[=DIR]. Use optional path to
> find
> > -                          offload target compiler during the build
> > +                          LIST of
>  TARGET[=DIR]. Use optional path to find
> > +                          offload target compiler
>  during the build
> >    --enable-offload-defaulted
>
> What are those ^M (CR) characters, here and elsewhere?  Looks like
> some artifact of the way you produced the diffs?
>

Looks like a bug in autoreconf on MSYS2. I reran it now on Linux.


> > @@ -4502,7 +4503,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> >  /* end confdefs.h.  */
> >
> >  int
> > -main ()
> > +main (void)
> >  {
>
> Why is this needed?  Did you use some version of Autotools that
> produces these differences?
>

Possibly. Reverted now.

General comment: some of the sources patched in this series are
> maintained elsewhere: Readline is maintained by Bash, Libtool is
> maintained by its own project, etc.  So I expect you will need to
> submit the relevant parts to their upstream projects.
>

Ok, thanks.

- Orgad
  
Eli Zaretskii March 3, 2024, 10:57 a.m. UTC | #3
> From: Orgad Shaneh <orgads@gmail.com>
> Date: Sun, 3 Mar 2024 11:46:53 +0200
> Cc: gdb-patches@sourceware.org
> 
>  But before that: what exactly is the MSYS target, and how does it
>  differ from MinGW and Cygwin targets?
> 
> See https://www.msys2.org/docs/what-is-msys2/
> 
> It is based on Cygwin, but focuses on support for native Windows apps.
> 
> It also features a decent package manager, which Cygwin doesn't.

I was asking what is the native debugging target for this build.  I'm
guessing those are MSYS2 (as opposed to MinGW64) programs, is that
right?  Because if you say "support for native Windows apps", then it
is not clear how is this different from the MinGW port of GDB, which
also targets native Windows programs.
  
Orgad Shaneh March 3, 2024, 11:04 a.m. UTC | #4
On Sun, Mar 3, 2024 at 12:57 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Orgad Shaneh <orgads@gmail.com>
> > Date: Sun, 3 Mar 2024 11:46:53 +0200
> > Cc: gdb-patches@sourceware.org
> >
> >  But before that: what exactly is the MSYS target, and how does it
> >  differ from MinGW and Cygwin targets?
> >
> > See https://www.msys2.org/docs/what-is-msys2/
> >
> > It is based on Cygwin, but focuses on support for native Windows apps.
> >
> > It also features a decent package manager, which Cygwin doesn't.
>
> I was asking what is the native debugging target for this build.  I'm
> guessing those are MSYS2 (as opposed to MinGW64) programs, is that
> right?  Because if you say "support for native Windows apps", then it
> is not clear how is this different from the MinGW port of GDB, which
> also targets native Windows programs.
>

The runtime dlls are different, and the build environment is different
(uname -s: MSYS_NT-10.0-19043)

- Orgad
  

Patch

diff --git a/ar-lib b/ar-lib
index 05094d34c69..1b16134da54 100755
--- a/ar-lib
+++ b/ar-lib
@@ -53,7 +53,7 @@  func_file_conv ()
 	  MINGW*)
 	    file_conv=mingw
 	    ;;
-	  CYGWIN*)
+	  CYGWIN*|MSYS*)
 	    file_conv=cygwin
 	    ;;
 	  *)
@@ -65,7 +65,7 @@  func_file_conv ()
 	mingw)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
-	cygwin)
+	cygwin|msys)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	wine)
diff --git a/bfd/acinclude.m4 b/bfd/acinclude.m4
index 74f2003372c..9d9410435e2 100644
--- a/bfd/acinclude.m4
+++ b/bfd/acinclude.m4
@@ -21,7 +21,7 @@  AC_DEFUN([BFD_BINARY_FOPEN],
 [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 --git a/bfd/config.bfd b/bfd/config.bfd
index 08129e6a8cb..517c6b6f7e6 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -715,7 +715,7 @@  case "${targ}" in
     targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec"
     want64=true
     ;;
-  x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin)
+  x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin | x86_64-*-msys)
     targ_defvec=x86_64_pe_vec
     targ_selvecs="x86_64_pe_vec x86_64_pei_vec x86_64_pe_big_vec x86_64_elf64_vec i386_pe_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec pdb_vec"
     want64=true
@@ -774,7 +774,7 @@  case "${targ}" in
     targ_defvec=i386_elf32_vec
     targ_selvecs="iamcu_elf32_vec 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-*-mingw32* | i[3-7]86-*-cygwin* | i[3-7]86-*-msys* | i[3-7]86-*-winnt | i[3-7]86-*-pe)
     targ_defvec=i386_pe_vec
     targ_selvecs="i386_pe_vec i386_pe_big_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec pdb_vec"
     targ_underscore=yes
diff --git a/bfd/configure b/bfd/configure
index f0a07ff675f..1ea70f7d175 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -5654,7 +5654,7 @@  else
     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,
@@ -5996,7 +5996,7 @@  bsdi[45]*)
   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'
@@ -6612,7 +6612,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8198,7 +8198,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -8280,7 +8280,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -8742,7 +8742,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -8857,7 +8857,7 @@  _LT_EOF
       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'
@@ -9288,7 +9288,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -10189,14 +10189,14 @@  bsdi[45]*)
   # 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}`~
@@ -10218,6 +10218,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -10870,7 +10876,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13277,7 +13283,7 @@  _ACEOF
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
@@ -13597,7 +13603,7 @@  $as_echo "$bfd_cv_ld_as_needed" >&6; }
 
 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*)
@@ -13751,6 +13757,10 @@  if test "$enable_shared" = "yes"; then
     SHARED_LDFLAGS="-no-undefined"
     SHARED_LIBADD="-L`pwd`/../libiberty -liberty $SHARED_LIBADD -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
diff --git a/bfd/configure.ac b/bfd/configure.ac
index d1e7e3a4bf3..0dcb56765f4 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -287,6 +287,10 @@  if test "$enable_shared" = "yes"; then
     SHARED_LDFLAGS="-no-undefined"
     SHARED_LIBADD="-L`pwd`/../libiberty -liberty $SHARED_LIBADD -lcygwin -lkernel32"
   ;;
+  *-*-msys*)
+    SHARED_LDFLAGS="-no-undefined"
+    SHARED_LIBADD="-L`pwd`/../libiberty -liberty $SHARED_LIBADD -lmsys-2.0 -lkernel32"
+  ;;
   esac
 
   if test -n "$SHARED_LIBADD"; then
diff --git a/binutils/configure b/binutils/configure
index 7806ff2a0b3..1e3c0e74dd3 100755
--- a/binutils/configure
+++ b/binutils/configure
@@ -5334,7 +5334,7 @@  else
     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,
@@ -5676,7 +5676,7 @@  bsdi[45]*)
   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'
@@ -6292,7 +6292,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -7909,7 +7909,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -7991,7 +7991,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -8453,7 +8453,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -8568,7 +8568,7 @@  _LT_EOF
       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'
@@ -8999,7 +8999,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -9900,14 +9900,14 @@  bsdi[45]*)
   # 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}`~
@@ -9929,6 +9929,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -10581,7 +10587,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13784,7 +13790,7 @@  fi
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
@@ -14753,7 +14759,7 @@  do
 	BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)'
 	BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	;;
-    i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-mingw32** | all)
+    i[3-7]86-*-pe* | i[3-7]86-*-cygwin* |  i[3-7]86-*-msys* | i[3-7]86-*-mingw32** | all)
 	BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_I386"
@@ -14795,7 +14801,7 @@  do
 	BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)'
 	BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	;;
-    x86_64-*-mingw* | x86_64-*-cygwin*)
+    x86_64-*-mingw* | x86_64-*-cygwin* | x86_64-*-msys*)
 	BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_MX86_64"
@@ -14819,7 +14825,7 @@  do
     powerpc*-*-aix* | rs6000-*-aix*)
 	od_vectors="$od_vectors objdump_private_desc_xcoff"
 	;;
-    *-*-pe* | *-*-cygwin* | *-*-mingw*)
+    *-*-pe* | *-*-cygwin* | *-*-msys* | *-*-mingw*)
 	 od_vectors="$od_vectors objdump_private_desc_pe"
 	 ;;
     *-*-darwin*)
diff --git a/binutils/configure.ac b/binutils/configure.ac
index 30cd7b9ed1e..17d6056b194 100644
--- a/binutils/configure.ac
+++ b/binutils/configure.ac
@@ -396,7 +396,7 @@  changequote([,])dnl
 	BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	;;
 changequote(,)dnl
-    i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-mingw32** | all)
+    i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-msys* | i[3-7]86-*-mingw32** | all)
 changequote([,])dnl
 	BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	if test -z "$DLLTOOL_DEFAULT"; then
@@ -441,7 +441,7 @@  changequote([,])dnl
 	BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)'
 	BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	;;
-    x86_64-*-mingw* | x86_64-*-cygwin*)
+    x86_64-*-mingw* | x86_64-*-cygwin* | x86_64-*-msys*)
 	BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_MX86_64"
@@ -465,7 +465,7 @@  changequote([,])dnl
     powerpc*-*-aix* | rs6000-*-aix*)
 	od_vectors="$od_vectors objdump_private_desc_xcoff"
 	;;
-    *-*-pe* | *-*-cygwin* | *-*-mingw*)
+    *-*-pe* | *-*-cygwin* | *-*-msys* | *-*-mingw*)
 	 od_vectors="$od_vectors objdump_private_desc_pe"
 	 ;;
     *-*-darwin*)
diff --git a/binutils/dllwrap.c b/binutils/dllwrap.c
index f333eb561e2..06410a2e766 100644
--- a/binutils/dllwrap.c
+++ b/binutils/dllwrap.c
@@ -78,6 +78,7 @@  static int is_leading_underscore = -1;
 typedef enum {
   UNKNOWN_TARGET,
   CYGWIN_TARGET,
+  MSYS_TARGET,
   MINGW_TARGET
 }
 target_type;
@@ -833,6 +834,8 @@  Creating one, but that may not be what you want"));
   /* 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
@@ -884,6 +887,10 @@  Creating one, but that may not be what you want"));
 	  driver_flags = cygwin_driver_flags;
 	  break;
 
+	case MSYS_TARGET:
+	  driver_flags = cygwin_driver_flags;
+	  break;
+
 	case MINGW_TARGET:
 	  driver_flags = mingw32_driver_flags;
 	  break;
@@ -917,6 +924,10 @@  Creating one, but that may not be what you want"));
 	  name_entry = "_cygwin_dll_entry";
 	  break;
 
+	case MSYS_TARGET:
+	  name_entry = "_msys_dll_entry";
+	  break;
+
 	case MINGW_TARGET:
 	  name_entry = "DllMainCRTStartup";
 	  break;
@@ -980,7 +991,7 @@  Creating one, but that may not be what you want"));
 	{
 	  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 --git a/binutils/testsuite/binutils-all/dlltool.exp b/binutils/testsuite/binutils-all/dlltool.exp
index f87ec5c060f..34409f43338 100644
--- a/binutils/testsuite/binutils-all/dlltool.exp
+++ b/binutils/testsuite/binutils-all/dlltool.exp
@@ -22,6 +22,7 @@  if {![istarget "i*86-*-*"]
 
 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 --git a/compile b/compile
index a85b723c7e6..a4ecdb2519c 100755
--- a/compile
+++ b/compile
@@ -53,7 +53,7 @@  func_file_conv ()
 	  MINGW*)
 	    file_conv=mingw
 	    ;;
-	  CYGWIN*)
+	  CYGWIN*|MSYS*)
 	    file_conv=cygwin
 	    ;;
 	  *)
@@ -67,7 +67,7 @@  func_file_conv ()
 	mingw/*)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
-	cygwin/*)
+	cygwin/*|msys/*)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	wine/*)
diff --git a/config.guess b/config.guess
index 72d235025ed..bf9ba065b56 100755
--- a/config.guess
+++ b/config.guess
@@ -949,6 +949,9 @@  EOF
 	;;
     amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
 	GUESS=x86_64-pc-cygwin
+	exit ;;
+    amd64:MSYS*:*:* | x86_64:MSYS*:*:*)
+	echo x86_64-pc-msys
 	;;
     prep*:SunOS:5.*:*)
 	SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
diff --git a/config.rpath b/config.rpath
index 4dea75957c2..4f12c27e029 100755
--- a/config.rpath
+++ b/config.rpath
@@ -109,7 +109,7 @@  hardcode_direct=no
 hardcode_minus_L=no
 
 case "$host_os" in
-  cygwin* | mingw* | pw32*)
+  cygwin* | msys* | mingw* | 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 @@  if test "$with_gnu_ld" = yes; then
         ld_shlibs=no
       fi
       ;;
-    cygwin* | mingw* | pw32*)
+    cygwin* | msys* | mingw* | 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 @@  else
       ;;
     bsdi4*)
       ;;
-    cygwin* | mingw* | pw32*)
+    cygwin* | msys* | mingw* | 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 @@  case "$host_os" in
     ;;
   bsdi4*)
     ;;
-  cygwin* | mingw* | pw32*)
+  cygwin* | msys* | mingw* | pw32*)
     shrext=.dll
     ;;
   darwin* | rhapsody*)
diff --git a/config/dfp.m4 b/config/dfp.m4
index d1d151b2da7..6cc4d27ca6d 100644
--- a/config/dfp.m4
+++ b/config/dfp.m4
@@ -42,7 +42,8 @@  Valid choices are 'yes', 'bid', 'dpd', and 'no'.]) ;;
     powerpc*-*-linux* | i?86*-*-linux* | x86_64*-*-linux* | s390*-*-linux* | \
     i?86*-*-elfiamcu | i?86*-*-gnu* | x86_64*-*-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 --git a/config/elf.m4 b/config/elf.m4
index 1772a44318e..7d4f5054562 100644
--- a/config/elf.m4
+++ b/config/elf.m4
@@ -15,7 +15,7 @@  AC_REQUIRE([AC_CANONICAL_TARGET])
 
 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* | \
   nvptx-*-none)
diff --git a/config/lthostflags.m4 b/config/lthostflags.m4
index bc0f59ee79e..ad977d43dc5 100644
--- a/config/lthostflags.m4
+++ b/config/lthostflags.m4
@@ -13,7 +13,7 @@  AC_DEFUN([ACX_LT_HOST_FLAGS], [
 AC_REQUIRE([AC_CANONICAL_SYSTEM])
 
 case $host in
-  *-cygwin* | *-mingw*)
+  *-cygwin* | *-msys* | *-mingw*)
     # '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 --git a/config/mmap.m4 b/config/mmap.m4
index fba0d9d3657..df2c778524c 100644
--- a/config/mmap.m4
+++ b/config/mmap.m4
@@ -42,7 +42,7 @@  else
    # 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 @@  else
    # 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 --git a/config/picflag.m4 b/config/picflag.m4
index 3f3ac744c96..e7eb1f51989 100644
--- a/config/picflag.m4
+++ b/config/picflag.m4
@@ -25,6 +25,8 @@  case "${$2}" in
 	;;
     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 --git a/config/tcl.m4 b/config/tcl.m4
index 4542a4b23d7..209bd8d9b8e 100644
--- a/config/tcl.m4
+++ b/config/tcl.m4
@@ -33,7 +33,7 @@  AC_DEFUN([SC_PATH_TCLCONFIG], [
 
 	    # 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 @@  AC_DEFUN([SC_PATH_TKCONFIG], [
 
 	    # 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 --git a/configure b/configure
index dd743c58663..51c7d7b0b20 100755
--- a/configure
+++ b/configure
@@ -1534,12 +1534,12 @@  Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --enable-as-accelerator-for=ARG
-                          build as offload target compiler. Specify offload
+                          build as offload target compiler.
 Specify offload
                           host triple by ARG
   --enable-offload-targets=LIST
                           enable offloading to devices from comma-separated
-                          LIST of TARGET[=DIR]. Use optional path to find
-                          offload target compiler during the build
+                          LIST of
 TARGET[=DIR]. Use optional path to find
+                          offload target compiler
 during the build
   --enable-offload-defaulted
 		If enabled, configured but not installed offload compilers and
 		libgomp plugins are silently ignored.  Useful for distribution
@@ -1550,7 +1550,7 @@  Optional Features:
   --enable-gprofng[=ARG]  build gprofng [ARG={yes,no}]
   --enable-compressed-debug-sections={all,gas,gold,ld,none}
                           Enable compressed debug sections for gas, gold or ld
-                          by default
+                          by
 default
   --enable-default-compressed-debug-sections-algorithm={zlib,zstd}
                           Default compression algorithm for
                           --enable-compressed-debug-sections.
@@ -1577,17 +1577,17 @@  Optional Features:
   --enable-host-pie       build position independent host executables
   --enable-host-shared    build host code as shared libraries
   --enable-stage1-languages[=all]
-                          choose additional languages to build during stage1.
+                          choose additional languages to build during
 stage1.
                           Mostly useful for compiler development
-  --enable-objc-gc        enable use of Boehm's garbage collector with the GNU
-                          Objective-C runtime
+  --enable-objc-gc        enable use of Boehm's garbage collector with the
+                          GNU Objective-C runtime
   --enable-vtable-verify  Enable vtable verification feature
   --enable-serial-[{host,target,build}-]configure
-                          force sequential configuration of sub-packages for
-                          the host, target or build machine, or all
+                          force sequential configuration of
 sub-packages for
+                          the host, target or build
 machine, or all
                           sub-packages
   --enable-maintainer-mode
-                          enable make rules and dependencies not useful (and
+                          enable make rules and dependencies not useful
 (and
                           sometimes confusing) to the casual installer
   --enable-stage1-checking[=all]
                           choose additional checking for stage1 of the
@@ -1602,19 +1602,20 @@  Optional Packages:
   --with-zstd             Support zstd compressed debug sections
                           (default=auto)
   --with-mpc=PATH         specify prefix directory for installed MPC package.
-                          Equivalent to --with-mpc-include=PATH/include plus
+                          Equivalent to --with-mpc-include=PATH/include
 plus
                           --with-mpc-lib=PATH/lib
   --with-mpc-include=PATH specify directory for installed MPC include files
   --with-mpc-lib=PATH     specify directory for the installed MPC library
-  --with-mpfr=PATH        specify prefix directory for installed MPFR package.
-                          Equivalent to --with-mpfr-include=PATH/include plus
+  --with-mpfr=PATH        specify prefix directory for installed MPFR
+                          package.
 Equivalent to
+                          --with-mpfr-include=PATH/include
 plus
                           --with-mpfr-lib=PATH/lib
   --with-mpfr-include=PATH
                           specify directory for installed MPFR include files
   --with-mpfr-lib=PATH    specify directory for the installed MPFR library
   --with-gmp=PATH         specify prefix directory for the installed GMP
-                          package. Equivalent to
-                          --with-gmp-include=PATH/include plus
+                          package.
 Equivalent to
+                          --with-gmp-include=PATH/include
 plus
                           --with-gmp-lib=PATH/lib
   --with-gmp-include=PATH specify directory for installed GMP include files
   --with-gmp-lib=PATH     specify directory for the installed GMP library
@@ -1628,15 +1629,15 @@  Optional Packages:
   --with-boot-ldflags=FLAGS
                           linker flags for stage2 and later
   --with-isl=PATH         Specify prefix directory for the installed isl
-                          package. Equivalent to
-                          --with-isl-include=PATH/include plus
+                          package.
 Equivalent to
+                          --with-isl-include=PATH/include
 plus
                           --with-isl-lib=PATH/lib
   --with-isl-include=PATH Specify directory for installed isl include files
   --with-isl-lib=PATH     Specify the directory for the installed isl library
   --with-target-bdw-gc=PATHLIST
                           specify prefix directory for installed bdw-gc
-                          package. Equivalent to
-                          --with-target-bdw-gc-include=PATH/include plus
+                          package.
 Equivalent to
+                          --with-target-bdw-gc-include=PATH/include
 plus
                           --with-target-bdw-gc-lib=PATH/lib
   --with-target-bdw-gc-include=PATHLIST
                           specify directories for installed bdw-gc include
@@ -3179,7 +3180,7 @@  fi
 # Configure extra directories which are host specific
 
 case "${host}" in
-  *-cygwin*)
+  *-cygwin* | *-msys*)
     configdirs="$configdirs libtermcap" ;;
 esac
 
@@ -3607,7 +3608,7 @@  esac
 # Disable the go frontend on systems where it is known to not work. Please keep
 # this in sync with contrib/config-list.mk.
 case "${target}" in
-*-*-darwin* | *-*-cygwin* | *-*-mingw* | bpf-* )
+*-*-darwin* | *-*-cygwin* | *-*-msys* | *-*-mingw* | bpf-* )
     unsupported_languages="$unsupported_languages go"
     ;;
 esac
@@ -3639,7 +3640,7 @@  if test x$enable_libgo = x; then
 	# PR 46986
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
-    *-*-cygwin* | *-*-mingw*)
+    *-*-cygwin* | *-*-msys* | *-*-mingw*)
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
     bpf-*-*)
@@ -3934,7 +3935,7 @@  case "${target}" in
   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.
@@ -4090,7 +4091,7 @@  case "${host}" in
   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; }
@@ -4502,7 +4503,7 @@  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -4642,7 +4643,7 @@  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdio.h>
 int
-main ()
+main (void)
 {
 FILE *f = fopen ("conftest.out", "w");
  return ferror (f) || fclose (f) != 0;
@@ -4706,7 +4707,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -4757,7 +4758,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 #ifndef __GNUC__
        choke me
@@ -4798,7 +4799,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -4813,7 +4814,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -4829,7 +4830,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -4878,9 +4879,7 @@  struct stat;
 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
 struct buf { int x; };
 FILE * (*rcsopen) (struct buf *, struct stat *, int);
-static char *e (p, i)
-     char **p;
-     int i;
+static char *e (char **p, int i)
 {
   return p[i];
 }
@@ -4915,7 +4914,7 @@  int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, i
 int argc;
 char **argv;
 int
-main ()
+main (void)
 {
 return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
   ;
@@ -5063,7 +5062,7 @@  test_varargs (const char *format, ...)
 }
 
 int
-main ()
+main (void)
 {
 
   // Check bool.
@@ -5281,7 +5280,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 #ifndef __GNUC__
        choke me
@@ -5322,7 +5321,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -5337,7 +5336,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -5353,7 +5352,7 @@  else
 /* end confdefs.h.  */
 
 int
-main ()
+main (void)
 {
 
   ;
@@ -8157,7 +8156,7 @@  $as_echo_n "checking for the correct version of gmp.h... " >&6; }
 /* end confdefs.h.  */
 #include "gmp.h"
 int
-main ()
+main (void)
 {
 
   #define GCC_GMP_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
@@ -8175,7 +8174,7 @@  if ac_fn_c_try_compile "$LINENO"; then :
 /* end confdefs.h.  */
 #include <gmp.h>
 int
-main ()
+main (void)
 {
 
   #define GCC_GMP_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
@@ -8212,7 +8211,7 @@  $as_echo_n "checking for the correct version of mpfr.h... " >&6; }
 #include <gmp.h>
     #include <mpfr.h>
 int
-main ()
+main (void)
 {
 
     #if MPFR_VERSION < MPFR_VERSION_NUM(3,1,0)
@@ -8229,7 +8228,7 @@  if ac_fn_c_try_compile "$LINENO"; then :
 #include <gmp.h>
     #include <mpfr.h>
 int
-main ()
+main (void)
 {
 
     #if MPFR_VERSION < MPFR_VERSION_NUM(3,1,6)
@@ -8264,7 +8263,7 @@  $as_echo_n "checking for the correct version of mpc.h... " >&6; }
 /* end confdefs.h.  */
 #include <mpc.h>
 int
-main ()
+main (void)
 {
 
     #if MPC_VERSION < MPC_VERSION_NUM(0,8,0)
@@ -8280,7 +8279,7 @@  if ac_fn_c_try_compile "$LINENO"; then :
 /* end confdefs.h.  */
 #include <mpc.h>
 int
-main ()
+main (void)
 {
 
     #if MPC_VERSION < MPC_VERSION_NUM(0,8,1)
@@ -8316,7 +8315,7 @@  $as_echo_n "checking for the correct version of the gmp/mpfr libraries... " >&6;
 /* end confdefs.h.  */
 #include <mpfr.h>
 int
-main ()
+main (void)
 {
 
     mpfr_t n;
@@ -8356,7 +8355,7 @@  $as_echo_n "checking for the correct version of the mpc libraries... " >&6; }
 /* end confdefs.h.  */
 #include <mpc.h>
 int
-main ()
+main (void)
 {
 
     mpc_t c;
@@ -8589,7 +8588,7 @@  $as_echo_n "checking for isl 0.15 or later... " >&6; }
 /* end confdefs.h.  */
 #include <isl/schedule.h>
 int
-main ()
+main (void)
 {
 isl_options_set_schedule_serialize_sccs (NULL, 0);
   ;
@@ -8672,7 +8671,7 @@  fi
 
 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* | \
   nvptx-*-none)
@@ -8690,7 +8689,7 @@  if test $target_elf = yes; then :
 else
   if test x"$default_enable_lto" = x"yes" ; then
     case $target in
-      *-apple-darwin[912]* | *-cygwin* | *-mingw* | *djgpp*) ;;
+      *-apple-darwin[912]* | *-cygwin* | *-msys* | *-mingw* | *djgpp*) ;;
       # On other non-ELF platforms, LTO has yet to be validated.
       *) enable_lto=no ;;
     esac
@@ -8701,7 +8700,7 @@  else
   # 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* | *djgpp*) ;;
+      *-cygwin* | *-msys* | *-mingw* | *-apple-darwin* | *djgpp*) ;;
       *) if test x"$enable_lto" = x"yes"; then
 	as_fn_error $? "LTO support is not enabled for this target." "$LINENO" 5
         fi
@@ -8711,7 +8710,7 @@  else
   # 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* | *-msys* | *-mingw*) build_lto_plugin=$enable_lto ;;
     *) ;;
   esac
 
@@ -9799,7 +9798,7 @@  rm -f conftest*
 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
 
@@ -10351,7 +10350,7 @@  case " $target_configdirs " in
   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 --git a/configure.ac b/configure.ac
index 01cfd017273..57e1375510b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -441,7 +441,7 @@  AC_ARG_ENABLE(default_compressed_debug_sections_algorithm,
 # Configure extra directories which are host specific
 
 case "${host}" in
-  *-cygwin*)
+  *-cygwin* | *-msys*)
     configdirs="$configdirs libtermcap" ;;
 esac
 
@@ -837,7 +837,7 @@  esac
 # Disable the go frontend on systems where it is known to not work. Please keep
 # this in sync with contrib/config-list.mk.
 case "${target}" in
-*-*-darwin* | *-*-cygwin* | *-*-mingw* | bpf-* )
+*-*-darwin* | *-*-cygwin* | *-*-msys* | *-*-mingw* | bpf-* )
     unsupported_languages="$unsupported_languages go"
     ;;
 esac
@@ -866,7 +866,7 @@  if test x$enable_libgo = x; then
 	# PR 46986
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
-    *-*-cygwin* | *-*-mingw*)
+    *-*-cygwin* | *-*-msys* | *-*-mingw*)
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
     bpf-*-*)
@@ -1161,7 +1161,7 @@  case "${target}" in
   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.
@@ -1317,7 +1317,7 @@  case "${host}" in
   i[[3456789]]86-*-msdosdjgpp*)
     host_makefile_frag="config/mh-djgpp"
     ;;
-  *-cygwin*)
+  *-cygwin* | *-msys*)
     ACX_CHECK_CYGWIN_CAT_WORKS
     host_makefile_frag="config/mh-cygwin"
     ;;
@@ -1913,7 +1913,7 @@  ACX_ELF_TARGET_IFELSE([# ELF platforms build the lto-plugin always.
   build_lto_plugin=yes
 ],[if test x"$default_enable_lto" = x"yes" ; then
     case $target in
-      *-apple-darwin[[912]]* | *-cygwin* | *-mingw* | *djgpp*) ;;
+      *-apple-darwin[[912]]* | *-cygwin* | *-msys* | *-mingw* | *djgpp*) ;;
       # On other non-ELF platforms, LTO has yet to be validated.
       *) enable_lto=no ;;
     esac
@@ -1924,7 +1924,7 @@  ACX_ELF_TARGET_IFELSE([# ELF platforms build the lto-plugin always.
   # 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* | *djgpp*) ;;
+      *-cygwin* | *-msys* | *-mingw* | *-apple-darwin* | *djgpp*) ;;
       *) if test x"$enable_lto" = x"yes"; then
 	AC_MSG_ERROR([LTO support is not enabled for this target.])
         fi
@@ -1934,7 +1934,7 @@  ACX_ELF_TARGET_IFELSE([# ELF platforms build the lto-plugin always.
   # 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* | *-msys* | *-mingw*) build_lto_plugin=$enable_lto ;;
     *) ;;
   esac
 ])
@@ -2926,7 +2926,7 @@  rm -f conftest*
 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
 
@@ -3473,7 +3473,7 @@  case " $target_configdirs " in
   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 --git a/gas/configure b/gas/configure
index 3c80fe5741a..ba92b6db198 100755
--- a/gas/configure
+++ b/gas/configure
@@ -5243,7 +5243,7 @@  else
     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,
@@ -5585,7 +5585,7 @@  bsdi[45]*)
   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'
@@ -6201,7 +6201,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -7818,7 +7818,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -7900,7 +7900,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -8362,7 +8362,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -8477,7 +8477,7 @@  _LT_EOF
       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'
@@ -8908,7 +8908,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -9809,14 +9809,14 @@  bsdi[45]*)
   # 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}`~
@@ -9838,6 +9838,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -10490,7 +10496,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -13685,7 +13691,7 @@  case "${need_libm}" in
 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*)
@@ -14018,7 +14024,7 @@  _ACEOF
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 3a582ef41d4..11dd0a7ec9e 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -251,7 +251,7 @@  case ${generic_target} in
   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 --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
index 007408f03d8..b92bc326f10 100644
--- a/gas/testsuite/gas/all/gas.exp
+++ b/gas/testsuite/gas/all/gas.exp
@@ -181,8 +181,8 @@  switch -glob $target_triplet {
 	# failures.
 	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-*-cygwin*" "x86_64-*-mingw*"
+	    "i\[3-7\]86-*-cygwin*" "i\[3-7\]86-*-msys*" "i\[3-7\]86-*-mingw*" \
+	    "x86_64-*-cygwin*" "x86_64-*-msys*" "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"
@@ -326,6 +326,7 @@  if {   ([istarget *-*-coff*] && ![istarget *c4x*-*-coff] && ![istarget *c54x*-*-
      || [istarget i*86-*-aix*] \
      || [istarget i*86-*-go32*] \
      || [istarget i*86-*-cygwin*] \
+     || [istarget i*86-*-msys*] \
      || [istarget x86_64-*-mingw*] \
      || [istarget i*86-*-*nt] \
      || [istarget i*86-*-interix*] } {
@@ -399,6 +400,7 @@  if {    ![istarget avr-*-*]
 
 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 --git a/gdb/configure b/gdb/configure
index 5361bf42952..22673a3f3a2 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -5926,7 +5926,7 @@  else
     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,
@@ -6268,7 +6268,7 @@  bsdi[45]*)
   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'
@@ -6926,7 +6926,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8544,7 +8544,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -8626,7 +8626,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -9088,7 +9088,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -9203,7 +9203,7 @@  _LT_EOF
       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'
@@ -9634,7 +9634,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -10535,14 +10535,14 @@  bsdi[45]*)
   # 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}`~
@@ -10560,9 +10560,9 @@  cygwin* | mingw* | pw32* | cegcc*)
     shlibpath_overrides_runpath=yes
 
     case $host_os in
-    cygwin*)
+    cygwin* | msys*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
-      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      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"
       ;;
@@ -11216,7 +11216,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -12438,7 +12438,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
         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'
@@ -13408,7 +13408,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
     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
@@ -13948,7 +13948,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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'
   ;;
   *)
@@ -14212,14 +14212,14 @@  bsdi[45]*)
   # 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}`~
@@ -14237,9 +14237,9 @@  cygwin* | mingw* | pw32* | cegcc*)
     shlibpath_overrides_runpath=yes
 
     case $host_os in
-    cygwin*)
+    cygwin* | msys*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
-      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      soname_spec='`echo $libname | $SED -e 's/^lib/msys-/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext'
 
       ;;
     mingw* | cegcc*)
@@ -20748,7 +20748,7 @@  fi
 # have a separate termcap library, or no curses library at all.
 
 case $host_os in
-  cygwin*)
+  cygwin* | msys*)
     if test -d "$srcdir/libtermcap"; then
       LIBS="../libtermcap/libtermcap.a $LIBS"
       ac_cv_search_tgetent="../libtermcap/libtermcap.a"
@@ -28363,7 +28363,7 @@  WIN32LIBS=
 if test x"$gdb_cv_os_cygwin" = xyes; then
     WIN32LIBS="-luser32"
     case "${target}" in
-	*cygwin*) WIN32LIBS="$WIN32LIBS -limagehlp"
+	*cygwin* | *msys*) WIN32LIBS="$WIN32LIBS -limagehlp"
 	;;
     esac
 fi
@@ -29059,7 +29059,7 @@  WIN32LDAPP=
 
 
 case "${host}" in
-*-*-cygwin* | *-*-mingw* )
+*-*-cygwin* | *-*-msys* | *-*-mingw* )
     configdir="win"
     ;;
 *)
@@ -29102,7 +29102,7 @@  else
 
 	    # 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
@@ -29231,7 +29231,7 @@  else
 
 	    # 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 --git a/gdb/configure.ac b/gdb/configure.ac
index 3912b77b27f..e1518d36d43 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -584,7 +584,7 @@  fi
 # have a separate termcap library, or no curses library at all.
 
 case $host_os in
-  cygwin*)
+  cygwin* | msys*)
     if test -d "$srcdir/libtermcap"; then
       LIBS="../libtermcap/libtermcap.a $LIBS"
       ac_cv_search_tgetent="../libtermcap/libtermcap.a"
@@ -1840,7 +1840,7 @@  WIN32LIBS=
 if test x"$gdb_cv_os_cygwin" = xyes; then
     WIN32LIBS="-luser32"
     case "${target}" in
-	*cygwin*) WIN32LIBS="$WIN32LIBS -limagehlp"
+	*cygwin* | *msys*) WIN32LIBS="$WIN32LIBS -limagehlp"
 	;;
     esac
 fi
@@ -1904,7 +1904,7 @@  AC_SUBST(WIN32LIBS)
 AC_SUBST(WIN32LDAPP)
 
 case "${host}" in
-*-*-cygwin* | *-*-mingw* )
+*-*-cygwin* | *-*-msys* | *-*-mingw* )
     configdir="win"
     ;;
 *)
diff --git a/gdb/configure.host b/gdb/configure.host
index da71675b201..deb1bd7ec48 100644
--- a/gdb/configure.host
+++ b/gdb/configure.host
@@ -115,6 +115,7 @@  i[34567]86-*-openbsd*)	gdb_host=obsd ;;
 i[34567]86-*-solaris2* | x86_64-*-solaris2*)
 			gdb_host=sol2 ;;
 i[34567]86-*-cygwin*)	gdb_host=cygwin ;;
+i[34567]86-*-msys*)	gdb_host=msys ;;
 
 ia64-*-linux*)		gdb_host=linux ;;
 
@@ -184,6 +185,7 @@  x86_64-*-mingw*)        gdb_host=mingw64
 			gdb_host_obs=mingw-hdep.o
 			;;
 x86_64-*-cygwin*)	gdb_host=cygwin64 ;;
+x86_64-*-msys*)	gdb_host=msys64 ;;
 m32r*-*-linux*)          gdb_host=linux ;;
 
 xtensa*-*-linux*)	gdb_host=linux ;;
diff --git a/gdb/configure.nat b/gdb/configure.nat
index 1dc4206b69c..aae888fe340 100644
--- a/gdb/configure.nat
+++ b/gdb/configure.nat
@@ -77,6 +77,9 @@  case ${gdb_host} in
     cygwin*)
 	NATDEPFILES='x86-nat.o nat/x86-dregs.o windows-nat.o nat/windows-nat.o'
 	;;
+    msys*)
+	NATDEPFILES='x86-nat.o nat/x86-dregs.o windows-nat.o nat/windows-nat.o'
+	;;
     mingw*)
 	NATDEPFILES='x86-nat.o nat/x86-dregs.o windows-nat.o nat/windows-nat.o'
 	;;
@@ -123,7 +126,7 @@  case ${gdb_host} in
 		;;
 	esac
 	;;
-    cygwin)
+    cygwin | msys)
 	case ${gdb_host_cpu} in
 	    i386)
 		# Native config information for GDB on i386
@@ -132,7 +135,7 @@  case ${gdb_host} in
 		;;
 	esac
 	;;
-    cygwin64)
+    cygwin64 | msys64)
 	case ${gdb_host_cpu} in
 	    i386)
 		# Native config information for GDB on amd64
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 47a674201f9..136da0a333b 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -334,6 +334,11 @@  i[34567]86-*-cygwin*)
 	# Target: Intel 386 running win32
 	gdb_target_obs="i386-windows-tdep.o windows-tdep.o"
 	;;
+i[34567]86-*-msys*)
+	# Target: Intel 386 running win32
+	gdb_target_obs="i386-windows-tdep.o windows-tdep.o"
+	build_gdbserver=yes
+	;;
 i[34567]86-*-mingw32*)
 	# Target: Intel 386 running win32
 	gdb_target_obs="i386-windows-tdep.o windows-tdep.o"
@@ -725,7 +730,7 @@  x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
 	gdb_target_obs="amd64-fbsd-tdep.o ${i386_tobjs} \
 			i386-bsd-tdep.o i386-fbsd-tdep.o"
 	;;
-x86_64-*-mingw* | x86_64-*-cygwin*)
+x86_64-*-mingw* | x86_64-*-cygwin* | x86_64-*-msys*)
         # Target: MingW/amd64
 	gdb_target_obs="amd64-windows-tdep.o \
                         ${i386_tobjs} i386-windows-tdep.o \
diff --git a/gdb/testsuite/gdb.base/bigcore.exp b/gdb/testsuite/gdb.base/bigcore.exp
index 743dc1dfbec..081b9123020 100644
--- a/gdb/testsuite/gdb.base/bigcore.exp
+++ b/gdb/testsuite/gdb.base/bigcore.exp
@@ -30,7 +30,8 @@  require isnative
 if { [istarget "*-*-*bsd*"]
      || [istarget "*-*-solaris*"] 
      || [istarget "*-*-darwin*"] 
-     || [istarget "*-*-cygwin*"] } {
+     || [istarget "*-*-cygwin*"] 
+     || [istarget "*-*-msys*"] } {
     untested "kernel lacks sparse corefile support (PR gdb/1551)"
     return
 }
diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp
index 6a708ed00ed..c0775006955 100644
--- a/gdb/testsuite/gdb.base/fileio.exp
+++ b/gdb/testsuite/gdb.base/fileio.exp
@@ -240,7 +240,7 @@  gdb_test continue \
 
 # This test fails on Cygwin because unlink() succeeds on Win32 systems
 # in that situation.
-if [ishost *cygwin*] {
+if { ([ishost *cygwin*] || [ishost *msys*]) } {
     setup_xfail "*-*-*"
 }
 # If the user is root, we will always have write permission.
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index c05d0987e7f..2f8d2c5a743 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -188,7 +188,7 @@  gdb_test "maint set per-command off" \
 # The timeout value is raised, because printing all the symbols and
 # statistical information about Cygwin and Windows libraries takes a lot
 # of time.
-if [istarget "*-*-cygwin*"] {
+if { ([istarget "*-*-cygwin*"] || [istarget "*-*-msys*"]) } {
 	set oldtimeout $timeout
 	set timeout [expr $timeout + 500]
 }
diff --git a/gdb/testsuite/gdb.base/shreloc.exp b/gdb/testsuite/gdb.base/shreloc.exp
index 315250c5529..b474015796e 100644
--- a/gdb/testsuite/gdb.base/shreloc.exp
+++ b/gdb/testsuite/gdb.base/shreloc.exp
@@ -38,7 +38,7 @@  set lib2_sl [standard_output_file shreloc2.sl]
 set lib_opts "debug"
 set exec_opts [list debug shlib=$lib1_sl shlib=$lib2_sl]
 
-if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
+if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"] || [istarget "*pc-msys"]) } {
     lappend lib_opts "ldflags=-Wl,--image-base,0x04000000"
 }
 
@@ -219,7 +219,7 @@  if [send_gdb_discard "maint print msymbols ${msymfile}"] {
     }
 }
 
-if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
+if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"] || [istarget "*pc-msys"]) } {
     #
     # We know the names of some absolute symbols included in the
     # portable-executable (DLL) format. Check that they didn't get
diff --git a/gdb/testsuite/gdb.base/solib-weak.exp b/gdb/testsuite/gdb.base/solib-weak.exp
index dc99be71648..4840d711d3c 100644
--- a/gdb/testsuite/gdb.base/solib-weak.exp
+++ b/gdb/testsuite/gdb.base/solib-weak.exp
@@ -22,7 +22,8 @@  require allow_shlib_tests
 # These targets have shared libraries, but weak symbols are not meaningful.
 if {([istarget *-*-mingw*]
      || [istarget *-*-cygwin*]
-     || [istarget *-*-pe*])} {
+     || [istarget *-*-pe*]
+     || [istarget *-*-msys*]) } {
     return 0
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-dos-drive.exp b/gdb/testsuite/gdb.dwarf2/dw2-dos-drive.exp
index 58792e130f7..4b4a5c7b0d1 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-dos-drive.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-dos-drive.exp
@@ -30,7 +30,8 @@  gdb_test_no_output "set breakpoint pending off"
 gdb_test "break 'z:file.c':func" {Breakpoint [0-9]+ at .*}
 
 set dos [expr [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"] \
-	      || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] ]
+	      || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] \
+	      || [istarget "*-*-msys*"] ]
 
 if { $dos } {
     gdb_test "break file.c:func" {Breakpoint [0-9]+ at .*}
diff --git a/gdb/testsuite/gdb.server/wrapper.exp b/gdb/testsuite/gdb.server/wrapper.exp
index ec985e0da2e..2f04f1f8813 100644
--- a/gdb/testsuite/gdb.server/wrapper.exp
+++ b/gdb/testsuite/gdb.server/wrapper.exp
@@ -24,7 +24,8 @@  standard_testfile
 require allow_gdbserver_tests
 
 if { [istarget *-*-mingw*]
-     || [istarget *-*-cygwin*] } {
+     || [istarget *-*-cygwin*]
+     || [istarget *-*-msys*] } {
     unsupported "gdbserver does not support --wrapper on this target (PR server/15967)"
     return -1
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 0a908e0af0f..e2cdc4b49b3 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2641,7 +2641,8 @@  proc allow_shlib_tests {} {
 	 || [istarget *-*-solaris2*]
 	 || [istarget *-*-mingw*]
 	 || [istarget *-*-cygwin*]
-	 || [istarget *-*-pe*])} {
+	 || [istarget *-*-pe*]
+	 || [istarget *-*-msys*])} {
 	return 1
     }
 
@@ -5316,7 +5317,8 @@  proc gdb_compile {source dest type options} {
 		lappend source "-Wl,$shlib_name"
 	    } elseif { ([istarget "*-*-mingw*"]
 			|| [istarget *-*-cygwin*]
-			|| [istarget *-*-pe*])} {
+			|| [istarget *-*-pe*]
+			|| [istarget *-*-msys*])} {
 		lappend source "${shlib_name}.a"
             } else {
                lappend source $shlib_name
@@ -5324,7 +5326,8 @@  proc gdb_compile {source dest type options} {
             if { $shlib_found == 0 } {
                 set shlib_found 1
 		if { ([istarget "*-*-mingw*"]
-		      || [istarget *-*-cygwin*]) } {
+		      || [istarget *-*-cygwin*]
+		      || [istarget *-*-msys*]) } {
 		    lappend new_options "ldflags=-Wl,--enable-auto-import"
 		}
 		if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
@@ -5385,6 +5388,7 @@  proc gdb_compile {source dest type options} {
     if { $shlib_load || $shlib_found } {
 	if { ([istarget "*-*-mingw*"]
 	      || [istarget *-*-cygwin*]
+	      || [istarget *-*-msys*]
 	      || [istarget *-*-pe*]) } {
 	    # Do not need anything.
 	} elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
@@ -5483,7 +5487,8 @@  proc gdb_compile {source dest type options} {
     if { $type == "executable" } {
 	if { ([istarget "*-*-mingw*"]
 	      || [istarget "*-*-*djgpp"]
-	      || [istarget "*-*-cygwin*"])} {
+	      || [istarget "*-*-cygwin*"]
+	      || [istarget "*-*-msys*"])} {
 	    # Force output to unbuffered mode, by linking in an object file
 	    # with a global contructor that calls setvbuf.
 	    #
@@ -5629,6 +5634,7 @@  proc gdb_compile_shlib_1 {sources dest options} {
         }
 	"clang-*" {
 	    if { [istarget "*-*-cygwin*"]
+		 || [istarget *-*-msys*]
 		 || [istarget "*-*-mingw*"] } {
 		lappend obj_options "additional_flags=-fPIC"
 	    } else {
@@ -5639,6 +5645,7 @@  proc gdb_compile_shlib_1 {sources dest options} {
             if { [istarget "powerpc*-*-aix*"]
                    || [istarget "rs6000*-*-aix*"]
                    || [istarget "*-*-cygwin*"]
+                   || [istarget "*-*-msys*"]
                    || [istarget "*-*-mingw*"]
                    || [istarget "*-*-pe*"] } {
                 lappend obj_options "additional_flags=-fPIC"
@@ -5704,6 +5711,7 @@  proc gdb_compile_shlib_1 {sources dest options} {
 
 	if { ([istarget "*-*-mingw*"]
 	      || [istarget *-*-cygwin*]
+	      || [istarget *-*-msys*]
 	      || [istarget *-*-pe*]) } {
 	    if { [is_remote host] } {
 		set name [file tail ${dest}]
@@ -5731,6 +5739,7 @@  proc gdb_compile_shlib_1 {sources dest options} {
     if { [is_remote host]
 	 && ([istarget "*-*-mingw*"]
 	     || [istarget *-*-cygwin*]
+	     || [istarget *-*-msys*]
 	     || [istarget *-*-pe*]) } {
 	set dest_tail_name [file tail ${dest}]
 	remote_upload host $dest_tail_name.a ${dest}.a
@@ -6162,7 +6171,7 @@  proc kill_wait_spawned_process { proc_spawn_id } {
 proc spawn_id_get_pid { spawn_id } {
     set testpid [exp_pid -i $spawn_id]
 
-    if { [istarget "*-*-cygwin*"] } {
+    if { ([istarget "*-*-cygwin*"] || [istarget *-*-msys*]) } {
 	# testpid is the Cygwin PID, GDB uses the Windows PID, which
 	# might be different due to the way fork/exec works.
 	set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
@@ -7712,6 +7721,7 @@  gdb_caching_proc gdb_has_argv0 {} {
 	  || [istarget *-*-aix*]
 	  || [istarget *-*-gnu*]
 	  || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
+	  || [istarget *-*-msys*]
 	  || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
 	  || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
 	  || [istarget *-*-osf*]
@@ -7746,7 +7756,7 @@  gdb_caching_proc gdb_has_argv0 {} {
 
 proc get_build_id { filename } {
     if { ([istarget "*-*-mingw*"]
-	  || [istarget *-*-cygwin*]) } {
+	  || [istarget *-*-cygwin*] || [istarget *-*-msys*]) } {
 	set objdump_program [gdb_find_objdump]
 	set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
 	verbose "result is $result"
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index d46de87f238..971efd086c0 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -900,11 +900,19 @@  windows_make_so (const char *name, LPVOID load_addr)
 	    }
 	}
     }
+#ifdef __MSYS__
+  /* Record msys-2.0.dll .text start/end.  */
+  size_t len = sizeof ("/msys-2.0.dll") - 1;
+  if (so->name.size () >= len
+      && strcasecmp (so->name.c_str () + so->name.size () - len,
+		     "/msys-2.0.dll") == 0)
+#else
   /* Record cygwin1.dll .text start/end.  */
   size_t len = sizeof ("/cygwin1.dll") - 1;
   if (so->name.size () >= len
       && strcasecmp (so->name.c_str () + so->name.size () - len,
 		     "/cygwin1.dll") == 0)
+#endif
     {
       asection *text = NULL;
 
diff --git a/gdbserver/configure.srv b/gdbserver/configure.srv
index 9e861a75088..a9e16f79a10 100644
--- a/gdbserver/configure.srv
+++ b/gdbserver/configure.srv
@@ -94,7 +94,7 @@  case "${gdbserver_host}" in
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
 			;;
-  i[34567]86-*-cygwin*)	srv_regobj=""
+  i[34567]86-*-cygwin* | i[34567]86-*-msys*)	srv_regobj=""
 			srv_tgtobj="x86-low.o nat/x86-dregs.o win32-low.o"
 			srv_tgtobj="${srv_tgtobj} win32-i386-low.o"
 			srv_tgtobj="${srv_tgtobj} nat/windows-nat.o"
@@ -387,7 +387,7 @@  case "${gdbserver_host}" in
 			srv_tgtobj="${srv_tgtobj} arch/amd64.o arch/i386.o"
 			srv_mingw=yes
 			;;
-  x86_64-*-cygwin*)	srv_regobj=""
+  x86_64-*-cygwin* | x86_64-*-msys*)	srv_regobj=""
 			srv_tgtobj="x86-low.o nat/x86-dregs.o"
 			srv_tgtobj="${srv_tgtobj} nat/x86-xstate.o i387-fp.o"
 			srv_tgtobj="${srv_tgtobj} win32-low.o win32-i386-low.o"
diff --git a/gnulib/configure b/gnulib/configure
index cc7e8287d5a..808ce376a1c 100644
--- a/gnulib/configure
+++ b/gnulib/configure
@@ -9124,7 +9124,7 @@  else
         # special semantics and is distinct from /, please report it to
         # <bug-gnulib@gnu.org>.
         case $host in
-          *-cygwin | i370-ibm-openedition)
+          *-cygwin | *-msys | i370-ibm-openedition)
             gl_cv_double_slash_root=yes ;;
           *)
             # Be optimistic and assume that / and // are the same when we
@@ -23563,7 +23563,7 @@  else
         # special semantics and is distinct from /, please report it to
         # <bug-gnulib@gnu.org>.
         case $host in
-          *-cygwin | i370-ibm-openedition)
+          *-cygwin | *-msys | i370-ibm-openedition)
             gl_cv_double_slash_root=yes ;;
           *)
             # Be optimistic and assume that / and // are the same when we
@@ -23711,7 +23711,7 @@  else
   case "$host_os" in
          mingw*) # on this platform, dup2 always returns 0 for success
            gl_cv_func_dup2_works="guessing no" ;;
-         cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
+         cygwin* | msys*) # on cygwin 1.5.x, dup2(1,1) returns 0
            gl_cv_func_dup2_works="guessing no" ;;
          aix* | freebsd*)
                  # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
@@ -24112,7 +24112,7 @@  if ${gl_cv_func_fcntl_f_dupfd_works+:} false; then :
 else
   if test "$cross_compiling" = yes; then :
   case $host_os in
-            aix* | cygwin* | haiku*)
+            aix* | cygwin* | msys* | haiku*)
                gl_cv_func_fcntl_f_dupfd_works="guessing no" ;;
             *) gl_cv_func_fcntl_f_dupfd_works="guessing yes" ;;
           esac
diff --git a/gnulib/import/m4/double-slash-root.m4 b/gnulib/import/m4/double-slash-root.m4
index 09ff5f0d17a..1e11243ff02 100644
--- a/gnulib/import/m4/double-slash-root.m4
+++ b/gnulib/import/m4/double-slash-root.m4
@@ -16,7 +16,7 @@  AC_DEFUN([gl_DOUBLE_SLASH_ROOT],
         # special semantics and is distinct from /, please report it to
         # <bug-gnulib@gnu.org>.
         case $host in
-          *-cygwin | i370-ibm-openedition)
+          *-cygwin | *-msys | i370-ibm-openedition)
             gl_cv_double_slash_root=yes ;;
           *)
             # Be optimistic and assume that / and // are the same when we
diff --git a/gnulib/import/m4/dup2.m4 b/gnulib/import/m4/dup2.m4
index 7e777cdee6a..62ad578c090 100644
--- a/gnulib/import/m4/dup2.m4
+++ b/gnulib/import/m4/dup2.m4
@@ -69,7 +69,7 @@  AC_DEFUN([gl_FUNC_DUP2],
       [case "$host_os" in
          mingw*) # on this platform, dup2 always returns 0 for success
            gl_cv_func_dup2_works="guessing no" ;;
-         cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
+         cygwin* | msys*) # on cygwin 1.5.x, dup2(1,1) returns 0
            gl_cv_func_dup2_works="guessing no" ;;
          aix* | freebsd*)
                  # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
diff --git a/gnulib/import/m4/fcntl.m4 b/gnulib/import/m4/fcntl.m4
index 428e5709d30..84f84fbb3dc 100644
--- a/gnulib/import/m4/fcntl.m4
+++ b/gnulib/import/m4/fcntl.m4
@@ -70,7 +70,7 @@  AC_DEFUN([gl_FUNC_FCNTL],
          [gl_cv_func_fcntl_f_dupfd_works=yes],
          [gl_cv_func_fcntl_f_dupfd_works=no],
          [case $host_os in
-            aix* | cygwin* | haiku*)
+            aix* | cygwin* | msys* | haiku*)
                gl_cv_func_fcntl_f_dupfd_works="guessing no" ;;
             *) gl_cv_func_fcntl_f_dupfd_works="guessing yes" ;;
           esac])])
diff --git a/gprof/configure b/gprof/configure
index 4727b2acbfc..1a226d2b0d7 100755
--- a/gprof/configure
+++ b/gprof/configure
@@ -5121,7 +5121,7 @@  else
     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,
@@ -5463,7 +5463,7 @@  bsdi[45]*)
   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'
@@ -6079,7 +6079,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -7696,7 +7696,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -7778,7 +7778,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -8240,7 +8240,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -8355,7 +8355,7 @@  _LT_EOF
       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'
@@ -8786,7 +8786,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -9687,14 +9687,14 @@  bsdi[45]*)
   # 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}`~
@@ -9716,6 +9716,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -10368,7 +10374,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
diff --git a/intl/configure b/intl/configure
index b0aae146908..3f25b36fe76 100755
--- a/intl/configure
+++ b/intl/configure
@@ -6844,6 +6844,8 @@  case "${host}" in
 	;;
     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 --git a/ld/configure b/ld/configure
index d2cdf256b89..bab43a135b9 100755
--- a/ld/configure
+++ b/ld/configure
@@ -6140,7 +6140,7 @@  else
     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,
@@ -6482,7 +6482,7 @@  bsdi[45]*)
   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'
@@ -7098,7 +7098,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8716,7 +8716,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -8798,7 +8798,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -9260,7 +9260,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -9375,7 +9375,7 @@  _LT_EOF
       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'
@@ -9806,7 +9806,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -10707,14 +10707,14 @@  bsdi[45]*)
   # 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}`~
@@ -10736,6 +10736,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -11388,7 +11394,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -12610,7 +12616,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
         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'
@@ -13580,7 +13586,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
     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
@@ -14120,7 +14126,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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'
   ;;
   *)
@@ -14384,14 +14390,14 @@  bsdi[45]*)
   # 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}`~
@@ -14413,6 +14419,11 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       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
@@ -16800,7 +16811,7 @@  done
 
 
 case "${host}" in
-*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
+*-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-msys* | *-*-windows*)
 
 $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
  ;;
diff --git a/ld/configure.tgt b/ld/configure.tgt
index 3aa595ef130..eb9e5858304 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -424,7 +424,7 @@  i[3-7]86-*-winnt*)	targ_emul=i386pe ;
 i[3-7]86-*-pe)		targ_emul=i386pe ;
 			targ_extra_ofiles="deffilep.o pdb.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 pdb.o pe-dll.o" ;
 			test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api'
 			;;
@@ -1055,7 +1055,7 @@  x86_64-*-pe | x86_64-*-pep) targ_emul=i386pep ;
 			targ_extra_emuls=i386pe ;
 			targ_extra_ofiles="deffilep.o pdb.o pep-dll-x86_64.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 pdb.o pep-dll.o pe-dll.o"
 			test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api'
@@ -1140,7 +1140,7 @@  spu-*-elf*)
   NATIVE_LIB_DIRS='/lib'
   ;;
 
-i[03-9x]86-*-cygwin* | x86_64-*-cygwin*)
+i[03-9x]86-*-cygwin* | x86_64-*-cygwin* | i[03-9x]86-*-msys* | x86_64-*-msys*)
   NATIVE_LIB_DIRS='/usr/lib /usr/lib/w32api'
   ;;
 
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 24dc19afff3..f7bfc203455 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -7,7 +7,7 @@  else
 fi
 
 case ${target} in
-  *-*-cygwin*)
+  *-*-cygwin* | *-*-msys*)
     cygwin_behavior=1
     ;;
   *)
@@ -208,7 +208,7 @@  EOF
 # 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 --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 289c72e3036..feb92b6fca4 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -7,7 +7,7 @@  else
 fi
 
 case ${target} in
-  *-*-cygwin*)
+  *-*-cygwin* | *-*-msys*)
     move_default_addr_high=1
     cygwin_behavior=1
     ;;
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index fc83f5208d6..5a54f5362a8 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -210,6 +210,7 @@  static const autofilter_entry_type autofilter_symbollist_i386[] =
   { 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_plus
   { STRING_COMMA_LEN ("DllMain") },
   { STRING_COMMA_LEN ("DllEntryPoint") },
@@ -217,6 +218,9 @@  static const autofilter_entry_type autofilter_symbollist_i386[] =
   { 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") },
@@ -225,6 +229,10 @@  static const autofilter_entry_type autofilter_symbollist_i386[] =
   { 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") },
@@ -348,6 +356,7 @@  static const autofilter_entry_type autofilter_liblist[] =
 {
   { 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 --git a/ld/testsuite/ld-auto-import/auto-import.exp b/ld/testsuite/ld-auto-import/auto-import.exp
index f86f01e326d..0ec1f3f9933 100644
--- a/ld/testsuite/ld-auto-import/auto-import.exp
+++ b/ld/testsuite/ld-auto-import/auto-import.exp
@@ -174,3 +174,65 @@  if [istarget *-pc-cygwin] {
     	fail $msg
     }
 }
+
+if [istarget *-pc-msys] {
+    # Set some libs needed for msys.
+    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 ![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"
+    }
+
+    # Create symbolic link.
+    catch "exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
+
+    # Compile and link the client program.
+    if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/client.c $tmpdir/client.o] {
+        fail "compiling client"
+    }
+
+    # Check linking with import library.
+    set msg "linking auto-import client using a standard import library"
+    if [ld_special_link $ld $tmpdir/client-linklib.exe "--enable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -lstandard $MYLIBS"] {
+	pass $msg
+    } else {
+	fail $msg 
+    }
+
+    # Check linking directly with dll.
+    set msg "linking auto-import client using the dll"
+    if [ld_special_link $ld $tmpdir/client-linkdll.exe "--enable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -ldll $MYLIBS"] {
+	pass $msg
+    } else {
+	fail $msg 
+    }
+
+    # Check linking with symlinked dll.
+    set msg "linking auto-import client using symbolic linked dll"
+    if [ld_special_link $ld $tmpdir/client-symlinkeddll.exe "--enable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -lsymlinked_dll $MYLIBS"] {
+	pass $msg
+    } else {
+	fail $msg 
+    }
+
+    # Check linking with disabled auto-import, this must produce linking error.
+    set msg "linking with disabled auto-import"
+    if ![ld_special_link $ld $tmpdir/client-failed.exe "--disable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -ldll $MYLIBS"] {
+	pass $msg
+    } else {
+	fail $msg
+    }
+
+    # Check that the app works - ie that there is output when the applications runs.
+    set msg "application runtime segfault check" 
+    catch "exec $tmpdir/client-linklib.exe" exec_output
+    if ![string match "" $exec_output] then {
+    	pass $msg
+    } else {
+    	fail $msg
+    }
+}
diff --git a/ld/testsuite/ld-fastcall/fastcall.exp b/ld/testsuite/ld-fastcall/fastcall.exp
index 280aef015f8..1a766ec2462 100644
--- a/ld/testsuite/ld-fastcall/fastcall.exp
+++ b/ld/testsuite/ld-fastcall/fastcall.exp
@@ -26,6 +26,7 @@  if {![istarget "i*86-*-*"] && ![istarget "x86_64-*-mingw*"] } {
 
 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 --git a/ld/testsuite/ld-pe/pe-compile.exp b/ld/testsuite/ld-pe/pe-compile.exp
index 020b544182a..4e7a631e042 100644
--- a/ld/testsuite/ld-pe/pe-compile.exp
+++ b/ld/testsuite/ld-pe/pe-compile.exp
@@ -116,6 +116,7 @@  run_ver_script_test "vers-script-3"
 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 --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp
index 35a88d26bcf..d2612783830 100644
--- a/ld/testsuite/ld-pe/pe.exp
+++ b/ld/testsuite/ld-pe/pe.exp
@@ -26,6 +26,7 @@  if {![is_pecoff_format]} {
 
 # 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*]
@@ -42,7 +43,7 @@  if {[istarget i*86-*-cygwin*]
 	{"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 --disable-reloc-section" "" "" {secrel1.s secrel2.s}
 	 {{objdump -s secrel.d}} "secrel.x"}
@@ -127,7 +128,7 @@  run_ld_link_tests $pr19803_dll
 
 if {[istarget x86_64-*-mingw*] } {
 	run_dump_test "cfi"
-} elseif {[istarget i*86-*-cygwin*] || [istarget i*86-*-mingw*] } {
+} elseif {[istarget i*86-*-cygwin*] || [istarget i*86-*-msys*] || [istarget i*86-*-mingw*] } {
 	run_dump_test "cfi32"
 }
 
diff --git a/ld/testsuite/ld-pe/weakdef-1.d b/ld/testsuite/ld-pe/weakdef-1.d
index 57a85656ea5..a653170629b 100644
--- a/ld/testsuite/ld-pe/weakdef-1.d
+++ b/ld/testsuite/ld-pe/weakdef-1.d
@@ -1,5 +1,5 @@ 
 #source: weakdef-1.s
-#target: i*86-*-cygwin* i*86-*-pe i*86-*-mingw*
+#target: i*86-*-cygwin* i*86-*-msys* i*86-*-pe i*86-*-mingw*
 #ld: -e _start --gc-sections
 #objdump: -d
 
diff --git a/libctf/configure b/libctf/configure
index 4c01c022837..4c6a4457aab 100755
--- a/libctf/configure
+++ b/libctf/configure
@@ -6178,7 +6178,7 @@  else
     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,
@@ -6520,7 +6520,7 @@  bsdi[45]*)
   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'
@@ -7136,7 +7136,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8723,7 +8723,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -8805,7 +8805,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -9267,7 +9267,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -9382,7 +9382,7 @@  _LT_EOF
       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'
@@ -9813,7 +9813,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -10714,14 +10714,14 @@  bsdi[45]*)
   # 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}`~
@@ -10743,6 +10743,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -11395,7 +11401,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -14947,6 +14953,10 @@  if test "$enable_shared" = "yes"; then
       SHARED_LDFLAGS="-no-undefined"
       CTF_LIBADD="$CTF_LIBADD -lcygwin"
       ;;
+    *-*-msys*)
+      SHARED_LDFLAGS="-no-undefined"
+      CTF_LIBADD="$CTF_LIBADD -lmsys-2.0"
+      ;;
   esac
 fi
 
diff --git a/libctf/configure.ac b/libctf/configure.ac
index 6a5eade1855..d0465ab30cb 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -229,6 +229,10 @@  if test "$enable_shared" = "yes"; then
       SHARED_LDFLAGS="-no-undefined"
       CTF_LIBADD="$CTF_LIBADD -lcygwin"
       ;;
+    *-*-msys*)
+      SHARED_LDFLAGS="-no-undefined"
+      CTF_LIBADD="$CTF_LIBADD -lmsys-2.0"
+      ;;
   esac
 fi
 AC_SUBST(SHARED_LDFLAGS)
diff --git a/libdecnumber/configure b/libdecnumber/configure
index e4600c10e55..8ecb083a560 100755
--- a/libdecnumber/configure
+++ b/libdecnumber/configure
@@ -4769,7 +4769,8 @@  else
     powerpc*-*-linux* | i?86*-*-linux* | x86_64*-*-linux* | s390*-*-linux* | \
     i?86*-*-elfiamcu | i?86*-*-gnu* | x86_64*-*-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 --git a/libiberty/configure b/libiberty/configure
index dd896270dc6..791c15e59e7 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -5330,6 +5330,8 @@  case "${host}" in
 	;;
     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]*)
@@ -6629,7 +6631,7 @@  fi
 
 
 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 --git a/libiberty/configure.ac b/libiberty/configure.ac
index 0748c592704..ba44fccef3f 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -578,7 +578,7 @@  AC_SUBST(CHECK)
 AC_SUBST(target_header_dir)
 
 case "${host}" in
-  *-*-cygwin* | *-*-mingw*)
+  *-*-cygwin* | *-*-msys* | *-*-mingw*)
     AC_DEFINE(HAVE_SYS_ERRLIST)
     AC_DEFINE(HAVE_SYS_NERR)
     ;;
diff --git a/libtool.m4 b/libtool.m4
index e36fdd3c0e2..8602498fc03 100644
--- a/libtool.m4
+++ b/libtool.m4
@@ -1523,7 +1523,7 @@  AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
     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,
@@ -1765,7 +1765,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -2236,14 +2236,14 @@  bsdi[[45]]*)
   # 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}`~
@@ -2264,6 +2264,12 @@  cygwin* | mingw* | pw32* | cegcc*)
     cygwin*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``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"])
+      ;;
+    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"])
       ;;
@@ -3047,7 +3053,7 @@  bsdi[[45]]*)
   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'
@@ -3344,7 +3350,7 @@  AC_DEFUN([LT_LIB_M],
 [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*)
@@ -3419,7 +3425,7 @@  case $host_os in
 aix*)
   symcode='[[BCDT]]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[[ABCDGISTW]]'
   ;;
 hpux*)
@@ -3666,7 +3672,7 @@  m4_if([$1], [CXX], [
     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
@@ -3979,7 +3985,7 @@  m4_if([$1], [CXX], [
       # 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
@@ -4062,7 +4068,7 @@  m4_if([$1], [CXX], [
       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], [],
@@ -4295,7 +4301,7 @@  m4_if([$1], [CXX], [
   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'
   ;;
   *)
@@ -4347,7 +4353,7 @@  dnl Note also adjust exclude_expsyms for C++ above.
   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++.
@@ -4462,7 +4468,7 @@  _LT_EOF
       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'
@@ -4835,7 +4841,7 @@  _LT_EOF
       _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
@@ -5779,7 +5785,7 @@  if test "$_lt_caught_CXX_error" != yes; then
         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 --git a/ltmain.sh b/ltmain.sh
index 70990740b6c..e8161587051 100644
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -976,7 +976,7 @@  func_enable_tag ()
 
 
   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 @@  func_mode_compile ()
 
     # 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 @@  func_mode_install ()
 	      '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 @@  func_mode_install ()
 
 	# 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 @@  func_mode_install ()
 	# 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 @@  extern \"C\" {
 	      $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 @@  extern \"C\" {
 	      $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 @@  typedef struct {
 } 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 @@  static const void *lt_preloaded_setup() {
 	# 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 ()
             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 @@  func_to_host_pathlist ()
 	      ( 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 @@  main (int argc, char *argv[])
 	{
 EOF
 	    case "$host" in
-	      *mingw* | *cygwin* )
+	      *mingw* | *cygwin* | *msys* )
 		# make stdout use "unix" line endings
 		echo "          setmode(1,_O_BINARY);"
 		;;
@@ -4233,7 +4233,7 @@  func_mode_link ()
 {
     $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 @@  func_mode_link ()
 	  ;;
 	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 @@  func_mode_link ()
       -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 @@  func_mode_link ()
 
       -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 @@  func_mode_link ()
 	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 @@  func_mode_link ()
 	    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 @@  func_mode_link ()
       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 @@  EOF
 
 	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 @@  EOF
 
     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 @@  EOF
 	  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 @@  EOF
         # 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 @@  EOF
 	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 @@  EOF
 	  # 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 --git a/ltoptions.m4 b/ltoptions.m4
index 5ef12ced2a8..5e7bc34702b 100644
--- a/ltoptions.m4
+++ b/ltoptions.m4
@@ -126,7 +126,7 @@  LT_OPTION_DEFINE([LT_INIT], [win32-dll],
 [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 --git a/opcodes/configure b/opcodes/configure
index a65b0a2f95b..1860d144c72 100755
--- a/opcodes/configure
+++ b/opcodes/configure
@@ -5588,7 +5588,7 @@  else
     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,
@@ -5930,7 +5930,7 @@  bsdi[45]*)
   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'
@@ -6546,7 +6546,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -8133,7 +8133,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -8215,7 +8215,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -8677,7 +8677,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -8792,7 +8792,7 @@  _LT_EOF
       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'
@@ -9223,7 +9223,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -10124,14 +10124,14 @@  bsdi[45]*)
   # 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}`~
@@ -10153,6 +10153,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -10805,7 +10811,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
@@ -12305,7 +12311,7 @@  $as_echo "$bfd_cv_ld_as_needed" >&6; }
 
 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*)
@@ -12481,6 +12487,10 @@  if test "$enable_shared" = "yes"; then
       SHARED_LDFLAGS="-no-undefined"
       SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
       ;;
+    *-*-msys*)
+      SHARED_LDFLAGS="-no-undefined"
+      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty -L`pwd`/../intl -lintl -lmsys-2.0"
+      ;;
     *)
       SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
       SHARED_DEPENDENCIES="../bfd/libbfd.la"
diff --git a/opcodes/configure.ac b/opcodes/configure.ac
index cae2a67ff10..33784fd5ce6 100644
--- a/opcodes/configure.ac
+++ b/opcodes/configure.ac
@@ -198,6 +198,10 @@  if test "$enable_shared" = "yes"; then
       SHARED_LDFLAGS="-no-undefined"
       SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
       ;;
+    *-*-msys*)
+      SHARED_LDFLAGS="-no-undefined"
+      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
+      ;;
     *)
       SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
       SHARED_DEPENDENCIES="../bfd/libbfd.la"
diff --git a/readline/readline/configure b/readline/readline/configure
index 6ea4545e26f..2aec06a0d99 100755
--- a/readline/readline/configure
+++ b/readline/readline/configure
@@ -2615,7 +2615,7 @@  fi
 CROSS_COMPILE=
 if test "x$cross_compiling" = "xyes"; then
     case "${host}" in
-    *-cygwin*)
+    *-cygwin* | *-msys*)
         cross_cache=${srcdir}/cross-build/cygwin.cache
         ;;
     *-mingw*)
diff --git a/readline/readline/configure.ac b/readline/readline/configure.ac
index 912c99b6575..4e9ee84b7a4 100644
--- a/readline/readline/configure.ac
+++ b/readline/readline/configure.ac
@@ -85,7 +85,7 @@  dnl build machine.
 CROSS_COMPILE=
 if test "x$cross_compiling" = "xyes"; then
     case "${host}" in
-    *-cygwin*)
+    *-cygwin* | *-msys*)
         cross_cache=${srcdir}/cross-build/cygwin.cache
         ;;
     *-mingw*)
diff --git a/readline/readline/support/config.guess b/readline/readline/support/config.guess
index cc7a8107011..85c30845c7c 100755
--- a/readline/readline/support/config.guess
+++ b/readline/readline/support/config.guess
@@ -918,6 +918,9 @@  EOF
     amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
 	echo x86_64-pc-cygwin
 	exit ;;
+    amd64:MSYS*:*:* | x86_64:MSYS*:*:*)
+	echo x86_64-pc-msys
+	exit ;;
     prep*:SunOS:5.*:*)
 	echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')"
 	exit ;;
diff --git a/readline/readline/support/config.rpath b/readline/readline/support/config.rpath
index fc5913d7878..54df9203647 100755
--- a/readline/readline/support/config.rpath
+++ b/readline/readline/support/config.rpath
@@ -57,7 +57,7 @@  else
     aix*)
       wl='-Wl,'
       ;;
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
       ;;
     hpux9* | hpux10* | hpux11*)
       wl='-Wl,'
@@ -149,7 +149,7 @@  hardcode_direct=no
 hardcode_minus_L=no
 
 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++.
@@ -198,7 +198,7 @@  if test "$with_gnu_ld" = yes; then
         ld_shlibs=no
       fi
       ;;
-    cygwin* | mingw* | pw32* | cegcc*)
+    cygwin* | msys* | mingw* | pw32* | cegcc*)
       # hardcode_libdir_flag_spec is actually meaningless, as there is
       # no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -348,7 +348,7 @@  else
       ;;
     bsdi[45]*)
       ;;
-    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
@@ -533,7 +533,7 @@  case "$host_os" in
   bsdi[45]*)
     library_names_spec='$libname$shrext'
     ;;
-  cygwin* | mingw* | pw32* | cegcc*)
+  cygwin* | msys* | mingw* | pw32* | cegcc*)
     shrext=.dll
     library_names_spec='$libname.dll.a $libname.lib'
     ;;
diff --git a/readline/readline/support/shlib-install b/readline/readline/support/shlib-install
index 661355d32b2..39d0fddb96e 100755
--- a/readline/readline/support/shlib-install
+++ b/readline/readline/support/shlib-install
@@ -75,7 +75,7 @@  hpux*|darwin*|macosx*|linux*|solaris2*)
 	if [ -z "$uninstall" ]; then
 		chmod 755 ${INSTALLDIR}/${LIBNAME}
 	fi ;;
-cygwin*|mingw*)
+cygwin*|msys*|mingw*)
 	IMPLIBNAME=`echo ${LIBNAME} \
 		| sed -e 's,^cyg,lib,' -e 's,[0-9]*.dll$,.dll.a,'`
 	if [ -z "$uninstall" ]; then
@@ -162,7 +162,7 @@  hpux1*)
 	fi
 	;;
 
-cygwin*|mingw*)
+cygwin*|msys*|mingw*)
 	# Links to .dlls don't work.  Hence shobj-conf used DLLVERSION.dll
 	# instead of so.SHLIB_MAJOR.SHLIB_MINOR.  The postinstall above
 	# took care of everything else.
diff --git a/readline/readline/support/shobj-conf b/readline/readline/support/shobj-conf
index 5a3f9776e91..595e92384f2 100755
--- a/readline/readline/support/shobj-conf
+++ b/readline/readline/support/shobj-conf
@@ -494,6 +494,24 @@  cygwin*)
 	fi
 	;;
 
+msys*)
+	SHOBJ_LD='$(CC)'
+	SHOBJ_LDFLAGS='-shared -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all -Wl,--out-implib=$(@).a'
+	SHLIB_LIBPREF='msys-'
+	SHLIB_LIBSUFF='dll'
+	SHLIB_LIBVERSION='$(SHLIB_DLLVERSION).$(SHLIB_LIBSUFF)'
+	SHLIB_LIBS='$(TERMCAP_LIB)'
+
+	SHLIB_DOT=
+	# For official cygwin releases, DLLVERSION will be defined in the
+	# environment of configure, and will be incremented any time the API
+	# changes in a non-backwards compatible manner.  Otherwise, it is just
+	# SHLIB_MAJOR.
+	if [ -n "$DLLVERSION" ] ; then
+		SHLIB_DLLVERSION="$DLLVERSION"
+	fi
+	;;
+
 mingw*)
 	SHOBJ_LD='$(CC)'
 	SHOBJ_LDFLAGS='-shared -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all -Wl,--out-implib=$(@).a'
diff --git a/sim/configure b/sim/configure
index de67d95d4ab..6ad777da0d3 100755
--- a/sim/configure
+++ b/sim/configure
@@ -6086,7 +6086,7 @@  else
     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,
@@ -6428,7 +6428,7 @@  bsdi[45]*)
   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'
@@ -7086,7 +7086,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -9349,7 +9349,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -9431,7 +9431,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -9893,7 +9893,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -10008,7 +10008,7 @@  _LT_EOF
       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'
@@ -10439,7 +10439,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -11340,14 +11340,14 @@  bsdi[45]*)
   # 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}`~
@@ -11369,6 +11369,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -12021,7 +12027,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;
diff --git a/zlib/configure b/zlib/configure
index 2d551360683..705b179bf8c 100755
--- a/zlib/configure
+++ b/zlib/configure
@@ -4931,7 +4931,7 @@  else
     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,
@@ -5273,7 +5273,7 @@  bsdi[45]*)
   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'
@@ -5889,7 +5889,7 @@  case $host_os in
 aix*)
   symcode='[BCDT]'
   ;;
-cygwin* | mingw* | pw32* | cegcc*)
+cygwin* | msys* | mingw* | pw32* | cegcc*)
   symcode='[ABCDGISTW]'
   ;;
 hpux*)
@@ -7780,7 +7780,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       # 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
@@ -7862,7 +7862,7 @@  $as_echo_n "checking for $compiler option to produce PIC... " >&6; }
       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'
@@ -8324,7 +8324,7 @@  $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   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++.
@@ -8439,7 +8439,7 @@  _LT_EOF
       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'
@@ -8876,7 +8876,7 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
       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
@@ -9780,14 +9780,14 @@  bsdi[45]*)
   # 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}`~
@@ -9809,6 +9809,12 @@  cygwin* | mingw* | pw32* | cegcc*)
       # Cygwin DLLs use 'cyg' prefix rather than 'lib'
       soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
 
+      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*)
@@ -10464,7 +10470,7 @@  else
     lt_cv_dlopen_libs=
     ;;
 
-  cygwin*)
+  cygwin* | msys*)
     lt_cv_dlopen="dlopen"
     lt_cv_dlopen_libs=
     ;;