setup.py 31.9 KB
Newer Older
1 2
# Autodetecting setup.py script for building the Python extensions
#
3

4 5 6
__version__ = "$Revision$"

import sys, os, getopt
7
from distutils import sysconfig
8
from distutils import text_file
9
from distutils.errors import *
10 11
from distutils.core import Extension, setup
from distutils.command.build_ext import build_ext
12
from distutils.command.install import install
13 14 15 16

# This global variable is used to hold the list of modules to be disabled.
disabled_module_list = []

17 18 19 20
def find_file(filename, std_dirs, paths):
    """Searches for the directory where a given file is located,
    and returns a possibly-empty list of additional directories, or None
    if the file couldn't be found at all.
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    'filename' is the name of a file, such as readline.h or libcrypto.a.
    'std_dirs' is the list of standard system directories; if the
        file is found in one of them, no additional directives are needed.
    'paths' is a list of additional locations to check; if the file is
        found in one of them, the resulting list will contain the directory.
    """

    # Check the standard locations
    for dir in std_dirs:
        f = os.path.join(dir, filename)
        if os.path.exists(f): return []

    # Check the additional directories
    for dir in paths:
        f = os.path.join(dir, filename)
        if os.path.exists(f):
            return [dir]

    # Not found anywhere
41 42
    return None

43 44 45 46
def find_library_file(compiler, libname, std_dirs, paths):
    filename = compiler.library_filename(libname, lib_type='shared')
    result = find_file(filename, std_dirs, paths)
    if result is not None: return result
47

48 49 50 51
    filename = compiler.library_filename(libname, lib_type='static')
    result = find_file(filename, std_dirs, paths)
    return result

52 53 54 55 56
def module_enabled(extlist, modname):
    """Returns whether the module 'modname' is present in the list
    of extensions 'extlist'."""
    extlist = [ext for ext in extlist if ext.name == modname]
    return len(extlist)
57

58 59 60 61 62 63 64 65 66 67
def find_module_file(module, dirlist):
    """Find a module in a set of possible folders. If it is not found
    return the unadorned filename"""
    list = find_file(module, [], dirlist)
    if not list:
        return module
    if len(list) > 1:
        self.announce("WARNING: multiple copies of %s found"%module)
    return os.path.join(list[0], module)
    
68
class PyBuildExt(build_ext):
69

70 71 72 73 74 75 76 77
    def build_extensions(self):

        # Detect which modules should be compiled
        self.detect_modules()

        # Remove modules that are present on the disabled list
        self.extensions = [ext for ext in self.extensions
                           if ext.name not in disabled_module_list]
78

79 80 81 82
        # Fix up the autodetected modules, prefixing all the source files
        # with Modules/ and adding Python's include directory to the path.
        (srcdir,) = sysconfig.get_config_vars('srcdir')

83 84
        # Figure out the location of the source code for extension modules
        moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
85 86 87 88
        moddir = os.path.normpath(moddir)
        srcdir, tail = os.path.split(moddir)
        srcdir = os.path.normpath(srcdir)
        moddir = os.path.normpath(moddir)
89 90 91 92 93 94 95 96 97 98 99
        
        moddirlist = [moddir]
        incdirlist = ['./Include']
        
        # Platform-dependent module source and include directories
        platform = self.get_platform()
        if platform == 'darwin1':
            # Mac OS X also includes some mac-specific modules
            macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
            moddirlist.append(macmoddir)
            incdirlist.append('./Mac/Include')
100

101 102 103 104
        # Fix up the paths for scripts, too
        self.distribution.scripts = [os.path.join(srcdir, filename)
                                     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 109 110
            ext.include_dirs.append( '.' ) # to get config.h
            for incdir in incdirlist:
                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 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        # Parse Modules/Setup to figure out which modules are turned
        # on in the file. 
        input = text_file.TextFile('Modules/Setup', join_lines=1)
        remove_modules = []
        while 1:
            line = input.readline()
            if not line: break
            line = line.split()
            remove_modules.append( line[0] )
        input.close()
        
        for ext in self.extensions[:]:
            if ext.name in remove_modules:
                self.extensions.remove(ext)
        
132 133 134 135 136 137 138 139 140
        # When you run "make CC=altcc" or something similar, you really want
        # those environment variables passed into the setup.py phase.  Here's
        # a small set of useful ones.
        compiler = os.environ.get('CC')
        linker_so = os.environ.get('LDSHARED')
        args = {}
        # unfortunately, distutils doesn't let us provide separate C and C++
        # compilers
        if compiler is not None:
141 142
            (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
            args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
143
        if linker_so is not None:
144
            args['linker_so'] = linker_so
145 146
        self.compiler.set_executables(**args)

147 148
        build_ext.build_extensions(self)

149 150 151 152 153 154 155
    def build_extension(self, ext):

        try:
            build_ext.build_extension(self, ext)
        except (CCompilerError, DistutilsError), why:
            self.announce('WARNING: building of extension "%s" failed: %s' %
                          (ext.name, sys.exc_info()[1]))
156
            return
157 158 159 160 161
        # Workaround for Mac OS X: The Carbon-based modules cannot be
        # reliably imported into a command-line Python
        if 'Carbon' in ext.extra_link_args:
        	self.announce('WARNING: skipping import check for Carbon-based "%s"' % ext.name)
        	return
162 163 164 165 166 167 168 169 170 171
        try:
            __import__(ext.name)
        except ImportError:
            self.announce('WARNING: removing "%s" since importing it failed' %
                          ext.name)
            assert not self.inplace
            fullname = self.get_ext_fullname(ext.name)
            ext_filename = os.path.join(self.build_lib,
                                        self.get_ext_filename(fullname))
            os.remove(ext_filename)
172

173
    def get_platform (self):
174 175 176 177
        # Get value of sys.platform
        platform = sys.platform
        if platform[:6] =='cygwin':
            platform = 'cygwin'
178 179
        elif platform[:4] =='beos':
            platform = 'beos'
180

181
        return platform
182

183
    def detect_modules(self):
184
        # Ensure that /usr/local is always used
185
        if '/usr/local/lib' not in self.compiler.library_dirs:
186
            self.compiler.library_dirs.insert(0, '/usr/local/lib')
187
        if '/usr/local/include' not in self.compiler.include_dirs:
188
            self.compiler.include_dirs.insert(0, '/usr/local/include' )
189

190 191 192 193 194
        try:
            have_unicode = unicode
        except NameError:
            have_unicode = 0

195 196 197 198
        # lib_dirs and inc_dirs are used to search for files;
        # if a file is found in one of those directories, it can
        # be assumed that no additional -I,-L directives are needed.
        lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
199
        inc_dirs = self.compiler.include_dirs + ['/usr/include'] 
200 201
        exts = []

202
        platform = self.get_platform()
203
        
204 205
        # Check for MacOS X, which doesn't need libm.a at all
        math_libs = ['m']
206
        if platform in ['Darwin1.2', 'beos']:
207
            math_libs = []
208
        
209 210 211 212 213 214
        # XXX Omitted modules: gl, pure, dl, SGI-specific modules

        #
        # The following modules are all pretty straightforward, and compile
        # on pretty much any POSIXish platform.
        #
215

216 217 218
        # Some modules that are normally always on:
        exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
        exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
219

Fred Drake's avatar
Fred Drake committed
220
        exts.append( Extension('_hotshot', ['_hotshot.c']) )
221
        exts.append( Extension('_weakref', ['_weakref.c']) )
Andrew M. Kuchling's avatar
Andrew M. Kuchling committed
222
        exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
223 224 225 226

        # array objects
        exts.append( Extension('array', ['arraymodule.c']) )
        # complex math library functions
227 228
        exts.append( Extension('cmath', ['cmathmodule.c'],
                               libraries=math_libs) )
229

230
        # math library functions, e.g. sin()
231 232
        exts.append( Extension('math',  ['mathmodule.c'],
                               libraries=math_libs) )
233 234 235
        # fast string operations implemented in C
        exts.append( Extension('strop', ['stropmodule.c']) )
        # time operations and variables
236 237
        exts.append( Extension('time', ['timemodule.c'],
                               libraries=math_libs) )
238 239 240 241
        # operator.add() and similar goodies
        exts.append( Extension('operator', ['operator.c']) )
        # access to the builtin codecs and codec registry
        exts.append( Extension('_codecs', ['_codecsmodule.c']) )
242
        # Python C API test module
243
        exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
244
        # static Unicode character database
245 246
        if have_unicode:
            exts.append( Extension('unicodedata', ['unicodedata.c']) )
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
        # access to ISO C locale support
        exts.append( Extension('_locale', ['_localemodule.c']) )

        # Modules with some UNIX dependencies -- on by default:
        # (If you have a really backward UNIX, select and socket may not be
        # supported...)

        # fcntl(2) and ioctl(2)
        exts.append( Extension('fcntl', ['fcntlmodule.c']) )
        # pwd(3)
        exts.append( Extension('pwd', ['pwdmodule.c']) )
        # grp(3)
        exts.append( Extension('grp', ['grpmodule.c']) )
        # posix (UNIX) errno values
        exts.append( Extension('errno', ['errnomodule.c']) )
        # select(2); not on ancient System V
        exts.append( Extension('select', ['selectmodule.c']) )

        # The md5 module implements the RSA Data Security, Inc. MD5
        # Message-Digest Algorithm, described in RFC 1321.  The necessary files
        # md5c.c and md5.h are included here.
        exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )

        # The sha module implements the SHA checksum algorithm.
        # (NIST's Secure Hash Algorithm.)
        exts.append( Extension('sha', ['shamodule.c']) )

        # Helper module for various ascii-encoders
        exts.append( Extension('binascii', ['binascii.c']) )

        # Fred Drake's interface to the Python parser
        exts.append( Extension('parser', ['parsermodule.c']) )

        # Digital Creations' cStringIO and cPickle
        exts.append( Extension('cStringIO', ['cStringIO.c']) )
        exts.append( Extension('cPickle', ['cPickle.c']) )

        # Memory-mapped files (also works on Win32).
        exts.append( Extension('mmap', ['mmapmodule.c']) )

        # Lance Ellinghaus's modules:
        # enigma-inspired encryption
        exts.append( Extension('rotor', ['rotormodule.c']) )
        # syslog daemon interface
        exts.append( Extension('syslog', ['syslogmodule.c']) )

        # George Neville-Neil's timing module:
        exts.append( Extension('timing', ['timingmodule.c']) )

        #
297 298
        # Here ends the simple stuff.  From here on, modules need certain
        # libraries, are platform-specific, or present other surprises.
299 300 301 302 303 304
        #

        # Multimedia modules
        # These don't work for 64-bit platforms!!!
        # These represent audio samples or images as strings:

305
        # Disabled on 64-bit platforms
306 307 308 309 310 311 312 313 314
        if sys.maxint != 9223372036854775807L:
            # Operations on audio samples
            exts.append( Extension('audioop', ['audioop.c']) )
            # Operations on images
            exts.append( Extension('imageop', ['imageop.c']) )
            # Read SGI RGB image files (but coded portably)
            exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )

        # readline
315 316
        if self.compiler.find_library_file(lib_dirs, 'readline'):
            readline_libs = ['readline']
317 318 319 320
            if self.compiler.find_library_file(lib_dirs,
                                                 'ncurses'):
                readline_libs.append('ncurses')
            elif self.compiler.find_library_file(lib_dirs +
321 322 323
                                               ['/usr/lib/termcap'],
                                               'termcap'):
                readline_libs.append('termcap')
324
            exts.append( Extension('readline', ['readline.c'],
325
                                   library_dirs=['/usr/lib/termcap'],
326
                                   libraries=readline_libs) )
327

328
        # crypt module.
329 330 331 332 333 334 335 336 337

        if self.compiler.find_library_file(lib_dirs, 'crypt'):
            libs = ['crypt']
        else:
            libs = []
        exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )

        # socket(2)
        # Detect SSL support for the socket module
338
        ssl_incs = find_file('openssl/ssl.h', inc_dirs,
339 340 341
                             ['/usr/local/ssl/include',
                              '/usr/contrib/ssl/include/'
                             ]
342 343
                             )
        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
344 345 346
                                     ['/usr/local/ssl/lib',
                                      '/usr/contrib/ssl/lib/'
                                     ] )
347

348 349
        if (ssl_incs is not None and
            ssl_libs is not None):
350
            exts.append( Extension('_socket', ['socketmodule.c'],
351
                                   include_dirs = ssl_incs,
352
                                   library_dirs = ssl_libs,
353 354 355 356 357 358 359 360 361 362 363 364 365
                                   libraries = ['ssl', 'crypto'],
                                   define_macros = [('USE_SSL',1)] ) )
        else:
            exts.append( Extension('_socket', ['socketmodule.c']) )

        # Modules that provide persistent dictionary-like semantics.  You will
        # probably want to arrange for at least one of them to be available on
        # your machine, though none are defined by default because of library
        # dependencies.  The Python module anydbm.py provides an
        # implementation independent wrapper for these; dumbdbm.py provides
        # similar functionality (but slower of course) implemented in Python.

        # The standard Unix dbm module:
366 367 368 369
        if platform not in ['cygwin']:
            if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
                exts.append( Extension('dbm', ['dbmmodule.c'],
                                       libraries = ['ndbm'] ) )
370 371 372
            elif self.compiler.find_library_file(lib_dirs, 'db1'):
                exts.append( Extension('dbm', ['dbmmodule.c'],
                                       libraries = ['db1'] ) )
373 374
            else:
                exts.append( Extension('dbm', ['dbmmodule.c']) )
375

376 377 378 379 380 381 382 383 384 385 386 387 388
        # Anthony Baxter's gdbm module.  GNU dbm(3) will require -lgdbm:
        if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
            exts.append( Extension('gdbm', ['gdbmmodule.c'],
                                   libraries = ['gdbm'] ) )

        # Berkeley DB interface.
        #
        # This requires the Berkeley DB code, see
        # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
        #
        # Edit the variables DB and DBPORT to point to the db top directory
        # and the subdirectory of PORT where you built it.
        #
389 390
        # (See http://pybsddb.sourceforge.net/ for an interface to
        # Berkeley DB 3.x.)
391

392
        dblib = []
393 394
        if self.compiler.find_library_file(lib_dirs, 'db-3.1'):
            dblib = ['db-3.1']
395 396
        elif self.compiler.find_library_file(lib_dirs, 'db3'):
            dblib = ['db3']
397 398 399 400 401
        elif self.compiler.find_library_file(lib_dirs, 'db2'):
            dblib = ['db2']
        elif self.compiler.find_library_file(lib_dirs, 'db1'):
            dblib = ['db1']
        elif self.compiler.find_library_file(lib_dirs, 'db'):
402 403 404 405 406 407
            dblib = ['db']
        
        db185_incs = find_file('db_185.h', inc_dirs,
                               ['/usr/include/db3', '/usr/include/db2'])
        db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
        if db185_incs is not None:
408
            exts.append( Extension('bsddb', ['bsddbmodule.c'],
409 410 411 412 413 414 415
                                   include_dirs = db185_incs,
                                   define_macros=[('HAVE_DB_185_H',1)],
                                   libraries = dblib ) )
        elif db_inc is not None:
            exts.append( Extension('bsddb', ['bsddbmodule.c'],
                                   include_dirs = db_inc,
                                   libraries = dblib) )
416 417

        # The mpz module interfaces to the GNU Multiple Precision library.
418
        # You need to ftp the GNU MP library.
419 420 421 422 423
        # This was originally written and tested against GMP 1.2 and 1.3.2.
        # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
        # haven't tested it recently.   For a more complete module,
        # refer to pympz.sourceforge.net.

424
        # A compatible MP library unencumbered by the GPL also exists.  It was
425 426 427 428 429 430 431 432 433 434
        # posted to comp.sources.misc in volume 40 and is widely available from
        # FTP archive sites. One URL for it is:
        # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z

        if (self.compiler.find_library_file(lib_dirs, 'gmp')):
            exts.append( Extension('mpz', ['mpzmodule.c'],
                                   libraries = ['gmp'] ) )


        # Unix-only modules
435
        if platform not in ['mac', 'win32']:
436 437 438
            # Steen Lumholt's termios module
            exts.append( Extension('termios', ['termios.c']) )
            # Jeremy Hylton's rlimit interface
439
            exts.append( Extension('resource', ['resource.c']) )
440

441
            # Sun yellow pages. Some systems have the functions in libc.
442 443 444 445 446 447 448
            if platform not in ['cygwin']:
                if (self.compiler.find_library_file(lib_dirs, 'nsl')):
                    libs = ['nsl']
                else:
                    libs = []
                exts.append( Extension('nis', ['nismodule.c'],
                                       libraries = libs) )
449 450

        # Curses support, requring the System V version of curses, often
451
        # provided by the ncurses library.
452
        if platform == 'sunos4':
453
            inc_dirs += ['/usr/5include']
454 455 456 457 458 459
            lib_dirs += ['/usr/5lib']

        if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
            curses_libs = ['ncurses']
            exts.append( Extension('_curses', ['_cursesmodule.c'],
                                   libraries = curses_libs) )
460 461
        elif (self.compiler.find_library_file(lib_dirs, 'curses')) and platform != 'darwin1':
        	# OSX has an old Berkeley curses, not good enough for the _curses module.
462 463 464 465
            if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
                curses_libs = ['curses', 'terminfo']
            else:
                curses_libs = ['curses', 'termcap']
466

467 468
            exts.append( Extension('_curses', ['_cursesmodule.c'],
                                   libraries = curses_libs) )
469

470 471 472 473 474 475
        # If the curses module is enabled, check for the panel module
        if (os.path.exists('Modules/_curses_panel.c') and
            module_enabled(exts, '_curses') and
            self.compiler.find_library_file(lib_dirs, 'panel')):
            exts.append( Extension('_curses_panel', ['_curses_panel.c'],
                                   libraries = ['panel'] + curses_libs) )
476 477


478 479 480 481 482

        # Lee Busby's SIGFPE modules.
        # The library to link fpectl with is platform specific.
        # Choose *one* of the options below for fpectl:

483
        if platform == 'irix5':
484 485 486
            # For SGI IRIX (tested on 5.3):
            exts.append( Extension('fpectl', ['fpectlmodule.c'],
                                   libraries=['fpe']) )
487
        elif 0: # XXX how to detect SunPro?
488 489 490 491 492 493 494 495 496 497 498 499 500
            # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
            # (Without the compiler you don't have -lsunmath.)
            #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
            pass
        else:
            # For other systems: see instructions in fpectlmodule.c.
            #fpectl fpectlmodule.c ...
            exts.append( Extension('fpectl', ['fpectlmodule.c']) )


        # Andrew Kuchling's zlib module.
        # This require zlib 1.1.3 (or later).
        # See http://www.cdrom.com/pub/infozip/zlib/
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
        zlib_inc = find_file('zlib.h', [], inc_dirs)
        if zlib_inc is not None:
            zlib_h = zlib_inc[0] + '/zlib.h'
            version = '"0.0.0"'
            version_req = '"1.1.3"'
            fp = open(zlib_h)
            while 1:
                line = fp.readline()
                if not line:
                    break
                if line.find('#define ZLIB_VERSION', 0) == 0:
                    version = line.split()[2]
                    break
            if version >= version_req:
                if (self.compiler.find_library_file(lib_dirs, 'z')):
                    exts.append( Extension('zlib', ['zlibmodule.c'],
                                           libraries = ['z']) )
518 519 520 521 522 523 524

        # Interface to the Expat XML parser
        #
        # Expat is written by James Clark and must be downloaded separately
        # (see below).  The pyexpat module was written by Paul Prescod after a
        # prototype by Jack Jansen.
        #
525 526 527
        # The Expat dist includes Windows .lib and .dll files.  Home page is
        # at http://www.jclark.com/xml/expat.html, the current production
        # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
528 529 530 531
        #
        # EXPAT_DIR, below, should point to the expat/ directory created by
        # unpacking the Expat source distribution.
        #
532 533 534 535
        # Note: the expat build process doesn't yet build a libexpat.a; you
        # can do this manually while we try convince the author to add it.  To
        # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
        # run:
536 537 538
        #
        #    ar cr libexpat.a xmltok/*.o xmlparse/*.o
        #
539 540 541 542 543 544 545
        expat_defs = []
        expat_incs = find_file('expat.h', inc_dirs, [])
        if expat_incs is not None:
            # expat.h was found
            expat_defs = [('HAVE_EXPAT_H', 1)]
        else:
            expat_incs = find_file('xmlparse.h', inc_dirs, [])
546

547
        if (expat_incs is not None and
548 549 550 551
            self.compiler.find_library_file(lib_dirs, 'expat')):
            exts.append( Extension('pyexpat', ['pyexpat.c'],
                                   define_macros = expat_defs,
                                   libraries = ['expat']) )
552 553

        # Platform-specific libraries
554
        if platform == 'linux2':
555 556 557
            # Linux-specific modules
            exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )

558
        if platform == 'sunos5':
559
            # SunOS specific modules
560
            exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
561 562 563 564 565 566
        
        if platform == 'darwin1':
            # Mac OS X specific modules. These are ported over from MacPython
            # and still experimental. Some (such as gestalt or icglue) are
            # already generally useful, some (the GUI ones) really need to
            # be used from a framework.
567 568 569 570 571
            #
            # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
            # available here. This Makefile variable is also what the install
            # procedure triggers on.
            frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
572
            exts.append( Extension('gestalt', ['gestaltmodule.c']) )
573 574 575 576 577 578 579 580 581 582
            exts.append( Extension('MacOS', ['macosmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
            exts.append( Extension('icglue', ['icgluemodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
            exts.append( Extension('macfs', ['macfsmodule.c', '../Python/getapplbycreator.c'],
            		extra_link_args=['-framework', 'Carbon']) )
            exts.append( Extension('_CF', ['cf/_CFmodule.c']) )
            exts.append( Extension('_Res', ['res/_Resmodule.c']) )
            exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
583
            if frameworkdir:
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
                exts.append( Extension('Nav', ['Nav.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_AE', ['ae/_AEmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_App', ['app/_Appmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Drag', ['drag/_Dragmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Evt', ['evt/_Evtmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Fm', ['fm/_Fmmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_List', ['list/_Listmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Qd', ['qd/_Qdmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
                exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
614
                exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
615
                        extra_link_args=['-framework', 'QuickTime', '-framework', 'Carbon']) )
616
##              exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c']) )
617 618
                exts.append( Extension('_TE', ['te/_TEmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
619
##              exts.append( Extension('waste', ['waste/wastemodule.c']) )
620 621
                exts.append( Extension('_Win', ['win/_Winmodule.c'],
            		extra_link_args=['-framework', 'Carbon']) )
622
            
623 624 625 626
        self.extensions.extend(exts)

        # Call the method for detecting whether _tkinter can be compiled
        self.detect_tkinter(inc_dirs, lib_dirs)
627

628 629

    def detect_tkinter(self, inc_dirs, lib_dirs):
630
        # The _tkinter module.
631
        
632
        # Assume we haven't found any of the libraries or include files
633 634
        # The versions with dots are used on Unix, and the versions without
        # dots on Windows, for detection by cygwin.
635
        tcllib = tklib = tcl_includes = tk_includes = None
636 637
        for version in ['8.4', '84', '8.3', '83', '8.2',
                        '82', '8.1', '81', '8.0', '80']:
638 639 640 641
             tklib = self.compiler.find_library_file(lib_dirs,
                                                     'tk' + version )
             tcllib = self.compiler.find_library_file(lib_dirs,
                                                      'tcl' + version )
642
             if tklib and tcllib:
643 644
                # Exit the loop when we've found the Tcl/Tk libraries
                break
645

646
        # Now check for the header files
647 648 649
        if tklib and tcllib:
            # Check for the include files on Debian, where
            # they're put in /usr/include/{tcl,tk}X.Y
650 651 652 653
            debian_tcl_include = [ '/usr/include/tcl' + version ]
            debian_tk_include =  [ '/usr/include/tk'  + version ] + debian_tcl_include
            tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
            tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
654 655 656 657 658

        if (tcllib is None or tklib is None and
            tcl_includes is None or tk_includes is None):
            # Something's missing, so give up
            return
659

660 661 662 663 664 665
        # OK... everything seems to be present for Tcl/Tk.

        include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
        for dir in tcl_includes + tk_includes:
            if dir not in include_dirs:
                include_dirs.append(dir)
666

667
        # Check for various platform-specific directories
668 669
        platform = self.get_platform()
        if platform == 'sunos5':
670 671 672 673 674 675 676 677 678
            include_dirs.append('/usr/openwin/include')
            added_lib_dirs.append('/usr/openwin/lib')
        elif os.path.exists('/usr/X11R6/include'):
            include_dirs.append('/usr/X11R6/include')
            added_lib_dirs.append('/usr/X11R6/lib')
        elif os.path.exists('/usr/X11R5/include'):
            include_dirs.append('/usr/X11R5/include')
            added_lib_dirs.append('/usr/X11R5/lib')
        else:
679
            # Assume default location for X11
680 681 682
            include_dirs.append('/usr/X11/include')
            added_lib_dirs.append('/usr/X11/lib')

683 684 685 686 687 688 689
        # If Cygwin, then verify that X is installed before proceeding
        if platform == 'cygwin':
            x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
            if x11_inc is None:
                # X header files missing, so give up
                return

690 691 692 693 694 695
        # Check for BLT extension
        if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
            defs.append( ('WITH_BLT', 1) )
            libs.append('BLT8.0')

        # Add the Tcl/Tk libraries
696
        libs.append('tk'+version)
697
        libs.append('tcl'+version)
698

699
        if platform in ['aix3', 'aix4']:
700 701
            libs.append('ld')

702 703 704
        # Finally, link with the X11 libraries (not appropriate on cygwin)
        if platform != "cygwin":
            libs.append('X11')
705 706 707 708 709 710 711 712

        ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
                        define_macros=[('WITH_APPINIT', 1)] + defs,
                        include_dirs = include_dirs,
                        libraries = libs,
                        library_dirs = added_lib_dirs,
                        )
        self.extensions.append(ext)
713

714
        # XXX handle these, but how to detect?
715
        # *** Uncomment and edit for PIL (TkImaging) extension only:
716
        #       -DWITH_PIL -I../Extensions/Imaging/libImaging  tkImaging.c \
717
        # *** Uncomment and edit for TOGL extension only:
718
        #       -DWITH_TOGL togl.c \
719
        # *** Uncomment these for TOGL extension only:
720
        #       -lGL -lGLU -lXext -lXmu \
721

722 723 724 725 726 727 728 729
class PyBuildInstall(install):
    # Suppress the warning about installation into the lib_dynload
    # directory, which is not in sys.path when running Python during
    # installation:
    def initialize_options (self):
        install.initialize_options(self)
        self.warn_dir=0
    
730
def main():
731 732 733
    # turn off warnings when deprecated modules are imported
    import warnings
    warnings.filterwarnings("ignore",category=DeprecationWarning)
734
    setup(name = 'Python standard library',
735
          version = '%d.%d' % sys.version_info[:2],
736
          cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
737 738
          # The struct module is defined here, because build_ext won't be
          # called unless there's at least one extension module defined.
739 740 741 742
          ext_modules=[Extension('struct', ['structmodule.c'])],

          # Scripts to install
          scripts = ['Tools/scripts/pydoc']
743
        )
744

745 746 747 748
# --install-platlib
if __name__ == '__main__':
    sysconfig.set_python_build()
    main()