setup.py revision 93227275dcf18196c1b81a3c884dbd2e78c8f440
1# Autodetecting setup.py script for building the Python extensions 2# 3 4__version__ = "$Revision$" 5 6import sys, os, getopt 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 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. 21 22 'filename' is the name of a file, such as readline.h or libcrypto.a. 23 'std_dirs' is the list of standard system directories; if the 24 file is found in one of them, no additional directives are needed. 25 'paths' is a list of additional locations to check; if the file is 26 found in one of them, the resulting list will contain the directory. 27 """ 28 29 # Check the standard locations 30 for dir in std_dirs: 31 f = os.path.join(dir, filename) 32 if os.path.exists(f): return [] 33 34 # Check the additional directories 35 for dir in paths: 36 f = os.path.join(dir, filename) 37 if os.path.exists(f): 38 return [dir] 39 40 # Not found anywhere 41 return None 42 43def 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 47 48 filename = compiler.library_filename(libname, lib_type='static') 49 result = find_file(filename, std_dirs, paths) 50 return result 51 52def module_enabled(extlist, modname): 53 """Returns whether the module 'modname' is present in the list 54 of extensions 'extlist'.""" 55 extlist = [ext for ext in extlist if ext.name == modname] 56 return len(extlist) 57 58def find_module_file(module, dirlist): 59 """Find a module in a set of possible folders. If it is not found 60 return the unadorned filename""" 61 list = find_file(module, [], dirlist) 62 if not list: 63 return module 64 if len(list) > 1: 65 self.announce("WARNING: multiple copies of %s found"%module) 66 return os.path.join(list[0], module) 67 68class PyBuildExt(build_ext): 69 70 def build_extensions(self): 71 72 # Detect which modules should be compiled 73 self.detect_modules() 74 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] 78 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') 82 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) 89 90 moddirlist = [moddir] 91 incdirlist = ['./Include'] 92 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') 100 101 # Fix up the paths for scripts, too 102 self.distribution.scripts = [os.path.join(srcdir, filename) 103 for filename in self.distribution.scripts] 104 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) ) 111 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) 116 117 # Parse Modules/Setup to figure out which modules are turned 118 # on in the file. 119 input = text_file.TextFile('Modules/Setup', join_lines=1) 120 remove_modules = [] 121 while 1: 122 line = input.readline() 123 if not line: break 124 line = line.split() 125 remove_modules.append( line[0] ) 126 input.close() 127 128 for ext in self.extensions[:]: 129 if ext.name in remove_modules: 130 self.extensions.remove(ext) 131 132 # When you run "make CC=altcc" or something similar, you really want 133 # those environment variables passed into the setup.py phase. Here's 134 # a small set of useful ones. 135 compiler = os.environ.get('CC') 136 linker_so = os.environ.get('LDSHARED') 137 args = {} 138 # unfortunately, distutils doesn't let us provide separate C and C++ 139 # compilers 140 if compiler is not None: 141 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT') 142 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared 143 if linker_so is not None: 144 args['linker_so'] = linker_so 145 self.compiler.set_executables(**args) 146 147 build_ext.build_extensions(self) 148 149 def build_extension(self, ext): 150 151 try: 152 build_ext.build_extension(self, ext) 153 except (CCompilerError, DistutilsError), why: 154 self.announce('WARNING: building of extension "%s" failed: %s' % 155 (ext.name, sys.exc_info()[1])) 156 return 157 # Workaround for Mac OS X: The Carbon-based modules cannot be 158 # reliably imported into a command-line Python 159 if 'Carbon' in ext.extra_link_args: 160 self.announce( 161 'WARNING: skipping import check for Carbon-based "%s"' % 162 ext.name) 163 return 164 try: 165 __import__(ext.name) 166 except ImportError: 167 self.announce('WARNING: removing "%s" since importing it failed' % 168 ext.name) 169 assert not self.inplace 170 fullname = self.get_ext_fullname(ext.name) 171 ext_filename = os.path.join(self.build_lib, 172 self.get_ext_filename(fullname)) 173 os.remove(ext_filename) 174 175 # XXX -- This relies on a Vile HACK in 176 # distutils.command.build_ext.build_extension(). The 177 # _built_objects attribute is stored there strictly for 178 # use here. 179 for filename in self._built_objects: 180 os.remove(filename) 181 182 def get_platform (self): 183 # Get value of sys.platform 184 platform = sys.platform 185 if platform[:6] =='cygwin': 186 platform = 'cygwin' 187 elif platform[:4] =='beos': 188 platform = 'beos' 189 elif platform[:6] == 'darwin': 190 platform = 'darwin' 191 192 return platform 193 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' ) 200 201 try: 202 have_unicode = unicode 203 except NameError: 204 have_unicode = 0 205 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'] 211 exts = [] 212 213 platform = self.get_platform() 214 215 # Check for MacOS X, which doesn't need libm.a at all 216 math_libs = ['m'] 217 if platform in ['darwin', 'beos']: 218 math_libs = [] 219 220 # XXX Omitted modules: gl, pure, dl, SGI-specific modules 221 222 # 223 # The following modules are all pretty straightforward, and compile 224 # on pretty much any POSIXish platform. 225 # 226 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']) ) 230 231 exts.append( Extension('_hotshot', ['_hotshot.c']) ) 232 exts.append( Extension('_weakref', ['_weakref.c']) ) 233 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) ) 234 235 # array objects 236 exts.append( Extension('array', ['arraymodule.c']) ) 237 # complex math library functions 238 exts.append( Extension('cmath', ['cmathmodule.c'], 239 libraries=math_libs) ) 240 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 256 if have_unicode: 257 exts.append( Extension('unicodedata', ['unicodedata.c']) ) 258 # access to ISO C locale support 259 exts.append( Extension('_locale', ['_localemodule.c']) ) 260 261 # Modules with some UNIX dependencies -- on by default: 262 # (If you have a really backward UNIX, select and socket may not be 263 # supported...) 264 265 # fcntl(2) and ioctl(2) 266 exts.append( Extension('fcntl', ['fcntlmodule.c']) ) 267 # pwd(3) 268 exts.append( Extension('pwd', ['pwdmodule.c']) ) 269 # grp(3) 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']) ) 275 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']) ) 280 281 # The sha module implements the SHA checksum algorithm. 282 # (NIST's Secure Hash Algorithm.) 283 exts.append( Extension('sha', ['shamodule.c']) ) 284 285 # Helper module for various ascii-encoders 286 exts.append( Extension('binascii', ['binascii.c']) ) 287 288 # Fred Drake's interface to the Python parser 289 exts.append( Extension('parser', ['parsermodule.c']) ) 290 291 # Digital Creations' cStringIO and cPickle 292 exts.append( Extension('cStringIO', ['cStringIO.c']) ) 293 exts.append( Extension('cPickle', ['cPickle.c']) ) 294 295 # Memory-mapped files (also works on Win32). 296 exts.append( Extension('mmap', ['mmapmodule.c']) ) 297 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']) ) 303 304 # George Neville-Neil's timing module: 305 exts.append( Extension('timing', ['timingmodule.c']) ) 306 307 # 308 # Here ends the simple stuff. From here on, modules need certain 309 # libraries, are platform-specific, or present other surprises. 310 # 311 312 # Multimedia modules 313 # These don't work for 64-bit platforms!!! 314 # These represent audio samples or images as strings: 315 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']) ) 324 325 # readline 326 if self.compiler.find_library_file(lib_dirs, 'readline'): 327 readline_libs = ['readline'] 328 if self.compiler.find_library_file(lib_dirs, 329 'ncurses'): 330 readline_libs.append('ncurses') 331 elif self.compiler.find_library_file(lib_dirs + 332 ['/usr/lib/termcap'], 333 'termcap'): 334 readline_libs.append('termcap') 335 exts.append( Extension('readline', ['readline.c'], 336 library_dirs=['/usr/lib/termcap'], 337 libraries=readline_libs) ) 338 339 # crypt module. 340 341 if self.compiler.find_library_file(lib_dirs, 'crypt'): 342 libs = ['crypt'] 343 else: 344 libs = [] 345 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) ) 346 347 # socket(2) 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/' 352 ] 353 ) 354 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, 355 ['/usr/local/ssl/lib', 356 '/usr/contrib/ssl/lib/' 357 ] ) 358 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)] ) ) 366 else: 367 exts.append( Extension('_socket', ['socketmodule.c']) ) 368 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. 375 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'] ) ) 384 else: 385 exts.append( Extension('dbm', ['dbmmodule.c']) ) 386 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'] ) ) 391 392 # Berkeley DB interface. 393 # 394 # This requires the Berkeley DB code, see 395 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz 396 # 397 # Edit the variables DB and DBPORT to point to the db top directory 398 # and the subdirectory of PORT where you built it. 399 # 400 # (See http://pybsddb.sourceforge.net/ for an interface to 401 # Berkeley DB 3.x.) 402 403 dblib = [] 404 if self.compiler.find_library_file(lib_dirs, 'db-3.2'): 405 dblib = ['db-3.2'] 406 elif self.compiler.find_library_file(lib_dirs, 'db-3.1'): 407 dblib = ['db-3.1'] 408 elif self.compiler.find_library_file(lib_dirs, 'db3'): 409 dblib = ['db3'] 410 elif self.compiler.find_library_file(lib_dirs, 'db2'): 411 dblib = ['db2'] 412 elif self.compiler.find_library_file(lib_dirs, 'db1'): 413 dblib = ['db1'] 414 elif self.compiler.find_library_file(lib_dirs, 'db'): 415 dblib = ['db'] 416 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, 428 libraries = dblib) ) 429 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 438 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 443 444 if (self.compiler.find_library_file(lib_dirs, 'gmp')): 445 exts.append( Extension('mpz', ['mpzmodule.c'], 446 libraries = ['gmp'] ) ) 447 448 449 # Unix-only modules 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']) ) 455 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')): 459 libs = ['nsl'] 460 else: 461 libs = [] 462 exts.append( Extension('nis', ['nismodule.c'], 463 libraries = libs) ) 464 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'] 470 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'] 481 else: 482 curses_libs = ['curses', 'termcap'] 483 484 exts.append( Extension('_curses', ['_cursesmodule.c'], 485 libraries = curses_libs) ) 486 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) ) 492 493 494 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: 498 499 if platform == 'irix5': 500 # For SGI IRIX (tested on 5.3): 501 exts.append( Extension('fpectl', ['fpectlmodule.c'], 502 libraries=['fpe']) ) 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 506 # -lsunmath.) 507 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm 508 pass 509 else: 510 # For other systems: see instructions in fpectlmodule.c. 511 #fpectl fpectlmodule.c ... 512 exts.append( Extension('fpectl', ['fpectlmodule.c']) ) 513 514 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' 521 version = '"0.0.0"' 522 version_req = '"1.1.3"' 523 fp = open(zlib_h) 524 while 1: 525 line = fp.readline() 526 if not line: 527 break 528 if line.find('#define ZLIB_VERSION', 0) == 0: 529 version = line.split()[2] 530 break 531 if version >= version_req: 532 if (self.compiler.find_library_file(lib_dirs, 'z')): 533 exts.append( Extension('zlib', ['zlibmodule.c'], 534 libraries = ['z']) ) 535 536 # Interface to the Expat XML parser 537 # 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. 541 # 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. 545 # 546 # EXPAT_DIR, below, should point to the expat/ directory created by 547 # unpacking the Expat source distribution. 548 # 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 552 # run: 553 # 554 # ar cr libexpat.a xmltok/*.o xmlparse/*.o 555 # 556 expat_defs = [] 557 expat_incs = find_file('expat.h', inc_dirs, []) 558 if expat_incs is not None: 559 # expat.h was found 560 expat_defs = [('HAVE_EXPAT_H', 1)] 561 else: 562 expat_incs = find_file('xmlparse.h', inc_dirs, []) 563 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']) ) 569 570 # Dynamic loading module 571 dl_inc = find_file('dlfcn.h', [], inc_dirs) 572 if dl_inc is not None: 573 exts.append( Extension('dl', ['dlmodule.c']) ) 574 575 # Platform-specific libraries 576 if platform == 'linux2': 577 # Linux-specific modules 578 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) 579 580 if platform == 'sunos5': 581 # SunOS specific modules 582 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) 583 584 if platform == 'darwin': 585 # Mac OS X specific modules. These are ported over from MacPython 586 # and still experimental. Some (such as gestalt or icglue) are 587 # already generally useful, some (the GUI ones) really need to 588 # be used from a framework. 589 # 590 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't 591 # available here. This Makefile variable is also what the install 592 # procedure triggers on. 593 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR') 594 exts.append( Extension('gestalt', ['gestaltmodule.c']) ) 595 exts.append( Extension('MacOS', ['macosmodule.c'], 596 extra_link_args=['-framework', 'Carbon']) ) 597 exts.append( Extension('icglue', ['icgluemodule.c'], 598 extra_link_args=['-framework', 'Carbon']) ) 599 exts.append( Extension('macfs', 600 ['macfsmodule.c', 601 '../Python/getapplbycreator.c'], 602 extra_link_args=['-framework', 'Carbon']) ) 603 exts.append( Extension('_CF', ['cf/_CFmodule.c']) ) 604 exts.append( Extension('_Res', ['res/_Resmodule.c']) ) 605 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'], 606 extra_link_args=['-framework', 'Carbon']) ) 607 if frameworkdir: 608 exts.append( Extension('Nav', ['Nav.c'], 609 extra_link_args=['-framework', 'Carbon']) ) 610 exts.append( Extension('_AE', ['ae/_AEmodule.c'], 611 extra_link_args=['-framework', 'Carbon']) ) 612 exts.append( Extension('_App', ['app/_Appmodule.c'], 613 extra_link_args=['-framework', 'Carbon']) ) 614 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'], 615 extra_link_args=['-framework', 'Carbon']) ) 616 exts.append( Extension('_CG', ['cg/_CGmodule.c'], 617 extra_link_args=['-framework', 'ApplicationServices', 618 '-framework', 'Carbon']) ) 619 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'], 620 extra_link_args=['-framework', 'Carbon']) ) 621 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'], 622 extra_link_args=['-framework', 'Carbon']) ) 623 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'], 624 extra_link_args=['-framework', 'Carbon']) ) 625 exts.append( Extension('_Drag', ['drag/_Dragmodule.c'], 626 extra_link_args=['-framework', 'Carbon']) ) 627 exts.append( Extension('_Evt', ['evt/_Evtmodule.c'], 628 extra_link_args=['-framework', 'Carbon']) ) 629 exts.append( Extension('_Fm', ['fm/_Fmmodule.c'], 630 extra_link_args=['-framework', 'Carbon']) ) 631 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'], 632 extra_link_args=['-framework', 'Carbon']) ) 633 exts.append( Extension('_List', ['list/_Listmodule.c'], 634 extra_link_args=['-framework', 'Carbon']) ) 635 exts.append( Extension('_Menu', ['menu/_Menumodule.c'], 636 extra_link_args=['-framework', 'Carbon']) ) 637 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'], 638 extra_link_args=['-framework', 'Carbon']) ) 639 exts.append( Extension('_Qd', ['qd/_Qdmodule.c'], 640 extra_link_args=['-framework', 'Carbon']) ) 641 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'], 642 extra_link_args=['-framework', 'Carbon']) ) 643 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'], 644 extra_link_args=['-framework', 'QuickTime', 645 '-framework', 'Carbon']) ) 646## exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c']) ) 647 exts.append( Extension('_TE', ['te/_TEmodule.c'], 648 extra_link_args=['-framework', 'Carbon']) ) 649 # As there is no standardized place (yet) to put user-installed 650 # Mac libraries on OSX you should put a symlink to your Waste 651 # installation in the same folder as your python source tree. 652 # Or modify the next two lines:-) 653 waste_incs = find_file("WASTE.h", [], ["../waste/C_C++ Headers"]) 654 waste_libs = find_library_file(self.compiler, "WASTE", [], 655 ["../waste/Static Libraries"]) 656 if waste_incs != None and waste_libs != None: 657 exts.append( Extension('waste', 658 ['waste/wastemodule.c', 659 'Mac/Wastemods/WEObjectHandlers.c', 660 'Mac/Wastemods/WETabHooks.c', 661 'Mac/Wastemods/WETabs.c' 662 ], 663 include_dirs = waste_incs + ['Mac/Wastemods'], 664 library_dirs = waste_libs, 665 libraries = ['WASTE'], 666 extra_link_args = ['-framework', 'Carbon'], 667 ) ) 668 exts.append( Extension('_Win', ['win/_Winmodule.c'], 669 extra_link_args=['-framework', 'Carbon']) ) 670 671 self.extensions.extend(exts) 672 673 # Call the method for detecting whether _tkinter can be compiled 674 self.detect_tkinter(inc_dirs, lib_dirs) 675 676 677 def detect_tkinter(self, inc_dirs, lib_dirs): 678 # The _tkinter module. 679 680 # Assume we haven't found any of the libraries or include files 681 # The versions with dots are used on Unix, and the versions without 682 # dots on Windows, for detection by cygwin. 683 tcllib = tklib = tcl_includes = tk_includes = None 684 for version in ['8.4', '84', '8.3', '83', '8.2', 685 '82', '8.1', '81', '8.0', '80']: 686 tklib = self.compiler.find_library_file(lib_dirs, 687 'tk' + version ) 688 tcllib = self.compiler.find_library_file(lib_dirs, 689 'tcl' + version ) 690 if tklib and tcllib: 691 # Exit the loop when we've found the Tcl/Tk libraries 692 break 693 694 # Now check for the header files 695 if tklib and tcllib: 696 # Check for the include files on Debian, where 697 # they're put in /usr/include/{tcl,tk}X.Y 698 debian_tcl_include = [ '/usr/include/tcl' + version ] 699 debian_tk_include = [ '/usr/include/tk' + version ] + \ 700 debian_tcl_include 701 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include) 702 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include) 703 704 if (tcllib is None or tklib is None and 705 tcl_includes is None or tk_includes is None): 706 # Something's missing, so give up 707 return 708 709 # OK... everything seems to be present for Tcl/Tk. 710 711 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] 712 for dir in tcl_includes + tk_includes: 713 if dir not in include_dirs: 714 include_dirs.append(dir) 715 716 # Check for various platform-specific directories 717 platform = self.get_platform() 718 if platform == 'sunos5': 719 include_dirs.append('/usr/openwin/include') 720 added_lib_dirs.append('/usr/openwin/lib') 721 elif os.path.exists('/usr/X11R6/include'): 722 include_dirs.append('/usr/X11R6/include') 723 added_lib_dirs.append('/usr/X11R6/lib') 724 elif os.path.exists('/usr/X11R5/include'): 725 include_dirs.append('/usr/X11R5/include') 726 added_lib_dirs.append('/usr/X11R5/lib') 727 else: 728 # Assume default location for X11 729 include_dirs.append('/usr/X11/include') 730 added_lib_dirs.append('/usr/X11/lib') 731 732 # If Cygwin, then verify that X is installed before proceeding 733 if platform == 'cygwin': 734 x11_inc = find_file('X11/Xlib.h', [], inc_dirs) 735 if x11_inc is None: 736 # X header files missing, so give up 737 return 738 739 # Check for BLT extension 740 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 741 'BLT8.0'): 742 defs.append( ('WITH_BLT', 1) ) 743 libs.append('BLT8.0') 744 745 # Add the Tcl/Tk libraries 746 libs.append('tk'+version) 747 libs.append('tcl'+version) 748 749 if platform in ['aix3', 'aix4']: 750 libs.append('ld') 751 752 # Finally, link with the X11 libraries (not appropriate on cygwin) 753 if platform != "cygwin": 754 libs.append('X11') 755 756 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], 757 define_macros=[('WITH_APPINIT', 1)] + defs, 758 include_dirs = include_dirs, 759 libraries = libs, 760 library_dirs = added_lib_dirs, 761 ) 762 self.extensions.append(ext) 763 764 # XXX handle these, but how to detect? 765 # *** Uncomment and edit for PIL (TkImaging) extension only: 766 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ 767 # *** Uncomment and edit for TOGL extension only: 768 # -DWITH_TOGL togl.c \ 769 # *** Uncomment these for TOGL extension only: 770 # -lGL -lGLU -lXext -lXmu \ 771 772class PyBuildInstall(install): 773 # Suppress the warning about installation into the lib_dynload 774 # directory, which is not in sys.path when running Python during 775 # installation: 776 def initialize_options (self): 777 install.initialize_options(self) 778 self.warn_dir=0 779 780def main(): 781 # turn off warnings when deprecated modules are imported 782 import warnings 783 warnings.filterwarnings("ignore",category=DeprecationWarning) 784 setup(name = 'Python standard library', 785 version = '%d.%d' % sys.version_info[:2], 786 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall}, 787 # The struct module is defined here, because build_ext won't be 788 # called unless there's at least one extension module defined. 789 ext_modules=[Extension('struct', ['structmodule.c'])], 790 791 # Scripts to install 792 scripts = ['Tools/scripts/pydoc'] 793 ) 794 795# --install-platlib 796if __name__ == '__main__': 797 sysconfig.set_python_build() 798 main() 799