This commit was manufactured by cvs2svn to create tag 'r221c2'.
[python/dscho.git] / setup.py
blob037226d7ab4541b208eaac1a77ccf19f684f26d0
1 # Autodetecting setup.py script for building the Python extensions
4 __version__ = "$Revision$"
6 import sys, os, getopt
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 find_file(filename, std_dirs, paths):
18 """Searches for the directory where a given file is located,
19 and returns a possibly-empty list of additional directories, or None
20 if the file couldn't be found at all.
22 'filename' is the name of a file, such as readline.h or libcrypto.a.
23 'std_dirs' is the list of standard system directories; if the
24 file is found in one of them, no additional directives are needed.
25 'paths' is a list of additional locations to check; if the file is
26 found in one of them, the resulting list will contain the directory.
27 """
29 # Check the standard locations
30 for dir in std_dirs:
31 f = os.path.join(dir, filename)
32 if os.path.exists(f): return []
34 # Check the additional directories
35 for dir in paths:
36 f = os.path.join(dir, filename)
37 if os.path.exists(f):
38 return [dir]
40 # Not found anywhere
41 return None
43 def find_library_file(compiler, libname, std_dirs, paths):
44 filename = compiler.library_filename(libname, lib_type='shared')
45 result = find_file(filename, std_dirs, paths)
46 if result is not None: return result
48 filename = compiler.library_filename(libname, lib_type='static')
49 result = find_file(filename, std_dirs, paths)
50 return result
52 def module_enabled(extlist, modname):
53 """Returns whether the module 'modname' is present in the list
54 of extensions 'extlist'."""
55 extlist = [ext for ext in extlist if ext.name == modname]
56 return len(extlist)
58 def find_module_file(module, dirlist):
59 """Find a module in a set of possible folders. If it is not found
60 return the unadorned filename"""
61 list = find_file(module, [], dirlist)
62 if not list:
63 return module
64 if len(list) > 1:
65 self.announce("WARNING: multiple copies of %s found"%module)
66 return os.path.join(list[0], module)
68 class PyBuildExt(build_ext):
70 def build_extensions(self):
72 # Detect which modules should be compiled
73 self.detect_modules()
75 # Remove modules that are present on the disabled list
76 self.extensions = [ext for ext in self.extensions
77 if ext.name not in disabled_module_list]
79 # Fix up the autodetected modules, prefixing all the source files
80 # with Modules/ and adding Python's include directory to the path.
81 (srcdir,) = sysconfig.get_config_vars('srcdir')
83 # Figure out the location of the source code for extension modules
84 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
85 moddir = os.path.normpath(moddir)
86 srcdir, tail = os.path.split(moddir)
87 srcdir = os.path.normpath(srcdir)
88 moddir = os.path.normpath(moddir)
90 moddirlist = [moddir]
91 incdirlist = ['./Include']
93 # Platform-dependent module source and include directories
94 platform = self.get_platform()
95 if platform == 'darwin':
96 # Mac OS X also includes some mac-specific modules
97 macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
98 moddirlist.append(macmoddir)
99 incdirlist.append('./Mac/Include')
101 # Fix up the paths for scripts, too
102 self.distribution.scripts = [os.path.join(srcdir, filename)
103 for filename in self.distribution.scripts]
105 for ext in self.extensions[:]:
106 ext.sources = [ find_module_file(filename, moddirlist)
107 for filename in ext.sources ]
108 ext.include_dirs.append( '.' ) # to get config.h
109 for incdir in incdirlist:
110 ext.include_dirs.append( os.path.join(srcdir, incdir) )
112 # If a module has already been built statically,
113 # don't build it here
114 if ext.name in sys.builtin_module_names:
115 self.extensions.remove(ext)
117 # Parse Modules/Setup to figure out which modules are turned
118 # on in the file.
119 input = text_file.TextFile('Modules/Setup', join_lines=1)
120 remove_modules = []
121 while 1:
122 line = input.readline()
123 if not line: break
124 line = line.split()
125 remove_modules.append( line[0] )
126 input.close()
128 for ext in self.extensions[:]:
129 if ext.name in remove_modules:
130 self.extensions.remove(ext)
132 # When you run "make CC=altcc" or something similar, you really want
133 # those environment variables passed into the setup.py phase. Here's
134 # a small set of useful ones.
135 compiler = os.environ.get('CC')
136 linker_so = os.environ.get('LDSHARED')
137 args = {}
138 # unfortunately, distutils doesn't let us provide separate C and C++
139 # compilers
140 if compiler is not None:
141 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
142 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
143 if linker_so is not None:
144 args['linker_so'] = linker_so
145 self.compiler.set_executables(**args)
147 build_ext.build_extensions(self)
149 def build_extension(self, ext):
151 try:
152 build_ext.build_extension(self, ext)
153 except (CCompilerError, DistutilsError), why:
154 self.announce('WARNING: building of extension "%s" failed: %s' %
155 (ext.name, sys.exc_info()[1]))
156 return
157 # Workaround for Mac OS X: The Carbon-based modules cannot be
158 # reliably imported into a command-line Python
159 if 'Carbon' in ext.extra_link_args:
160 self.announce(
161 'WARNING: skipping import check for Carbon-based "%s"' %
162 ext.name)
163 return
164 try:
165 __import__(ext.name)
166 except ImportError:
167 self.announce('WARNING: removing "%s" since importing it failed' %
168 ext.name)
169 assert not self.inplace
170 fullname = self.get_ext_fullname(ext.name)
171 ext_filename = os.path.join(self.build_lib,
172 self.get_ext_filename(fullname))
173 os.remove(ext_filename)
175 # XXX -- This relies on a Vile HACK in
176 # distutils.command.build_ext.build_extension(). The
177 # _built_objects attribute is stored there strictly for
178 # use here.
179 # If there is a failure, _built_objects may not be there,
180 # so catch the AttributeError and move on.
181 try:
182 for filename in self._built_objects:
183 os.remove(filename)
184 except AttributeError:
185 self.announce('unable to remove files (ignored)')
187 def get_platform (self):
188 # Get value of sys.platform
189 platform = sys.platform
190 if platform[:6] =='cygwin':
191 platform = 'cygwin'
192 elif platform[:4] =='beos':
193 platform = 'beos'
194 elif platform[:6] == 'darwin':
195 platform = 'darwin'
197 return platform
199 def detect_modules(self):
200 # Ensure that /usr/local is always used
201 if '/usr/local/lib' not in self.compiler.library_dirs:
202 self.compiler.library_dirs.insert(0, '/usr/local/lib')
203 if '/usr/local/include' not in self.compiler.include_dirs:
204 self.compiler.include_dirs.insert(0, '/usr/local/include' )
206 try:
207 have_unicode = unicode
208 except NameError:
209 have_unicode = 0
211 # lib_dirs and inc_dirs are used to search for files;
212 # if a file is found in one of those directories, it can
213 # be assumed that no additional -I,-L directives are needed.
214 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
215 inc_dirs = self.compiler.include_dirs + ['/usr/include']
216 exts = []
218 platform = self.get_platform()
220 # Check for MacOS X, which doesn't need libm.a at all
221 math_libs = ['m']
222 if platform in ['darwin', 'beos']:
223 math_libs = []
225 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
228 # The following modules are all pretty straightforward, and compile
229 # on pretty much any POSIXish platform.
232 # Some modules that are normally always on:
233 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
234 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
236 exts.append( Extension('_hotshot', ['_hotshot.c']) )
237 exts.append( Extension('_weakref', ['_weakref.c']) )
238 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
240 # array objects
241 exts.append( Extension('array', ['arraymodule.c']) )
242 # complex math library functions
243 exts.append( Extension('cmath', ['cmathmodule.c'],
244 libraries=math_libs) )
246 # math library functions, e.g. sin()
247 exts.append( Extension('math', ['mathmodule.c'],
248 libraries=math_libs) )
249 # fast string operations implemented in C
250 exts.append( Extension('strop', ['stropmodule.c']) )
251 # time operations and variables
252 exts.append( Extension('time', ['timemodule.c'],
253 libraries=math_libs) )
254 # operator.add() and similar goodies
255 exts.append( Extension('operator', ['operator.c']) )
256 # access to the builtin codecs and codec registry
257 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
258 # Python C API test module
259 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
260 # static Unicode character database
261 if have_unicode:
262 exts.append( Extension('unicodedata', ['unicodedata.c']) )
263 # access to ISO C locale support
264 exts.append( Extension('_locale', ['_localemodule.c']) )
266 # Modules with some UNIX dependencies -- on by default:
267 # (If you have a really backward UNIX, select and socket may not be
268 # supported...)
270 # fcntl(2) and ioctl(2)
271 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
272 # pwd(3)
273 exts.append( Extension('pwd', ['pwdmodule.c']) )
274 # grp(3)
275 exts.append( Extension('grp', ['grpmodule.c']) )
276 # posix (UNIX) errno values
277 exts.append( Extension('errno', ['errnomodule.c']) )
278 # select(2); not on ancient System V
279 exts.append( Extension('select', ['selectmodule.c']) )
281 # The md5 module implements the RSA Data Security, Inc. MD5
282 # Message-Digest Algorithm, described in RFC 1321. The
283 # necessary files md5c.c and md5.h are included here.
284 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
286 # The sha module implements the SHA checksum algorithm.
287 # (NIST's Secure Hash Algorithm.)
288 exts.append( Extension('sha', ['shamodule.c']) )
290 # Helper module for various ascii-encoders
291 exts.append( Extension('binascii', ['binascii.c']) )
293 # Fred Drake's interface to the Python parser
294 exts.append( Extension('parser', ['parsermodule.c']) )
296 # Digital Creations' cStringIO and cPickle
297 exts.append( Extension('cStringIO', ['cStringIO.c']) )
298 exts.append( Extension('cPickle', ['cPickle.c']) )
300 # Memory-mapped files (also works on Win32).
301 exts.append( Extension('mmap', ['mmapmodule.c']) )
303 # Lance Ellinghaus's modules:
304 # enigma-inspired encryption
305 exts.append( Extension('rotor', ['rotormodule.c']) )
306 # syslog daemon interface
307 exts.append( Extension('syslog', ['syslogmodule.c']) )
309 # George Neville-Neil's timing module:
310 exts.append( Extension('timing', ['timingmodule.c']) )
313 # Here ends the simple stuff. From here on, modules need certain
314 # libraries, are platform-specific, or present other surprises.
317 # Multimedia modules
318 # These don't work for 64-bit platforms!!!
319 # These represent audio samples or images as strings:
321 # Disabled on 64-bit platforms
322 if sys.maxint != 9223372036854775807L:
323 # Operations on audio samples
324 exts.append( Extension('audioop', ['audioop.c']) )
325 # Operations on images
326 exts.append( Extension('imageop', ['imageop.c']) )
327 # Read SGI RGB image files (but coded portably)
328 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
330 # readline
331 if self.compiler.find_library_file(lib_dirs, 'readline'):
332 readline_libs = ['readline']
333 if self.compiler.find_library_file(lib_dirs,
334 'ncurses'):
335 readline_libs.append('ncurses')
336 elif self.compiler.find_library_file(lib_dirs +
337 ['/usr/lib/termcap'],
338 'termcap'):
339 readline_libs.append('termcap')
340 exts.append( Extension('readline', ['readline.c'],
341 library_dirs=['/usr/lib/termcap'],
342 libraries=readline_libs) )
344 # crypt module.
346 if self.compiler.find_library_file(lib_dirs, 'crypt'):
347 libs = ['crypt']
348 else:
349 libs = []
350 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
352 # socket(2)
353 # Detect SSL support for the socket module
354 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
355 ['/usr/local/ssl/include',
356 '/usr/contrib/ssl/include/'
359 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
360 ['/usr/local/ssl/lib',
361 '/usr/contrib/ssl/lib/'
364 if (ssl_incs is not None and
365 ssl_libs is not None):
366 exts.append( Extension('_socket', ['socketmodule.c'],
367 include_dirs = ssl_incs,
368 library_dirs = ssl_libs,
369 libraries = ['ssl', 'crypto'],
370 define_macros = [('USE_SSL',1)] ) )
371 else:
372 exts.append( Extension('_socket', ['socketmodule.c']) )
374 # Modules that provide persistent dictionary-like semantics. You will
375 # probably want to arrange for at least one of them to be available on
376 # your machine, though none are defined by default because of library
377 # dependencies. The Python module anydbm.py provides an
378 # implementation independent wrapper for these; dumbdbm.py provides
379 # similar functionality (but slower of course) implemented in Python.
381 # The standard Unix dbm module:
382 if platform not in ['cygwin']:
383 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
384 exts.append( Extension('dbm', ['dbmmodule.c'],
385 libraries = ['ndbm'] ) )
386 elif self.compiler.find_library_file(lib_dirs, 'db1'):
387 exts.append( Extension('dbm', ['dbmmodule.c'],
388 libraries = ['db1'] ) )
389 else:
390 exts.append( Extension('dbm', ['dbmmodule.c']) )
392 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
393 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
394 exts.append( Extension('gdbm', ['gdbmmodule.c'],
395 libraries = ['gdbm'] ) )
397 # Berkeley DB interface.
399 # This requires the Berkeley DB code, see
400 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
402 # Edit the variables DB and DBPORT to point to the db top directory
403 # and the subdirectory of PORT where you built it.
405 # (See http://pybsddb.sourceforge.net/ for an interface to
406 # Berkeley DB 3.x.)
408 dblib = []
409 if self.compiler.find_library_file(lib_dirs, 'db-3.2'):
410 dblib = ['db-3.2']
411 elif self.compiler.find_library_file(lib_dirs, 'db-3.1'):
412 dblib = ['db-3.1']
413 elif self.compiler.find_library_file(lib_dirs, 'db3'):
414 dblib = ['db3']
415 elif self.compiler.find_library_file(lib_dirs, 'db2'):
416 dblib = ['db2']
417 elif self.compiler.find_library_file(lib_dirs, 'db1'):
418 dblib = ['db1']
419 elif self.compiler.find_library_file(lib_dirs, 'db'):
420 dblib = ['db']
422 db185_incs = find_file('db_185.h', inc_dirs,
423 ['/usr/include/db3', '/usr/include/db2'])
424 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
425 if db185_incs is not None:
426 exts.append( Extension('bsddb', ['bsddbmodule.c'],
427 include_dirs = db185_incs,
428 define_macros=[('HAVE_DB_185_H',1)],
429 libraries = dblib ) )
430 elif db_inc is not None:
431 exts.append( Extension('bsddb', ['bsddbmodule.c'],
432 include_dirs = db_inc,
433 libraries = dblib) )
435 # The mpz module interfaces to the GNU Multiple Precision library.
436 # You need to ftp the GNU MP library.
437 # This was originally written and tested against GMP 1.2 and 1.3.2.
438 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
439 # haven't tested it recently, and it definitely doesn't work with
440 # GMP 4.0. For more complete modules, refer to
441 # http://gmpy.sourceforge.net and
442 # http://www.egenix.com/files/python/mxNumber.html
444 # A compatible MP library unencumbered by the GPL also exists. It was
445 # posted to comp.sources.misc in volume 40 and is widely available from
446 # FTP archive sites. One URL for it is:
447 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
449 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
450 exts.append( Extension('mpz', ['mpzmodule.c'],
451 libraries = ['gmp'] ) )
454 # Unix-only modules
455 if platform not in ['mac', 'win32']:
456 # Steen Lumholt's termios module
457 exts.append( Extension('termios', ['termios.c']) )
458 # Jeremy Hylton's rlimit interface
459 exts.append( Extension('resource', ['resource.c']) )
461 # Sun yellow pages. Some systems have the functions in libc.
462 if platform not in ['cygwin']:
463 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
464 libs = ['nsl']
465 else:
466 libs = []
467 exts.append( Extension('nis', ['nismodule.c'],
468 libraries = libs) )
470 # Curses support, requring the System V version of curses, often
471 # provided by the ncurses library.
472 if platform == 'sunos4':
473 inc_dirs += ['/usr/5include']
474 lib_dirs += ['/usr/5lib']
476 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
477 curses_libs = ['ncurses']
478 exts.append( Extension('_curses', ['_cursesmodule.c'],
479 libraries = curses_libs) )
480 elif (self.compiler.find_library_file(lib_dirs, 'curses')
481 and platform != 'darwin'):
482 # OSX has an old Berkeley curses, not good enough for
483 # the _curses module.
484 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
485 curses_libs = ['curses', 'terminfo']
486 else:
487 curses_libs = ['curses', 'termcap']
489 exts.append( Extension('_curses', ['_cursesmodule.c'],
490 libraries = curses_libs) )
492 # If the curses module is enabled, check for the panel module
493 if (module_enabled(exts, '_curses') and
494 self.compiler.find_library_file(lib_dirs, 'panel')):
495 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
496 libraries = ['panel'] + curses_libs) )
500 # Lee Busby's SIGFPE modules.
501 # The library to link fpectl with is platform specific.
502 # Choose *one* of the options below for fpectl:
504 if platform == 'irix5':
505 # For SGI IRIX (tested on 5.3):
506 exts.append( Extension('fpectl', ['fpectlmodule.c'],
507 libraries=['fpe']) )
508 elif 0: # XXX how to detect SunPro?
509 # For Solaris with SunPro compiler (tested on Solaris 2.5
510 # with SunPro C 4.2): (Without the compiler you don't have
511 # -lsunmath.)
512 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
513 pass
514 else:
515 # For other systems: see instructions in fpectlmodule.c.
516 #fpectl fpectlmodule.c ...
517 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
520 # Andrew Kuchling's zlib module.
521 # This require zlib 1.1.3 (or later).
522 # See http://www.cdrom.com/pub/infozip/zlib/
523 zlib_inc = find_file('zlib.h', [], inc_dirs)
524 if zlib_inc is not None:
525 zlib_h = zlib_inc[0] + '/zlib.h'
526 version = '"0.0.0"'
527 version_req = '"1.1.3"'
528 fp = open(zlib_h)
529 while 1:
530 line = fp.readline()
531 if not line:
532 break
533 if line.find('#define ZLIB_VERSION', 0) == 0:
534 version = line.split()[2]
535 break
536 if version >= version_req:
537 if (self.compiler.find_library_file(lib_dirs, 'z')):
538 exts.append( Extension('zlib', ['zlibmodule.c'],
539 libraries = ['z']) )
541 # Interface to the Expat XML parser
543 # Expat is written by James Clark and must be downloaded separately
544 # (see below). The pyexpat module was written by Paul Prescod after a
545 # prototype by Jack Jansen.
547 # The Expat dist includes Windows .lib and .dll files. Home page is
548 # at http://www.jclark.com/xml/expat.html, the current production
549 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
551 # EXPAT_DIR, below, should point to the expat/ directory created by
552 # unpacking the Expat source distribution.
554 # Note: the expat build process doesn't yet build a libexpat.a; you
555 # can do this manually while we try convince the author to add it. To
556 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
557 # run:
559 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
561 expat_defs = []
562 expat_incs = find_file('expat.h', inc_dirs, [])
563 if expat_incs is not None:
564 # expat.h was found
565 expat_defs = [('HAVE_EXPAT_H', 1)]
566 else:
567 expat_incs = find_file('xmlparse.h', inc_dirs, [])
569 if (expat_incs is not None and
570 self.compiler.find_library_file(lib_dirs, 'expat')):
571 exts.append( Extension('pyexpat', ['pyexpat.c'],
572 define_macros = expat_defs,
573 libraries = ['expat']) )
575 # Platform-specific libraries
576 if platform == 'linux2':
577 # Linux-specific modules
578 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
580 if platform == 'sunos5':
581 # SunOS specific modules
582 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
584 if platform == 'darwin':
585 # Mac OS X specific modules. These are ported over from MacPython
586 # and still experimental. Some (such as gestalt or icglue) are
587 # already generally useful, some (the GUI ones) really need to
588 # be used from a framework.
590 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
591 # available here. This Makefile variable is also what the install
592 # procedure triggers on.
593 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
594 exts.append( Extension('gestalt', ['gestaltmodule.c'],
595 extra_link_args=['-framework', 'Carbon']) )
596 exts.append( Extension('MacOS', ['macosmodule.c'],
597 extra_link_args=['-framework', 'Carbon']) )
598 exts.append( Extension('icglue', ['icgluemodule.c'],
599 extra_link_args=['-framework', 'Carbon']) )
600 exts.append( Extension('macfs',
601 ['macfsmodule.c',
602 '../Python/getapplbycreator.c'],
603 extra_link_args=['-framework', 'Carbon']) )
604 exts.append( Extension('_CF', ['cf/_CFmodule.c'],
605 extra_link_args=['-framework', 'CoreFoundation']) )
606 exts.append( Extension('_Res', ['res/_Resmodule.c'],
607 extra_link_args=['-framework', 'Carbon']) )
608 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
609 extra_link_args=['-framework', 'Carbon']) )
610 if frameworkdir:
611 exts.append( Extension('Nav', ['Nav.c'],
612 extra_link_args=['-framework', 'Carbon']) )
613 exts.append( Extension('_AE', ['ae/_AEmodule.c'],
614 extra_link_args=['-framework', 'Carbon']) )
615 exts.append( Extension('_App', ['app/_Appmodule.c'],
616 extra_link_args=['-framework', 'Carbon']) )
617 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
618 extra_link_args=['-framework', 'Carbon']) )
619 exts.append( Extension('_CG', ['cg/_CGmodule.c'],
620 extra_link_args=['-framework', 'ApplicationServices',
621 '-framework', 'Carbon']) )
622 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
623 extra_link_args=['-framework', 'Carbon']) )
624 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
625 extra_link_args=['-framework', 'Carbon']) )
626 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
627 extra_link_args=['-framework', 'Carbon']) )
628 exts.append( Extension('_Drag', ['drag/_Dragmodule.c'],
629 extra_link_args=['-framework', 'Carbon']) )
630 exts.append( Extension('_Evt', ['evt/_Evtmodule.c'],
631 extra_link_args=['-framework', 'Carbon']) )
632 exts.append( Extension('_Fm', ['fm/_Fmmodule.c'],
633 extra_link_args=['-framework', 'Carbon']) )
634 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
635 extra_link_args=['-framework', 'Carbon']) )
636 exts.append( Extension('_List', ['list/_Listmodule.c'],
637 extra_link_args=['-framework', 'Carbon']) )
638 exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
639 extra_link_args=['-framework', 'Carbon']) )
640 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
641 extra_link_args=['-framework', 'Carbon']) )
642 exts.append( Extension('_Qd', ['qd/_Qdmodule.c'],
643 extra_link_args=['-framework', 'Carbon']) )
644 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
645 extra_link_args=['-framework', 'Carbon']) )
646 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
647 extra_link_args=['-framework', 'QuickTime',
648 '-framework', 'Carbon']) )
649 exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
650 extra_link_args=['-framework', 'Carbon']) )
651 exts.append( Extension('_TE', ['te/_TEmodule.c'],
652 extra_link_args=['-framework', 'Carbon']) )
653 # As there is no standardized place (yet) to put user-installed
654 # Mac libraries on OSX you should put a symlink to your Waste
655 # installation in the same folder as your python source tree.
656 # Or modify the next two lines:-)
657 waste_incs = find_file("WASTE.h", [], ["../waste/C_C++ Headers"])
658 waste_libs = find_library_file(self.compiler, "WASTE", [],
659 ["../waste/Static Libraries"])
660 if waste_incs != None and waste_libs != None:
661 exts.append( Extension('waste',
662 ['waste/wastemodule.c',
663 'Mac/Wastemods/WEObjectHandlers.c',
664 'Mac/Wastemods/WETabHooks.c',
665 'Mac/Wastemods/WETabs.c'
667 include_dirs = waste_incs + ['Mac/Wastemods'],
668 library_dirs = waste_libs,
669 libraries = ['WASTE'],
670 extra_link_args = ['-framework', 'Carbon'],
672 exts.append( Extension('_Win', ['win/_Winmodule.c'],
673 extra_link_args=['-framework', 'Carbon']) )
675 self.extensions.extend(exts)
677 # Call the method for detecting whether _tkinter can be compiled
678 self.detect_tkinter(inc_dirs, lib_dirs)
681 def detect_tkinter(self, inc_dirs, lib_dirs):
682 # The _tkinter module.
684 # Assume we haven't found any of the libraries or include files
685 # The versions with dots are used on Unix, and the versions without
686 # dots on Windows, for detection by cygwin.
687 tcllib = tklib = tcl_includes = tk_includes = None
688 for version in ['8.4', '84', '8.3', '83', '8.2',
689 '82', '8.1', '81', '8.0', '80']:
690 tklib = self.compiler.find_library_file(lib_dirs,
691 'tk' + version )
692 tcllib = self.compiler.find_library_file(lib_dirs,
693 'tcl' + version )
694 if tklib and tcllib:
695 # Exit the loop when we've found the Tcl/Tk libraries
696 break
698 # Now check for the header files
699 if tklib and tcllib:
700 # Check for the include files on Debian, where
701 # they're put in /usr/include/{tcl,tk}X.Y
702 debian_tcl_include = [ '/usr/include/tcl' + version ]
703 debian_tk_include = [ '/usr/include/tk' + version ] + \
704 debian_tcl_include
705 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
706 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
708 if (tcllib is None or tklib is None and
709 tcl_includes is None or tk_includes is None):
710 # Something's missing, so give up
711 return
713 # OK... everything seems to be present for Tcl/Tk.
715 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
716 for dir in tcl_includes + tk_includes:
717 if dir not in include_dirs:
718 include_dirs.append(dir)
720 # Check for various platform-specific directories
721 platform = self.get_platform()
722 if platform == 'sunos5':
723 include_dirs.append('/usr/openwin/include')
724 added_lib_dirs.append('/usr/openwin/lib')
725 elif os.path.exists('/usr/X11R6/include'):
726 include_dirs.append('/usr/X11R6/include')
727 added_lib_dirs.append('/usr/X11R6/lib')
728 elif os.path.exists('/usr/X11R5/include'):
729 include_dirs.append('/usr/X11R5/include')
730 added_lib_dirs.append('/usr/X11R5/lib')
731 else:
732 # Assume default location for X11
733 include_dirs.append('/usr/X11/include')
734 added_lib_dirs.append('/usr/X11/lib')
736 # If Cygwin, then verify that X is installed before proceeding
737 if platform == 'cygwin':
738 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
739 if x11_inc is None:
740 # X header files missing, so give up
741 return
743 # Check for BLT extension
744 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
745 'BLT8.0'):
746 defs.append( ('WITH_BLT', 1) )
747 libs.append('BLT8.0')
749 # Add the Tcl/Tk libraries
750 libs.append('tk'+version)
751 libs.append('tcl'+version)
753 if platform in ['aix3', 'aix4']:
754 libs.append('ld')
756 # Finally, link with the X11 libraries (not appropriate on cygwin)
757 if platform != "cygwin":
758 libs.append('X11')
760 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
761 define_macros=[('WITH_APPINIT', 1)] + defs,
762 include_dirs = include_dirs,
763 libraries = libs,
764 library_dirs = added_lib_dirs,
766 self.extensions.append(ext)
768 # XXX handle these, but how to detect?
769 # *** Uncomment and edit for PIL (TkImaging) extension only:
770 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
771 # *** Uncomment and edit for TOGL extension only:
772 # -DWITH_TOGL togl.c \
773 # *** Uncomment these for TOGL extension only:
774 # -lGL -lGLU -lXext -lXmu \
776 class PyBuildInstall(install):
777 # Suppress the warning about installation into the lib_dynload
778 # directory, which is not in sys.path when running Python during
779 # installation:
780 def initialize_options (self):
781 install.initialize_options(self)
782 self.warn_dir=0
784 def main():
785 # turn off warnings when deprecated modules are imported
786 import warnings
787 warnings.filterwarnings("ignore",category=DeprecationWarning)
788 setup(name = 'Python standard library',
789 version = '%d.%d' % sys.version_info[:2],
790 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
791 # The struct module is defined here, because build_ext won't be
792 # called unless there's at least one extension module defined.
793 ext_modules=[Extension('struct', ['structmodule.c'])],
795 # Scripts to install
796 scripts = ['Tools/scripts/pydoc']
799 # --install-platlib
800 if __name__ == '__main__':
801 sysconfig.set_python_build()
802 main()