| 1 | n/a | # Autodetecting setup.py script for building the Python extensions |
|---|
| 2 | n/a | # |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | __version__ = "$Revision: 78784 $" |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | import sys, os, imp, re, optparse |
|---|
| 7 | n/a | from glob import glob |
|---|
| 8 | n/a | from platform import machine as platform_machine |
|---|
| 9 | n/a | import sysconfig |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | from distutils import log |
|---|
| 12 | n/a | from distutils import text_file |
|---|
| 13 | n/a | from distutils.errors import * |
|---|
| 14 | n/a | from distutils.core import Extension, setup |
|---|
| 15 | n/a | from distutils.command.build_ext import build_ext |
|---|
| 16 | n/a | from distutils.command.install import install |
|---|
| 17 | n/a | from distutils.command.install_lib import install_lib |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | # Were we compiled --with-pydebug or with #define Py_DEBUG? |
|---|
| 20 | n/a | COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount') |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | # This global variable is used to hold the list of modules to be disabled. |
|---|
| 23 | n/a | disabled_module_list = [] |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | def add_dir_to_list(dirlist, dir): |
|---|
| 26 | n/a | """Add the directory 'dir' to the list 'dirlist' (at the front) if |
|---|
| 27 | n/a | 1) 'dir' is not already in 'dirlist' |
|---|
| 28 | n/a | 2) 'dir' actually exists, and is a directory.""" |
|---|
| 29 | n/a | if dir is not None and os.path.isdir(dir) and dir not in dirlist: |
|---|
| 30 | n/a | dirlist.insert(0, dir) |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | def find_file(filename, std_dirs, paths): |
|---|
| 33 | n/a | """Searches for the directory where a given file is located, |
|---|
| 34 | n/a | and returns a possibly-empty list of additional directories, or None |
|---|
| 35 | n/a | if the file couldn't be found at all. |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | 'filename' is the name of a file, such as readline.h or libcrypto.a. |
|---|
| 38 | n/a | 'std_dirs' is the list of standard system directories; if the |
|---|
| 39 | n/a | file is found in one of them, no additional directives are needed. |
|---|
| 40 | n/a | 'paths' is a list of additional locations to check; if the file is |
|---|
| 41 | n/a | found in one of them, the resulting list will contain the directory. |
|---|
| 42 | n/a | """ |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | # Check the standard locations |
|---|
| 45 | n/a | for dir in std_dirs: |
|---|
| 46 | n/a | f = os.path.join(dir, filename) |
|---|
| 47 | n/a | if os.path.exists(f): return [] |
|---|
| 48 | n/a | |
|---|
| 49 | n/a | # Check the additional directories |
|---|
| 50 | n/a | for dir in paths: |
|---|
| 51 | n/a | f = os.path.join(dir, filename) |
|---|
| 52 | n/a | if os.path.exists(f): |
|---|
| 53 | n/a | return [dir] |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | # Not found anywhere |
|---|
| 56 | n/a | return None |
|---|
| 57 | n/a | |
|---|
| 58 | n/a | def find_library_file(compiler, libname, std_dirs, paths): |
|---|
| 59 | n/a | result = compiler.find_library_file(std_dirs + paths, libname) |
|---|
| 60 | n/a | if result is None: |
|---|
| 61 | n/a | return None |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | # Check whether the found file is in one of the standard directories |
|---|
| 64 | n/a | dirname = os.path.dirname(result) |
|---|
| 65 | n/a | for p in std_dirs: |
|---|
| 66 | n/a | # Ensure path doesn't end with path separator |
|---|
| 67 | n/a | p = p.rstrip(os.sep) |
|---|
| 68 | n/a | if p == dirname: |
|---|
| 69 | n/a | return [ ] |
|---|
| 70 | n/a | |
|---|
| 71 | n/a | # Otherwise, it must have been in one of the additional directories, |
|---|
| 72 | n/a | # so we have to figure out which one. |
|---|
| 73 | n/a | for p in paths: |
|---|
| 74 | n/a | # Ensure path doesn't end with path separator |
|---|
| 75 | n/a | p = p.rstrip(os.sep) |
|---|
| 76 | n/a | if p == dirname: |
|---|
| 77 | n/a | return [p] |
|---|
| 78 | n/a | else: |
|---|
| 79 | n/a | assert False, "Internal error: Path not found in std_dirs or paths" |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | def module_enabled(extlist, modname): |
|---|
| 82 | n/a | """Returns whether the module 'modname' is present in the list |
|---|
| 83 | n/a | of extensions 'extlist'.""" |
|---|
| 84 | n/a | extlist = [ext for ext in extlist if ext.name == modname] |
|---|
| 85 | n/a | return len(extlist) |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | def find_module_file(module, dirlist): |
|---|
| 88 | n/a | """Find a module in a set of possible folders. If it is not found |
|---|
| 89 | n/a | return the unadorned filename""" |
|---|
| 90 | n/a | list = find_file(module, [], dirlist) |
|---|
| 91 | n/a | if not list: |
|---|
| 92 | n/a | return module |
|---|
| 93 | n/a | if len(list) > 1: |
|---|
| 94 | n/a | log.info("WARNING: multiple copies of %s found"%module) |
|---|
| 95 | n/a | return os.path.join(list[0], module) |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | class PyBuildExt(build_ext): |
|---|
| 98 | n/a | |
|---|
| 99 | n/a | def __init__(self, dist): |
|---|
| 100 | n/a | build_ext.__init__(self, dist) |
|---|
| 101 | n/a | self.failed = [] |
|---|
| 102 | n/a | |
|---|
| 103 | n/a | def build_extensions(self): |
|---|
| 104 | n/a | |
|---|
| 105 | n/a | # Detect which modules should be compiled |
|---|
| 106 | n/a | missing = self.detect_modules() |
|---|
| 107 | n/a | |
|---|
| 108 | n/a | # Remove modules that are present on the disabled list |
|---|
| 109 | n/a | extensions = [ext for ext in self.extensions |
|---|
| 110 | n/a | if ext.name not in disabled_module_list] |
|---|
| 111 | n/a | # move ctypes to the end, it depends on other modules |
|---|
| 112 | n/a | ext_map = dict((ext.name, i) for i, ext in enumerate(extensions)) |
|---|
| 113 | n/a | if "_ctypes" in ext_map: |
|---|
| 114 | n/a | ctypes = extensions.pop(ext_map["_ctypes"]) |
|---|
| 115 | n/a | extensions.append(ctypes) |
|---|
| 116 | n/a | self.extensions = extensions |
|---|
| 117 | n/a | |
|---|
| 118 | n/a | # Fix up the autodetected modules, prefixing all the source files |
|---|
| 119 | n/a | # with Modules/ and adding Python's include directory to the path. |
|---|
| 120 | n/a | (srcdir,) = sysconfig.get_config_vars('srcdir') |
|---|
| 121 | n/a | if not srcdir: |
|---|
| 122 | n/a | # Maybe running on Windows but not using CYGWIN? |
|---|
| 123 | n/a | raise ValueError("No source directory; cannot proceed.") |
|---|
| 124 | n/a | srcdir = os.path.abspath(srcdir) |
|---|
| 125 | n/a | moddirlist = [os.path.join(srcdir, 'Modules')] |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | # Platform-dependent module source and include directories |
|---|
| 128 | n/a | incdirlist = [] |
|---|
| 129 | n/a | platform = self.get_platform() |
|---|
| 130 | n/a | if platform in ('darwin', 'mac') and ("--disable-toolbox-glue" not in |
|---|
| 131 | n/a | sysconfig.get_config_var("CONFIG_ARGS")): |
|---|
| 132 | n/a | # Mac OS X also includes some mac-specific modules |
|---|
| 133 | n/a | macmoddir = os.path.join(srcdir, 'Mac/Modules') |
|---|
| 134 | n/a | moddirlist.append(macmoddir) |
|---|
| 135 | n/a | incdirlist.append(os.path.join(srcdir, 'Mac/Include')) |
|---|
| 136 | n/a | |
|---|
| 137 | n/a | # Fix up the paths for scripts, too |
|---|
| 138 | n/a | self.distribution.scripts = [os.path.join(srcdir, filename) |
|---|
| 139 | n/a | for filename in self.distribution.scripts] |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | # Python header files |
|---|
| 142 | n/a | headers = [sysconfig.get_config_h_filename()] |
|---|
| 143 | n/a | headers += glob(os.path.join(sysconfig.get_path('platinclude'), "*.h")) |
|---|
| 144 | n/a | for ext in self.extensions[:]: |
|---|
| 145 | n/a | ext.sources = [ find_module_file(filename, moddirlist) |
|---|
| 146 | n/a | for filename in ext.sources ] |
|---|
| 147 | n/a | if ext.depends is not None: |
|---|
| 148 | n/a | ext.depends = [find_module_file(filename, moddirlist) |
|---|
| 149 | n/a | for filename in ext.depends] |
|---|
| 150 | n/a | else: |
|---|
| 151 | n/a | ext.depends = [] |
|---|
| 152 | n/a | # re-compile extensions if a header file has been changed |
|---|
| 153 | n/a | ext.depends.extend(headers) |
|---|
| 154 | n/a | |
|---|
| 155 | n/a | # platform specific include directories |
|---|
| 156 | n/a | ext.include_dirs.extend(incdirlist) |
|---|
| 157 | n/a | |
|---|
| 158 | n/a | # If a module has already been built statically, |
|---|
| 159 | n/a | # don't build it here |
|---|
| 160 | n/a | if ext.name in sys.builtin_module_names: |
|---|
| 161 | n/a | self.extensions.remove(ext) |
|---|
| 162 | n/a | |
|---|
| 163 | n/a | if platform != 'mac': |
|---|
| 164 | n/a | # Parse Modules/Setup and Modules/Setup.local to figure out which |
|---|
| 165 | n/a | # modules are turned on in the file. |
|---|
| 166 | n/a | remove_modules = [] |
|---|
| 167 | n/a | for filename in ('Modules/Setup', 'Modules/Setup.local'): |
|---|
| 168 | n/a | input = text_file.TextFile(filename, join_lines=1) |
|---|
| 169 | n/a | while 1: |
|---|
| 170 | n/a | line = input.readline() |
|---|
| 171 | n/a | if not line: break |
|---|
| 172 | n/a | line = line.split() |
|---|
| 173 | n/a | remove_modules.append(line[0]) |
|---|
| 174 | n/a | input.close() |
|---|
| 175 | n/a | |
|---|
| 176 | n/a | for ext in self.extensions[:]: |
|---|
| 177 | n/a | if ext.name in remove_modules: |
|---|
| 178 | n/a | self.extensions.remove(ext) |
|---|
| 179 | n/a | |
|---|
| 180 | n/a | # When you run "make CC=altcc" or something similar, you really want |
|---|
| 181 | n/a | # those environment variables passed into the setup.py phase. Here's |
|---|
| 182 | n/a | # a small set of useful ones. |
|---|
| 183 | n/a | compiler = os.environ.get('CC') |
|---|
| 184 | n/a | args = {} |
|---|
| 185 | n/a | # unfortunately, distutils doesn't let us provide separate C and C++ |
|---|
| 186 | n/a | # compilers |
|---|
| 187 | n/a | if compiler is not None: |
|---|
| 188 | n/a | (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') |
|---|
| 189 | n/a | args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags |
|---|
| 190 | n/a | self.compiler.set_executables(**args) |
|---|
| 191 | n/a | |
|---|
| 192 | n/a | build_ext.build_extensions(self) |
|---|
| 193 | n/a | |
|---|
| 194 | n/a | longest = max([len(e.name) for e in self.extensions]) |
|---|
| 195 | n/a | if self.failed: |
|---|
| 196 | n/a | longest = max(longest, max([len(name) for name in self.failed])) |
|---|
| 197 | n/a | |
|---|
| 198 | n/a | def print_three_column(lst): |
|---|
| 199 | n/a | lst.sort(key=str.lower) |
|---|
| 200 | n/a | # guarantee zip() doesn't drop anything |
|---|
| 201 | n/a | while len(lst) % 3: |
|---|
| 202 | n/a | lst.append("") |
|---|
| 203 | n/a | for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]): |
|---|
| 204 | n/a | print "%-*s %-*s %-*s" % (longest, e, longest, f, |
|---|
| 205 | n/a | longest, g) |
|---|
| 206 | n/a | |
|---|
| 207 | n/a | if missing: |
|---|
| 208 | n/a | print |
|---|
| 209 | n/a | print ("Python build finished, but the necessary bits to build " |
|---|
| 210 | n/a | "these modules were not found:") |
|---|
| 211 | n/a | print_three_column(missing) |
|---|
| 212 | n/a | print ("To find the necessary bits, look in setup.py in" |
|---|
| 213 | n/a | " detect_modules() for the module's name.") |
|---|
| 214 | n/a | print |
|---|
| 215 | n/a | |
|---|
| 216 | n/a | if self.failed: |
|---|
| 217 | n/a | failed = self.failed[:] |
|---|
| 218 | n/a | print |
|---|
| 219 | n/a | print "Failed to build these modules:" |
|---|
| 220 | n/a | print_three_column(failed) |
|---|
| 221 | n/a | print |
|---|
| 222 | n/a | |
|---|
| 223 | n/a | def build_extension(self, ext): |
|---|
| 224 | n/a | |
|---|
| 225 | n/a | if ext.name == '_ctypes': |
|---|
| 226 | n/a | if not self.configure_ctypes(ext): |
|---|
| 227 | n/a | return |
|---|
| 228 | n/a | |
|---|
| 229 | n/a | try: |
|---|
| 230 | n/a | build_ext.build_extension(self, ext) |
|---|
| 231 | n/a | except (CCompilerError, DistutilsError), why: |
|---|
| 232 | n/a | self.announce('WARNING: building of extension "%s" failed: %s' % |
|---|
| 233 | n/a | (ext.name, sys.exc_info()[1])) |
|---|
| 234 | n/a | self.failed.append(ext.name) |
|---|
| 235 | n/a | return |
|---|
| 236 | n/a | # Workaround for Mac OS X: The Carbon-based modules cannot be |
|---|
| 237 | n/a | # reliably imported into a command-line Python |
|---|
| 238 | n/a | if 'Carbon' in ext.extra_link_args: |
|---|
| 239 | n/a | self.announce( |
|---|
| 240 | n/a | 'WARNING: skipping import check for Carbon-based "%s"' % |
|---|
| 241 | n/a | ext.name) |
|---|
| 242 | n/a | return |
|---|
| 243 | n/a | |
|---|
| 244 | n/a | if self.get_platform() == 'darwin' and ( |
|---|
| 245 | n/a | sys.maxint > 2**32 and '-arch' in ext.extra_link_args): |
|---|
| 246 | n/a | # Don't bother doing an import check when an extension was |
|---|
| 247 | n/a | # build with an explicit '-arch' flag on OSX. That's currently |
|---|
| 248 | n/a | # only used to build 32-bit only extensions in a 4-way |
|---|
| 249 | n/a | # universal build and loading 32-bit code into a 64-bit |
|---|
| 250 | n/a | # process will fail. |
|---|
| 251 | n/a | self.announce( |
|---|
| 252 | n/a | 'WARNING: skipping import check for "%s"' % |
|---|
| 253 | n/a | ext.name) |
|---|
| 254 | n/a | return |
|---|
| 255 | n/a | |
|---|
| 256 | n/a | # Workaround for Cygwin: Cygwin currently has fork issues when many |
|---|
| 257 | n/a | # modules have been imported |
|---|
| 258 | n/a | if self.get_platform() == 'cygwin': |
|---|
| 259 | n/a | self.announce('WARNING: skipping import check for Cygwin-based "%s"' |
|---|
| 260 | n/a | % ext.name) |
|---|
| 261 | n/a | return |
|---|
| 262 | n/a | ext_filename = os.path.join( |
|---|
| 263 | n/a | self.build_lib, |
|---|
| 264 | n/a | self.get_ext_filename(self.get_ext_fullname(ext.name))) |
|---|
| 265 | n/a | try: |
|---|
| 266 | n/a | imp.load_dynamic(ext.name, ext_filename) |
|---|
| 267 | n/a | except ImportError, why: |
|---|
| 268 | n/a | self.failed.append(ext.name) |
|---|
| 269 | n/a | self.announce('*** WARNING: renaming "%s" since importing it' |
|---|
| 270 | n/a | ' failed: %s' % (ext.name, why), level=3) |
|---|
| 271 | n/a | assert not self.inplace |
|---|
| 272 | n/a | basename, tail = os.path.splitext(ext_filename) |
|---|
| 273 | n/a | newname = basename + "_failed" + tail |
|---|
| 274 | n/a | if os.path.exists(newname): |
|---|
| 275 | n/a | os.remove(newname) |
|---|
| 276 | n/a | os.rename(ext_filename, newname) |
|---|
| 277 | n/a | |
|---|
| 278 | n/a | # XXX -- This relies on a Vile HACK in |
|---|
| 279 | n/a | # distutils.command.build_ext.build_extension(). The |
|---|
| 280 | n/a | # _built_objects attribute is stored there strictly for |
|---|
| 281 | n/a | # use here. |
|---|
| 282 | n/a | # If there is a failure, _built_objects may not be there, |
|---|
| 283 | n/a | # so catch the AttributeError and move on. |
|---|
| 284 | n/a | try: |
|---|
| 285 | n/a | for filename in self._built_objects: |
|---|
| 286 | n/a | os.remove(filename) |
|---|
| 287 | n/a | except AttributeError: |
|---|
| 288 | n/a | self.announce('unable to remove files (ignored)') |
|---|
| 289 | n/a | except: |
|---|
| 290 | n/a | exc_type, why, tb = sys.exc_info() |
|---|
| 291 | n/a | self.announce('*** WARNING: importing extension "%s" ' |
|---|
| 292 | n/a | 'failed with %s: %s' % (ext.name, exc_type, why), |
|---|
| 293 | n/a | level=3) |
|---|
| 294 | n/a | self.failed.append(ext.name) |
|---|
| 295 | n/a | |
|---|
| 296 | n/a | def get_platform(self): |
|---|
| 297 | n/a | # Get value of sys.platform |
|---|
| 298 | n/a | for platform in ['cygwin', 'beos', 'darwin', 'atheos', 'osf1']: |
|---|
| 299 | n/a | if sys.platform.startswith(platform): |
|---|
| 300 | n/a | return platform |
|---|
| 301 | n/a | return sys.platform |
|---|
| 302 | n/a | |
|---|
| 303 | n/a | def detect_modules(self): |
|---|
| 304 | n/a | # Ensure that /usr/local is always used |
|---|
| 305 | n/a | add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') |
|---|
| 306 | n/a | add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') |
|---|
| 307 | n/a | |
|---|
| 308 | n/a | # Add paths specified in the environment variables LDFLAGS and |
|---|
| 309 | n/a | # CPPFLAGS for header and library files. |
|---|
| 310 | n/a | # We must get the values from the Makefile and not the environment |
|---|
| 311 | n/a | # directly since an inconsistently reproducible issue comes up where |
|---|
| 312 | n/a | # the environment variable is not set even though the value were passed |
|---|
| 313 | n/a | # into configure and stored in the Makefile (issue found on OS X 10.3). |
|---|
| 314 | n/a | for env_var, arg_name, dir_list in ( |
|---|
| 315 | n/a | ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), |
|---|
| 316 | n/a | ('LDFLAGS', '-L', self.compiler.library_dirs), |
|---|
| 317 | n/a | ('CPPFLAGS', '-I', self.compiler.include_dirs)): |
|---|
| 318 | n/a | env_val = sysconfig.get_config_var(env_var) |
|---|
| 319 | n/a | if env_val: |
|---|
| 320 | n/a | # To prevent optparse from raising an exception about any |
|---|
| 321 | n/a | # options in env_val that it doesn't know about we strip out |
|---|
| 322 | n/a | # all double dashes and any dashes followed by a character |
|---|
| 323 | n/a | # that is not for the option we are dealing with. |
|---|
| 324 | n/a | # |
|---|
| 325 | n/a | # Please note that order of the regex is important! We must |
|---|
| 326 | n/a | # strip out double-dashes first so that we don't end up with |
|---|
| 327 | n/a | # substituting "--Long" to "-Long" and thus lead to "ong" being |
|---|
| 328 | n/a | # used for a library directory. |
|---|
| 329 | n/a | env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], |
|---|
| 330 | n/a | ' ', env_val) |
|---|
| 331 | n/a | parser = optparse.OptionParser() |
|---|
| 332 | n/a | # Make sure that allowing args interspersed with options is |
|---|
| 333 | n/a | # allowed |
|---|
| 334 | n/a | parser.allow_interspersed_args = True |
|---|
| 335 | n/a | parser.error = lambda msg: None |
|---|
| 336 | n/a | parser.add_option(arg_name, dest="dirs", action="append") |
|---|
| 337 | n/a | options = parser.parse_args(env_val.split())[0] |
|---|
| 338 | n/a | if options.dirs: |
|---|
| 339 | n/a | for directory in reversed(options.dirs): |
|---|
| 340 | n/a | add_dir_to_list(dir_list, directory) |
|---|
| 341 | n/a | |
|---|
| 342 | n/a | if os.path.normpath(sys.prefix) != '/usr': |
|---|
| 343 | n/a | add_dir_to_list(self.compiler.library_dirs, |
|---|
| 344 | n/a | sysconfig.get_config_var("LIBDIR")) |
|---|
| 345 | n/a | add_dir_to_list(self.compiler.include_dirs, |
|---|
| 346 | n/a | sysconfig.get_config_var("INCLUDEDIR")) |
|---|
| 347 | n/a | |
|---|
| 348 | n/a | try: |
|---|
| 349 | n/a | have_unicode = unicode |
|---|
| 350 | n/a | except NameError: |
|---|
| 351 | n/a | have_unicode = 0 |
|---|
| 352 | n/a | |
|---|
| 353 | n/a | # lib_dirs and inc_dirs are used to search for files; |
|---|
| 354 | n/a | # if a file is found in one of those directories, it can |
|---|
| 355 | n/a | # be assumed that no additional -I,-L directives are needed. |
|---|
| 356 | n/a | lib_dirs = self.compiler.library_dirs + [ |
|---|
| 357 | n/a | '/lib64', '/usr/lib64', |
|---|
| 358 | n/a | '/lib', '/usr/lib', |
|---|
| 359 | n/a | ] |
|---|
| 360 | n/a | inc_dirs = self.compiler.include_dirs + ['/usr/include'] |
|---|
| 361 | n/a | exts = [] |
|---|
| 362 | n/a | missing = [] |
|---|
| 363 | n/a | |
|---|
| 364 | n/a | config_h = sysconfig.get_config_h_filename() |
|---|
| 365 | n/a | config_h_vars = sysconfig.parse_config_h(open(config_h)) |
|---|
| 366 | n/a | |
|---|
| 367 | n/a | platform = self.get_platform() |
|---|
| 368 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 369 | n/a | |
|---|
| 370 | n/a | # Check for AtheOS which has libraries in non-standard locations |
|---|
| 371 | n/a | if platform == 'atheos': |
|---|
| 372 | n/a | lib_dirs += ['/system/libs', '/atheos/autolnk/lib'] |
|---|
| 373 | n/a | lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep) |
|---|
| 374 | n/a | inc_dirs += ['/system/include', '/atheos/autolnk/include'] |
|---|
| 375 | n/a | inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep) |
|---|
| 376 | n/a | |
|---|
| 377 | n/a | # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) |
|---|
| 378 | n/a | if platform in ['osf1', 'unixware7', 'openunix8']: |
|---|
| 379 | n/a | lib_dirs += ['/usr/ccs/lib'] |
|---|
| 380 | n/a | |
|---|
| 381 | n/a | if platform == 'darwin': |
|---|
| 382 | n/a | # This should work on any unixy platform ;-) |
|---|
| 383 | n/a | # If the user has bothered specifying additional -I and -L flags |
|---|
| 384 | n/a | # in OPT and LDFLAGS we might as well use them here. |
|---|
| 385 | n/a | # NOTE: using shlex.split would technically be more correct, but |
|---|
| 386 | n/a | # also gives a bootstrap problem. Let's hope nobody uses directories |
|---|
| 387 | n/a | # with whitespace in the name to store libraries. |
|---|
| 388 | n/a | cflags, ldflags = sysconfig.get_config_vars( |
|---|
| 389 | n/a | 'CFLAGS', 'LDFLAGS') |
|---|
| 390 | n/a | for item in cflags.split(): |
|---|
| 391 | n/a | if item.startswith('-I'): |
|---|
| 392 | n/a | inc_dirs.append(item[2:]) |
|---|
| 393 | n/a | |
|---|
| 394 | n/a | for item in ldflags.split(): |
|---|
| 395 | n/a | if item.startswith('-L'): |
|---|
| 396 | n/a | lib_dirs.append(item[2:]) |
|---|
| 397 | n/a | |
|---|
| 398 | n/a | # Check for MacOS X, which doesn't need libm.a at all |
|---|
| 399 | n/a | math_libs = ['m'] |
|---|
| 400 | n/a | if platform in ['darwin', 'beos', 'mac']: |
|---|
| 401 | n/a | math_libs = [] |
|---|
| 402 | n/a | |
|---|
| 403 | n/a | # XXX Omitted modules: gl, pure, dl, SGI-specific modules |
|---|
| 404 | n/a | |
|---|
| 405 | n/a | # |
|---|
| 406 | n/a | # The following modules are all pretty straightforward, and compile |
|---|
| 407 | n/a | # on pretty much any POSIXish platform. |
|---|
| 408 | n/a | # |
|---|
| 409 | n/a | |
|---|
| 410 | n/a | # Some modules that are normally always on: |
|---|
| 411 | n/a | exts.append( Extension('_weakref', ['_weakref.c']) ) |
|---|
| 412 | n/a | |
|---|
| 413 | n/a | # array objects |
|---|
| 414 | n/a | exts.append( Extension('array', ['arraymodule.c']) ) |
|---|
| 415 | n/a | # complex math library functions |
|---|
| 416 | n/a | exts.append( Extension('cmath', ['cmathmodule.c', '_math.c'], |
|---|
| 417 | n/a | depends=['_math.h'], |
|---|
| 418 | n/a | libraries=math_libs) ) |
|---|
| 419 | n/a | # math library functions, e.g. sin() |
|---|
| 420 | n/a | exts.append( Extension('math', ['mathmodule.c', '_math.c'], |
|---|
| 421 | n/a | depends=['_math.h'], |
|---|
| 422 | n/a | libraries=math_libs) ) |
|---|
| 423 | n/a | # fast string operations implemented in C |
|---|
| 424 | n/a | exts.append( Extension('strop', ['stropmodule.c']) ) |
|---|
| 425 | n/a | # time operations and variables |
|---|
| 426 | n/a | exts.append( Extension('time', ['timemodule.c'], |
|---|
| 427 | n/a | libraries=math_libs) ) |
|---|
| 428 | n/a | exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'], |
|---|
| 429 | n/a | libraries=math_libs) ) |
|---|
| 430 | n/a | # fast iterator tools implemented in C |
|---|
| 431 | n/a | exts.append( Extension("itertools", ["itertoolsmodule.c"]) ) |
|---|
| 432 | n/a | # code that will be builtins in the future, but conflict with the |
|---|
| 433 | n/a | # current builtins |
|---|
| 434 | n/a | exts.append( Extension('future_builtins', ['future_builtins.c']) ) |
|---|
| 435 | n/a | # random number generator implemented in C |
|---|
| 436 | n/a | exts.append( Extension("_random", ["_randommodule.c"]) ) |
|---|
| 437 | n/a | # high-performance collections |
|---|
| 438 | n/a | exts.append( Extension("_collections", ["_collectionsmodule.c"]) ) |
|---|
| 439 | n/a | # bisect |
|---|
| 440 | n/a | exts.append( Extension("_bisect", ["_bisectmodule.c"]) ) |
|---|
| 441 | n/a | # heapq |
|---|
| 442 | n/a | exts.append( Extension("_heapq", ["_heapqmodule.c"]) ) |
|---|
| 443 | n/a | # operator.add() and similar goodies |
|---|
| 444 | n/a | exts.append( Extension('operator', ['operator.c']) ) |
|---|
| 445 | n/a | # Python 3.1 _io library |
|---|
| 446 | n/a | exts.append( Extension("_io", |
|---|
| 447 | n/a | ["_io/bufferedio.c", "_io/bytesio.c", "_io/fileio.c", |
|---|
| 448 | n/a | "_io/iobase.c", "_io/_iomodule.c", "_io/stringio.c", "_io/textio.c"], |
|---|
| 449 | n/a | depends=["_io/_iomodule.h"], include_dirs=["Modules/_io"])) |
|---|
| 450 | n/a | # _functools |
|---|
| 451 | n/a | exts.append( Extension("_functools", ["_functoolsmodule.c"]) ) |
|---|
| 452 | n/a | # _json speedups |
|---|
| 453 | n/a | exts.append( Extension("_json", ["_json.c"]) ) |
|---|
| 454 | n/a | # Python C API test module |
|---|
| 455 | n/a | exts.append( Extension('_testcapi', ['_testcapimodule.c'], |
|---|
| 456 | n/a | depends=['testcapi_long.h']) ) |
|---|
| 457 | n/a | # profilers (_lsprof is for cProfile.py) |
|---|
| 458 | n/a | exts.append( Extension('_hotshot', ['_hotshot.c']) ) |
|---|
| 459 | n/a | exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) ) |
|---|
| 460 | n/a | # static Unicode character database |
|---|
| 461 | n/a | if have_unicode: |
|---|
| 462 | n/a | exts.append( Extension('unicodedata', ['unicodedata.c']) ) |
|---|
| 463 | n/a | else: |
|---|
| 464 | n/a | missing.append('unicodedata') |
|---|
| 465 | n/a | # access to ISO C locale support |
|---|
| 466 | n/a | data = open('pyconfig.h').read() |
|---|
| 467 | n/a | m = re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*", data) |
|---|
| 468 | n/a | if m is not None: |
|---|
| 469 | n/a | locale_libs = ['intl'] |
|---|
| 470 | n/a | else: |
|---|
| 471 | n/a | locale_libs = [] |
|---|
| 472 | n/a | if platform == 'darwin': |
|---|
| 473 | n/a | locale_extra_link_args = ['-framework', 'CoreFoundation'] |
|---|
| 474 | n/a | else: |
|---|
| 475 | n/a | locale_extra_link_args = [] |
|---|
| 476 | n/a | |
|---|
| 477 | n/a | |
|---|
| 478 | n/a | exts.append( Extension('_locale', ['_localemodule.c'], |
|---|
| 479 | n/a | libraries=locale_libs, |
|---|
| 480 | n/a | extra_link_args=locale_extra_link_args) ) |
|---|
| 481 | n/a | |
|---|
| 482 | n/a | # Modules with some UNIX dependencies -- on by default: |
|---|
| 483 | n/a | # (If you have a really backward UNIX, select and socket may not be |
|---|
| 484 | n/a | # supported...) |
|---|
| 485 | n/a | |
|---|
| 486 | n/a | # fcntl(2) and ioctl(2) |
|---|
| 487 | n/a | exts.append( Extension('fcntl', ['fcntlmodule.c']) ) |
|---|
| 488 | n/a | if platform not in ['mac']: |
|---|
| 489 | n/a | # pwd(3) |
|---|
| 490 | n/a | exts.append( Extension('pwd', ['pwdmodule.c']) ) |
|---|
| 491 | n/a | # grp(3) |
|---|
| 492 | n/a | exts.append( Extension('grp', ['grpmodule.c']) ) |
|---|
| 493 | n/a | # spwd, shadow passwords |
|---|
| 494 | n/a | if (config_h_vars.get('HAVE_GETSPNAM', False) or |
|---|
| 495 | n/a | config_h_vars.get('HAVE_GETSPENT', False)): |
|---|
| 496 | n/a | exts.append( Extension('spwd', ['spwdmodule.c']) ) |
|---|
| 497 | n/a | else: |
|---|
| 498 | n/a | missing.append('spwd') |
|---|
| 499 | n/a | else: |
|---|
| 500 | n/a | missing.extend(['pwd', 'grp', 'spwd']) |
|---|
| 501 | n/a | |
|---|
| 502 | n/a | # select(2); not on ancient System V |
|---|
| 503 | n/a | exts.append( Extension('select', ['selectmodule.c']) ) |
|---|
| 504 | n/a | |
|---|
| 505 | n/a | # Fred Drake's interface to the Python parser |
|---|
| 506 | n/a | exts.append( Extension('parser', ['parsermodule.c']) ) |
|---|
| 507 | n/a | |
|---|
| 508 | n/a | # cStringIO and cPickle |
|---|
| 509 | n/a | exts.append( Extension('cStringIO', ['cStringIO.c']) ) |
|---|
| 510 | n/a | exts.append( Extension('cPickle', ['cPickle.c']) ) |
|---|
| 511 | n/a | |
|---|
| 512 | n/a | # Memory-mapped files (also works on Win32). |
|---|
| 513 | n/a | if platform not in ['atheos', 'mac']: |
|---|
| 514 | n/a | exts.append( Extension('mmap', ['mmapmodule.c']) ) |
|---|
| 515 | n/a | else: |
|---|
| 516 | n/a | missing.append('mmap') |
|---|
| 517 | n/a | |
|---|
| 518 | n/a | # Lance Ellinghaus's syslog module |
|---|
| 519 | n/a | if platform not in ['mac']: |
|---|
| 520 | n/a | # syslog daemon interface |
|---|
| 521 | n/a | exts.append( Extension('syslog', ['syslogmodule.c']) ) |
|---|
| 522 | n/a | else: |
|---|
| 523 | n/a | missing.append('syslog') |
|---|
| 524 | n/a | |
|---|
| 525 | n/a | # George Neville-Neil's timing module: |
|---|
| 526 | n/a | # Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html |
|---|
| 527 | n/a | # http://mail.python.org/pipermail/python-dev/2006-January/060023.html |
|---|
| 528 | n/a | #exts.append( Extension('timing', ['timingmodule.c']) ) |
|---|
| 529 | n/a | |
|---|
| 530 | n/a | # |
|---|
| 531 | n/a | # Here ends the simple stuff. From here on, modules need certain |
|---|
| 532 | n/a | # libraries, are platform-specific, or present other surprises. |
|---|
| 533 | n/a | # |
|---|
| 534 | n/a | |
|---|
| 535 | n/a | # Multimedia modules |
|---|
| 536 | n/a | # These don't work for 64-bit platforms!!! |
|---|
| 537 | n/a | # These represent audio samples or images as strings: |
|---|
| 538 | n/a | |
|---|
| 539 | n/a | # Operations on audio samples |
|---|
| 540 | n/a | # According to #993173, this one should actually work fine on |
|---|
| 541 | n/a | # 64-bit platforms. |
|---|
| 542 | n/a | exts.append( Extension('audioop', ['audioop.c']) ) |
|---|
| 543 | n/a | |
|---|
| 544 | n/a | # Disabled on 64-bit platforms |
|---|
| 545 | n/a | if sys.maxint != 9223372036854775807L: |
|---|
| 546 | n/a | # Operations on images |
|---|
| 547 | n/a | exts.append( Extension('imageop', ['imageop.c']) ) |
|---|
| 548 | n/a | else: |
|---|
| 549 | n/a | missing.extend(['imageop']) |
|---|
| 550 | n/a | |
|---|
| 551 | n/a | # readline |
|---|
| 552 | n/a | do_readline = self.compiler.find_library_file(lib_dirs, 'readline') |
|---|
| 553 | n/a | if platform == 'darwin': |
|---|
| 554 | n/a | os_release = int(os.uname()[2].split('.')[0]) |
|---|
| 555 | n/a | dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') |
|---|
| 556 | n/a | if dep_target and dep_target.split('.') < ['10', '5']: |
|---|
| 557 | n/a | os_release = 8 |
|---|
| 558 | n/a | if os_release < 9: |
|---|
| 559 | n/a | # MacOSX 10.4 has a broken readline. Don't try to build |
|---|
| 560 | n/a | # the readline module unless the user has installed a fixed |
|---|
| 561 | n/a | # readline package |
|---|
| 562 | n/a | if find_file('readline/rlconf.h', inc_dirs, []) is None: |
|---|
| 563 | n/a | do_readline = False |
|---|
| 564 | n/a | if do_readline: |
|---|
| 565 | n/a | if platform == 'darwin' and os_release < 9: |
|---|
| 566 | n/a | # In every directory on the search path search for a dynamic |
|---|
| 567 | n/a | # library and then a static library, instead of first looking |
|---|
| 568 | n/a | # for dynamic libraries on the entiry path. |
|---|
| 569 | n/a | # This way a staticly linked custom readline gets picked up |
|---|
| 570 | n/a | # before the (broken) dynamic library in /usr/lib. |
|---|
| 571 | n/a | readline_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 572 | n/a | else: |
|---|
| 573 | n/a | readline_extra_link_args = () |
|---|
| 574 | n/a | |
|---|
| 575 | n/a | readline_libs = ['readline'] |
|---|
| 576 | n/a | if self.compiler.find_library_file(lib_dirs, |
|---|
| 577 | n/a | 'ncursesw'): |
|---|
| 578 | n/a | readline_libs.append('ncursesw') |
|---|
| 579 | n/a | elif self.compiler.find_library_file(lib_dirs, |
|---|
| 580 | n/a | 'ncurses'): |
|---|
| 581 | n/a | readline_libs.append('ncurses') |
|---|
| 582 | n/a | elif self.compiler.find_library_file(lib_dirs, 'curses'): |
|---|
| 583 | n/a | readline_libs.append('curses') |
|---|
| 584 | n/a | elif self.compiler.find_library_file(lib_dirs + |
|---|
| 585 | n/a | ['/usr/lib/termcap'], |
|---|
| 586 | n/a | 'termcap'): |
|---|
| 587 | n/a | readline_libs.append('termcap') |
|---|
| 588 | n/a | exts.append( Extension('readline', ['readline.c'], |
|---|
| 589 | n/a | library_dirs=['/usr/lib/termcap'], |
|---|
| 590 | n/a | extra_link_args=readline_extra_link_args, |
|---|
| 591 | n/a | libraries=readline_libs) ) |
|---|
| 592 | n/a | else: |
|---|
| 593 | n/a | missing.append('readline') |
|---|
| 594 | n/a | |
|---|
| 595 | n/a | if platform not in ['mac']: |
|---|
| 596 | n/a | # crypt module. |
|---|
| 597 | n/a | |
|---|
| 598 | n/a | if self.compiler.find_library_file(lib_dirs, 'crypt'): |
|---|
| 599 | n/a | libs = ['crypt'] |
|---|
| 600 | n/a | else: |
|---|
| 601 | n/a | libs = [] |
|---|
| 602 | n/a | exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) ) |
|---|
| 603 | n/a | else: |
|---|
| 604 | n/a | missing.append('crypt') |
|---|
| 605 | n/a | |
|---|
| 606 | n/a | # CSV files |
|---|
| 607 | n/a | exts.append( Extension('_csv', ['_csv.c']) ) |
|---|
| 608 | n/a | |
|---|
| 609 | n/a | # socket(2) |
|---|
| 610 | n/a | exts.append( Extension('_socket', ['socketmodule.c'], |
|---|
| 611 | n/a | depends = ['socketmodule.h']) ) |
|---|
| 612 | n/a | # Detect SSL support for the socket module (via _ssl) |
|---|
| 613 | n/a | search_for_ssl_incs_in = [ |
|---|
| 614 | n/a | '/usr/local/ssl/include', |
|---|
| 615 | n/a | '/usr/contrib/ssl/include/' |
|---|
| 616 | n/a | ] |
|---|
| 617 | n/a | ssl_incs = find_file('openssl/ssl.h', inc_dirs, |
|---|
| 618 | n/a | search_for_ssl_incs_in |
|---|
| 619 | n/a | ) |
|---|
| 620 | n/a | if ssl_incs is not None: |
|---|
| 621 | n/a | krb5_h = find_file('krb5.h', inc_dirs, |
|---|
| 622 | n/a | ['/usr/kerberos/include']) |
|---|
| 623 | n/a | if krb5_h: |
|---|
| 624 | n/a | ssl_incs += krb5_h |
|---|
| 625 | n/a | ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, |
|---|
| 626 | n/a | ['/usr/local/ssl/lib', |
|---|
| 627 | n/a | '/usr/contrib/ssl/lib/' |
|---|
| 628 | n/a | ] ) |
|---|
| 629 | n/a | |
|---|
| 630 | n/a | if (ssl_incs is not None and |
|---|
| 631 | n/a | ssl_libs is not None): |
|---|
| 632 | n/a | exts.append( Extension('_ssl', ['_ssl.c'], |
|---|
| 633 | n/a | include_dirs = ssl_incs, |
|---|
| 634 | n/a | library_dirs = ssl_libs, |
|---|
| 635 | n/a | libraries = ['ssl', 'crypto'], |
|---|
| 636 | n/a | depends = ['socketmodule.h']), ) |
|---|
| 637 | n/a | else: |
|---|
| 638 | n/a | missing.append('_ssl') |
|---|
| 639 | n/a | |
|---|
| 640 | n/a | # find out which version of OpenSSL we have |
|---|
| 641 | n/a | openssl_ver = 0 |
|---|
| 642 | n/a | openssl_ver_re = re.compile( |
|---|
| 643 | n/a | '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' ) |
|---|
| 644 | n/a | for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in: |
|---|
| 645 | n/a | name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h') |
|---|
| 646 | n/a | if os.path.isfile(name): |
|---|
| 647 | n/a | try: |
|---|
| 648 | n/a | incfile = open(name, 'r') |
|---|
| 649 | n/a | for line in incfile: |
|---|
| 650 | n/a | m = openssl_ver_re.match(line) |
|---|
| 651 | n/a | if m: |
|---|
| 652 | n/a | openssl_ver = eval(m.group(1)) |
|---|
| 653 | n/a | break |
|---|
| 654 | n/a | except IOError: |
|---|
| 655 | n/a | pass |
|---|
| 656 | n/a | |
|---|
| 657 | n/a | # first version found is what we'll use (as the compiler should) |
|---|
| 658 | n/a | if openssl_ver: |
|---|
| 659 | n/a | break |
|---|
| 660 | n/a | |
|---|
| 661 | n/a | #print 'openssl_ver = 0x%08x' % openssl_ver |
|---|
| 662 | n/a | min_openssl_ver = 0x00907000 |
|---|
| 663 | n/a | have_any_openssl = ssl_incs is not None and ssl_libs is not None |
|---|
| 664 | n/a | have_usable_openssl = (have_any_openssl and |
|---|
| 665 | n/a | openssl_ver >= min_openssl_ver) |
|---|
| 666 | n/a | |
|---|
| 667 | n/a | if have_any_openssl: |
|---|
| 668 | n/a | if have_usable_openssl: |
|---|
| 669 | n/a | # The _hashlib module wraps optimized implementations |
|---|
| 670 | n/a | # of hash functions from the OpenSSL library. |
|---|
| 671 | n/a | exts.append( Extension('_hashlib', ['_hashopenssl.c'], |
|---|
| 672 | n/a | include_dirs = ssl_incs, |
|---|
| 673 | n/a | library_dirs = ssl_libs, |
|---|
| 674 | n/a | libraries = ['ssl', 'crypto']) ) |
|---|
| 675 | n/a | else: |
|---|
| 676 | n/a | print ("warning: openssl 0x%08x is too old for _hashlib" % |
|---|
| 677 | n/a | openssl_ver) |
|---|
| 678 | n/a | missing.append('_hashlib') |
|---|
| 679 | n/a | if COMPILED_WITH_PYDEBUG or not have_usable_openssl: |
|---|
| 680 | n/a | # The _sha module implements the SHA1 hash algorithm. |
|---|
| 681 | n/a | exts.append( Extension('_sha', ['shamodule.c']) ) |
|---|
| 682 | n/a | # The _md5 module implements the RSA Data Security, Inc. MD5 |
|---|
| 683 | n/a | # Message-Digest Algorithm, described in RFC 1321. The |
|---|
| 684 | n/a | # necessary files md5.c and md5.h are included here. |
|---|
| 685 | n/a | exts.append( Extension('_md5', |
|---|
| 686 | n/a | sources = ['md5module.c', 'md5.c'], |
|---|
| 687 | n/a | depends = ['md5.h']) ) |
|---|
| 688 | n/a | |
|---|
| 689 | n/a | min_sha2_openssl_ver = 0x00908000 |
|---|
| 690 | n/a | if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver: |
|---|
| 691 | n/a | # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash |
|---|
| 692 | n/a | exts.append( Extension('_sha256', ['sha256module.c']) ) |
|---|
| 693 | n/a | exts.append( Extension('_sha512', ['sha512module.c']) ) |
|---|
| 694 | n/a | |
|---|
| 695 | n/a | # Modules that provide persistent dictionary-like semantics. You will |
|---|
| 696 | n/a | # probably want to arrange for at least one of them to be available on |
|---|
| 697 | n/a | # your machine, though none are defined by default because of library |
|---|
| 698 | n/a | # dependencies. The Python module anydbm.py provides an |
|---|
| 699 | n/a | # implementation independent wrapper for these; dumbdbm.py provides |
|---|
| 700 | n/a | # similar functionality (but slower of course) implemented in Python. |
|---|
| 701 | n/a | |
|---|
| 702 | n/a | # Sleepycat^WOracle Berkeley DB interface. |
|---|
| 703 | n/a | # http://www.oracle.com/database/berkeley-db/db/index.html |
|---|
| 704 | n/a | # |
|---|
| 705 | n/a | # This requires the Sleepycat^WOracle DB code. The supported versions |
|---|
| 706 | n/a | # are set below. Visit the URL above to download |
|---|
| 707 | n/a | # a release. Most open source OSes come with one or more |
|---|
| 708 | n/a | # versions of BerkeleyDB already installed. |
|---|
| 709 | n/a | |
|---|
| 710 | n/a | max_db_ver = (4, 7) |
|---|
| 711 | n/a | min_db_ver = (3, 3) |
|---|
| 712 | n/a | db_setup_debug = False # verbose debug prints from this script? |
|---|
| 713 | n/a | |
|---|
| 714 | n/a | def allow_db_ver(db_ver): |
|---|
| 715 | n/a | """Returns a boolean if the given BerkeleyDB version is acceptable. |
|---|
| 716 | n/a | |
|---|
| 717 | n/a | Args: |
|---|
| 718 | n/a | db_ver: A tuple of the version to verify. |
|---|
| 719 | n/a | """ |
|---|
| 720 | n/a | if not (min_db_ver <= db_ver <= max_db_ver): |
|---|
| 721 | n/a | return False |
|---|
| 722 | n/a | # Use this function to filter out known bad configurations. |
|---|
| 723 | n/a | if (4, 6) == db_ver[:2]: |
|---|
| 724 | n/a | # BerkeleyDB 4.6.x is not stable on many architectures. |
|---|
| 725 | n/a | arch = platform_machine() |
|---|
| 726 | n/a | if arch not in ('i386', 'i486', 'i586', 'i686', |
|---|
| 727 | n/a | 'x86_64', 'ia64'): |
|---|
| 728 | n/a | return False |
|---|
| 729 | n/a | return True |
|---|
| 730 | n/a | |
|---|
| 731 | n/a | def gen_db_minor_ver_nums(major): |
|---|
| 732 | n/a | if major == 4: |
|---|
| 733 | n/a | for x in range(max_db_ver[1]+1): |
|---|
| 734 | n/a | if allow_db_ver((4, x)): |
|---|
| 735 | n/a | yield x |
|---|
| 736 | n/a | elif major == 3: |
|---|
| 737 | n/a | for x in (3,): |
|---|
| 738 | n/a | if allow_db_ver((3, x)): |
|---|
| 739 | n/a | yield x |
|---|
| 740 | n/a | else: |
|---|
| 741 | n/a | raise ValueError("unknown major BerkeleyDB version", major) |
|---|
| 742 | n/a | |
|---|
| 743 | n/a | # construct a list of paths to look for the header file in on |
|---|
| 744 | n/a | # top of the normal inc_dirs. |
|---|
| 745 | n/a | db_inc_paths = [ |
|---|
| 746 | n/a | '/usr/include/db4', |
|---|
| 747 | n/a | '/usr/local/include/db4', |
|---|
| 748 | n/a | '/opt/sfw/include/db4', |
|---|
| 749 | n/a | '/usr/include/db3', |
|---|
| 750 | n/a | '/usr/local/include/db3', |
|---|
| 751 | n/a | '/opt/sfw/include/db3', |
|---|
| 752 | n/a | # Fink defaults (http://fink.sourceforge.net/) |
|---|
| 753 | n/a | '/sw/include/db4', |
|---|
| 754 | n/a | '/sw/include/db3', |
|---|
| 755 | n/a | ] |
|---|
| 756 | n/a | # 4.x minor number specific paths |
|---|
| 757 | n/a | for x in gen_db_minor_ver_nums(4): |
|---|
| 758 | n/a | db_inc_paths.append('/usr/include/db4%d' % x) |
|---|
| 759 | n/a | db_inc_paths.append('/usr/include/db4.%d' % x) |
|---|
| 760 | n/a | db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x) |
|---|
| 761 | n/a | db_inc_paths.append('/usr/local/include/db4%d' % x) |
|---|
| 762 | n/a | db_inc_paths.append('/pkg/db-4.%d/include' % x) |
|---|
| 763 | n/a | db_inc_paths.append('/opt/db-4.%d/include' % x) |
|---|
| 764 | n/a | # MacPorts default (http://www.macports.org/) |
|---|
| 765 | n/a | db_inc_paths.append('/opt/local/include/db4%d' % x) |
|---|
| 766 | n/a | # 3.x minor number specific paths |
|---|
| 767 | n/a | for x in gen_db_minor_ver_nums(3): |
|---|
| 768 | n/a | db_inc_paths.append('/usr/include/db3%d' % x) |
|---|
| 769 | n/a | db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x) |
|---|
| 770 | n/a | db_inc_paths.append('/usr/local/include/db3%d' % x) |
|---|
| 771 | n/a | db_inc_paths.append('/pkg/db-3.%d/include' % x) |
|---|
| 772 | n/a | db_inc_paths.append('/opt/db-3.%d/include' % x) |
|---|
| 773 | n/a | |
|---|
| 774 | n/a | # Add some common subdirectories for Sleepycat DB to the list, |
|---|
| 775 | n/a | # based on the standard include directories. This way DB3/4 gets |
|---|
| 776 | n/a | # picked up when it is installed in a non-standard prefix and |
|---|
| 777 | n/a | # the user has added that prefix into inc_dirs. |
|---|
| 778 | n/a | std_variants = [] |
|---|
| 779 | n/a | for dn in inc_dirs: |
|---|
| 780 | n/a | std_variants.append(os.path.join(dn, 'db3')) |
|---|
| 781 | n/a | std_variants.append(os.path.join(dn, 'db4')) |
|---|
| 782 | n/a | for x in gen_db_minor_ver_nums(4): |
|---|
| 783 | n/a | std_variants.append(os.path.join(dn, "db4%d"%x)) |
|---|
| 784 | n/a | std_variants.append(os.path.join(dn, "db4.%d"%x)) |
|---|
| 785 | n/a | for x in gen_db_minor_ver_nums(3): |
|---|
| 786 | n/a | std_variants.append(os.path.join(dn, "db3%d"%x)) |
|---|
| 787 | n/a | std_variants.append(os.path.join(dn, "db3.%d"%x)) |
|---|
| 788 | n/a | |
|---|
| 789 | n/a | db_inc_paths = std_variants + db_inc_paths |
|---|
| 790 | n/a | db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)] |
|---|
| 791 | n/a | |
|---|
| 792 | n/a | db_ver_inc_map = {} |
|---|
| 793 | n/a | |
|---|
| 794 | n/a | class db_found(Exception): pass |
|---|
| 795 | n/a | try: |
|---|
| 796 | n/a | # See whether there is a Sleepycat header in the standard |
|---|
| 797 | n/a | # search path. |
|---|
| 798 | n/a | for d in inc_dirs + db_inc_paths: |
|---|
| 799 | n/a | f = os.path.join(d, "db.h") |
|---|
| 800 | n/a | if db_setup_debug: print "db: looking for db.h in", f |
|---|
| 801 | n/a | if os.path.exists(f): |
|---|
| 802 | n/a | f = open(f).read() |
|---|
| 803 | n/a | m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f) |
|---|
| 804 | n/a | if m: |
|---|
| 805 | n/a | db_major = int(m.group(1)) |
|---|
| 806 | n/a | m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f) |
|---|
| 807 | n/a | db_minor = int(m.group(1)) |
|---|
| 808 | n/a | db_ver = (db_major, db_minor) |
|---|
| 809 | n/a | |
|---|
| 810 | n/a | # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug |
|---|
| 811 | n/a | if db_ver == (4, 6): |
|---|
| 812 | n/a | m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f) |
|---|
| 813 | n/a | db_patch = int(m.group(1)) |
|---|
| 814 | n/a | if db_patch < 21: |
|---|
| 815 | n/a | print "db.h:", db_ver, "patch", db_patch, |
|---|
| 816 | n/a | print "being ignored (4.6.x must be >= 4.6.21)" |
|---|
| 817 | n/a | continue |
|---|
| 818 | n/a | |
|---|
| 819 | n/a | if ( (db_ver not in db_ver_inc_map) and |
|---|
| 820 | n/a | allow_db_ver(db_ver) ): |
|---|
| 821 | n/a | # save the include directory with the db.h version |
|---|
| 822 | n/a | # (first occurrence only) |
|---|
| 823 | n/a | db_ver_inc_map[db_ver] = d |
|---|
| 824 | n/a | if db_setup_debug: |
|---|
| 825 | n/a | print "db.h: found", db_ver, "in", d |
|---|
| 826 | n/a | else: |
|---|
| 827 | n/a | # we already found a header for this library version |
|---|
| 828 | n/a | if db_setup_debug: print "db.h: ignoring", d |
|---|
| 829 | n/a | else: |
|---|
| 830 | n/a | # ignore this header, it didn't contain a version number |
|---|
| 831 | n/a | if db_setup_debug: |
|---|
| 832 | n/a | print "db.h: no version number version in", d |
|---|
| 833 | n/a | |
|---|
| 834 | n/a | db_found_vers = db_ver_inc_map.keys() |
|---|
| 835 | n/a | db_found_vers.sort() |
|---|
| 836 | n/a | |
|---|
| 837 | n/a | while db_found_vers: |
|---|
| 838 | n/a | db_ver = db_found_vers.pop() |
|---|
| 839 | n/a | db_incdir = db_ver_inc_map[db_ver] |
|---|
| 840 | n/a | |
|---|
| 841 | n/a | # check lib directories parallel to the location of the header |
|---|
| 842 | n/a | db_dirs_to_check = [ |
|---|
| 843 | n/a | db_incdir.replace("include", 'lib64'), |
|---|
| 844 | n/a | db_incdir.replace("include", 'lib'), |
|---|
| 845 | n/a | ] |
|---|
| 846 | n/a | db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check) |
|---|
| 847 | n/a | |
|---|
| 848 | n/a | # Look for a version specific db-X.Y before an ambiguoius dbX |
|---|
| 849 | n/a | # XXX should we -ever- look for a dbX name? Do any |
|---|
| 850 | n/a | # systems really not name their library by version and |
|---|
| 851 | n/a | # symlink to more general names? |
|---|
| 852 | n/a | for dblib in (('db-%d.%d' % db_ver), |
|---|
| 853 | n/a | ('db%d%d' % db_ver), |
|---|
| 854 | n/a | ('db%d' % db_ver[0])): |
|---|
| 855 | n/a | dblib_file = self.compiler.find_library_file( |
|---|
| 856 | n/a | db_dirs_to_check + lib_dirs, dblib ) |
|---|
| 857 | n/a | if dblib_file: |
|---|
| 858 | n/a | dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ] |
|---|
| 859 | n/a | raise db_found |
|---|
| 860 | n/a | else: |
|---|
| 861 | n/a | if db_setup_debug: print "db lib: ", dblib, "not found" |
|---|
| 862 | n/a | |
|---|
| 863 | n/a | except db_found: |
|---|
| 864 | n/a | if db_setup_debug: |
|---|
| 865 | n/a | print "bsddb using BerkeleyDB lib:", db_ver, dblib |
|---|
| 866 | n/a | print "bsddb lib dir:", dblib_dir, " inc dir:", db_incdir |
|---|
| 867 | n/a | db_incs = [db_incdir] |
|---|
| 868 | n/a | dblibs = [dblib] |
|---|
| 869 | n/a | # We add the runtime_library_dirs argument because the |
|---|
| 870 | n/a | # BerkeleyDB lib we're linking against often isn't in the |
|---|
| 871 | n/a | # system dynamic library search path. This is usually |
|---|
| 872 | n/a | # correct and most trouble free, but may cause problems in |
|---|
| 873 | n/a | # some unusual system configurations (e.g. the directory |
|---|
| 874 | n/a | # is on an NFS server that goes away). |
|---|
| 875 | n/a | exts.append(Extension('_bsddb', ['_bsddb.c'], |
|---|
| 876 | n/a | depends = ['bsddb.h'], |
|---|
| 877 | n/a | library_dirs=dblib_dir, |
|---|
| 878 | n/a | runtime_library_dirs=dblib_dir, |
|---|
| 879 | n/a | include_dirs=db_incs, |
|---|
| 880 | n/a | libraries=dblibs)) |
|---|
| 881 | n/a | else: |
|---|
| 882 | n/a | if db_setup_debug: print "db: no appropriate library found" |
|---|
| 883 | n/a | db_incs = None |
|---|
| 884 | n/a | dblibs = [] |
|---|
| 885 | n/a | dblib_dir = None |
|---|
| 886 | n/a | missing.append('_bsddb') |
|---|
| 887 | n/a | |
|---|
| 888 | n/a | # The sqlite interface |
|---|
| 889 | n/a | sqlite_setup_debug = False # verbose debug prints from this script? |
|---|
| 890 | n/a | |
|---|
| 891 | n/a | # We hunt for #define SQLITE_VERSION "n.n.n" |
|---|
| 892 | n/a | # We need to find >= sqlite version 3.0.8 |
|---|
| 893 | n/a | sqlite_incdir = sqlite_libdir = None |
|---|
| 894 | n/a | sqlite_inc_paths = [ '/usr/include', |
|---|
| 895 | n/a | '/usr/include/sqlite', |
|---|
| 896 | n/a | '/usr/include/sqlite3', |
|---|
| 897 | n/a | '/usr/local/include', |
|---|
| 898 | n/a | '/usr/local/include/sqlite', |
|---|
| 899 | n/a | '/usr/local/include/sqlite3', |
|---|
| 900 | n/a | ] |
|---|
| 901 | n/a | MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) |
|---|
| 902 | n/a | MIN_SQLITE_VERSION = ".".join([str(x) |
|---|
| 903 | n/a | for x in MIN_SQLITE_VERSION_NUMBER]) |
|---|
| 904 | n/a | |
|---|
| 905 | n/a | # Scan the default include directories before the SQLite specific |
|---|
| 906 | n/a | # ones. This allows one to override the copy of sqlite on OSX, |
|---|
| 907 | n/a | # where /usr/include contains an old version of sqlite. |
|---|
| 908 | n/a | for d in inc_dirs + sqlite_inc_paths: |
|---|
| 909 | n/a | f = os.path.join(d, "sqlite3.h") |
|---|
| 910 | n/a | if os.path.exists(f): |
|---|
| 911 | n/a | if sqlite_setup_debug: print "sqlite: found %s"%f |
|---|
| 912 | n/a | incf = open(f).read() |
|---|
| 913 | n/a | m = re.search( |
|---|
| 914 | n/a | r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf) |
|---|
| 915 | n/a | if m: |
|---|
| 916 | n/a | sqlite_version = m.group(1) |
|---|
| 917 | n/a | sqlite_version_tuple = tuple([int(x) |
|---|
| 918 | n/a | for x in sqlite_version.split(".")]) |
|---|
| 919 | n/a | if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: |
|---|
| 920 | n/a | # we win! |
|---|
| 921 | n/a | if sqlite_setup_debug: |
|---|
| 922 | n/a | print "%s/sqlite3.h: version %s"%(d, sqlite_version) |
|---|
| 923 | n/a | sqlite_incdir = d |
|---|
| 924 | n/a | break |
|---|
| 925 | n/a | else: |
|---|
| 926 | n/a | if sqlite_setup_debug: |
|---|
| 927 | n/a | print "%s: version %d is too old, need >= %s"%(d, |
|---|
| 928 | n/a | sqlite_version, MIN_SQLITE_VERSION) |
|---|
| 929 | n/a | elif sqlite_setup_debug: |
|---|
| 930 | n/a | print "sqlite: %s had no SQLITE_VERSION"%(f,) |
|---|
| 931 | n/a | |
|---|
| 932 | n/a | if sqlite_incdir: |
|---|
| 933 | n/a | sqlite_dirs_to_check = [ |
|---|
| 934 | n/a | os.path.join(sqlite_incdir, '..', 'lib64'), |
|---|
| 935 | n/a | os.path.join(sqlite_incdir, '..', 'lib'), |
|---|
| 936 | n/a | os.path.join(sqlite_incdir, '..', '..', 'lib64'), |
|---|
| 937 | n/a | os.path.join(sqlite_incdir, '..', '..', 'lib'), |
|---|
| 938 | n/a | ] |
|---|
| 939 | n/a | sqlite_libfile = self.compiler.find_library_file( |
|---|
| 940 | n/a | sqlite_dirs_to_check + lib_dirs, 'sqlite3') |
|---|
| 941 | n/a | if sqlite_libfile: |
|---|
| 942 | n/a | sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] |
|---|
| 943 | n/a | |
|---|
| 944 | n/a | if sqlite_incdir and sqlite_libdir: |
|---|
| 945 | n/a | sqlite_srcs = ['_sqlite/cache.c', |
|---|
| 946 | n/a | '_sqlite/connection.c', |
|---|
| 947 | n/a | '_sqlite/cursor.c', |
|---|
| 948 | n/a | '_sqlite/microprotocols.c', |
|---|
| 949 | n/a | '_sqlite/module.c', |
|---|
| 950 | n/a | '_sqlite/prepare_protocol.c', |
|---|
| 951 | n/a | '_sqlite/row.c', |
|---|
| 952 | n/a | '_sqlite/statement.c', |
|---|
| 953 | n/a | '_sqlite/util.c', ] |
|---|
| 954 | n/a | |
|---|
| 955 | n/a | sqlite_defines = [] |
|---|
| 956 | n/a | if sys.platform != "win32": |
|---|
| 957 | n/a | sqlite_defines.append(('MODULE_NAME', '"sqlite3"')) |
|---|
| 958 | n/a | else: |
|---|
| 959 | n/a | sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"')) |
|---|
| 960 | n/a | |
|---|
| 961 | n/a | # Comment this out if you want the sqlite3 module to be able to load extensions. |
|---|
| 962 | n/a | sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1")) |
|---|
| 963 | n/a | |
|---|
| 964 | n/a | if sys.platform == 'darwin': |
|---|
| 965 | n/a | # In every directory on the search path search for a dynamic |
|---|
| 966 | n/a | # library and then a static library, instead of first looking |
|---|
| 967 | n/a | # for dynamic libraries on the entiry path. |
|---|
| 968 | n/a | # This way a staticly linked custom sqlite gets picked up |
|---|
| 969 | n/a | # before the dynamic library in /usr/lib. |
|---|
| 970 | n/a | sqlite_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 971 | n/a | else: |
|---|
| 972 | n/a | sqlite_extra_link_args = () |
|---|
| 973 | n/a | |
|---|
| 974 | n/a | exts.append(Extension('_sqlite3', sqlite_srcs, |
|---|
| 975 | n/a | define_macros=sqlite_defines, |
|---|
| 976 | n/a | include_dirs=["Modules/_sqlite", |
|---|
| 977 | n/a | sqlite_incdir], |
|---|
| 978 | n/a | library_dirs=sqlite_libdir, |
|---|
| 979 | n/a | runtime_library_dirs=sqlite_libdir, |
|---|
| 980 | n/a | extra_link_args=sqlite_extra_link_args, |
|---|
| 981 | n/a | libraries=["sqlite3",])) |
|---|
| 982 | n/a | else: |
|---|
| 983 | n/a | missing.append('_sqlite3') |
|---|
| 984 | n/a | |
|---|
| 985 | n/a | # Look for Berkeley db 1.85. Note that it is built as a different |
|---|
| 986 | n/a | # module name so it can be included even when later versions are |
|---|
| 987 | n/a | # available. A very restrictive search is performed to avoid |
|---|
| 988 | n/a | # accidentally building this module with a later version of the |
|---|
| 989 | n/a | # underlying db library. May BSD-ish Unixes incorporate db 1.85 |
|---|
| 990 | n/a | # symbols into libc and place the include file in /usr/include. |
|---|
| 991 | n/a | # |
|---|
| 992 | n/a | # If the better bsddb library can be built (db_incs is defined) |
|---|
| 993 | n/a | # we do not build this one. Otherwise this build will pick up |
|---|
| 994 | n/a | # the more recent berkeleydb's db.h file first in the include path |
|---|
| 995 | n/a | # when attempting to compile and it will fail. |
|---|
| 996 | n/a | f = "/usr/include/db.h" |
|---|
| 997 | n/a | if os.path.exists(f) and not db_incs: |
|---|
| 998 | n/a | data = open(f).read() |
|---|
| 999 | n/a | m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data) |
|---|
| 1000 | n/a | if m is not None: |
|---|
| 1001 | n/a | # bingo - old version used hash file format version 2 |
|---|
| 1002 | n/a | ### XXX this should be fixed to not be platform-dependent |
|---|
| 1003 | n/a | ### but I don't have direct access to an osf1 platform and |
|---|
| 1004 | n/a | ### seemed to be muffing the search somehow |
|---|
| 1005 | n/a | libraries = platform == "osf1" and ['db'] or None |
|---|
| 1006 | n/a | if libraries is not None: |
|---|
| 1007 | n/a | exts.append(Extension('bsddb185', ['bsddbmodule.c'], |
|---|
| 1008 | n/a | libraries=libraries)) |
|---|
| 1009 | n/a | else: |
|---|
| 1010 | n/a | exts.append(Extension('bsddb185', ['bsddbmodule.c'])) |
|---|
| 1011 | n/a | else: |
|---|
| 1012 | n/a | missing.append('bsddb185') |
|---|
| 1013 | n/a | else: |
|---|
| 1014 | n/a | missing.append('bsddb185') |
|---|
| 1015 | n/a | |
|---|
| 1016 | n/a | dbm_order = ['gdbm'] |
|---|
| 1017 | n/a | # The standard Unix dbm module: |
|---|
| 1018 | n/a | if platform not in ['cygwin']: |
|---|
| 1019 | n/a | config_args = [arg.strip("'") |
|---|
| 1020 | n/a | for arg in sysconfig.get_config_var("CONFIG_ARGS").split()] |
|---|
| 1021 | n/a | dbm_args = [arg for arg in config_args |
|---|
| 1022 | n/a | if arg.startswith('--with-dbmliborder=')] |
|---|
| 1023 | n/a | if dbm_args: |
|---|
| 1024 | n/a | dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":") |
|---|
| 1025 | n/a | else: |
|---|
| 1026 | n/a | dbm_order = "ndbm:gdbm:bdb".split(":") |
|---|
| 1027 | n/a | dbmext = None |
|---|
| 1028 | n/a | for cand in dbm_order: |
|---|
| 1029 | n/a | if cand == "ndbm": |
|---|
| 1030 | n/a | if find_file("ndbm.h", inc_dirs, []) is not None: |
|---|
| 1031 | n/a | # Some systems have -lndbm, others don't |
|---|
| 1032 | n/a | if self.compiler.find_library_file(lib_dirs, |
|---|
| 1033 | n/a | 'ndbm'): |
|---|
| 1034 | n/a | ndbm_libs = ['ndbm'] |
|---|
| 1035 | n/a | else: |
|---|
| 1036 | n/a | ndbm_libs = [] |
|---|
| 1037 | n/a | print "building dbm using ndbm" |
|---|
| 1038 | n/a | dbmext = Extension('dbm', ['dbmmodule.c'], |
|---|
| 1039 | n/a | define_macros=[ |
|---|
| 1040 | n/a | ('HAVE_NDBM_H',None), |
|---|
| 1041 | n/a | ], |
|---|
| 1042 | n/a | libraries=ndbm_libs) |
|---|
| 1043 | n/a | break |
|---|
| 1044 | n/a | |
|---|
| 1045 | n/a | elif cand == "gdbm": |
|---|
| 1046 | n/a | if self.compiler.find_library_file(lib_dirs, 'gdbm'): |
|---|
| 1047 | n/a | gdbm_libs = ['gdbm'] |
|---|
| 1048 | n/a | if self.compiler.find_library_file(lib_dirs, |
|---|
| 1049 | n/a | 'gdbm_compat'): |
|---|
| 1050 | n/a | gdbm_libs.append('gdbm_compat') |
|---|
| 1051 | n/a | if find_file("gdbm/ndbm.h", inc_dirs, []) is not None: |
|---|
| 1052 | n/a | print "building dbm using gdbm" |
|---|
| 1053 | n/a | dbmext = Extension( |
|---|
| 1054 | n/a | 'dbm', ['dbmmodule.c'], |
|---|
| 1055 | n/a | define_macros=[ |
|---|
| 1056 | n/a | ('HAVE_GDBM_NDBM_H', None), |
|---|
| 1057 | n/a | ], |
|---|
| 1058 | n/a | libraries = gdbm_libs) |
|---|
| 1059 | n/a | break |
|---|
| 1060 | n/a | if find_file("gdbm-ndbm.h", inc_dirs, []) is not None: |
|---|
| 1061 | n/a | print "building dbm using gdbm" |
|---|
| 1062 | n/a | dbmext = Extension( |
|---|
| 1063 | n/a | 'dbm', ['dbmmodule.c'], |
|---|
| 1064 | n/a | define_macros=[ |
|---|
| 1065 | n/a | ('HAVE_GDBM_DASH_NDBM_H', None), |
|---|
| 1066 | n/a | ], |
|---|
| 1067 | n/a | libraries = gdbm_libs) |
|---|
| 1068 | n/a | break |
|---|
| 1069 | n/a | elif cand == "bdb": |
|---|
| 1070 | n/a | if db_incs is not None: |
|---|
| 1071 | n/a | print "building dbm using bdb" |
|---|
| 1072 | n/a | dbmext = Extension('dbm', ['dbmmodule.c'], |
|---|
| 1073 | n/a | library_dirs=dblib_dir, |
|---|
| 1074 | n/a | runtime_library_dirs=dblib_dir, |
|---|
| 1075 | n/a | include_dirs=db_incs, |
|---|
| 1076 | n/a | define_macros=[ |
|---|
| 1077 | n/a | ('HAVE_BERKDB_H', None), |
|---|
| 1078 | n/a | ('DB_DBM_HSEARCH', None), |
|---|
| 1079 | n/a | ], |
|---|
| 1080 | n/a | libraries=dblibs) |
|---|
| 1081 | n/a | break |
|---|
| 1082 | n/a | if dbmext is not None: |
|---|
| 1083 | n/a | exts.append(dbmext) |
|---|
| 1084 | n/a | else: |
|---|
| 1085 | n/a | missing.append('dbm') |
|---|
| 1086 | n/a | |
|---|
| 1087 | n/a | # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: |
|---|
| 1088 | n/a | if ('gdbm' in dbm_order and |
|---|
| 1089 | n/a | self.compiler.find_library_file(lib_dirs, 'gdbm')): |
|---|
| 1090 | n/a | exts.append( Extension('gdbm', ['gdbmmodule.c'], |
|---|
| 1091 | n/a | libraries = ['gdbm'] ) ) |
|---|
| 1092 | n/a | else: |
|---|
| 1093 | n/a | missing.append('gdbm') |
|---|
| 1094 | n/a | |
|---|
| 1095 | n/a | # Unix-only modules |
|---|
| 1096 | n/a | if platform not in ['mac', 'win32']: |
|---|
| 1097 | n/a | # Steen Lumholt's termios module |
|---|
| 1098 | n/a | exts.append( Extension('termios', ['termios.c']) ) |
|---|
| 1099 | n/a | # Jeremy Hylton's rlimit interface |
|---|
| 1100 | n/a | if platform not in ['atheos']: |
|---|
| 1101 | n/a | exts.append( Extension('resource', ['resource.c']) ) |
|---|
| 1102 | n/a | else: |
|---|
| 1103 | n/a | missing.append('resource') |
|---|
| 1104 | n/a | |
|---|
| 1105 | n/a | # Sun yellow pages. Some systems have the functions in libc. |
|---|
| 1106 | n/a | if (platform not in ['cygwin', 'atheos', 'qnx6'] and |
|---|
| 1107 | n/a | find_file('rpcsvc/yp_prot.h', inc_dirs, []) is not None): |
|---|
| 1108 | n/a | if (self.compiler.find_library_file(lib_dirs, 'nsl')): |
|---|
| 1109 | n/a | libs = ['nsl'] |
|---|
| 1110 | n/a | else: |
|---|
| 1111 | n/a | libs = [] |
|---|
| 1112 | n/a | exts.append( Extension('nis', ['nismodule.c'], |
|---|
| 1113 | n/a | libraries = libs) ) |
|---|
| 1114 | n/a | else: |
|---|
| 1115 | n/a | missing.append('nis') |
|---|
| 1116 | n/a | else: |
|---|
| 1117 | n/a | missing.extend(['nis', 'resource', 'termios']) |
|---|
| 1118 | n/a | |
|---|
| 1119 | n/a | # Curses support, requiring the System V version of curses, often |
|---|
| 1120 | n/a | # provided by the ncurses library. |
|---|
| 1121 | n/a | panel_library = 'panel' |
|---|
| 1122 | n/a | if (self.compiler.find_library_file(lib_dirs, 'ncursesw')): |
|---|
| 1123 | n/a | curses_libs = ['ncursesw'] |
|---|
| 1124 | n/a | # Bug 1464056: If _curses.so links with ncursesw, |
|---|
| 1125 | n/a | # _curses_panel.so must link with panelw. |
|---|
| 1126 | n/a | panel_library = 'panelw' |
|---|
| 1127 | n/a | exts.append( Extension('_curses', ['_cursesmodule.c'], |
|---|
| 1128 | n/a | libraries = curses_libs) ) |
|---|
| 1129 | n/a | elif (self.compiler.find_library_file(lib_dirs, 'ncurses')): |
|---|
| 1130 | n/a | curses_libs = ['ncurses'] |
|---|
| 1131 | n/a | exts.append( Extension('_curses', ['_cursesmodule.c'], |
|---|
| 1132 | n/a | libraries = curses_libs) ) |
|---|
| 1133 | n/a | elif (self.compiler.find_library_file(lib_dirs, 'curses') |
|---|
| 1134 | n/a | and platform != 'darwin'): |
|---|
| 1135 | n/a | # OSX has an old Berkeley curses, not good enough for |
|---|
| 1136 | n/a | # the _curses module. |
|---|
| 1137 | n/a | if (self.compiler.find_library_file(lib_dirs, 'terminfo')): |
|---|
| 1138 | n/a | curses_libs = ['curses', 'terminfo'] |
|---|
| 1139 | n/a | elif (self.compiler.find_library_file(lib_dirs, 'termcap')): |
|---|
| 1140 | n/a | curses_libs = ['curses', 'termcap'] |
|---|
| 1141 | n/a | else: |
|---|
| 1142 | n/a | curses_libs = ['curses'] |
|---|
| 1143 | n/a | |
|---|
| 1144 | n/a | exts.append( Extension('_curses', ['_cursesmodule.c'], |
|---|
| 1145 | n/a | libraries = curses_libs) ) |
|---|
| 1146 | n/a | else: |
|---|
| 1147 | n/a | missing.append('_curses') |
|---|
| 1148 | n/a | |
|---|
| 1149 | n/a | # If the curses module is enabled, check for the panel module |
|---|
| 1150 | n/a | if (module_enabled(exts, '_curses') and |
|---|
| 1151 | n/a | self.compiler.find_library_file(lib_dirs, panel_library)): |
|---|
| 1152 | n/a | exts.append( Extension('_curses_panel', ['_curses_panel.c'], |
|---|
| 1153 | n/a | libraries = [panel_library] + curses_libs) ) |
|---|
| 1154 | n/a | else: |
|---|
| 1155 | n/a | missing.append('_curses_panel') |
|---|
| 1156 | n/a | |
|---|
| 1157 | n/a | # Andrew Kuchling's zlib module. Note that some versions of zlib |
|---|
| 1158 | n/a | # 1.1.3 have security problems. See CERT Advisory CA-2002-07: |
|---|
| 1159 | n/a | # http://www.cert.org/advisories/CA-2002-07.html |
|---|
| 1160 | n/a | # |
|---|
| 1161 | n/a | # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to |
|---|
| 1162 | n/a | # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For |
|---|
| 1163 | n/a | # now, we still accept 1.1.3, because we think it's difficult to |
|---|
| 1164 | n/a | # exploit this in Python, and we'd rather make it RedHat's problem |
|---|
| 1165 | n/a | # than our problem <wink>. |
|---|
| 1166 | n/a | # |
|---|
| 1167 | n/a | # You can upgrade zlib to version 1.1.4 yourself by going to |
|---|
| 1168 | n/a | # http://www.gzip.org/zlib/ |
|---|
| 1169 | n/a | zlib_inc = find_file('zlib.h', [], inc_dirs) |
|---|
| 1170 | n/a | have_zlib = False |
|---|
| 1171 | n/a | if zlib_inc is not None: |
|---|
| 1172 | n/a | zlib_h = zlib_inc[0] + '/zlib.h' |
|---|
| 1173 | n/a | version = '"0.0.0"' |
|---|
| 1174 | n/a | version_req = '"1.1.3"' |
|---|
| 1175 | n/a | fp = open(zlib_h) |
|---|
| 1176 | n/a | while 1: |
|---|
| 1177 | n/a | line = fp.readline() |
|---|
| 1178 | n/a | if not line: |
|---|
| 1179 | n/a | break |
|---|
| 1180 | n/a | if line.startswith('#define ZLIB_VERSION'): |
|---|
| 1181 | n/a | version = line.split()[2] |
|---|
| 1182 | n/a | break |
|---|
| 1183 | n/a | if version >= version_req: |
|---|
| 1184 | n/a | if (self.compiler.find_library_file(lib_dirs, 'z')): |
|---|
| 1185 | n/a | if sys.platform == "darwin": |
|---|
| 1186 | n/a | zlib_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 1187 | n/a | else: |
|---|
| 1188 | n/a | zlib_extra_link_args = () |
|---|
| 1189 | n/a | exts.append( Extension('zlib', ['zlibmodule.c'], |
|---|
| 1190 | n/a | libraries = ['z'], |
|---|
| 1191 | n/a | extra_link_args = zlib_extra_link_args)) |
|---|
| 1192 | n/a | have_zlib = True |
|---|
| 1193 | n/a | else: |
|---|
| 1194 | n/a | missing.append('zlib') |
|---|
| 1195 | n/a | else: |
|---|
| 1196 | n/a | missing.append('zlib') |
|---|
| 1197 | n/a | else: |
|---|
| 1198 | n/a | missing.append('zlib') |
|---|
| 1199 | n/a | |
|---|
| 1200 | n/a | # Helper module for various ascii-encoders. Uses zlib for an optimized |
|---|
| 1201 | n/a | # crc32 if we have it. Otherwise binascii uses its own. |
|---|
| 1202 | n/a | if have_zlib: |
|---|
| 1203 | n/a | extra_compile_args = ['-DUSE_ZLIB_CRC32'] |
|---|
| 1204 | n/a | libraries = ['z'] |
|---|
| 1205 | n/a | extra_link_args = zlib_extra_link_args |
|---|
| 1206 | n/a | else: |
|---|
| 1207 | n/a | extra_compile_args = [] |
|---|
| 1208 | n/a | libraries = [] |
|---|
| 1209 | n/a | extra_link_args = [] |
|---|
| 1210 | n/a | exts.append( Extension('binascii', ['binascii.c'], |
|---|
| 1211 | n/a | extra_compile_args = extra_compile_args, |
|---|
| 1212 | n/a | libraries = libraries, |
|---|
| 1213 | n/a | extra_link_args = extra_link_args) ) |
|---|
| 1214 | n/a | |
|---|
| 1215 | n/a | # Gustavo Niemeyer's bz2 module. |
|---|
| 1216 | n/a | if (self.compiler.find_library_file(lib_dirs, 'bz2')): |
|---|
| 1217 | n/a | if sys.platform == "darwin": |
|---|
| 1218 | n/a | bz2_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 1219 | n/a | else: |
|---|
| 1220 | n/a | bz2_extra_link_args = () |
|---|
| 1221 | n/a | exts.append( Extension('bz2', ['bz2module.c'], |
|---|
| 1222 | n/a | libraries = ['bz2'], |
|---|
| 1223 | n/a | extra_link_args = bz2_extra_link_args) ) |
|---|
| 1224 | n/a | else: |
|---|
| 1225 | n/a | missing.append('bz2') |
|---|
| 1226 | n/a | |
|---|
| 1227 | n/a | # Interface to the Expat XML parser |
|---|
| 1228 | n/a | # |
|---|
| 1229 | n/a | # Expat was written by James Clark and is now maintained by a group of |
|---|
| 1230 | n/a | # developers on SourceForge; see www.libexpat.org for more information. |
|---|
| 1231 | n/a | # The pyexpat module was written by Paul Prescod after a prototype by |
|---|
| 1232 | n/a | # Jack Jansen. The Expat source is included in Modules/expat/. Usage |
|---|
| 1233 | n/a | # of a system shared libexpat.so is possible with --with-system-expat |
|---|
| 1234 | n/a | # cofigure option. |
|---|
| 1235 | n/a | # |
|---|
| 1236 | n/a | # More information on Expat can be found at www.libexpat.org. |
|---|
| 1237 | n/a | # |
|---|
| 1238 | n/a | if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"): |
|---|
| 1239 | n/a | expat_inc = [] |
|---|
| 1240 | n/a | define_macros = [] |
|---|
| 1241 | n/a | expat_lib = ['expat'] |
|---|
| 1242 | n/a | expat_sources = [] |
|---|
| 1243 | n/a | else: |
|---|
| 1244 | n/a | expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')] |
|---|
| 1245 | n/a | define_macros = [ |
|---|
| 1246 | n/a | ('HAVE_EXPAT_CONFIG_H', '1'), |
|---|
| 1247 | n/a | ] |
|---|
| 1248 | n/a | expat_lib = [] |
|---|
| 1249 | n/a | expat_sources = ['expat/xmlparse.c', |
|---|
| 1250 | n/a | 'expat/xmlrole.c', |
|---|
| 1251 | n/a | 'expat/xmltok.c'] |
|---|
| 1252 | n/a | |
|---|
| 1253 | n/a | exts.append(Extension('pyexpat', |
|---|
| 1254 | n/a | define_macros = define_macros, |
|---|
| 1255 | n/a | include_dirs = expat_inc, |
|---|
| 1256 | n/a | libraries = expat_lib, |
|---|
| 1257 | n/a | sources = ['pyexpat.c'] + expat_sources |
|---|
| 1258 | n/a | )) |
|---|
| 1259 | n/a | |
|---|
| 1260 | n/a | # Fredrik Lundh's cElementTree module. Note that this also |
|---|
| 1261 | n/a | # uses expat (via the CAPI hook in pyexpat). |
|---|
| 1262 | n/a | |
|---|
| 1263 | n/a | if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')): |
|---|
| 1264 | n/a | define_macros.append(('USE_PYEXPAT_CAPI', None)) |
|---|
| 1265 | n/a | exts.append(Extension('_elementtree', |
|---|
| 1266 | n/a | define_macros = define_macros, |
|---|
| 1267 | n/a | include_dirs = expat_inc, |
|---|
| 1268 | n/a | libraries = expat_lib, |
|---|
| 1269 | n/a | sources = ['_elementtree.c'], |
|---|
| 1270 | n/a | )) |
|---|
| 1271 | n/a | else: |
|---|
| 1272 | n/a | missing.append('_elementtree') |
|---|
| 1273 | n/a | |
|---|
| 1274 | n/a | # Hye-Shik Chang's CJKCodecs modules. |
|---|
| 1275 | n/a | if have_unicode: |
|---|
| 1276 | n/a | exts.append(Extension('_multibytecodec', |
|---|
| 1277 | n/a | ['cjkcodecs/multibytecodec.c'])) |
|---|
| 1278 | n/a | for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): |
|---|
| 1279 | n/a | exts.append(Extension('_codecs_%s' % loc, |
|---|
| 1280 | n/a | ['cjkcodecs/_codecs_%s.c' % loc])) |
|---|
| 1281 | n/a | else: |
|---|
| 1282 | n/a | missing.append('_multibytecodec') |
|---|
| 1283 | n/a | for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): |
|---|
| 1284 | n/a | missing.append('_codecs_%s' % loc) |
|---|
| 1285 | n/a | |
|---|
| 1286 | n/a | # Dynamic loading module |
|---|
| 1287 | n/a | if sys.maxint == 0x7fffffff: |
|---|
| 1288 | n/a | # This requires sizeof(int) == sizeof(long) == sizeof(char*) |
|---|
| 1289 | n/a | dl_inc = find_file('dlfcn.h', [], inc_dirs) |
|---|
| 1290 | n/a | if (dl_inc is not None) and (platform not in ['atheos']): |
|---|
| 1291 | n/a | exts.append( Extension('dl', ['dlmodule.c']) ) |
|---|
| 1292 | n/a | else: |
|---|
| 1293 | n/a | missing.append('dl') |
|---|
| 1294 | n/a | else: |
|---|
| 1295 | n/a | missing.append('dl') |
|---|
| 1296 | n/a | |
|---|
| 1297 | n/a | # Thomas Heller's _ctypes module |
|---|
| 1298 | n/a | self.detect_ctypes(inc_dirs, lib_dirs) |
|---|
| 1299 | n/a | |
|---|
| 1300 | n/a | # Richard Oudkerk's multiprocessing module |
|---|
| 1301 | n/a | if platform == 'win32': # Windows |
|---|
| 1302 | n/a | macros = dict() |
|---|
| 1303 | n/a | libraries = ['ws2_32'] |
|---|
| 1304 | n/a | |
|---|
| 1305 | n/a | elif platform == 'darwin': # Mac OSX |
|---|
| 1306 | n/a | macros = dict() |
|---|
| 1307 | n/a | libraries = [] |
|---|
| 1308 | n/a | |
|---|
| 1309 | n/a | elif platform == 'cygwin': # Cygwin |
|---|
| 1310 | n/a | macros = dict() |
|---|
| 1311 | n/a | libraries = [] |
|---|
| 1312 | n/a | |
|---|
| 1313 | n/a | elif platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'): |
|---|
| 1314 | n/a | # FreeBSD's P1003.1b semaphore support is very experimental |
|---|
| 1315 | n/a | # and has many known problems. (as of June 2008) |
|---|
| 1316 | n/a | macros = dict() |
|---|
| 1317 | n/a | libraries = [] |
|---|
| 1318 | n/a | |
|---|
| 1319 | n/a | elif platform.startswith('openbsd'): |
|---|
| 1320 | n/a | macros = dict() |
|---|
| 1321 | n/a | libraries = [] |
|---|
| 1322 | n/a | |
|---|
| 1323 | n/a | elif platform.startswith('netbsd'): |
|---|
| 1324 | n/a | macros = dict() |
|---|
| 1325 | n/a | libraries = [] |
|---|
| 1326 | n/a | |
|---|
| 1327 | n/a | else: # Linux and other unices |
|---|
| 1328 | n/a | macros = dict() |
|---|
| 1329 | n/a | libraries = ['rt'] |
|---|
| 1330 | n/a | |
|---|
| 1331 | n/a | if platform == 'win32': |
|---|
| 1332 | n/a | multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', |
|---|
| 1333 | n/a | '_multiprocessing/semaphore.c', |
|---|
| 1334 | n/a | '_multiprocessing/pipe_connection.c', |
|---|
| 1335 | n/a | '_multiprocessing/socket_connection.c', |
|---|
| 1336 | n/a | '_multiprocessing/win32_functions.c' |
|---|
| 1337 | n/a | ] |
|---|
| 1338 | n/a | |
|---|
| 1339 | n/a | else: |
|---|
| 1340 | n/a | multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', |
|---|
| 1341 | n/a | '_multiprocessing/socket_connection.c' |
|---|
| 1342 | n/a | ] |
|---|
| 1343 | n/a | if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not |
|---|
| 1344 | n/a | sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')): |
|---|
| 1345 | n/a | multiprocessing_srcs.append('_multiprocessing/semaphore.c') |
|---|
| 1346 | n/a | |
|---|
| 1347 | n/a | if sysconfig.get_config_var('WITH_THREAD'): |
|---|
| 1348 | n/a | exts.append ( Extension('_multiprocessing', multiprocessing_srcs, |
|---|
| 1349 | n/a | define_macros=macros.items(), |
|---|
| 1350 | n/a | include_dirs=["Modules/_multiprocessing"])) |
|---|
| 1351 | n/a | else: |
|---|
| 1352 | n/a | missing.append('_multiprocessing') |
|---|
| 1353 | n/a | |
|---|
| 1354 | n/a | # End multiprocessing |
|---|
| 1355 | n/a | |
|---|
| 1356 | n/a | |
|---|
| 1357 | n/a | # Platform-specific libraries |
|---|
| 1358 | n/a | if platform == 'linux2': |
|---|
| 1359 | n/a | # Linux-specific modules |
|---|
| 1360 | n/a | exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) |
|---|
| 1361 | n/a | else: |
|---|
| 1362 | n/a | missing.append('linuxaudiodev') |
|---|
| 1363 | n/a | |
|---|
| 1364 | n/a | if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', |
|---|
| 1365 | n/a | 'freebsd7', 'freebsd8'): |
|---|
| 1366 | n/a | exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) |
|---|
| 1367 | n/a | else: |
|---|
| 1368 | n/a | missing.append('ossaudiodev') |
|---|
| 1369 | n/a | |
|---|
| 1370 | n/a | if platform == 'sunos5': |
|---|
| 1371 | n/a | # SunOS specific modules |
|---|
| 1372 | n/a | exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) |
|---|
| 1373 | n/a | else: |
|---|
| 1374 | n/a | missing.append('sunaudiodev') |
|---|
| 1375 | n/a | |
|---|
| 1376 | n/a | if platform == 'darwin': |
|---|
| 1377 | n/a | # _scproxy |
|---|
| 1378 | n/a | exts.append(Extension("_scproxy", [os.path.join(srcdir, "Mac/Modules/_scproxy.c")], |
|---|
| 1379 | n/a | extra_link_args= [ |
|---|
| 1380 | n/a | '-framework', 'SystemConfiguration', |
|---|
| 1381 | n/a | '-framework', 'CoreFoundation' |
|---|
| 1382 | n/a | ])) |
|---|
| 1383 | n/a | |
|---|
| 1384 | n/a | |
|---|
| 1385 | n/a | if platform == 'darwin' and ("--disable-toolbox-glue" not in |
|---|
| 1386 | n/a | sysconfig.get_config_var("CONFIG_ARGS")): |
|---|
| 1387 | n/a | |
|---|
| 1388 | n/a | if int(os.uname()[2].split('.')[0]) >= 8: |
|---|
| 1389 | n/a | # We're on Mac OS X 10.4 or later, the compiler should |
|---|
| 1390 | n/a | # support '-Wno-deprecated-declarations'. This will |
|---|
| 1391 | n/a | # surpress deprecation warnings for the Carbon extensions, |
|---|
| 1392 | n/a | # these extensions wrap the Carbon APIs and even those |
|---|
| 1393 | n/a | # parts that are deprecated. |
|---|
| 1394 | n/a | carbon_extra_compile_args = ['-Wno-deprecated-declarations'] |
|---|
| 1395 | n/a | else: |
|---|
| 1396 | n/a | carbon_extra_compile_args = [] |
|---|
| 1397 | n/a | |
|---|
| 1398 | n/a | # Mac OS X specific modules. |
|---|
| 1399 | n/a | def macSrcExists(name1, name2=''): |
|---|
| 1400 | n/a | if not name1: |
|---|
| 1401 | n/a | return None |
|---|
| 1402 | n/a | names = (name1,) |
|---|
| 1403 | n/a | if name2: |
|---|
| 1404 | n/a | names = (name1, name2) |
|---|
| 1405 | n/a | path = os.path.join(srcdir, 'Mac', 'Modules', *names) |
|---|
| 1406 | n/a | return os.path.exists(path) |
|---|
| 1407 | n/a | |
|---|
| 1408 | n/a | def addMacExtension(name, kwds, extra_srcs=[]): |
|---|
| 1409 | n/a | dirname = '' |
|---|
| 1410 | n/a | if name[0] == '_': |
|---|
| 1411 | n/a | dirname = name[1:].lower() |
|---|
| 1412 | n/a | cname = name + '.c' |
|---|
| 1413 | n/a | cmodulename = name + 'module.c' |
|---|
| 1414 | n/a | # Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c |
|---|
| 1415 | n/a | if macSrcExists(cname): |
|---|
| 1416 | n/a | srcs = [cname] |
|---|
| 1417 | n/a | elif macSrcExists(cmodulename): |
|---|
| 1418 | n/a | srcs = [cmodulename] |
|---|
| 1419 | n/a | elif macSrcExists(dirname, cname): |
|---|
| 1420 | n/a | # XXX(nnorwitz): If all the names ended with module, we |
|---|
| 1421 | n/a | # wouldn't need this condition. ibcarbon is the only one. |
|---|
| 1422 | n/a | srcs = [os.path.join(dirname, cname)] |
|---|
| 1423 | n/a | elif macSrcExists(dirname, cmodulename): |
|---|
| 1424 | n/a | srcs = [os.path.join(dirname, cmodulename)] |
|---|
| 1425 | n/a | else: |
|---|
| 1426 | n/a | raise RuntimeError("%s not found" % name) |
|---|
| 1427 | n/a | |
|---|
| 1428 | n/a | # Here's the whole point: add the extension with sources |
|---|
| 1429 | n/a | exts.append(Extension(name, srcs + extra_srcs, **kwds)) |
|---|
| 1430 | n/a | |
|---|
| 1431 | n/a | # Core Foundation |
|---|
| 1432 | n/a | core_kwds = {'extra_compile_args': carbon_extra_compile_args, |
|---|
| 1433 | n/a | 'extra_link_args': ['-framework', 'CoreFoundation'], |
|---|
| 1434 | n/a | } |
|---|
| 1435 | n/a | addMacExtension('_CF', core_kwds, ['cf/pycfbridge.c']) |
|---|
| 1436 | n/a | addMacExtension('autoGIL', core_kwds) |
|---|
| 1437 | n/a | |
|---|
| 1438 | n/a | |
|---|
| 1439 | n/a | |
|---|
| 1440 | n/a | # Carbon |
|---|
| 1441 | n/a | carbon_kwds = {'extra_compile_args': carbon_extra_compile_args, |
|---|
| 1442 | n/a | 'extra_link_args': ['-framework', 'Carbon'], |
|---|
| 1443 | n/a | } |
|---|
| 1444 | n/a | CARBON_EXTS = ['ColorPicker', 'gestalt', 'MacOS', 'Nav', |
|---|
| 1445 | n/a | 'OSATerminology', 'icglue', |
|---|
| 1446 | n/a | # All these are in subdirs |
|---|
| 1447 | n/a | '_AE', '_AH', '_App', '_CarbonEvt', '_Cm', '_Ctl', |
|---|
| 1448 | n/a | '_Dlg', '_Drag', '_Evt', '_File', '_Folder', '_Fm', |
|---|
| 1449 | n/a | '_Help', '_Icn', '_IBCarbon', '_List', |
|---|
| 1450 | n/a | '_Menu', '_Mlte', '_OSA', '_Res', '_Qd', '_Qdoffs', |
|---|
| 1451 | n/a | '_Scrap', '_Snd', '_TE', |
|---|
| 1452 | n/a | ] |
|---|
| 1453 | n/a | for name in CARBON_EXTS: |
|---|
| 1454 | n/a | addMacExtension(name, carbon_kwds) |
|---|
| 1455 | n/a | |
|---|
| 1456 | n/a | # Workaround for a bug in the version of gcc shipped with Xcode 3. |
|---|
| 1457 | n/a | # The _Win extension should build just like the other Carbon extensions, but |
|---|
| 1458 | n/a | # this actually results in a hard crash of the linker. |
|---|
| 1459 | n/a | # |
|---|
| 1460 | n/a | if '-arch ppc64' in cflags and '-arch ppc' in cflags: |
|---|
| 1461 | n/a | win_kwds = {'extra_compile_args': carbon_extra_compile_args + ['-arch', 'i386', '-arch', 'ppc'], |
|---|
| 1462 | n/a | 'extra_link_args': ['-framework', 'Carbon', '-arch', 'i386', '-arch', 'ppc'], |
|---|
| 1463 | n/a | } |
|---|
| 1464 | n/a | addMacExtension('_Win', win_kwds) |
|---|
| 1465 | n/a | else: |
|---|
| 1466 | n/a | addMacExtension('_Win', carbon_kwds) |
|---|
| 1467 | n/a | |
|---|
| 1468 | n/a | |
|---|
| 1469 | n/a | # Application Services & QuickTime |
|---|
| 1470 | n/a | app_kwds = {'extra_compile_args': carbon_extra_compile_args, |
|---|
| 1471 | n/a | 'extra_link_args': ['-framework','ApplicationServices'], |
|---|
| 1472 | n/a | } |
|---|
| 1473 | n/a | addMacExtension('_Launch', app_kwds) |
|---|
| 1474 | n/a | addMacExtension('_CG', app_kwds) |
|---|
| 1475 | n/a | |
|---|
| 1476 | n/a | exts.append( Extension('_Qt', ['qt/_Qtmodule.c'], |
|---|
| 1477 | n/a | extra_compile_args=carbon_extra_compile_args, |
|---|
| 1478 | n/a | extra_link_args=['-framework', 'QuickTime', |
|---|
| 1479 | n/a | '-framework', 'Carbon']) ) |
|---|
| 1480 | n/a | |
|---|
| 1481 | n/a | |
|---|
| 1482 | n/a | self.extensions.extend(exts) |
|---|
| 1483 | n/a | |
|---|
| 1484 | n/a | # Call the method for detecting whether _tkinter can be compiled |
|---|
| 1485 | n/a | self.detect_tkinter(inc_dirs, lib_dirs) |
|---|
| 1486 | n/a | |
|---|
| 1487 | n/a | if '_tkinter' not in [e.name for e in self.extensions]: |
|---|
| 1488 | n/a | missing.append('_tkinter') |
|---|
| 1489 | n/a | |
|---|
| 1490 | n/a | return missing |
|---|
| 1491 | n/a | |
|---|
| 1492 | n/a | def detect_tkinter_darwin(self, inc_dirs, lib_dirs): |
|---|
| 1493 | n/a | # The _tkinter module, using frameworks. Since frameworks are quite |
|---|
| 1494 | n/a | # different the UNIX search logic is not sharable. |
|---|
| 1495 | n/a | from os.path import join, exists |
|---|
| 1496 | n/a | framework_dirs = [ |
|---|
| 1497 | n/a | '/Library/Frameworks', |
|---|
| 1498 | n/a | '/System/Library/Frameworks/', |
|---|
| 1499 | n/a | join(os.getenv('HOME'), '/Library/Frameworks') |
|---|
| 1500 | n/a | ] |
|---|
| 1501 | n/a | |
|---|
| 1502 | n/a | # Find the directory that contains the Tcl.framework and Tk.framework |
|---|
| 1503 | n/a | # bundles. |
|---|
| 1504 | n/a | # XXX distutils should support -F! |
|---|
| 1505 | n/a | for F in framework_dirs: |
|---|
| 1506 | n/a | # both Tcl.framework and Tk.framework should be present |
|---|
| 1507 | n/a | for fw in 'Tcl', 'Tk': |
|---|
| 1508 | n/a | if not exists(join(F, fw + '.framework')): |
|---|
| 1509 | n/a | break |
|---|
| 1510 | n/a | else: |
|---|
| 1511 | n/a | # ok, F is now directory with both frameworks. Continure |
|---|
| 1512 | n/a | # building |
|---|
| 1513 | n/a | break |
|---|
| 1514 | n/a | else: |
|---|
| 1515 | n/a | # Tk and Tcl frameworks not found. Normal "unix" tkinter search |
|---|
| 1516 | n/a | # will now resume. |
|---|
| 1517 | n/a | return 0 |
|---|
| 1518 | n/a | |
|---|
| 1519 | n/a | # For 8.4a2, we must add -I options that point inside the Tcl and Tk |
|---|
| 1520 | n/a | # frameworks. In later release we should hopefully be able to pass |
|---|
| 1521 | n/a | # the -F option to gcc, which specifies a framework lookup path. |
|---|
| 1522 | n/a | # |
|---|
| 1523 | n/a | include_dirs = [ |
|---|
| 1524 | n/a | join(F, fw + '.framework', H) |
|---|
| 1525 | n/a | for fw in 'Tcl', 'Tk' |
|---|
| 1526 | n/a | for H in 'Headers', 'Versions/Current/PrivateHeaders' |
|---|
| 1527 | n/a | ] |
|---|
| 1528 | n/a | |
|---|
| 1529 | n/a | # For 8.4a2, the X11 headers are not included. Rather than include a |
|---|
| 1530 | n/a | # complicated search, this is a hard-coded path. It could bail out |
|---|
| 1531 | n/a | # if X11 libs are not found... |
|---|
| 1532 | n/a | include_dirs.append('/usr/X11R6/include') |
|---|
| 1533 | n/a | frameworks = ['-framework', 'Tcl', '-framework', 'Tk'] |
|---|
| 1534 | n/a | |
|---|
| 1535 | n/a | # All existing framework builds of Tcl/Tk don't support 64-bit |
|---|
| 1536 | n/a | # architectures. |
|---|
| 1537 | n/a | cflags = sysconfig.get_config_vars('CFLAGS')[0] |
|---|
| 1538 | n/a | archs = re.findall('-arch\s+(\w+)', cflags) |
|---|
| 1539 | n/a | fp = os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(F,)) |
|---|
| 1540 | n/a | detected_archs = [] |
|---|
| 1541 | n/a | for ln in fp: |
|---|
| 1542 | n/a | a = ln.split()[-1] |
|---|
| 1543 | n/a | if a in archs: |
|---|
| 1544 | n/a | detected_archs.append(ln.split()[-1]) |
|---|
| 1545 | n/a | fp.close() |
|---|
| 1546 | n/a | |
|---|
| 1547 | n/a | for a in detected_archs: |
|---|
| 1548 | n/a | frameworks.append('-arch') |
|---|
| 1549 | n/a | frameworks.append(a) |
|---|
| 1550 | n/a | |
|---|
| 1551 | n/a | ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
|---|
| 1552 | n/a | define_macros=[('WITH_APPINIT', 1)], |
|---|
| 1553 | n/a | include_dirs = include_dirs, |
|---|
| 1554 | n/a | libraries = [], |
|---|
| 1555 | n/a | extra_compile_args = frameworks[2:], |
|---|
| 1556 | n/a | extra_link_args = frameworks, |
|---|
| 1557 | n/a | ) |
|---|
| 1558 | n/a | self.extensions.append(ext) |
|---|
| 1559 | n/a | return 1 |
|---|
| 1560 | n/a | |
|---|
| 1561 | n/a | |
|---|
| 1562 | n/a | def detect_tkinter(self, inc_dirs, lib_dirs): |
|---|
| 1563 | n/a | # The _tkinter module. |
|---|
| 1564 | n/a | |
|---|
| 1565 | n/a | # Rather than complicate the code below, detecting and building |
|---|
| 1566 | n/a | # AquaTk is a separate method. Only one Tkinter will be built on |
|---|
| 1567 | n/a | # Darwin - either AquaTk, if it is found, or X11 based Tk. |
|---|
| 1568 | n/a | platform = self.get_platform() |
|---|
| 1569 | n/a | if (platform == 'darwin' and |
|---|
| 1570 | n/a | self.detect_tkinter_darwin(inc_dirs, lib_dirs)): |
|---|
| 1571 | n/a | return |
|---|
| 1572 | n/a | |
|---|
| 1573 | n/a | # Assume we haven't found any of the libraries or include files |
|---|
| 1574 | n/a | # The versions with dots are used on Unix, and the versions without |
|---|
| 1575 | n/a | # dots on Windows, for detection by cygwin. |
|---|
| 1576 | n/a | tcllib = tklib = tcl_includes = tk_includes = None |
|---|
| 1577 | n/a | for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83', |
|---|
| 1578 | n/a | '8.2', '82', '8.1', '81', '8.0', '80']: |
|---|
| 1579 | n/a | tklib = self.compiler.find_library_file(lib_dirs, |
|---|
| 1580 | n/a | 'tk' + version) |
|---|
| 1581 | n/a | tcllib = self.compiler.find_library_file(lib_dirs, |
|---|
| 1582 | n/a | 'tcl' + version) |
|---|
| 1583 | n/a | if tklib and tcllib: |
|---|
| 1584 | n/a | # Exit the loop when we've found the Tcl/Tk libraries |
|---|
| 1585 | n/a | break |
|---|
| 1586 | n/a | |
|---|
| 1587 | n/a | # Now check for the header files |
|---|
| 1588 | n/a | if tklib and tcllib: |
|---|
| 1589 | n/a | # Check for the include files on Debian and {Free,Open}BSD, where |
|---|
| 1590 | n/a | # they're put in /usr/include/{tcl,tk}X.Y |
|---|
| 1591 | n/a | dotversion = version |
|---|
| 1592 | n/a | if '.' not in dotversion and "bsd" in sys.platform.lower(): |
|---|
| 1593 | n/a | # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a, |
|---|
| 1594 | n/a | # but the include subdirs are named like .../include/tcl8.3. |
|---|
| 1595 | n/a | dotversion = dotversion[:-1] + '.' + dotversion[-1] |
|---|
| 1596 | n/a | tcl_include_sub = [] |
|---|
| 1597 | n/a | tk_include_sub = [] |
|---|
| 1598 | n/a | for dir in inc_dirs: |
|---|
| 1599 | n/a | tcl_include_sub += [dir + os.sep + "tcl" + dotversion] |
|---|
| 1600 | n/a | tk_include_sub += [dir + os.sep + "tk" + dotversion] |
|---|
| 1601 | n/a | tk_include_sub += tcl_include_sub |
|---|
| 1602 | n/a | tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub) |
|---|
| 1603 | n/a | tk_includes = find_file('tk.h', inc_dirs, tk_include_sub) |
|---|
| 1604 | n/a | |
|---|
| 1605 | n/a | if (tcllib is None or tklib is None or |
|---|
| 1606 | n/a | tcl_includes is None or tk_includes is None): |
|---|
| 1607 | n/a | self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2) |
|---|
| 1608 | n/a | return |
|---|
| 1609 | n/a | |
|---|
| 1610 | n/a | # OK... everything seems to be present for Tcl/Tk. |
|---|
| 1611 | n/a | |
|---|
| 1612 | n/a | include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] |
|---|
| 1613 | n/a | for dir in tcl_includes + tk_includes: |
|---|
| 1614 | n/a | if dir not in include_dirs: |
|---|
| 1615 | n/a | include_dirs.append(dir) |
|---|
| 1616 | n/a | |
|---|
| 1617 | n/a | # Check for various platform-specific directories |
|---|
| 1618 | n/a | if platform == 'sunos5': |
|---|
| 1619 | n/a | include_dirs.append('/usr/openwin/include') |
|---|
| 1620 | n/a | added_lib_dirs.append('/usr/openwin/lib') |
|---|
| 1621 | n/a | elif os.path.exists('/usr/X11R6/include'): |
|---|
| 1622 | n/a | include_dirs.append('/usr/X11R6/include') |
|---|
| 1623 | n/a | added_lib_dirs.append('/usr/X11R6/lib64') |
|---|
| 1624 | n/a | added_lib_dirs.append('/usr/X11R6/lib') |
|---|
| 1625 | n/a | elif os.path.exists('/usr/X11R5/include'): |
|---|
| 1626 | n/a | include_dirs.append('/usr/X11R5/include') |
|---|
| 1627 | n/a | added_lib_dirs.append('/usr/X11R5/lib') |
|---|
| 1628 | n/a | else: |
|---|
| 1629 | n/a | # Assume default location for X11 |
|---|
| 1630 | n/a | include_dirs.append('/usr/X11/include') |
|---|
| 1631 | n/a | added_lib_dirs.append('/usr/X11/lib') |
|---|
| 1632 | n/a | |
|---|
| 1633 | n/a | # If Cygwin, then verify that X is installed before proceeding |
|---|
| 1634 | n/a | if platform == 'cygwin': |
|---|
| 1635 | n/a | x11_inc = find_file('X11/Xlib.h', [], include_dirs) |
|---|
| 1636 | n/a | if x11_inc is None: |
|---|
| 1637 | n/a | return |
|---|
| 1638 | n/a | |
|---|
| 1639 | n/a | # Check for BLT extension |
|---|
| 1640 | n/a | if self.compiler.find_library_file(lib_dirs + added_lib_dirs, |
|---|
| 1641 | n/a | 'BLT8.0'): |
|---|
| 1642 | n/a | defs.append( ('WITH_BLT', 1) ) |
|---|
| 1643 | n/a | libs.append('BLT8.0') |
|---|
| 1644 | n/a | elif self.compiler.find_library_file(lib_dirs + added_lib_dirs, |
|---|
| 1645 | n/a | 'BLT'): |
|---|
| 1646 | n/a | defs.append( ('WITH_BLT', 1) ) |
|---|
| 1647 | n/a | libs.append('BLT') |
|---|
| 1648 | n/a | |
|---|
| 1649 | n/a | # Add the Tcl/Tk libraries |
|---|
| 1650 | n/a | libs.append('tk'+ version) |
|---|
| 1651 | n/a | libs.append('tcl'+ version) |
|---|
| 1652 | n/a | |
|---|
| 1653 | n/a | if platform in ['aix3', 'aix4']: |
|---|
| 1654 | n/a | libs.append('ld') |
|---|
| 1655 | n/a | |
|---|
| 1656 | n/a | # Finally, link with the X11 libraries (not appropriate on cygwin) |
|---|
| 1657 | n/a | if platform != "cygwin": |
|---|
| 1658 | n/a | libs.append('X11') |
|---|
| 1659 | n/a | |
|---|
| 1660 | n/a | ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
|---|
| 1661 | n/a | define_macros=[('WITH_APPINIT', 1)] + defs, |
|---|
| 1662 | n/a | include_dirs = include_dirs, |
|---|
| 1663 | n/a | libraries = libs, |
|---|
| 1664 | n/a | library_dirs = added_lib_dirs, |
|---|
| 1665 | n/a | ) |
|---|
| 1666 | n/a | self.extensions.append(ext) |
|---|
| 1667 | n/a | |
|---|
| 1668 | n/a | ## # Uncomment these lines if you want to play with xxmodule.c |
|---|
| 1669 | n/a | ## ext = Extension('xx', ['xxmodule.c']) |
|---|
| 1670 | n/a | ## self.extensions.append(ext) |
|---|
| 1671 | n/a | |
|---|
| 1672 | n/a | # XXX handle these, but how to detect? |
|---|
| 1673 | n/a | # *** Uncomment and edit for PIL (TkImaging) extension only: |
|---|
| 1674 | n/a | # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ |
|---|
| 1675 | n/a | # *** Uncomment and edit for TOGL extension only: |
|---|
| 1676 | n/a | # -DWITH_TOGL togl.c \ |
|---|
| 1677 | n/a | # *** Uncomment these for TOGL extension only: |
|---|
| 1678 | n/a | # -lGL -lGLU -lXext -lXmu \ |
|---|
| 1679 | n/a | |
|---|
| 1680 | n/a | def configure_ctypes_darwin(self, ext): |
|---|
| 1681 | n/a | # Darwin (OS X) uses preconfigured files, in |
|---|
| 1682 | n/a | # the Modules/_ctypes/libffi_osx directory. |
|---|
| 1683 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 1684 | n/a | ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', |
|---|
| 1685 | n/a | '_ctypes', 'libffi_osx')) |
|---|
| 1686 | n/a | sources = [os.path.join(ffi_srcdir, p) |
|---|
| 1687 | n/a | for p in ['ffi.c', |
|---|
| 1688 | n/a | 'x86/darwin64.S', |
|---|
| 1689 | n/a | 'x86/x86-darwin.S', |
|---|
| 1690 | n/a | 'x86/x86-ffi_darwin.c', |
|---|
| 1691 | n/a | 'x86/x86-ffi64.c', |
|---|
| 1692 | n/a | 'powerpc/ppc-darwin.S', |
|---|
| 1693 | n/a | 'powerpc/ppc-darwin_closure.S', |
|---|
| 1694 | n/a | 'powerpc/ppc-ffi_darwin.c', |
|---|
| 1695 | n/a | 'powerpc/ppc64-darwin_closure.S', |
|---|
| 1696 | n/a | ]] |
|---|
| 1697 | n/a | |
|---|
| 1698 | n/a | # Add .S (preprocessed assembly) to C compiler source extensions. |
|---|
| 1699 | n/a | self.compiler.src_extensions.append('.S') |
|---|
| 1700 | n/a | |
|---|
| 1701 | n/a | include_dirs = [os.path.join(ffi_srcdir, 'include'), |
|---|
| 1702 | n/a | os.path.join(ffi_srcdir, 'powerpc')] |
|---|
| 1703 | n/a | ext.include_dirs.extend(include_dirs) |
|---|
| 1704 | n/a | ext.sources.extend(sources) |
|---|
| 1705 | n/a | return True |
|---|
| 1706 | n/a | |
|---|
| 1707 | n/a | def configure_ctypes(self, ext): |
|---|
| 1708 | n/a | if not self.use_system_libffi: |
|---|
| 1709 | n/a | if sys.platform == 'darwin': |
|---|
| 1710 | n/a | return self.configure_ctypes_darwin(ext) |
|---|
| 1711 | n/a | |
|---|
| 1712 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 1713 | n/a | ffi_builddir = os.path.join(self.build_temp, 'libffi') |
|---|
| 1714 | n/a | ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', |
|---|
| 1715 | n/a | '_ctypes', 'libffi')) |
|---|
| 1716 | n/a | ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py') |
|---|
| 1717 | n/a | |
|---|
| 1718 | n/a | from distutils.dep_util import newer_group |
|---|
| 1719 | n/a | |
|---|
| 1720 | n/a | config_sources = [os.path.join(ffi_srcdir, fname) |
|---|
| 1721 | n/a | for fname in os.listdir(ffi_srcdir) |
|---|
| 1722 | n/a | if os.path.isfile(os.path.join(ffi_srcdir, fname))] |
|---|
| 1723 | n/a | if self.force or newer_group(config_sources, |
|---|
| 1724 | n/a | ffi_configfile): |
|---|
| 1725 | n/a | from distutils.dir_util import mkpath |
|---|
| 1726 | n/a | mkpath(ffi_builddir) |
|---|
| 1727 | n/a | config_args = [] |
|---|
| 1728 | n/a | |
|---|
| 1729 | n/a | # Pass empty CFLAGS because we'll just append the resulting |
|---|
| 1730 | n/a | # CFLAGS to Python's; -g or -O2 is to be avoided. |
|---|
| 1731 | n/a | cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \ |
|---|
| 1732 | n/a | % (ffi_builddir, ffi_srcdir, " ".join(config_args)) |
|---|
| 1733 | n/a | |
|---|
| 1734 | n/a | res = os.system(cmd) |
|---|
| 1735 | n/a | if res or not os.path.exists(ffi_configfile): |
|---|
| 1736 | n/a | print "Failed to configure _ctypes module" |
|---|
| 1737 | n/a | return False |
|---|
| 1738 | n/a | |
|---|
| 1739 | n/a | fficonfig = {} |
|---|
| 1740 | n/a | with open(ffi_configfile) as f: |
|---|
| 1741 | n/a | exec f in fficonfig |
|---|
| 1742 | n/a | |
|---|
| 1743 | n/a | # Add .S (preprocessed assembly) to C compiler source extensions. |
|---|
| 1744 | n/a | self.compiler.src_extensions.append('.S') |
|---|
| 1745 | n/a | |
|---|
| 1746 | n/a | include_dirs = [os.path.join(ffi_builddir, 'include'), |
|---|
| 1747 | n/a | ffi_builddir, |
|---|
| 1748 | n/a | os.path.join(ffi_srcdir, 'src')] |
|---|
| 1749 | n/a | extra_compile_args = fficonfig['ffi_cflags'].split() |
|---|
| 1750 | n/a | |
|---|
| 1751 | n/a | ext.sources.extend(os.path.join(ffi_srcdir, f) for f in |
|---|
| 1752 | n/a | fficonfig['ffi_sources']) |
|---|
| 1753 | n/a | ext.include_dirs.extend(include_dirs) |
|---|
| 1754 | n/a | ext.extra_compile_args.extend(extra_compile_args) |
|---|
| 1755 | n/a | return True |
|---|
| 1756 | n/a | |
|---|
| 1757 | n/a | def detect_ctypes(self, inc_dirs, lib_dirs): |
|---|
| 1758 | n/a | self.use_system_libffi = False |
|---|
| 1759 | n/a | include_dirs = [] |
|---|
| 1760 | n/a | extra_compile_args = [] |
|---|
| 1761 | n/a | extra_link_args = [] |
|---|
| 1762 | n/a | sources = ['_ctypes/_ctypes.c', |
|---|
| 1763 | n/a | '_ctypes/callbacks.c', |
|---|
| 1764 | n/a | '_ctypes/callproc.c', |
|---|
| 1765 | n/a | '_ctypes/stgdict.c', |
|---|
| 1766 | n/a | '_ctypes/cfield.c', |
|---|
| 1767 | n/a | '_ctypes/malloc_closure.c'] |
|---|
| 1768 | n/a | depends = ['_ctypes/ctypes.h'] |
|---|
| 1769 | n/a | |
|---|
| 1770 | n/a | if sys.platform == 'darwin': |
|---|
| 1771 | n/a | sources.append('_ctypes/darwin/dlfcn_simple.c') |
|---|
| 1772 | n/a | extra_compile_args.append('-DMACOSX') |
|---|
| 1773 | n/a | include_dirs.append('_ctypes/darwin') |
|---|
| 1774 | n/a | # XXX Is this still needed? |
|---|
| 1775 | n/a | ## extra_link_args.extend(['-read_only_relocs', 'warning']) |
|---|
| 1776 | n/a | |
|---|
| 1777 | n/a | elif sys.platform == 'sunos5': |
|---|
| 1778 | n/a | # XXX This shouldn't be necessary; it appears that some |
|---|
| 1779 | n/a | # of the assembler code is non-PIC (i.e. it has relocations |
|---|
| 1780 | n/a | # when it shouldn't. The proper fix would be to rewrite |
|---|
| 1781 | n/a | # the assembler code to be PIC. |
|---|
| 1782 | n/a | # This only works with GCC; the Sun compiler likely refuses |
|---|
| 1783 | n/a | # this option. If you want to compile ctypes with the Sun |
|---|
| 1784 | n/a | # compiler, please research a proper solution, instead of |
|---|
| 1785 | n/a | # finding some -z option for the Sun compiler. |
|---|
| 1786 | n/a | extra_link_args.append('-mimpure-text') |
|---|
| 1787 | n/a | |
|---|
| 1788 | n/a | elif sys.platform.startswith('hp-ux'): |
|---|
| 1789 | n/a | extra_link_args.append('-fPIC') |
|---|
| 1790 | n/a | |
|---|
| 1791 | n/a | ext = Extension('_ctypes', |
|---|
| 1792 | n/a | include_dirs=include_dirs, |
|---|
| 1793 | n/a | extra_compile_args=extra_compile_args, |
|---|
| 1794 | n/a | extra_link_args=extra_link_args, |
|---|
| 1795 | n/a | libraries=[], |
|---|
| 1796 | n/a | sources=sources, |
|---|
| 1797 | n/a | depends=depends) |
|---|
| 1798 | n/a | ext_test = Extension('_ctypes_test', |
|---|
| 1799 | n/a | sources=['_ctypes/_ctypes_test.c']) |
|---|
| 1800 | n/a | self.extensions.extend([ext, ext_test]) |
|---|
| 1801 | n/a | |
|---|
| 1802 | n/a | if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): |
|---|
| 1803 | n/a | return |
|---|
| 1804 | n/a | |
|---|
| 1805 | n/a | if sys.platform == 'darwin': |
|---|
| 1806 | n/a | # OS X 10.5 comes with libffi.dylib; the include files are |
|---|
| 1807 | n/a | # in /usr/include/ffi |
|---|
| 1808 | n/a | inc_dirs.append('/usr/include/ffi') |
|---|
| 1809 | n/a | |
|---|
| 1810 | n/a | ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")] |
|---|
| 1811 | n/a | if not ffi_inc: |
|---|
| 1812 | n/a | ffi_inc = find_file('ffi.h', [], inc_dirs) |
|---|
| 1813 | n/a | if ffi_inc is not None: |
|---|
| 1814 | n/a | ffi_h = ffi_inc[0] + '/ffi.h' |
|---|
| 1815 | n/a | fp = open(ffi_h) |
|---|
| 1816 | n/a | while 1: |
|---|
| 1817 | n/a | line = fp.readline() |
|---|
| 1818 | n/a | if not line: |
|---|
| 1819 | n/a | ffi_inc = None |
|---|
| 1820 | n/a | break |
|---|
| 1821 | n/a | if line.startswith('#define LIBFFI_H'): |
|---|
| 1822 | n/a | break |
|---|
| 1823 | n/a | ffi_lib = None |
|---|
| 1824 | n/a | if ffi_inc is not None: |
|---|
| 1825 | n/a | for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'): |
|---|
| 1826 | n/a | if (self.compiler.find_library_file(lib_dirs, lib_name)): |
|---|
| 1827 | n/a | ffi_lib = lib_name |
|---|
| 1828 | n/a | break |
|---|
| 1829 | n/a | |
|---|
| 1830 | n/a | if ffi_inc and ffi_lib: |
|---|
| 1831 | n/a | ext.include_dirs.extend(ffi_inc) |
|---|
| 1832 | n/a | ext.libraries.append(ffi_lib) |
|---|
| 1833 | n/a | self.use_system_libffi = True |
|---|
| 1834 | n/a | |
|---|
| 1835 | n/a | |
|---|
| 1836 | n/a | class PyBuildInstall(install): |
|---|
| 1837 | n/a | # Suppress the warning about installation into the lib_dynload |
|---|
| 1838 | n/a | # directory, which is not in sys.path when running Python during |
|---|
| 1839 | n/a | # installation: |
|---|
| 1840 | n/a | def initialize_options (self): |
|---|
| 1841 | n/a | install.initialize_options(self) |
|---|
| 1842 | n/a | self.warn_dir=0 |
|---|
| 1843 | n/a | |
|---|
| 1844 | n/a | class PyBuildInstallLib(install_lib): |
|---|
| 1845 | n/a | # Do exactly what install_lib does but make sure correct access modes get |
|---|
| 1846 | n/a | # set on installed directories and files. All installed files with get |
|---|
| 1847 | n/a | # mode 644 unless they are a shared library in which case they will get |
|---|
| 1848 | n/a | # mode 755. All installed directories will get mode 755. |
|---|
| 1849 | n/a | |
|---|
| 1850 | n/a | so_ext = sysconfig.get_config_var("SO") |
|---|
| 1851 | n/a | |
|---|
| 1852 | n/a | def install(self): |
|---|
| 1853 | n/a | outfiles = install_lib.install(self) |
|---|
| 1854 | n/a | self.set_file_modes(outfiles, 0644, 0755) |
|---|
| 1855 | n/a | self.set_dir_modes(self.install_dir, 0755) |
|---|
| 1856 | n/a | return outfiles |
|---|
| 1857 | n/a | |
|---|
| 1858 | n/a | def set_file_modes(self, files, defaultMode, sharedLibMode): |
|---|
| 1859 | n/a | if not self.is_chmod_supported(): return |
|---|
| 1860 | n/a | if not files: return |
|---|
| 1861 | n/a | |
|---|
| 1862 | n/a | for filename in files: |
|---|
| 1863 | n/a | if os.path.islink(filename): continue |
|---|
| 1864 | n/a | mode = defaultMode |
|---|
| 1865 | n/a | if filename.endswith(self.so_ext): mode = sharedLibMode |
|---|
| 1866 | n/a | log.info("changing mode of %s to %o", filename, mode) |
|---|
| 1867 | n/a | if not self.dry_run: os.chmod(filename, mode) |
|---|
| 1868 | n/a | |
|---|
| 1869 | n/a | def set_dir_modes(self, dirname, mode): |
|---|
| 1870 | n/a | if not self.is_chmod_supported(): return |
|---|
| 1871 | n/a | os.path.walk(dirname, self.set_dir_modes_visitor, mode) |
|---|
| 1872 | n/a | |
|---|
| 1873 | n/a | def set_dir_modes_visitor(self, mode, dirname, names): |
|---|
| 1874 | n/a | if os.path.islink(dirname): return |
|---|
| 1875 | n/a | log.info("changing mode of %s to %o", dirname, mode) |
|---|
| 1876 | n/a | if not self.dry_run: os.chmod(dirname, mode) |
|---|
| 1877 | n/a | |
|---|
| 1878 | n/a | def is_chmod_supported(self): |
|---|
| 1879 | n/a | return hasattr(os, 'chmod') |
|---|
| 1880 | n/a | |
|---|
| 1881 | n/a | SUMMARY = """ |
|---|
| 1882 | n/a | Python is an interpreted, interactive, object-oriented programming |
|---|
| 1883 | n/a | language. It is often compared to Tcl, Perl, Scheme or Java. |
|---|
| 1884 | n/a | |
|---|
| 1885 | n/a | Python combines remarkable power with very clear syntax. It has |
|---|
| 1886 | n/a | modules, classes, exceptions, very high level dynamic data types, and |
|---|
| 1887 | n/a | dynamic typing. There are interfaces to many system calls and |
|---|
| 1888 | n/a | libraries, as well as to various windowing systems (X11, Motif, Tk, |
|---|
| 1889 | n/a | Mac, MFC). New built-in modules are easily written in C or C++. Python |
|---|
| 1890 | n/a | is also usable as an extension language for applications that need a |
|---|
| 1891 | n/a | programmable interface. |
|---|
| 1892 | n/a | |
|---|
| 1893 | n/a | The Python implementation is portable: it runs on many brands of UNIX, |
|---|
| 1894 | n/a | on Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't |
|---|
| 1895 | n/a | listed here, it may still be supported, if there's a C compiler for |
|---|
| 1896 | n/a | it. Ask around on comp.lang.python -- or just try compiling Python |
|---|
| 1897 | n/a | yourself. |
|---|
| 1898 | n/a | """ |
|---|
| 1899 | n/a | |
|---|
| 1900 | n/a | CLASSIFIERS = """ |
|---|
| 1901 | n/a | Development Status :: 6 - Mature |
|---|
| 1902 | n/a | License :: OSI Approved :: Python Software Foundation License |
|---|
| 1903 | n/a | Natural Language :: English |
|---|
| 1904 | n/a | Programming Language :: C |
|---|
| 1905 | n/a | Programming Language :: Python |
|---|
| 1906 | n/a | Topic :: Software Development |
|---|
| 1907 | n/a | """ |
|---|
| 1908 | n/a | |
|---|
| 1909 | n/a | def main(): |
|---|
| 1910 | n/a | # turn off warnings when deprecated modules are imported |
|---|
| 1911 | n/a | import warnings |
|---|
| 1912 | n/a | warnings.filterwarnings("ignore",category=DeprecationWarning) |
|---|
| 1913 | n/a | setup(# PyPI Metadata (PEP 301) |
|---|
| 1914 | n/a | name = "Python", |
|---|
| 1915 | n/a | version = sys.version.split()[0], |
|---|
| 1916 | n/a | url = "http://www.python.org/%s" % sys.version[:3], |
|---|
| 1917 | n/a | maintainer = "Guido van Rossum and the Python community", |
|---|
| 1918 | n/a | maintainer_email = "python-dev@python.org", |
|---|
| 1919 | n/a | description = "A high-level object-oriented programming language", |
|---|
| 1920 | n/a | long_description = SUMMARY.strip(), |
|---|
| 1921 | n/a | license = "PSF license", |
|---|
| 1922 | n/a | classifiers = filter(None, CLASSIFIERS.split("\n")), |
|---|
| 1923 | n/a | platforms = ["Many"], |
|---|
| 1924 | n/a | |
|---|
| 1925 | n/a | # Build info |
|---|
| 1926 | n/a | cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall, |
|---|
| 1927 | n/a | 'install_lib':PyBuildInstallLib}, |
|---|
| 1928 | n/a | # The struct module is defined here, because build_ext won't be |
|---|
| 1929 | n/a | # called unless there's at least one extension module defined. |
|---|
| 1930 | n/a | ext_modules=[Extension('_struct', ['_struct.c'])], |
|---|
| 1931 | n/a | |
|---|
| 1932 | n/a | # Scripts to install |
|---|
| 1933 | n/a | scripts = ['Tools/scripts/pydoc', 'Tools/scripts/idle', |
|---|
| 1934 | n/a | 'Tools/scripts/2to3', |
|---|
| 1935 | n/a | 'Lib/smtpd.py'] |
|---|
| 1936 | n/a | ) |
|---|
| 1937 | n/a | |
|---|
| 1938 | n/a | # --install-platlib |
|---|
| 1939 | n/a | if __name__ == '__main__': |
|---|
| 1940 | n/a | main() |
|---|