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