setup.py revision ef3dab28f25c6725c789704ef140e23071ceb923
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 80902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smithfrom platform import machine as platform_machine 9529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 10529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudsonfrom distutils import log 1100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingfrom distutils import sysconfig 128d7f0869ee672d7e9e8e1bf126bf717d8223ee2bAndrew M. Kuchlingfrom distutils import text_file 137c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburgfrom distutils.errors import * 1400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingfrom distutils.core import Extension, setup 1500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingfrom distutils.command.build_ext import build_ext 16f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchlingfrom distutils.command.install import install 17529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudsonfrom distutils.command.install_lib import install_lib 1800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 1900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling# This global variable is used to hold the list of modules to be disabled. 2000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingdisabled_module_list = [] 2100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 2239230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudsondef add_dir_to_list(dirlist, dir): 2339230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson """Add the directory 'dir' to the list 'dirlist' (at the front) if 2439230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson 1) 'dir' is not already in 'dirlist' 2539230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson 2) 'dir' actually exists, and is a directory.""" 264439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen if dir is not None and os.path.isdir(dir) and dir not in dirlist: 2739230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson dirlist.insert(0, dir) 2839230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson 29fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchlingdef find_file(filename, std_dirs, paths): 30fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling """Searches for the directory where a given file is located, 31fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling and returns a possibly-empty list of additional directories, or None 32fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling if the file couldn't be found at all. 33ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 34fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 'filename' is the name of a file, such as readline.h or libcrypto.a. 35fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 'std_dirs' is the list of standard system directories; if the 36fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling file is found in one of them, no additional directives are needed. 37fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 'paths' is a list of additional locations to check; if the file is 38fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling found in one of them, the resulting list will contain the directory. 39fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling """ 40fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 41fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Check the standard locations 42fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling for dir in std_dirs: 43fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling f = os.path.join(dir, filename) 44fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling if os.path.exists(f): return [] 45fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 46fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Check the additional directories 47fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling for dir in paths: 48fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling f = os.path.join(dir, filename) 49fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling if os.path.exists(f): 50fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling return [dir] 51fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 52fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Not found anywhere 5300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling return None 5400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 55fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchlingdef find_library_file(compiler, libname, std_dirs, paths): 56a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling result = compiler.find_library_file(std_dirs + paths, libname) 57a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling if result is None: 58a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling return None 59ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 60a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling # Check whether the found file is in one of the standard directories 61a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling dirname = os.path.dirname(result) 62a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling for p in std_dirs: 63a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling # Ensure path doesn't end with path separator 649f5178abb7edd1b1bcaffcdfcf1afd8816dab102Skip Montanaro p = p.rstrip(os.sep) 65a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling if p == dirname: 66a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling return [ ] 67fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 68a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling # Otherwise, it must have been in one of the additional directories, 69a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling # so we have to figure out which one. 70a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling for p in paths: 71a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling # Ensure path doesn't end with path separator 729f5178abb7edd1b1bcaffcdfcf1afd8816dab102Skip Montanaro p = p.rstrip(os.sep) 73a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling if p == dirname: 74a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling return [p] 75a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling else: 76a246d9fefd729294e84a190f2e92cf4e4ff08f20Andrew M. Kuchling assert False, "Internal error: Path not found in std_dirs or paths" 772c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters 7800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingdef module_enabled(extlist, modname): 7900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling """Returns whether the module 'modname' is present in the list 8000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling of extensions 'extlist'.""" 8100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling extlist = [ext for ext in extlist if ext.name == modname] 8200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling return len(extlist) 83ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 84144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansendef find_module_file(module, dirlist): 85144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen """Find a module in a set of possible folders. If it is not found 86144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen return the unadorned filename""" 87144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen list = find_file(module, [], dirlist) 88144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen if not list: 89144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen return module 90144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen if len(list) > 1: 9112471d63893f84cb88deccf83af5aa5c6866c275Guido van Rossum log.info("WARNING: multiple copies of %s found"%module) 92144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen return os.path.join(list[0], module) 935b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 9400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingclass PyBuildExt(build_ext): 95ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 96d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro def __init__(self, dist): 97d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro build_ext.__init__(self, dist) 98d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro self.failed = [] 99d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 10000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling def build_extensions(self): 10100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 10200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Detect which modules should be compiled 103d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing = self.detect_modules() 10400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 10500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Remove modules that are present on the disabled list 106b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes extensions = [ext for ext in self.extensions 107b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes if ext.name not in disabled_module_list] 108b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes # move ctypes to the end, it depends on other modules 109b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes ext_map = dict((ext.name, i) for i, ext in enumerate(extensions)) 110b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes if "_ctypes" in ext_map: 111b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes ctypes = extensions.pop(ext_map["_ctypes"]) 112b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes extensions.append(ctypes) 113b222bbc32105f7ca9a1c5c5ad37c07de3997b9c4Christian Heimes self.extensions = extensions 114ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 11500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Fix up the autodetected modules, prefixing all the source files 11600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # with Modules/ and adding Python's include directory to the path. 11700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling (srcdir,) = sysconfig.get_config_vars('srcdir') 118e0fea6c4edcb977d722ed30de4a76a83355e2617Guido van Rossum if not srcdir: 119e0fea6c4edcb977d722ed30de4a76a83355e2617Guido van Rossum # Maybe running on Windows but not using CYGWIN? 120e0fea6c4edcb977d722ed30de4a76a83355e2617Guido van Rossum raise ValueError("No source directory; cannot proceed.") 12100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 122726b78ecb8660278399abaf36f98dec56ecf1271Neil Schemenauer # Figure out the location of the source code for extension modules 1232fab8f1abb1c5d51cfe3bbdc7a912e7c574ccf46Thomas Wouters # (This logic is copied in distutils.test.test_sysconfig, 1242fab8f1abb1c5d51cfe3bbdc7a912e7c574ccf46Thomas Wouters # so building in a separate directory does not break test_distutils.) 125726b78ecb8660278399abaf36f98dec56ecf1271Neil Schemenauer moddir = os.path.join(os.getcwd(), srcdir, 'Modules') 12600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling moddir = os.path.normpath(moddir) 12700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling srcdir, tail = os.path.split(moddir) 12800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling srcdir = os.path.normpath(srcdir) 12900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling moddir = os.path.normpath(moddir) 1305b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 131144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen moddirlist = [moddir] 132144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen incdirlist = ['./Include'] 1335b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 134144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen # Platform-dependent module source and include directories 135144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen platform = self.get_platform() 13666cb018c96e49b5e5cf1b8fc395171a223d86d8eTim Peters if platform in ('darwin', 'mac') and ("--disable-toolbox-glue" not in 137cc8a4f6563395e39d77da9888d0ea3675214ca64Brett Cannon sysconfig.get_config_var("CONFIG_ARGS")): 138144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen # Mac OS X also includes some mac-specific modules 139144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules') 140144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen moddirlist.append(macmoddir) 141144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen incdirlist.append('./Mac/Include') 14200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 143340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton alldirlist = moddirlist + incdirlist 144340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton 1453da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling # Fix up the paths for scripts, too 1463da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling self.distribution.scripts = [os.path.join(srcdir, filename) 1473da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling for filename in self.distribution.scripts] 1483da989c6bc0c80bd75547dbd8efc5a9deb29eff5Andrew M. Kuchling 1498608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes # Python header files 1508608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes headers = glob("Include/*.h") + ["pyconfig.h"] 1518608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes 152fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling for ext in self.extensions[:]: 153144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen ext.sources = [ find_module_file(filename, moddirlist) 15400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling for filename in ext.sources ] 155340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton if ext.depends is not None: 156340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton ext.depends = [find_module_file(filename, alldirlist) 157340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton for filename in ext.depends] 1588608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes else: 1598608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes ext.depends = [] 1608608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes # re-compile extensions if a header file has been changed 1618608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes ext.depends.extend(headers) 1628608d91e07868f14f71be9784149f813ef1b0a74Christian Heimes 163144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen ext.include_dirs.append( '.' ) # to get config.h 164144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen for incdir in incdirlist: 165144ebcc444e72e486837cd51e6f7f8c50d016fe2Jack Jansen ext.include_dirs.append( os.path.join(srcdir, incdir) ) 166fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 167e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling # If a module has already been built statically, 168fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # don't build it here 169e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling if ext.name in sys.builtin_module_names: 170fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling self.extensions.remove(ext) 1715bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling 1724439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen if platform != 'mac': 173e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl # Parse Modules/Setup and Modules/Setup.local to figure out which 174e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl # modules are turned on in the file. 1754439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen remove_modules = [] 176e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl for filename in ('Modules/Setup', 'Modules/Setup.local'): 177e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl input = text_file.TextFile(filename, join_lines=1) 178e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl while 1: 179e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl line = input.readline() 180e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl if not line: break 181e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl line = line.split() 182e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl remove_modules.append(line[0]) 183e08fa29d0e5bf02006ae30d79c31a6fd02d62068Georg Brandl input.close() 1841b27f86411f2593fe6137c54143c0d23f21271c7Tim Peters 1854439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen for ext in self.extensions[:]: 1864439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen if ext.name in remove_modules: 1874439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen self.extensions.remove(ext) 1885b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 1895bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # When you run "make CC=altcc" or something similar, you really want 1905bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # those environment variables passed into the setup.py phase. Here's 1915bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # a small set of useful ones. 1925bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling compiler = os.environ.get('CC') 1935bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling args = {} 1945bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # unfortunately, distutils doesn't let us provide separate C and C++ 1955bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # compilers 1965bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling if compiler is not None: 197d7c795e72966f7c72b94b919f3539be66495e6c3Martin v. Löwis (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') 198d7c795e72966f7c72b94b919f3539be66495e6c3Martin v. Löwis args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags 1995bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling self.compiler.set_executables(**args) 2005bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling 20100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling build_ext.build_extensions(self) 20200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 203d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro longest = max([len(e.name) for e in self.extensions]) 204d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro if self.failed: 205d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro longest = max(longest, max([len(name) for name in self.failed])) 206d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 207d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro def print_three_column(lst): 208e95cf1c8a2cba11b38f9c83da659895fbc952466Georg Brandl lst.sort(key=str.lower) 209d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro # guarantee zip() doesn't drop anything 210d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro while len(lst) % 3: 211d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro lst.append("") 212d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]): 213d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print "%-*s %-*s %-*s" % (longest, e, longest, f, 214d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro longest, g) 215d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 216d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro if missing: 217d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print 218d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print "Failed to find the necessary bits to build these modules:" 219d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print_three_column(missing) 220879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin print ("To find the necessary bits, look in setup.py in" 221879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin " detect_modules() for the module's name.") 222879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin print 223d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 224d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro if self.failed: 225d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro failed = self.failed[:] 226d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print 227d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print "Failed to build these modules:" 228d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro print_three_column(failed) 229879975677adb31c94384004e88b80e1da3528db8Jeffrey Yasskin print 230d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 2317c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg def build_extension(self, ext): 2327c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg 233eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller if ext.name == '_ctypes': 234795246cf9937f088f8d98253f38da4a093c08300Thomas Heller if not self.configure_ctypes(ext): 235795246cf9937f088f8d98253f38da4a093c08300Thomas Heller return 236eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller 2377c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg try: 2387c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg build_ext.build_extension(self, ext) 2397c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg except (CCompilerError, DistutilsError), why: 2407c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg self.announce('WARNING: building of extension "%s" failed: %s' % 2417c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg (ext.name, sys.exc_info()[1])) 242d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro self.failed.append(ext.name) 24362686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling return 244f49c6f9954aa59e29c8b392347646f95cbf8215aJack Jansen # Workaround for Mac OS X: The Carbon-based modules cannot be 245f49c6f9954aa59e29c8b392347646f95cbf8215aJack Jansen # reliably imported into a command-line Python 246f49c6f9954aa59e29c8b392347646f95cbf8215aJack Jansen if 'Carbon' in ext.extra_link_args: 2475b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson self.announce( 2485b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 'WARNING: skipping import check for Carbon-based "%s"' % 2495b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson ext.name) 2505b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson return 25124cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler # Workaround for Cygwin: Cygwin currently has fork issues when many 25224cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler # modules have been imported 25324cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler if self.get_platform() == 'cygwin': 25424cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler self.announce('WARNING: skipping import check for Cygwin-based "%s"' 25524cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler % ext.name) 25624cf7766bca616cd5d32e0c707dbcda8941d0a27Jason Tishler return 257af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson ext_filename = os.path.join( 258af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson self.build_lib, 259af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson self.get_ext_filename(self.get_ext_fullname(ext.name))) 26062686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling try: 261af14289c5426743015dbbe0567e2c2677f1bff0cMichael W. Hudson imp.load_dynamic(ext.name, ext_filename) 2626e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz except ImportError, why: 263d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro self.failed.append(ext.name) 2646e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz self.announce('*** WARNING: renaming "%s" since importing it' 2656e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz ' failed: %s' % (ext.name, why), level=3) 2666e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz assert not self.inplace 2676e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz basename, tail = os.path.splitext(ext_filename) 2686e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz newname = basename + "_failed" + tail 2696e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz if os.path.exists(newname): 2706e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz os.remove(newname) 2716e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz os.rename(ext_filename, newname) 2726e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz 2736e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz # XXX -- This relies on a Vile HACK in 2746e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz # distutils.command.build_ext.build_extension(). The 2756e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz # _built_objects attribute is stored there strictly for 2766e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz # use here. 2776e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz # If there is a failure, _built_objects may not be there, 2786e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz # so catch the AttributeError and move on. 2796e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz try: 2806e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz for filename in self._built_objects: 2816e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz os.remove(filename) 2826e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz except AttributeError: 2836e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz self.announce('unable to remove files (ignored)') 2843f5fcc8acce9fa620fe29d15980850e433f1d5c9Neal Norwitz except: 2853f5fcc8acce9fa620fe29d15980850e433f1d5c9Neal Norwitz exc_type, why, tb = sys.exc_info() 2866e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz self.announce('*** WARNING: importing extension "%s" ' 2876e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz 'failed with %s: %s' % (ext.name, exc_type, why), 2886e2d1c7ab83eef723176861ac2bc0732f10ba1caNeal Norwitz level=3) 289d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro self.failed.append(ext.name) 2909028d0a52529a8bc76868ade697511f29614b207Fred Drake 29151dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz def get_platform(self): 292ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # Get value of sys.platform 29351dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz for platform in ['cygwin', 'beos', 'darwin', 'atheos', 'osf1']: 29451dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz if sys.platform.startswith(platform): 29551dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz return platform 29651dead79b5e4514fe6cbc481d72a32a40e1f449cNeal Norwitz return sys.platform 29734febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling 29800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling def detect_modules(self): 299ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # Ensure that /usr/local is always used 30039230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') 30139230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') 30239230b3230783d55fd5b21c0f745ab5eec366fa5Michael W. Hudson 303516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon # Add paths specified in the environment variables LDFLAGS and 3044810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # CPPFLAGS for header and library files. 3055399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon # We must get the values from the Makefile and not the environment 3065399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon # directly since an inconsistently reproducible issue comes up where 3075399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon # the environment variable is not set even though the value were passed 3084810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # into configure and stored in the Makefile (issue found on OS X 10.3). 309516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon for env_var, arg_name, dir_list in ( 310516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon ('LDFLAGS', '-L', self.compiler.library_dirs), 311516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon ('CPPFLAGS', '-I', self.compiler.include_dirs)): 3125399c6d3d4cf9496b46ce9f37975d6c8107a743dBrett Cannon env_val = sysconfig.get_config_var(env_var) 313516592f4ff13ee39ebd115088c7429631328e2dbBrett Cannon if env_val: 3144810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # To prevent optparse from raising an exception about any 3154810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # options in env_val that is doesn't know about we strip out 3164810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # all double dashes and any dashes followed by a character 3174810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # that is not for the option we are dealing with. 3184810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # 3194810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # Please note that order of the regex is important! We must 3204810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # strip out double-dashes first so that we don't end up with 3214810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # substituting "--Long" to "-Long" and thus lead to "ong" being 3224810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # used for a library directory. 323915c87d3e5d84c0635c2957f4ae9e96d0ab6705fGeorg Brandl env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], 324915c87d3e5d84c0635c2957f4ae9e96d0ab6705fGeorg Brandl ' ', env_val) 32584667c063a1e93a985134f7cef376edf82941c02Brett Cannon parser = optparse.OptionParser() 3264810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # Make sure that allowing args interspersed with options is 3274810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon # allowed 3284810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon parser.allow_interspersed_args = True 3294810eb9a0852bc428a46d5590aafbe9b50f3370cBrett Cannon parser.error = lambda msg: None 33084667c063a1e93a985134f7cef376edf82941c02Brett Cannon parser.add_option(arg_name, dest="dirs", action="append") 33184667c063a1e93a985134f7cef376edf82941c02Brett Cannon options = parser.parse_args(env_val.split())[0] 33244837719ef2886da0671aed55e99cdae14d24b9dBrett Cannon if options.dirs: 333861e39678f574496c6e730753f12cbd7f59b6541Brett Cannon for directory in reversed(options.dirs): 33444837719ef2886da0671aed55e99cdae14d24b9dBrett Cannon add_dir_to_list(dir_list, directory) 335decc6a47df823a988845d3753a4cfb7a85b80828Skip Montanaro 33690b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson if os.path.normpath(sys.prefix) != '/usr': 33790b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson add_dir_to_list(self.compiler.library_dirs, 33890b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson sysconfig.get_config_var("LIBDIR")) 33990b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson add_dir_to_list(self.compiler.include_dirs, 34090b8e4d40cc8ec3aed05d5bc6a5afc981e7ebc0cMichael W. Hudson sysconfig.get_config_var("INCLUDEDIR")) 341fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 342339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis try: 343339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis have_unicode = unicode 344339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis except NameError: 345339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis have_unicode = 0 346339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis 347fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # lib_dirs and inc_dirs are used to search for files; 348fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # if a file is found in one of those directories, it can 349fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # be assumed that no additional -I,-L directives are needed. 350fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis lib_dirs = self.compiler.library_dirs + [ 351fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis '/lib64', '/usr/lib64', 352fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis '/lib', '/usr/lib', 353fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis ] 3545b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson inc_dirs = self.compiler.include_dirs + ['/usr/include'] 35500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts = [] 356d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing = [] 35700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 3584454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon config_h = sysconfig.get_config_h_filename() 3594454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon config_h_vars = sysconfig.parse_config_h(open(config_h)) 3604454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon 361ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh platform = self.get_platform() 3628301256a440fdd98fd500d225dac20ebb192e08fMartin v. Löwis (srcdir,) = sysconfig.get_config_vars('srcdir') 3635b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 364f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis # Check for AtheOS which has libraries in non-standard locations 365f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis if platform == 'atheos': 366f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis lib_dirs += ['/system/libs', '/atheos/autolnk/lib'] 367f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep) 368f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis inc_dirs += ['/system/include', '/atheos/autolnk/include'] 369f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep) 370f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis 3717883dc8abb81026fb111b2fde09ba602ccf04226Andrew M. Kuchling # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) 3727883dc8abb81026fb111b2fde09ba602ccf04226Andrew M. Kuchling if platform in ['osf1', 'unixware7', 'openunix8']: 37322e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro lib_dirs += ['/usr/ccs/lib'] 37422e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro 37539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren if platform == 'darwin': 37639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # This should work on any unixy platform ;-) 37739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # If the user has bothered specifying additional -I and -L flags 37839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # in OPT and LDFLAGS we might as well use them here. 37939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # NOTE: using shlex.split would technically be more correct, but 38039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # also gives a bootstrap problem. Let's hope nobody uses directories 38139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # with whitespace in the name to store libraries. 38239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren cflags, ldflags = sysconfig.get_config_vars( 38339be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 'CFLAGS', 'LDFLAGS') 38439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren for item in cflags.split(): 38539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren if item.startswith('-I'): 38639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren inc_dirs.append(item[2:]) 38739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 38839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren for item in ldflags.split(): 38939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren if item.startswith('-L'): 39039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren lib_dirs.append(item[2:]) 39139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 392ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # Check for MacOS X, which doesn't need libm.a at all 393ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh math_libs = ['m'] 3944439b7c67e057db24067e723f1f553258dfa9d94Jack Jansen if platform in ['darwin', 'beos', 'mac']: 395ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh math_libs = [] 3965b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 39700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # XXX Omitted modules: gl, pure, dl, SGI-specific modules 39800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 39900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # 40000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # The following modules are all pretty straightforward, and compile 40100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # on pretty much any POSIXish platform. 40200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # 403ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 40400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Some modules that are normally always on: 4052de7471d69b950a64e52a950675d59d9f4071da1Fred Drake exts.append( Extension('_weakref', ['_weakref.c']) ) 40600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 40700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # array objects 40800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('array', ['arraymodule.c']) ) 40900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # complex math library functions 4105ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling exts.append( Extension('cmath', ['cmathmodule.c'], 4115ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling libraries=math_libs) ) 412ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 41300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # math library functions, e.g. sin() 4145ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling exts.append( Extension('math', ['mathmodule.c'], 4155ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling libraries=math_libs) ) 41600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # fast string operations implemented in C 41700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('strop', ['stropmodule.c']) ) 41800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # time operations and variables 4195ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling exts.append( Extension('time', ['timemodule.c'], 4205ddb25f36f676aa32b048a24261dcc8490b99c98Andrew M. Kuchling libraries=math_libs) ) 421057e7200d1c300f3c914dbc84eca327c10bf7751Brett Cannon exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'], 422a29d508ec4f29f73a9569e27402f159b8efa57caGuido van Rossum libraries=math_libs) ) 4230d2192be8b71c2effeedad4bf9ccac9c022c03d8Neal Norwitz # fast iterator tools implemented in C 4240d2192be8b71c2effeedad4bf9ccac9c022c03d8Neal Norwitz exts.append( Extension("itertools", ["itertoolsmodule.c"]) ) 425a73fbe791d0d41db543ebe39d2f6df0a4265be4bEric Smith # code that will be builtins in the future, but conflict with the 426a73fbe791d0d41db543ebe39d2f6df0a4265be4bEric Smith # current builtins 427a73fbe791d0d41db543ebe39d2f6df0a4265be4bEric Smith exts.append( Extension('future_builtins', ['future_builtins.c']) ) 42840f621709286a7a0f7e6f260c0fd020d0fac0de0Raymond Hettinger # random number generator implemented in C 4292c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters exts.append( Extension("_random", ["_randommodule.c"]) ) 430756b3f3c15bd314ffa25299ca25465ae21e62a30Raymond Hettinger # high-performance collections 431eb9798892d7ed54762ae006e39db0a84f671cfd3Raymond Hettinger exts.append( Extension("_collections", ["_collectionsmodule.c"]) ) 4320c4102760c440af3e7b575b0fd27fe25549641a2Raymond Hettinger # bisect 4330c4102760c440af3e7b575b0fd27fe25549641a2Raymond Hettinger exts.append( Extension("_bisect", ["_bisectmodule.c"]) ) 434b3af1813eb5cf99766f55a0dfc0d566e9bd7c3c1Raymond Hettinger # heapq 435c46cb2a1a92c26e01ddb3921aa6828bcd3576f3eRaymond Hettinger exts.append( Extension("_heapq", ["_heapqmodule.c"]) ) 43600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # operator.add() and similar goodies 43700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('operator', ['operator.c']) ) 4387f39c9fcbba0cc59293d80a7bbcbb8bca62790eeChristian Heimes # Python 3.0 _fileio module 4397f39c9fcbba0cc59293d80a7bbcbb8bca62790eeChristian Heimes exts.append( Extension("_fileio", ["_fileio.c"]) ) 4401aed624f7c6051bc670a846825bd40108d3f8dd5Alexandre Vassalotti # Python 3.0 _bytesio module 4411aed624f7c6051bc670a846825bd40108d3f8dd5Alexandre Vassalotti exts.append( Extension("_bytesio", ["_bytesio.c"]) ) 442c649ec5b69bd864914e02a2a9ec73c23bd307448Nick Coghlan # _functools 443c649ec5b69bd864914e02a2a9ec73c23bd307448Nick Coghlan exts.append( Extension("_functools", ["_functoolsmodule.c"]) ) 4444b964f9c904744b7d7d88054e54a2e4ca8aeb395Brett Cannon # _json speedups 4454b964f9c904744b7d7d88054e54a2e4ca8aeb395Brett Cannon exts.append( Extension("_json", ["_json.c"]) ) 446261b8e26f199b8e548d9cf81fc4a94820a5a83dbMarc-André Lemburg # Python C API test module 447d66595fe423227f3bf8ea4867df5d27c6d2764e1Tim Peters exts.append( Extension('_testcapi', ['_testcapimodule.c']) ) 448a871ef2b3e924f058ec1b0aed7d4c83a546414b7Armin Rigo # profilers (_lsprof is for cProfile.py) 449a871ef2b3e924f058ec1b0aed7d4c83a546414b7Armin Rigo exts.append( Extension('_hotshot', ['_hotshot.c']) ) 450a871ef2b3e924f058ec1b0aed7d4c83a546414b7Armin Rigo exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) ) 45100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # static Unicode character database 452339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis if have_unicode: 453339d0f720e86dc34837547c90d3003a4a68d7d46Martin v. Löwis exts.append( Extension('unicodedata', ['unicodedata.c']) ) 454d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 455d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('unicodedata') 45600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # access to ISO C locale support 45719d173486b2263a269260343d65ac3929c89297eMartin v. Löwis data = open('pyconfig.h').read() 45819d173486b2263a269260343d65ac3929c89297eMartin v. Löwis m = re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*", data) 45919d173486b2263a269260343d65ac3929c89297eMartin v. Löwis if m is not None: 460d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler locale_libs = ['intl'] 461d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler else: 462d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler locale_libs = [] 46384b744775206eceefc9c94ba3e23f18332ac062bJack Jansen if platform == 'darwin': 46484b744775206eceefc9c94ba3e23f18332ac062bJack Jansen locale_extra_link_args = ['-framework', 'CoreFoundation'] 46584b744775206eceefc9c94ba3e23f18332ac062bJack Jansen else: 46684b744775206eceefc9c94ba3e23f18332ac062bJack Jansen locale_extra_link_args = [] 467e6ddc8b20b493fef2e7cffb2e1351fe1d238857eTim Peters 46884b744775206eceefc9c94ba3e23f18332ac062bJack Jansen 469d28216b279743ed680d84fe37da190e9754e6be4Jason Tishler exts.append( Extension('_locale', ['_localemodule.c'], 47084b744775206eceefc9c94ba3e23f18332ac062bJack Jansen libraries=locale_libs, 47184b744775206eceefc9c94ba3e23f18332ac062bJack Jansen extra_link_args=locale_extra_link_args) ) 47200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 47300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Modules with some UNIX dependencies -- on by default: 47400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # (If you have a really backward UNIX, select and socket may not be 47500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # supported...) 47600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 47700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # fcntl(2) and ioctl(2) 47800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('fcntl', ['fcntlmodule.c']) ) 47973aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen if platform not in ['mac']: 48046d9623875893be9e2bcbb804b82cfd7f8ed05dfBrett Cannon # pwd(3) 4812c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters exts.append( Extension('pwd', ['pwdmodule.c']) ) 4822c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters # grp(3) 4832c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters exts.append( Extension('grp', ['grpmodule.c']) ) 484c300175547ced0af17857a29462b0f9294e8c31cMartin v. Löwis # spwd, shadow passwords 4854454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon if (config_h_vars.get('HAVE_GETSPNAM', False) or 4864454a1ff8453c12739c65da21e00927ea3bf9ad9Brett Cannon config_h_vars.get('HAVE_GETSPENT', False)): 48746d9623875893be9e2bcbb804b82cfd7f8ed05dfBrett Cannon exts.append( Extension('spwd', ['spwdmodule.c']) ) 488d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 489d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('spwd') 490d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 491d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.extend(['pwd', 'grp', 'spwd']) 492d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 49300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # select(2); not on ancient System V 49400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('select', ['selectmodule.c']) ) 49500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 49600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Fred Drake's interface to the Python parser 49700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('parser', ['parsermodule.c']) ) 49800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 4992e1c09c1fd06531a3ce1de5b12ec5c8f771e78e0Guido van Rossum # cStringIO and cPickle 50000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('cStringIO', ['cStringIO.c']) ) 50100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('cPickle', ['cPickle.c']) ) 50200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 50300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Memory-mapped files (also works on Win32). 50473aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen if platform not in ['atheos', 'mac']: 505f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis exts.append( Extension('mmap', ['mmapmodule.c']) ) 506d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 507d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('mmap') 50800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 50957269d0c7c7a6fc989fcbef5b82853aa36fb44caAndrew M. Kuchling # Lance Ellinghaus's syslog module 51073aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen if platform not in ['mac']: 5112c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters # syslog daemon interface 5122c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters exts.append( Extension('syslog', ['syslogmodule.c']) ) 513d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 514d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('syslog') 51500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 51600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # George Neville-Neil's timing module: 5176143c547dd45dfc56ad05af31b829479a3ce7e2dNeal Norwitz # Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html 5186143c547dd45dfc56ad05af31b829479a3ce7e2dNeal Norwitz # http://mail.python.org/pipermail/python-dev/2006-January/060023.html 5196143c547dd45dfc56ad05af31b829479a3ce7e2dNeal Norwitz #exts.append( Extension('timing', ['timingmodule.c']) ) 52000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 52100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # 5225bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # Here ends the simple stuff. From here on, modules need certain 5235bbc7b9283c40996c198511f57211d4f77d6a12dAndrew M. Kuchling # libraries, are platform-specific, or present other surprises. 52400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # 52500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 52600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Multimedia modules 52700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # These don't work for 64-bit platforms!!! 52800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # These represent audio samples or images as strings: 52900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 5305e4a3b86b359952dc6ba3da2f48594179a811319Neal Norwitz # Operations on audio samples 531f9cbf211578c3d5a7d5fe2ac3bf09b1b5a2dd5e2Tim Peters # According to #993173, this one should actually work fine on 5328fbefe28745f980579620147dd0c0fdef94374deMartin v. Löwis # 64-bit platforms. 5338fbefe28745f980579620147dd0c0fdef94374deMartin v. Löwis exts.append( Extension('audioop', ['audioop.c']) ) 5348fbefe28745f980579620147dd0c0fdef94374deMartin v. Löwis 535ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # Disabled on 64-bit platforms 53600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling if sys.maxint != 9223372036854775807L: 53700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Operations on images 53800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('imageop', ['imageop.c']) ) 539d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 540dc48b74497b67a449dd622fdaa7d69e7bff65a5eBrett Cannon missing.extend(['imageop']) 54100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 54200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # readline 54381ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen do_readline = self.compiler.find_library_file(lib_dirs, 'readline') 54481ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen if platform == 'darwin': 54581ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen # MacOSX 10.4 has a broken readline. Don't try to build 54681ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen # the readline module unless the user has installed a fixed 54781ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen # readline package 5482086eaf79c9dc2992fef64392a9813e25f60696fMartin v. Löwis if find_file('readline/rlconf.h', inc_dirs, []) is None: 54981ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen do_readline = False 55081ae235146a058446e5a2ff8b2722686b9e36cc3Jack Jansen if do_readline: 55139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren if sys.platform == 'darwin': 55239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # In every directory on the search path search for a dynamic 55339be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # library and then a static library, instead of first looking 55439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # for dynamic libraries on the entiry path. 55539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # This way a staticly linked custom readline gets picked up 55639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # before the (broken) dynamic library in /usr/lib. 55739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren readline_extra_link_args = ('-Wl,-search_paths_first',) 55839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren else: 55939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren readline_extra_link_args = () 56039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 5612efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg readline_libs = ['readline'] 5625aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling if self.compiler.find_library_file(lib_dirs, 563a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis 'ncursesw'): 564a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis readline_libs.append('ncursesw') 565a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis elif self.compiler.find_library_file(lib_dirs, 5665aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling 'ncurses'): 5675aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling readline_libs.append('ncurses') 5680b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz elif self.compiler.find_library_file(lib_dirs, 'curses'): 5690b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz readline_libs.append('curses') 5705aa3c4af76a1ed08cf275bb049cfa3ebe9758386Andrew M. Kuchling elif self.compiler.find_library_file(lib_dirs + 5712efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg ['/usr/lib/termcap'], 5722efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg 'termcap'): 5732efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg readline_libs.append('termcap') 57400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('readline', ['readline.c'], 5757c6fcda7bfe45a3b075f6434ebb65055ab4d7537Marc-André Lemburg library_dirs=['/usr/lib/termcap'], 57639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren extra_link_args=readline_extra_link_args, 5772efc3238d749977364568422eb0acec37c2438baMarc-André Lemburg libraries=readline_libs) ) 578d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 579d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('readline') 580d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 58173aa1fff85c7c6ff940ace1a5de8a895e24e0132Jack Jansen if platform not in ['mac']: 5827883dc8abb81026fb111b2fde09ba602ccf04226Andrew M. Kuchling # crypt module. 5832c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters 5842c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters if self.compiler.find_library_file(lib_dirs, 'crypt'): 5852c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters libs = ['crypt'] 5862c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters else: 5872c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters libs = [] 5882c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) ) 589d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 590d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('crypt') 59100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 592ba9e9781805f85d32b5a2a17efdf00b77d747500Skip Montanaro # CSV files 593ba9e9781805f85d32b5a2a17efdf00b77d747500Skip Montanaro exts.append( Extension('_csv', ['_csv.c']) ) 594ba9e9781805f85d32b5a2a17efdf00b77d747500Skip Montanaro 59500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # socket(2) 59647d3a7afdaf52887d1bbd1a8cbcd717893c6d480Guido van Rossum exts.append( Extension('_socket', ['socketmodule.c'], 597340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton depends = ['socketmodule.h']) ) 598a5d2b4cb180ec87d006d63f838860fba785bcad0Marc-André Lemburg # Detect SSL support for the socket module (via _ssl) 599ade97338016947bad1d0def339328963fca09685Gregory P. Smith search_for_ssl_incs_in = [ 600ade97338016947bad1d0def339328963fca09685Gregory P. Smith '/usr/local/ssl/include', 601e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling '/usr/contrib/ssl/include/' 602e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling ] 603ade97338016947bad1d0def339328963fca09685Gregory P. Smith ssl_incs = find_file('openssl/ssl.h', inc_dirs, 604ade97338016947bad1d0def339328963fca09685Gregory P. Smith search_for_ssl_incs_in 605fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling ) 606a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis if ssl_incs is not None: 607a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis krb5_h = find_file('krb5.h', inc_dirs, 608a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis ['/usr/kerberos/include']) 609a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis if krb5_h: 610a950f7ff0dad8718b999bdd944f5f48c8640be59Martin v. Löwis ssl_incs += krb5_h 611fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, 612e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling ['/usr/local/ssl/lib', 613e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling '/usr/contrib/ssl/lib/' 614e7c87327b3d98359d713b9fc66eae01a041bb624Andrew M. Kuchling ] ) 615ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 616fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling if (ssl_incs is not None and 617fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling ssl_libs is not None): 618a5d2b4cb180ec87d006d63f838860fba785bcad0Marc-André Lemburg exts.append( Extension('_ssl', ['_ssl.c'], 619fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs = ssl_incs, 620ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh library_dirs = ssl_libs, 62147d3a7afdaf52887d1bbd1a8cbcd717893c6d480Guido van Rossum libraries = ['ssl', 'crypto'], 622340043ea7916f4ada4e849cfb3da6d7cad621f5dJeremy Hylton depends = ['socketmodule.h']), ) 623d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 624d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_ssl') 62500e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 626ade97338016947bad1d0def339328963fca09685Gregory P. Smith # find out which version of OpenSSL we have 627ade97338016947bad1d0def339328963fca09685Gregory P. Smith openssl_ver = 0 628ade97338016947bad1d0def339328963fca09685Gregory P. Smith openssl_ver_re = re.compile( 629ade97338016947bad1d0def339328963fca09685Gregory P. Smith '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' ) 630ade97338016947bad1d0def339328963fca09685Gregory P. Smith for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in: 631ade97338016947bad1d0def339328963fca09685Gregory P. Smith name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h') 632ade97338016947bad1d0def339328963fca09685Gregory P. Smith if os.path.isfile(name): 633ade97338016947bad1d0def339328963fca09685Gregory P. Smith try: 634ade97338016947bad1d0def339328963fca09685Gregory P. Smith incfile = open(name, 'r') 635ade97338016947bad1d0def339328963fca09685Gregory P. Smith for line in incfile: 636ade97338016947bad1d0def339328963fca09685Gregory P. Smith m = openssl_ver_re.match(line) 637ade97338016947bad1d0def339328963fca09685Gregory P. Smith if m: 638ade97338016947bad1d0def339328963fca09685Gregory P. Smith openssl_ver = eval(m.group(1)) 639ade97338016947bad1d0def339328963fca09685Gregory P. Smith break 640ade97338016947bad1d0def339328963fca09685Gregory P. Smith except IOError: 641ade97338016947bad1d0def339328963fca09685Gregory P. Smith pass 642ade97338016947bad1d0def339328963fca09685Gregory P. Smith 643ade97338016947bad1d0def339328963fca09685Gregory P. Smith # first version found is what we'll use (as the compiler should) 644ade97338016947bad1d0def339328963fca09685Gregory P. Smith if openssl_ver: 645ade97338016947bad1d0def339328963fca09685Gregory P. Smith break 646ade97338016947bad1d0def339328963fca09685Gregory P. Smith 647ade97338016947bad1d0def339328963fca09685Gregory P. Smith #print 'openssl_ver = 0x%08x' % openssl_ver 648ade97338016947bad1d0def339328963fca09685Gregory P. Smith 649f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith if (ssl_incs is not None and 650ade97338016947bad1d0def339328963fca09685Gregory P. Smith ssl_libs is not None and 651ade97338016947bad1d0def339328963fca09685Gregory P. Smith openssl_ver >= 0x00907000): 652f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith # The _hashlib module wraps optimized implementations 653f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith # of hash functions from the OpenSSL library. 654f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith exts.append( Extension('_hashlib', ['_hashopenssl.c'], 655f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith include_dirs = ssl_incs, 656f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith library_dirs = ssl_libs, 657f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith libraries = ['ssl', 'crypto']) ) 6584eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # these aren't strictly missing since they are unneeded. 6594eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith #missing.extend(['_sha', '_md5']) 660f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith else: 661f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith # The _sha module implements the SHA1 hash algorithm. 662f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith exts.append( Extension('_sha', ['shamodule.c']) ) 663f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith # The _md5 module implements the RSA Data Security, Inc. MD5 664f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith # Message-Digest Algorithm, described in RFC 1321. The 6658e39ec78bcede7291e0573fc522425221eb05475Matthias Klose # necessary files md5.c and md5.h are included here. 666d792392db4b63bea14b40e3f6e3c41ab4eb6e6faGregory P. Smith exts.append( Extension('_md5', 667d792392db4b63bea14b40e3f6e3c41ab4eb6e6faGregory P. Smith sources = ['md5module.c', 'md5.c'], 668d792392db4b63bea14b40e3f6e3c41ab4eb6e6faGregory P. Smith depends = ['md5.h']) ) 669d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_hashlib') 670f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith 671ade97338016947bad1d0def339328963fca09685Gregory P. Smith if (openssl_ver < 0x00908000): 672ade97338016947bad1d0def339328963fca09685Gregory P. Smith # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash 673ade97338016947bad1d0def339328963fca09685Gregory P. Smith exts.append( Extension('_sha256', ['sha256module.c']) ) 674ade97338016947bad1d0def339328963fca09685Gregory P. Smith exts.append( Extension('_sha512', ['sha512module.c']) ) 675f21a5f773964d34c7b6deb7e3d753fae2b9c70e2Gregory P. Smith 67600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Modules that provide persistent dictionary-like semantics. You will 67700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # probably want to arrange for at least one of them to be available on 67800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # your machine, though none are defined by default because of library 67900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # dependencies. The Python module anydbm.py provides an 68000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # implementation independent wrapper for these; dumbdbm.py provides 68100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # similar functionality (but slower of course) implemented in Python. 68200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 6831475cd876190ccad16e47600958b226bfd788332Gregory P. Smith # Sleepycat^WOracle Berkeley DB interface. 6841475cd876190ccad16e47600958b226bfd788332Gregory P. Smith # http://www.oracle.com/database/berkeley-db/db/index.html 68557454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro # 6864eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # This requires the Sleepycat^WOracle DB code. The supported versions 687e7f4d8483082d2f694e8a89ec531ab378e6b8326Gregory P. Smith # are set below. Visit the URL above to download 6883adc4aa2fb58aaca2f7692a37239ee3157887166Gregory P. Smith # a release. Most open source OSes come with one or more 6893adc4aa2fb58aaca2f7692a37239ee3157887166Gregory P. Smith # versions of BerkeleyDB already installed. 69057454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro 6918f1a4a68289c9ec4181f45f9ecc648fdf1050566Gregory P. Smith max_db_ver = (4, 7) 6923adc4aa2fb58aaca2f7692a37239ee3157887166Gregory P. Smith min_db_ver = (3, 3) 693e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_setup_debug = False # verbose debug prints from this script? 694e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 6950902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith def allow_db_ver(db_ver): 6960902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith """Returns a boolean if the given BerkeleyDB version is acceptable. 6970902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith 6980902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith Args: 6990902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith db_ver: A tuple of the version to verify. 7000902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith """ 7010902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith if not (min_db_ver <= db_ver <= max_db_ver): 7020902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith return False 7030902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith # Use this function to filter out known bad configurations. 7040902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith if (4, 6) == db_ver[:2]: 7050902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith # BerkeleyDB 4.6.x is not stable on many architectures. 7060902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith arch = platform_machine() 7070902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith if arch not in ('i386', 'i486', 'i586', 'i686', 7080902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith 'x86_64', 'ia64'): 7090902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith return False 7100902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith return True 7110902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith 7120902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith def gen_db_minor_ver_nums(major): 7130902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith if major == 4: 7140902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith for x in range(max_db_ver[1]+1): 7150902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith if allow_db_ver((4, x)): 7160902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith yield x 7170902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith elif major == 3: 7180902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith for x in (3,): 7190902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith if allow_db_ver((3, x)): 7200902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith yield x 7210902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith else: 7220902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith raise ValueError("unknown major BerkeleyDB version", major) 7230902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith 724e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # construct a list of paths to look for the header file in on 725e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # top of the normal inc_dirs. 726e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths = [ 727e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/usr/include/db4', 728e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/usr/local/include/db4', 729e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/opt/sfw/include/db4', 730e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/usr/include/db3', 731e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/usr/local/include/db3', 732e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/opt/sfw/include/db3', 73300c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro # Fink defaults (http://fink.sourceforge.net/) 73400c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro '/sw/include/db4', 735e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith '/sw/include/db3', 736e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith ] 737e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # 4.x minor number specific paths 7380902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith for x in gen_db_minor_ver_nums(4): 739e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/usr/include/db4%d' % x) 7408f40171b6734250008e68f79ae64308e37902dfaNeal Norwitz db_inc_paths.append('/usr/include/db4.%d' % x) 741e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x) 742e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/usr/local/include/db4%d' % x) 743e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/pkg/db-4.%d/include' % x) 74429602d2153e56081fad5db19e356e51c37ec2ec8Gregory P. Smith db_inc_paths.append('/opt/db-4.%d/include' % x) 74500c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro # MacPorts default (http://www.macports.org/) 74600c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro db_inc_paths.append('/opt/local/include/db4%d' % x) 747e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # 3.x minor number specific paths 7480902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith for x in gen_db_minor_ver_nums(3): 749e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/usr/include/db3%d' % x) 750e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x) 751e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/usr/local/include/db3%d' % x) 752e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_inc_paths.append('/pkg/db-3.%d/include' % x) 75329602d2153e56081fad5db19e356e51c37ec2ec8Gregory P. Smith db_inc_paths.append('/opt/db-3.%d/include' % x) 754e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 7559b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren # Add some common subdirectories for Sleepycat DB to the list, 7569b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren # based on the standard include directories. This way DB3/4 gets 7579b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren # picked up when it is installed in a non-standard prefix and 7589b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren # the user has added that prefix into inc_dirs. 7599b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants = [] 7609b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren for dn in inc_dirs: 7619b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants.append(os.path.join(dn, 'db3')) 7629b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants.append(os.path.join(dn, 'db4')) 7630902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith for x in gen_db_minor_ver_nums(4): 7649b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants.append(os.path.join(dn, "db4%d"%x)) 7659b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants.append(os.path.join(dn, "db4.%d"%x)) 7660902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith for x in gen_db_minor_ver_nums(3): 7679b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants.append(os.path.join(dn, "db3%d"%x)) 7689b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren std_variants.append(os.path.join(dn, "db3.%d"%x)) 7699b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren 77038ff36c4ccde02b104553ef1ed979c1261196b48Tim Peters db_inc_paths = std_variants + db_inc_paths 77100c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)] 7729b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren 773e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_ver_inc_map = {} 774e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 775e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith class db_found(Exception): pass 77657454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro try: 77705d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis # See whether there is a Sleepycat header in the standard 77805d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis # search path. 779e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith for d in inc_dirs + db_inc_paths: 78005d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis f = os.path.join(d, "db.h") 781e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith if db_setup_debug: print "db: looking for db.h in", f 78205d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis if os.path.exists(f): 78305d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis f = open(f).read() 784e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f) 78505d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis if m: 786e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_major = int(m.group(1)) 787e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f) 788e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_minor = int(m.group(1)) 789e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_ver = (db_major, db_minor) 790e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 7911475cd876190ccad16e47600958b226bfd788332Gregory P. Smith # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug 7921475cd876190ccad16e47600958b226bfd788332Gregory P. Smith if db_ver == (4, 6): 7931475cd876190ccad16e47600958b226bfd788332Gregory P. Smith m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f) 7941475cd876190ccad16e47600958b226bfd788332Gregory P. Smith db_patch = int(m.group(1)) 7951475cd876190ccad16e47600958b226bfd788332Gregory P. Smith if db_patch < 21: 7961475cd876190ccad16e47600958b226bfd788332Gregory P. Smith print "db.h:", db_ver, "patch", db_patch, 7971475cd876190ccad16e47600958b226bfd788332Gregory P. Smith print "being ignored (4.6.x must be >= 4.6.21)" 7981475cd876190ccad16e47600958b226bfd788332Gregory P. Smith continue 7991475cd876190ccad16e47600958b226bfd788332Gregory P. Smith 800e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith if ( (not db_ver_inc_map.has_key(db_ver)) and 8010902cac4b355e98184b0e435f9bb7e24ed68f6a2Gregory P. Smith allow_db_ver(db_ver) ): 802e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # save the include directory with the db.h version 80300c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro # (first occurrence only) 804e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_ver_inc_map[db_ver] = d 805738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling if db_setup_debug: 806738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling print "db.h: found", db_ver, "in", d 807e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith else: 808e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # we already found a header for this library version 809e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith if db_setup_debug: print "db.h: ignoring", d 810e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith else: 811e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # ignore this header, it didn't contain a version number 81200c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro if db_setup_debug: 81300c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro print "db.h: no version number version in", d 814e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 815e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_found_vers = db_ver_inc_map.keys() 816e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_found_vers.sort() 817e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 818e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith while db_found_vers: 819e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_ver = db_found_vers.pop() 820e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_incdir = db_ver_inc_map[db_ver] 821e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 822e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # check lib directories parallel to the location of the header 823e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_dirs_to_check = [ 82400c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro db_incdir.replace("include", 'lib64'), 82500c5a0138b52926c303b8954c2d898c90365414bSkip Montanaro db_incdir.replace("include", 'lib'), 826e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith ] 827e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check) 828e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 829e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # Look for a version specific db-X.Y before an ambiguoius dbX 830e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # XXX should we -ever- look for a dbX name? Do any 831e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # systems really not name their library by version and 832e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # symlink to more general names? 833953f98d4bdd27c74e2c4220b90e20f8e6e6c8b7fAndrew MacIntyre for dblib in (('db-%d.%d' % db_ver), 834953f98d4bdd27c74e2c4220b90e20f8e6e6c8b7fAndrew MacIntyre ('db%d%d' % db_ver), 835953f98d4bdd27c74e2c4220b90e20f8e6e6c8b7fAndrew MacIntyre ('db%d' % db_ver[0])): 836e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith dblib_file = self.compiler.find_library_file( 837e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_dirs_to_check + lib_dirs, dblib ) 838e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith if dblib_file: 839e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ] 840e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith raise db_found 841e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith else: 842e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith if db_setup_debug: print "db lib: ", dblib, "not found" 843e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith 844e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith except db_found: 845ef3dab28f25c6725c789704ef140e23071ceb923Brett Cannon if db_setup_debug: 846ef3dab28f25c6725c789704ef140e23071ceb923Brett Cannon print "bsddb using BerkeleyDB lib:", db_ver, dblib 847ef3dab28f25c6725c789704ef140e23071ceb923Brett Cannon print "bsddb lib dir:", dblib_dir, " inc dir:", db_incdir 848e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith db_incs = [db_incdir] 849d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen dblibs = [dblib] 850e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # We add the runtime_library_dirs argument because the 851e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # BerkeleyDB lib we're linking against often isn't in the 852e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # system dynamic library search path. This is usually 853e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # correct and most trouble free, but may cause problems in 854e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # some unusual system configurations (e.g. the directory 855e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith # is on an NFS server that goes away). 8566aa4a1f29ca575e25fc595857b2a5168a02c9780Martin v. Löwis exts.append(Extension('_bsddb', ['_bsddb.c'], 857392505391e1703fe0df4da8e077793f7e71b1075Gregory P. Smith depends = ['bsddb.h'], 85805d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis library_dirs=dblib_dir, 85905d4d562d70568469b12cb2b45dfc78886f8c5d9Martin v. Löwis runtime_library_dirs=dblib_dir, 8606aa4a1f29ca575e25fc595857b2a5168a02c9780Martin v. Löwis include_dirs=db_incs, 8616aa4a1f29ca575e25fc595857b2a5168a02c9780Martin v. Löwis libraries=dblibs)) 86257454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro else: 863e76c8c03830072b220f337dfca72c5e6c2660e8eGregory P. Smith if db_setup_debug: print "db: no appropriate library found" 86457454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro db_incs = None 86557454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro dblibs = [] 86657454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro dblib_dir = None 867d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_bsddb') 86857454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro 869c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter # The sqlite interface 870738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling sqlite_setup_debug = False # verbose debug prints from this script? 871c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter 8723dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter # We hunt for #define SQLITE_VERSION "n.n.n" 8733dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter # We need to find >= sqlite version 3.0.8 874c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_incdir = sqlite_libdir = None 8753dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter sqlite_inc_paths = [ '/usr/include', 876c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '/usr/include/sqlite', 877c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '/usr/include/sqlite3', 878c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '/usr/local/include', 879c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '/usr/local/include/sqlite', 880c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '/usr/local/include/sqlite3', 881c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter ] 8823dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) 8833dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter MIN_SQLITE_VERSION = ".".join([str(x) 8843dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter for x in MIN_SQLITE_VERSION_NUMBER]) 88539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 88639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # Scan the default include directories before the SQLite specific 88739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # ones. This allows one to override the copy of sqlite on OSX, 88839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # where /usr/include contains an old version of sqlite. 88939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren for d in inc_dirs + sqlite_inc_paths: 890c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter f = os.path.join(d, "sqlite3.h") 891c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter if os.path.exists(f): 89207f5b35e190ab9be85143c6e8e1217d96bbf75caAnthony Baxter if sqlite_setup_debug: print "sqlite: found %s"%f 8933dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter incf = open(f).read() 8943dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter m = re.search( 8953dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf) 896c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter if m: 8973dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter sqlite_version = m.group(1) 8983dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter sqlite_version_tuple = tuple([int(x) 8993dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter for x in sqlite_version.split(".")]) 9003dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: 901c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter # we win! 902738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling if sqlite_setup_debug: 903738446f44d6d37d920d00fa99bbb1a7084bd537bAndrew M. Kuchling print "%s/sqlite3.h: version %s"%(d, sqlite_version) 904c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_incdir = d 905c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter break 906c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter else: 9073dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter if sqlite_setup_debug: 908c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter print "%s: version %d is too old, need >= %s"%(d, 909c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_version, MIN_SQLITE_VERSION) 9103dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter elif sqlite_setup_debug: 9113dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter print "sqlite: %s had no SQLITE_VERSION"%(f,) 9123dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter 913c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter if sqlite_incdir: 914c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_dirs_to_check = [ 915c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter os.path.join(sqlite_incdir, '..', 'lib64'), 916c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter os.path.join(sqlite_incdir, '..', 'lib'), 917c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter os.path.join(sqlite_incdir, '..', '..', 'lib64'), 918c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter os.path.join(sqlite_incdir, '..', '..', 'lib'), 919c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter ] 920c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_libfile = self.compiler.find_library_file( 921c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_dirs_to_check + lib_dirs, 'sqlite3') 922c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] 923c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter 924c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter if sqlite_incdir and sqlite_libdir: 9253e99c0ad649de0393d9a8af17f34d9d1f55f4ab2Gerhard Häring sqlite_srcs = ['_sqlite/cache.c', 926c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/connection.c', 927c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/cursor.c', 928c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/microprotocols.c', 929c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/module.c', 930c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/prepare_protocol.c', 931c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/row.c', 932c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/statement.c', 933c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter '_sqlite/util.c', ] 934c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter 935c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_defines = [] 936c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter if sys.platform != "win32": 9378e7b4908901e30f594e52d5fdcdc8b4e2d274ff1Anthony Baxter sqlite_defines.append(('MODULE_NAME', '"sqlite3"')) 938c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter else: 9398e7b4908901e30f594e52d5fdcdc8b4e2d274ff1Anthony Baxter sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"')) 9408e7b4908901e30f594e52d5fdcdc8b4e2d274ff1Anthony Baxter 94139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 94239be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren if sys.platform == 'darwin': 94339be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # In every directory on the search path search for a dynamic 94439be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # library and then a static library, instead of first looking 94539be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # for dynamic libraries on the entiry path. 94639be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # This way a staticly linked custom sqlite gets picked up 94739be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren # before the dynamic library in /usr/lib. 94839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren sqlite_extra_link_args = ('-Wl,-search_paths_first',) 94939be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren else: 95039be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren sqlite_extra_link_args = () 95139be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren 952c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter exts.append(Extension('_sqlite3', sqlite_srcs, 953c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter define_macros=sqlite_defines, 9543dc6bb3c25dd2834b198a4bbcff2f9b760d1a2d9Anthony Baxter include_dirs=["Modules/_sqlite", 955c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter sqlite_incdir], 956c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter library_dirs=sqlite_libdir, 957c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter runtime_library_dirs=sqlite_libdir, 95839be38c96555cdfea3fa7ef5b1d5d2fd48373b52Ronald Oussoren extra_link_args=sqlite_extra_link_args, 959c51ee69b27a35bb45e501766dd33674eae7ddb30Anthony Baxter libraries=["sqlite3",])) 960d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 961d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_sqlite3') 96222e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro 96322e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # Look for Berkeley db 1.85. Note that it is built as a different 96422e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # module name so it can be included even when later versions are 96522e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # available. A very restrictive search is performed to avoid 96622e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # accidentally building this module with a later version of the 96722e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # underlying db library. May BSD-ish Unixes incorporate db 1.85 96822e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # symbols into libc and place the include file in /usr/include. 9694eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # 9704eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # If the better bsddb library can be built (db_incs is defined) 9714eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # we do not build this one. Otherwise this build will pick up 9724eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # the more recent berkeleydb's db.h file first in the include path 9734eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith # when attempting to compile and it will fail. 97422e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro f = "/usr/include/db.h" 9754eb60e5330758e1bdf9809dfa4bbe0991e16674dGregory P. Smith if os.path.exists(f) and not db_incs: 97622e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro data = open(f).read() 97722e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data) 97822e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro if m is not None: 97922e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro # bingo - old version used hash file format version 2 98022e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro ### XXX this should be fixed to not be platform-dependent 98122e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro ### but I don't have direct access to an osf1 platform and 98222e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro ### seemed to be muffing the search somehow 98322e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro libraries = platform == "osf1" and ['db'] or None 98422e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro if libraries is not None: 98522e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro exts.append(Extension('bsddb185', ['bsddbmodule.c'], 98622e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro libraries=libraries)) 98722e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro else: 98822e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro exts.append(Extension('bsddb185', ['bsddbmodule.c'])) 989d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 990d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('bsddb185') 991d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 992d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('bsddb185') 99322e00c42c092c151ab220b234e859d91f5b19c77Skip Montanaro 99400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # The standard Unix dbm module: 995d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen if platform not in ['cygwin']: 996a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis if find_file("ndbm.h", inc_dirs, []) is not None: 997a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis # Some systems have -lndbm, others don't 998a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis if self.compiler.find_library_file(lib_dirs, 'ndbm'): 999a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis ndbm_libs = ['ndbm'] 1000a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis else: 1001a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis ndbm_libs = [] 100234febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling exts.append( Extension('dbm', ['dbmmodule.c'], 1003d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen define_macros=[('HAVE_NDBM_H',None)], 1004a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis libraries = ndbm_libs ) ) 1005d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen elif (self.compiler.find_library_file(lib_dirs, 'gdbm') 1006d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen and find_file("gdbm/ndbm.h", inc_dirs, []) is not None): 1007d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen exts.append( Extension('dbm', ['dbmmodule.c'], 1008d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen define_macros=[('HAVE_GDBM_NDBM_H',None)], 100957454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro libraries = ['gdbm'] ) ) 101057454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro elif db_incs is not None: 101157454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro exts.append( Extension('dbm', ['dbmmodule.c'], 1012a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis library_dirs=dblib_dir, 1013a37d61f1d64fb5e35c0d4c658b2f97caf673c171Martin v. Löwis runtime_library_dirs=dblib_dir, 101457454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro include_dirs=db_incs, 1015d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen define_macros=[('HAVE_BERKDB_H',None), 1016d1b2045958306349b04da931a1a400d7e9a49fb9Jack Jansen ('DB_DBM_HSEARCH',None)], 101757454e57f83b407dd2653cbfcead7c9801beeff0Skip Montanaro libraries=dblibs)) 1018d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1019d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('dbm') 1020ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 102100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: 102200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling if (self.compiler.find_library_file(lib_dirs, 'gdbm')): 102300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('gdbm', ['gdbmmodule.c'], 102400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling libraries = ['gdbm'] ) ) 1025d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1026d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('gdbm') 102700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 102800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Unix-only modules 102934febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling if platform not in ['mac', 'win32']: 103000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Steen Lumholt's termios module 103100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('termios', ['termios.c']) ) 103200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Jeremy Hylton's rlimit interface 10332c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters if platform not in ['atheos']: 1034f90ae20354ceb501f0ba0b6459df17f1a8005a47Martin v. Löwis exts.append( Extension('resource', ['resource.c']) ) 1035d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1036d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('resource') 103700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 1038cf393f3fd9759ffac71c816f97ea01780848512cAndrew M. Kuchling # Sun yellow pages. Some systems have the functions in libc. 10398c255e4173cfc86ff7015b8f75dccf0d41b24003Martin v. Löwis if platform not in ['cygwin', 'atheos', 'qnx6']: 10406efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling if (self.compiler.find_library_file(lib_dirs, 'nsl')): 10416efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling libs = ['nsl'] 10426efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling else: 10436efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling libs = [] 10446efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling exts.append( Extension('nis', ['nismodule.c'], 10456efc6e783247f54e4dd3b4297a0a7d2bc654a141Andrew M. Kuchling libraries = libs) ) 1046d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1047d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('nis') 1048d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1049d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.extend(['nis', 'resource', 'termios']) 105000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 105172092941125cb0a3577fbf63294d14a02bb5dd2aSkip Montanaro # Curses support, requiring the System V version of curses, often 1052ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # provided by the ncurses library. 105386070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling panel_library = 'panel' 1054a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis if (self.compiler.find_library_file(lib_dirs, 'ncursesw')): 1055a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis curses_libs = ['ncursesw'] 105686070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling # Bug 1464056: If _curses.so links with ncursesw, 105786070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling # _curses_panel.so must link with panelw. 105886070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling panel_library = 'panelw' 1059a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis exts.append( Extension('_curses', ['_cursesmodule.c'], 1060a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis libraries = curses_libs) ) 1061a55e55e9f3034ceacbf90facc1a0548d63250df4Martin v. Löwis elif (self.compiler.find_library_file(lib_dirs, 'ncurses')): 106200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling curses_libs = ['ncurses'] 106300e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('_curses', ['_cursesmodule.c'], 106400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling libraries = curses_libs) ) 106538419c003c7f162d937320d01edce0c97ef502c3Fred Drake elif (self.compiler.find_library_file(lib_dirs, 'curses') 106638419c003c7f162d937320d01edce0c97ef502c3Fred Drake and platform != 'darwin'): 10675b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson # OSX has an old Berkeley curses, not good enough for 10685b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson # the _curses module. 106900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling if (self.compiler.find_library_file(lib_dirs, 'terminfo')): 107000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling curses_libs = ['curses', 'terminfo'] 10710b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz elif (self.compiler.find_library_file(lib_dirs, 'termcap')): 107200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling curses_libs = ['curses', 'termcap'] 10730b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz else: 10740b27ff92d2127ed39f52d9987e4e96313937cbc8Neal Norwitz curses_libs = ['curses'] 1075ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 107600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('_curses', ['_cursesmodule.c'], 107700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling libraries = curses_libs) ) 1078d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1079d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_curses') 1080ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 108100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # If the curses module is enabled, check for the panel module 1082e7ffbb24e80800de3667a88af96d03f8c9717039Andrew M. Kuchling if (module_enabled(exts, '_curses') and 108386070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling self.compiler.find_library_file(lib_dirs, panel_library)): 108400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('_curses_panel', ['_curses_panel.c'], 108586070428898b811339b0e4454e10ebf6f6ad4641Andrew M. Kuchling libraries = [panel_library] + curses_libs) ) 1086d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1087d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_curses_panel') 1088ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 1089259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # Andrew Kuchling's zlib module. Note that some versions of zlib 1090259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # 1.1.3 have security problems. See CERT Advisory CA-2002-07: 1091259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # http://www.cert.org/advisories/CA-2002-07.html 1092259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # 1093259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to 1094259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For 1095259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # now, we still accept 1.1.3, because we think it's difficult to 1096259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # exploit this in Python, and we'd rather make it RedHat's problem 1097259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # than our problem <wink>. 1098259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # 1099259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # You can upgrade zlib to version 1.1.4 yourself by going to 1100259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw # http://www.gzip.org/zlib/ 1101e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum zlib_inc = find_file('zlib.h', [], inc_dirs) 1102440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith have_zlib = False 1103e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum if zlib_inc is not None: 1104e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum zlib_h = zlib_inc[0] + '/zlib.h' 1105e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum version = '"0.0.0"' 1106259b1e18b4b5f8acca8366efa3a06e7d489d1045Barry Warsaw version_req = '"1.1.3"' 1107e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum fp = open(zlib_h) 1108e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum while 1: 1109e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum line = fp.readline() 1110e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum if not line: 1111e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum break 11128cdc03dca571fd2847d68bfd220234c0153f8f47Guido van Rossum if line.startswith('#define ZLIB_VERSION'): 1113e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum version = line.split()[2] 1114e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum break 1115e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum if version >= version_req: 1116e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum if (self.compiler.find_library_file(lib_dirs, 'z')): 11179b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren if sys.platform == "darwin": 11189b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren zlib_extra_link_args = ('-Wl,-search_paths_first',) 11199b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren else: 11209b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren zlib_extra_link_args = () 1121e697091c45001a1674434a553d67e15f2c6b13b8Guido van Rossum exts.append( Extension('zlib', ['zlibmodule.c'], 11229b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren libraries = ['z'], 11239b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren extra_link_args = zlib_extra_link_args)) 1124440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith have_zlib = True 1125d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1126d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('zlib') 1127d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1128d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('zlib') 1129d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1130d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('zlib') 113100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 1132440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith # Helper module for various ascii-encoders. Uses zlib for an optimized 1133440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith # crc32 if we have it. Otherwise binascii uses its own. 1134440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith if have_zlib: 1135440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith extra_compile_args = ['-DUSE_ZLIB_CRC32'] 1136440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith libraries = ['z'] 1137440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith extra_link_args = zlib_extra_link_args 1138440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith else: 1139440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith extra_compile_args = [] 1140440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith libraries = [] 1141440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith extra_link_args = [] 1142440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith exts.append( Extension('binascii', ['binascii.c'], 1143440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith extra_compile_args = extra_compile_args, 1144440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith libraries = libraries, 1145440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith extra_link_args = extra_link_args) ) 1146440ca772f33b7c2eae1beb2e26a643d3054066f9Gregory P. Smith 1147f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer # Gustavo Niemeyer's bz2 module. 1148f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer if (self.compiler.find_library_file(lib_dirs, 'bz2')): 11499b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren if sys.platform == "darwin": 11509b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren bz2_extra_link_args = ('-Wl,-search_paths_first',) 11519b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren else: 11529b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren bz2_extra_link_args = () 1153f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer exts.append( Extension('bz2', ['bz2module.c'], 11549b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren libraries = ['bz2'], 11559b8b619491144430a88c2a767e398c67ae057c5aRonald Oussoren extra_link_args = bz2_extra_link_args) ) 1156d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1157d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('bz2') 1158f8ca8364c9682df468a982a5f29831b76521bb6dGustavo Niemeyer 115900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Interface to the Expat XML parser 116000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # 1161fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # Expat was written by James Clark and is now maintained by a 1162fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # group of developers on SourceForge; see www.libexpat.org for 1163fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # more information. The pyexpat module was written by Paul 116499f3ba1648004af22ede20d09d567cb33dce3db8Andrew M. Kuchling # Prescod after a prototype by Jack Jansen. The Expat source 116599f3ba1648004af22ede20d09d567cb33dce3db8Andrew M. Kuchling # is included in Modules/expat/. Usage of a system 1166fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # shared libexpat.so/expat.dll is not advised. 1167fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # 1168fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # More information on Expat can be found at www.libexpat.org. 1169fc8341d0706bcf41711b289897cf7b8c4b7178a7Fred Drake # 11708301256a440fdd98fd500d225dac20ebb192e08fMartin v. Löwis expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat') 11712d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake define_macros = [ 1172988117fd6323c2b21ce1bdb2b1153a5d759a511cRonald Oussoren ('HAVE_EXPAT_CONFIG_H', '1'), 1173988117fd6323c2b21ce1bdb2b1153a5d759a511cRonald Oussoren ] 1174988117fd6323c2b21ce1bdb2b1153a5d759a511cRonald Oussoren 11752d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake exts.append(Extension('pyexpat', 11762d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake define_macros = define_macros, 11772d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake include_dirs = [expatinc], 11782d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake sources = ['pyexpat.c', 11792d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake 'expat/xmlparse.c', 11802d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake 'expat/xmlrole.c', 11812d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake 'expat/xmltok.c', 11822d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake ], 11832d59a4921234333b55e4f7b7f54d5649771d7c09Fred Drake )) 118400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 11854c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh # Fredrik Lundh's cElementTree module. Note that this also 11864c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh # uses expat (via the CAPI hook in pyexpat). 11874c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh 11886c403597954487e8129221351f72da3735c52c09Hye-Shik Chang if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')): 11894c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh define_macros.append(('USE_PYEXPAT_CAPI', None)) 11904c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh exts.append(Extension('_elementtree', 11914c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh define_macros = define_macros, 11924c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh include_dirs = [expatinc], 11934c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh sources = ['_elementtree.c'], 11944c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh )) 1195d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1196d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_elementtree') 11974c86ec651e4f251a9cf5a200d3521ea28566d3a0Fredrik Lundh 11983e2a30692085d32ac63f72b35da39158a471fc68Hye-Shik Chang # Hye-Shik Chang's CJKCodecs modules. 1199e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis if have_unicode: 1200e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis exts.append(Extension('_multibytecodec', 1201e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis ['cjkcodecs/multibytecodec.c'])) 1202e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): 1203d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro exts.append(Extension('_codecs_%s' % loc, 1204e2713becd8cb0c3b2db4d33832dd57a1d619f0f3Martin v. Löwis ['cjkcodecs/_codecs_%s.c' % loc])) 1205d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1206d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_multibytecodec') 1207d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): 1208d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_codecs_%s' % loc) 12093e2a30692085d32ac63f72b35da39158a471fc68Hye-Shik Chang 12105b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson # Dynamic loading module 1211770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum if sys.maxint == 0x7fffffff: 1212770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum # This requires sizeof(int) == sizeof(long) == sizeof(char*) 1213770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum dl_inc = find_file('dlfcn.h', [], inc_dirs) 12148220174489e3f28b874b3b45516585c30e5999daAnthony Baxter if (dl_inc is not None) and (platform not in ['atheos']): 1215770acd3f7fff52eef0d0ad02beaa4c569d70811fGuido van Rossum exts.append( Extension('dl', ['dlmodule.c']) ) 1216d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1217d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('dl') 1218d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1219d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('dl') 12205b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 1221cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller # Thomas Heller's _ctypes module 12229176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis self.detect_ctypes(inc_dirs, lib_dirs) 1223cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller 122400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Platform-specific libraries 122534febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling if platform == 'linux2': 122600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Linux-specific modules 122700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) 1228d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1229d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('linuxaudiodev') 12300a6355eb1fb5af03827a00e146c147c94efe78c9Greg Ward 12314e422817eb1bc5a6a42365001ad45683ae07e559Hye-Shik Chang if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', 1232ea684743daa0c198ab327d07832eca48a9578c68Hye-Shik Chang 'freebsd7', 'freebsd8'): 12330c016a9590b3da47f19420d0616e0c72cae19abfGuido van Rossum exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) 1234d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1235d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('ossaudiodev') 123600e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 123734febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling if platform == 'sunos5': 1238ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # SunOS specific modules 123900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) 1240d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro else: 1241d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('sunaudiodev') 12425b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 124366cb018c96e49b5e5cf1b8fc395171a223d86d8eTim Peters if platform == 'darwin' and ("--disable-toolbox-glue" not in 1244090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren sysconfig.get_config_var("CONFIG_ARGS")): 1245090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren 1246090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren if os.uname()[2] > '8.': 1247090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren # We're on Mac OS X 10.4 or later, the compiler should 1248090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren # support '-Wno-deprecated-declarations'. This will 1249090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren # surpress deprecation warnings for the Carbon extensions, 1250090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren # these extensions wrap the Carbon APIs and even those 1251090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren # parts that are deprecated. 1252090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren carbon_extra_compile_args = ['-Wno-deprecated-declarations'] 1253090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren else: 1254090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren carbon_extra_compile_args = [] 1255090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren 125605ced6aa761bab7348e95a479b6f791e636ceae7Just van Rossum # Mac OS X specific modules. 12573e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz def macSrcExists(name1, name2=''): 12583e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz if not name1: 12593e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz return None 12603e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz names = (name1,) 12613e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz if name2: 12623e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz names = (name1, name2) 12633e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz path = os.path.join(srcdir, 'Mac', 'Modules', *names) 12643e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz return os.path.exists(path) 12653e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 12663e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz def addMacExtension(name, kwds, extra_srcs=[]): 12673e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz dirname = '' 12683e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz if name[0] == '_': 12693e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz dirname = name[1:].lower() 12703e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz cname = name + '.c' 12713e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz cmodulename = name + 'module.c' 12723e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c 12733e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz if macSrcExists(cname): 12743e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz srcs = [cname] 12753e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz elif macSrcExists(cmodulename): 12763e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz srcs = [cmodulename] 12773e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz elif macSrcExists(dirname, cname): 12783e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # XXX(nnorwitz): If all the names ended with module, we 12793e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # wouldn't need this condition. ibcarbon is the only one. 12803e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz srcs = [os.path.join(dirname, cname)] 12813e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz elif macSrcExists(dirname, cmodulename): 12823e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz srcs = [os.path.join(dirname, cmodulename)] 12833e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz else: 12843e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz raise RuntimeError("%s not found" % name) 12853e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 12863e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # Here's the whole point: add the extension with sources 12873e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz exts.append(Extension(name, srcs + extra_srcs, **kwds)) 12883e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 12893e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # Core Foundation 12903e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz core_kwds = {'extra_compile_args': carbon_extra_compile_args, 12913e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 'extra_link_args': ['-framework', 'CoreFoundation'], 12923e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz } 12933e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz addMacExtension('_CF', core_kwds, ['cf/pycfbridge.c']) 12943e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz addMacExtension('autoGIL', core_kwds) 12953e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 12963e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # Carbon 12973e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz carbon_kwds = {'extra_compile_args': carbon_extra_compile_args, 12983e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 'extra_link_args': ['-framework', 'Carbon'], 12993e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz } 1300a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter CARBON_EXTS = ['ColorPicker', 'gestalt', 'MacOS', 'Nav', 1301a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter 'OSATerminology', 'icglue', 13023e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # All these are in subdirs 1303a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter '_AE', '_AH', '_App', '_CarbonEvt', '_Cm', '_Ctl', 13043e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz '_Dlg', '_Drag', '_Evt', '_File', '_Folder', '_Fm', 1305a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter '_Help', '_Icn', '_IBCarbon', '_List', 1306a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter '_Menu', '_Mlte', '_OSA', '_Res', '_Qd', '_Qdoffs', 13073e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz '_Scrap', '_Snd', '_TE', '_Win', 1308a2a26b9e1f00692c01ea6a731eef7d150088a5bdAnthony Baxter ] 13093e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz for name in CARBON_EXTS: 13103e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz addMacExtension(name, carbon_kwds) 13113e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 13123e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz # Application Services & QuickTime 13133e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz app_kwds = {'extra_compile_args': carbon_extra_compile_args, 13143e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 'extra_link_args': ['-framework','ApplicationServices'], 13153e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz } 13163e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz addMacExtension('_Launch', app_kwds) 13173e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz addMacExtension('_CG', app_kwds) 13183e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 131905ced6aa761bab7348e95a479b6f791e636ceae7Just van Rossum exts.append( Extension('_Qt', ['qt/_Qtmodule.c'], 1320090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren extra_compile_args=carbon_extra_compile_args, 1321090f81588fc2298b3c967ddda3c3ffc592caf92aRonald Oussoren extra_link_args=['-framework', 'QuickTime', 132205ced6aa761bab7348e95a479b6f791e636ceae7Just van Rossum '-framework', 'Carbon']) ) 13233e1ec3aa22ea152b8485c1d8cd986b6eff68ece8Neal Norwitz 13245b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 1325fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling self.extensions.extend(exts) 1326fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 1327fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Call the method for detecting whether _tkinter can be compiled 1328fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling self.detect_tkinter(inc_dirs, lib_dirs) 1329ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 1330d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro if '_tkinter' not in [e.name for e in self.extensions]: 1331d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro missing.append('_tkinter') 1332d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 1333d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro return missing 1334d1287323ca3273f4408a5c3f3047c316b72ea78cSkip Montanaro 13350b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen def detect_tkinter_darwin(self, inc_dirs, lib_dirs): 13360b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # The _tkinter module, using frameworks. Since frameworks are quite 13370b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # different the UNIX search logic is not sharable. 13380b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen from os.path import join, exists 13390b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen framework_dirs = [ 13402c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters '/System/Library/Frameworks/', 13412c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters '/Library/Frameworks', 13420b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen join(os.getenv('HOME'), '/Library/Frameworks') 13430b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen ] 13440b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen 13450174dddc65af50900324afca3c5d2400858b75f0Skip Montanaro # Find the directory that contains the Tcl.framework and Tk.framework 13460b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # bundles. 13470b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # XXX distutils should support -F! 13480b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen for F in framework_dirs: 13492c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters # both Tcl.framework and Tk.framework should be present 13500b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen for fw in 'Tcl', 'Tk': 13512c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters if not exists(join(F, fw + '.framework')): 13520b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen break 13530b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen else: 13540b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # ok, F is now directory with both frameworks. Continure 13550b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # building 13560b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen break 13570b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen else: 13580b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # Tk and Tcl frameworks not found. Normal "unix" tkinter search 13590b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # will now resume. 13600b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen return 0 13612c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters 13620b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # For 8.4a2, we must add -I options that point inside the Tcl and Tk 13630b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # frameworks. In later release we should hopefully be able to pass 13642c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters # the -F option to gcc, which specifies a framework lookup path. 13650b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # 13660b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen include_dirs = [ 13672c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters join(F, fw + '.framework', H) 13680b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen for fw in 'Tcl', 'Tk' 13690b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen for H in 'Headers', 'Versions/Current/PrivateHeaders' 13700b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen ] 13710b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen 13722c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters # For 8.4a2, the X11 headers are not included. Rather than include a 13730b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # complicated search, this is a hard-coded path. It could bail out 13740b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # if X11 libs are not found... 13750b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen include_dirs.append('/usr/X11R6/include') 13760b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen frameworks = ['-framework', 'Tcl', '-framework', 'Tk'] 13770b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen 13780b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], 13790b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen define_macros=[('WITH_APPINIT', 1)], 13800b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen include_dirs = include_dirs, 13810b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen libraries = [], 13820b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen extra_compile_args = frameworks, 13830b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen extra_link_args = frameworks, 13840b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen ) 13850b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen self.extensions.append(ext) 13860b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen return 1 13870b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen 13882c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters 1389fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling def detect_tkinter(self, inc_dirs, lib_dirs): 139000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # The _tkinter module. 13915b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 13920b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # Rather than complicate the code below, detecting and building 13930b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # AquaTk is a separate method. Only one Tkinter will be built on 13940b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen # Darwin - either AquaTk, if it is found, or X11 based Tk. 13950b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen platform = self.get_platform() 13960174dddc65af50900324afca3c5d2400858b75f0Skip Montanaro if (platform == 'darwin' and 13970174dddc65af50900324afca3c5d2400858b75f0Skip Montanaro self.detect_tkinter_darwin(inc_dirs, lib_dirs)): 13982c60f7a13697bbc19c4d5ef0b052c34cf1848244Tim Peters return 13990b06be7b0be87bd78707a939cb9964f634f392d4Jack Jansen 1400fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Assume we haven't found any of the libraries or include files 14013db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis # The versions with dots are used on Unix, and the versions without 14023db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis # dots on Windows, for detection by cygwin. 1403fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling tcllib = tklib = tcl_includes = tk_includes = None 14044c4a45de8f992bb0c5cf35910d34ed6c63fa9d14Andrew M. Kuchling for version in ['8.5', '85', '8.4', '84', '8.3', '83', '8.2', 14053db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis '82', '8.1', '81', '8.0', '80']: 1406cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler tklib = self.compiler.find_library_file(lib_dirs, 'tk' + version) 1407cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler tcllib = self.compiler.find_library_file(lib_dirs, 'tcl' + version) 14085b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson if tklib and tcllib: 140900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # Exit the loop when we've found the Tcl/Tk libraries 141000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling break 1411fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 1412ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # Now check for the header files 1413fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling if tklib and tcllib: 14143c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling # Check for the include files on Debian and {Free,Open}BSD, where 1415fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # they're put in /usr/include/{tcl,tk}X.Y 14163c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling dotversion = version 14173c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling if '.' not in dotversion and "bsd" in sys.platform.lower(): 14183c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a, 14193c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling # but the include subdirs are named like .../include/tcl8.3. 14203c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling dotversion = dotversion[:-1] + '.' + dotversion[-1] 14213c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tcl_include_sub = [] 14223c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tk_include_sub = [] 14233c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling for dir in inc_dirs: 14243c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tcl_include_sub += [dir + os.sep + "tcl" + dotversion] 14253c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tk_include_sub += [dir + os.sep + "tk" + dotversion] 14263c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tk_include_sub += tcl_include_sub 14273c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub) 14283c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling tk_includes = find_file('tk.h', inc_dirs, tk_include_sub) 1429fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 1430e86a59af886d6c0f58f53e42878a25e48627fed1Martin v. Löwis if (tcllib is None or tklib is None or 1431fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling tcl_includes is None or tk_includes is None): 14323c0aa7e7a2e5bee936d281af3bd9f99b6096325cAndrew M. Kuchling self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2) 1433fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling return 1434ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 1435fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # OK... everything seems to be present for Tcl/Tk. 1436fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 1437fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] 1438fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling for dir in tcl_includes + tk_includes: 1439fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling if dir not in include_dirs: 1440fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs.append(dir) 1441ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 1442fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Check for various platform-specific directories 144334febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling if platform == 'sunos5': 1444fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs.append('/usr/openwin/include') 1445fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling added_lib_dirs.append('/usr/openwin/lib') 1446fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling elif os.path.exists('/usr/X11R6/include'): 1447fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs.append('/usr/X11R6/include') 1448fba73698240660d9154b6917b87dd333d6fb8284Martin v. Löwis added_lib_dirs.append('/usr/X11R6/lib64') 1449fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling added_lib_dirs.append('/usr/X11R6/lib') 1450fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling elif os.path.exists('/usr/X11R5/include'): 1451fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs.append('/usr/X11R5/include') 1452fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling added_lib_dirs.append('/usr/X11R5/lib') 1453fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling else: 1454ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # Assume default location for X11 1455fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs.append('/usr/X11/include') 1456fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling added_lib_dirs.append('/usr/X11/lib') 1457fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 14589181c94e05250b8f69615a96634d55afe532e406Jason Tishler # If Cygwin, then verify that X is installed before proceeding 14599181c94e05250b8f69615a96634d55afe532e406Jason Tishler if platform == 'cygwin': 14609181c94e05250b8f69615a96634d55afe532e406Jason Tishler x11_inc = find_file('X11/Xlib.h', [], include_dirs) 14619181c94e05250b8f69615a96634d55afe532e406Jason Tishler if x11_inc is None: 14629181c94e05250b8f69615a96634d55afe532e406Jason Tishler return 14639181c94e05250b8f69615a96634d55afe532e406Jason Tishler 1464fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Check for BLT extension 146538419c003c7f162d937320d01edce0c97ef502c3Fred Drake if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 146638419c003c7f162d937320d01edce0c97ef502c3Fred Drake 'BLT8.0'): 1467fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling defs.append( ('WITH_BLT', 1) ) 1468fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling libs.append('BLT8.0') 1469427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis elif self.compiler.find_library_file(lib_dirs + added_lib_dirs, 1470427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis 'BLT'): 1471427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis defs.append( ('WITH_BLT', 1) ) 1472427a290c9afca605ab8ed799f0072d890318b837Martin v. Löwis libs.append('BLT') 1473fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 1474fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # Add the Tcl/Tk libraries 1475cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler libs.append('tk'+ version) 1476cccac1a163915d7a4e757a1a4e62b21c91b5c475Jason Tishler libs.append('tcl'+ version) 1477ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 147834febf5e9273cf7715b46286ff28fb41fa413231Andrew M. Kuchling if platform in ['aix3', 'aix4']: 1479fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling libs.append('ld') 1480fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 14813db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis # Finally, link with the X11 libraries (not appropriate on cygwin) 14823db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis if platform != "cygwin": 14833db5b8cc76d055c6576aaff51722fc4d64d64388Martin v. Löwis libs.append('X11') 1484fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling 1485fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], 1486fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling define_macros=[('WITH_APPINIT', 1)] + defs, 1487fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling include_dirs = include_dirs, 1488fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling libraries = libs, 1489fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling library_dirs = added_lib_dirs, 1490fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling ) 1491fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling self.extensions.append(ext) 1492ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 14936c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum## # Uncomment these lines if you want to play with xxmodule.c 14946c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum## ext = Extension('xx', ['xxmodule.c']) 14956c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum## self.extensions.append(ext) 14966c7438e784a0537260ed9423079e3bb5d61be8c3Guido van Rossum 1497fbe73769a45aac293d8abb66ac4cd7a22f40fff8Andrew M. Kuchling # XXX handle these, but how to detect? 149800e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # *** Uncomment and edit for PIL (TkImaging) extension only: 1499ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ 150000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # *** Uncomment and edit for TOGL extension only: 1501ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # -DWITH_TOGL togl.c \ 150200e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # *** Uncomment these for TOGL extension only: 1503ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh # -lGL -lGLU -lXext -lXmu \ 150400e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling 15058bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller def configure_ctypes_darwin(self, ext): 15068bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller # Darwin (OS X) uses preconfigured files, in 15078bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller # the Modules/_ctypes/libffi_osx directory. 15088bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller (srcdir,) = sysconfig.get_config_vars('srcdir') 15098bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', 15108bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller '_ctypes', 'libffi_osx')) 15118bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller sources = [os.path.join(ffi_srcdir, p) 15128bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller for p in ['ffi.c', 15138bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'x86/x86-darwin.S', 15148bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'x86/x86-ffi_darwin.c', 15158bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'x86/x86-ffi64.c', 15168bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'powerpc/ppc-darwin.S', 15178bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'powerpc/ppc-darwin_closure.S', 15188bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'powerpc/ppc-ffi_darwin.c', 15198bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 'powerpc/ppc64-darwin_closure.S', 15208bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller ]] 15218bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 15228bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller # Add .S (preprocessed assembly) to C compiler source extensions. 15238bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller self.compiler.src_extensions.append('.S') 15248bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 15258bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller include_dirs = [os.path.join(ffi_srcdir, 'include'), 15268bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller os.path.join(ffi_srcdir, 'powerpc')] 15278bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller ext.include_dirs.extend(include_dirs) 15288bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller ext.sources.extend(sources) 15298bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller return True 15308bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 1531eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller def configure_ctypes(self, ext): 15329176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if not self.use_system_libffi: 15338bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller if sys.platform == 'darwin': 15348bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller return self.configure_ctypes_darwin(ext) 15358bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 15369176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis (srcdir,) = sysconfig.get_config_vars('srcdir') 15379176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_builddir = os.path.join(self.build_temp, 'libffi') 15389176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', 15399176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis '_ctypes', 'libffi')) 15409176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py') 15419176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15425e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller from distutils.dep_util import newer_group 15435e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller 15445e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller config_sources = [os.path.join(ffi_srcdir, fname) 1545f1a4aa340ea3794a6cc2d54fb6647b4d7b61f275Martin v. Löwis for fname in os.listdir(ffi_srcdir) 1546f1a4aa340ea3794a6cc2d54fb6647b4d7b61f275Martin v. Löwis if os.path.isfile(os.path.join(ffi_srcdir, fname))] 15475e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller if self.force or newer_group(config_sources, 15485e218b44549153816f2dd842d532b2ea5aa476e8Thomas Heller ffi_configfile): 15499176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis from distutils.dir_util import mkpath 15509176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis mkpath(ffi_builddir) 15519176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis config_args = [] 15529176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15539176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis # Pass empty CFLAGS because we'll just append the resulting 15549176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis # CFLAGS to Python's; -g or -O2 is to be avoided. 15559176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \ 15569176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis % (ffi_builddir, ffi_srcdir, " ".join(config_args)) 15579176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15589176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis res = os.system(cmd) 15599176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if res or not os.path.exists(ffi_configfile): 15609176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis print "Failed to configure _ctypes module" 15619176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis return False 15629176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15639176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis fficonfig = {} 15649176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis execfile(ffi_configfile, globals(), fficonfig) 15659176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src') 15669176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15679176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis # Add .S (preprocessed assembly) to C compiler source extensions. 15689176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis self.compiler.src_extensions.append('.S') 15699176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15709176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis include_dirs = [os.path.join(ffi_builddir, 'include'), 15719176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_builddir, ffi_srcdir] 15729176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis extra_compile_args = fficonfig['ffi_cflags'].split() 15739176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 15749176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ext.sources.extend(fficonfig['ffi_sources']) 15759176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ext.include_dirs.extend(include_dirs) 15769176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ext.extra_compile_args.extend(extra_compile_args) 1577795246cf9937f088f8d98253f38da4a093c08300Thomas Heller return True 1578eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller 15799176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis def detect_ctypes(self, inc_dirs, lib_dirs): 15809176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis self.use_system_libffi = False 1581eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller include_dirs = [] 1582eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller extra_compile_args = [] 15831798489547a259876c495280dcd5d649269967f3Thomas Heller extra_link_args = [] 1584cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller sources = ['_ctypes/_ctypes.c', 1585cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller '_ctypes/callbacks.c', 1586cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller '_ctypes/callproc.c', 1587cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller '_ctypes/stgdict.c', 1588cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller '_ctypes/cfield.c', 1589eba43c157b1ed57bf95144f704d56c3296a6f637Thomas Heller '_ctypes/malloc_closure.c'] 1590cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller depends = ['_ctypes/ctypes.h'] 1591cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller 1592cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller if sys.platform == 'darwin': 1593cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller sources.append('_ctypes/darwin/dlfcn_simple.c') 15948bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller extra_compile_args.append('-DMACOSX') 1595cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller include_dirs.append('_ctypes/darwin') 1596cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller# XXX Is this still needed? 1597cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller## extra_link_args.extend(['-read_only_relocs', 'warning']) 1598cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller 15991798489547a259876c495280dcd5d649269967f3Thomas Heller elif sys.platform == 'sunos5': 160073f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # XXX This shouldn't be necessary; it appears that some 160173f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # of the assembler code is non-PIC (i.e. it has relocations 160273f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # when it shouldn't. The proper fix would be to rewrite 160373f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # the assembler code to be PIC. 160473f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # This only works with GCC; the Sun compiler likely refuses 160573f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # this option. If you want to compile ctypes with the Sun 160673f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # compiler, please research a proper solution, instead of 160773f12a33f7fffb820cb90487ba962598c0f0d275Martin v. Löwis # finding some -z option for the Sun compiler. 16081798489547a259876c495280dcd5d649269967f3Thomas Heller extra_link_args.append('-mimpure-text') 16091798489547a259876c495280dcd5d649269967f3Thomas Heller 161003b75ddf7c63bb7b7bc1b424661c94076b57be9eThomas Heller elif sys.platform.startswith('hpux'): 161103b75ddf7c63bb7b7bc1b424661c94076b57be9eThomas Heller extra_link_args.append('-fPIC') 161203b75ddf7c63bb7b7bc1b424661c94076b57be9eThomas Heller 1613cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller ext = Extension('_ctypes', 1614cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller include_dirs=include_dirs, 1615cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller extra_compile_args=extra_compile_args, 16161798489547a259876c495280dcd5d649269967f3Thomas Heller extra_link_args=extra_link_args, 16179176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis libraries=[], 1618cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller sources=sources, 1619cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller depends=depends) 1620cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller ext_test = Extension('_ctypes_test', 1621cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller sources=['_ctypes/_ctypes_test.c']) 1622cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller self.extensions.extend([ext, ext_test]) 1623cf567c1b9c347e5a5e5833fecb7d10ecc675a83bThomas Heller 16249176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): 16259176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis return 16269176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 16278bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller if sys.platform == 'darwin': 16288bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller # OS X 10.5 comes with libffi.dylib; the include files are 16298bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller # in /usr/include/ffi 16308bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller inc_dirs.append('/usr/include/ffi') 16318bdf81d2df388ce06088193f95c992a7ee1eb553Thomas Heller 16329176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_inc = find_file('ffi.h', [], inc_dirs) 16339176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if ffi_inc is not None: 16349176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_h = ffi_inc[0] + '/ffi.h' 16359176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis fp = open(ffi_h) 16369176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis while 1: 16379176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis line = fp.readline() 16389176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if not line: 16399176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_inc = None 16409176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis break 16419176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if line.startswith('#define LIBFFI_H'): 16429176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis break 16439176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_lib = None 16449176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if ffi_inc is not None: 16459176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'): 16469176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if (self.compiler.find_library_file(lib_dirs, lib_name)): 16479176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ffi_lib = lib_name 16489176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis break 16499176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 16509176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis if ffi_inc and ffi_lib: 16519176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ext.include_dirs.extend(ffi_inc) 16529176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis ext.libraries.append(ffi_lib) 16539176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis self.use_system_libffi = True 16549176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 16559176fc1466c8a896ab57b054bd426e63770e2cfaMartin v. Löwis 1656f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchlingclass PyBuildInstall(install): 1657f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling # Suppress the warning about installation into the lib_dynload 1658f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling # directory, which is not in sys.path when running Python during 1659f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling # installation: 1660f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling def initialize_options (self): 1661f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling install.initialize_options(self) 1662f52d27e52d289b99837b4555fb3f757f2c89f4adAndrew M. Kuchling self.warn_dir=0 16635b10910d7a1f9543568aba732af3881c85e9289dMichael W. Hudson 1664529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudsonclass PyBuildInstallLib(install_lib): 1665529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson # Do exactly what install_lib does but make sure correct access modes get 1666529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson # set on installed directories and files. All installed files with get 1667529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson # mode 644 unless they are a shared library in which case they will get 1668529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson # mode 755. All installed directories will get mode 755. 1669529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1670529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson so_ext = sysconfig.get_config_var("SO") 1671529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1672529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson def install(self): 1673529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson outfiles = install_lib.install(self) 1674529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson self.set_file_modes(outfiles, 0644, 0755) 1675529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson self.set_dir_modes(self.install_dir, 0755) 1676529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson return outfiles 1677529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1678529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson def set_file_modes(self, files, defaultMode, sharedLibMode): 1679529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if not self.is_chmod_supported(): return 1680529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if not files: return 1681529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1682529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson for filename in files: 1683529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if os.path.islink(filename): continue 1684529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson mode = defaultMode 1685529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if filename.endswith(self.so_ext): mode = sharedLibMode 1686529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson log.info("changing mode of %s to %o", filename, mode) 1687529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if not self.dry_run: os.chmod(filename, mode) 1688529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1689529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson def set_dir_modes(self, dirname, mode): 1690529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if not self.is_chmod_supported(): return 1691529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson os.path.walk(dirname, self.set_dir_modes_visitor, mode) 1692529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1693529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson def set_dir_modes_visitor(self, mode, dirname, names): 1694529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if os.path.islink(dirname): return 1695529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson log.info("changing mode of %s to %o", dirname, mode) 1696529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson if not self.dry_run: os.chmod(dirname, mode) 1697529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 1698529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson def is_chmod_supported(self): 1699529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson return hasattr(os, 'chmod') 1700529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 170114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumSUMMARY = """ 170214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumPython is an interpreted, interactive, object-oriented programming 170314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumlanguage. It is often compared to Tcl, Perl, Scheme or Java. 170414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum 170514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumPython combines remarkable power with very clear syntax. It has 170614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossummodules, classes, exceptions, very high level dynamic data types, and 170714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumdynamic typing. There are interfaces to many system calls and 170814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumlibraries, as well as to various windowing systems (X11, Motif, Tk, 170914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumMac, MFC). New built-in modules are easily written in C or C++. Python 171014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumis also usable as an extension language for applications that need a 171114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumprogrammable interface. 171214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum 171314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumThe Python implementation is portable: it runs on many brands of UNIX, 171414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumon Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't 171514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumlisted here, it may still be supported, if there's a C compiler for 171614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumit. Ask around on comp.lang.python -- or just try compiling Python 171714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossumyourself. 171814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum""" 171914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum 172014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumCLASSIFIERS = """ 172114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumDevelopment Status :: 3 - Alpha 172214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumDevelopment Status :: 6 - Mature 172314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumLicense :: OSI Approved :: Python Software Foundation License 172414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumNatural Language :: English 172514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumProgramming Language :: C 172614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumProgramming Language :: Python 172714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van RossumTopic :: Software Development 172814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum""" 172914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum 173000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingdef main(): 173162686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling # turn off warnings when deprecated modules are imported 173262686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling import warnings 173362686696123eb82df5f688b9a3906b9b648ce220Andrew M. Kuchling warnings.filterwarnings("ignore",category=DeprecationWarning) 173414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum setup(# PyPI Metadata (PEP 301) 173514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum name = "Python", 173614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum version = sys.version.split()[0], 173714ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum url = "http://www.python.org/%s" % sys.version[:3], 173814ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum maintainer = "Guido van Rossum and the Python community", 173914ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum maintainer_email = "python-dev@python.org", 174014ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum description = "A high-level object-oriented programming language", 174114ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum long_description = SUMMARY.strip(), 174214ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum license = "PSF license", 174314ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum classifiers = filter(None, CLASSIFIERS.split("\n")), 174414ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum platforms = ["Many"], 174514ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum 174614ee89c785fe61c9397dfdd457994a2ba601a00bGuido van Rossum # Build info 1747529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall, 1748529a505da4c2ffc79b598935a241a9ffe17563e5Michael W. Hudson 'install_lib':PyBuildInstallLib}, 174900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # The struct module is defined here, because build_ext won't be 175000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling # called unless there's at least one extension module defined. 17517ccc95a315315568dd0660b5fb915f9e2e38f9daBob Ippolito ext_modules=[Extension('_struct', ['_struct.c'])], 1752aece4270b1de4777eef3f2aadd7aaf3ac9b69ceeAndrew M. Kuchling 1753aece4270b1de4777eef3f2aadd7aaf3ac9b69ceeAndrew M. Kuchling # Scripts to install 1754852f79993f8d04f00f54a94e7275550a72454f5fSkip Montanaro scripts = ['Tools/scripts/pydoc', 'Tools/scripts/idle', 1755cdbc977c0344cfe2294e8be69cd1acd77b3b79adMartin v. Löwis 'Tools/scripts/2to3', 1756852f79993f8d04f00f54a94e7275550a72454f5fSkip Montanaro 'Lib/smtpd.py'] 175700e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling ) 1758ade711a5c347fdb483c7d91027499a3a7b9acd05Fredrik Lundh 175900e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling# --install-platlib 176000e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchlingif __name__ == '__main__': 176100e0f21be8517acde581ef7b93982e852c62ea70Andrew M. Kuchling main() 1762