- Got rid of newmodule.c
[python/dscho.git] / setup.py
blob39997e4c2c16adf87033551d5923d2a85e8b319e
1 # Autodetecting setup.py script for building the Python extensions
4 __version__ = "$Revision$"
6 import sys, os, getopt, imp
7 from distutils import sysconfig
8 from distutils import text_file
9 from distutils.errors import *
10 from distutils.core import Extension, setup
11 from distutils.command.build_ext import build_ext
12 from distutils.command.install import install
14 # This global variable is used to hold the list of modules to be disabled.
15 disabled_module_list = []
17 def add_dir_to_list(dirlist, dir):
18 """Add the directory 'dir' to the list 'dirlist' (at the front) if
19 1) 'dir' is not already in 'dirlist'
20 2) 'dir' actually exists, and is a directory."""
21 if os.path.isdir(dir) and dir not in dirlist:
22 dirlist.insert(0, dir)
24 def find_file(filename, std_dirs, paths):
25 """Searches for the directory where a given file is located,
26 and returns a possibly-empty list of additional directories, or None
27 if the file couldn't be found at all.
29 'filename' is the name of a file, such as readline.h or libcrypto.a.
30 'std_dirs' is the list of standard system directories; if the
31 file is found in one of them, no additional directives are needed.
32 'paths' is a list of additional locations to check; if the file is
33 found in one of them, the resulting list will contain the directory.
34 """
36 # Check the standard locations
37 for dir in std_dirs:
38 f = os.path.join(dir, filename)
39 if os.path.exists(f): return []
41 # Check the additional directories
42 for dir in paths:
43 f = os.path.join(dir, filename)
44 if os.path.exists(f):
45 return [dir]
47 # Not found anywhere
48 return None
50 def find_library_file(compiler, libname, std_dirs, paths):
51 filename = compiler.library_filename(libname, lib_type='shared')
52 result = find_file(filename, std_dirs, paths)
53 if result is not None: return result
55 filename = compiler.library_filename(libname, lib_type='static')
56 result = find_file(filename, std_dirs, paths)
57 return result
59 def module_enabled(extlist, modname):
60 """Returns whether the module 'modname' is present in the list
61 of extensions 'extlist'."""
62 extlist = [ext for ext in extlist if ext.name == modname]
63 return len(extlist)
65 def find_module_file(module, dirlist):
66 """Find a module in a set of possible folders. If it is not found
67 return the unadorned filename"""
68 list = find_file(module, [], dirlist)
69 if not list:
70 return module
71 if len(list) > 1:
72 self.announce("WARNING: multiple copies of %s found"%module)
73 return os.path.join(list[0], module)
75 class PyBuildExt(build_ext):
77 def build_extensions(self):
79 # Detect which modules should be compiled
80 self.detect_modules()
82 # Remove modules that are present on the disabled list
83 self.extensions = [ext for ext in self.extensions
84 if ext.name not in disabled_module_list]
86 # Fix up the autodetected modules, prefixing all the source files
87 # with Modules/ and adding Python's include directory to the path.
88 (srcdir,) = sysconfig.get_config_vars('srcdir')
90 # Figure out the location of the source code for extension modules
91 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
92 moddir = os.path.normpath(moddir)
93 srcdir, tail = os.path.split(moddir)
94 srcdir = os.path.normpath(srcdir)
95 moddir = os.path.normpath(moddir)
97 moddirlist = [moddir]
98 incdirlist = ['./Include']
100 # Platform-dependent module source and include directories
101 platform = self.get_platform()
102 if platform == 'darwin':
103 # Mac OS X also includes some mac-specific modules
104 macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
105 moddirlist.append(macmoddir)
106 incdirlist.append('./Mac/Include')
108 alldirlist = moddirlist + incdirlist
110 # Fix up the paths for scripts, too
111 self.distribution.scripts = [os.path.join(srcdir, filename)
112 for filename in self.distribution.scripts]
114 for ext in self.extensions[:]:
115 ext.sources = [ find_module_file(filename, moddirlist)
116 for filename in ext.sources ]
117 if ext.depends is not None:
118 ext.depends = [find_module_file(filename, alldirlist)
119 for filename in ext.depends]
120 ext.include_dirs.append( '.' ) # to get config.h
121 for incdir in incdirlist:
122 ext.include_dirs.append( os.path.join(srcdir, incdir) )
124 # If a module has already been built statically,
125 # don't build it here
126 if ext.name in sys.builtin_module_names:
127 self.extensions.remove(ext)
129 # Parse Modules/Setup to figure out which modules are turned
130 # on in the file.
131 input = text_file.TextFile('Modules/Setup', join_lines=1)
132 remove_modules = []
133 while 1:
134 line = input.readline()
135 if not line: break
136 line = line.split()
137 remove_modules.append( line[0] )
138 input.close()
140 for ext in self.extensions[:]:
141 if ext.name in remove_modules:
142 self.extensions.remove(ext)
144 # When you run "make CC=altcc" or something similar, you really want
145 # those environment variables passed into the setup.py phase. Here's
146 # a small set of useful ones.
147 compiler = os.environ.get('CC')
148 linker_so = os.environ.get('LDSHARED')
149 args = {}
150 # unfortunately, distutils doesn't let us provide separate C and C++
151 # compilers
152 if compiler is not None:
153 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
154 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
155 if linker_so is not None:
156 args['linker_so'] = linker_so
157 self.compiler.set_executables(**args)
159 build_ext.build_extensions(self)
161 def build_extension(self, ext):
163 try:
164 build_ext.build_extension(self, ext)
165 except (CCompilerError, DistutilsError), why:
166 self.announce('WARNING: building of extension "%s" failed: %s' %
167 (ext.name, sys.exc_info()[1]))
168 return
169 # Workaround for Mac OS X: The Carbon-based modules cannot be
170 # reliably imported into a command-line Python
171 if 'Carbon' in ext.extra_link_args:
172 self.announce(
173 'WARNING: skipping import check for Carbon-based "%s"' %
174 ext.name)
175 return
176 # Workaround for Cygwin: Cygwin currently has fork issues when many
177 # modules have been imported
178 if self.get_platform() == 'cygwin':
179 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
180 % ext.name)
181 return
182 ext_filename = os.path.join(
183 self.build_lib,
184 self.get_ext_filename(self.get_ext_fullname(ext.name)))
185 try:
186 imp.load_dynamic(ext.name, ext_filename)
187 except ImportError, why:
189 if 1:
190 self.announce('*** WARNING: renaming "%s" since importing it'
191 ' failed: %s' % (ext.name, why))
192 assert not self.inplace
193 basename, tail = os.path.splitext(ext_filename)
194 newname = basename + "_failed" + tail
195 if os.path.exists(newname): os.remove(newname)
196 os.rename(ext_filename, newname)
198 # XXX -- This relies on a Vile HACK in
199 # distutils.command.build_ext.build_extension(). The
200 # _built_objects attribute is stored there strictly for
201 # use here.
202 # If there is a failure, _built_objects may not be there,
203 # so catch the AttributeError and move on.
204 try:
205 for filename in self._built_objects:
206 os.remove(filename)
207 except AttributeError:
208 self.announce('unable to remove files (ignored)')
209 else:
210 self.announce('*** WARNING: importing extension "%s" '
211 'failed: %s' % (ext.name, why))
213 def get_platform (self):
214 # Get value of sys.platform
215 platform = sys.platform
216 if platform[:6] =='cygwin':
217 platform = 'cygwin'
218 elif platform[:4] =='beos':
219 platform = 'beos'
220 elif platform[:6] == 'darwin':
221 platform = 'darwin'
222 elif platform[:6] == 'atheos':
223 platform = 'atheos'
225 return platform
227 def detect_modules(self):
228 # Ensure that /usr/local is always used
229 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
230 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
232 add_dir_to_list(self.compiler.library_dirs,
233 sysconfig.get_config_var("LIBDIR"))
234 add_dir_to_list(self.compiler.include_dirs,
235 sysconfig.get_config_var("INCLUDEDIR"))
237 try:
238 have_unicode = unicode
239 except NameError:
240 have_unicode = 0
242 # lib_dirs and inc_dirs are used to search for files;
243 # if a file is found in one of those directories, it can
244 # be assumed that no additional -I,-L directives are needed.
245 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
246 inc_dirs = self.compiler.include_dirs + ['/usr/include']
247 exts = []
249 platform = self.get_platform()
250 (srcdir,) = sysconfig.get_config_vars('srcdir')
252 # Check for AtheOS which has libraries in non-standard locations
253 if platform == 'atheos':
254 lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
255 lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
256 inc_dirs += ['/system/include', '/atheos/autolnk/include']
257 inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
259 # Check for MacOS X, which doesn't need libm.a at all
260 math_libs = ['m']
261 if platform in ['darwin', 'beos']:
262 math_libs = []
264 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
267 # The following modules are all pretty straightforward, and compile
268 # on pretty much any POSIXish platform.
271 # Some modules that are normally always on:
272 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
273 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
275 exts.append( Extension('_hotshot', ['_hotshot.c']) )
276 exts.append( Extension('_weakref', ['_weakref.c']) )
277 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
279 # array objects
280 exts.append( Extension('array', ['arraymodule.c']) )
281 # complex math library functions
282 exts.append( Extension('cmath', ['cmathmodule.c'],
283 libraries=math_libs) )
285 # math library functions, e.g. sin()
286 exts.append( Extension('math', ['mathmodule.c'],
287 libraries=math_libs) )
288 # fast string operations implemented in C
289 exts.append( Extension('strop', ['stropmodule.c']) )
290 # time operations and variables
291 exts.append( Extension('time', ['timemodule.c'],
292 libraries=math_libs) )
293 # operator.add() and similar goodies
294 exts.append( Extension('operator', ['operator.c']) )
295 # access to the builtin codecs and codec registry
296 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
297 # Python C API test module
298 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
299 # static Unicode character database
300 if have_unicode:
301 exts.append( Extension('unicodedata', ['unicodedata.c']) )
302 # access to ISO C locale support
303 exts.append( Extension('_locale', ['_localemodule.c']) )
305 # Modules with some UNIX dependencies -- on by default:
306 # (If you have a really backward UNIX, select and socket may not be
307 # supported...)
309 # fcntl(2) and ioctl(2)
310 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
311 # pwd(3)
312 exts.append( Extension('pwd', ['pwdmodule.c']) )
313 # grp(3)
314 exts.append( Extension('grp', ['grpmodule.c']) )
315 # posix (UNIX) errno values
316 exts.append( Extension('errno', ['errnomodule.c']) )
317 # select(2); not on ancient System V
318 exts.append( Extension('select', ['selectmodule.c']) )
320 # The md5 module implements the RSA Data Security, Inc. MD5
321 # Message-Digest Algorithm, described in RFC 1321. The
322 # necessary files md5c.c and md5.h are included here.
323 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
325 # The sha module implements the SHA checksum algorithm.
326 # (NIST's Secure Hash Algorithm.)
327 exts.append( Extension('sha', ['shamodule.c']) )
329 # Helper module for various ascii-encoders
330 exts.append( Extension('binascii', ['binascii.c']) )
332 # Fred Drake's interface to the Python parser
333 exts.append( Extension('parser', ['parsermodule.c']) )
335 # cStringIO and cPickle
336 exts.append( Extension('cStringIO', ['cStringIO.c']) )
337 exts.append( Extension('cPickle', ['cPickle.c']) )
339 # Memory-mapped files (also works on Win32).
340 if platform not in ['atheos']:
341 exts.append( Extension('mmap', ['mmapmodule.c']) )
343 # Lance Ellinghaus's modules:
344 # enigma-inspired encryption
345 exts.append( Extension('rotor', ['rotormodule.c']) )
346 # syslog daemon interface
347 exts.append( Extension('syslog', ['syslogmodule.c']) )
349 # George Neville-Neil's timing module:
350 exts.append( Extension('timing', ['timingmodule.c']) )
353 # Here ends the simple stuff. From here on, modules need certain
354 # libraries, are platform-specific, or present other surprises.
357 # Multimedia modules
358 # These don't work for 64-bit platforms!!!
359 # These represent audio samples or images as strings:
361 # Disabled on 64-bit platforms
362 if sys.maxint != 9223372036854775807L:
363 # Operations on audio samples
364 exts.append( Extension('audioop', ['audioop.c']) )
365 # Operations on images
366 exts.append( Extension('imageop', ['imageop.c']) )
367 # Read SGI RGB image files (but coded portably)
368 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
370 # readline
371 if self.compiler.find_library_file(lib_dirs, 'readline'):
372 readline_libs = ['readline']
373 if self.compiler.find_library_file(lib_dirs,
374 'ncurses'):
375 readline_libs.append('ncurses')
376 elif self.compiler.find_library_file(lib_dirs +
377 ['/usr/lib/termcap'],
378 'termcap'):
379 readline_libs.append('termcap')
380 exts.append( Extension('readline', ['readline.c'],
381 library_dirs=['/usr/lib/termcap'],
382 libraries=readline_libs) )
384 # crypt module.
386 if self.compiler.find_library_file(lib_dirs, 'crypt'):
387 libs = ['crypt']
388 else:
389 libs = []
390 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
392 # socket(2)
393 exts.append( Extension('_socket', ['socketmodule.c'],
394 depends = ['socketmodule.h']) )
395 # Detect SSL support for the socket module (via _ssl)
396 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
397 ['/usr/local/ssl/include',
398 '/usr/contrib/ssl/include/'
401 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
402 ['/usr/local/ssl/lib',
403 '/usr/contrib/ssl/lib/'
406 if (ssl_incs is not None and
407 ssl_libs is not None):
408 exts.append( Extension('_ssl', ['_ssl.c'],
409 include_dirs = ssl_incs,
410 library_dirs = ssl_libs,
411 libraries = ['ssl', 'crypto'],
412 depends = ['socketmodule.h']), )
414 # Modules that provide persistent dictionary-like semantics. You will
415 # probably want to arrange for at least one of them to be available on
416 # your machine, though none are defined by default because of library
417 # dependencies. The Python module anydbm.py provides an
418 # implementation independent wrapper for these; dumbdbm.py provides
419 # similar functionality (but slower of course) implemented in Python.
421 # Berkeley DB interface.
423 # This requires the Berkeley DB code, see
424 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
426 # (See http://pybsddb.sourceforge.net/ for an interface to
427 # Berkeley DB 3.x.)
429 # when sorted in reverse order, keys for this dict must appear in the
430 # order you wish to search - e.g., search for db3 before db2, db2
431 # before db1
432 db_try_this = {
433 'db4': {'libs': ('db-4.3', 'db-4.2', 'db-4.1', 'db-4.0'),
434 'libdirs': ('/usr/local/BerkeleyDB.4.3/lib',
435 '/usr/local/BerkeleyDB.4.2/lib',
436 '/usr/local/BerkeleyDB.4.1/lib',
437 '/usr/local/BerkeleyDB.4.0/lib',
438 '/usr/lib',
439 '/opt/sfw',
440 '/sw/lib',
441 '/lib',
443 'incdirs': ('/usr/local/BerkeleyDB.4.3/include',
444 '/usr/local/BerkeleyDB.4.2/include',
445 '/usr/local/BerkeleyDB.4.1/include',
446 '/usr/local/BerkeleyDB.4.0/include',
447 '/usr/include/db3',
448 '/opt/sfw/include/db3',
449 '/sw/include/db3',
450 '/usr/local/include/db3',
452 'incs': ('db_185.h',)},
453 'db3': {'libs': ('db-3.3', 'db-3.2', 'db-3.1', 'db-3.0'),
454 'libdirs': ('/usr/local/BerkeleyDB.3.3/lib',
455 '/usr/local/BerkeleyDB.3.2/lib',
456 '/usr/local/BerkeleyDB.3.1/lib',
457 '/usr/local/BerkeleyDB.3.0/lib',
458 '/usr/lib',
459 '/opt/sfw',
460 '/sw/lib',
461 '/lib',
463 'incdirs': ('/usr/local/BerkeleyDB.3.3/include',
464 '/usr/local/BerkeleyDB.3.2/include',
465 '/usr/local/BerkeleyDB.3.1/include',
466 '/usr/local/BerkeleyDB.3.0/include',
467 '/usr/include/db3',
468 '/opt/sfw/include/db3',
469 '/sw/include/db3',
470 '/usr/local/include/db3',
472 'incs': ('db_185.h',)},
473 'db2': {'libs': ('db2',),
474 'libdirs': ('/usr/lib', '/sw/lib', '/lib'),
475 'incdirs': ('/usr/include/db2',
476 '/usr/local/include/db2', '/sw/include/db2'),
477 'incs': ('db_185.h',)},
478 # if you are willing to risk hash db file corruption you can
479 # uncomment the lines below for db1. Note that this will affect
480 # not only the bsddb module, but the dbhash and anydbm modules
481 # as well. you have been warned!!!
482 ##'db1': {'libs': ('db1', 'db'),
483 ## 'libdirs': ('/usr/lib', '/sw/lib', '/lib'),
484 ## 'incdirs': ('/usr/include/db1', '/usr/local/include/db1',
485 ## '/usr/include', '/usr/local/include'),
486 ## 'incs': ('db.h',)},
489 # override this list to affect the library version search order
490 # for example, if you want to force version 2 to be used:
491 # db_search_order = ["db2"]
492 db_search_order = db_try_this.keys()
493 db_search_order.sort()
494 db_search_order.reverse()
496 find_lib_file = self.compiler.find_library_file
497 class found(Exception): pass
498 try:
499 for dbkey in db_search_order:
500 dbd = db_try_this[dbkey]
501 for dblib in dbd['libs']:
502 for dbinc in dbd['incs']:
503 db_incs = find_file(dbinc, [], dbd['incdirs'])
504 dblib_dir = find_lib_file(dbd['libdirs'], dblib)
505 if db_incs and dblib_dir:
506 dblib_dir = os.path.dirname(dblib_dir)
507 dblibs = [dblib]
508 raise found
509 except found:
510 if dbinc == 'db_185.h':
511 exts.append(Extension('bsddb', ['bsddbmodule.c'],
512 library_dirs=[dblib_dir],
513 include_dirs=db_incs,
514 define_macros=[('HAVE_DB_185_H',1)],
515 libraries=[dblib]))
516 else:
517 exts.append(Extension('bsddb', ['bsddbmodule.c'],
518 library_dirs=[dblib_dir],
519 include_dirs=db_incs,
520 libraries=[dblib]))
521 else:
522 db_incs = None
523 dblibs = []
524 dblib_dir = None
526 # The standard Unix dbm module:
527 if platform not in ['cygwin']:
528 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
529 exts.append( Extension('dbm', ['dbmmodule.c'],
530 libraries = ['ndbm'] ) )
531 elif self.compiler.find_library_file(lib_dirs, 'gdbm'):
532 exts.append( Extension('dbm', ['dbmmodule.c'],
533 libraries = ['gdbm'] ) )
534 elif db_incs is not None:
535 exts.append( Extension('dbm', ['dbmmodule.c'],
536 library_dirs=dblib_dir,
537 include_dirs=db_incs,
538 libraries=dblibs))
539 else:
540 exts.append( Extension('dbm', ['dbmmodule.c']) )
542 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
543 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
544 exts.append( Extension('gdbm', ['gdbmmodule.c'],
545 libraries = ['gdbm'] ) )
547 # The mpz module interfaces to the GNU Multiple Precision library.
548 # You need to ftp the GNU MP library.
549 # This was originally written and tested against GMP 1.2 and 1.3.2.
550 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
551 # haven't tested it recently, and it definitely doesn't work with
552 # GMP 4.0. For more complete modules, refer to
553 # http://gmpy.sourceforge.net and
554 # http://www.egenix.com/files/python/mxNumber.html
556 # A compatible MP library unencumbered by the GPL also exists. It was
557 # posted to comp.sources.misc in volume 40 and is widely available from
558 # FTP archive sites. One URL for it is:
559 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
561 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
562 exts.append( Extension('mpz', ['mpzmodule.c'],
563 libraries = ['gmp'] ) )
566 # Unix-only modules
567 if platform not in ['mac', 'win32']:
568 # Steen Lumholt's termios module
569 exts.append( Extension('termios', ['termios.c']) )
570 # Jeremy Hylton's rlimit interface
571 if platform not in ['atheos']:
572 exts.append( Extension('resource', ['resource.c']) )
574 # Sun yellow pages. Some systems have the functions in libc.
575 if platform not in ['cygwin', 'atheos']:
576 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
577 libs = ['nsl']
578 else:
579 libs = []
580 exts.append( Extension('nis', ['nismodule.c'],
581 libraries = libs) )
583 # Curses support, requring the System V version of curses, often
584 # provided by the ncurses library.
585 if platform == 'sunos4':
586 inc_dirs += ['/usr/5include']
587 lib_dirs += ['/usr/5lib']
589 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
590 curses_libs = ['ncurses']
591 exts.append( Extension('_curses', ['_cursesmodule.c'],
592 libraries = curses_libs) )
593 elif (self.compiler.find_library_file(lib_dirs, 'curses')
594 and platform != 'darwin'):
595 # OSX has an old Berkeley curses, not good enough for
596 # the _curses module.
597 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
598 curses_libs = ['curses', 'terminfo']
599 else:
600 curses_libs = ['curses', 'termcap']
602 exts.append( Extension('_curses', ['_cursesmodule.c'],
603 libraries = curses_libs) )
605 # If the curses module is enabled, check for the panel module
606 if (module_enabled(exts, '_curses') and
607 self.compiler.find_library_file(lib_dirs, 'panel')):
608 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
609 libraries = ['panel'] + curses_libs) )
613 # Lee Busby's SIGFPE modules.
614 # The library to link fpectl with is platform specific.
615 # Choose *one* of the options below for fpectl:
617 if platform == 'irix5':
618 # For SGI IRIX (tested on 5.3):
619 exts.append( Extension('fpectl', ['fpectlmodule.c'],
620 libraries=['fpe']) )
621 elif 0: # XXX how to detect SunPro?
622 # For Solaris with SunPro compiler (tested on Solaris 2.5
623 # with SunPro C 4.2): (Without the compiler you don't have
624 # -lsunmath.)
625 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
626 pass
627 else:
628 # For other systems: see instructions in fpectlmodule.c.
629 #fpectl fpectlmodule.c ...
630 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
633 # Andrew Kuchling's zlib module.
634 # This require zlib 1.1.3 (or later).
635 # See http://www.cdrom.com/pub/infozip/zlib/
636 zlib_inc = find_file('zlib.h', [], inc_dirs)
637 if zlib_inc is not None:
638 zlib_h = zlib_inc[0] + '/zlib.h'
639 version = '"0.0.0"'
640 version_req = '"1.1.3"'
641 fp = open(zlib_h)
642 while 1:
643 line = fp.readline()
644 if not line:
645 break
646 if line.find('#define ZLIB_VERSION', 0) == 0:
647 version = line.split()[2]
648 break
649 if version >= version_req:
650 if (self.compiler.find_library_file(lib_dirs, 'z')):
651 exts.append( Extension('zlib', ['zlibmodule.c'],
652 libraries = ['z']) )
654 # Interface to the Expat XML parser
656 # Expat was written by James Clark and is now maintained by a
657 # group of developers on SourceForge; see www.libexpat.org for
658 # more information. The pyexpat module was written by Paul
659 # Prescod after a prototype by Jack Jansen. Source of Expat
660 # 1.95.2 is included in Modules/expat/. Usage of a system
661 # shared libexpat.so/expat.dll is not advised.
663 # More information on Expat can be found at www.libexpat.org.
665 if sys.byteorder == "little":
666 xmlbo = "12"
667 else:
668 xmlbo = "21"
669 expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
670 exts.append(Extension('pyexpat',
671 sources = [
672 'pyexpat.c',
673 'expat/xmlparse.c',
674 'expat/xmlrole.c',
675 'expat/xmltok.c',
677 define_macros = [
678 ('HAVE_EXPAT_H',None),
679 ('XML_NS', '1'),
680 ('XML_DTD', '1'),
681 ('XML_BYTE_ORDER', xmlbo),
682 ('XML_CONTEXT_BYTES','1024'),
684 include_dirs = [expatinc]
687 # Dynamic loading module
688 dl_inc = find_file('dlfcn.h', [], inc_dirs)
689 if (dl_inc is not None) and (platform not in ['atheos']):
690 exts.append( Extension('dl', ['dlmodule.c']) )
692 # Platform-specific libraries
693 if platform == 'linux2':
694 # Linux-specific modules
695 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
697 if platform == 'sunos5':
698 # SunOS specific modules
699 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
701 if platform == 'darwin':
702 # Mac OS X specific modules. These are ported over from MacPython
703 # and still experimental. Some (such as gestalt or icglue) are
704 # already generally useful, some (the GUI ones) really need to
705 # be used from a framework.
707 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
708 # available here. This Makefile variable is also what the install
709 # procedure triggers on.
710 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
711 exts.append( Extension('gestalt', ['gestaltmodule.c'],
712 extra_link_args=['-framework', 'Carbon']) )
713 exts.append( Extension('MacOS', ['macosmodule.c'],
714 extra_link_args=['-framework', 'Carbon']) )
715 exts.append( Extension('icglue', ['icgluemodule.c'],
716 extra_link_args=['-framework', 'Carbon']) )
717 exts.append( Extension('macfs',
718 ['macfsmodule.c',
719 '../Python/getapplbycreator.c'],
720 extra_link_args=['-framework', 'Carbon']) )
721 exts.append( Extension('_CF', ['cf/_CFmodule.c'],
722 extra_link_args=['-framework', 'CoreFoundation']) )
723 exts.append( Extension('_Res', ['res/_Resmodule.c'],
724 extra_link_args=['-framework', 'Carbon']) )
725 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
726 extra_link_args=['-framework', 'Carbon']) )
727 if frameworkdir:
728 exts.append( Extension('Nav', ['Nav.c'],
729 extra_link_args=['-framework', 'Carbon']) )
730 exts.append( Extension('_AE', ['ae/_AEmodule.c'],
731 extra_link_args=['-framework', 'Carbon']) )
732 exts.append( Extension('_App', ['app/_Appmodule.c'],
733 extra_link_args=['-framework', 'Carbon']) )
734 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
735 extra_link_args=['-framework', 'Carbon']) )
736 exts.append( Extension('_CG', ['cg/_CGmodule.c'],
737 extra_link_args=['-framework', 'ApplicationServices',
738 '-framework', 'Carbon']) )
739 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
740 extra_link_args=['-framework', 'Carbon']) )
741 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
742 extra_link_args=['-framework', 'Carbon']) )
743 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
744 extra_link_args=['-framework', 'Carbon']) )
745 exts.append( Extension('_Drag', ['drag/_Dragmodule.c'],
746 extra_link_args=['-framework', 'Carbon']) )
747 exts.append( Extension('_Evt', ['evt/_Evtmodule.c'],
748 extra_link_args=['-framework', 'Carbon']) )
749 exts.append( Extension('_Fm', ['fm/_Fmmodule.c'],
750 extra_link_args=['-framework', 'Carbon']) )
751 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
752 extra_link_args=['-framework', 'Carbon']) )
753 exts.append( Extension('_List', ['list/_Listmodule.c'],
754 extra_link_args=['-framework', 'Carbon']) )
755 exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
756 extra_link_args=['-framework', 'Carbon']) )
757 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
758 extra_link_args=['-framework', 'Carbon']) )
759 exts.append( Extension('_Qd', ['qd/_Qdmodule.c'],
760 extra_link_args=['-framework', 'Carbon']) )
761 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
762 extra_link_args=['-framework', 'Carbon']) )
763 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
764 extra_link_args=['-framework', 'QuickTime',
765 '-framework', 'Carbon']) )
766 exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
767 extra_link_args=['-framework', 'Carbon']) )
768 exts.append( Extension('_TE', ['te/_TEmodule.c'],
769 extra_link_args=['-framework', 'Carbon']) )
770 # As there is no standardized place (yet) to put user-installed
771 # Mac libraries on OSX you should put a symlink to your Waste
772 # installation in the same folder as your python source tree.
773 # Or modify the next two lines:-)
774 waste_incs = find_file("WASTE.h", [], ["../waste/C_C++ Headers"])
775 waste_libs = find_library_file(self.compiler, "WASTE", [],
776 ["../waste/Static Libraries"])
777 if waste_incs != None and waste_libs != None:
778 exts.append( Extension('waste',
779 ['waste/wastemodule.c',
780 'Mac/Wastemods/WEObjectHandlers.c',
781 'Mac/Wastemods/WETabHooks.c',
782 'Mac/Wastemods/WETabs.c'
784 include_dirs = waste_incs + ['Mac/Wastemods'],
785 library_dirs = waste_libs,
786 libraries = ['WASTE'],
787 extra_link_args = ['-framework', 'Carbon'],
789 exts.append( Extension('_Win', ['win/_Winmodule.c'],
790 extra_link_args=['-framework', 'Carbon']) )
792 self.extensions.extend(exts)
794 # Call the method for detecting whether _tkinter can be compiled
795 self.detect_tkinter(inc_dirs, lib_dirs)
798 def detect_tkinter(self, inc_dirs, lib_dirs):
799 # The _tkinter module.
801 # Assume we haven't found any of the libraries or include files
802 # The versions with dots are used on Unix, and the versions without
803 # dots on Windows, for detection by cygwin.
804 tcllib = tklib = tcl_includes = tk_includes = None
805 for version in ['8.4', '84', '8.3', '83', '8.2',
806 '82', '8.1', '81', '8.0', '80']:
807 tklib = self.compiler.find_library_file(lib_dirs,
808 'tk' + version )
809 tcllib = self.compiler.find_library_file(lib_dirs,
810 'tcl' + version )
811 if tklib and tcllib:
812 # Exit the loop when we've found the Tcl/Tk libraries
813 break
815 # Now check for the header files
816 if tklib and tcllib:
817 # Check for the include files on Debian, where
818 # they're put in /usr/include/{tcl,tk}X.Y
819 debian_tcl_include = [ '/usr/include/tcl' + version ]
820 debian_tk_include = [ '/usr/include/tk' + version ] + \
821 debian_tcl_include
822 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
823 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
825 if (tcllib is None or tklib is None and
826 tcl_includes is None or tk_includes is None):
827 # Something's missing, so give up
828 return
830 # OK... everything seems to be present for Tcl/Tk.
832 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
833 for dir in tcl_includes + tk_includes:
834 if dir not in include_dirs:
835 include_dirs.append(dir)
837 # Check for various platform-specific directories
838 platform = self.get_platform()
839 if platform == 'sunos5':
840 include_dirs.append('/usr/openwin/include')
841 added_lib_dirs.append('/usr/openwin/lib')
842 elif os.path.exists('/usr/X11R6/include'):
843 include_dirs.append('/usr/X11R6/include')
844 added_lib_dirs.append('/usr/X11R6/lib')
845 elif os.path.exists('/usr/X11R5/include'):
846 include_dirs.append('/usr/X11R5/include')
847 added_lib_dirs.append('/usr/X11R5/lib')
848 else:
849 # Assume default location for X11
850 include_dirs.append('/usr/X11/include')
851 added_lib_dirs.append('/usr/X11/lib')
853 # If Cygwin, then verify that X is installed before proceeding
854 if platform == 'cygwin':
855 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
856 if x11_inc is None:
857 # X header files missing, so give up
858 return
860 # Check for BLT extension
861 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
862 'BLT8.0'):
863 defs.append( ('WITH_BLT', 1) )
864 libs.append('BLT8.0')
866 # Add the Tcl/Tk libraries
867 libs.append('tk'+version)
868 libs.append('tcl'+version)
870 if platform in ['aix3', 'aix4']:
871 libs.append('ld')
873 # Finally, link with the X11 libraries (not appropriate on cygwin)
874 if platform != "cygwin":
875 libs.append('X11')
877 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
878 define_macros=[('WITH_APPINIT', 1)] + defs,
879 include_dirs = include_dirs,
880 libraries = libs,
881 library_dirs = added_lib_dirs,
883 self.extensions.append(ext)
885 # XXX handle these, but how to detect?
886 # *** Uncomment and edit for PIL (TkImaging) extension only:
887 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
888 # *** Uncomment and edit for TOGL extension only:
889 # -DWITH_TOGL togl.c \
890 # *** Uncomment these for TOGL extension only:
891 # -lGL -lGLU -lXext -lXmu \
893 class PyBuildInstall(install):
894 # Suppress the warning about installation into the lib_dynload
895 # directory, which is not in sys.path when running Python during
896 # installation:
897 def initialize_options (self):
898 install.initialize_options(self)
899 self.warn_dir=0
901 def main():
902 # turn off warnings when deprecated modules are imported
903 import warnings
904 warnings.filterwarnings("ignore",category=DeprecationWarning)
905 setup(name = 'Python standard library',
906 version = '%d.%d' % sys.version_info[:2],
907 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
908 # The struct module is defined here, because build_ext won't be
909 # called unless there's at least one extension module defined.
910 ext_modules=[Extension('struct', ['structmodule.c'])],
912 # Scripts to install
913 scripts = ['Tools/scripts/pydoc']
916 # --install-platlib
917 if __name__ == '__main__':
918 main()