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