This commit was manufactured by cvs2svn to create tag 'r22a4-fork'.
[python/dscho.git] / setup.py
blobbb4be3f7f9ce24ceb75580bd940952baf64a5d7b
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 == 'darwin1':
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 if platform == 'darwin1':
145 args['linker_so'] = linker_so
146 else:
147 args['linker_so'] = linker_so + ' -shared'
148 self.compiler.set_executables(**args)
150 build_ext.build_extensions(self)
152 def build_extension(self, ext):
154 try:
155 build_ext.build_extension(self, ext)
156 except (CCompilerError, DistutilsError), why:
157 self.announce('WARNING: building of extension "%s" failed: %s' %
158 (ext.name, sys.exc_info()[1]))
159 return
160 try:
161 __import__(ext.name)
162 except ImportError:
163 self.announce('WARNING: removing "%s" since importing it failed' %
164 ext.name)
165 assert not self.inplace
166 fullname = self.get_ext_fullname(ext.name)
167 ext_filename = os.path.join(self.build_lib,
168 self.get_ext_filename(fullname))
169 os.remove(ext_filename)
171 def get_platform (self):
172 # Get value of sys.platform
173 platform = sys.platform
174 if platform[:6] =='cygwin':
175 platform = 'cygwin'
176 elif platform[:4] =='beos':
177 platform = 'beos'
179 return platform
181 def detect_modules(self):
182 # Ensure that /usr/local is always used
183 if '/usr/local/lib' not in self.compiler.library_dirs:
184 self.compiler.library_dirs.insert(0, '/usr/local/lib')
185 if '/usr/local/include' not in self.compiler.include_dirs:
186 self.compiler.include_dirs.insert(0, '/usr/local/include' )
188 try:
189 have_unicode = unicode
190 except NameError:
191 have_unicode = 0
193 # lib_dirs and inc_dirs are used to search for files;
194 # if a file is found in one of those directories, it can
195 # be assumed that no additional -I,-L directives are needed.
196 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
197 inc_dirs = self.compiler.include_dirs + ['/usr/include']
198 exts = []
200 platform = self.get_platform()
202 # Check for MacOS X, which doesn't need libm.a at all
203 math_libs = ['m']
204 if platform in ['Darwin1.2', 'beos']:
205 math_libs = []
207 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
210 # The following modules are all pretty straightforward, and compile
211 # on pretty much any POSIXish platform.
214 # Some modules that are normally always on:
215 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
216 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
218 exts.append( Extension('_weakref', ['_weakref.c']) )
219 exts.append( Extension('_symtable', ['symtablemodule.c']) )
220 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
222 # array objects
223 exts.append( Extension('array', ['arraymodule.c']) )
224 # complex math library functions
225 exts.append( Extension('cmath', ['cmathmodule.c'],
226 libraries=math_libs) )
228 # math library functions, e.g. sin()
229 exts.append( Extension('math', ['mathmodule.c'],
230 libraries=math_libs) )
231 # fast string operations implemented in C
232 exts.append( Extension('strop', ['stropmodule.c']) )
233 # time operations and variables
234 exts.append( Extension('time', ['timemodule.c'],
235 libraries=math_libs) )
236 # operator.add() and similar goodies
237 exts.append( Extension('operator', ['operator.c']) )
238 # access to the builtin codecs and codec registry
239 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
240 # Python C API test module
241 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
242 # static Unicode character database
243 if have_unicode:
244 exts.append( Extension('unicodedata', ['unicodedata.c']) )
245 # access to ISO C locale support
246 exts.append( Extension('_locale', ['_localemodule.c']) )
248 # Modules with some UNIX dependencies -- on by default:
249 # (If you have a really backward UNIX, select and socket may not be
250 # supported...)
252 # fcntl(2) and ioctl(2)
253 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
254 # pwd(3)
255 exts.append( Extension('pwd', ['pwdmodule.c']) )
256 # grp(3)
257 exts.append( Extension('grp', ['grpmodule.c']) )
258 # posix (UNIX) errno values
259 exts.append( Extension('errno', ['errnomodule.c']) )
260 # select(2); not on ancient System V
261 exts.append( Extension('select', ['selectmodule.c']) )
263 # The md5 module implements the RSA Data Security, Inc. MD5
264 # Message-Digest Algorithm, described in RFC 1321. The necessary files
265 # md5c.c and md5.h are included here.
266 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
268 # The sha module implements the SHA checksum algorithm.
269 # (NIST's Secure Hash Algorithm.)
270 exts.append( Extension('sha', ['shamodule.c']) )
272 # Helper module for various ascii-encoders
273 exts.append( Extension('binascii', ['binascii.c']) )
275 # Fred Drake's interface to the Python parser
276 exts.append( Extension('parser', ['parsermodule.c']) )
278 # Digital Creations' cStringIO and cPickle
279 exts.append( Extension('cStringIO', ['cStringIO.c']) )
280 exts.append( Extension('cPickle', ['cPickle.c']) )
282 # Memory-mapped files (also works on Win32).
283 exts.append( Extension('mmap', ['mmapmodule.c']) )
285 # Lance Ellinghaus's modules:
286 # enigma-inspired encryption
287 exts.append( Extension('rotor', ['rotormodule.c']) )
288 # syslog daemon interface
289 exts.append( Extension('syslog', ['syslogmodule.c']) )
291 # George Neville-Neil's timing module:
292 exts.append( Extension('timing', ['timingmodule.c']) )
295 # Here ends the simple stuff. From here on, modules need certain
296 # libraries, are platform-specific, or present other surprises.
299 # Multimedia modules
300 # These don't work for 64-bit platforms!!!
301 # These represent audio samples or images as strings:
303 # Disabled on 64-bit platforms
304 if sys.maxint != 9223372036854775807L:
305 # Operations on audio samples
306 exts.append( Extension('audioop', ['audioop.c']) )
307 # Operations on images
308 exts.append( Extension('imageop', ['imageop.c']) )
309 # Read SGI RGB image files (but coded portably)
310 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
312 # readline
313 if self.compiler.find_library_file(lib_dirs, 'readline'):
314 readline_libs = ['readline']
315 if self.compiler.find_library_file(lib_dirs,
316 'ncurses'):
317 readline_libs.append('ncurses')
318 elif self.compiler.find_library_file(lib_dirs +
319 ['/usr/lib/termcap'],
320 'termcap'):
321 readline_libs.append('termcap')
322 exts.append( Extension('readline', ['readline.c'],
323 library_dirs=['/usr/lib/termcap'],
324 libraries=readline_libs) )
326 # crypt module.
328 if self.compiler.find_library_file(lib_dirs, 'crypt'):
329 libs = ['crypt']
330 else:
331 libs = []
332 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
334 # socket(2)
335 # Detect SSL support for the socket module
336 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
337 ['/usr/local/ssl/include',
338 '/usr/contrib/ssl/include/'
341 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
342 ['/usr/local/ssl/lib',
343 '/usr/contrib/ssl/lib/'
346 if (ssl_incs is not None and
347 ssl_libs is not None):
348 exts.append( Extension('_socket', ['socketmodule.c'],
349 include_dirs = ssl_incs,
350 library_dirs = ssl_libs,
351 libraries = ['ssl', 'crypto'],
352 define_macros = [('USE_SSL',1)] ) )
353 else:
354 exts.append( Extension('_socket', ['socketmodule.c']) )
356 # Modules that provide persistent dictionary-like semantics. You will
357 # probably want to arrange for at least one of them to be available on
358 # your machine, though none are defined by default because of library
359 # dependencies. The Python module anydbm.py provides an
360 # implementation independent wrapper for these; dumbdbm.py provides
361 # similar functionality (but slower of course) implemented in Python.
363 # The standard Unix dbm module:
364 if platform not in ['cygwin']:
365 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
366 exts.append( Extension('dbm', ['dbmmodule.c'],
367 libraries = ['ndbm'] ) )
368 else:
369 exts.append( Extension('dbm', ['dbmmodule.c']) )
371 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
372 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
373 exts.append( Extension('gdbm', ['gdbmmodule.c'],
374 libraries = ['gdbm'] ) )
376 # Berkeley DB interface.
378 # This requires the Berkeley DB code, see
379 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
381 # Edit the variables DB and DBPORT to point to the db top directory
382 # and the subdirectory of PORT where you built it.
384 # (See http://pybsddb.sourceforge.net/ for an interface to
385 # Berkeley DB 3.x.)
387 dblib = []
388 if self.compiler.find_library_file(lib_dirs, 'db-3.1'):
389 dblib = ['db-3.1']
390 elif self.compiler.find_library_file(lib_dirs, 'db2'):
391 dblib = ['db2']
392 elif self.compiler.find_library_file(lib_dirs, 'db1'):
393 dblib = ['db1']
394 elif self.compiler.find_library_file(lib_dirs, 'db'):
395 dblib = ['db']
397 db185_incs = find_file('db_185.h', inc_dirs,
398 ['/usr/include/db3', '/usr/include/db2'])
399 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
400 if db185_incs is not None:
401 exts.append( Extension('bsddb', ['bsddbmodule.c'],
402 include_dirs = db185_incs,
403 define_macros=[('HAVE_DB_185_H',1)],
404 libraries = dblib ) )
405 elif db_inc is not None:
406 exts.append( Extension('bsddb', ['bsddbmodule.c'],
407 include_dirs = db_inc,
408 libraries = dblib) )
410 # The mpz module interfaces to the GNU Multiple Precision library.
411 # You need to ftp the GNU MP library.
412 # This was originally written and tested against GMP 1.2 and 1.3.2.
413 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
414 # haven't tested it recently. For a more complete module,
415 # refer to pympz.sourceforge.net.
417 # A compatible MP library unencombered by the GPL also exists. It was
418 # posted to comp.sources.misc in volume 40 and is widely available from
419 # FTP archive sites. One URL for it is:
420 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
422 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
423 exts.append( Extension('mpz', ['mpzmodule.c'],
424 libraries = ['gmp'] ) )
427 # Unix-only modules
428 if platform not in ['mac', 'win32']:
429 # Steen Lumholt's termios module
430 exts.append( Extension('termios', ['termios.c']) )
431 # Jeremy Hylton's rlimit interface
432 exts.append( Extension('resource', ['resource.c']) )
434 # Sun yellow pages. Some systems have the functions in libc.
435 if platform not in ['cygwin']:
436 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
437 libs = ['nsl']
438 else:
439 libs = []
440 exts.append( Extension('nis', ['nismodule.c'],
441 libraries = libs) )
443 # Curses support, requring the System V version of curses, often
444 # provided by the ncurses library.
445 if platform == 'sunos4':
446 inc_dirs += ['/usr/5include']
447 lib_dirs += ['/usr/5lib']
449 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
450 curses_libs = ['ncurses']
451 exts.append( Extension('_curses', ['_cursesmodule.c'],
452 libraries = curses_libs) )
453 elif (self.compiler.find_library_file(lib_dirs, 'curses')) and platform != 'darwin1':
454 # OSX has an old Berkeley curses, not good enough for the _curses module.
455 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
456 curses_libs = ['curses', 'terminfo']
457 else:
458 curses_libs = ['curses', 'termcap']
460 exts.append( Extension('_curses', ['_cursesmodule.c'],
461 libraries = curses_libs) )
463 # If the curses module is enabled, check for the panel module
464 if (os.path.exists('Modules/_curses_panel.c') and
465 module_enabled(exts, '_curses') and
466 self.compiler.find_library_file(lib_dirs, 'panel')):
467 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
468 libraries = ['panel'] + curses_libs) )
472 # Lee Busby's SIGFPE modules.
473 # The library to link fpectl with is platform specific.
474 # Choose *one* of the options below for fpectl:
476 if platform == 'irix5':
477 # For SGI IRIX (tested on 5.3):
478 exts.append( Extension('fpectl', ['fpectlmodule.c'],
479 libraries=['fpe']) )
480 elif 0: # XXX how to detect SunPro?
481 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
482 # (Without the compiler you don't have -lsunmath.)
483 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
484 pass
485 else:
486 # For other systems: see instructions in fpectlmodule.c.
487 #fpectl fpectlmodule.c ...
488 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
491 # Andrew Kuchling's zlib module.
492 # This require zlib 1.1.3 (or later).
493 # See http://www.cdrom.com/pub/infozip/zlib/
494 zlib_inc = find_file('zlib.h', [], inc_dirs)
495 if zlib_inc is not None:
496 zlib_h = zlib_inc[0] + '/zlib.h'
497 version = '"0.0.0"'
498 version_req = '"1.1.3"'
499 fp = open(zlib_h)
500 while 1:
501 line = fp.readline()
502 if not line:
503 break
504 if line.find('#define ZLIB_VERSION', 0) == 0:
505 version = line.split()[2]
506 break
507 if version >= version_req:
508 if (self.compiler.find_library_file(lib_dirs, 'z')):
509 exts.append( Extension('zlib', ['zlibmodule.c'],
510 libraries = ['z']) )
512 # Interface to the Expat XML parser
514 # Expat is written by James Clark and must be downloaded separately
515 # (see below). The pyexpat module was written by Paul Prescod after a
516 # prototype by Jack Jansen.
518 # The Expat dist includes Windows .lib and .dll files. Home page is
519 # at http://www.jclark.com/xml/expat.html, the current production
520 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
522 # EXPAT_DIR, below, should point to the expat/ directory created by
523 # unpacking the Expat source distribution.
525 # Note: the expat build process doesn't yet build a libexpat.a; you
526 # can do this manually while we try convince the author to add it. To
527 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
528 # run:
530 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
532 expat_defs = []
533 expat_incs = find_file('expat.h', inc_dirs, [])
534 if expat_incs is not None:
535 # expat.h was found
536 expat_defs = [('HAVE_EXPAT_H', 1)]
537 else:
538 expat_incs = find_file('xmlparse.h', inc_dirs, [])
540 if (expat_incs is not None and
541 self.compiler.find_library_file(lib_dirs, 'expat')):
542 exts.append( Extension('pyexpat', ['pyexpat.c'],
543 define_macros = expat_defs,
544 libraries = ['expat']) )
546 # Platform-specific libraries
547 if platform == 'linux2':
548 # Linux-specific modules
549 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
551 if platform == 'sunos5':
552 # SunOS specific modules
553 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
555 if platform == 'darwin1':
556 # Mac OS X specific modules. These are ported over from MacPython
557 # and still experimental. Some (such as gestalt or icglue) are
558 # already generally useful, some (the GUI ones) really need to
559 # be used from a framework.
561 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
562 # available here. This Makefile variable is also what the install
563 # procedure triggers on.
564 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
565 exts.append( Extension('gestalt', ['gestaltmodule.c']) )
566 exts.append( Extension('MacOS', ['macosmodule.c']) )
567 exts.append( Extension('icglue', ['icgluemodule.c']) )
568 exts.append( Extension('macfs', ['macfsmodule.c', '../Python/getapplbycreator.c']) )
569 exts.append( Extension('_CF', ['cf/_CFmodule.c'],
570 extra_link_args=['-framework', 'CoreFoundation']) )
571 exts.append( Extension('_Res', ['res/_Resmodule.c'] ) )
572 exts.append( Extension('_Snd', ['snd/_Sndmodule.c']) )
573 if frameworkdir:
574 exts.append( Extension('Nav', ['Nav.c']) )
575 exts.append( Extension('_AE', ['ae/_AEmodule.c']) )
576 exts.append( Extension('_App', ['app/_Appmodule.c']) )
577 exts.append( Extension('_Cm', ['cm/_Cmmodule.c']) )
578 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c']) )
579 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c']) )
580 exts.append( Extension('_Drag', ['drag/_Dragmodule.c']) )
581 exts.append( Extension('_Evt', ['evt/_Evtmodule.c']) )
582 exts.append( Extension('_Fm', ['fm/_Fmmodule.c']) )
583 exts.append( Extension('_Icn', ['icn/_Icnmodule.c']) )
584 exts.append( Extension('_List', ['list/_Listmodule.c']) )
585 exts.append( Extension('_Menu', ['menu/_Menumodule.c']) )
586 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c']) )
587 exts.append( Extension('_Qd', ['qd/_Qdmodule.c']) )
588 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c']) )
589 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
590 extra_link_args=['-framework', 'QuickTime']) )
591 ## exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c']) )
592 exts.append( Extension('_TE', ['te/_TEmodule.c']) )
593 ## exts.append( Extension('waste', ['waste/wastemodule.c']) )
594 exts.append( Extension('_Win', ['win/_Winmodule.c']) )
596 self.extensions.extend(exts)
598 # Call the method for detecting whether _tkinter can be compiled
599 self.detect_tkinter(inc_dirs, lib_dirs)
602 def detect_tkinter(self, inc_dirs, lib_dirs):
603 # The _tkinter module.
605 # Assume we haven't found any of the libraries or include files
606 # The versions with dots are used on Unix, and the versions without
607 # dots on Windows, for detection by cygwin.
608 tcllib = tklib = tcl_includes = tk_includes = None
609 for version in ['8.4', '84', '8.3', '83', '8.2',
610 '82', '8.1', '81', '8.0', '80']:
611 tklib = self.compiler.find_library_file(lib_dirs,
612 'tk' + version )
613 tcllib = self.compiler.find_library_file(lib_dirs,
614 'tcl' + version )
615 if tklib and tcllib:
616 # Exit the loop when we've found the Tcl/Tk libraries
617 break
619 # Now check for the header files
620 if tklib and tcllib:
621 # Check for the include files on Debian, where
622 # they're put in /usr/include/{tcl,tk}X.Y
623 debian_tcl_include = [ '/usr/include/tcl' + version ]
624 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
625 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
626 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
628 if (tcllib is None or tklib is None and
629 tcl_includes is None or tk_includes is None):
630 # Something's missing, so give up
631 return
633 # OK... everything seems to be present for Tcl/Tk.
635 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
636 for dir in tcl_includes + tk_includes:
637 if dir not in include_dirs:
638 include_dirs.append(dir)
640 # Check for various platform-specific directories
641 platform = self.get_platform()
642 if platform == 'sunos5':
643 include_dirs.append('/usr/openwin/include')
644 added_lib_dirs.append('/usr/openwin/lib')
645 elif os.path.exists('/usr/X11R6/include'):
646 include_dirs.append('/usr/X11R6/include')
647 added_lib_dirs.append('/usr/X11R6/lib')
648 elif os.path.exists('/usr/X11R5/include'):
649 include_dirs.append('/usr/X11R5/include')
650 added_lib_dirs.append('/usr/X11R5/lib')
651 else:
652 # Assume default location for X11
653 include_dirs.append('/usr/X11/include')
654 added_lib_dirs.append('/usr/X11/lib')
656 # If Cygwin, then verify that X is installed before proceeding
657 if platform == 'cygwin':
658 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
659 if x11_inc is None:
660 # X header files missing, so give up
661 return
663 # Check for BLT extension
664 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
665 defs.append( ('WITH_BLT', 1) )
666 libs.append('BLT8.0')
668 # Add the Tcl/Tk libraries
669 libs.append('tk'+version)
670 libs.append('tcl'+version)
672 if platform in ['aix3', 'aix4']:
673 libs.append('ld')
675 # Finally, link with the X11 libraries (not appropriate on cygwin)
676 if platform != "cygwin":
677 libs.append('X11')
679 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
680 define_macros=[('WITH_APPINIT', 1)] + defs,
681 include_dirs = include_dirs,
682 libraries = libs,
683 library_dirs = added_lib_dirs,
685 self.extensions.append(ext)
687 # XXX handle these, but how to detect?
688 # *** Uncomment and edit for PIL (TkImaging) extension only:
689 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
690 # *** Uncomment and edit for TOGL extension only:
691 # -DWITH_TOGL togl.c \
692 # *** Uncomment these for TOGL extension only:
693 # -lGL -lGLU -lXext -lXmu \
695 class PyBuildInstall(install):
696 # Suppress the warning about installation into the lib_dynload
697 # directory, which is not in sys.path when running Python during
698 # installation:
699 def initialize_options (self):
700 install.initialize_options(self)
701 self.warn_dir=0
703 def main():
704 # turn off warnings when deprecated modules are imported
705 import warnings
706 warnings.filterwarnings("ignore",category=DeprecationWarning)
707 setup(name = 'Python standard library',
708 version = '%d.%d' % sys.version_info[:2],
709 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
710 # The struct module is defined here, because build_ext won't be
711 # called unless there's at least one extension module defined.
712 ext_modules=[Extension('struct', ['structmodule.c'])],
714 # Scripts to install
715 scripts = ['Tools/scripts/pydoc']
718 # --install-platlib
719 if __name__ == '__main__':
720 sysconfig.set_python_build()
721 main()