blob: 44af3385d3de81288d39149546a202d8a44ca467 [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. Kuchlinga99202a2001-01-17 20:51:18 +000071 inc_dirs = ['/usr/include', '/usr/local/include'] + self.include_dirs
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000072 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
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +000086 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000087
88 # array objects
89 exts.append( Extension('array', ['arraymodule.c']) )
90 # complex math library functions
91 exts.append( Extension('cmath', ['cmathmodule.c'], libraries=['m']) )
92 # math library functions, e.g. sin()
93 exts.append( Extension('math', ['mathmodule.c'], libraries=['m']) )
94 # fast string operations implemented in C
95 exts.append( Extension('strop', ['stropmodule.c']) )
96 # time operations and variables
97 exts.append( Extension('time', ['timemodule.c'], libraries=['m']) )
98 # operator.add() and similar goodies
99 exts.append( Extension('operator', ['operator.c']) )
100 # access to the builtin codecs and codec registry
101 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
102 # static Unicode character database
103 exts.append( Extension('unicodedata', ['unicodedata.c', 'unicodedatabase.c']) )
104 # Unicode Character Name expansion hash table
105 exts.append( Extension('ucnhash', ['ucnhash.c']) )
106 # access to ISO C locale support
107 exts.append( Extension('_locale', ['_localemodule.c']) )
108
109 # Modules with some UNIX dependencies -- on by default:
110 # (If you have a really backward UNIX, select and socket may not be
111 # supported...)
112
113 # fcntl(2) and ioctl(2)
114 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
115 # pwd(3)
116 exts.append( Extension('pwd', ['pwdmodule.c']) )
117 # grp(3)
118 exts.append( Extension('grp', ['grpmodule.c']) )
119 # posix (UNIX) errno values
120 exts.append( Extension('errno', ['errnomodule.c']) )
121 # select(2); not on ancient System V
122 exts.append( Extension('select', ['selectmodule.c']) )
123
124 # The md5 module implements the RSA Data Security, Inc. MD5
125 # Message-Digest Algorithm, described in RFC 1321. The necessary files
126 # md5c.c and md5.h are included here.
127 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
128
129 # The sha module implements the SHA checksum algorithm.
130 # (NIST's Secure Hash Algorithm.)
131 exts.append( Extension('sha', ['shamodule.c']) )
132
133 # Tommy Burnette's 'new' module (creates new empty objects of certain kinds):
134 exts.append( Extension('new', ['newmodule.c']) )
135
136 # Helper module for various ascii-encoders
137 exts.append( Extension('binascii', ['binascii.c']) )
138
139 # Fred Drake's interface to the Python parser
140 exts.append( Extension('parser', ['parsermodule.c']) )
141
142 # Digital Creations' cStringIO and cPickle
143 exts.append( Extension('cStringIO', ['cStringIO.c']) )
144 exts.append( Extension('cPickle', ['cPickle.c']) )
145
146 # Memory-mapped files (also works on Win32).
147 exts.append( Extension('mmap', ['mmapmodule.c']) )
148
149 # Lance Ellinghaus's modules:
150 # enigma-inspired encryption
151 exts.append( Extension('rotor', ['rotormodule.c']) )
152 # syslog daemon interface
153 exts.append( Extension('syslog', ['syslogmodule.c']) )
154
155 # George Neville-Neil's timing module:
156 exts.append( Extension('timing', ['timingmodule.c']) )
157
158 #
159 # Here ends the simple stuff. From here on, modules need certain libraries,
160 # are platform-specific, or present other surprises.
161 #
162
163 # Multimedia modules
164 # These don't work for 64-bit platforms!!!
165 # These represent audio samples or images as strings:
166
167 # Disabled on 64-bit platforms
168 if sys.maxint != 9223372036854775807L:
169 # Operations on audio samples
170 exts.append( Extension('audioop', ['audioop.c']) )
171 # Operations on images
172 exts.append( Extension('imageop', ['imageop.c']) )
173 # Read SGI RGB image files (but coded portably)
174 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
175
176 # readline
Andrew M. Kuchling4f9e9432001-01-17 20:20:44 +0000177 if (self.compiler.find_library_file(lib_dirs, 'readline')):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000178 exts.append( Extension('readline', ['readline.c'],
179 libraries=['readline', 'termcap']) )
180
181 # The crypt module is now disabled by default because it breaks builds
182 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
183
184 if self.compiler.find_library_file(lib_dirs, 'crypt'):
185 libs = ['crypt']
186 else:
187 libs = []
188 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
189
190 # socket(2)
191 # Detect SSL support for the socket module
192 if (self.compiler.find_library_file(lib_dirs, 'ssl') and
193 self.compiler.find_library_file(lib_dirs, 'crypto') ):
194 exts.append( Extension('_socket', ['socketmodule.c'],
195 libraries = ['ssl', 'crypto'],
196 define_macros = [('USE_SSL',1)] ) )
197 else:
198 exts.append( Extension('_socket', ['socketmodule.c']) )
199
200 # Modules that provide persistent dictionary-like semantics. You will
201 # probably want to arrange for at least one of them to be available on
202 # your machine, though none are defined by default because of library
203 # dependencies. The Python module anydbm.py provides an
204 # implementation independent wrapper for these; dumbdbm.py provides
205 # similar functionality (but slower of course) implemented in Python.
206
207 # The standard Unix dbm module:
208 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
209 exts.append( Extension('dbm', ['dbmmodule.c'],
210 libraries = ['ndbm'] ) )
211 else:
212 exts.append( Extension('dbm', ['dbmmodule.c']) )
213
214 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
215 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
216 exts.append( Extension('gdbm', ['gdbmmodule.c'],
217 libraries = ['gdbm'] ) )
218
219 # Berkeley DB interface.
220 #
221 # This requires the Berkeley DB code, see
222 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
223 #
224 # Edit the variables DB and DBPORT to point to the db top directory
225 # and the subdirectory of PORT where you built it.
226 #
227 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
228 # BSD DB 3.x.)
229
230 # Note: If a db.h file is found by configure, bsddb will be enabled
231 # automatically via Setup.config.in. It only needs to be enabled here
232 # if it is not automatically enabled there; check the generated
233 # Setup.config before enabling it here.
234
235 if (self.compiler.find_library_file(lib_dirs, 'db') and
Andrew M. Kuchlinga99202a2001-01-17 20:51:18 +0000236 find_file(inc_dirs, 'db_185.h') ):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000237 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')):
Andrew M. Kuchlinga99202a2001-01-17 20:51:18 +0000343 defs = None
344 if find_file(inc_dirs, 'expat.h'):
345 defs = [('HAVE_EXPAT_H', 1)]
346 elif find_file(inc_dirs, 'xmlparse.h'):
347 defs = []
348 if defs is not None:
349 exts.append( Extension('pyexpat', ['pyexpat.c'],
350 define_macros = defs,
351 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000352
353 # Platform-specific libraries
354 plat = sys.platform
355 if plat == 'linux2':
356 # Linux-specific modules
357 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
358
359 if plat == 'sunos5':
360 # SunOS specific modules
361 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
362
363 # The _tkinter module.
364 #
365 # The command for _tkinter is long and site specific. Please
366 # uncomment and/or edit those parts as indicated. If you don't have a
367 # specific extension (e.g. Tix or BLT), leave the corresponding line
368 # commented out. (Leave the trailing backslashes in! If you
369 # experience strange errors, you may want to join all uncommented
370 # lines and remove the backslashes -- the backslash interpretation is
371 # done by the shell's "read" command and it may not be implemented on
372 # every system.
373
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000374 for version in ['8.4', '8.3', '8.2', '8.1', '8.0']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000375 tklib = self.compiler.find_library_file(lib_dirs,
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000376 'tk' + version )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000377 tcllib = self.compiler.find_library_file(lib_dirs,
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000378 'tcl' + version )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000379 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
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000398 debian_tcl_include = ( prefix + os.sep + 'include/tcl' +
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000399 version )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000400 debian_tk_include = ( prefix + os.sep + 'include/tk' +
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000401 version )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000402 if os.path.exists(debian_tcl_include):
403 include_dirs = [debian_tcl_include, debian_tk_include]
404 else:
405 # Fallback for non-Debian systems
406 include_dirs = [prefix + os.sep + 'include']
407
408 # Check for various platform-specific directories
409 if sys.platform == 'sunos5':
410 include_dirs.append('/usr/openwin/include')
411 added_lib_dirs.append('/usr/openwin/lib')
412 elif os.path.exists('/usr/X11R6/include'):
413 include_dirs.append('/usr/X11R6/include')
414 added_lib_dirs.append('/usr/X11R6/lib')
415 elif os.path.exists('/usr/X11R5/include'):
416 include_dirs.append('/usr/X11R5/include')
417 added_lib_dirs.append('/usr/X11R5/lib')
418 else:
419 # Assume default form
420 include_dirs.append('/usr/X11/include')
421 added_lib_dirs.append('/usr/X11/lib')
422
423 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'):
424 defs.append( ('WITH_TIX', 1) )
425 libs.append('tix4.1.8.0')
426
427 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
428 defs.append( ('WITH_BLT', 1) )
429 libs.append('BLT8.0')
430
431 if sys.platform in ['aix3', 'aix4']:
432 libs.append('ld')
433
434 # X11 libraries to link with:
435 libs.append('X11')
436
437 tklib, ext = os.path.splitext(tklib)
438 tcllib, ext = os.path.splitext(tcllib)
439 tklib = os.path.basename(tklib)
440 tcllib = os.path.basename(tcllib)
441 libs.append( tklib[3:] ) # Chop off 'lib' prefix
442 libs.append( tcllib[3:] )
443
444 exts.append( Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
445 define_macros=[('WITH_APPINIT', 1)] + defs,
446 include_dirs = include_dirs,
447 libraries = libs,
448 library_dirs = added_lib_dirs,
449 )
450 )
451 # XXX handle these
452 # *** Uncomment and edit for PIL (TkImaging) extension only:
453 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
454 # *** Uncomment and edit for TOGL extension only:
455 # -DWITH_TOGL togl.c \
456 # *** Uncomment these for TOGL extension only:
457 # -lGL -lGLU -lXext -lXmu \
458
459 self.extensions = exts
460
461def main():
462 setup(name = 'Python standard library',
463 version = '2.0',
464 cmdclass = {'build_ext':PyBuildExt},
465 # The struct module is defined here, because build_ext won't be
466 # called unless there's at least one extension module defined.
467 ext_modules=[Extension('struct', ['structmodule.c'])]
468 )
469
470# --install-platlib
471if __name__ == '__main__':
472 sysconfig.set_python_build()
473 main()
474