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