setup.py revision 03b75ddf7c63bb7b7bc1b424661c94076b57be9e
166012fe889db4ad88326f739f2e7cd7cb693f52aAndrew M. Kuchling# Autodetecting setup.py script for building the Python extensions
266012fe889db4ad88326f739f2e7cd7cb693f52aAndrew M. Kuchling#
3ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
466012fe889db4ad88326f739f2e7cd7cb693f52aAndrew M. Kuchling__version__ = "$Revision$"
566012fe889db4ad88326f739f2e7cd7cb693f52aAndrew M. Kuchling
684667c063a1e93a985134f7cef376edf82941c02Brett Cannonimport sys, os, imp, re, optparse
78608d91e07868f14f71be9784149f813ef1b0a74Christian Heimesfrom glob import glob
8529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
9529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudsonfrom distutils import log
1000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingfrom distutils import sysconfig
118d7f0869ee672d7e9e8e1bf126bf717d8223ee2bAndrew M. Kuchlingfrom distutils import text_file
127c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburgfrom distutils.errors import *
1300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingfrom distutils.core import Extension, setup
1400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingfrom distutils.command.build_ext import build_ext
15f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchlingfrom distutils.command.install import install
16529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudsonfrom distutils.command.install_lib import install_lib
1700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
1800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling# This global variable is used to hold the list of modules to be disabled.
1900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingdisabled_module_list = []
2000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
2139230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudsondef add_dir_to_list(dirlist, dir):
2239230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson    """Add the directory 'dir' to the list 'dirlist' (at the front) if
2339230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson    1) 'dir' is not already in 'dirlist'
2439230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson    2) 'dir' actually exists, and is a directory."""
254439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen    if dir is not None and os.path.isdir(dir) and dir not in dirlist:
2639230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson        dirlist.insert(0, dir)
2739230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson
28fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchlingdef find_file(filename, std_dirs, paths):
29fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    """Searches for the directory where a given file is located,
30fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    and returns a possibly-empty list of additional directories, or None
31fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    if the file couldn't be found at all.
32ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
33fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    'filename' is the name of a file, such as readline.h or libcrypto.a.
34fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    'std_dirs' is the list of standard system directories; if the
35fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        file is found in one of them, no additional directives are needed.
36fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    'paths' is a list of additional locations to check; if the file is
37fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        found in one of them, the resulting list will contain the directory.
38fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    """
39fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
40fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    # Check the standard locations
41fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    for dir in std_dirs:
42fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        f = os.path.join(dir, filename)
43fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        if os.path.exists(f): return []
44fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
45fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    # Check the additional directories
46fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    for dir in paths:
47fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        f = os.path.join(dir, filename)
48fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        if os.path.exists(f):
49fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            return [dir]
50fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
51fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    # Not found anywhere
5200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    return None
5300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
54fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchlingdef find_library_file(compiler, libname, std_dirs, paths):
55a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    result = compiler.find_library_file(std_dirs + paths, libname)
56a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    if result is None:
57a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling        return None
58ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
59a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    # Check whether the found file is in one of the standard directories
60a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    dirname = os.path.dirname(result)
61a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    for p in std_dirs:
62a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling        # Ensure path doesn't end with path separator
639f5178abb7edd1b1bcaffcdfcf1afd8816dab102Skip Montanaro        p = p.rstrip(os.sep)
64a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling        if p == dirname:
65a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling            return [ ]
66fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
67a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    # Otherwise, it must have been in one of the additional directories,
68a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    # so we have to figure out which one.
69a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    for p in paths:
70a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling        # Ensure path doesn't end with path separator
719f5178abb7edd1b1bcaffcdfcf1afd8816dab102Skip Montanaro        p = p.rstrip(os.sep)
72a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling        if p == dirname:
73a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling            return [p]
74a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling    else:
75a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling        assert False, "Internal error: Path not found in std_dirs or paths"
762c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters
7700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingdef module_enabled(extlist, modname):
7800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    """Returns whether the module 'modname' is present in the list
7900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    of extensions 'extlist'."""
8000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    extlist = [ext for ext in extlist if ext.name == modname]
8100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    return len(extlist)
82ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
83144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansendef find_module_file(module, dirlist):
84144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen    """Find a module in a set of possible folders. If it is not found
85144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen    return the unadorned filename"""
86144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen    list = find_file(module, [], dirlist)
87144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen    if not list:
88144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen        return module
89144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen    if len(list) > 1:
9012471d63893f84cb88deccf83af5aa5c6866c275Guido van Rossum        log.info("WARNING: multiple copies of %s found"%module)
91144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen    return os.path.join(list[0], module)
925b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
9300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingclass PyBuildExt(build_ext):
94ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
95d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro    def __init__(self, dist):
96d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        build_ext.__init__(self, dist)
97d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        self.failed = []
98d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
9900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    def build_extensions(self):
10000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
10100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Detect which modules should be compiled
102d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        missing = self.detect_modules()
10300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
10400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Remove modules that are present on the disabled list
105b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes        extensions = [ext for ext in self.extensions
106b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes                      if ext.name not in disabled_module_list]
107b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes        # move ctypes to the end, it depends on other modules
108b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes        ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
109b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes        if "_ctypes" in ext_map:
110b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes            ctypes = extensions.pop(ext_map["_ctypes"])
111b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes            extensions.append(ctypes)
112b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes        self.extensions = extensions
113ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
11400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Fix up the autodetected modules, prefixing all the source files
11500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # with Modules/ and adding Python's include directory to the path.
11600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        (srcdir,) = sysconfig.get_config_vars('srcdir')
117e0fea6c4edcb977d722ed30de4a76a83355e2617Guido van Rossum        if not srcdir:
118e0fea6c4edcb977d722ed30de4a76a83355e2617Guido van Rossum            # Maybe running on Windows but not using CYGWIN?
119e0fea6c4edcb977d722ed30de4a76a83355e2617Guido van Rossum            raise ValueError("No source directory; cannot proceed.")
12000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
121726b78ecb8660278399abaf36f98dec56ecf1271Neil Schemenauer        # Figure out the location of the source code for extension modules
1222fab8f1abb1c5d51cfe3bbdc7a912e7c574ccf46Thomas Wouters        # (This logic is copied in distutils.test.test_sysconfig,
1232fab8f1abb1c5d51cfe3bbdc7a912e7c574ccf46Thomas Wouters        # so building in a separate directory does not break test_distutils.)
124726b78ecb8660278399abaf36f98dec56ecf1271Neil Schemenauer        moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
12500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        moddir = os.path.normpath(moddir)
12600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        srcdir, tail = os.path.split(moddir)
12700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        srcdir = os.path.normpath(srcdir)
12800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        moddir = os.path.normpath(moddir)
1295b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
130144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen        moddirlist = [moddir]
131144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen        incdirlist = ['./Include']
1325b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
133144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen        # Platform-dependent module source and include directories
134144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen        platform = self.get_platform()
13566cb018c96e49b5e5cf1b8fc395171a223d86d8eTim Peters        if platform in ('darwin', 'mac') and ("--disable-toolbox-glue" not in
136cc8a4f6563395e39d77da9888d0ea3675214ca64Brett Cannon            sysconfig.get_config_var("CONFIG_ARGS")):
137144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            # Mac OS X also includes some mac-specific modules
138144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
139144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            moddirlist.append(macmoddir)
140144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            incdirlist.append('./Mac/Include')
14100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
142340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton        alldirlist = moddirlist + incdirlist
143340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton
1443da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling        # Fix up the paths for scripts, too
1453da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling        self.distribution.scripts = [os.path.join(srcdir, filename)
1463da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling                                     for filename in self.distribution.scripts]
1473da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling
1488608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes        # Python header files
1498608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes        headers = glob("Include/*.h") + ["pyconfig.h"]
1508608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes
151fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        for ext in self.extensions[:]:
152144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            ext.sources = [ find_module_file(filename, moddirlist)
15300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                            for filename in ext.sources ]
154340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton            if ext.depends is not None:
155340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton                ext.depends = [find_module_file(filename, alldirlist)
156340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton                               for filename in ext.depends]
1578608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes            else:
1588608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes                ext.depends = []
1598608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes            # re-compile extensions if a header file has been changed
1608608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes            ext.depends.extend(headers)
1618608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes
162144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            ext.include_dirs.append( '.' ) # to get config.h
163144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen            for incdir in incdirlist:
164144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen                ext.include_dirs.append( os.path.join(srcdir, incdir) )
165fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
166e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling            # If a module has already been built statically,
167fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            # don't build it here
168e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling            if ext.name in sys.builtin_module_names:
169fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                self.extensions.remove(ext)
1705bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling
1714439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen        if platform != 'mac':
172e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl            # Parse Modules/Setup and Modules/Setup.local to figure out which
173e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl            # modules are turned on in the file.
1744439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen            remove_modules = []
175e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl            for filename in ('Modules/Setup', 'Modules/Setup.local'):
176e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                input = text_file.TextFile(filename, join_lines=1)
177e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                while 1:
178e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                    line = input.readline()
179e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                    if not line: break
180e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                    line = line.split()
181e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                    remove_modules.append(line[0])
182e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl                input.close()
1831b27f86411f2593fe6137c54143c0d23f21271c7Tim Peters
1844439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen            for ext in self.extensions[:]:
1854439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen                if ext.name in remove_modules:
1864439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen                    self.extensions.remove(ext)
1875b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
1885bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # When you run "make CC=altcc" or something similar, you really want
1895bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # those environment variables passed into the setup.py phase.  Here's
1905bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # a small set of useful ones.
1915bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        compiler = os.environ.get('CC')
1925bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        args = {}
1935bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # unfortunately, distutils doesn't let us provide separate C and C++
1945bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # compilers
1955bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        if compiler is not None:
196d7c795e72966f7c72b94b919f3539be66495e6c3Martin v. Löwis            (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
197d7c795e72966f7c72b94b919f3539be66495e6c3Martin v. Löwis            args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
1985bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        self.compiler.set_executables(**args)
1995bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling
20000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        build_ext.build_extensions(self)
20100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
202d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        longest = max([len(e.name) for e in self.extensions])
203d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        if self.failed:
204d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            longest = max(longest, max([len(name) for name in self.failed]))
205d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
206d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        def print_three_column(lst):
207e95cf1c8a2cba11b38f9c83da659895fbc952466Georg Brandl            lst.sort(key=str.lower)
208d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            # guarantee zip() doesn't drop anything
209d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            while len(lst) % 3:
210d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                lst.append("")
211d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
212d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                print "%-*s   %-*s   %-*s" % (longest, e, longest, f,
213d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                                              longest, g)
214d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
215d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        if missing:
216d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            print
217d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            print "Failed to find the necessary bits to build these modules:"
218d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            print_three_column(missing)
219879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin            print ("To find the necessary bits, look in setup.py in"
220879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin                   " detect_modules() for the module's name.")
221879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin            print
222d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
223d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        if self.failed:
224d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            failed = self.failed[:]
225d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            print
226d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            print "Failed to build these modules:"
227d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            print_three_column(failed)
228879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin            print
229d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
2307c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg    def build_extension(self, ext):
2317c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg
232eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller        if ext.name == '_ctypes':
233795246cf9937f088f8d98253f38da4a093c08300Thomas Heller            if not self.configure_ctypes(ext):
234795246cf9937f088f8d98253f38da4a093c08300Thomas Heller                return
235eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller
2367c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg        try:
2377c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg            build_ext.build_extension(self, ext)
2387c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg        except (CCompilerError, DistutilsError), why:
2397c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg            self.announce('WARNING: building of extension "%s" failed: %s' %
2407c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg                          (ext.name, sys.exc_info()[1]))
241d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            self.failed.append(ext.name)
24262686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling            return
243f49c6f9954aa59e29c8b392347646f95cbf8215aJack Jansen        # Workaround for Mac OS X: The Carbon-based modules cannot be
244f49c6f9954aa59e29c8b392347646f95cbf8215aJack Jansen        # reliably imported into a command-line Python
245f49c6f9954aa59e29c8b392347646f95cbf8215aJack Jansen        if 'Carbon' in ext.extra_link_args:
2465b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson            self.announce(
2475b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson                'WARNING: skipping import check for Carbon-based "%s"' %
2485b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson                ext.name)
2495b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson            return
25024cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler        # Workaround for Cygwin: Cygwin currently has fork issues when many
25124cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler        # modules have been imported
25224cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler        if self.get_platform() == 'cygwin':
25324cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler            self.announce('WARNING: skipping import check for Cygwin-based "%s"'
25424cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler                % ext.name)
25524cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler            return
256af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson        ext_filename = os.path.join(
257af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson            self.build_lib,
258af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson            self.get_ext_filename(self.get_ext_fullname(ext.name)))
25962686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling        try:
260af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson            imp.load_dynamic(ext.name, ext_filename)
2616e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz        except ImportError, why:
262d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            self.failed.append(ext.name)
2636e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            self.announce('*** WARNING: renaming "%s" since importing it'
2646e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                          ' failed: %s' % (ext.name, why), level=3)
2656e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            assert not self.inplace
2666e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            basename, tail = os.path.splitext(ext_filename)
2676e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            newname = basename + "_failed" + tail
2686e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            if os.path.exists(newname):
2696e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                os.remove(newname)
2706e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            os.rename(ext_filename, newname)
2716e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz
2726e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            # XXX -- This relies on a Vile HACK in
2736e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            # distutils.command.build_ext.build_extension().  The
2746e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            # _built_objects attribute is stored there strictly for
2756e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            # use here.
2766e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            # If there is a failure, _built_objects may not be there,
2776e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            # so catch the AttributeError and move on.
2786e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            try:
2796e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                for filename in self._built_objects:
2806e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                    os.remove(filename)
2816e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            except AttributeError:
2826e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                self.announce('unable to remove files (ignored)')
2833f5fcc8acce9fa620fe29d15980850e433f1d5c9Neal Norwitz        except:
2843f5fcc8acce9fa620fe29d15980850e433f1d5c9Neal Norwitz            exc_type, why, tb = sys.exc_info()
2856e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz            self.announce('*** WARNING: importing extension "%s" '
2866e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                          'failed with %s: %s' % (ext.name, exc_type, why),
2876e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz                          level=3)
288d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            self.failed.append(ext.name)
2899028d0a52529a8bc76868ade697511f29614b207Fred Drake
29051dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz    def get_platform(self):
291ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        # Get value of sys.platform
29251dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz        for platform in ['cygwin', 'beos', 'darwin', 'atheos', 'osf1']:
29351dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz            if sys.platform.startswith(platform):
29451dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz                return platform
29551dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz        return sys.platform
29634febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling
29700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    def detect_modules(self):
298ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        # Ensure that /usr/local is always used
29939230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson        add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
30039230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson        add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
30139230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson
302516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon        # Add paths specified in the environment variables LDFLAGS and
3034810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon        # CPPFLAGS for header and library files.
3045399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon        # We must get the values from the Makefile and not the environment
3055399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon        # directly since an inconsistently reproducible issue comes up where
3065399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon        # the environment variable is not set even though the value were passed
3074810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon        # into configure and stored in the Makefile (issue found on OS X 10.3).
308516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon        for env_var, arg_name, dir_list in (
309516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon                ('LDFLAGS', '-L', self.compiler.library_dirs),
310516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon                ('CPPFLAGS', '-I', self.compiler.include_dirs)):
3115399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon            env_val = sysconfig.get_config_var(env_var)
312516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon            if env_val:
3134810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # To prevent optparse from raising an exception about any
3144810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # options in env_val that is doesn't know about we strip out
3154810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # all double dashes and any dashes followed by a character
3164810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # that is not for the option we are dealing with.
3174810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                #
3184810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # Please note that order of the regex is important!  We must
3194810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # strip out double-dashes first so that we don't end up with
3204810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # substituting "--Long" to "-Long" and thus lead to "ong" being
3214810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # used for a library directory.
322915c87d3e5d84c0635c2957f4ae9e96d0ab6705fGeorg Brandl                env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
323915c87d3e5d84c0635c2957f4ae9e96d0ab6705fGeorg Brandl                                 ' ', env_val)
32484667c063a1e93a985134f7cef376edf82941c02Brett Cannon                parser = optparse.OptionParser()
3254810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # Make sure that allowing args interspersed with options is
3264810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                # allowed
3274810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                parser.allow_interspersed_args = True
3284810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon                parser.error = lambda msg: None
32984667c063a1e93a985134f7cef376edf82941c02Brett Cannon                parser.add_option(arg_name, dest="dirs", action="append")
33084667c063a1e93a985134f7cef376edf82941c02Brett Cannon                options = parser.parse_args(env_val.split())[0]
33144837719ef2886da0671aed55e99cdae14d24b9dBrett Cannon                if options.dirs:
332861e39678f574496c6e730753f12cbd7f59b6541Brett Cannon                    for directory in reversed(options.dirs):
33344837719ef2886da0671aed55e99cdae14d24b9dBrett Cannon                        add_dir_to_list(dir_list, directory)
334decc6a47df823a988845d3753a4cfb7a85b80828Skip Montanaro
33590b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson        if os.path.normpath(sys.prefix) != '/usr':
33690b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson            add_dir_to_list(self.compiler.library_dirs,
33790b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson                            sysconfig.get_config_var("LIBDIR"))
33890b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson            add_dir_to_list(self.compiler.include_dirs,
33990b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson                            sysconfig.get_config_var("INCLUDEDIR"))
340fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
341339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis        try:
342339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis            have_unicode = unicode
343339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis        except NameError:
344339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis            have_unicode = 0
345339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis
346fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # lib_dirs and inc_dirs are used to search for files;
347fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # if a file is found in one of those directories, it can
348fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # be assumed that no additional -I,-L directives are needed.
349fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis        lib_dirs = self.compiler.library_dirs + [
350fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis            '/lib64', '/usr/lib64',
351fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis            '/lib', '/usr/lib',
352fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis            ]
3535b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson        inc_dirs = self.compiler.include_dirs + ['/usr/include']
35400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts = []
355d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        missing = []
35600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
3574454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon        config_h = sysconfig.get_config_h_filename()
3584454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon        config_h_vars = sysconfig.parse_config_h(open(config_h))
3594454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon
360ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        platform = self.get_platform()
3618301256a440fdd98fd500d225dac20ebb192e08fMartin v. Löwis        (srcdir,) = sysconfig.get_config_vars('srcdir')
3625b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
363f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis        # Check for AtheOS which has libraries in non-standard locations
364f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis        if platform == 'atheos':
365f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis            lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
366f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis            lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
367f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis            inc_dirs += ['/system/include', '/atheos/autolnk/include']
368f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis            inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
369f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis
3707883dc8abb81026fb111b2fde09ba602ccf04226Andrew M. Kuchling        # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
3717883dc8abb81026fb111b2fde09ba602ccf04226Andrew M. Kuchling        if platform in ['osf1', 'unixware7', 'openunix8']:
37222e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro            lib_dirs += ['/usr/ccs/lib']
37322e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro
37439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren        if platform == 'darwin':
37539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            # This should work on any unixy platform ;-)
37639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            # If the user has bothered specifying additional -I and -L flags
37739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            # in OPT and LDFLAGS we might as well use them here.
37839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            #   NOTE: using shlex.split would technically be more correct, but
37939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            # also gives a bootstrap problem. Let's hope nobody uses directories
38039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            # with whitespace in the name to store libraries.
38139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            cflags, ldflags = sysconfig.get_config_vars(
38239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                    'CFLAGS', 'LDFLAGS')
38339be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            for item in cflags.split():
38439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                if item.startswith('-I'):
38539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                    inc_dirs.append(item[2:])
38639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren
38739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            for item in ldflags.split():
38839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                if item.startswith('-L'):
38939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                    lib_dirs.append(item[2:])
39039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren
391ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        # Check for MacOS X, which doesn't need libm.a at all
392ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        math_libs = ['m']
3934439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen        if platform in ['darwin', 'beos', 'mac']:
394ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh            math_libs = []
3955b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
39600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # XXX Omitted modules: gl, pure, dl, SGI-specific modules
39700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
39800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        #
39900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # The following modules are all pretty straightforward, and compile
40000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # on pretty much any POSIXish platform.
40100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        #
402ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
40300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Some modules that are normally always on:
4042de7471d69b950a64e52a950675d59d9f4071da1Fred Drake        exts.append( Extension('_weakref', ['_weakref.c']) )
40500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
40600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # array objects
40700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('array', ['arraymodule.c']) )
40800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # complex math library functions
4095ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling        exts.append( Extension('cmath', ['cmathmodule.c'],
4105ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling                               libraries=math_libs) )
411ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
41200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # math library functions, e.g. sin()
4135ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling        exts.append( Extension('math',  ['mathmodule.c'],
4145ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling                               libraries=math_libs) )
41500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # fast string operations implemented in C
41600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('strop', ['stropmodule.c']) )
41700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # time operations and variables
4185ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling        exts.append( Extension('time', ['timemodule.c'],
4195ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling                               libraries=math_libs) )
420057e7200d1c300f3c914dbc84eca327c10bf7751Brett Cannon        exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
421a29d508ec4f29f73a9569e27402f159b8efa57caGuido van Rossum                               libraries=math_libs) )
4220d2192be8b71c2effeedad4bf9ccac9c022c03d8Neal Norwitz        # fast iterator tools implemented in C
4230d2192be8b71c2effeedad4bf9ccac9c022c03d8Neal Norwitz        exts.append( Extension("itertools", ["itertoolsmodule.c"]) )
424a73fbe791d0d41db543ebe39d2f6df0a4265be4bEric Smith        # code that will be builtins in the future, but conflict with the
425a73fbe791d0d41db543ebe39d2f6df0a4265be4bEric Smith        #  current builtins
426a73fbe791d0d41db543ebe39d2f6df0a4265be4bEric Smith        exts.append( Extension('future_builtins', ['future_builtins.c']) )
42740f621709286a7a0f7e6f260c0fd020d0fac0de0Raymond Hettinger        # random number generator implemented in C
4282c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters        exts.append( Extension("_random", ["_randommodule.c"]) )
429756b3f3c15bd314ffa25299ca25465ae21e62a30Raymond Hettinger        # high-performance collections
430eb9798892d7ed54762ae006e39db0a84f671cfd3Raymond Hettinger        exts.append( Extension("_collections", ["_collectionsmodule.c"]) )
4310c4102760c440af3e7b575b0fd27fe25549641a2Raymond Hettinger        # bisect
4320c4102760c440af3e7b575b0fd27fe25549641a2Raymond Hettinger        exts.append( Extension("_bisect", ["_bisectmodule.c"]) )
433b3af1813eb5cf99766f55a0dfc0d566e9bd7c3c1Raymond Hettinger        # heapq
434c46cb2a1a92c26e01ddb3921aa6828bcd3576f3eRaymond Hettinger        exts.append( Extension("_heapq", ["_heapqmodule.c"]) )
43500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # operator.add() and similar goodies
43600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('operator', ['operator.c']) )
4377f39c9fcbba0cc59293d80a7bbcbb8bca62790eeChristian Heimes        # Python 3.0 _fileio module
4387f39c9fcbba0cc59293d80a7bbcbb8bca62790eeChristian Heimes        exts.append( Extension("_fileio", ["_fileio.c"]) )
4391aed624f7c6051bc670a846825bd40108d3f8dd5Alexandre Vassalotti        # Python 3.0 _bytesio module
4401aed624f7c6051bc670a846825bd40108d3f8dd5Alexandre Vassalotti        exts.append( Extension("_bytesio", ["_bytesio.c"]) )
441c649ec5b69bd864914e02a2a9ec73c23bd307448Nick Coghlan        # _functools
442c649ec5b69bd864914e02a2a9ec73c23bd307448Nick Coghlan        exts.append( Extension("_functools", ["_functoolsmodule.c"]) )
4434b964f9c904744b7d7d88054e54a2e4ca8aeb395Brett Cannon        # _json speedups
4444b964f9c904744b7d7d88054e54a2e4ca8aeb395Brett Cannon        exts.append( Extension("_json", ["_json.c"]) )
445261b8e26f199b8e548d9cf81fc4a94820a5a83dbMarc-André Lemburg        # Python C API test module
446d66595fe423227f3bf8ea4867df5d27c6d2764e1Tim Peters        exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
447a871ef2b3e924f058ec1b0aed7d4c83a546414b7Armin Rigo        # profilers (_lsprof is for cProfile.py)
448a871ef2b3e924f058ec1b0aed7d4c83a546414b7Armin Rigo        exts.append( Extension('_hotshot', ['_hotshot.c']) )
449a871ef2b3e924f058ec1b0aed7d4c83a546414b7Armin Rigo        exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
45000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # static Unicode character database
451339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis        if have_unicode:
452339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis            exts.append( Extension('unicodedata', ['unicodedata.c']) )
453d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
454d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('unicodedata')
45500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # access to ISO C locale support
45619d173486b2263a269260343d65ac3929c89297eMartin v. Löwis        data = open('pyconfig.h').read()
45719d173486b2263a269260343d65ac3929c89297eMartin v. Löwis        m = re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*", data)
45819d173486b2263a269260343d65ac3929c89297eMartin v. Löwis        if m is not None:
459d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler            locale_libs = ['intl']
460d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler        else:
461d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler            locale_libs = []
46284b744775206eceefc9c94ba3e23f18332ac062bJack Jansen        if platform == 'darwin':
46384b744775206eceefc9c94ba3e23f18332ac062bJack Jansen            locale_extra_link_args = ['-framework', 'CoreFoundation']
46484b744775206eceefc9c94ba3e23f18332ac062bJack Jansen        else:
46584b744775206eceefc9c94ba3e23f18332ac062bJack Jansen            locale_extra_link_args = []
466e6ddc8b20b493fef2e7cffb2e1351fe1d238857eTim Peters
46784b744775206eceefc9c94ba3e23f18332ac062bJack Jansen
468d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler        exts.append( Extension('_locale', ['_localemodule.c'],
46984b744775206eceefc9c94ba3e23f18332ac062bJack Jansen                               libraries=locale_libs,
47084b744775206eceefc9c94ba3e23f18332ac062bJack Jansen                               extra_link_args=locale_extra_link_args) )
47100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
47200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Modules with some UNIX dependencies -- on by default:
47300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # (If you have a really backward UNIX, select and socket may not be
47400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # supported...)
47500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
47600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # fcntl(2) and ioctl(2)
47700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('fcntl', ['fcntlmodule.c']) )
47873aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen        if platform not in ['mac']:
47946d9623875893be9e2bcbb804b82cfd7f8ed05dfBrett Cannon            # pwd(3)
4802c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            exts.append( Extension('pwd', ['pwdmodule.c']) )
4812c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            # grp(3)
4822c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            exts.append( Extension('grp', ['grpmodule.c']) )
483c300175547ced0af17857a29462b0f9294e8c31cMartin v. Löwis            # spwd, shadow passwords
4844454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon            if (config_h_vars.get('HAVE_GETSPNAM', False) or
4854454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon                    config_h_vars.get('HAVE_GETSPENT', False)):
48646d9623875893be9e2bcbb804b82cfd7f8ed05dfBrett Cannon                exts.append( Extension('spwd', ['spwdmodule.c']) )
487d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
488d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('spwd')
489d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
490d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.extend(['pwd', 'grp', 'spwd'])
491d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
49200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # select(2); not on ancient System V
49300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('select', ['selectmodule.c']) )
49400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
49500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Fred Drake's interface to the Python parser
49600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('parser', ['parsermodule.c']) )
49700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
4982e1c09c1fd06531a3ce1de5b12ec5c8f771e78e0Guido van Rossum        # cStringIO and cPickle
49900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('cStringIO', ['cStringIO.c']) )
50000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        exts.append( Extension('cPickle', ['cPickle.c']) )
50100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
50200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Memory-mapped files (also works on Win32).
50373aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen        if platform not in ['atheos', 'mac']:
504f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis            exts.append( Extension('mmap', ['mmapmodule.c']) )
505d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
506d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('mmap')
50700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
50857269d0c7c7a6fc989fcbef5b82853aa36fb44caAndrew M. Kuchling        # Lance Ellinghaus's syslog module
50973aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen        if platform not in ['mac']:
5102c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            # syslog daemon interface
5112c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            exts.append( Extension('syslog', ['syslogmodule.c']) )
512d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
513d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('syslog')
51400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
51500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # George Neville-Neil's timing module:
5166143c547dd45dfc56ad05af31b829479a3ce7e2dNeal Norwitz        # Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html
5176143c547dd45dfc56ad05af31b829479a3ce7e2dNeal Norwitz        # http://mail.python.org/pipermail/python-dev/2006-January/060023.html
5186143c547dd45dfc56ad05af31b829479a3ce7e2dNeal Norwitz        #exts.append( Extension('timing', ['timingmodule.c']) )
51900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
52000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        #
5215bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # Here ends the simple stuff.  From here on, modules need certain
5225bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling        # libraries, are platform-specific, or present other surprises.
52300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        #
52400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
52500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Multimedia modules
52600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # These don't work for 64-bit platforms!!!
52700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # These represent audio samples or images as strings:
52800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
5295e4a3b86b359952dc6ba3da2f48594179a811319Neal Norwitz        # Operations on audio samples
530f9cbf211578c3d5a7d5fe2ac3bf09b1b5a2dd5e2Tim Peters        # According to #993173, this one should actually work fine on
5318fbefe28745f980579620147dd0c0fdef94374deMartin v. Löwis        # 64-bit platforms.
5328fbefe28745f980579620147dd0c0fdef94374deMartin v. Löwis        exts.append( Extension('audioop', ['audioop.c']) )
5338fbefe28745f980579620147dd0c0fdef94374deMartin v. Löwis
534ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        # Disabled on 64-bit platforms
53500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        if sys.maxint != 9223372036854775807L:
53600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            # Operations on images
53700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('imageop', ['imageop.c']) )
538d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
539dc48b74497b67a449dd622fdaa7d69e7bff65a5eBrett Cannon            missing.extend(['imageop'])
54000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
54100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # readline
54281ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen        do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
54381ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen        if platform == 'darwin':
54481ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen            # MacOSX 10.4 has a broken readline. Don't try to build
54581ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen            # the readline module unless the user has installed a fixed
54681ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen            # readline package
5472086eaf79c9dc2992fef64392a9813e25f60696fMartin v. Löwis            if find_file('readline/rlconf.h', inc_dirs, []) is None:
54881ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen                do_readline = False
54981ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen        if do_readline:
55039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            if sys.platform == 'darwin':
55139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # In every directory on the search path search for a dynamic
55239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # library and then a static library, instead of first looking
55339be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # for dynamic libraries on the entiry path.
55439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # This way a staticly linked custom readline gets picked up
55539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # before the (broken) dynamic library in /usr/lib.
55639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                readline_extra_link_args = ('-Wl,-search_paths_first',)
55739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            else:
55839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                readline_extra_link_args = ()
55939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren
5602efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg            readline_libs = ['readline']
5615aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling            if self.compiler.find_library_file(lib_dirs,
562a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis                                                 'ncursesw'):
563a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis                readline_libs.append('ncursesw')
564a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis            elif self.compiler.find_library_file(lib_dirs,
5655aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling                                                 'ncurses'):
5665aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling                readline_libs.append('ncurses')
5670b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz            elif self.compiler.find_library_file(lib_dirs, 'curses'):
5680b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz                readline_libs.append('curses')
5695aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling            elif self.compiler.find_library_file(lib_dirs +
5702efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg                                               ['/usr/lib/termcap'],
5712efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg                                               'termcap'):
5722efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg                readline_libs.append('termcap')
57300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('readline', ['readline.c'],
5747c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg                                   library_dirs=['/usr/lib/termcap'],
57539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                                   extra_link_args=readline_extra_link_args,
5762efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg                                   libraries=readline_libs) )
577d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
578d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('readline')
579d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
58073aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen        if platform not in ['mac']:
5817883dc8abb81026fb111b2fde09ba602ccf04226Andrew M. Kuchling            # crypt module.
5822c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters
5832c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            if self.compiler.find_library_file(lib_dirs, 'crypt'):
5842c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters                libs = ['crypt']
5852c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            else:
5862c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters                libs = []
5872c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
588d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
589d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('crypt')
59000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
591ba9e9781805f85d32b5a2a17efdf00b77d747500Skip Montanaro        # CSV files
592ba9e9781805f85d32b5a2a17efdf00b77d747500Skip Montanaro        exts.append( Extension('_csv', ['_csv.c']) )
593ba9e9781805f85d32b5a2a17efdf00b77d747500Skip Montanaro
59400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # socket(2)
59547d3a7afdaf52887d1bbd1a8cbcd717893c6d480Guido van Rossum        exts.append( Extension('_socket', ['socketmodule.c'],
596340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton                               depends = ['socketmodule.h']) )
597a5d2b4cb180ec87d006d63f838860fba785bcad0Marc-André Lemburg        # Detect SSL support for the socket module (via _ssl)
598ade97338016947bad1d0def339328963fca09685Gregory P. Smith        search_for_ssl_incs_in = [
599ade97338016947bad1d0def339328963fca09685Gregory P. Smith                              '/usr/local/ssl/include',
600e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling                              '/usr/contrib/ssl/include/'
601e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling                             ]
602ade97338016947bad1d0def339328963fca09685Gregory P. Smith        ssl_incs = find_file('openssl/ssl.h', inc_dirs,
603ade97338016947bad1d0def339328963fca09685Gregory P. Smith                             search_for_ssl_incs_in
604fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                             )
605a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis        if ssl_incs is not None:
606a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis            krb5_h = find_file('krb5.h', inc_dirs,
607a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis                               ['/usr/kerberos/include'])
608a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis            if krb5_h:
609a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis                ssl_incs += krb5_h
610fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
611e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling                                     ['/usr/local/ssl/lib',
612e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling                                      '/usr/contrib/ssl/lib/'
613e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling                                     ] )
614ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
615fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        if (ssl_incs is not None and
616fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            ssl_libs is not None):
617a5d2b4cb180ec87d006d63f838860fba785bcad0Marc-André Lemburg            exts.append( Extension('_ssl', ['_ssl.c'],
618fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                                   include_dirs = ssl_incs,
619ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh                                   library_dirs = ssl_libs,
62047d3a7afdaf52887d1bbd1a8cbcd717893c6d480Guido van Rossum                                   libraries = ['ssl', 'crypto'],
621340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton                                   depends = ['socketmodule.h']), )
622d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
623d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_ssl')
62400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
625ade97338016947bad1d0def339328963fca09685Gregory P. Smith        # find out which version of OpenSSL we have
626ade97338016947bad1d0def339328963fca09685Gregory P. Smith        openssl_ver = 0
627ade97338016947bad1d0def339328963fca09685Gregory P. Smith        openssl_ver_re = re.compile(
628ade97338016947bad1d0def339328963fca09685Gregory P. Smith            '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
629ade97338016947bad1d0def339328963fca09685Gregory P. Smith        for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in:
630ade97338016947bad1d0def339328963fca09685Gregory P. Smith            name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h')
631ade97338016947bad1d0def339328963fca09685Gregory P. Smith            if os.path.isfile(name):
632ade97338016947bad1d0def339328963fca09685Gregory P. Smith                try:
633ade97338016947bad1d0def339328963fca09685Gregory P. Smith                    incfile = open(name, 'r')
634ade97338016947bad1d0def339328963fca09685Gregory P. Smith                    for line in incfile:
635ade97338016947bad1d0def339328963fca09685Gregory P. Smith                        m = openssl_ver_re.match(line)
636ade97338016947bad1d0def339328963fca09685Gregory P. Smith                        if m:
637ade97338016947bad1d0def339328963fca09685Gregory P. Smith                            openssl_ver = eval(m.group(1))
638ade97338016947bad1d0def339328963fca09685Gregory P. Smith                            break
639ade97338016947bad1d0def339328963fca09685Gregory P. Smith                except IOError:
640ade97338016947bad1d0def339328963fca09685Gregory P. Smith                    pass
641ade97338016947bad1d0def339328963fca09685Gregory P. Smith
642ade97338016947bad1d0def339328963fca09685Gregory P. Smith            # first version found is what we'll use (as the compiler should)
643ade97338016947bad1d0def339328963fca09685Gregory P. Smith            if openssl_ver:
644ade97338016947bad1d0def339328963fca09685Gregory P. Smith                break
645ade97338016947bad1d0def339328963fca09685Gregory P. Smith
646ade97338016947bad1d0def339328963fca09685Gregory P. Smith        #print 'openssl_ver = 0x%08x' % openssl_ver
647ade97338016947bad1d0def339328963fca09685Gregory P. Smith
648f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith        if (ssl_incs is not None and
649ade97338016947bad1d0def339328963fca09685Gregory P. Smith            ssl_libs is not None and
650ade97338016947bad1d0def339328963fca09685Gregory P. Smith            openssl_ver >= 0x00907000):
651f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            # The _hashlib module wraps optimized implementations
652f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            # of hash functions from the OpenSSL library.
653f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            exts.append( Extension('_hashlib', ['_hashopenssl.c'],
654f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith                                   include_dirs = ssl_incs,
655f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith                                   library_dirs = ssl_libs,
656f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith                                   libraries = ['ssl', 'crypto']) )
6574eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith            # these aren't strictly missing since they are unneeded.
6584eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith            #missing.extend(['_sha', '_md5'])
659f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith        else:
660f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            # The _sha module implements the SHA1 hash algorithm.
661f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            exts.append( Extension('_sha', ['shamodule.c']) )
662f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            # The _md5 module implements the RSA Data Security, Inc. MD5
663f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith            # Message-Digest Algorithm, described in RFC 1321.  The
6648e39ec78bcede7291e0573fc522425221eb05475Matthias Klose            # necessary files md5.c and md5.h are included here.
665d792392db4b63bea14b40e3f6e3c41ab4eb6e6faGregory P. Smith            exts.append( Extension('_md5',
666d792392db4b63bea14b40e3f6e3c41ab4eb6e6faGregory P. Smith                            sources = ['md5module.c', 'md5.c'],
667d792392db4b63bea14b40e3f6e3c41ab4eb6e6faGregory P. Smith                            depends = ['md5.h']) )
668d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_hashlib')
669f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith
670ade97338016947bad1d0def339328963fca09685Gregory P. Smith        if (openssl_ver < 0x00908000):
671ade97338016947bad1d0def339328963fca09685Gregory P. Smith            # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
672ade97338016947bad1d0def339328963fca09685Gregory P. Smith            exts.append( Extension('_sha256', ['sha256module.c']) )
673ade97338016947bad1d0def339328963fca09685Gregory P. Smith            exts.append( Extension('_sha512', ['sha512module.c']) )
674f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith
67500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Modules that provide persistent dictionary-like semantics.  You will
67600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # probably want to arrange for at least one of them to be available on
67700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # your machine, though none are defined by default because of library
67800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # dependencies.  The Python module anydbm.py provides an
67900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # implementation independent wrapper for these; dumbdbm.py provides
68000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # similar functionality (but slower of course) implemented in Python.
68100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
6821475cd876190ccad16e47600958b226bfd788332Gregory P. Smith        # Sleepycat^WOracle Berkeley DB interface.
6831475cd876190ccad16e47600958b226bfd788332Gregory P. Smith        #  http://www.oracle.com/database/berkeley-db/db/index.html
68457454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro        #
6854eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        # This requires the Sleepycat^WOracle DB code. The supported versions
686e7f4d8483082d2f694e8a89ec531ab378e6b8326Gregory P. Smith        # are set below.  Visit the URL above to download
6873adc4aa2fb58aaca2f7692a37239ee3157887166Gregory P. Smith        # a release.  Most open source OSes come with one or more
6883adc4aa2fb58aaca2f7692a37239ee3157887166Gregory P. Smith        # versions of BerkeleyDB already installed.
68957454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro
690f866bac73c6a6f6a15ef2217cb5ac9f3160a9378Gregory P. Smith        max_db_ver = (4, 5)  # XXX(gregory.p.smith): 4.6 "works" but seems to
691f866bac73c6a6f6a15ef2217cb5ac9f3160a9378Gregory P. Smith                             # have issues on many platforms.  I've temporarily
692f866bac73c6a6f6a15ef2217cb5ac9f3160a9378Gregory P. Smith                             # disabled 4.6 to see what the odd platform
693f866bac73c6a6f6a15ef2217cb5ac9f3160a9378Gregory P. Smith                             # buildbots say.
6943adc4aa2fb58aaca2f7692a37239ee3157887166Gregory P. Smith        min_db_ver = (3, 3)
695e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        db_setup_debug = False   # verbose debug prints from this script?
696e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
697e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        # construct a list of paths to look for the header file in on
698e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        # top of the normal inc_dirs.
699e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        db_inc_paths = [
700e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/usr/include/db4',
701e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/usr/local/include/db4',
702e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/opt/sfw/include/db4',
703e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/usr/include/db3',
704e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/usr/local/include/db3',
705e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/opt/sfw/include/db3',
70600c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro            # Fink defaults (http://fink.sourceforge.net/)
70700c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro            '/sw/include/db4',
708e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            '/sw/include/db3',
709e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        ]
710e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        # 4.x minor number specific paths
711f3d280e62acfa2d597dff13105f7fec4a5eeb8e6Gregory P. Smith        for x in range(max_db_ver[1]+1):
712e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/usr/include/db4%d' % x)
7138f40171b6734250008e68f79ae64308e37902dfaNeal Norwitz            db_inc_paths.append('/usr/include/db4.%d' % x)
714e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
715e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/usr/local/include/db4%d' % x)
716e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/pkg/db-4.%d/include' % x)
71729602d2153e56081fad5db19e356e51c37ec2ec8Gregory P. Smith            db_inc_paths.append('/opt/db-4.%d/include' % x)
71800c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro            # MacPorts default (http://www.macports.org/)
71900c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro            db_inc_paths.append('/opt/local/include/db4%d' % x)
720e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        # 3.x minor number specific paths
7218b96a35d14c0ec5db5f32321e544269a5b0a8759Gregory P. Smith        for x in (3,):
722e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/usr/include/db3%d' % x)
723e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
724e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/usr/local/include/db3%d' % x)
725e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_inc_paths.append('/pkg/db-3.%d/include' % x)
72629602d2153e56081fad5db19e356e51c37ec2ec8Gregory P. Smith            db_inc_paths.append('/opt/db-3.%d/include' % x)
727e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
7289b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren        # Add some common subdirectories for Sleepycat DB to the list,
7299b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren        # based on the standard include directories. This way DB3/4 gets
7309b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren        # picked up when it is installed in a non-standard prefix and
7319b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren        # the user has added that prefix into inc_dirs.
7329b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren        std_variants = []
7339b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren        for dn in inc_dirs:
7349b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren            std_variants.append(os.path.join(dn, 'db3'))
7359b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren            std_variants.append(os.path.join(dn, 'db4'))
736773f347e7c9572b0f8a8797eff2f423397885c8bGregory P. Smith            for x in range(max_db_ver[1]+1):
7379b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                std_variants.append(os.path.join(dn, "db4%d"%x))
7389b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                std_variants.append(os.path.join(dn, "db4.%d"%x))
739773f347e7c9572b0f8a8797eff2f423397885c8bGregory P. Smith            for x in (3,):
7409b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                std_variants.append(os.path.join(dn, "db3%d"%x))
7419b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                std_variants.append(os.path.join(dn, "db3.%d"%x))
7429b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren
74338ff36c4ccde02b104553ef1ed979c1261196b48Tim Peters        db_inc_paths = std_variants + db_inc_paths
74400c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro        db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
7459b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren
746e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        db_ver_inc_map = {}
747e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
748e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        class db_found(Exception): pass
74957454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro        try:
75005d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis            # See whether there is a Sleepycat header in the standard
75105d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis            # search path.
752e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            for d in inc_dirs + db_inc_paths:
75305d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis                f = os.path.join(d, "db.h")
754e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                if db_setup_debug: print "db: looking for db.h in", f
75505d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis                if os.path.exists(f):
75605d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis                    f = open(f).read()
757e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                    m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f)
75805d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis                    if m:
759e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        db_major = int(m.group(1))
760e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f)
761e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        db_minor = int(m.group(1))
762e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        db_ver = (db_major, db_minor)
763e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
7641475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                        # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
7651475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                        if db_ver == (4, 6):
7661475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                            m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f)
7671475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                            db_patch = int(m.group(1))
7681475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                            if db_patch < 21:
7691475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                                print "db.h:", db_ver, "patch", db_patch,
7701475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                                print "being ignored (4.6.x must be >= 4.6.21)"
7711475cd876190ccad16e47600958b226bfd788332Gregory P. Smith                                continue
7721475cd876190ccad16e47600958b226bfd788332Gregory P. Smith
773e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        if ( (not db_ver_inc_map.has_key(db_ver)) and
774e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                           (db_ver <= max_db_ver and db_ver >= min_db_ver) ):
775e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                            # save the include directory with the db.h version
77600c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro                            # (first occurrence only)
777e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                            db_ver_inc_map[db_ver] = d
778738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling                            if db_setup_debug:
779738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling                                print "db.h: found", db_ver, "in", d
780e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        else:
781e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                            # we already found a header for this library version
782e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                            if db_setup_debug: print "db.h: ignoring", d
783e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                    else:
784e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        # ignore this header, it didn't contain a version number
78500c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro                        if db_setup_debug:
78600c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro                            print "db.h: no version number version in", d
787e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
788e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_found_vers = db_ver_inc_map.keys()
789e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_found_vers.sort()
790e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
791e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            while db_found_vers:
792e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                db_ver = db_found_vers.pop()
793e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                db_incdir = db_ver_inc_map[db_ver]
794e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
795e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                # check lib directories parallel to the location of the header
796e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                db_dirs_to_check = [
79700c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro                    db_incdir.replace("include", 'lib64'),
79800c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro                    db_incdir.replace("include", 'lib'),
799e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                ]
800e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check)
801e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
802e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                # Look for a version specific db-X.Y before an ambiguoius dbX
803e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                # XXX should we -ever- look for a dbX name?  Do any
804e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                # systems really not name their library by version and
805e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                # symlink to more general names?
806953f98d4bdd27c74e2c4220b90e20f8e6e6c8b7fAndrew MacIntyre                for dblib in (('db-%d.%d' % db_ver),
807953f98d4bdd27c74e2c4220b90e20f8e6e6c8b7fAndrew MacIntyre                              ('db%d%d' % db_ver),
808953f98d4bdd27c74e2c4220b90e20f8e6e6c8b7fAndrew MacIntyre                              ('db%d' % db_ver[0])):
809e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                    dblib_file = self.compiler.find_library_file(
810e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                                    db_dirs_to_check + lib_dirs, dblib )
811e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                    if dblib_file:
812e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
813e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        raise db_found
814e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                    else:
815e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith                        if db_setup_debug: print "db lib: ", dblib, "not found"
816e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith
817e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith        except db_found:
818738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling            if db_setup_debug:
819738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling                print "db lib: using", db_ver, dblib
820738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling                print "db: lib dir", dblib_dir, "inc dir", db_incdir
821e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            db_incs = [db_incdir]
822d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen            dblibs = [dblib]
823e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            # We add the runtime_library_dirs argument because the
824e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            # BerkeleyDB lib we're linking against often isn't in the
825e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            # system dynamic library search path.  This is usually
826e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            # correct and most trouble free, but may cause problems in
827e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            # some unusual system configurations (e.g. the directory
828e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            # is on an NFS server that goes away).
8296aa4a1f29ca575e25fc595857b2a5168a02c9780Martin v. Löwis            exts.append(Extension('_bsddb', ['_bsddb.c'],
830392505391e1703fe0df4da8e077793f7e71b1075Gregory P. Smith                                  depends = ['bsddb.h'],
83105d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis                                  library_dirs=dblib_dir,
83205d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis                                  runtime_library_dirs=dblib_dir,
8336aa4a1f29ca575e25fc595857b2a5168a02c9780Martin v. Löwis                                  include_dirs=db_incs,
8346aa4a1f29ca575e25fc595857b2a5168a02c9780Martin v. Löwis                                  libraries=dblibs))
83557454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro        else:
836e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith            if db_setup_debug: print "db: no appropriate library found"
83757454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro            db_incs = None
83857454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro            dblibs = []
83957454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro            dblib_dir = None
840d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_bsddb')
84157454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro
842c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter        # The sqlite interface
843738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling        sqlite_setup_debug = False   # verbose debug prints from this script?
844c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter
8453dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter        # We hunt for #define SQLITE_VERSION "n.n.n"
8463dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter        # We need to find >= sqlite version 3.0.8
847c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter        sqlite_incdir = sqlite_libdir = None
8483dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter        sqlite_inc_paths = [ '/usr/include',
849c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                             '/usr/include/sqlite',
850c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                             '/usr/include/sqlite3',
851c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                             '/usr/local/include',
852c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                             '/usr/local/include/sqlite',
853c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                             '/usr/local/include/sqlite3',
854c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                           ]
8553dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter        MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
8563dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter        MIN_SQLITE_VERSION = ".".join([str(x)
8573dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                                    for x in MIN_SQLITE_VERSION_NUMBER])
85839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren
85939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren        # Scan the default include directories before the SQLite specific
86039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren        # ones. This allows one to override the copy of sqlite on OSX,
86139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren        # where /usr/include contains an old version of sqlite.
86239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren        for d in inc_dirs + sqlite_inc_paths:
863c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            f = os.path.join(d, "sqlite3.h")
864c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            if os.path.exists(f):
86507f5b35e190ab9be85143c6e8e1217d96bbf75caAnthony Baxter                if sqlite_setup_debug: print "sqlite: found %s"%f
8663dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                incf = open(f).read()
8673dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                m = re.search(
8683dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                    r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf)
869c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                if m:
8703dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                    sqlite_version = m.group(1)
8713dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                    sqlite_version_tuple = tuple([int(x)
8723dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                                        for x in sqlite_version.split(".")])
8733dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                    if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
874c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                        # we win!
875738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling                        if sqlite_setup_debug:
876738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling                            print "%s/sqlite3.h: version %s"%(d, sqlite_version)
877c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                        sqlite_incdir = d
878c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                        break
879c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                    else:
8803dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                        if sqlite_setup_debug:
881c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                            print "%s: version %d is too old, need >= %s"%(d,
882c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                        sqlite_version, MIN_SQLITE_VERSION)
8833dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                elif sqlite_setup_debug:
8843dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                    print "sqlite: %s had no SQLITE_VERSION"%(f,)
8853dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter
886c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter        if sqlite_incdir:
887c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            sqlite_dirs_to_check = [
888c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                os.path.join(sqlite_incdir, '..', 'lib64'),
889c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                os.path.join(sqlite_incdir, '..', 'lib'),
890c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                os.path.join(sqlite_incdir, '..', '..', 'lib64'),
891c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                os.path.join(sqlite_incdir, '..', '..', 'lib'),
892c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            ]
893c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            sqlite_libfile = self.compiler.find_library_file(
894c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                sqlite_dirs_to_check + lib_dirs, 'sqlite3')
895c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
896c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter
897c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter        if sqlite_incdir and sqlite_libdir:
8983e99c0ad649de0393d9a8af17f34d9d1f55f4ab2Gerhard Häring            sqlite_srcs = ['_sqlite/cache.c',
899c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/connection.c',
900c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/cursor.c',
901c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/microprotocols.c',
902c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/module.c',
903c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/prepare_protocol.c',
904c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/row.c',
905c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/statement.c',
906c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                '_sqlite/util.c', ]
907c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter
908c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            sqlite_defines = []
909c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            if sys.platform != "win32":
9108e7b4908901e30f594e52d5fdcdc8b4e2d274ff1Anthony Baxter                sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
911c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            else:
9128e7b4908901e30f594e52d5fdcdc8b4e2d274ff1Anthony Baxter                sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
9138e7b4908901e30f594e52d5fdcdc8b4e2d274ff1Anthony Baxter
91439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren
91539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            if sys.platform == 'darwin':
91639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # In every directory on the search path search for a dynamic
91739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # library and then a static library, instead of first looking
91839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # for dynamic libraries on the entiry path.
91939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # This way a staticly linked custom sqlite gets picked up
92039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                # before the dynamic library in /usr/lib.
92139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                sqlite_extra_link_args = ('-Wl,-search_paths_first',)
92239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren            else:
92339be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                sqlite_extra_link_args = ()
92439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren
925c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter            exts.append(Extension('_sqlite3', sqlite_srcs,
926c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                  define_macros=sqlite_defines,
9273dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter                                  include_dirs=["Modules/_sqlite",
928c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                                sqlite_incdir],
929c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                  library_dirs=sqlite_libdir,
930c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                  runtime_library_dirs=sqlite_libdir,
93139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren                                  extra_link_args=sqlite_extra_link_args,
932c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter                                  libraries=["sqlite3",]))
933d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
934d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_sqlite3')
93522e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro
93622e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        # Look for Berkeley db 1.85.   Note that it is built as a different
93722e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        # module name so it can be included even when later versions are
93822e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        # available.  A very restrictive search is performed to avoid
93922e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        # accidentally building this module with a later version of the
94022e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        # underlying db library.  May BSD-ish Unixes incorporate db 1.85
94122e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        # symbols into libc and place the include file in /usr/include.
9424eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        #
9434eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        # If the better bsddb library can be built (db_incs is defined)
9444eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        # we do not build this one.  Otherwise this build will pick up
9454eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        # the more recent berkeleydb's db.h file first in the include path
9464eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        # when attempting to compile and it will fail.
94722e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro        f = "/usr/include/db.h"
9484eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith        if os.path.exists(f) and not db_incs:
94922e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro            data = open(f).read()
95022e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro            m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data)
95122e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro            if m is not None:
95222e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                # bingo - old version used hash file format version 2
95322e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                ### XXX this should be fixed to not be platform-dependent
95422e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                ### but I don't have direct access to an osf1 platform and
95522e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                ### seemed to be muffing the search somehow
95622e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                libraries = platform == "osf1" and ['db'] or None
95722e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                if libraries is not None:
95822e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                    exts.append(Extension('bsddb185', ['bsddbmodule.c'],
95922e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                                          libraries=libraries))
96022e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                else:
96122e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro                    exts.append(Extension('bsddb185', ['bsddbmodule.c']))
962d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
963d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('bsddb185')
964d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
965d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('bsddb185')
96622e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro
96700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # The standard Unix dbm module:
968d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen        if platform not in ['cygwin']:
969a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis            if find_file("ndbm.h", inc_dirs, []) is not None:
970a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                # Some systems have -lndbm, others don't
971a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                if self.compiler.find_library_file(lib_dirs, 'ndbm'):
972a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                    ndbm_libs = ['ndbm']
973a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                else:
974a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                    ndbm_libs = []
97534febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling                exts.append( Extension('dbm', ['dbmmodule.c'],
976d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen                                       define_macros=[('HAVE_NDBM_H',None)],
977a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                                       libraries = ndbm_libs ) )
978d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen            elif (self.compiler.find_library_file(lib_dirs, 'gdbm')
979d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen                  and find_file("gdbm/ndbm.h", inc_dirs, []) is not None):
980d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen                exts.append( Extension('dbm', ['dbmmodule.c'],
981d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen                                       define_macros=[('HAVE_GDBM_NDBM_H',None)],
98257454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro                                       libraries = ['gdbm'] ) )
98357454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro            elif db_incs is not None:
98457454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro                exts.append( Extension('dbm', ['dbmmodule.c'],
985a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                                       library_dirs=dblib_dir,
986a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis                                       runtime_library_dirs=dblib_dir,
98757454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro                                       include_dirs=db_incs,
988d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen                                       define_macros=[('HAVE_BERKDB_H',None),
989d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen                                                      ('DB_DBM_HSEARCH',None)],
99057454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro                                       libraries=dblibs))
991d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
992d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('dbm')
993ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
99400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Anthony Baxter's gdbm module.  GNU dbm(3) will require -lgdbm:
99500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
99600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('gdbm', ['gdbmmodule.c'],
99700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                                   libraries = ['gdbm'] ) )
998d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
999d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('gdbm')
100000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
100100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Unix-only modules
100234febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling        if platform not in ['mac', 'win32']:
100300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            # Steen Lumholt's termios module
100400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('termios', ['termios.c']) )
100500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            # Jeremy Hylton's rlimit interface
10062c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            if platform not in ['atheos']:
1007f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis                exts.append( Extension('resource', ['resource.c']) )
1008d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
1009d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('resource')
101000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
1011cf393f3fd9759ffac71c816f97ea01780848512cAndrew M. Kuchling            # Sun yellow pages. Some systems have the functions in libc.
1012f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis            if platform not in ['cygwin', 'atheos']:
10136efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling                if (self.compiler.find_library_file(lib_dirs, 'nsl')):
10146efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling                    libs = ['nsl']
10156efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling                else:
10166efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling                    libs = []
10176efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling                exts.append( Extension('nis', ['nismodule.c'],
10186efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling                                       libraries = libs) )
1019d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
1020d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('nis')
1021d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1022d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.extend(['nis', 'resource', 'termios'])
102300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
102472092941125cb0a3577fbf63294d14a02bb5dd2aSkip Montanaro        # Curses support, requiring the System V version of curses, often
1025ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        # provided by the ncurses library.
102686070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling        panel_library = 'panel'
1027a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis        if (self.compiler.find_library_file(lib_dirs, 'ncursesw')):
1028a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis            curses_libs = ['ncursesw']
102986070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling            # Bug 1464056: If _curses.so links with ncursesw,
103086070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling            # _curses_panel.so must link with panelw.
103186070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling            panel_library = 'panelw'
1032a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis            exts.append( Extension('_curses', ['_cursesmodule.c'],
1033a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis                                   libraries = curses_libs) )
1034a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis        elif (self.compiler.find_library_file(lib_dirs, 'ncurses')):
103500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            curses_libs = ['ncurses']
103600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('_curses', ['_cursesmodule.c'],
103700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                                   libraries = curses_libs) )
103838419c003c7f162d937320d01edce0c97ef502c3Fred Drake        elif (self.compiler.find_library_file(lib_dirs, 'curses')
103938419c003c7f162d937320d01edce0c97ef502c3Fred Drake              and platform != 'darwin'):
10405b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson                # OSX has an old Berkeley curses, not good enough for
10415b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson                # the _curses module.
104200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
104300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                curses_libs = ['curses', 'terminfo']
10440b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz            elif (self.compiler.find_library_file(lib_dirs, 'termcap')):
104500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                curses_libs = ['curses', 'termcap']
10460b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz            else:
10470b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz                curses_libs = ['curses']
1048ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
104900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('_curses', ['_cursesmodule.c'],
105000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                                   libraries = curses_libs) )
1051d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1052d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_curses')
1053ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
105400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # If the curses module is enabled, check for the panel module
1055e7ffbb24e80800de3667a88af96d03f8c9717039Andrew M. Kuchling        if (module_enabled(exts, '_curses') and
105686070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling            self.compiler.find_library_file(lib_dirs, panel_library)):
105700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('_curses_panel', ['_curses_panel.c'],
105886070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling                                   libraries = [panel_library] + curses_libs) )
1059d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1060d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_curses_panel')
1061ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
1062259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # Andrew Kuchling's zlib module.  Note that some versions of zlib
1063259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # 1.1.3 have security problems.  See CERT Advisory CA-2002-07:
1064259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # http://www.cert.org/advisories/CA-2002-07.html
1065259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        #
1066259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1067259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # patch its zlib 1.1.3 package instead of upgrading to 1.1.4.  For
1068259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # now, we still accept 1.1.3, because we think it's difficult to
1069259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # exploit this in Python, and we'd rather make it RedHat's problem
1070259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # than our problem <wink>.
1071259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        #
1072259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # You can upgrade zlib to version 1.1.4 yourself by going to
1073259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw        # http://www.gzip.org/zlib/
1074e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum        zlib_inc = find_file('zlib.h', [], inc_dirs)
1075440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith        have_zlib = False
1076e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum        if zlib_inc is not None:
1077e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum            zlib_h = zlib_inc[0] + '/zlib.h'
1078e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum            version = '"0.0.0"'
1079259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw            version_req = '"1.1.3"'
1080e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum            fp = open(zlib_h)
1081e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum            while 1:
1082e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                line = fp.readline()
1083e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                if not line:
1084e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                    break
10858cdc03dca571fd2847d68bfd220234c0153f8f47Guido van Rossum                if line.startswith('#define ZLIB_VERSION'):
1086e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                    version = line.split()[2]
1087e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                    break
1088e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum            if version >= version_req:
1089e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                if (self.compiler.find_library_file(lib_dirs, 'z')):
10909b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                    if sys.platform == "darwin":
10919b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                        zlib_extra_link_args = ('-Wl,-search_paths_first',)
10929b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                    else:
10939b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                        zlib_extra_link_args = ()
1094e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum                    exts.append( Extension('zlib', ['zlibmodule.c'],
10959b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                                           libraries = ['z'],
10969b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                                           extra_link_args = zlib_extra_link_args))
1097440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith                    have_zlib = True
1098d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                else:
1099d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                    missing.append('zlib')
1100d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
1101d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('zlib')
1102d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1103d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('zlib')
110400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
1105440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith        # Helper module for various ascii-encoders.  Uses zlib for an optimized
1106440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith        # crc32 if we have it.  Otherwise binascii uses its own.
1107440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith        if have_zlib:
1108440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith            extra_compile_args = ['-DUSE_ZLIB_CRC32']
1109440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith            libraries = ['z']
1110440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith            extra_link_args = zlib_extra_link_args
1111440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith        else:
1112440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith            extra_compile_args = []
1113440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith            libraries = []
1114440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith            extra_link_args = []
1115440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith        exts.append( Extension('binascii', ['binascii.c'],
1116440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith                               extra_compile_args = extra_compile_args,
1117440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith                               libraries = libraries,
1118440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith                               extra_link_args = extra_link_args) )
1119440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith
1120f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer        # Gustavo Niemeyer's bz2 module.
1121f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer        if (self.compiler.find_library_file(lib_dirs, 'bz2')):
11229b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren            if sys.platform == "darwin":
11239b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                bz2_extra_link_args = ('-Wl,-search_paths_first',)
11249b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren            else:
11259b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                bz2_extra_link_args = ()
1126f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer            exts.append( Extension('bz2', ['bz2module.c'],
11279b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                                   libraries = ['bz2'],
11289b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren                                   extra_link_args = bz2_extra_link_args) )
1129d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1130d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('bz2')
1131f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer
113200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Interface to the Expat XML parser
113300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        #
1134fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        # Expat was written by James Clark and is now maintained by a
1135fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        # group of developers on SourceForge; see www.libexpat.org for
1136fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        # more information.  The pyexpat module was written by Paul
113799f3ba1648004af22ede20d09d567cb33dce3db8Andrew M. Kuchling        # Prescod after a prototype by Jack Jansen.  The Expat source
113899f3ba1648004af22ede20d09d567cb33dce3db8Andrew M. Kuchling        # is included in Modules/expat/.  Usage of a system
1139fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        # shared libexpat.so/expat.dll is not advised.
1140fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        #
1141fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        # More information on Expat can be found at www.libexpat.org.
1142fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake        #
11438301256a440fdd98fd500d225dac20ebb192e08fMartin v. Löwis        expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
11442d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake        define_macros = [
1145988117fd6323c2b21ce1bdb2b1153a5d759a511cRonald Oussoren            ('HAVE_EXPAT_CONFIG_H', '1'),
1146988117fd6323c2b21ce1bdb2b1153a5d759a511cRonald Oussoren        ]
1147988117fd6323c2b21ce1bdb2b1153a5d759a511cRonald Oussoren
11482d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake        exts.append(Extension('pyexpat',
11492d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                              define_macros = define_macros,
11502d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                              include_dirs = [expatinc],
11512d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                              sources = ['pyexpat.c',
11522d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                                         'expat/xmlparse.c',
11532d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                                         'expat/xmlrole.c',
11542d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                                         'expat/xmltok.c',
11552d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                                         ],
11562d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake                              ))
115700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
11584c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh        # Fredrik Lundh's cElementTree module.  Note that this also
11594c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh        # uses expat (via the CAPI hook in pyexpat).
11604c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh
11616c403597954487e8129221351f72da3735c52c09Hye-Shik Chang        if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')):
11624c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh            define_macros.append(('USE_PYEXPAT_CAPI', None))
11634c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh            exts.append(Extension('_elementtree',
11644c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh                                  define_macros = define_macros,
11654c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh                                  include_dirs = [expatinc],
11664c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh                                  sources = ['_elementtree.c'],
11674c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh                                  ))
1168d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1169d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_elementtree')
11704c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh
11713e2a30692085d32ac63f72b35da39158a471fc68Hye-Shik Chang        # Hye-Shik Chang's CJKCodecs modules.
1172e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis        if have_unicode:
1173e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis            exts.append(Extension('_multibytecodec',
1174e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis                                  ['cjkcodecs/multibytecodec.c']))
1175e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis            for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
1176d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                exts.append(Extension('_codecs_%s' % loc,
1177e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis                                      ['cjkcodecs/_codecs_%s.c' % loc]))
1178d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1179d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_multibytecodec')
1180d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
1181d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('_codecs_%s' % loc)
11823e2a30692085d32ac63f72b35da39158a471fc68Hye-Shik Chang
11835b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson        # Dynamic loading module
1184770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum        if sys.maxint == 0x7fffffff:
1185770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum            # This requires sizeof(int) == sizeof(long) == sizeof(char*)
1186770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum            dl_inc = find_file('dlfcn.h', [], inc_dirs)
11878220174489e3f28b874b3b45516585c30e5999daAnthony Baxter            if (dl_inc is not None) and (platform not in ['atheos']):
1188770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum                exts.append( Extension('dl', ['dlmodule.c']) )
1189d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            else:
1190d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro                missing.append('dl')
1191d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1192d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('dl')
11935b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
1194cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        # Thomas Heller's _ctypes module
11959176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        self.detect_ctypes(inc_dirs, lib_dirs)
1196cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller
119700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # Platform-specific libraries
119834febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling        if platform == 'linux2':
119900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            # Linux-specific modules
120000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
1201d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1202d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('linuxaudiodev')
12030a6355eb1fb5af03827a00e146c147c94efe78c9Greg Ward
12044e422817eb1bc5a6a42365001ad45683ae07e559Hye-Shik Chang        if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
1205ea684743daa0c198ab327d07832eca48a9578c68Hye-Shik Chang                        'freebsd7', 'freebsd8'):
12060c016a9590b3da47f19420d0616e0c72cae19abfGuido van Rossum            exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
1207d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1208d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('ossaudiodev')
120900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
121034febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling        if platform == 'sunos5':
1211ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh            # SunOS specific modules
121200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling            exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
1213d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        else:
1214d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('sunaudiodev')
12155b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
121666cb018c96e49b5e5cf1b8fc395171a223d86d8eTim Peters        if platform == 'darwin' and ("--disable-toolbox-glue" not in
1217090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                sysconfig.get_config_var("CONFIG_ARGS")):
1218090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren
1219090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren            if os.uname()[2] > '8.':
1220090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                # We're on Mac OS X 10.4 or later, the compiler should
1221090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                # support '-Wno-deprecated-declarations'. This will
1222090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                # surpress deprecation warnings for the Carbon extensions,
1223090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                # these extensions wrap the Carbon APIs and even those
1224090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                # parts that are deprecated.
1225090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                carbon_extra_compile_args = ['-Wno-deprecated-declarations']
1226090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren            else:
1227090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                carbon_extra_compile_args = []
1228090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren
122905ced6aa761bab7348e95a479b6f791e636ceae7Just van Rossum            # Mac OS X specific modules.
12303e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            def macSrcExists(name1, name2=''):
12313e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                if not name1:
12323e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    return None
12333e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                names = (name1,)
12343e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                if name2:
12353e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    names = (name1, name2)
12363e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                path = os.path.join(srcdir, 'Mac', 'Modules', *names)
12373e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                return os.path.exists(path)
12383e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
12393e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            def addMacExtension(name, kwds, extra_srcs=[]):
12403e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                dirname = ''
12413e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                if name[0] == '_':
12423e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    dirname = name[1:].lower()
12433e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                cname = name + '.c'
12443e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                cmodulename = name + 'module.c'
12453e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                # Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c
12463e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                if macSrcExists(cname):
12473e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    srcs = [cname]
12483e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                elif macSrcExists(cmodulename):
12493e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    srcs = [cmodulename]
12503e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                elif macSrcExists(dirname, cname):
12513e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    # XXX(nnorwitz): If all the names ended with module, we
12523e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    # wouldn't need this condition.  ibcarbon is the only one.
12533e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    srcs = [os.path.join(dirname, cname)]
12543e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                elif macSrcExists(dirname, cmodulename):
12553e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    srcs = [os.path.join(dirname, cmodulename)]
12563e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                else:
12573e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                    raise RuntimeError("%s not found" % name)
12583e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
12593e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                # Here's the whole point:  add the extension with sources
12603e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                exts.append(Extension(name, srcs + extra_srcs, **kwds))
12613e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
12623e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            # Core Foundation
12633e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            core_kwds = {'extra_compile_args': carbon_extra_compile_args,
12643e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                         'extra_link_args': ['-framework', 'CoreFoundation'],
12653e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                        }
12663e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            addMacExtension('_CF', core_kwds, ['cf/pycfbridge.c'])
12673e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            addMacExtension('autoGIL', core_kwds)
12683e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
12693e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            # Carbon
12703e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            carbon_kwds = {'extra_compile_args': carbon_extra_compile_args,
12713e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                           'extra_link_args': ['-framework', 'Carbon'],
12723e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                          }
1273a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter            CARBON_EXTS = ['ColorPicker', 'gestalt', 'MacOS', 'Nav',
1274a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter                           'OSATerminology', 'icglue',
12753e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                           # All these are in subdirs
1276a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter                           '_AE', '_AH', '_App', '_CarbonEvt', '_Cm', '_Ctl',
12773e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                           '_Dlg', '_Drag', '_Evt', '_File', '_Folder', '_Fm',
1278a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter                           '_Help', '_Icn', '_IBCarbon', '_List',
1279a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter                           '_Menu', '_Mlte', '_OSA', '_Res', '_Qd', '_Qdoffs',
12803e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                           '_Scrap', '_Snd', '_TE', '_Win',
1281a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter                          ]
12823e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            for name in CARBON_EXTS:
12833e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                addMacExtension(name, carbon_kwds)
12843e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
12853e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            # Application Services & QuickTime
12863e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            app_kwds = {'extra_compile_args': carbon_extra_compile_args,
12873e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                        'extra_link_args': ['-framework','ApplicationServices'],
12883e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz                       }
12893e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            addMacExtension('_Launch', app_kwds)
12903e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz            addMacExtension('_CG', app_kwds)
12913e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
129205ced6aa761bab7348e95a479b6f791e636ceae7Just van Rossum            exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
1293090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                        extra_compile_args=carbon_extra_compile_args,
1294090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren                        extra_link_args=['-framework', 'QuickTime',
129505ced6aa761bab7348e95a479b6f791e636ceae7Just van Rossum                                     '-framework', 'Carbon']) )
12963e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz
12975b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
1298fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        self.extensions.extend(exts)
1299fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
1300fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # Call the method for detecting whether _tkinter can be compiled
1301fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        self.detect_tkinter(inc_dirs, lib_dirs)
1302ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
1303d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        if '_tkinter' not in [e.name for e in self.extensions]:
1304d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro            missing.append('_tkinter')
1305d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
1306d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro        return missing
1307d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro
13080b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen    def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
13090b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # The _tkinter module, using frameworks. Since frameworks are quite
13100b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # different the UNIX search logic is not sharable.
13110b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        from os.path import join, exists
13120b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        framework_dirs = [
13132c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            '/System/Library/Frameworks/',
13142c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            '/Library/Frameworks',
13150b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            join(os.getenv('HOME'), '/Library/Frameworks')
13160b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        ]
13170b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen
13180174dddc65af50900324afca3c5d2400858b75f0Skip Montanaro        # Find the directory that contains the Tcl.framework and Tk.framework
13190b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # bundles.
13200b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # XXX distutils should support -F!
13210b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        for F in framework_dirs:
13222c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            # both Tcl.framework and Tk.framework should be present
13230b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            for fw in 'Tcl', 'Tk':
13242c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters                if not exists(join(F, fw + '.framework')):
13250b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                    break
13260b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            else:
13270b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                # ok, F is now directory with both frameworks. Continure
13280b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                # building
13290b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                break
13300b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        else:
13310b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            # Tk and Tcl frameworks not found. Normal "unix" tkinter search
13320b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            # will now resume.
13330b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            return 0
13342c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters
13350b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # For 8.4a2, we must add -I options that point inside the Tcl and Tk
13360b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # frameworks. In later release we should hopefully be able to pass
13372c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters        # the -F option to gcc, which specifies a framework lookup path.
13380b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        #
13390b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        include_dirs = [
13402c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            join(F, fw + '.framework', H)
13410b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            for fw in 'Tcl', 'Tk'
13420b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen            for H in 'Headers', 'Versions/Current/PrivateHeaders'
13430b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        ]
13440b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen
13452c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters        # For 8.4a2, the X11 headers are not included. Rather than include a
13460b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # complicated search, this is a hard-coded path. It could bail out
13470b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # if X11 libs are not found...
13480b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        include_dirs.append('/usr/X11R6/include')
13490b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
13500b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen
13510b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
13520b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                        define_macros=[('WITH_APPINIT', 1)],
13530b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                        include_dirs = include_dirs,
13540b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                        libraries = [],
13550b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                        extra_compile_args = frameworks,
13560b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                        extra_link_args = frameworks,
13570b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen                        )
13580b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        self.extensions.append(ext)
13590b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        return 1
13600b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen
13612c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters
1362fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling    def detect_tkinter(self, inc_dirs, lib_dirs):
136300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # The _tkinter module.
13645b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
13650b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # Rather than complicate the code below, detecting and building
13660b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # AquaTk is a separate method. Only one Tkinter will be built on
13670b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        # Darwin - either AquaTk, if it is found, or X11 based Tk.
13680b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen        platform = self.get_platform()
13690174dddc65af50900324afca3c5d2400858b75f0Skip Montanaro        if (platform == 'darwin' and
13700174dddc65af50900324afca3c5d2400858b75f0Skip Montanaro            self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
13712c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters            return
13720b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen
1373fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # Assume we haven't found any of the libraries or include files
13743db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis        # The versions with dots are used on Unix, and the versions without
13753db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis        # dots on Windows, for detection by cygwin.
1376fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        tcllib = tklib = tcl_includes = tk_includes = None
13774c4a45de8f992bb0c5cf35910d34ed6c63fa9d14Andrew M. Kuchling        for version in ['8.5', '85', '8.4', '84', '8.3', '83', '8.2',
13783db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis                        '82', '8.1', '81', '8.0', '80']:
1379cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler            tklib = self.compiler.find_library_file(lib_dirs, 'tk' + version)
1380cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler            tcllib = self.compiler.find_library_file(lib_dirs, 'tcl' + version)
13815b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson            if tklib and tcllib:
138200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                # Exit the loop when we've found the Tcl/Tk libraries
138300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling                break
1384fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
1385ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        # Now check for the header files
1386fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        if tklib and tcllib:
13873c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            # Check for the include files on Debian and {Free,Open}BSD, where
1388fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            # they're put in /usr/include/{tcl,tk}X.Y
13893c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            dotversion = version
13903c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            if '.' not in dotversion and "bsd" in sys.platform.lower():
13913c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling                # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
13923c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling                # but the include subdirs are named like .../include/tcl8.3.
13933c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling                dotversion = dotversion[:-1] + '.' + dotversion[-1]
13943c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            tcl_include_sub = []
13953c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            tk_include_sub = []
13963c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            for dir in inc_dirs:
13973c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling                tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
13983c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling                tk_include_sub += [dir + os.sep + "tk" + dotversion]
13993c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            tk_include_sub += tcl_include_sub
14003c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub)
14013c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            tk_includes = find_file('tk.h', inc_dirs, tk_include_sub)
1402fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
1403e86a59af886d6c0f58f53e42878a25e48627fed1Martin v. Löwis        if (tcllib is None or tklib is None or
1404fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            tcl_includes is None or tk_includes is None):
14053c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling            self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
1406fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            return
1407ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
1408fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # OK... everything seems to be present for Tcl/Tk.
1409fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
1410fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
1411fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        for dir in tcl_includes + tk_includes:
1412fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            if dir not in include_dirs:
1413fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                include_dirs.append(dir)
1414ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
1415fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # Check for various platform-specific directories
141634febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling        if platform == 'sunos5':
1417fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            include_dirs.append('/usr/openwin/include')
1418fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            added_lib_dirs.append('/usr/openwin/lib')
1419fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        elif os.path.exists('/usr/X11R6/include'):
1420fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            include_dirs.append('/usr/X11R6/include')
1421fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis            added_lib_dirs.append('/usr/X11R6/lib64')
1422fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            added_lib_dirs.append('/usr/X11R6/lib')
1423fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        elif os.path.exists('/usr/X11R5/include'):
1424fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            include_dirs.append('/usr/X11R5/include')
1425fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            added_lib_dirs.append('/usr/X11R5/lib')
1426fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        else:
1427ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh            # Assume default location for X11
1428fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            include_dirs.append('/usr/X11/include')
1429fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            added_lib_dirs.append('/usr/X11/lib')
1430fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
14319181c94e05250b8f69615a96634d55afe532e406Jason Tishler        # If Cygwin, then verify that X is installed before proceeding
14329181c94e05250b8f69615a96634d55afe532e406Jason Tishler        if platform == 'cygwin':
14339181c94e05250b8f69615a96634d55afe532e406Jason Tishler            x11_inc = find_file('X11/Xlib.h', [], include_dirs)
14349181c94e05250b8f69615a96634d55afe532e406Jason Tishler            if x11_inc is None:
14359181c94e05250b8f69615a96634d55afe532e406Jason Tishler                return
14369181c94e05250b8f69615a96634d55afe532e406Jason Tishler
1437fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # Check for BLT extension
143838419c003c7f162d937320d01edce0c97ef502c3Fred Drake        if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
143938419c003c7f162d937320d01edce0c97ef502c3Fred Drake                                           'BLT8.0'):
1440fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            defs.append( ('WITH_BLT', 1) )
1441fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            libs.append('BLT8.0')
1442427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis        elif self.compiler.find_library_file(lib_dirs + added_lib_dirs,
1443427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis                                           'BLT'):
1444427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis            defs.append( ('WITH_BLT', 1) )
1445427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis            libs.append('BLT')
1446fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
1447fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # Add the Tcl/Tk libraries
1448cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler        libs.append('tk'+ version)
1449cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler        libs.append('tcl'+ version)
1450ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
145134febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling        if platform in ['aix3', 'aix4']:
1452fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling            libs.append('ld')
1453fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
14543db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis        # Finally, link with the X11 libraries (not appropriate on cygwin)
14553db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis        if platform != "cygwin":
14563db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis            libs.append('X11')
1457fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling
1458fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1459fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                        define_macros=[('WITH_APPINIT', 1)] + defs,
1460fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                        include_dirs = include_dirs,
1461fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                        libraries = libs,
1462fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                        library_dirs = added_lib_dirs,
1463fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling                        )
1464fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        self.extensions.append(ext)
1465ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
14666c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum##         # Uncomment these lines if you want to play with xxmodule.c
14676c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum##         ext = Extension('xx', ['xxmodule.c'])
14686c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum##         self.extensions.append(ext)
14696c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum
1470fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling        # XXX handle these, but how to detect?
147100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # *** Uncomment and edit for PIL (TkImaging) extension only:
1472ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        #       -DWITH_PIL -I../Extensions/Imaging/libImaging  tkImaging.c \
147300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # *** Uncomment and edit for TOGL extension only:
1474ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        #       -DWITH_TOGL togl.c \
147500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        # *** Uncomment these for TOGL extension only:
1476ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh        #       -lGL -lGLU -lXext -lXmu \
147700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling
14788bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller    def configure_ctypes_darwin(self, ext):
14798bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        # Darwin (OS X) uses preconfigured files, in
14808bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        # the Modules/_ctypes/libffi_osx directory.
14818bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        (srcdir,) = sysconfig.get_config_vars('srcdir')
14828bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
14838bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                                                  '_ctypes', 'libffi_osx'))
14848bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        sources = [os.path.join(ffi_srcdir, p)
14858bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                   for p in ['ffi.c',
14868bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'x86/x86-darwin.S',
14878bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'x86/x86-ffi_darwin.c',
14888bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'x86/x86-ffi64.c',
14898bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'powerpc/ppc-darwin.S',
14908bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'powerpc/ppc-darwin_closure.S',
14918bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'powerpc/ppc-ffi_darwin.c',
14928bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             'powerpc/ppc64-darwin_closure.S',
14938bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                             ]]
14948bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller
14958bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        # Add .S (preprocessed assembly) to C compiler source extensions.
14968bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        self.compiler.src_extensions.append('.S')
14978bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller
14988bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        include_dirs = [os.path.join(ffi_srcdir, 'include'),
14998bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                        os.path.join(ffi_srcdir, 'powerpc')]
15008bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        ext.include_dirs.extend(include_dirs)
15018bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        ext.sources.extend(sources)
15028bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        return True
15038bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller
1504eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller    def configure_ctypes(self, ext):
15059176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        if not self.use_system_libffi:
15068bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller            if sys.platform == 'darwin':
15078bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller                return self.configure_ctypes_darwin(ext)
15088bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller
15099176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            (srcdir,) = sysconfig.get_config_vars('srcdir')
15109176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ffi_builddir = os.path.join(self.build_temp, 'libffi')
15119176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
15129176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                                         '_ctypes', 'libffi'))
15139176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
15149176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15155e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller            from distutils.dep_util import newer_group
15165e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller
15175e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller            config_sources = [os.path.join(ffi_srcdir, fname)
1518f1a4aa340ea3794a6cc2d54fb6647b4d7b61f275Martin v. Löwis                              for fname in os.listdir(ffi_srcdir)
1519f1a4aa340ea3794a6cc2d54fb6647b4d7b61f275Martin v. Löwis                              if os.path.isfile(os.path.join(ffi_srcdir, fname))]
15205e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller            if self.force or newer_group(config_sources,
15215e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller                                         ffi_configfile):
15229176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                from distutils.dir_util import mkpath
15239176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                mkpath(ffi_builddir)
15249176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                config_args = []
15259176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15269176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                # Pass empty CFLAGS because we'll just append the resulting
15279176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                # CFLAGS to Python's; -g or -O2 is to be avoided.
15289176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
15299176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                      % (ffi_builddir, ffi_srcdir, " ".join(config_args))
15309176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15319176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                res = os.system(cmd)
15329176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                if res or not os.path.exists(ffi_configfile):
15339176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    print "Failed to configure _ctypes module"
15349176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    return False
15359176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15369176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            fficonfig = {}
15379176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            execfile(ffi_configfile, globals(), fficonfig)
15389176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
15399176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15409176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            # Add .S (preprocessed assembly) to C compiler source extensions.
15419176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            self.compiler.src_extensions.append('.S')
15429176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15439176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            include_dirs = [os.path.join(ffi_builddir, 'include'),
15449176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                            ffi_builddir, ffi_srcdir]
15459176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            extra_compile_args = fficonfig['ffi_cflags'].split()
15469176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
15479176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ext.sources.extend(fficonfig['ffi_sources'])
15489176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ext.include_dirs.extend(include_dirs)
15499176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ext.extra_compile_args.extend(extra_compile_args)
1550795246cf9937f088f8d98253f38da4a093c08300Thomas Heller        return True
1551eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller
15529176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis    def detect_ctypes(self, inc_dirs, lib_dirs):
15539176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        self.use_system_libffi = False
1554eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller        include_dirs = []
1555eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller        extra_compile_args = []
15561798489547a259876c495280dcd5d649269967f3Thomas Heller        extra_link_args = []
1557cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        sources = ['_ctypes/_ctypes.c',
1558cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                   '_ctypes/callbacks.c',
1559cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                   '_ctypes/callproc.c',
1560cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                   '_ctypes/stgdict.c',
1561cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                   '_ctypes/cfield.c',
1562eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller                   '_ctypes/malloc_closure.c']
1563cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        depends = ['_ctypes/ctypes.h']
1564cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller
1565cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        if sys.platform == 'darwin':
1566cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller            sources.append('_ctypes/darwin/dlfcn_simple.c')
15678bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller            extra_compile_args.append('-DMACOSX')
1568cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller            include_dirs.append('_ctypes/darwin')
1569cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller# XXX Is this still needed?
1570cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller##            extra_link_args.extend(['-read_only_relocs', 'warning'])
1571cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller
15721798489547a259876c495280dcd5d649269967f3Thomas Heller        elif sys.platform == 'sunos5':
157373f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # XXX This shouldn't be necessary; it appears that some
157473f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # of the assembler code is non-PIC (i.e. it has relocations
157573f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # when it shouldn't. The proper fix would be to rewrite
157673f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # the assembler code to be PIC.
157773f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # This only works with GCC; the Sun compiler likely refuses
157873f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # this option. If you want to compile ctypes with the Sun
157973f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # compiler, please research a proper solution, instead of
158073f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis            # finding some -z option for the Sun compiler.
15811798489547a259876c495280dcd5d649269967f3Thomas Heller            extra_link_args.append('-mimpure-text')
15821798489547a259876c495280dcd5d649269967f3Thomas Heller
158303b75ddf7c63bb7b7bc1b424661c94076b57be9eThomas Heller        elif sys.platform.startswith('hpux'):
158403b75ddf7c63bb7b7bc1b424661c94076b57be9eThomas Heller            extra_link_args.append('-fPIC')
158503b75ddf7c63bb7b7bc1b424661c94076b57be9eThomas Heller
1586cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        ext = Extension('_ctypes',
1587cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                        include_dirs=include_dirs,
1588cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                        extra_compile_args=extra_compile_args,
15891798489547a259876c495280dcd5d649269967f3Thomas Heller                        extra_link_args=extra_link_args,
15909176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                        libraries=[],
1591cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                        sources=sources,
1592cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                        depends=depends)
1593cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        ext_test = Extension('_ctypes_test',
1594cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller                             sources=['_ctypes/_ctypes_test.c'])
1595cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller        self.extensions.extend([ext, ext_test])
1596cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller
15979176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
15989176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            return
15999176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
16008bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller        if sys.platform == 'darwin':
16018bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller            # OS X 10.5 comes with libffi.dylib; the include files are
16028bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller            # in /usr/include/ffi
16038bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller            inc_dirs.append('/usr/include/ffi')
16048bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller
16059176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        ffi_inc = find_file('ffi.h', [], inc_dirs)
16069176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        if ffi_inc is not None:
16079176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ffi_h = ffi_inc[0] + '/ffi.h'
16089176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            fp = open(ffi_h)
16099176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            while 1:
16109176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                line = fp.readline()
16119176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                if not line:
16129176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    ffi_inc = None
16139176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    break
16149176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                if line.startswith('#define LIBFFI_H'):
16159176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    break
16169176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        ffi_lib = None
16179176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        if ffi_inc is not None:
16189176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):
16199176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                if (self.compiler.find_library_file(lib_dirs, lib_name)):
16209176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    ffi_lib = lib_name
16219176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis                    break
16229176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
16239176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis        if ffi_inc and ffi_lib:
16249176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ext.include_dirs.extend(ffi_inc)
16259176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            ext.libraries.append(ffi_lib)
16269176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis            self.use_system_libffi = True
16279176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
16289176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis
1629f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchlingclass PyBuildInstall(install):
1630f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling    # Suppress the warning about installation into the lib_dynload
1631f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling    # directory, which is not in sys.path when running Python during
1632f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling    # installation:
1633f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling    def initialize_options (self):
1634f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling        install.initialize_options(self)
1635f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling        self.warn_dir=0
16365b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson
1637529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudsonclass PyBuildInstallLib(install_lib):
1638529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    # Do exactly what install_lib does but make sure correct access modes get
1639529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    # set on installed directories and files. All installed files with get
1640529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    # mode 644 unless they are a shared library in which case they will get
1641529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    # mode 755. All installed directories will get mode 755.
1642529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1643529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    so_ext = sysconfig.get_config_var("SO")
1644529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1645529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    def install(self):
1646529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        outfiles = install_lib.install(self)
1647529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        self.set_file_modes(outfiles, 0644, 0755)
1648529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        self.set_dir_modes(self.install_dir, 0755)
1649529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        return outfiles
1650529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1651529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    def set_file_modes(self, files, defaultMode, sharedLibMode):
1652529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        if not self.is_chmod_supported(): return
1653529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        if not files: return
1654529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1655529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        for filename in files:
1656529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson            if os.path.islink(filename): continue
1657529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson            mode = defaultMode
1658529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson            if filename.endswith(self.so_ext): mode = sharedLibMode
1659529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson            log.info("changing mode of %s to %o", filename, mode)
1660529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson            if not self.dry_run: os.chmod(filename, mode)
1661529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1662529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    def set_dir_modes(self, dirname, mode):
1663529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        if not self.is_chmod_supported(): return
1664529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        os.path.walk(dirname, self.set_dir_modes_visitor, mode)
1665529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1666529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    def set_dir_modes_visitor(self, mode, dirname, names):
1667529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        if os.path.islink(dirname): return
1668529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        log.info("changing mode of %s to %o", dirname, mode)
1669529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        if not self.dry_run: os.chmod(dirname, mode)
1670529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
1671529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson    def is_chmod_supported(self):
1672529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson        return hasattr(os, 'chmod')
1673529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson
167414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumSUMMARY = """
167514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumPython is an interpreted, interactive, object-oriented programming
167614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumlanguage. It is often compared to Tcl, Perl, Scheme or Java.
167714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum
167814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumPython combines remarkable power with very clear syntax. It has
167914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossummodules, classes, exceptions, very high level dynamic data types, and
168014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumdynamic typing. There are interfaces to many system calls and
168114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumlibraries, as well as to various windowing systems (X11, Motif, Tk,
168214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumMac, MFC). New built-in modules are easily written in C or C++. Python
168314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumis also usable as an extension language for applications that need a
168414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumprogrammable interface.
168514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum
168614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumThe Python implementation is portable: it runs on many brands of UNIX,
168714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumon Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't
168814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumlisted here, it may still be supported, if there's a C compiler for
168914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumit. Ask around on comp.lang.python -- or just try compiling Python
169014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumyourself.
169114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum"""
169214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum
169314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumCLASSIFIERS = """
169414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumDevelopment Status :: 3 - Alpha
169514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumDevelopment Status :: 6 - Mature
169614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumLicense :: OSI Approved :: Python Software Foundation License
169714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumNatural Language :: English
169814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumProgramming Language :: C
169914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumProgramming Language :: Python
170014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumTopic :: Software Development
170114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum"""
170214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum
170300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingdef main():
170462686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling    # turn off warnings when deprecated modules are imported
170562686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling    import warnings
170662686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling    warnings.filterwarnings("ignore",category=DeprecationWarning)
170714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum    setup(# PyPI Metadata (PEP 301)
170814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          name = "Python",
170914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          version = sys.version.split()[0],
171014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          url = "http://www.python.org/%s" % sys.version[:3],
171114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          maintainer = "Guido van Rossum and the Python community",
171214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          maintainer_email = "python-dev@python.org",
171314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          description = "A high-level object-oriented programming language",
171414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          long_description = SUMMARY.strip(),
171514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          license = "PSF license",
171614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          classifiers = filter(None, CLASSIFIERS.split("\n")),
171714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          platforms = ["Many"],
171814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum
171914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum          # Build info
1720529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson          cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall,
1721529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson                      'install_lib':PyBuildInstallLib},
172200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling          # The struct module is defined here, because build_ext won't be
172300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling          # called unless there's at least one extension module defined.
17247ccc95a315315568dd0660b5fb915f9e2e38f9daBob Ippolito          ext_modules=[Extension('_struct', ['_struct.c'])],
1725aece4270b1de4777eef3f2aadd7aaf3ac9b69ceeAndrew M. Kuchling
1726aece4270b1de4777eef3f2aadd7aaf3ac9b69ceeAndrew M. Kuchling          # Scripts to install
1727852f79993f8d04f00f54a94e7275550a72454f5fSkip Montanaro          scripts = ['Tools/scripts/pydoc', 'Tools/scripts/idle',
1728cdbc977c0344cfe2294e8be69cd1acd77b3b79adMartin v. Löwis                     'Tools/scripts/2to3',
1729852f79993f8d04f00f54a94e7275550a72454f5fSkip Montanaro                     'Lib/smtpd.py']
173000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling        )
1731ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh
173200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling# --install-platlib
173300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingif __name__ == '__main__':
173400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling    main()
1735