1 # Autodetecting setup.py script for building the Python extensions
4 __version__
= "$Revision$"
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.
29 # Check the standard locations
31 f
= os
.path
.join(dir, filename
)
32 if os
.path
.exists(f
): return []
34 # Check the additional directories
36 f
= os
.path
.join(dir, filename
)
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
)
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
]
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
)
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
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
)
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
119 input = text_file
.TextFile('Modules/Setup', join_lines
=1)
122 line
= input.readline()
125 remove_modules
.append( line
[0] )
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')
138 # unfortunately, distutils doesn't let us provide separate C and C++
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
):
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]))
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
:
161 'WARNING: skipping import check for Carbon-based "%s"' %
167 self
.announce('WARNING: removing "%s" since importing it failed' %
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
179 for filename
in self
._built
_objects
:
182 def get_platform (self
):
183 # Get value of sys.platform
184 platform
= sys
.platform
185 if platform
[:6] =='cygwin':
187 elif platform
[:4] =='beos':
189 elif platform
[:6] == 'darwin':
194 def detect_modules(self
):
195 # Ensure that /usr/local is always used
196 if '/usr/local/lib' not in self
.compiler
.library_dirs
:
197 self
.compiler
.library_dirs
.insert(0, '/usr/local/lib')
198 if '/usr/local/include' not in self
.compiler
.include_dirs
:
199 self
.compiler
.include_dirs
.insert(0, '/usr/local/include' )
202 have_unicode
= unicode
206 # lib_dirs and inc_dirs are used to search for files;
207 # if a file is found in one of those directories, it can
208 # be assumed that no additional -I,-L directives are needed.
209 lib_dirs
= self
.compiler
.library_dirs
+ ['/lib', '/usr/lib']
210 inc_dirs
= self
.compiler
.include_dirs
+ ['/usr/include']
213 platform
= self
.get_platform()
215 # Check for MacOS X, which doesn't need libm.a at all
217 if platform
in ['darwin', 'beos']:
220 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
223 # The following modules are all pretty straightforward, and compile
224 # on pretty much any POSIXish platform.
227 # Some modules that are normally always on:
228 exts
.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
229 exts
.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
231 exts
.append( Extension('_hotshot', ['_hotshot.c']) )
232 exts
.append( Extension('_weakref', ['_weakref.c']) )
233 exts
.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
236 exts
.append( Extension('array', ['arraymodule.c']) )
237 # complex math library functions
238 exts
.append( Extension('cmath', ['cmathmodule.c'],
239 libraries
=math_libs
) )
241 # math library functions, e.g. sin()
242 exts
.append( Extension('math', ['mathmodule.c'],
243 libraries
=math_libs
) )
244 # fast string operations implemented in C
245 exts
.append( Extension('strop', ['stropmodule.c']) )
246 # time operations and variables
247 exts
.append( Extension('time', ['timemodule.c'],
248 libraries
=math_libs
) )
249 # operator.add() and similar goodies
250 exts
.append( Extension('operator', ['operator.c']) )
251 # access to the builtin codecs and codec registry
252 exts
.append( Extension('_codecs', ['_codecsmodule.c']) )
253 # Python C API test module
254 exts
.append( Extension('_testcapi', ['_testcapimodule.c']) )
255 # static Unicode character database
257 exts
.append( Extension('unicodedata', ['unicodedata.c']) )
258 # access to ISO C locale support
259 exts
.append( Extension('_locale', ['_localemodule.c']) )
261 # Modules with some UNIX dependencies -- on by default:
262 # (If you have a really backward UNIX, select and socket may not be
265 # fcntl(2) and ioctl(2)
266 exts
.append( Extension('fcntl', ['fcntlmodule.c']) )
268 exts
.append( Extension('pwd', ['pwdmodule.c']) )
270 exts
.append( Extension('grp', ['grpmodule.c']) )
271 # posix (UNIX) errno values
272 exts
.append( Extension('errno', ['errnomodule.c']) )
273 # select(2); not on ancient System V
274 exts
.append( Extension('select', ['selectmodule.c']) )
276 # The md5 module implements the RSA Data Security, Inc. MD5
277 # Message-Digest Algorithm, described in RFC 1321. The
278 # necessary files md5c.c and md5.h are included here.
279 exts
.append( Extension('md5', ['md5module.c', 'md5c.c']) )
281 # The sha module implements the SHA checksum algorithm.
282 # (NIST's Secure Hash Algorithm.)
283 exts
.append( Extension('sha', ['shamodule.c']) )
285 # Helper module for various ascii-encoders
286 exts
.append( Extension('binascii', ['binascii.c']) )
288 # Fred Drake's interface to the Python parser
289 exts
.append( Extension('parser', ['parsermodule.c']) )
291 # Digital Creations' cStringIO and cPickle
292 exts
.append( Extension('cStringIO', ['cStringIO.c']) )
293 exts
.append( Extension('cPickle', ['cPickle.c']) )
295 # Memory-mapped files (also works on Win32).
296 exts
.append( Extension('mmap', ['mmapmodule.c']) )
298 # Lance Ellinghaus's modules:
299 # enigma-inspired encryption
300 exts
.append( Extension('rotor', ['rotormodule.c']) )
301 # syslog daemon interface
302 exts
.append( Extension('syslog', ['syslogmodule.c']) )
304 # George Neville-Neil's timing module:
305 exts
.append( Extension('timing', ['timingmodule.c']) )
308 # Here ends the simple stuff. From here on, modules need certain
309 # libraries, are platform-specific, or present other surprises.
313 # These don't work for 64-bit platforms!!!
314 # These represent audio samples or images as strings:
316 # Disabled on 64-bit platforms
317 if sys
.maxint
!= 9223372036854775807L:
318 # Operations on audio samples
319 exts
.append( Extension('audioop', ['audioop.c']) )
320 # Operations on images
321 exts
.append( Extension('imageop', ['imageop.c']) )
322 # Read SGI RGB image files (but coded portably)
323 exts
.append( Extension('rgbimg', ['rgbimgmodule.c']) )
326 if self
.compiler
.find_library_file(lib_dirs
, 'readline'):
327 readline_libs
= ['readline']
328 if self
.compiler
.find_library_file(lib_dirs
,
330 readline_libs
.append('ncurses')
331 elif self
.compiler
.find_library_file(lib_dirs
+
332 ['/usr/lib/termcap'],
334 readline_libs
.append('termcap')
335 exts
.append( Extension('readline', ['readline.c'],
336 library_dirs
=['/usr/lib/termcap'],
337 libraries
=readline_libs
) )
341 if self
.compiler
.find_library_file(lib_dirs
, 'crypt'):
345 exts
.append( Extension('crypt', ['cryptmodule.c'], libraries
=libs
) )
348 # Detect SSL support for the socket module
349 ssl_incs
= find_file('openssl/ssl.h', inc_dirs
,
350 ['/usr/local/ssl/include',
351 '/usr/contrib/ssl/include/'
354 ssl_libs
= find_library_file(self
.compiler
, 'ssl',lib_dirs
,
355 ['/usr/local/ssl/lib',
356 '/usr/contrib/ssl/lib/'
359 if (ssl_incs
is not None and
360 ssl_libs
is not None):
361 exts
.append( Extension('_socket', ['socketmodule.c'],
362 include_dirs
= ssl_incs
,
363 library_dirs
= ssl_libs
,
364 libraries
= ['ssl', 'crypto'],
365 define_macros
= [('USE_SSL',1)] ) )
367 exts
.append( Extension('_socket', ['socketmodule.c']) )
369 # Modules that provide persistent dictionary-like semantics. You will
370 # probably want to arrange for at least one of them to be available on
371 # your machine, though none are defined by default because of library
372 # dependencies. The Python module anydbm.py provides an
373 # implementation independent wrapper for these; dumbdbm.py provides
374 # similar functionality (but slower of course) implemented in Python.
376 # The standard Unix dbm module:
377 if platform
not in ['cygwin']:
378 if (self
.compiler
.find_library_file(lib_dirs
, 'ndbm')):
379 exts
.append( Extension('dbm', ['dbmmodule.c'],
380 libraries
= ['ndbm'] ) )
381 elif self
.compiler
.find_library_file(lib_dirs
, 'db1'):
382 exts
.append( Extension('dbm', ['dbmmodule.c'],
383 libraries
= ['db1'] ) )
385 exts
.append( Extension('dbm', ['dbmmodule.c']) )
387 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
388 if (self
.compiler
.find_library_file(lib_dirs
, 'gdbm')):
389 exts
.append( Extension('gdbm', ['gdbmmodule.c'],
390 libraries
= ['gdbm'] ) )
392 # Berkeley DB interface.
394 # This requires the Berkeley DB code, see
395 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
397 # Edit the variables DB and DBPORT to point to the db top directory
398 # and the subdirectory of PORT where you built it.
400 # (See http://pybsddb.sourceforge.net/ for an interface to
404 if self
.compiler
.find_library_file(lib_dirs
, 'db-3.2'):
406 elif self
.compiler
.find_library_file(lib_dirs
, 'db-3.1'):
408 elif self
.compiler
.find_library_file(lib_dirs
, 'db3'):
410 elif self
.compiler
.find_library_file(lib_dirs
, 'db2'):
412 elif self
.compiler
.find_library_file(lib_dirs
, 'db1'):
414 elif self
.compiler
.find_library_file(lib_dirs
, 'db'):
417 db185_incs
= find_file('db_185.h', inc_dirs
,
418 ['/usr/include/db3', '/usr/include/db2'])
419 db_inc
= find_file('db.h', inc_dirs
, ['/usr/include/db1'])
420 if db185_incs
is not None:
421 exts
.append( Extension('bsddb', ['bsddbmodule.c'],
422 include_dirs
= db185_incs
,
423 define_macros
=[('HAVE_DB_185_H',1)],
424 libraries
= dblib
) )
425 elif db_inc
is not None:
426 exts
.append( Extension('bsddb', ['bsddbmodule.c'],
427 include_dirs
= db_inc
,
430 # The mpz module interfaces to the GNU Multiple Precision library.
431 # You need to ftp the GNU MP library.
432 # This was originally written and tested against GMP 1.2 and 1.3.2.
433 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
434 # haven't tested it recently, and it definitely doesn't work with
435 # GMP 4.0. For more complete modules, refer to
436 # http://gmpy.sourceforge.net and
437 # http://www.egenix.com/files/python/mxNumber.html
439 # A compatible MP library unencumbered by the GPL also exists. It was
440 # posted to comp.sources.misc in volume 40 and is widely available from
441 # FTP archive sites. One URL for it is:
442 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
444 if (self
.compiler
.find_library_file(lib_dirs
, 'gmp')):
445 exts
.append( Extension('mpz', ['mpzmodule.c'],
446 libraries
= ['gmp'] ) )
450 if platform
not in ['mac', 'win32']:
451 # Steen Lumholt's termios module
452 exts
.append( Extension('termios', ['termios.c']) )
453 # Jeremy Hylton's rlimit interface
454 exts
.append( Extension('resource', ['resource.c']) )
456 # Sun yellow pages. Some systems have the functions in libc.
457 if platform
not in ['cygwin']:
458 if (self
.compiler
.find_library_file(lib_dirs
, 'nsl')):
462 exts
.append( Extension('nis', ['nismodule.c'],
465 # Curses support, requring the System V version of curses, often
466 # provided by the ncurses library.
467 if platform
== 'sunos4':
468 inc_dirs
+= ['/usr/5include']
469 lib_dirs
+= ['/usr/5lib']
471 if (self
.compiler
.find_library_file(lib_dirs
, 'ncurses')):
472 curses_libs
= ['ncurses']
473 exts
.append( Extension('_curses', ['_cursesmodule.c'],
474 libraries
= curses_libs
) )
475 elif (self
.compiler
.find_library_file(lib_dirs
, 'curses')
476 and platform
!= 'darwin'):
477 # OSX has an old Berkeley curses, not good enough for
478 # the _curses module.
479 if (self
.compiler
.find_library_file(lib_dirs
, 'terminfo')):
480 curses_libs
= ['curses', 'terminfo']
482 curses_libs
= ['curses', 'termcap']
484 exts
.append( Extension('_curses', ['_cursesmodule.c'],
485 libraries
= curses_libs
) )
487 # If the curses module is enabled, check for the panel module
488 if (module_enabled(exts
, '_curses') and
489 self
.compiler
.find_library_file(lib_dirs
, 'panel')):
490 exts
.append( Extension('_curses_panel', ['_curses_panel.c'],
491 libraries
= ['panel'] + curses_libs
) )
495 # Lee Busby's SIGFPE modules.
496 # The library to link fpectl with is platform specific.
497 # Choose *one* of the options below for fpectl:
499 if platform
== 'irix5':
500 # For SGI IRIX (tested on 5.3):
501 exts
.append( Extension('fpectl', ['fpectlmodule.c'],
503 elif 0: # XXX how to detect SunPro?
504 # For Solaris with SunPro compiler (tested on Solaris 2.5
505 # with SunPro C 4.2): (Without the compiler you don't have
507 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
510 # For other systems: see instructions in fpectlmodule.c.
511 #fpectl fpectlmodule.c ...
512 exts
.append( Extension('fpectl', ['fpectlmodule.c']) )
515 # Andrew Kuchling's zlib module.
516 # This require zlib 1.1.3 (or later).
517 # See http://www.cdrom.com/pub/infozip/zlib/
518 zlib_inc
= find_file('zlib.h', [], inc_dirs
)
519 if zlib_inc
is not None:
520 zlib_h
= zlib_inc
[0] + '/zlib.h'
522 version_req
= '"1.1.3"'
528 if line
.find('#define ZLIB_VERSION', 0) == 0:
529 version
= line
.split()[2]
531 if version
>= version_req
:
532 if (self
.compiler
.find_library_file(lib_dirs
, 'z')):
533 exts
.append( Extension('zlib', ['zlibmodule.c'],
536 # Interface to the Expat XML parser
538 # Expat is written by James Clark and must be downloaded separately
539 # (see below). The pyexpat module was written by Paul Prescod after a
540 # prototype by Jack Jansen.
542 # The Expat dist includes Windows .lib and .dll files. Home page is
543 # at http://www.jclark.com/xml/expat.html, the current production
544 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
546 # EXPAT_DIR, below, should point to the expat/ directory created by
547 # unpacking the Expat source distribution.
549 # Note: the expat build process doesn't yet build a libexpat.a; you
550 # can do this manually while we try convince the author to add it. To
551 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
554 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
557 expat_incs
= find_file('expat.h', inc_dirs
, [])
558 if expat_incs
is not None:
560 expat_defs
= [('HAVE_EXPAT_H', 1)]
562 expat_incs
= find_file('xmlparse.h', inc_dirs
, [])
564 if (expat_incs
is not None and
565 self
.compiler
.find_library_file(lib_dirs
, 'expat')):
566 exts
.append( Extension('pyexpat', ['pyexpat.c'],
567 define_macros
= expat_defs
,
568 libraries
= ['expat']) )
570 # Platform-specific libraries
571 if platform
== 'linux2':
572 # Linux-specific modules
573 exts
.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
575 if platform
== 'sunos5':
576 # SunOS specific modules
577 exts
.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
579 if platform
== 'darwin':
580 # Mac OS X specific modules. These are ported over from MacPython
581 # and still experimental. Some (such as gestalt or icglue) are
582 # already generally useful, some (the GUI ones) really need to
583 # be used from a framework.
585 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
586 # available here. This Makefile variable is also what the install
587 # procedure triggers on.
588 frameworkdir
= sysconfig
.get_config_var('PYTHONFRAMEWORKDIR')
589 exts
.append( Extension('gestalt', ['gestaltmodule.c']) )
590 exts
.append( Extension('MacOS', ['macosmodule.c'],
591 extra_link_args
=['-framework', 'Carbon']) )
592 exts
.append( Extension('icglue', ['icgluemodule.c'],
593 extra_link_args
=['-framework', 'Carbon']) )
594 exts
.append( Extension('macfs',
596 '../Python/getapplbycreator.c'],
597 extra_link_args
=['-framework', 'Carbon']) )
598 exts
.append( Extension('_CF', ['cf/_CFmodule.c']) )
599 exts
.append( Extension('_Res', ['res/_Resmodule.c']) )
600 exts
.append( Extension('_Snd', ['snd/_Sndmodule.c'],
601 extra_link_args
=['-framework', 'Carbon']) )
603 exts
.append( Extension('Nav', ['Nav.c'],
604 extra_link_args
=['-framework', 'Carbon']) )
605 exts
.append( Extension('_AE', ['ae/_AEmodule.c'],
606 extra_link_args
=['-framework', 'Carbon']) )
607 exts
.append( Extension('_App', ['app/_Appmodule.c'],
608 extra_link_args
=['-framework', 'Carbon']) )
609 exts
.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
610 extra_link_args
=['-framework', 'Carbon']) )
611 exts
.append( Extension('_CG', ['cg/_CGmodule.c'],
612 extra_link_args
=['-framework', 'ApplicationServices',
613 '-framework', 'Carbon']) )
614 exts
.append( Extension('_Cm', ['cm/_Cmmodule.c'],
615 extra_link_args
=['-framework', 'Carbon']) )
616 exts
.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
617 extra_link_args
=['-framework', 'Carbon']) )
618 exts
.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
619 extra_link_args
=['-framework', 'Carbon']) )
620 exts
.append( Extension('_Drag', ['drag/_Dragmodule.c'],
621 extra_link_args
=['-framework', 'Carbon']) )
622 exts
.append( Extension('_Evt', ['evt/_Evtmodule.c'],
623 extra_link_args
=['-framework', 'Carbon']) )
624 exts
.append( Extension('_Fm', ['fm/_Fmmodule.c'],
625 extra_link_args
=['-framework', 'Carbon']) )
626 exts
.append( Extension('_Icn', ['icn/_Icnmodule.c'],
627 extra_link_args
=['-framework', 'Carbon']) )
628 exts
.append( Extension('_List', ['list/_Listmodule.c'],
629 extra_link_args
=['-framework', 'Carbon']) )
630 exts
.append( Extension('_Menu', ['menu/_Menumodule.c'],
631 extra_link_args
=['-framework', 'Carbon']) )
632 exts
.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
633 extra_link_args
=['-framework', 'Carbon']) )
634 exts
.append( Extension('_Qd', ['qd/_Qdmodule.c'],
635 extra_link_args
=['-framework', 'Carbon']) )
636 exts
.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
637 extra_link_args
=['-framework', 'Carbon']) )
638 exts
.append( Extension('_Qt', ['qt/_Qtmodule.c'],
639 extra_link_args
=['-framework', 'QuickTime',
640 '-framework', 'Carbon']) )
641 ## exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c']) )
642 exts
.append( Extension('_TE', ['te/_TEmodule.c'],
643 extra_link_args
=['-framework', 'Carbon']) )
644 # As there is no standardized place (yet) to put user-installed
645 # Mac libraries on OSX you should put a symlink to your Waste
646 # installation in the same folder as your python source tree.
647 # Or modify the next two lines:-)
648 waste_incs
= find_file("WASTE.h", [], ["../waste/C_C++ Headers"])
649 waste_libs
= find_library_file(self
.compiler
, "WASTE", [],
650 ["../waste/Static Libraries"])
651 if waste_incs
!= None and waste_libs
!= None:
652 exts
.append( Extension('waste',
653 ['waste/wastemodule.c',
654 'Mac/Wastemods/WEObjectHandlers.c',
655 'Mac/Wastemods/WETabHooks.c',
656 'Mac/Wastemods/WETabs.c'
658 include_dirs
= waste_incs
+ ['Mac/Wastemods'],
659 library_dirs
= waste_libs
,
660 libraries
= ['WASTE'],
661 extra_link_args
= ['-framework', 'Carbon'],
663 exts
.append( Extension('_Win', ['win/_Winmodule.c'],
664 extra_link_args
=['-framework', 'Carbon']) )
666 self
.extensions
.extend(exts
)
668 # Call the method for detecting whether _tkinter can be compiled
669 self
.detect_tkinter(inc_dirs
, lib_dirs
)
672 def detect_tkinter(self
, inc_dirs
, lib_dirs
):
673 # The _tkinter module.
675 # Assume we haven't found any of the libraries or include files
676 # The versions with dots are used on Unix, and the versions without
677 # dots on Windows, for detection by cygwin.
678 tcllib
= tklib
= tcl_includes
= tk_includes
= None
679 for version
in ['8.4', '84', '8.3', '83', '8.2',
680 '82', '8.1', '81', '8.0', '80']:
681 tklib
= self
.compiler
.find_library_file(lib_dirs
,
683 tcllib
= self
.compiler
.find_library_file(lib_dirs
,
686 # Exit the loop when we've found the Tcl/Tk libraries
689 # Now check for the header files
691 # Check for the include files on Debian, where
692 # they're put in /usr/include/{tcl,tk}X.Y
693 debian_tcl_include
= [ '/usr/include/tcl' + version
]
694 debian_tk_include
= [ '/usr/include/tk' + version
] + \
696 tcl_includes
= find_file('tcl.h', inc_dirs
, debian_tcl_include
)
697 tk_includes
= find_file('tk.h', inc_dirs
, debian_tk_include
)
699 if (tcllib
is None or tklib
is None and
700 tcl_includes
is None or tk_includes
is None):
701 # Something's missing, so give up
704 # OK... everything seems to be present for Tcl/Tk.
706 include_dirs
= [] ; libs
= [] ; defs
= [] ; added_lib_dirs
= []
707 for dir in tcl_includes
+ tk_includes
:
708 if dir not in include_dirs
:
709 include_dirs
.append(dir)
711 # Check for various platform-specific directories
712 platform
= self
.get_platform()
713 if platform
== 'sunos5':
714 include_dirs
.append('/usr/openwin/include')
715 added_lib_dirs
.append('/usr/openwin/lib')
716 elif os
.path
.exists('/usr/X11R6/include'):
717 include_dirs
.append('/usr/X11R6/include')
718 added_lib_dirs
.append('/usr/X11R6/lib')
719 elif os
.path
.exists('/usr/X11R5/include'):
720 include_dirs
.append('/usr/X11R5/include')
721 added_lib_dirs
.append('/usr/X11R5/lib')
723 # Assume default location for X11
724 include_dirs
.append('/usr/X11/include')
725 added_lib_dirs
.append('/usr/X11/lib')
727 # If Cygwin, then verify that X is installed before proceeding
728 if platform
== 'cygwin':
729 x11_inc
= find_file('X11/Xlib.h', [], inc_dirs
)
731 # X header files missing, so give up
734 # Check for BLT extension
735 if self
.compiler
.find_library_file(lib_dirs
+ added_lib_dirs
,
737 defs
.append( ('WITH_BLT', 1) )
738 libs
.append('BLT8.0')
740 # Add the Tcl/Tk libraries
741 libs
.append('tk'+version
)
742 libs
.append('tcl'+version
)
744 if platform
in ['aix3', 'aix4']:
747 # Finally, link with the X11 libraries (not appropriate on cygwin)
748 if platform
!= "cygwin":
751 ext
= Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
752 define_macros
=[('WITH_APPINIT', 1)] + defs
,
753 include_dirs
= include_dirs
,
755 library_dirs
= added_lib_dirs
,
757 self
.extensions
.append(ext
)
759 # XXX handle these, but how to detect?
760 # *** Uncomment and edit for PIL (TkImaging) extension only:
761 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
762 # *** Uncomment and edit for TOGL extension only:
763 # -DWITH_TOGL togl.c \
764 # *** Uncomment these for TOGL extension only:
765 # -lGL -lGLU -lXext -lXmu \
767 class PyBuildInstall(install
):
768 # Suppress the warning about installation into the lib_dynload
769 # directory, which is not in sys.path when running Python during
771 def initialize_options (self
):
772 install
.initialize_options(self
)
776 # turn off warnings when deprecated modules are imported
778 warnings
.filterwarnings("ignore",category
=DeprecationWarning)
779 setup(name
= 'Python standard library',
780 version
= '%d.%d' % sys
.version_info
[:2],
781 cmdclass
= {'build_ext':PyBuildExt
, 'install':PyBuildInstall
},
782 # The struct module is defined here, because build_ext won't be
783 # called unless there's at least one extension module defined.
784 ext_modules
=[Extension('struct', ['structmodule.c'])],
787 scripts
= ['Tools/scripts/pydoc']
791 if __name__
== '__main__':
792 sysconfig
.set_python_build()