132132
133133# Build the mingw import library, libpythonXY.a
134134# This requires 'nm' and 'dlltool' executables on your PATH
135- def build_mingw_lib (lib_file , def_file , dll_file , mingw_lib ):
135+ def build_mingw_lib (dll_path , def_file , dll_file , mingw_lib ):
136136 warning = "WARNING: %s - libpythonXX.a not built"
137- nm = find_executable ('nm ' )
137+ gendef = find_executable ('gendef ' )
138138 dlltool = find_executable ('dlltool' )
139139
140- if not nm or not dlltool :
141- print warning % "nm and/or dlltool were not found"
140+ if not gendef or not dlltool :
141+ print warning % "gendef and/or dlltool were not found"
142142 return False
143143
144- nm_command = '%s -Cs %s' % (nm , lib_file )
144+ gendef_command = '%s - %s' % (gendef , dll_path )
145145 dlltool_command = "%s --dllname %s --def %s --output-lib %s" % \
146146 (dlltool , dll_file , def_file , mingw_lib )
147- export_match = re .compile (r"^_imp__(.*) in python\d+\.dll" ).match
147+ if msilib .Win64 :
148+ dlltool_command += " -m i386:x86-64"
149+ else :
150+ dlltool_command += " -m i386"
148151
149152 f = open (def_file ,'w' )
150- print >> f , "LIBRARY %s" % dll_file
151- print >> f , "EXPORTS"
152-
153- nm_pipe = os .popen (nm_command )
154- for line in nm_pipe .readlines ():
155- m = export_match (line )
156- if m :
157- print >> f , m .group (1 )
153+ gendef_pipe = os .popen (gendef_command )
154+ for line in gendef_pipe .readlines ():
155+ print >> f , line
158156 f .close ()
159- exit = nm_pipe .close ()
157+ exit = gendef_pipe .close ()
160158
161159 if exit :
162- print warning % "nm did not run successfully"
160+ print warning % "gendef did not run successfully"
163161 return False
164162
165163 if os .system (dlltool_command ) != 0 :
@@ -169,27 +167,28 @@ def build_mingw_lib(lib_file, def_file, dll_file, mingw_lib):
169167 return True
170168
171169# Target files (.def and .a) go in PCBuild directory
172- lib_file = os .path .join (srcdir , PCBUILD , "python%s%s.lib " % (major , minor ))
170+ dll_path = os .path .join (srcdir , PCBUILD , "python%s%s.dll " % (major , minor ))
173171def_file = os .path .join (srcdir , PCBUILD , "python%s%s.def" % (major , minor ))
174172dll_file = "python%s%s.dll" % (major , minor )
175173mingw_lib = os .path .join (srcdir , PCBUILD , "libpython%s%s.a" % (major , minor ))
176174
177- have_mingw = build_mingw_lib (lib_file , def_file , dll_file , mingw_lib )
178-
179175# Determine the target architecture
180176if os .system ("nmake /nologo /c /f msisupport.mak" ) != 0 :
181177 raise RuntimeError ("'nmake /f msisupport.mak' failed" )
182178dll_path = os .path .join (srcdir , PCBUILD , dll_file )
183179msilib .set_arch_from_file (dll_path )
184180if msilib .pe_type (dll_path ) != msilib .pe_type ("msisupport.dll" ):
185181 raise SystemError , "msisupport.dll for incorrect architecture"
182+
186183if msilib .Win64 :
187184 upgrade_code = upgrade_code_64
188185 # Bump the last digit of the code by one, so that 32-bit and 64-bit
189186 # releases get separate product codes
190187 digit = hex ((int (product_code [- 2 ],16 )+ 1 )% 16 )[- 1 ]
191188 product_code = product_code [:- 2 ] + digit + '}'
192189
190+ have_mingw = build_mingw_lib (dll_path , def_file , dll_file , mingw_lib )
191+
193192if testpackage :
194193 ext = 'px'
195194 testprefix = 'x'
0 commit comments