Fixes recursion bug in disambiguate_in().
[ohcount] / python / mingw_setup.py
1 #=== mingw_setup.py by Phillip J. Eby
2 """Create pythonNN.def and libpythonNN.a in 'PythonNN/libs' directory
3
4 This script makes it possible to use the MinGW compiler tools to
5 build C extensions that work with the standard Windows Python
6 distribution.
7
8 Before running, you should have installed the MinGW compiler toolset,
9 and placed its 'bin' directory on your PATH.  An easy way to do this
10 is to install Cygwin's "binutils", "gcc", and "mingw-*" packages,
11 then run this script from the Cygwin shell.  (Be sure to use *Windows*
12 Python, not Cygwin python!)
13
14 Once this script has been run, you should be able to build extensions
15 using distutils in the standard way, as long as you select the
16 'mingw32' compiler, and the required tools are on your PATH.  See
17 the "Installing Python Modules" manual for more information on
18 selecting a compiler.
19 """
20
21
22 from distutils.spawn import find_executable
23 from distutils.sysconfig import get_config_var
24 from distutils import __file__ as distutils_file
25 import os, re, sys
26
27 if sys.platform=='cygwin':
28      print "Please run this script using Windows python,",
29      print "not Cygwin python.  E.g, try:"
30      print
31      print "/cygdrive/c/PythonNN/python", " ".join(sys.argv)
32      print
33      print "(where NN is the major/minor python version number)"
34      sys.exit()
35
36 basename = 'python%d%d' % sys.version_info[:2]
37
38 libs_dir = os.path.join(get_config_var('prefix'),'libs')
39 lib_file = os.path.join(libs_dir,basename+'.lib')
40 def_file = os.path.join(libs_dir,basename+'.def')
41 ming_lib = os.path.join(libs_dir,'lib%s.a' % basename)
42
43 distutils_cfg = os.path.join(os.path.dirname(distutils_file),'distutils.cfg')
44
45 export_match = re.compile(r"^_imp__(.*) in python\d+\.dll").match
46
47 nm      = find_executable('nm')
48 dlltool = find_executable('dlltool')
49
50 if not nm or not dlltool:
51      print "'nm' and/or 'dlltool' were not found;"
52      print "Please make sure they're on your PATH."
53      sys.exit()
54
55 nm_command = '%s -Cs %s' % (nm, lib_file)
56
57 print "Building", def_file, "using", nm_command
58 f = open(def_file,'w')
59 print >>f, "LIBRARY %s.dll" % basename
60 print >>f, "EXPORTS"
61
62
63 nm_pipe = os.popen(nm_command)
64 for line in nm_pipe.readlines():
65      m = export_match(line)
66      if m:
67          print >>f, m.group(1)
68 f.close()
69
70 exit = nm_pipe.close()
71 if exit:
72      print "nm exited with status", exit
73      print "Please check that", lib_file, "exists and is valid."
74      sys.exit()
75
76
77 print "Building",ming_lib,"using",dlltool
78 dlltool_pipe = os.popen(
79      "%s --dllname %s.dll --def %s --output-lib %s" %
80      (dlltool, basename, def_file, ming_lib)
81 )
82
83 dlltool_pipe.readlines()
84 exit = dlltool_pipe.close()
85 if exit:
86      print "dlltool exited with status", exit
87      print "Unable to proceed."
88      sys.exit()
89
90 print
91 print "Installation complete.  You may wish to add the following"
92 print "lines to", distutils_cfg, ':'
93 print
94 print "[build]"
95 print "compiler = mingw32"
96 print
97 print "This will make the distutils use MinGW as the default"
98 print "compiler, so that you don't need to configure this for"
99 print "every 'setup.py' you run."
100