  
              # Sun yellow pages. Some systems have the functions in libc.
              if (host_platform not in ['cygwin', 'qnx6'] and
-@@ -1445,7 +1479,10 @@
+@@ -1385,6 +1422,8 @@
+             curses_defines.append(('HAVE_NCURSESW', '1'))
+             if not cross_compiling:
+                 curses_includes.append('/usr/include/ncursesw')
++            else:
++                curses_includes += cross_incs
+             # Bug 1464056: If _curses.so links with ncursesw,
+             # _curses_panel.so must link with panelw.
+             panel_library = 'panelw'
+@@ -1403,8 +1442,9 @@
+ 
+         if curses_library.startswith('ncurses'):
+             curses_libs = [curses_library]
+-            exts.append( Extension('_curses', ['_cursesmodule.c'],
++            exts.append( Extension('_curses', ['Modules/_cursesmodule.c'],
+                                    include_dirs=curses_includes,
++                                   library_dirs=cross_libs,
+                                    define_macros=curses_defines,
+                                    libraries = curses_libs) )
+         elif curses_library == 'curses' and host_platform != 'darwin':
+@@ -1425,8 +1465,10 @@
+ 
+         # If the curses module is enabled, check for the panel module
+         if (module_enabled(exts, '_curses') and
+-            self.compiler.find_library_file(lib_dirs, panel_library)):
+-            exts.append( Extension('_curses_panel', ['_curses_panel.c'],
++            self.compiler.find_library_file(cross_libs, panel_library)):
++            exts.append( Extension('_curses_panel',
++                                   ['Modules/_curses_panel.c'],
++                                   library_dirs=cross_libs,
+                                    include_dirs=curses_includes,
+                                    define_macros=curses_defines,
+                                    libraries = [panel_library] + curses_libs) )
+@@ -1445,7 +1487,10 @@
          #
          # You can upgrade zlib to version 1.1.4 yourself by going to
          # http://www.gzip.org/zlib/

                              ]
 
             cc = sysconfig.get_config_var('CC').split()[0]
@@ -1567,7 +1604,7 @@
                               extra_compile_args = extra_compile_args,
                               include_dirs = expat_inc,
                               libraries = expat_lib,

                                libraries=math_libs) )
 
         # readline
-        do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
+        do_readline = self.compiler.find_library_file(cross_libs, 'readline')
         readline_termcap_library = ""
         curses_library = ""
         # Cannot use os.popen here in py3k.
@@ -776,11 +810,11 @@
         # use the same library for the readline and curses modules.
         if 'curses' in readline_termcap_library:
             curses_library = readline_termcap_library
-        elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
+        elif self.compiler.find_library_file(cross_libs, 'ncursesw'):
             curses_library = 'ncursesw'
-        elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
+        elif self.compiler.find_library_file(cross_libs, 'ncurses'):
             curses_library = 'ncurses'
-        elif self.compiler.find_library_file(lib_dirs, 'curses'):
+        elif self.compiler.find_library_file(cross_libs, 'curses'):
             curses_library = 'curses'
 
         if host_platform == 'darwin':
@@ -816,9 +850,10 @@
                                                      ['/usr/lib/termcap'],
                                                      'termcap'):
                 readline_libs.append('termcap')
-            exts.append( Extension('readline', ['readline.c'],
-                                   library_dirs=['/usr/lib/termcap'],
-                                   extra_link_args=readline_extra_link_args,
+            exts.append( Extension('readline', ['Modules/readline.c'],
+                                   include_dirs=cross_incs,
+                                   library_dirs=cross_libs,
+                                   # extra_link_args=readline_extra_link_args,
                                    libraries=readline_libs) )
         else:
             missing.append('readline')
@@ -829,19 +864,21 @@
             libs = ['crypt']
         else:
             libs = []
