1 # Autodetecting setup.py script for building the Python extensions
4 __version__
= "$Revision$"
6 import sys
, os
, getopt
, imp
, re
8 from distutils
import log
9 from distutils
import sysconfig
10 from distutils
import text_file
11 from distutils
.errors
import *
12 from distutils
.core
import Extension
, setup
13 from distutils
.command
.build_ext
import build_ext
14 from distutils
.command
.install
import install
15 from distutils
.command
.install_lib
import install_lib
17 # This global variable is used to hold the list of modules to be disabled.
18 disabled_module_list
= []
20 def add_dir_to_list(dirlist
, dir):
21 """Add the directory 'dir' to the list 'dirlist' (at the front) if
22 1) 'dir' is not already in 'dirlist'
23 2) 'dir' actually exists, and is a directory."""
24 if dir is not None and os
.path
.isdir(dir) and dir not in dirlist
:
25 dirlist
.insert(0, dir)
27 def find_file(filename
, std_dirs
, paths
):
28 """Searches for the directory where a given file is located,
29 and returns a possibly-empty list of additional directories, or None
30 if the file couldn't be found at all.
32 'filename' is the name of a file, such as readline.h or libcrypto.a.
33 'std_dirs' is the list of standard system directories; if the
34 file is found in one of them, no additional directives are needed.
35 'paths' is a list of additional locations to check; if the file is
36 found in one of them, the resulting list will contain the directory.
39 # Check the standard locations
41 f
= os
.path
.join(dir, filename
)
42 if os
.path
.exists(f
): return []
44 # Check the additional directories
46 f
= os
.path
.join(dir, filename
)
53 def find_library_file(compiler
, libname
, std_dirs
, paths
):
54 result
= compiler
.find_library_file(std_dirs
+ paths
, libname
)
58 # Check whether the found file is in one of the standard directories
59 dirname
= os
.path
.dirname(result
)
61 # Ensure path doesn't end with path separator
62 if p
.endswith(os
.sep
):
67 # Otherwise, it must have been in one of the additional directories,
68 # so we have to figure out which one.
70 # Ensure path doesn't end with path separator
71 if p
.endswith(os
.sep
):
76 assert False, "Internal error: Path not found in std_dirs or paths"
78 def module_enabled(extlist
, modname
):
79 """Returns whether the module 'modname' is present in the list
80 of extensions 'extlist'."""
81 extlist
= [ext
for ext
in extlist
if ext
.name
== modname
]
84 def find_module_file(module
, dirlist
):
85 """Find a module in a set of possible folders. If it is not found
86 return the unadorned filename"""
87 list = find_file(module
, [], dirlist
)
91 self
.announce("WARNING: multiple copies of %s found"%module
)
92 return os
.path
.join(list[0], module
)
94 class PyBuildExt(build_ext
):
96 def build_extensions(self
):
98 # Detect which modules should be compiled
101 # Remove modules that are present on the disabled list
102 self
.extensions
= [ext
for ext
in self
.extensions
103 if ext
.name
not in disabled_module_list
]
105 # Fix up the autodetected modules, prefixing all the source files
106 # with Modules/ and adding Python's include directory to the path.
107 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
109 # Maybe running on Windows but not using CYGWIN?
110 raise ValueError("No source directory; cannot proceed.")
112 # Figure out the location of the source code for extension modules
113 moddir
= os
.path
.join(os
.getcwd(), srcdir
, 'Modules')
114 moddir
= os
.path
.normpath(moddir
)
115 srcdir
, tail
= os
.path
.split(moddir
)
116 srcdir
= os
.path
.normpath(srcdir
)
117 moddir
= os
.path
.normpath(moddir
)
119 moddirlist
= [moddir
]
120 incdirlist
= ['./Include']
122 # Platform-dependent module source and include directories
123 platform
= self
.get_platform()
124 if platform
in ('darwin', 'mac'):
125 # Mac OS X also includes some mac-specific modules
126 macmoddir
= os
.path
.join(os
.getcwd(), srcdir
, 'Mac/Modules')
127 moddirlist
.append(macmoddir
)
128 incdirlist
.append('./Mac/Include')
130 alldirlist
= moddirlist
+ incdirlist
132 # Fix up the paths for scripts, too
133 self
.distribution
.scripts
= [os
.path
.join(srcdir
, filename
)
134 for filename
in self
.distribution
.scripts
]
136 for ext
in self
.extensions
[:]:
137 ext
.sources
= [ find_module_file(filename
, moddirlist
)
138 for filename
in ext
.sources
]
139 if ext
.depends
is not None:
140 ext
.depends
= [find_module_file(filename
, alldirlist
)
141 for filename
in ext
.depends
]
142 ext
.include_dirs
.append( '.' ) # to get config.h
143 for incdir
in incdirlist
:
144 ext
.include_dirs
.append( os
.path
.join(srcdir
, incdir
) )
146 # If a module has already been built statically,
147 # don't build it here
148 if ext
.name
in sys
.builtin_module_names
:
149 self
.extensions
.remove(ext
)
151 if platform
!= 'mac':
152 # Parse Modules/Setup to figure out which modules are turned
154 input = text_file
.TextFile('Modules/Setup', join_lines
=1)
157 line
= input.readline()
160 remove_modules
.append( line
[0] )
163 for ext
in self
.extensions
[:]:
164 if ext
.name
in remove_modules
:
165 self
.extensions
.remove(ext
)
167 # When you run "make CC=altcc" or something similar, you really want
168 # those environment variables passed into the setup.py phase. Here's
169 # a small set of useful ones.
170 compiler
= os
.environ
.get('CC')
171 linker_so
= os
.environ
.get('LDSHARED')
173 # unfortunately, distutils doesn't let us provide separate C and C++
175 if compiler
is not None:
176 (ccshared
,opt
) = sysconfig
.get_config_vars('CCSHARED','OPT')
177 args
['compiler_so'] = compiler
+ ' ' + opt
+ ' ' + ccshared
178 if linker_so
is not None:
179 args
['linker_so'] = linker_so
180 self
.compiler
.set_executables(**args
)
182 build_ext
.build_extensions(self
)
184 def build_extension(self
, ext
):
187 build_ext
.build_extension(self
, ext
)
188 except (CCompilerError
, DistutilsError
), why
:
189 self
.announce('WARNING: building of extension "%s" failed: %s' %
190 (ext
.name
, sys
.exc_info()[1]))
192 # Workaround for Mac OS X: The Carbon-based modules cannot be
193 # reliably imported into a command-line Python
194 if 'Carbon' in ext
.extra_link_args
:
196 'WARNING: skipping import check for Carbon-based "%s"' %
199 # Workaround for Cygwin: Cygwin currently has fork issues when many
200 # modules have been imported
201 if self
.get_platform() == 'cygwin':
202 self
.announce('WARNING: skipping import check for Cygwin-based "%s"'
205 ext_filename
= os
.path
.join(
207 self
.get_ext_filename(self
.get_ext_fullname(ext
.name
)))
209 imp
.load_dynamic(ext
.name
, ext_filename
)
210 except ImportError, why
:
213 self
.announce('*** WARNING: renaming "%s" since importing it'
214 ' failed: %s' % (ext
.name
, why
))
215 assert not self
.inplace
216 basename
, tail
= os
.path
.splitext(ext_filename
)
217 newname
= basename
+ "_failed" + tail
218 if os
.path
.exists(newname
): os
.remove(newname
)
219 os
.rename(ext_filename
, newname
)
221 # XXX -- This relies on a Vile HACK in
222 # distutils.command.build_ext.build_extension(). The
223 # _built_objects attribute is stored there strictly for
225 # If there is a failure, _built_objects may not be there,
226 # so catch the AttributeError and move on.
228 for filename
in self
._built
_objects
:
230 except AttributeError:
231 self
.announce('unable to remove files (ignored)')
233 self
.announce('*** WARNING: importing extension "%s" '
234 'failed: %s' % (ext
.name
, why
))
236 def get_platform (self
):
237 # Get value of sys.platform
238 platform
= sys
.platform
239 if platform
[:6] =='cygwin':
241 elif platform
[:4] =='beos':
243 elif platform
[:6] == 'darwin':
245 elif platform
[:6] == 'atheos':
250 def detect_modules(self
):
251 # Ensure that /usr/local is always used
252 add_dir_to_list(self
.compiler
.library_dirs
, '/usr/local/lib')
253 add_dir_to_list(self
.compiler
.include_dirs
, '/usr/local/include')
255 if os
.path
.normpath(sys
.prefix
) != '/usr':
256 add_dir_to_list(self
.compiler
.library_dirs
,
257 sysconfig
.get_config_var("LIBDIR"))
258 add_dir_to_list(self
.compiler
.include_dirs
,
259 sysconfig
.get_config_var("INCLUDEDIR"))
262 have_unicode
= unicode
266 # lib_dirs and inc_dirs are used to search for files;
267 # if a file is found in one of those directories, it can
268 # be assumed that no additional -I,-L directives are needed.
269 lib_dirs
= self
.compiler
.library_dirs
+ ['/lib', '/usr/lib']
270 inc_dirs
= self
.compiler
.include_dirs
+ ['/usr/include']
273 platform
= self
.get_platform()
274 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
276 # Check for AtheOS which has libraries in non-standard locations
277 if platform
== 'atheos':
278 lib_dirs
+= ['/system/libs', '/atheos/autolnk/lib']
279 lib_dirs
+= os
.getenv('LIBRARY_PATH', '').split(os
.pathsep
)
280 inc_dirs
+= ['/system/include', '/atheos/autolnk/include']
281 inc_dirs
+= os
.getenv('C_INCLUDE_PATH', '').split(os
.pathsep
)
283 # Check for MacOS X, which doesn't need libm.a at all
285 if platform
in ['darwin', 'beos', 'mac']:
288 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
291 # The following modules are all pretty straightforward, and compile
292 # on pretty much any POSIXish platform.
295 # Some modules that are normally always on:
296 exts
.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
297 exts
.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
299 exts
.append( Extension('_hotshot', ['_hotshot.c']) )
300 exts
.append( Extension('_weakref', ['_weakref.c']) )
301 exts
.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
304 exts
.append( Extension('array', ['arraymodule.c']) )
305 # complex math library functions
306 exts
.append( Extension('cmath', ['cmathmodule.c'],
307 libraries
=math_libs
) )
309 # math library functions, e.g. sin()
310 exts
.append( Extension('math', ['mathmodule.c'],
311 libraries
=math_libs
) )
312 # fast string operations implemented in C
313 exts
.append( Extension('strop', ['stropmodule.c']) )
314 # time operations and variables
315 exts
.append( Extension('time', ['timemodule.c'],
316 libraries
=math_libs
) )
317 exts
.append( Extension('datetime', ['datetimemodule.c'],
318 libraries
=math_libs
) )
319 # random number generator implemented in C
320 exts
.append( Extension("_random", ["_randommodule.c"]) )
321 # operator.add() and similar goodies
322 exts
.append( Extension('operator', ['operator.c']) )
323 # Python C API test module
324 exts
.append( Extension('_testcapi', ['_testcapimodule.c']) )
325 # static Unicode character database
327 exts
.append( Extension('unicodedata', ['unicodedata.c']) )
328 # access to ISO C locale support
329 if platform
in ['cygwin']:
330 locale_libs
= ['intl']
333 exts
.append( Extension('_locale', ['_localemodule.c'],
334 libraries
=locale_libs
) )
336 # Modules with some UNIX dependencies -- on by default:
337 # (If you have a really backward UNIX, select and socket may not be
340 # fcntl(2) and ioctl(2)
341 exts
.append( Extension('fcntl', ['fcntlmodule.c']) )
342 if platform
not in ['mac']:
344 exts
.append( Extension('pwd', ['pwdmodule.c']) )
346 exts
.append( Extension('grp', ['grpmodule.c']) )
347 # select(2); not on ancient System V
348 exts
.append( Extension('select', ['selectmodule.c']) )
350 # The md5 module implements the RSA Data Security, Inc. MD5
351 # Message-Digest Algorithm, described in RFC 1321. The
352 # necessary files md5c.c and md5.h are included here.
353 exts
.append( Extension('md5', ['md5module.c', 'md5c.c']) )
355 # The sha module implements the SHA checksum algorithm.
356 # (NIST's Secure Hash Algorithm.)
357 exts
.append( Extension('sha', ['shamodule.c']) )
359 # Helper module for various ascii-encoders
360 exts
.append( Extension('binascii', ['binascii.c']) )
362 # Fred Drake's interface to the Python parser
363 exts
.append( Extension('parser', ['parsermodule.c']) )
365 # cStringIO and cPickle
366 exts
.append( Extension('cStringIO', ['cStringIO.c']) )
367 exts
.append( Extension('cPickle', ['cPickle.c']) )
369 # Memory-mapped files (also works on Win32).
370 if platform
not in ['atheos', 'mac']:
371 exts
.append( Extension('mmap', ['mmapmodule.c']) )
373 # Lance Ellinghaus's modules:
374 # enigma-inspired encryption
375 exts
.append( Extension('rotor', ['rotormodule.c']) )
376 if platform
not in ['mac']:
377 # syslog daemon interface
378 exts
.append( Extension('syslog', ['syslogmodule.c']) )
380 # George Neville-Neil's timing module:
381 exts
.append( Extension('timing', ['timingmodule.c']) )
384 # Here ends the simple stuff. From here on, modules need certain
385 # libraries, are platform-specific, or present other surprises.
389 # These don't work for 64-bit platforms!!!
390 # These represent audio samples or images as strings:
392 # Disabled on 64-bit platforms
393 if sys
.maxint
!= 9223372036854775807L:
394 # Operations on audio samples
395 exts
.append( Extension('audioop', ['audioop.c']) )
396 # Operations on images
397 exts
.append( Extension('imageop', ['imageop.c']) )
398 # Read SGI RGB image files (but coded portably)
399 exts
.append( Extension('rgbimg', ['rgbimgmodule.c']) )
402 if self
.compiler
.find_library_file(lib_dirs
, 'readline'):
403 readline_libs
= ['readline']
404 if self
.compiler
.find_library_file(lib_dirs
,
406 readline_libs
.append('ncurses')
407 elif self
.compiler
.find_library_file(lib_dirs
+
408 ['/usr/lib/termcap'],
410 readline_libs
.append('termcap')
411 exts
.append( Extension('readline', ['readline.c'],
412 library_dirs
=['/usr/lib/termcap'],
413 libraries
=readline_libs
) )
414 if platform
not in ['mac']:
417 if self
.compiler
.find_library_file(lib_dirs
, 'crypt'):
421 exts
.append( Extension('crypt', ['cryptmodule.c'], libraries
=libs
) )
424 exts
.append( Extension('_socket', ['socketmodule.c'],
425 depends
= ['socketmodule.h']) )
426 # Detect SSL support for the socket module (via _ssl)
427 ssl_incs
= find_file('openssl/ssl.h', inc_dirs
,
428 ['/usr/local/ssl/include',
429 '/usr/contrib/ssl/include/'
432 ssl_libs
= find_library_file(self
.compiler
, 'ssl',lib_dirs
,
433 ['/usr/local/ssl/lib',
434 '/usr/contrib/ssl/lib/'
437 if (ssl_incs
is not None and
438 ssl_libs
is not None):
439 exts
.append( Extension('_ssl', ['_ssl.c'],
440 include_dirs
= ssl_incs
,
441 library_dirs
= ssl_libs
,
442 libraries
= ['ssl', 'crypto'],
443 depends
= ['socketmodule.h']), )
445 # Modules that provide persistent dictionary-like semantics. You will
446 # probably want to arrange for at least one of them to be available on
447 # your machine, though none are defined by default because of library
448 # dependencies. The Python module anydbm.py provides an
449 # implementation independent wrapper for these; dumbdbm.py provides
450 # similar functionality (but slower of course) implemented in Python.
452 # Sleepycat Berkeley DB interface. http://www.sleepycat.com
454 # This requires the Sleepycat DB code. The earliest supported version
455 # of that library is 3.0, the latest supported version is 4.1. A list
456 # of available releases can be found at
458 # http://www.sleepycat.com/update/index.html
460 # when sorted in reverse order, keys for this dict must appear in the
461 # order you wish to search - e.g., search for db4 before db3
463 'db4': {'libs': ('db-4.1', 'db-4.0',),
464 'libdirs': ('/usr/local/BerkeleyDB.4.1/lib',
465 '/usr/local/BerkeleyDB.4.0/lib',
470 'incdirs': ('/usr/local/BerkeleyDB.4.1/include',
471 '/usr/local/BerkeleyDB.4.0/include',
472 '/usr/local/include/db4',
473 '/opt/sfw/include/db4',
477 'db3': {'libs': ('db-3.3', 'db-3.2', 'db-3.1', 'db-3.0'),
478 'libdirs': ('/usr/local/BerkeleyDB.3.3/lib',
479 '/usr/local/BerkeleyDB.3.2/lib',
480 '/usr/local/BerkeleyDB.3.1/lib',
481 '/usr/local/BerkeleyDB.3.0/lib',
486 'incdirs': ('/usr/local/BerkeleyDB.3.3/include',
487 '/usr/local/BerkeleyDB.3.2/include',
488 '/usr/local/BerkeleyDB.3.1/include',
489 '/usr/local/BerkeleyDB.3.0/include',
490 '/usr/local/include/db3',
491 '/opt/sfw/include/db3',
497 db_search_order
= db_try_this
.keys()
498 db_search_order
.sort()
499 db_search_order
.reverse()
501 class found(Exception): pass
503 # See whether there is a Sleepycat header in the standard
507 f
= os
.path
.join(d
, "db.h")
508 if os
.path
.exists(f
):
510 m
= re
.search(r
"#define\WDB_VERSION_MAJOR\W([1-9]+)", f
)
512 std_dbinc
= 'db' + m
.group(1)
513 for dbkey
in db_search_order
:
514 dbd
= db_try_this
[dbkey
]
515 for dblib
in dbd
['libs']:
516 # Prefer version-specific includes over standard
518 db_incs
= find_file('db.h', [], dbd
['incdirs'])
519 dblib_dir
= find_library_file(self
.compiler
,
522 list(dbd
['libdirs']))
523 if (db_incs
or dbkey
== std_dbinc
) and \
524 dblib_dir
is not None:
529 # A default source build puts Berkeley DB in something like
530 # /usr/local/Berkeley.3.3 and the lib dir under that isn't
531 # normally on ld.so's search path, unless the sysadmin has hacked
532 # /etc/ld.so.conf. We add the directory to runtime_library_dirs
533 # so the proper -R/--rpath flags get passed to the linker. This
534 # is usually correct and most trouble free, but may cause problems
535 # in some unusual system configurations (e.g. the directory is on
536 # an NFS server that goes away).
537 exts
.append(Extension('_bsddb', ['_bsddb.c'],
538 library_dirs
=dblib_dir
,
539 runtime_library_dirs
=dblib_dir
,
540 include_dirs
=db_incs
,
547 # The standard Unix dbm module:
548 if platform
not in ['cygwin']:
549 if find_file("ndbm.h", inc_dirs
, []) is not None:
550 # Some systems have -lndbm, others don't
551 if self
.compiler
.find_library_file(lib_dirs
, 'ndbm'):
555 exts
.append( Extension('dbm', ['dbmmodule.c'],
556 define_macros
=[('HAVE_NDBM_H',None)],
557 libraries
= ndbm_libs
) )
558 elif (self
.compiler
.find_library_file(lib_dirs
, 'gdbm')
559 and find_file("gdbm/ndbm.h", inc_dirs
, []) is not None):
560 exts
.append( Extension('dbm', ['dbmmodule.c'],
561 define_macros
=[('HAVE_GDBM_NDBM_H',None)],
562 libraries
= ['gdbm'] ) )
563 elif db_incs
is not None:
564 exts
.append( Extension('dbm', ['dbmmodule.c'],
565 library_dirs
=dblib_dir
,
566 runtime_library_dirs
=dblib_dir
,
567 include_dirs
=db_incs
,
568 define_macros
=[('HAVE_BERKDB_H',None),
569 ('DB_DBM_HSEARCH',None)],
572 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
573 if (self
.compiler
.find_library_file(lib_dirs
, 'gdbm')):
574 exts
.append( Extension('gdbm', ['gdbmmodule.c'],
575 libraries
= ['gdbm'] ) )
577 # The mpz module interfaces to the GNU Multiple Precision library.
578 # You need to ftp the GNU MP library.
579 # This was originally written and tested against GMP 1.2 and 1.3.2.
580 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
581 # haven't tested it recently, and it definitely doesn't work with
582 # GMP 4.0. For more complete modules, refer to
583 # http://gmpy.sourceforge.net and
584 # http://www.egenix.com/files/python/mxNumber.html
586 # A compatible MP library unencumbered by the GPL also exists. It was
587 # posted to comp.sources.misc in volume 40 and is widely available from
588 # FTP archive sites. One URL for it is:
589 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
591 if (self
.compiler
.find_library_file(lib_dirs
, 'gmp')):
592 exts
.append( Extension('mpz', ['mpzmodule.c'],
593 libraries
= ['gmp'] ) )
597 if platform
not in ['mac', 'win32']:
598 # Steen Lumholt's termios module
599 exts
.append( Extension('termios', ['termios.c']) )
600 # Jeremy Hylton's rlimit interface
601 if platform
not in ['atheos']:
602 exts
.append( Extension('resource', ['resource.c']) )
604 # Sun yellow pages. Some systems have the functions in libc.
605 if platform
not in ['cygwin', 'atheos']:
606 if (self
.compiler
.find_library_file(lib_dirs
, 'nsl')):
610 exts
.append( Extension('nis', ['nismodule.c'],
613 # Curses support, requring the System V version of curses, often
614 # provided by the ncurses library.
615 if platform
== 'sunos4':
616 inc_dirs
+= ['/usr/5include']
617 lib_dirs
+= ['/usr/5lib']
619 if (self
.compiler
.find_library_file(lib_dirs
, 'ncurses')):
620 curses_libs
= ['ncurses']
621 exts
.append( Extension('_curses', ['_cursesmodule.c'],
622 libraries
= curses_libs
) )
623 elif (self
.compiler
.find_library_file(lib_dirs
, 'curses')
624 and platform
!= 'darwin'):
625 # OSX has an old Berkeley curses, not good enough for
626 # the _curses module.
627 if (self
.compiler
.find_library_file(lib_dirs
, 'terminfo')):
628 curses_libs
= ['curses', 'terminfo']
630 curses_libs
= ['curses', 'termcap']
632 exts
.append( Extension('_curses', ['_cursesmodule.c'],
633 libraries
= curses_libs
) )
635 # If the curses module is enabled, check for the panel module
636 if (module_enabled(exts
, '_curses') and
637 self
.compiler
.find_library_file(lib_dirs
, 'panel')):
638 exts
.append( Extension('_curses_panel', ['_curses_panel.c'],
639 libraries
= ['panel'] + curses_libs
) )
642 # Andrew Kuchling's zlib module. Note that some versions of zlib
643 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
644 # http://www.cert.org/advisories/CA-2002-07.html
646 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
647 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
648 # now, we still accept 1.1.3, because we think it's difficult to
649 # exploit this in Python, and we'd rather make it RedHat's problem
650 # than our problem <wink>.
652 # You can upgrade zlib to version 1.1.4 yourself by going to
653 # http://www.gzip.org/zlib/
654 zlib_inc
= find_file('zlib.h', [], inc_dirs
)
655 if zlib_inc
is not None:
656 zlib_h
= zlib_inc
[0] + '/zlib.h'
658 version_req
= '"1.1.3"'
664 if line
.startswith('#define ZLIB_VERSION'):
665 version
= line
.split()[2]
667 if version
>= version_req
:
668 if (self
.compiler
.find_library_file(lib_dirs
, 'z')):
669 exts
.append( Extension('zlib', ['zlibmodule.c'],
672 # Gustavo Niemeyer's bz2 module.
673 if (self
.compiler
.find_library_file(lib_dirs
, 'bz2')):
674 exts
.append( Extension('bz2', ['bz2module.c'],
675 libraries
= ['bz2']) )
677 # Interface to the Expat XML parser
679 # Expat was written by James Clark and is now maintained by a
680 # group of developers on SourceForge; see www.libexpat.org for
681 # more information. The pyexpat module was written by Paul
682 # Prescod after a prototype by Jack Jansen. Source of Expat
683 # 1.95.2 is included in Modules/expat/. Usage of a system
684 # shared libexpat.so/expat.dll is not advised.
686 # More information on Expat can be found at www.libexpat.org.
688 if sys
.byteorder
== "little":
692 expatinc
= os
.path
.join(os
.getcwd(), srcdir
, 'Modules', 'expat')
693 exts
.append(Extension('pyexpat',
701 ('HAVE_EXPAT_H',None),
704 ('XML_BYTE_ORDER', xmlbo
),
705 ('XML_CONTEXT_BYTES','1024'),
707 include_dirs
= [expatinc
]
710 # Dynamic loading module
711 if sys
.maxint
== 0x7fffffff:
712 # This requires sizeof(int) == sizeof(long) == sizeof(char*)
713 dl_inc
= find_file('dlfcn.h', [], inc_dirs
)
714 if (dl_inc
is not None) and (platform
not in ['atheos']):
715 exts
.append( Extension('dl', ['dlmodule.c']) )
717 # Platform-specific libraries
718 if platform
== 'linux2':
719 # Linux-specific modules
720 exts
.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
722 if platform
== 'sunos5':
723 # SunOS specific modules
724 exts
.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
726 if platform
== 'darwin':
727 # Mac OS X specific modules.
728 exts
.append( Extension('_CF', ['cf/_CFmodule.c', 'cf/pycfbridge.c'],
729 extra_link_args
=['-framework', 'CoreFoundation']) )
731 exts
.append( Extension('gestalt', ['gestaltmodule.c'],
732 extra_link_args
=['-framework', 'Carbon']) )
733 exts
.append( Extension('MacOS', ['macosmodule.c'],
734 extra_link_args
=['-framework', 'Carbon']) )
735 exts
.append( Extension('icglue', ['icgluemodule.c'],
736 extra_link_args
=['-framework', 'Carbon']) )
737 exts
.append( Extension('_Res', ['res/_Resmodule.c'],
738 extra_link_args
=['-framework', 'Carbon']) )
739 exts
.append( Extension('_Snd', ['snd/_Sndmodule.c'],
740 extra_link_args
=['-framework', 'Carbon']) )
741 exts
.append( Extension('Nav', ['Nav.c'],
742 extra_link_args
=['-framework', 'Carbon']) )
743 exts
.append( Extension('_AE', ['ae/_AEmodule.c'],
744 extra_link_args
=['-framework', 'Carbon']) )
745 exts
.append( Extension('_AH', ['ah/_AHmodule.c'],
746 extra_link_args
=['-framework', 'Carbon']) )
747 exts
.append( Extension('_App', ['app/_Appmodule.c'],
748 extra_link_args
=['-framework', 'Carbon']) )
749 exts
.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
750 extra_link_args
=['-framework', 'Carbon']) )
751 exts
.append( Extension('_CG', ['cg/_CGmodule.c'],
752 extra_link_args
=['-framework', 'ApplicationServices',
753 '-framework', 'Carbon']) )
754 exts
.append( Extension('_Cm', ['cm/_Cmmodule.c'],
755 extra_link_args
=['-framework', 'Carbon']) )
756 exts
.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
757 extra_link_args
=['-framework', 'Carbon']) )
758 exts
.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
759 extra_link_args
=['-framework', 'Carbon']) )
760 exts
.append( Extension('_Drag', ['drag/_Dragmodule.c'],
761 extra_link_args
=['-framework', 'Carbon']) )
762 exts
.append( Extension('_Evt', ['evt/_Evtmodule.c'],
763 extra_link_args
=['-framework', 'Carbon']) )
764 exts
.append( Extension('_File', ['file/_Filemodule.c'],
765 extra_link_args
=['-framework', 'Carbon']) )
766 exts
.append( Extension('_Folder', ['folder/_Foldermodule.c'],
767 extra_link_args
=['-framework', 'Carbon']) )
768 exts
.append( Extension('_Fm', ['fm/_Fmmodule.c'],
769 extra_link_args
=['-framework', 'Carbon']) )
770 exts
.append( Extension('_Help', ['help/_Helpmodule.c'],
771 extra_link_args
=['-framework', 'Carbon']) )
772 exts
.append( Extension('_Icn', ['icn/_Icnmodule.c'],
773 extra_link_args
=['-framework', 'Carbon']) )
774 exts
.append( Extension('_IBCarbon', ['ibcarbon/_IBCarbon.c'],
775 extra_link_args
=['-framework', 'Carbon']) )
776 exts
.append( Extension('_List', ['list/_Listmodule.c'],
777 extra_link_args
=['-framework', 'Carbon']) )
778 exts
.append( Extension('_Menu', ['menu/_Menumodule.c'],
779 extra_link_args
=['-framework', 'Carbon']) )
780 exts
.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
781 extra_link_args
=['-framework', 'Carbon']) )
782 exts
.append( Extension('_Qd', ['qd/_Qdmodule.c'],
783 extra_link_args
=['-framework', 'Carbon']) )
784 exts
.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
785 extra_link_args
=['-framework', 'Carbon']) )
786 exts
.append( Extension('_Qt', ['qt/_Qtmodule.c'],
787 extra_link_args
=['-framework', 'QuickTime',
788 '-framework', 'Carbon']) )
789 exts
.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
790 extra_link_args
=['-framework', 'Carbon']) )
791 exts
.append( Extension('_TE', ['te/_TEmodule.c'],
792 extra_link_args
=['-framework', 'Carbon']) )
793 # As there is no standardized place (yet) to put
794 # user-installed Mac libraries on OSX, we search for "waste"
795 # in parent directories of the Python source tree. You
796 # should put a symlink to your Waste installation in the
797 # same folder as your python source tree. Or modify the
799 waste_incs
= find_file("WASTE.h", [],
800 ['../'*n
+ 'waste/C_C++ Headers' for n
in (0,1,2,3,4)])
801 waste_libs
= find_library_file(self
.compiler
, "WASTE", [],
802 ["../"*n
+ "waste/Static Libraries" for n
in (0,1,2,3,4)])
803 if waste_incs
!= None and waste_libs
!= None:
804 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
805 exts
.append( Extension('waste',
806 ['waste/wastemodule.c'] + [
807 os
.path
.join(srcdir
, d
) for d
in
808 'Mac/Wastemods/WEObjectHandlers.c',
809 'Mac/Wastemods/WETabHooks.c',
810 'Mac/Wastemods/WETabs.c'
812 include_dirs
= waste_incs
+ [os
.path
.join(srcdir
, 'Mac/Wastemods')],
813 library_dirs
= waste_libs
,
814 libraries
= ['WASTE'],
815 extra_link_args
= ['-framework', 'Carbon'],
817 exts
.append( Extension('_Win', ['win/_Winmodule.c'],
818 extra_link_args
=['-framework', 'Carbon']) )
820 self
.extensions
.extend(exts
)
822 # Call the method for detecting whether _tkinter can be compiled
823 self
.detect_tkinter(inc_dirs
, lib_dirs
)
825 def detect_tkinter_darwin(self
, inc_dirs
, lib_dirs
):
826 # The _tkinter module, using frameworks. Since frameworks are quite
827 # different the UNIX search logic is not sharable.
828 from os
.path
import join
, exists
830 '/System/Library/Frameworks/',
831 '/Library/Frameworks',
832 join(os
.getenv('HOME'), '/Library/Frameworks')
835 # Find the directory that contains the Tcl.framwork and Tk.framework
837 # XXX distutils should support -F!
838 for F
in framework_dirs
:
839 # both Tcl.framework and Tk.framework should be present
840 for fw
in 'Tcl', 'Tk':
841 if not exists(join(F
, fw
+ '.framework')):
844 # ok, F is now directory with both frameworks. Continure
848 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
852 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
853 # frameworks. In later release we should hopefully be able to pass
854 # the -F option to gcc, which specifies a framework lookup path.
857 join(F
, fw
+ '.framework', H
)
858 for fw
in 'Tcl', 'Tk'
859 for H
in 'Headers', 'Versions/Current/PrivateHeaders'
862 # For 8.4a2, the X11 headers are not included. Rather than include a
863 # complicated search, this is a hard-coded path. It could bail out
864 # if X11 libs are not found...
865 include_dirs
.append('/usr/X11R6/include')
866 frameworks
= ['-framework', 'Tcl', '-framework', 'Tk']
868 ext
= Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
869 define_macros
=[('WITH_APPINIT', 1)],
870 include_dirs
= include_dirs
,
872 extra_compile_args
= frameworks
,
873 extra_link_args
= frameworks
,
875 self
.extensions
.append(ext
)
879 def detect_tkinter(self
, inc_dirs
, lib_dirs
):
880 # The _tkinter module.
882 # Rather than complicate the code below, detecting and building
883 # AquaTk is a separate method. Only one Tkinter will be built on
884 # Darwin - either AquaTk, if it is found, or X11 based Tk.
885 platform
= self
.get_platform()
886 if platform
== 'darwin' and \
887 self
.detect_tkinter_darwin(inc_dirs
, lib_dirs
):
890 # Assume we haven't found any of the libraries or include files
891 # The versions with dots are used on Unix, and the versions without
892 # dots on Windows, for detection by cygwin.
893 tcllib
= tklib
= tcl_includes
= tk_includes
= None
894 for version
in ['8.4', '84', '8.3', '83', '8.2',
895 '82', '8.1', '81', '8.0', '80']:
896 tklib
= self
.compiler
.find_library_file(lib_dirs
,
898 tcllib
= self
.compiler
.find_library_file(lib_dirs
,
901 # Exit the loop when we've found the Tcl/Tk libraries
904 # Now check for the header files
906 # Check for the include files on Debian, where
907 # they're put in /usr/include/{tcl,tk}X.Y
908 debian_tcl_include
= [ '/usr/include/tcl' + version
]
909 debian_tk_include
= [ '/usr/include/tk' + version
] + \
911 tcl_includes
= find_file('tcl.h', inc_dirs
, debian_tcl_include
)
912 tk_includes
= find_file('tk.h', inc_dirs
, debian_tk_include
)
914 if (tcllib
is None or tklib
is None and
915 tcl_includes
is None or tk_includes
is None):
916 # Something's missing, so give up
919 # OK... everything seems to be present for Tcl/Tk.
921 include_dirs
= [] ; libs
= [] ; defs
= [] ; added_lib_dirs
= []
922 for dir in tcl_includes
+ tk_includes
:
923 if dir not in include_dirs
:
924 include_dirs
.append(dir)
926 # Check for various platform-specific directories
927 if platform
== 'sunos5':
928 include_dirs
.append('/usr/openwin/include')
929 added_lib_dirs
.append('/usr/openwin/lib')
930 elif os
.path
.exists('/usr/X11R6/include'):
931 include_dirs
.append('/usr/X11R6/include')
932 added_lib_dirs
.append('/usr/X11R6/lib')
933 elif os
.path
.exists('/usr/X11R5/include'):
934 include_dirs
.append('/usr/X11R5/include')
935 added_lib_dirs
.append('/usr/X11R5/lib')
937 # Assume default location for X11
938 include_dirs
.append('/usr/X11/include')
939 added_lib_dirs
.append('/usr/X11/lib')
941 # If Cygwin, then verify that X is installed before proceeding
942 if platform
== 'cygwin':
943 x11_inc
= find_file('X11/Xlib.h', [], inc_dirs
)
945 # X header files missing, so give up
948 # Check for BLT extension
949 if self
.compiler
.find_library_file(lib_dirs
+ added_lib_dirs
,
951 defs
.append( ('WITH_BLT', 1) )
952 libs
.append('BLT8.0')
953 elif self
.compiler
.find_library_file(lib_dirs
+ added_lib_dirs
,
955 defs
.append( ('WITH_BLT', 1) )
958 # Add the Tcl/Tk libraries
959 libs
.append('tk'+version
)
960 libs
.append('tcl'+version
)
962 if platform
in ['aix3', 'aix4']:
965 # Finally, link with the X11 libraries (not appropriate on cygwin)
966 if platform
!= "cygwin":
969 ext
= Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
970 define_macros
=[('WITH_APPINIT', 1)] + defs
,
971 include_dirs
= include_dirs
,
973 library_dirs
= added_lib_dirs
,
975 self
.extensions
.append(ext
)
977 # XXX handle these, but how to detect?
978 # *** Uncomment and edit for PIL (TkImaging) extension only:
979 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
980 # *** Uncomment and edit for TOGL extension only:
981 # -DWITH_TOGL togl.c \
982 # *** Uncomment these for TOGL extension only:
983 # -lGL -lGLU -lXext -lXmu \
985 class PyBuildInstall(install
):
986 # Suppress the warning about installation into the lib_dynload
987 # directory, which is not in sys.path when running Python during
989 def initialize_options (self
):
990 install
.initialize_options(self
)
993 class PyBuildInstallLib(install_lib
):
994 # Do exactly what install_lib does but make sure correct access modes get
995 # set on installed directories and files. All installed files with get
996 # mode 644 unless they are a shared library in which case they will get
997 # mode 755. All installed directories will get mode 755.
999 so_ext
= sysconfig
.get_config_var("SO")
1002 outfiles
= install_lib
.install(self
)
1003 self
.set_file_modes(outfiles
, 0644, 0755)
1004 self
.set_dir_modes(self
.install_dir
, 0755)
1007 def set_file_modes(self
, files
, defaultMode
, sharedLibMode
):
1008 if not self
.is_chmod_supported(): return
1009 if not files
: return
1011 for filename
in files
:
1012 if os
.path
.islink(filename
): continue
1014 if filename
.endswith(self
.so_ext
): mode
= sharedLibMode
1015 log
.info("changing mode of %s to %o", filename
, mode
)
1016 if not self
.dry_run
: os
.chmod(filename
, mode
)
1018 def set_dir_modes(self
, dirname
, mode
):
1019 if not self
.is_chmod_supported(): return
1020 os
.path
.walk(dirname
, self
.set_dir_modes_visitor
, mode
)
1022 def set_dir_modes_visitor(self
, mode
, dirname
, names
):
1023 if os
.path
.islink(dirname
): return
1024 log
.info("changing mode of %s to %o", dirname
, mode
)
1025 if not self
.dry_run
: os
.chmod(dirname
, mode
)
1027 def is_chmod_supported(self
):
1028 return hasattr(os
, 'chmod')
1031 # turn off warnings when deprecated modules are imported
1033 warnings
.filterwarnings("ignore",category
=DeprecationWarning)
1034 setup(name
= 'Python standard library',
1035 version
= '%d.%d' % sys
.version_info
[:2],
1036 cmdclass
= {'build_ext':PyBuildExt
, 'install':PyBuildInstall
,
1037 'install_lib':PyBuildInstallLib
},
1038 # The struct module is defined here, because build_ext won't be
1039 # called unless there's at least one extension module defined.
1040 ext_modules
=[Extension('struct', ['structmodule.c'])],
1042 # Scripts to install
1043 scripts
= ['Tools/scripts/pydoc']
1047 if __name__
== '__main__':