diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index 62506a6..f80230c 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -842,9 +842,9 @@ main (int argc, char **argv) {
     def library_filename(self, libname, lib_type='static',     # or 'shared'
                          strip_dir=0, output_dir=''):
         assert output_dir is not None
-        if lib_type not in ("static", "shared", "dylib", "xcode_stub"):
+        if lib_type not in ("static", "shared", "dylib", "xcode_stub", "import"):
             raise ValueError, ("""'lib_type' must be "static", "shared", """
-                               """"dylib", or "xcode_stub".""")
+                               """"dylib", "xcode_stub" or "import".""")
         fmt = getattr(self, lib_type + "_lib_format")
         ext = getattr(self, lib_type + "_lib_extension")
 
diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
index 4c35676..54f8356 100644
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -80,10 +80,12 @@ class UnixCCompiler(CCompiler):
     shared_lib_extension = ".so"
     dylib_lib_extension = ".dylib"
     xcode_stub_lib_extension = ".tbd"
-    static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
+    import_lib_extension = ".dll.a"
+    import_lib_format = static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
     xcode_stub_lib_format = dylib_lib_format
     if sys.platform == "cygwin":
         exe_extension = ".exe"
+        shared_lib_extension = ".dll"
 
     def preprocess(self, source,
                    output_file=None, macros=None, include_dirs=None,
@@ -249,6 +251,7 @@ class UnixCCompiler(CCompiler):
         dylib_f = self.library_filename(lib, lib_type='dylib')
         xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub')
         static_f = self.library_filename(lib, lib_type='static')
+        import_f = self.library_filename(lib, lib_type='import')
 
         if sys.platform == 'darwin':
             # On OSX users can specify an alternate SDK using
@@ -279,6 +282,7 @@ class UnixCCompiler(CCompiler):
 
 
         for dir in dirs:
+            implib = os.path.join(dir, import_f)
             shared = os.path.join(dir, shared_f)
             dylib = os.path.join(dir, dylib_f)
             static = os.path.join(dir, static_f)
@@ -297,7 +301,9 @@ class UnixCCompiler(CCompiler):
             # data to go on: GCC seems to prefer the shared library, so I'm
             # assuming that *all* Unix C compilers do.  And of course I'm
             # ignoring even GCC's "-static" option.  So sue me.
-            if os.path.exists(dylib):
+            if os.path.exists(implib):
+                return implib
+            elif os.path.exists(dylib):
                 return dylib
             elif os.path.exists(xcode_stub):
                 return xcode_stub
@@ -308,3 +314,22 @@ class UnixCCompiler(CCompiler):
 
         # Oops, didn't find it in *any* of 'dirs'
         return None
+
+    def implib_to_dll(self, dirs, implib, debug=0):
+        fp = os.popen("dlltool -I %s" % implib)
+        dlltool_output = fp.readlines()
+        ret = fp.close()
+
+        if ret is None or ret >> 8 == 0:
+            for ln in dlltool_output:
+                for dir in dirs:
+                    dll = os.path.join(dir, ln.rstrip('\n'))
+                    # We're second-guessing the linker here, with not much hard
+                    # data to go on: GCC seems to prefer the shared library, so I'm
+                    # assuming that *all* Unix C compilers do.  And of course I'm
+                    # ignoring even GCC's "-static" option.  So sue me.
+                    if os.path.exists(dll):
+                        return dll
+
+        # Oops, didn't find it in *any* of 'dirs'
+        return None
diff --git a/setup.py b/setup.py
index aa08ada..f41d200 100644
--- a/setup.py
+++ b/setup.py
@@ -726,8 +726,12 @@ class PyBuildExt(build_ext):
         do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
         readline_termcap_library = ""
         curses_library = ""
-        # Determine if readline is already linked against curses or tinfo.
+        # Determine if readline is linked against curses or tinfo.
         if do_readline and find_executable('ldd'):
+            # On Cygwin we have to find out which dll the implib point to
+            if host_platform == "cygwin" and find_executable('dlltool'):
+                do_readline = self.compiler.implib_to_dll(os.getenv('PATH').split(os.pathsep) + lib_dirs, do_readline)
+
             fp = os.popen("ldd %s" % do_readline)
             ldd_output = fp.readlines()
             ret = fp.close()
@@ -778,7 +782,10 @@ class PyBuildExt(build_ext):
 
             readline_libs = ['readline']
             if readline_termcap_library:
-                pass # Issue 7384: Already linked against curses or tinfo.
+                if host_platform != "cygwin":
+                    pass # Issue 7384: Already linked against curses or tinfo.
+                else:
+                    readline_libs.append(readline_termcap_library)
             elif curses_library:
                 readline_libs.append(curses_library)
             elif self.compiler.find_library_file(lib_dirs +
@@ -1370,6 +1377,8 @@ class PyBuildExt(build_ext):
                 # _curses_panel.so must link with panelw.
                 panel_library = 'panelw'
             curses_libs = [curses_library]
+            if readline_termcap_library == 'tinfo' and host_platform == "cygwin":
+                curses_libs.append(readline_termcap_library)
             curses_incs = find_file('curses.h', inc_dirs,
                                     [os.path.join(d, 'ncursesw') for d in inc_dirs])
             exts.append( Extension('_curses', ['_cursesmodule.c'],
