blob: 1ef5c5974bba9816b68b6948ae70431abba7bdc2 [file] [log] [blame]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001# To be fixed:
2# Implement --disable-modules setting
3# Don't install to site-packages, but to lib-dynload
4
5import sys, os, string, getopt
6from distutils import sysconfig
7from distutils.core import Extension, setup
8from distutils.command.build_ext import build_ext
9
10# This global variable is used to hold the list of modules to be disabled.
11disabled_module_list = []
12
13def find_file(path, filename):
14 for p in path:
15 fullpath = p + os.sep + filename
16 if os.path.exists(fullpath):
17 return fullpath
18 return None
19
20def module_enabled(extlist, modname):
21 """Returns whether the module 'modname' is present in the list
22 of extensions 'extlist'."""
23 extlist = [ext for ext in extlist if ext.name == modname]
24 return len(extlist)
25
26class PyBuildExt(build_ext):
27
28 def build_extensions(self):
29 from distutils.ccompiler import new_compiler
30 from distutils.sysconfig import customize_compiler
31
32 # Detect which modules should be compiled
33 self.detect_modules()
34
35 # Remove modules that are present on the disabled list
36 self.extensions = [ext for ext in self.extensions
37 if ext.name not in disabled_module_list]
38
39 # Fix up the autodetected modules, prefixing all the source files
40 # with Modules/ and adding Python's include directory to the path.
41 (srcdir,) = sysconfig.get_config_vars('srcdir')
42
43 #
44 moddir = os.path.join(os.getcwd(), 'Modules', srcdir)
45 moddir = os.path.normpath(moddir)
46 srcdir, tail = os.path.split(moddir)
47 srcdir = os.path.normpath(srcdir)
48 moddir = os.path.normpath(moddir)
49
50 for ext in self.extensions:
51 ext.sources = [ os.path.join(moddir, filename)
52 for filename in ext.sources ]
53 ext.include_dirs.append( '.' ) # to get config.h
54 ext.include_dirs.append( os.path.join(srcdir, './Include') )
55
56 # If the signal module is being compiled, remove the sigcheck.o and
57 # intrcheck.o object files from the archive.
58 if module_enabled(self.extensions, 'signal'):
59 print 'removing sigcheck.o intrcheck.o'
60 ar, library = sysconfig.get_config_vars('AR', 'LIBRARY')
61 cmd = '%s d Modules/%s sigcheck.o intrcheck.o' % (ar, library)
62# os.system(cmd)
63
64 build_ext.build_extensions(self)
65
66 def detect_modules(self):
67 # XXX this always gets an empty list -- hardwiring to
68 # a fixed list
69 lib_dirs = self.compiler.library_dirs[:]
70 lib_dirs += ['/lib', '/usr/lib', '/usr/local/lib']
71# std_lib_dirs = ['/lib', '/usr/lib']
72 exts = []
73
74 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
75
76 #
77 # The following modules are all pretty straightforward, and compile
78 # on pretty much any POSIXish platform.
79 #
80
81 # Some modules that are normally always on:
82 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
83 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
84 exts.append( Extension('signal', ['signalmodule.c']) )
85
86 # XXX uncomment this with 2.0CVS
87 #exts.append( Extension('xreadlines', ['xreadlines.c']) )
88
89 # array objects
90 exts.append( Extension('array', ['arraymodule.c']) )
91 # complex math library functions
92 exts.append( Extension('cmath', ['cmathmodule.c'], libraries=['m']) )
93 # math library functions, e.g. sin()
94 exts.append( Extension('math', ['mathmodule.c'], libraries=['m']) )
95 # fast string operations implemented in C
96 exts.append( Extension('strop', ['stropmodule.c']) )
97 # time operations and variables
98 exts.append( Extension('time', ['timemodule.c'], libraries=['m']) )
99 # operator.add() and similar goodies
100 exts.append( Extension('operator', ['operator.c']) )
101 # access to the builtin codecs and codec registry
102 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
103 # static Unicode character database
104 exts.append( Extension('unicodedata', ['unicodedata.c', 'unicodedatabase.c']) )
105 # Unicode Character Name expansion hash table
106 exts.append( Extension('ucnhash', ['ucnhash.c']) )
107 # access to ISO C locale support
108 exts.append( Extension('_locale', ['_localemodule.c']) )
109
110 # Modules with some UNIX dependencies -- on by default:
111 # (If you have a really backward UNIX, select and socket may not be
112 # supported...)
113
114 # fcntl(2) and ioctl(2)
115 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
116 # pwd(3)
117 exts.append( Extension('pwd', ['pwdmodule.c']) )
118 # grp(3)
119 exts.append( Extension('grp', ['grpmodule.c']) )
120 # posix (UNIX) errno values
121 exts.append( Extension('errno', ['errnomodule.c']) )
122 # select(2); not on ancient System V
123 exts.append( Extension('select', ['selectmodule.c']) )
124
125 # The md5 module implements the RSA Data Security, Inc. MD5
126 # Message-Digest Algorithm, described in RFC 1321. The necessary files
127 # md5c.c and md5.h are included here.
128 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
129
130 # The sha module implements the SHA checksum algorithm.
131 # (NIST's Secure Hash Algorithm.)
132 exts.append( Extension('sha', ['shamodule.c']) )
133
134 # Tommy Burnette's 'new' module (creates new empty objects of certain kinds):
135 exts.append( Extension('new', ['newmodule.c']) )
136
137 # Helper module for various ascii-encoders
138 exts.append( Extension('binascii', ['binascii.c']) )
139
140 # Fred Drake's interface to the Python parser
141 exts.append( Extension('parser', ['parsermodule.c']) )
142
143 # Digital Creations' cStringIO and cPickle
144 exts.append( Extension('cStringIO', ['cStringIO.c']) )
145 exts.append( Extension('cPickle', ['cPickle.c']) )
146
147 # Memory-mapped files (also works on Win32).
148 exts.append( Extension('mmap', ['mmapmodule.c']) )
149
150 # Lance Ellinghaus's modules:
151 # enigma-inspired encryption
152 exts.append( Extension('rotor', ['rotormodule.c']) )
153 # syslog daemon interface
154 exts.append( Extension('syslog', ['syslogmodule.c']) )
155
156 # George Neville-Neil's timing module:
157 exts.append( Extension('timing', ['timingmodule.c']) )
158
159 #
160 # Here ends the simple stuff. From here on, modules need certain libraries,
161 # are platform-specific, or present other surprises.
162 #
163
164 # Multimedia modules
165 # These don't work for 64-bit platforms!!!
166 # These represent audio samples or images as strings:
167
168 # Disabled on 64-bit platforms
169 if sys.maxint != 9223372036854775807L:
170 # Operations on audio samples
171 exts.append( Extension('audioop', ['audioop.c']) )
172 # Operations on images
173 exts.append( Extension('imageop', ['imageop.c']) )
174 # Read SGI RGB image files (but coded portably)
175 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
176
177 # readline
178 if (self.compiler.find_library_file(self.compiler.library_dirs, 'readline')):
179 exts.append( Extension('readline', ['readline.c'],
180 libraries=['readline', 'termcap']) )
181
182 # The crypt module is now disabled by default because it breaks builds
183 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
184
185 if self.compiler.find_library_file(lib_dirs, 'crypt'):
186 libs = ['crypt']
187 else:
188 libs = []
189 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
190
191 # socket(2)
192 # Detect SSL support for the socket module
193 if (self.compiler.find_library_file(lib_dirs, 'ssl') and
194 self.compiler.find_library_file(lib_dirs, 'crypto') ):
195 exts.append( Extension('_socket', ['socketmodule.c'],
196 libraries = ['ssl', 'crypto'],
197 define_macros = [('USE_SSL',1)] ) )
198 else:
199 exts.append( Extension('_socket', ['socketmodule.c']) )
200
201 # Modules that provide persistent dictionary-like semantics. You will
202 # probably want to arrange for at least one of them to be available on
203 # your machine, though none are defined by default because of library
204 # dependencies. The Python module anydbm.py provides an
205 # implementation independent wrapper for these; dumbdbm.py provides
206 # similar functionality (but slower of course) implemented in Python.
207
208 # The standard Unix dbm module:
209 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
210 exts.append( Extension('dbm', ['dbmmodule.c'],
211 libraries = ['ndbm'] ) )
212 else:
213 exts.append( Extension('dbm', ['dbmmodule.c']) )
214
215 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
216 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
217 exts.append( Extension('gdbm', ['gdbmmodule.c'],
218 libraries = ['gdbm'] ) )
219
220 # Berkeley DB interface.
221 #
222 # This requires the Berkeley DB code, see
223 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
224 #
225 # Edit the variables DB and DBPORT to point to the db top directory
226 # and the subdirectory of PORT where you built it.
227 #
228 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
229 # BSD DB 3.x.)
230
231 # Note: If a db.h file is found by configure, bsddb will be enabled
232 # automatically via Setup.config.in. It only needs to be enabled here
233 # if it is not automatically enabled there; check the generated
234 # Setup.config before enabling it here.
235
236 if (self.compiler.find_library_file(lib_dirs, 'db') and
237 find_file(['/usr/include', '/usr/local/include'] + self.include_dirs,
238 'db_185.h') ):
239 exts.append( Extension('bsddb', ['bsddbmodule.c'],
240 libraries = ['db'] ) )
241
242 # The mpz module interfaces to the GNU Multiple Precision library.
243 # You need to ftp the GNU MP library.
244 # This was originally written and tested against GMP 1.2 and 1.3.2.
245 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
246 # haven't tested it recently. For a more complete module,
247 # refer to pympz.sourceforge.net.
248
249 # A compatible MP library unencombered by the GPL also exists. It was
250 # posted to comp.sources.misc in volume 40 and is widely available from
251 # FTP archive sites. One URL for it is:
252 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
253
254 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
255 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
256 exts.append( Extension('mpz', ['mpzmodule.c'],
257 libraries = ['gmp'] ) )
258
259
260 # Unix-only modules
261 if sys.platform not in ['mac', 'win32']:
262 # Steen Lumholt's termios module
263 exts.append( Extension('termios', ['termios.c']) )
264 # Jeremy Hylton's rlimit interface
265 exts.append( Extension('resource', ['resource.c']) )
266
267 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
268 exts.append( Extension('nis', ['nismodule.c'],
269 libraries = ['nsl']) )
270
271 # Curses support, requring the System V version of curses, often
272 # provided by the ncurses library.
273 if sys.platform == 'sunos4':
274 include_dirs += ['/usr/5include']
275 lib_dirs += ['/usr/5lib']
276
277 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
278 curses_libs = ['ncurses']
279 exts.append( Extension('_curses', ['_cursesmodule.c'],
280 libraries = curses_libs) )
281 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
282 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
283 curses_libs = ['curses', 'terminfo']
284 else:
285 curses_libs = ['curses', 'termcap']
286
287 exts.append( Extension('_curses', ['_cursesmodule.c'],
288 libraries = curses_libs) )
289
290 # If the curses module is enabled, check for the panel module
291 if (os.path.exists('Modules/_curses_panel.c') and
292 module_enabled(exts, '_curses') and
293 self.compiler.find_library_file(lib_dirs, 'panel')):
294 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
295 libraries = ['panel'] + curses_libs) )
296
297
298
299 # Lee Busby's SIGFPE modules.
300 # The library to link fpectl with is platform specific.
301 # Choose *one* of the options below for fpectl:
302
303 if sys.platform == 'irix5':
304 # For SGI IRIX (tested on 5.3):
305 exts.append( Extension('fpectl', ['fpectlmodule.c'],
306 libraries=['fpe']) )
307 elif 0: # XXX
308 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
309 # (Without the compiler you don't have -lsunmath.)
310 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
311 pass
312 else:
313 # For other systems: see instructions in fpectlmodule.c.
314 #fpectl fpectlmodule.c ...
315 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
316
317
318 # Andrew Kuchling's zlib module.
319 # This require zlib 1.1.3 (or later).
320 # See http://www.cdrom.com/pub/infozip/zlib/
321 if (self.compiler.find_library_file(lib_dirs, 'z')):
322 exts.append( Extension('zlib', ['zlibmodule.c'],
323 libraries = ['z']) )
324
325 # Interface to the Expat XML parser
326 #
327 # Expat is written by James Clark and must be downloaded separately
328 # (see below). The pyexpat module was written by Paul Prescod after a
329 # prototype by Jack Jansen.
330 #
331 # The Expat dist includes Windows .lib and .dll files. Home page is at
332 # http://www.jclark.com/xml/expat.html, the current production release is
333 # always ftp://ftp.jclark.com/pub/xml/expat.zip.
334 #
335 # EXPAT_DIR, below, should point to the expat/ directory created by
336 # unpacking the Expat source distribution.
337 #
338 # Note: the expat build process doesn't yet build a libexpat.a; you can
339 # do this manually while we try convince the author to add it. To do so,
340 # cd to EXPAT_DIR, run "make" if you have not done so, then run:
341 #
342 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
343 #
344 if (self.compiler.find_library_file(lib_dirs, 'expat')):
345 exts.append( Extension('pyexpat', ['pyexpat.c'],
346 libraries = ['expat']) )
347
348 # Platform-specific libraries
349 plat = sys.platform
350 if plat == 'linux2':
351 # Linux-specific modules
352 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
353
354 if plat == 'sunos5':
355 # SunOS specific modules
356 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
357
358 # The _tkinter module.
359 #
360 # The command for _tkinter is long and site specific. Please
361 # uncomment and/or edit those parts as indicated. If you don't have a
362 # specific extension (e.g. Tix or BLT), leave the corresponding line
363 # commented out. (Leave the trailing backslashes in! If you
364 # experience strange errors, you may want to join all uncommented
365 # lines and remove the backslashes -- the backslash interpretation is
366 # done by the shell's "read" command and it may not be implemented on
367 # every system.
368
369 # XXX need to add the old 7.x/4.x unsynced version numbers here
370 for tcl_version, tk_version in [('8.4', '8.4'),
371 ('8.3', '8.3'),
372 ('8.2', '8.2'),
373 ('8.1', '8.1'),
374 ('8.0', '8.0')]:
375 tklib = self.compiler.find_library_file(lib_dirs,
376 'tk' + tk_version )
377 tcllib = self.compiler.find_library_file(lib_dirs,
378 'tcl' + tcl_version )
379 if tklib and tcllib:
380 # Exit the loop when we've found the Tcl/Tk libraries
381 break
382
383 if (tcllib and tklib):
384 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
385
386 # Determine the prefix where Tcl/Tk is installed by
387 # chopping off the 'lib' suffix.
388 prefix = os.path.dirname(tcllib)
389 L = string.split(prefix, os.sep)
390 if L[-1] == 'lib': del L[-1]
391 prefix = string.join(L, os.sep)
392
393 if prefix + os.sep + 'lib' not in lib_dirs:
394 added_lib_dirs.append( prefix + os.sep + 'lib')
395
396 # Check for the include files on Debian, where
397 # they're put in /usr/include/{tcl,tk}X.Y
398 # XXX currently untested
399 debian_tcl_include = ( prefix + os.sep + 'include/tcl' +
400 tcl_version )
401 debian_tk_include = ( prefix + os.sep + 'include/tk' +
402 tk_version )
403 if os.path.exists(debian_tcl_include):
404 include_dirs = [debian_tcl_include, debian_tk_include]
405 else:
406 # Fallback for non-Debian systems
407 include_dirs = [prefix + os.sep + 'include']
408
409 # Check for various platform-specific directories
410 if sys.platform == 'sunos5':
411 include_dirs.append('/usr/openwin/include')
412 added_lib_dirs.append('/usr/openwin/lib')
413 elif os.path.exists('/usr/X11R6/include'):
414 include_dirs.append('/usr/X11R6/include')
415 added_lib_dirs.append('/usr/X11R6/lib')
416 elif os.path.exists('/usr/X11R5/include'):
417 include_dirs.append('/usr/X11R5/include')
418 added_lib_dirs.append('/usr/X11R5/lib')
419 else:
420 # Assume default form
421 include_dirs.append('/usr/X11/include')
422 added_lib_dirs.append('/usr/X11/lib')
423
424 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'):
425 defs.append( ('WITH_TIX', 1) )
426 libs.append('tix4.1.8.0')
427
428 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
429 defs.append( ('WITH_BLT', 1) )
430 libs.append('BLT8.0')
431
432 if sys.platform in ['aix3', 'aix4']:
433 libs.append('ld')
434
435 # X11 libraries to link with:
436 libs.append('X11')
437
438 tklib, ext = os.path.splitext(tklib)
439 tcllib, ext = os.path.splitext(tcllib)
440 tklib = os.path.basename(tklib)
441 tcllib = os.path.basename(tcllib)
442 libs.append( tklib[3:] ) # Chop off 'lib' prefix
443 libs.append( tcllib[3:] )
444
445 exts.append( Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
446 define_macros=[('WITH_APPINIT', 1)] + defs,
447 include_dirs = include_dirs,
448 libraries = libs,
449 library_dirs = added_lib_dirs,
450 )
451 )
452 # XXX handle these
453 # *** Uncomment and edit for PIL (TkImaging) extension only:
454 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
455 # *** Uncomment and edit for TOGL extension only:
456 # -DWITH_TOGL togl.c \
457 # *** Uncomment these for TOGL extension only:
458 # -lGL -lGLU -lXext -lXmu \
459
460 self.extensions = exts
461
462def main():
463 setup(name = 'Python standard library',
464 version = '2.0',
465 cmdclass = {'build_ext':PyBuildExt},
466 # The struct module is defined here, because build_ext won't be
467 # called unless there's at least one extension module defined.
468 ext_modules=[Extension('struct', ['structmodule.c'])]
469 )
470
471# --install-platlib
472if __name__ == '__main__':
473 sysconfig.set_python_build()
474 main()
475