| 1 | n/a | # Autodetecting setup.py script for building the Python extensions |
|---|
| 2 | n/a | # |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | import sys, os, importlib.machinery, re, optparse |
|---|
| 5 | n/a | from glob import glob |
|---|
| 6 | n/a | import importlib._bootstrap |
|---|
| 7 | n/a | import importlib.util |
|---|
| 8 | n/a | import sysconfig |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | from distutils import log |
|---|
| 11 | n/a | from distutils.errors import * |
|---|
| 12 | n/a | from distutils.core import Extension, setup |
|---|
| 13 | n/a | from distutils.command.build_ext import build_ext |
|---|
| 14 | n/a | from distutils.command.install import install |
|---|
| 15 | n/a | from distutils.command.install_lib import install_lib |
|---|
| 16 | n/a | from distutils.command.build_scripts import build_scripts |
|---|
| 17 | n/a | from distutils.spawn import find_executable |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | # Add special CFLAGS reserved for building the interpreter and the stdlib |
|---|
| 22 | n/a | # modules (Issue #21121). |
|---|
| 23 | n/a | cflags = sysconfig.get_config_var('CFLAGS') |
|---|
| 24 | n/a | py_cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST') |
|---|
| 25 | n/a | sysconfig.get_config_vars()['CFLAGS'] = cflags + ' ' + py_cflags_nodist |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | class Dummy: |
|---|
| 28 | n/a | """Hack for parallel build""" |
|---|
| 29 | n/a | ProcessPoolExecutor = None |
|---|
| 30 | n/a | sys.modules['concurrent.futures.process'] = Dummy |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | def get_platform(): |
|---|
| 33 | n/a | # cross build |
|---|
| 34 | n/a | if "_PYTHON_HOST_PLATFORM" in os.environ: |
|---|
| 35 | n/a | return os.environ["_PYTHON_HOST_PLATFORM"] |
|---|
| 36 | n/a | # Get value of sys.platform |
|---|
| 37 | n/a | if sys.platform.startswith('osf1'): |
|---|
| 38 | n/a | return 'osf1' |
|---|
| 39 | n/a | return sys.platform |
|---|
| 40 | n/a | host_platform = get_platform() |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | # Were we compiled --with-pydebug or with #define Py_DEBUG? |
|---|
| 43 | n/a | COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS")) |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | # This global variable is used to hold the list of modules to be disabled. |
|---|
| 46 | n/a | disabled_module_list = [] |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | def add_dir_to_list(dirlist, dir): |
|---|
| 49 | n/a | """Add the directory 'dir' to the list 'dirlist' (after any relative |
|---|
| 50 | n/a | directories) if: |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | 1) 'dir' is not already in 'dirlist' |
|---|
| 53 | n/a | 2) 'dir' actually exists, and is a directory. |
|---|
| 54 | n/a | """ |
|---|
| 55 | n/a | if dir is None or not os.path.isdir(dir) or dir in dirlist: |
|---|
| 56 | n/a | return |
|---|
| 57 | n/a | for i, path in enumerate(dirlist): |
|---|
| 58 | n/a | if not os.path.isabs(path): |
|---|
| 59 | n/a | dirlist.insert(i + 1, dir) |
|---|
| 60 | n/a | return |
|---|
| 61 | n/a | dirlist.insert(0, dir) |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | def macosx_sdk_root(): |
|---|
| 64 | n/a | """ |
|---|
| 65 | n/a | Return the directory of the current OSX SDK, |
|---|
| 66 | n/a | or '/' if no SDK was specified. |
|---|
| 67 | n/a | """ |
|---|
| 68 | n/a | cflags = sysconfig.get_config_var('CFLAGS') |
|---|
| 69 | n/a | m = re.search(r'-isysroot\s+(\S+)', cflags) |
|---|
| 70 | n/a | if m is None: |
|---|
| 71 | n/a | sysroot = '/' |
|---|
| 72 | n/a | else: |
|---|
| 73 | n/a | sysroot = m.group(1) |
|---|
| 74 | n/a | return sysroot |
|---|
| 75 | n/a | |
|---|
| 76 | n/a | def is_macosx_sdk_path(path): |
|---|
| 77 | n/a | """ |
|---|
| 78 | n/a | Returns True if 'path' can be located in an OSX SDK |
|---|
| 79 | n/a | """ |
|---|
| 80 | n/a | return ( (path.startswith('/usr/') and not path.startswith('/usr/local')) |
|---|
| 81 | n/a | or path.startswith('/System/') |
|---|
| 82 | n/a | or path.startswith('/Library/') ) |
|---|
| 83 | n/a | |
|---|
| 84 | n/a | def find_file(filename, std_dirs, paths): |
|---|
| 85 | n/a | """Searches for the directory where a given file is located, |
|---|
| 86 | n/a | and returns a possibly-empty list of additional directories, or None |
|---|
| 87 | n/a | if the file couldn't be found at all. |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | 'filename' is the name of a file, such as readline.h or libcrypto.a. |
|---|
| 90 | n/a | 'std_dirs' is the list of standard system directories; if the |
|---|
| 91 | n/a | file is found in one of them, no additional directives are needed. |
|---|
| 92 | n/a | 'paths' is a list of additional locations to check; if the file is |
|---|
| 93 | n/a | found in one of them, the resulting list will contain the directory. |
|---|
| 94 | n/a | """ |
|---|
| 95 | n/a | if host_platform == 'darwin': |
|---|
| 96 | n/a | # Honor the MacOSX SDK setting when one was specified. |
|---|
| 97 | n/a | # An SDK is a directory with the same structure as a real |
|---|
| 98 | n/a | # system, but with only header files and libraries. |
|---|
| 99 | n/a | sysroot = macosx_sdk_root() |
|---|
| 100 | n/a | |
|---|
| 101 | n/a | # Check the standard locations |
|---|
| 102 | n/a | for dir in std_dirs: |
|---|
| 103 | n/a | f = os.path.join(dir, filename) |
|---|
| 104 | n/a | |
|---|
| 105 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(dir): |
|---|
| 106 | n/a | f = os.path.join(sysroot, dir[1:], filename) |
|---|
| 107 | n/a | |
|---|
| 108 | n/a | if os.path.exists(f): return [] |
|---|
| 109 | n/a | |
|---|
| 110 | n/a | # Check the additional directories |
|---|
| 111 | n/a | for dir in paths: |
|---|
| 112 | n/a | f = os.path.join(dir, filename) |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(dir): |
|---|
| 115 | n/a | f = os.path.join(sysroot, dir[1:], filename) |
|---|
| 116 | n/a | |
|---|
| 117 | n/a | if os.path.exists(f): |
|---|
| 118 | n/a | return [dir] |
|---|
| 119 | n/a | |
|---|
| 120 | n/a | # Not found anywhere |
|---|
| 121 | n/a | return None |
|---|
| 122 | n/a | |
|---|
| 123 | n/a | def find_library_file(compiler, libname, std_dirs, paths): |
|---|
| 124 | n/a | result = compiler.find_library_file(std_dirs + paths, libname) |
|---|
| 125 | n/a | if result is None: |
|---|
| 126 | n/a | return None |
|---|
| 127 | n/a | |
|---|
| 128 | n/a | if host_platform == 'darwin': |
|---|
| 129 | n/a | sysroot = macosx_sdk_root() |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | # Check whether the found file is in one of the standard directories |
|---|
| 132 | n/a | dirname = os.path.dirname(result) |
|---|
| 133 | n/a | for p in std_dirs: |
|---|
| 134 | n/a | # Ensure path doesn't end with path separator |
|---|
| 135 | n/a | p = p.rstrip(os.sep) |
|---|
| 136 | n/a | |
|---|
| 137 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(p): |
|---|
| 138 | n/a | # Note that, as of Xcode 7, Apple SDKs may contain textual stub |
|---|
| 139 | n/a | # libraries with .tbd extensions rather than the normal .dylib |
|---|
| 140 | n/a | # shared libraries installed in /. The Apple compiler tool |
|---|
| 141 | n/a | # chain handles this transparently but it can cause problems |
|---|
| 142 | n/a | # for programs that are being built with an SDK and searching |
|---|
| 143 | n/a | # for specific libraries. Distutils find_library_file() now |
|---|
| 144 | n/a | # knows to also search for and return .tbd files. But callers |
|---|
| 145 | n/a | # of find_library_file need to keep in mind that the base filename |
|---|
| 146 | n/a | # of the returned SDK library file might have a different extension |
|---|
| 147 | n/a | # from that of the library file installed on the running system, |
|---|
| 148 | n/a | # for example: |
|---|
| 149 | n/a | # /Applications/Xcode.app/Contents/Developer/Platforms/ |
|---|
| 150 | n/a | # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ |
|---|
| 151 | n/a | # usr/lib/libedit.tbd |
|---|
| 152 | n/a | # vs |
|---|
| 153 | n/a | # /usr/lib/libedit.dylib |
|---|
| 154 | n/a | if os.path.join(sysroot, p[1:]) == dirname: |
|---|
| 155 | n/a | return [ ] |
|---|
| 156 | n/a | |
|---|
| 157 | n/a | if p == dirname: |
|---|
| 158 | n/a | return [ ] |
|---|
| 159 | n/a | |
|---|
| 160 | n/a | # Otherwise, it must have been in one of the additional directories, |
|---|
| 161 | n/a | # so we have to figure out which one. |
|---|
| 162 | n/a | for p in paths: |
|---|
| 163 | n/a | # Ensure path doesn't end with path separator |
|---|
| 164 | n/a | p = p.rstrip(os.sep) |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(p): |
|---|
| 167 | n/a | if os.path.join(sysroot, p[1:]) == dirname: |
|---|
| 168 | n/a | return [ p ] |
|---|
| 169 | n/a | |
|---|
| 170 | n/a | if p == dirname: |
|---|
| 171 | n/a | return [p] |
|---|
| 172 | n/a | else: |
|---|
| 173 | n/a | assert False, "Internal error: Path not found in std_dirs or paths" |
|---|
| 174 | n/a | |
|---|
| 175 | n/a | def module_enabled(extlist, modname): |
|---|
| 176 | n/a | """Returns whether the module 'modname' is present in the list |
|---|
| 177 | n/a | of extensions 'extlist'.""" |
|---|
| 178 | n/a | extlist = [ext for ext in extlist if ext.name == modname] |
|---|
| 179 | n/a | return len(extlist) |
|---|
| 180 | n/a | |
|---|
| 181 | n/a | def find_module_file(module, dirlist): |
|---|
| 182 | n/a | """Find a module in a set of possible folders. If it is not found |
|---|
| 183 | n/a | return the unadorned filename""" |
|---|
| 184 | n/a | list = find_file(module, [], dirlist) |
|---|
| 185 | n/a | if not list: |
|---|
| 186 | n/a | return module |
|---|
| 187 | n/a | if len(list) > 1: |
|---|
| 188 | n/a | log.info("WARNING: multiple copies of %s found", module) |
|---|
| 189 | n/a | return os.path.join(list[0], module) |
|---|
| 190 | n/a | |
|---|
| 191 | n/a | class PyBuildExt(build_ext): |
|---|
| 192 | n/a | |
|---|
| 193 | n/a | def __init__(self, dist): |
|---|
| 194 | n/a | build_ext.__init__(self, dist) |
|---|
| 195 | n/a | self.failed = [] |
|---|
| 196 | n/a | self.failed_on_import = [] |
|---|
| 197 | n/a | if '-j' in os.environ.get('MAKEFLAGS', ''): |
|---|
| 198 | n/a | self.parallel = True |
|---|
| 199 | n/a | |
|---|
| 200 | n/a | def build_extensions(self): |
|---|
| 201 | n/a | |
|---|
| 202 | n/a | # Detect which modules should be compiled |
|---|
| 203 | n/a | missing = self.detect_modules() |
|---|
| 204 | n/a | |
|---|
| 205 | n/a | # Remove modules that are present on the disabled list |
|---|
| 206 | n/a | extensions = [ext for ext in self.extensions |
|---|
| 207 | n/a | if ext.name not in disabled_module_list] |
|---|
| 208 | n/a | # move ctypes to the end, it depends on other modules |
|---|
| 209 | n/a | ext_map = dict((ext.name, i) for i, ext in enumerate(extensions)) |
|---|
| 210 | n/a | if "_ctypes" in ext_map: |
|---|
| 211 | n/a | ctypes = extensions.pop(ext_map["_ctypes"]) |
|---|
| 212 | n/a | extensions.append(ctypes) |
|---|
| 213 | n/a | self.extensions = extensions |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | # Fix up the autodetected modules, prefixing all the source files |
|---|
| 216 | n/a | # with Modules/. |
|---|
| 217 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 218 | n/a | if not srcdir: |
|---|
| 219 | n/a | # Maybe running on Windows but not using CYGWIN? |
|---|
| 220 | n/a | raise ValueError("No source directory; cannot proceed.") |
|---|
| 221 | n/a | srcdir = os.path.abspath(srcdir) |
|---|
| 222 | n/a | moddirlist = [os.path.join(srcdir, 'Modules')] |
|---|
| 223 | n/a | |
|---|
| 224 | n/a | # Fix up the paths for scripts, too |
|---|
| 225 | n/a | self.distribution.scripts = [os.path.join(srcdir, filename) |
|---|
| 226 | n/a | for filename in self.distribution.scripts] |
|---|
| 227 | n/a | |
|---|
| 228 | n/a | # Python header files |
|---|
| 229 | n/a | headers = [sysconfig.get_config_h_filename()] |
|---|
| 230 | n/a | headers += glob(os.path.join(sysconfig.get_path('include'), "*.h")) |
|---|
| 231 | n/a | |
|---|
| 232 | n/a | # The sysconfig variable built by makesetup, listing the already |
|---|
| 233 | n/a | # built modules as configured by the Setup files. |
|---|
| 234 | n/a | modnames = sysconfig.get_config_var('MODNAMES').split() |
|---|
| 235 | n/a | |
|---|
| 236 | n/a | removed_modules = [] |
|---|
| 237 | n/a | for ext in self.extensions: |
|---|
| 238 | n/a | ext.sources = [ find_module_file(filename, moddirlist) |
|---|
| 239 | n/a | for filename in ext.sources ] |
|---|
| 240 | n/a | if ext.depends is not None: |
|---|
| 241 | n/a | ext.depends = [find_module_file(filename, moddirlist) |
|---|
| 242 | n/a | for filename in ext.depends] |
|---|
| 243 | n/a | else: |
|---|
| 244 | n/a | ext.depends = [] |
|---|
| 245 | n/a | # re-compile extensions if a header file has been changed |
|---|
| 246 | n/a | ext.depends.extend(headers) |
|---|
| 247 | n/a | |
|---|
| 248 | n/a | # If a module has already been built by the Makefile, |
|---|
| 249 | n/a | # don't build it here. |
|---|
| 250 | n/a | if ext.name in modnames: |
|---|
| 251 | n/a | removed_modules.append(ext) |
|---|
| 252 | n/a | |
|---|
| 253 | n/a | if removed_modules: |
|---|
| 254 | n/a | self.extensions = [x for x in self.extensions if x not in |
|---|
| 255 | n/a | removed_modules] |
|---|
| 256 | n/a | |
|---|
| 257 | n/a | # When you run "make CC=altcc" or something similar, you really want |
|---|
| 258 | n/a | # those environment variables passed into the setup.py phase. Here's |
|---|
| 259 | n/a | # a small set of useful ones. |
|---|
| 260 | n/a | compiler = os.environ.get('CC') |
|---|
| 261 | n/a | args = {} |
|---|
| 262 | n/a | # unfortunately, distutils doesn't let us provide separate C and C++ |
|---|
| 263 | n/a | # compilers |
|---|
| 264 | n/a | if compiler is not None: |
|---|
| 265 | n/a | (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') |
|---|
| 266 | n/a | args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags |
|---|
| 267 | n/a | self.compiler.set_executables(**args) |
|---|
| 268 | n/a | |
|---|
| 269 | n/a | build_ext.build_extensions(self) |
|---|
| 270 | n/a | |
|---|
| 271 | n/a | for ext in self.extensions: |
|---|
| 272 | n/a | self.check_extension_import(ext) |
|---|
| 273 | n/a | |
|---|
| 274 | n/a | longest = max([len(e.name) for e in self.extensions], default=0) |
|---|
| 275 | n/a | if self.failed or self.failed_on_import: |
|---|
| 276 | n/a | all_failed = self.failed + self.failed_on_import |
|---|
| 277 | n/a | longest = max(longest, max([len(name) for name in all_failed])) |
|---|
| 278 | n/a | |
|---|
| 279 | n/a | def print_three_column(lst): |
|---|
| 280 | n/a | lst.sort(key=str.lower) |
|---|
| 281 | n/a | # guarantee zip() doesn't drop anything |
|---|
| 282 | n/a | while len(lst) % 3: |
|---|
| 283 | n/a | lst.append("") |
|---|
| 284 | n/a | for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]): |
|---|
| 285 | n/a | print("%-*s %-*s %-*s" % (longest, e, longest, f, |
|---|
| 286 | n/a | longest, g)) |
|---|
| 287 | n/a | |
|---|
| 288 | n/a | if missing: |
|---|
| 289 | n/a | print() |
|---|
| 290 | n/a | print("Python build finished successfully!") |
|---|
| 291 | n/a | print("The necessary bits to build these optional modules were not " |
|---|
| 292 | n/a | "found:") |
|---|
| 293 | n/a | print_three_column(missing) |
|---|
| 294 | n/a | print("To find the necessary bits, look in setup.py in" |
|---|
| 295 | n/a | " detect_modules() for the module's name.") |
|---|
| 296 | n/a | print() |
|---|
| 297 | n/a | |
|---|
| 298 | n/a | if removed_modules: |
|---|
| 299 | n/a | print("The following modules found by detect_modules() in" |
|---|
| 300 | n/a | " setup.py, have been") |
|---|
| 301 | n/a | print("built by the Makefile instead, as configured by the" |
|---|
| 302 | n/a | " Setup files:") |
|---|
| 303 | n/a | print_three_column([ext.name for ext in removed_modules]) |
|---|
| 304 | n/a | |
|---|
| 305 | n/a | if self.failed: |
|---|
| 306 | n/a | failed = self.failed[:] |
|---|
| 307 | n/a | print() |
|---|
| 308 | n/a | print("Failed to build these modules:") |
|---|
| 309 | n/a | print_three_column(failed) |
|---|
| 310 | n/a | print() |
|---|
| 311 | n/a | |
|---|
| 312 | n/a | if self.failed_on_import: |
|---|
| 313 | n/a | failed = self.failed_on_import[:] |
|---|
| 314 | n/a | print() |
|---|
| 315 | n/a | print("Following modules built successfully" |
|---|
| 316 | n/a | " but were removed because they could not be imported:") |
|---|
| 317 | n/a | print_three_column(failed) |
|---|
| 318 | n/a | print() |
|---|
| 319 | n/a | |
|---|
| 320 | n/a | def build_extension(self, ext): |
|---|
| 321 | n/a | |
|---|
| 322 | n/a | if ext.name == '_ctypes': |
|---|
| 323 | n/a | if not self.configure_ctypes(ext): |
|---|
| 324 | n/a | self.failed.append(ext.name) |
|---|
| 325 | n/a | return |
|---|
| 326 | n/a | |
|---|
| 327 | n/a | try: |
|---|
| 328 | n/a | build_ext.build_extension(self, ext) |
|---|
| 329 | n/a | except (CCompilerError, DistutilsError) as why: |
|---|
| 330 | n/a | self.announce('WARNING: building of extension "%s" failed: %s' % |
|---|
| 331 | n/a | (ext.name, sys.exc_info()[1])) |
|---|
| 332 | n/a | self.failed.append(ext.name) |
|---|
| 333 | n/a | return |
|---|
| 334 | n/a | |
|---|
| 335 | n/a | def check_extension_import(self, ext): |
|---|
| 336 | n/a | # Don't try to import an extension that has failed to compile |
|---|
| 337 | n/a | if ext.name in self.failed: |
|---|
| 338 | n/a | self.announce( |
|---|
| 339 | n/a | 'WARNING: skipping import check for failed build "%s"' % |
|---|
| 340 | n/a | ext.name, level=1) |
|---|
| 341 | n/a | return |
|---|
| 342 | n/a | |
|---|
| 343 | n/a | # Workaround for Mac OS X: The Carbon-based modules cannot be |
|---|
| 344 | n/a | # reliably imported into a command-line Python |
|---|
| 345 | n/a | if 'Carbon' in ext.extra_link_args: |
|---|
| 346 | n/a | self.announce( |
|---|
| 347 | n/a | 'WARNING: skipping import check for Carbon-based "%s"' % |
|---|
| 348 | n/a | ext.name) |
|---|
| 349 | n/a | return |
|---|
| 350 | n/a | |
|---|
| 351 | n/a | if host_platform == 'darwin' and ( |
|---|
| 352 | n/a | sys.maxsize > 2**32 and '-arch' in ext.extra_link_args): |
|---|
| 353 | n/a | # Don't bother doing an import check when an extension was |
|---|
| 354 | n/a | # build with an explicit '-arch' flag on OSX. That's currently |
|---|
| 355 | n/a | # only used to build 32-bit only extensions in a 4-way |
|---|
| 356 | n/a | # universal build and loading 32-bit code into a 64-bit |
|---|
| 357 | n/a | # process will fail. |
|---|
| 358 | n/a | self.announce( |
|---|
| 359 | n/a | 'WARNING: skipping import check for "%s"' % |
|---|
| 360 | n/a | ext.name) |
|---|
| 361 | n/a | return |
|---|
| 362 | n/a | |
|---|
| 363 | n/a | # Workaround for Cygwin: Cygwin currently has fork issues when many |
|---|
| 364 | n/a | # modules have been imported |
|---|
| 365 | n/a | if host_platform == 'cygwin': |
|---|
| 366 | n/a | self.announce('WARNING: skipping import check for Cygwin-based "%s"' |
|---|
| 367 | n/a | % ext.name) |
|---|
| 368 | n/a | return |
|---|
| 369 | n/a | ext_filename = os.path.join( |
|---|
| 370 | n/a | self.build_lib, |
|---|
| 371 | n/a | self.get_ext_filename(self.get_ext_fullname(ext.name))) |
|---|
| 372 | n/a | |
|---|
| 373 | n/a | # If the build directory didn't exist when setup.py was |
|---|
| 374 | n/a | # started, sys.path_importer_cache has a negative result |
|---|
| 375 | n/a | # cached. Clear that cache before trying to import. |
|---|
| 376 | n/a | sys.path_importer_cache.clear() |
|---|
| 377 | n/a | |
|---|
| 378 | n/a | # Don't try to load extensions for cross builds |
|---|
| 379 | n/a | if cross_compiling: |
|---|
| 380 | n/a | return |
|---|
| 381 | n/a | |
|---|
| 382 | n/a | loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename) |
|---|
| 383 | n/a | spec = importlib.util.spec_from_file_location(ext.name, ext_filename, |
|---|
| 384 | n/a | loader=loader) |
|---|
| 385 | n/a | try: |
|---|
| 386 | n/a | importlib._bootstrap._load(spec) |
|---|
| 387 | n/a | except ImportError as why: |
|---|
| 388 | n/a | self.failed_on_import.append(ext.name) |
|---|
| 389 | n/a | self.announce('*** WARNING: renaming "%s" since importing it' |
|---|
| 390 | n/a | ' failed: %s' % (ext.name, why), level=3) |
|---|
| 391 | n/a | assert not self.inplace |
|---|
| 392 | n/a | basename, tail = os.path.splitext(ext_filename) |
|---|
| 393 | n/a | newname = basename + "_failed" + tail |
|---|
| 394 | n/a | if os.path.exists(newname): |
|---|
| 395 | n/a | os.remove(newname) |
|---|
| 396 | n/a | os.rename(ext_filename, newname) |
|---|
| 397 | n/a | |
|---|
| 398 | n/a | except: |
|---|
| 399 | n/a | exc_type, why, tb = sys.exc_info() |
|---|
| 400 | n/a | self.announce('*** WARNING: importing extension "%s" ' |
|---|
| 401 | n/a | 'failed with %s: %s' % (ext.name, exc_type, why), |
|---|
| 402 | n/a | level=3) |
|---|
| 403 | n/a | self.failed.append(ext.name) |
|---|
| 404 | n/a | |
|---|
| 405 | n/a | def add_multiarch_paths(self): |
|---|
| 406 | n/a | # Debian/Ubuntu multiarch support. |
|---|
| 407 | n/a | # https://wiki.ubuntu.com/MultiarchSpec |
|---|
| 408 | n/a | cc = sysconfig.get_config_var('CC') |
|---|
| 409 | n/a | tmpfile = os.path.join(self.build_temp, 'multiarch') |
|---|
| 410 | n/a | if not os.path.exists(self.build_temp): |
|---|
| 411 | n/a | os.makedirs(self.build_temp) |
|---|
| 412 | n/a | ret = os.system( |
|---|
| 413 | n/a | '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile)) |
|---|
| 414 | n/a | multiarch_path_component = '' |
|---|
| 415 | n/a | try: |
|---|
| 416 | n/a | if ret >> 8 == 0: |
|---|
| 417 | n/a | with open(tmpfile) as fp: |
|---|
| 418 | n/a | multiarch_path_component = fp.readline().strip() |
|---|
| 419 | n/a | finally: |
|---|
| 420 | n/a | os.unlink(tmpfile) |
|---|
| 421 | n/a | |
|---|
| 422 | n/a | if multiarch_path_component != '': |
|---|
| 423 | n/a | add_dir_to_list(self.compiler.library_dirs, |
|---|
| 424 | n/a | '/usr/lib/' + multiarch_path_component) |
|---|
| 425 | n/a | add_dir_to_list(self.compiler.include_dirs, |
|---|
| 426 | n/a | '/usr/include/' + multiarch_path_component) |
|---|
| 427 | n/a | return |
|---|
| 428 | n/a | |
|---|
| 429 | n/a | if not find_executable('dpkg-architecture'): |
|---|
| 430 | n/a | return |
|---|
| 431 | n/a | opt = '' |
|---|
| 432 | n/a | if cross_compiling: |
|---|
| 433 | n/a | opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE') |
|---|
| 434 | n/a | tmpfile = os.path.join(self.build_temp, 'multiarch') |
|---|
| 435 | n/a | if not os.path.exists(self.build_temp): |
|---|
| 436 | n/a | os.makedirs(self.build_temp) |
|---|
| 437 | n/a | ret = os.system( |
|---|
| 438 | n/a | 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' % |
|---|
| 439 | n/a | (opt, tmpfile)) |
|---|
| 440 | n/a | try: |
|---|
| 441 | n/a | if ret >> 8 == 0: |
|---|
| 442 | n/a | with open(tmpfile) as fp: |
|---|
| 443 | n/a | multiarch_path_component = fp.readline().strip() |
|---|
| 444 | n/a | add_dir_to_list(self.compiler.library_dirs, |
|---|
| 445 | n/a | '/usr/lib/' + multiarch_path_component) |
|---|
| 446 | n/a | add_dir_to_list(self.compiler.include_dirs, |
|---|
| 447 | n/a | '/usr/include/' + multiarch_path_component) |
|---|
| 448 | n/a | finally: |
|---|
| 449 | n/a | os.unlink(tmpfile) |
|---|
| 450 | n/a | |
|---|
| 451 | n/a | def add_gcc_paths(self): |
|---|
| 452 | n/a | gcc = sysconfig.get_config_var('CC') |
|---|
| 453 | n/a | tmpfile = os.path.join(self.build_temp, 'gccpaths') |
|---|
| 454 | n/a | if not os.path.exists(self.build_temp): |
|---|
| 455 | n/a | os.makedirs(self.build_temp) |
|---|
| 456 | n/a | ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile)) |
|---|
| 457 | n/a | is_gcc = False |
|---|
| 458 | n/a | in_incdirs = False |
|---|
| 459 | n/a | inc_dirs = [] |
|---|
| 460 | n/a | lib_dirs = [] |
|---|
| 461 | n/a | try: |
|---|
| 462 | n/a | if ret >> 8 == 0: |
|---|
| 463 | n/a | with open(tmpfile) as fp: |
|---|
| 464 | n/a | for line in fp.readlines(): |
|---|
| 465 | n/a | if line.startswith("gcc version"): |
|---|
| 466 | n/a | is_gcc = True |
|---|
| 467 | n/a | elif line.startswith("#include <...>"): |
|---|
| 468 | n/a | in_incdirs = True |
|---|
| 469 | n/a | elif line.startswith("End of search list"): |
|---|
| 470 | n/a | in_incdirs = False |
|---|
| 471 | n/a | elif is_gcc and line.startswith("LIBRARY_PATH"): |
|---|
| 472 | n/a | for d in line.strip().split("=")[1].split(":"): |
|---|
| 473 | n/a | d = os.path.normpath(d) |
|---|
| 474 | n/a | if '/gcc/' not in d: |
|---|
| 475 | n/a | add_dir_to_list(self.compiler.library_dirs, |
|---|
| 476 | n/a | d) |
|---|
| 477 | n/a | elif is_gcc and in_incdirs and '/gcc/' not in line: |
|---|
| 478 | n/a | add_dir_to_list(self.compiler.include_dirs, |
|---|
| 479 | n/a | line.strip()) |
|---|
| 480 | n/a | finally: |
|---|
| 481 | n/a | os.unlink(tmpfile) |
|---|
| 482 | n/a | |
|---|
| 483 | n/a | def detect_math_libs(self): |
|---|
| 484 | n/a | # Check for MacOS X, which doesn't need libm.a at all |
|---|
| 485 | n/a | if host_platform == 'darwin': |
|---|
| 486 | n/a | return [] |
|---|
| 487 | n/a | else: |
|---|
| 488 | n/a | return ['m'] |
|---|
| 489 | n/a | |
|---|
| 490 | n/a | def detect_modules(self): |
|---|
| 491 | n/a | # Ensure that /usr/local is always used, but the local build |
|---|
| 492 | n/a | # directories (i.e. '.' and 'Include') must be first. See issue |
|---|
| 493 | n/a | # 10520. |
|---|
| 494 | n/a | if not cross_compiling: |
|---|
| 495 | n/a | add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') |
|---|
| 496 | n/a | add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') |
|---|
| 497 | n/a | # only change this for cross builds for 3.3, issues on Mageia |
|---|
| 498 | n/a | if cross_compiling: |
|---|
| 499 | n/a | self.add_gcc_paths() |
|---|
| 500 | n/a | self.add_multiarch_paths() |
|---|
| 501 | n/a | |
|---|
| 502 | n/a | # Add paths specified in the environment variables LDFLAGS and |
|---|
| 503 | n/a | # CPPFLAGS for header and library files. |
|---|
| 504 | n/a | # We must get the values from the Makefile and not the environment |
|---|
| 505 | n/a | # directly since an inconsistently reproducible issue comes up where |
|---|
| 506 | n/a | # the environment variable is not set even though the value were passed |
|---|
| 507 | n/a | # into configure and stored in the Makefile (issue found on OS X 10.3). |
|---|
| 508 | n/a | for env_var, arg_name, dir_list in ( |
|---|
| 509 | n/a | ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), |
|---|
| 510 | n/a | ('LDFLAGS', '-L', self.compiler.library_dirs), |
|---|
| 511 | n/a | ('CPPFLAGS', '-I', self.compiler.include_dirs)): |
|---|
| 512 | n/a | env_val = sysconfig.get_config_var(env_var) |
|---|
| 513 | n/a | if env_val: |
|---|
| 514 | n/a | # To prevent optparse from raising an exception about any |
|---|
| 515 | n/a | # options in env_val that it doesn't know about we strip out |
|---|
| 516 | n/a | # all double dashes and any dashes followed by a character |
|---|
| 517 | n/a | # that is not for the option we are dealing with. |
|---|
| 518 | n/a | # |
|---|
| 519 | n/a | # Please note that order of the regex is important! We must |
|---|
| 520 | n/a | # strip out double-dashes first so that we don't end up with |
|---|
| 521 | n/a | # substituting "--Long" to "-Long" and thus lead to "ong" being |
|---|
| 522 | n/a | # used for a library directory. |
|---|
| 523 | n/a | env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], |
|---|
| 524 | n/a | ' ', env_val) |
|---|
| 525 | n/a | parser = optparse.OptionParser() |
|---|
| 526 | n/a | # Make sure that allowing args interspersed with options is |
|---|
| 527 | n/a | # allowed |
|---|
| 528 | n/a | parser.allow_interspersed_args = True |
|---|
| 529 | n/a | parser.error = lambda msg: None |
|---|
| 530 | n/a | parser.add_option(arg_name, dest="dirs", action="append") |
|---|
| 531 | n/a | options = parser.parse_args(env_val.split())[0] |
|---|
| 532 | n/a | if options.dirs: |
|---|
| 533 | n/a | for directory in reversed(options.dirs): |
|---|
| 534 | n/a | add_dir_to_list(dir_list, directory) |
|---|
| 535 | n/a | |
|---|
| 536 | n/a | if (not cross_compiling and |
|---|
| 537 | n/a | os.path.normpath(sys.base_prefix) != '/usr' and |
|---|
| 538 | n/a | not sysconfig.get_config_var('PYTHONFRAMEWORK')): |
|---|
| 539 | n/a | # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework |
|---|
| 540 | n/a | # (PYTHONFRAMEWORK is set) to avoid # linking problems when |
|---|
| 541 | n/a | # building a framework with different architectures than |
|---|
| 542 | n/a | # the one that is currently installed (issue #7473) |
|---|
| 543 | n/a | add_dir_to_list(self.compiler.library_dirs, |
|---|
| 544 | n/a | sysconfig.get_config_var("LIBDIR")) |
|---|
| 545 | n/a | add_dir_to_list(self.compiler.include_dirs, |
|---|
| 546 | n/a | sysconfig.get_config_var("INCLUDEDIR")) |
|---|
| 547 | n/a | |
|---|
| 548 | n/a | # lib_dirs and inc_dirs are used to search for files; |
|---|
| 549 | n/a | # if a file is found in one of those directories, it can |
|---|
| 550 | n/a | # be assumed that no additional -I,-L directives are needed. |
|---|
| 551 | n/a | if not cross_compiling: |
|---|
| 552 | n/a | lib_dirs = self.compiler.library_dirs + [ |
|---|
| 553 | n/a | '/lib64', '/usr/lib64', |
|---|
| 554 | n/a | '/lib', '/usr/lib', |
|---|
| 555 | n/a | ] |
|---|
| 556 | n/a | inc_dirs = self.compiler.include_dirs + ['/usr/include'] |
|---|
| 557 | n/a | else: |
|---|
| 558 | n/a | lib_dirs = self.compiler.library_dirs[:] |
|---|
| 559 | n/a | inc_dirs = self.compiler.include_dirs[:] |
|---|
| 560 | n/a | exts = [] |
|---|
| 561 | n/a | missing = [] |
|---|
| 562 | n/a | |
|---|
| 563 | n/a | config_h = sysconfig.get_config_h_filename() |
|---|
| 564 | n/a | with open(config_h) as file: |
|---|
| 565 | n/a | config_h_vars = sysconfig.parse_config_h(file) |
|---|
| 566 | n/a | |
|---|
| 567 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 568 | n/a | |
|---|
| 569 | n/a | # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) |
|---|
| 570 | n/a | if host_platform in ['osf1', 'unixware7', 'openunix8']: |
|---|
| 571 | n/a | lib_dirs += ['/usr/ccs/lib'] |
|---|
| 572 | n/a | |
|---|
| 573 | n/a | # HP-UX11iv3 keeps files in lib/hpux folders. |
|---|
| 574 | n/a | if host_platform == 'hp-ux11': |
|---|
| 575 | n/a | lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] |
|---|
| 576 | n/a | |
|---|
| 577 | n/a | if host_platform == 'darwin': |
|---|
| 578 | n/a | # This should work on any unixy platform ;-) |
|---|
| 579 | n/a | # If the user has bothered specifying additional -I and -L flags |
|---|
| 580 | n/a | # in OPT and LDFLAGS we might as well use them here. |
|---|
| 581 | n/a | # |
|---|
| 582 | n/a | # NOTE: using shlex.split would technically be more correct, but |
|---|
| 583 | n/a | # also gives a bootstrap problem. Let's hope nobody uses |
|---|
| 584 | n/a | # directories with whitespace in the name to store libraries. |
|---|
| 585 | n/a | cflags, ldflags = sysconfig.get_config_vars( |
|---|
| 586 | n/a | 'CFLAGS', 'LDFLAGS') |
|---|
| 587 | n/a | for item in cflags.split(): |
|---|
| 588 | n/a | if item.startswith('-I'): |
|---|
| 589 | n/a | inc_dirs.append(item[2:]) |
|---|
| 590 | n/a | |
|---|
| 591 | n/a | for item in ldflags.split(): |
|---|
| 592 | n/a | if item.startswith('-L'): |
|---|
| 593 | n/a | lib_dirs.append(item[2:]) |
|---|
| 594 | n/a | |
|---|
| 595 | n/a | math_libs = self.detect_math_libs() |
|---|
| 596 | n/a | |
|---|
| 597 | n/a | # XXX Omitted modules: gl, pure, dl, SGI-specific modules |
|---|
| 598 | n/a | |
|---|
| 599 | n/a | # |
|---|
| 600 | n/a | # The following modules are all pretty straightforward, and compile |
|---|
| 601 | n/a | # on pretty much any POSIXish platform. |
|---|
| 602 | n/a | # |
|---|
| 603 | n/a | |
|---|
| 604 | n/a | # array objects |
|---|
| 605 | n/a | exts.append( Extension('array', ['arraymodule.c']) ) |
|---|
| 606 | n/a | |
|---|
| 607 | n/a | shared_math = 'Modules/_math.o' |
|---|
| 608 | n/a | # complex math library functions |
|---|
| 609 | n/a | exts.append( Extension('cmath', ['cmathmodule.c'], |
|---|
| 610 | n/a | extra_objects=[shared_math], |
|---|
| 611 | n/a | depends=['_math.h', shared_math], |
|---|
| 612 | n/a | libraries=math_libs) ) |
|---|
| 613 | n/a | # math library functions, e.g. sin() |
|---|
| 614 | n/a | exts.append( Extension('math', ['mathmodule.c'], |
|---|
| 615 | n/a | extra_objects=[shared_math], |
|---|
| 616 | n/a | depends=['_math.h', shared_math], |
|---|
| 617 | n/a | libraries=math_libs) ) |
|---|
| 618 | n/a | |
|---|
| 619 | n/a | # time libraries: librt may be needed for clock_gettime() |
|---|
| 620 | n/a | time_libs = [] |
|---|
| 621 | n/a | lib = sysconfig.get_config_var('TIMEMODULE_LIB') |
|---|
| 622 | n/a | if lib: |
|---|
| 623 | n/a | time_libs.append(lib) |
|---|
| 624 | n/a | |
|---|
| 625 | n/a | # time operations and variables |
|---|
| 626 | n/a | exts.append( Extension('time', ['timemodule.c'], |
|---|
| 627 | n/a | libraries=time_libs) ) |
|---|
| 628 | n/a | # math_libs is needed by delta_new() that uses round() and by accum() |
|---|
| 629 | n/a | # that uses modf(). |
|---|
| 630 | n/a | exts.append( Extension('_datetime', ['_datetimemodule.c'], |
|---|
| 631 | n/a | libraries=math_libs) ) |
|---|
| 632 | n/a | # random number generator implemented in C |
|---|
| 633 | n/a | exts.append( Extension("_random", ["_randommodule.c"]) ) |
|---|
| 634 | n/a | # bisect |
|---|
| 635 | n/a | exts.append( Extension("_bisect", ["_bisectmodule.c"]) ) |
|---|
| 636 | n/a | # heapq |
|---|
| 637 | n/a | exts.append( Extension("_heapq", ["_heapqmodule.c"]) ) |
|---|
| 638 | n/a | # C-optimized pickle replacement |
|---|
| 639 | n/a | exts.append( Extension("_pickle", ["_pickle.c"]) ) |
|---|
| 640 | n/a | # atexit |
|---|
| 641 | n/a | exts.append( Extension("atexit", ["atexitmodule.c"]) ) |
|---|
| 642 | n/a | # _json speedups |
|---|
| 643 | n/a | exts.append( Extension("_json", ["_json.c"]) ) |
|---|
| 644 | n/a | # Python C API test module |
|---|
| 645 | n/a | exts.append( Extension('_testcapi', ['_testcapimodule.c'], |
|---|
| 646 | n/a | depends=['testcapi_long.h']) ) |
|---|
| 647 | n/a | # Python PEP-3118 (buffer protocol) test module |
|---|
| 648 | n/a | exts.append( Extension('_testbuffer', ['_testbuffer.c']) ) |
|---|
| 649 | n/a | # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421) |
|---|
| 650 | n/a | exts.append( Extension('_testimportmultiple', ['_testimportmultiple.c']) ) |
|---|
| 651 | n/a | # Test multi-phase extension module init (PEP 489) |
|---|
| 652 | n/a | exts.append( Extension('_testmultiphase', ['_testmultiphase.c']) ) |
|---|
| 653 | n/a | # profiler (_lsprof is for cProfile.py) |
|---|
| 654 | n/a | exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) ) |
|---|
| 655 | n/a | # static Unicode character database |
|---|
| 656 | n/a | exts.append( Extension('unicodedata', ['unicodedata.c'], |
|---|
| 657 | n/a | depends=['unicodedata_db.h', 'unicodename_db.h']) ) |
|---|
| 658 | n/a | # _opcode module |
|---|
| 659 | n/a | exts.append( Extension('_opcode', ['_opcode.c']) ) |
|---|
| 660 | n/a | # asyncio speedups |
|---|
| 661 | n/a | exts.append( Extension("_asyncio", ["_asynciomodule.c"]) ) |
|---|
| 662 | n/a | |
|---|
| 663 | n/a | # Modules with some UNIX dependencies -- on by default: |
|---|
| 664 | n/a | # (If you have a really backward UNIX, select and socket may not be |
|---|
| 665 | n/a | # supported...) |
|---|
| 666 | n/a | |
|---|
| 667 | n/a | # fcntl(2) and ioctl(2) |
|---|
| 668 | n/a | libs = [] |
|---|
| 669 | n/a | if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)): |
|---|
| 670 | n/a | # May be necessary on AIX for flock function |
|---|
| 671 | n/a | libs = ['bsd'] |
|---|
| 672 | n/a | exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) ) |
|---|
| 673 | n/a | # pwd(3) |
|---|
| 674 | n/a | exts.append( Extension('pwd', ['pwdmodule.c']) ) |
|---|
| 675 | n/a | # grp(3) |
|---|
| 676 | n/a | exts.append( Extension('grp', ['grpmodule.c']) ) |
|---|
| 677 | n/a | # spwd, shadow passwords |
|---|
| 678 | n/a | if (config_h_vars.get('HAVE_GETSPNAM', False) or |
|---|
| 679 | n/a | config_h_vars.get('HAVE_GETSPENT', False)): |
|---|
| 680 | n/a | exts.append( Extension('spwd', ['spwdmodule.c']) ) |
|---|
| 681 | n/a | else: |
|---|
| 682 | n/a | missing.append('spwd') |
|---|
| 683 | n/a | |
|---|
| 684 | n/a | # select(2); not on ancient System V |
|---|
| 685 | n/a | exts.append( Extension('select', ['selectmodule.c']) ) |
|---|
| 686 | n/a | |
|---|
| 687 | n/a | # Fred Drake's interface to the Python parser |
|---|
| 688 | n/a | exts.append( Extension('parser', ['parsermodule.c']) ) |
|---|
| 689 | n/a | |
|---|
| 690 | n/a | # Memory-mapped files (also works on Win32). |
|---|
| 691 | n/a | exts.append( Extension('mmap', ['mmapmodule.c']) ) |
|---|
| 692 | n/a | |
|---|
| 693 | n/a | # Lance Ellinghaus's syslog module |
|---|
| 694 | n/a | # syslog daemon interface |
|---|
| 695 | n/a | exts.append( Extension('syslog', ['syslogmodule.c']) ) |
|---|
| 696 | n/a | |
|---|
| 697 | n/a | # |
|---|
| 698 | n/a | # Here ends the simple stuff. From here on, modules need certain |
|---|
| 699 | n/a | # libraries, are platform-specific, or present other surprises. |
|---|
| 700 | n/a | # |
|---|
| 701 | n/a | |
|---|
| 702 | n/a | # Multimedia modules |
|---|
| 703 | n/a | # These don't work for 64-bit platforms!!! |
|---|
| 704 | n/a | # These represent audio samples or images as strings: |
|---|
| 705 | n/a | # |
|---|
| 706 | n/a | # Operations on audio samples |
|---|
| 707 | n/a | # According to #993173, this one should actually work fine on |
|---|
| 708 | n/a | # 64-bit platforms. |
|---|
| 709 | n/a | # |
|---|
| 710 | n/a | # audioop needs math_libs for floor() in multiple functions. |
|---|
| 711 | n/a | exts.append( Extension('audioop', ['audioop.c'], |
|---|
| 712 | n/a | libraries=math_libs) ) |
|---|
| 713 | n/a | |
|---|
| 714 | n/a | # readline |
|---|
| 715 | n/a | do_readline = self.compiler.find_library_file(lib_dirs, 'readline') |
|---|
| 716 | n/a | readline_termcap_library = "" |
|---|
| 717 | n/a | curses_library = "" |
|---|
| 718 | n/a | # Cannot use os.popen here in py3k. |
|---|
| 719 | n/a | tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib') |
|---|
| 720 | n/a | if not os.path.exists(self.build_temp): |
|---|
| 721 | n/a | os.makedirs(self.build_temp) |
|---|
| 722 | n/a | # Determine if readline is already linked against curses or tinfo. |
|---|
| 723 | n/a | if do_readline: |
|---|
| 724 | n/a | if cross_compiling: |
|---|
| 725 | n/a | ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \ |
|---|
| 726 | n/a | % (sysconfig.get_config_var('READELF'), |
|---|
| 727 | n/a | do_readline, tmpfile)) |
|---|
| 728 | n/a | elif find_executable('ldd'): |
|---|
| 729 | n/a | ret = os.system("ldd %s > %s" % (do_readline, tmpfile)) |
|---|
| 730 | n/a | else: |
|---|
| 731 | n/a | ret = 256 |
|---|
| 732 | n/a | if ret >> 8 == 0: |
|---|
| 733 | n/a | with open(tmpfile) as fp: |
|---|
| 734 | n/a | for ln in fp: |
|---|
| 735 | n/a | if 'curses' in ln: |
|---|
| 736 | n/a | readline_termcap_library = re.sub( |
|---|
| 737 | n/a | r'.*lib(n?cursesw?)\.so.*', r'\1', ln |
|---|
| 738 | n/a | ).rstrip() |
|---|
| 739 | n/a | break |
|---|
| 740 | n/a | # termcap interface split out from ncurses |
|---|
| 741 | n/a | if 'tinfo' in ln: |
|---|
| 742 | n/a | readline_termcap_library = 'tinfo' |
|---|
| 743 | n/a | break |
|---|
| 744 | n/a | if os.path.exists(tmpfile): |
|---|
| 745 | n/a | os.unlink(tmpfile) |
|---|
| 746 | n/a | # Issue 7384: If readline is already linked against curses, |
|---|
| 747 | n/a | # use the same library for the readline and curses modules. |
|---|
| 748 | n/a | if 'curses' in readline_termcap_library: |
|---|
| 749 | n/a | curses_library = readline_termcap_library |
|---|
| 750 | n/a | elif self.compiler.find_library_file(lib_dirs, 'ncursesw'): |
|---|
| 751 | n/a | curses_library = 'ncursesw' |
|---|
| 752 | n/a | elif self.compiler.find_library_file(lib_dirs, 'ncurses'): |
|---|
| 753 | n/a | curses_library = 'ncurses' |
|---|
| 754 | n/a | elif self.compiler.find_library_file(lib_dirs, 'curses'): |
|---|
| 755 | n/a | curses_library = 'curses' |
|---|
| 756 | n/a | |
|---|
| 757 | n/a | if host_platform == 'darwin': |
|---|
| 758 | n/a | os_release = int(os.uname()[2].split('.')[0]) |
|---|
| 759 | n/a | dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') |
|---|
| 760 | n/a | if (dep_target and |
|---|
| 761 | n/a | (tuple(int(n) for n in dep_target.split('.')[0:2]) |
|---|
| 762 | n/a | < (10, 5) ) ): |
|---|
| 763 | n/a | os_release = 8 |
|---|
| 764 | n/a | if os_release < 9: |
|---|
| 765 | n/a | # MacOSX 10.4 has a broken readline. Don't try to build |
|---|
| 766 | n/a | # the readline module unless the user has installed a fixed |
|---|
| 767 | n/a | # readline package |
|---|
| 768 | n/a | if find_file('readline/rlconf.h', inc_dirs, []) is None: |
|---|
| 769 | n/a | do_readline = False |
|---|
| 770 | n/a | if do_readline: |
|---|
| 771 | n/a | if host_platform == 'darwin' and os_release < 9: |
|---|
| 772 | n/a | # In every directory on the search path search for a dynamic |
|---|
| 773 | n/a | # library and then a static library, instead of first looking |
|---|
| 774 | n/a | # for dynamic libraries on the entire path. |
|---|
| 775 | n/a | # This way a statically linked custom readline gets picked up |
|---|
| 776 | n/a | # before the (possibly broken) dynamic library in /usr/lib. |
|---|
| 777 | n/a | readline_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 778 | n/a | else: |
|---|
| 779 | n/a | readline_extra_link_args = () |
|---|
| 780 | n/a | |
|---|
| 781 | n/a | readline_libs = ['readline'] |
|---|
| 782 | n/a | if readline_termcap_library: |
|---|
| 783 | n/a | pass # Issue 7384: Already linked against curses or tinfo. |
|---|
| 784 | n/a | elif curses_library: |
|---|
| 785 | n/a | readline_libs.append(curses_library) |
|---|
| 786 | n/a | elif self.compiler.find_library_file(lib_dirs + |
|---|
| 787 | n/a | ['/usr/lib/termcap'], |
|---|
| 788 | n/a | 'termcap'): |
|---|
| 789 | n/a | readline_libs.append('termcap') |
|---|
| 790 | n/a | exts.append( Extension('readline', ['readline.c'], |
|---|
| 791 | n/a | library_dirs=['/usr/lib/termcap'], |
|---|
| 792 | n/a | extra_link_args=readline_extra_link_args, |
|---|
| 793 | n/a | libraries=readline_libs) ) |
|---|
| 794 | n/a | else: |
|---|
| 795 | n/a | missing.append('readline') |
|---|
| 796 | n/a | |
|---|
| 797 | n/a | # crypt module. |
|---|
| 798 | n/a | |
|---|
| 799 | n/a | if self.compiler.find_library_file(lib_dirs, 'crypt'): |
|---|
| 800 | n/a | libs = ['crypt'] |
|---|
| 801 | n/a | else: |
|---|
| 802 | n/a | libs = [] |
|---|
| 803 | n/a | exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) |
|---|
| 804 | n/a | |
|---|
| 805 | n/a | # CSV files |
|---|
| 806 | n/a | exts.append( Extension('_csv', ['_csv.c']) ) |
|---|
| 807 | n/a | |
|---|
| 808 | n/a | # POSIX subprocess module helper. |
|---|
| 809 | n/a | exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) |
|---|
| 810 | n/a | |
|---|
| 811 | n/a | # socket(2) |
|---|
| 812 | n/a | exts.append( Extension('_socket', ['socketmodule.c'], |
|---|
| 813 | n/a | depends = ['socketmodule.h']) ) |
|---|
| 814 | n/a | # Detect SSL support for the socket module (via _ssl) |
|---|
| 815 | n/a | search_for_ssl_incs_in = [ |
|---|
| 816 | n/a | '/usr/local/ssl/include', |
|---|
| 817 | n/a | '/usr/contrib/ssl/include/' |
|---|
| 818 | n/a | ] |
|---|
| 819 | n/a | ssl_incs = find_file('openssl/ssl.h', inc_dirs, |
|---|
| 820 | n/a | search_for_ssl_incs_in |
|---|
| 821 | n/a | ) |
|---|
| 822 | n/a | if ssl_incs is not None: |
|---|
| 823 | n/a | krb5_h = find_file('krb5.h', inc_dirs, |
|---|
| 824 | n/a | ['/usr/kerberos/include']) |
|---|
| 825 | n/a | if krb5_h: |
|---|
| 826 | n/a | ssl_incs += krb5_h |
|---|
| 827 | n/a | ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, |
|---|
| 828 | n/a | ['/usr/local/ssl/lib', |
|---|
| 829 | n/a | '/usr/contrib/ssl/lib/' |
|---|
| 830 | n/a | ] ) |
|---|
| 831 | n/a | |
|---|
| 832 | n/a | if (ssl_incs is not None and |
|---|
| 833 | n/a | ssl_libs is not None): |
|---|
| 834 | n/a | exts.append( Extension('_ssl', ['_ssl.c'], |
|---|
| 835 | n/a | include_dirs = ssl_incs, |
|---|
| 836 | n/a | library_dirs = ssl_libs, |
|---|
| 837 | n/a | libraries = ['ssl', 'crypto'], |
|---|
| 838 | n/a | depends = ['socketmodule.h']), ) |
|---|
| 839 | n/a | else: |
|---|
| 840 | n/a | missing.append('_ssl') |
|---|
| 841 | n/a | |
|---|
| 842 | n/a | # find out which version of OpenSSL we have |
|---|
| 843 | n/a | openssl_ver = 0 |
|---|
| 844 | n/a | openssl_ver_re = re.compile( |
|---|
| 845 | n/a | r'^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' ) |
|---|
| 846 | n/a | |
|---|
| 847 | n/a | # look for the openssl version header on the compiler search path. |
|---|
| 848 | n/a | opensslv_h = find_file('openssl/opensslv.h', [], |
|---|
| 849 | n/a | inc_dirs + search_for_ssl_incs_in) |
|---|
| 850 | n/a | if opensslv_h: |
|---|
| 851 | n/a | name = os.path.join(opensslv_h[0], 'openssl/opensslv.h') |
|---|
| 852 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(name): |
|---|
| 853 | n/a | name = os.path.join(macosx_sdk_root(), name[1:]) |
|---|
| 854 | n/a | try: |
|---|
| 855 | n/a | with open(name, 'r') as incfile: |
|---|
| 856 | n/a | for line in incfile: |
|---|
| 857 | n/a | m = openssl_ver_re.match(line) |
|---|
| 858 | n/a | if m: |
|---|
| 859 | n/a | openssl_ver = int(m.group(1), 16) |
|---|
| 860 | n/a | break |
|---|
| 861 | n/a | except IOError as msg: |
|---|
| 862 | n/a | print("IOError while reading opensshv.h:", msg) |
|---|
| 863 | n/a | |
|---|
| 864 | n/a | #print('openssl_ver = 0x%08x' % openssl_ver) |
|---|
| 865 | n/a | min_openssl_ver = 0x00907000 |
|---|
| 866 | n/a | have_any_openssl = ssl_incs is not None and ssl_libs is not None |
|---|
| 867 | n/a | have_usable_openssl = (have_any_openssl and |
|---|
| 868 | n/a | openssl_ver >= min_openssl_ver) |
|---|
| 869 | n/a | |
|---|
| 870 | n/a | if have_any_openssl: |
|---|
| 871 | n/a | if have_usable_openssl: |
|---|
| 872 | n/a | # The _hashlib module wraps optimized implementations |
|---|
| 873 | n/a | # of hash functions from the OpenSSL library. |
|---|
| 874 | n/a | exts.append( Extension('_hashlib', ['_hashopenssl.c'], |
|---|
| 875 | n/a | depends = ['hashlib.h'], |
|---|
| 876 | n/a | include_dirs = ssl_incs, |
|---|
| 877 | n/a | library_dirs = ssl_libs, |
|---|
| 878 | n/a | libraries = ['ssl', 'crypto']) ) |
|---|
| 879 | n/a | else: |
|---|
| 880 | n/a | print("warning: openssl 0x%08x is too old for _hashlib" % |
|---|
| 881 | n/a | openssl_ver) |
|---|
| 882 | n/a | missing.append('_hashlib') |
|---|
| 883 | n/a | |
|---|
| 884 | n/a | # We always compile these even when OpenSSL is available (issue #14693). |
|---|
| 885 | n/a | # It's harmless and the object code is tiny (40-50 KB per module, |
|---|
| 886 | n/a | # only loaded when actually used). |
|---|
| 887 | n/a | exts.append( Extension('_sha256', ['sha256module.c'], |
|---|
| 888 | n/a | depends=['hashlib.h']) ) |
|---|
| 889 | n/a | exts.append( Extension('_sha512', ['sha512module.c'], |
|---|
| 890 | n/a | depends=['hashlib.h']) ) |
|---|
| 891 | n/a | exts.append( Extension('_md5', ['md5module.c'], |
|---|
| 892 | n/a | depends=['hashlib.h']) ) |
|---|
| 893 | n/a | exts.append( Extension('_sha1', ['sha1module.c'], |
|---|
| 894 | n/a | depends=['hashlib.h']) ) |
|---|
| 895 | n/a | |
|---|
| 896 | n/a | blake2_deps = glob(os.path.join(os.getcwd(), srcdir, |
|---|
| 897 | n/a | 'Modules/_blake2/impl/*')) |
|---|
| 898 | n/a | blake2_deps.append('hashlib.h') |
|---|
| 899 | n/a | |
|---|
| 900 | n/a | blake2_macros = [] |
|---|
| 901 | n/a | if not cross_compiling and os.uname().machine == "x86_64": |
|---|
| 902 | n/a | # Every x86_64 machine has at least SSE2. |
|---|
| 903 | n/a | blake2_macros.append(('BLAKE2_USE_SSE', '1')) |
|---|
| 904 | n/a | |
|---|
| 905 | n/a | exts.append( Extension('_blake2', |
|---|
| 906 | n/a | ['_blake2/blake2module.c', |
|---|
| 907 | n/a | '_blake2/blake2b_impl.c', |
|---|
| 908 | n/a | '_blake2/blake2s_impl.c'], |
|---|
| 909 | n/a | define_macros=blake2_macros, |
|---|
| 910 | n/a | depends=blake2_deps) ) |
|---|
| 911 | n/a | |
|---|
| 912 | n/a | sha3_deps = glob(os.path.join(os.getcwd(), srcdir, |
|---|
| 913 | n/a | 'Modules/_sha3/kcp/*')) |
|---|
| 914 | n/a | sha3_deps.append('hashlib.h') |
|---|
| 915 | n/a | exts.append( Extension('_sha3', |
|---|
| 916 | n/a | ['_sha3/sha3module.c'], |
|---|
| 917 | n/a | depends=sha3_deps)) |
|---|
| 918 | n/a | |
|---|
| 919 | n/a | # Modules that provide persistent dictionary-like semantics. You will |
|---|
| 920 | n/a | # probably want to arrange for at least one of them to be available on |
|---|
| 921 | n/a | # your machine, though none are defined by default because of library |
|---|
| 922 | n/a | # dependencies. The Python module dbm/__init__.py provides an |
|---|
| 923 | n/a | # implementation independent wrapper for these; dbm/dumb.py provides |
|---|
| 924 | n/a | # similar functionality (but slower of course) implemented in Python. |
|---|
| 925 | n/a | |
|---|
| 926 | n/a | # Sleepycat^WOracle Berkeley DB interface. |
|---|
| 927 | n/a | # http://www.oracle.com/database/berkeley-db/db/index.html |
|---|
| 928 | n/a | # |
|---|
| 929 | n/a | # This requires the Sleepycat^WOracle DB code. The supported versions |
|---|
| 930 | n/a | # are set below. Visit the URL above to download |
|---|
| 931 | n/a | # a release. Most open source OSes come with one or more |
|---|
| 932 | n/a | # versions of BerkeleyDB already installed. |
|---|
| 933 | n/a | |
|---|
| 934 | n/a | max_db_ver = (5, 3) |
|---|
| 935 | n/a | min_db_ver = (3, 3) |
|---|
| 936 | n/a | db_setup_debug = False # verbose debug prints from this script? |
|---|
| 937 | n/a | |
|---|
| 938 | n/a | def allow_db_ver(db_ver): |
|---|
| 939 | n/a | """Returns a boolean if the given BerkeleyDB version is acceptable. |
|---|
| 940 | n/a | |
|---|
| 941 | n/a | Args: |
|---|
| 942 | n/a | db_ver: A tuple of the version to verify. |
|---|
| 943 | n/a | """ |
|---|
| 944 | n/a | if not (min_db_ver <= db_ver <= max_db_ver): |
|---|
| 945 | n/a | return False |
|---|
| 946 | n/a | return True |
|---|
| 947 | n/a | |
|---|
| 948 | n/a | def gen_db_minor_ver_nums(major): |
|---|
| 949 | n/a | if major == 4: |
|---|
| 950 | n/a | for x in range(max_db_ver[1]+1): |
|---|
| 951 | n/a | if allow_db_ver((4, x)): |
|---|
| 952 | n/a | yield x |
|---|
| 953 | n/a | elif major == 3: |
|---|
| 954 | n/a | for x in (3,): |
|---|
| 955 | n/a | if allow_db_ver((3, x)): |
|---|
| 956 | n/a | yield x |
|---|
| 957 | n/a | else: |
|---|
| 958 | n/a | raise ValueError("unknown major BerkeleyDB version", major) |
|---|
| 959 | n/a | |
|---|
| 960 | n/a | # construct a list of paths to look for the header file in on |
|---|
| 961 | n/a | # top of the normal inc_dirs. |
|---|
| 962 | n/a | db_inc_paths = [ |
|---|
| 963 | n/a | '/usr/include/db4', |
|---|
| 964 | n/a | '/usr/local/include/db4', |
|---|
| 965 | n/a | '/opt/sfw/include/db4', |
|---|
| 966 | n/a | '/usr/include/db3', |
|---|
| 967 | n/a | '/usr/local/include/db3', |
|---|
| 968 | n/a | '/opt/sfw/include/db3', |
|---|
| 969 | n/a | # Fink defaults (http://fink.sourceforge.net/) |
|---|
| 970 | n/a | '/sw/include/db4', |
|---|
| 971 | n/a | '/sw/include/db3', |
|---|
| 972 | n/a | ] |
|---|
| 973 | n/a | # 4.x minor number specific paths |
|---|
| 974 | n/a | for x in gen_db_minor_ver_nums(4): |
|---|
| 975 | n/a | db_inc_paths.append('/usr/include/db4%d' % x) |
|---|
| 976 | n/a | db_inc_paths.append('/usr/include/db4.%d' % x) |
|---|
| 977 | n/a | db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x) |
|---|
| 978 | n/a | db_inc_paths.append('/usr/local/include/db4%d' % x) |
|---|
| 979 | n/a | db_inc_paths.append('/pkg/db-4.%d/include' % x) |
|---|
| 980 | n/a | db_inc_paths.append('/opt/db-4.%d/include' % x) |
|---|
| 981 | n/a | # MacPorts default (http://www.macports.org/) |
|---|
| 982 | n/a | db_inc_paths.append('/opt/local/include/db4%d' % x) |
|---|
| 983 | n/a | # 3.x minor number specific paths |
|---|
| 984 | n/a | for x in gen_db_minor_ver_nums(3): |
|---|
| 985 | n/a | db_inc_paths.append('/usr/include/db3%d' % x) |
|---|
| 986 | n/a | db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x) |
|---|
| 987 | n/a | db_inc_paths.append('/usr/local/include/db3%d' % x) |
|---|
| 988 | n/a | db_inc_paths.append('/pkg/db-3.%d/include' % x) |
|---|
| 989 | n/a | db_inc_paths.append('/opt/db-3.%d/include' % x) |
|---|
| 990 | n/a | |
|---|
| 991 | n/a | if cross_compiling: |
|---|
| 992 | n/a | db_inc_paths = [] |
|---|
| 993 | n/a | |
|---|
| 994 | n/a | # Add some common subdirectories for Sleepycat DB to the list, |
|---|
| 995 | n/a | # based on the standard include directories. This way DB3/4 gets |
|---|
| 996 | n/a | # picked up when it is installed in a non-standard prefix and |
|---|
| 997 | n/a | # the user has added that prefix into inc_dirs. |
|---|
| 998 | n/a | std_variants = [] |
|---|
| 999 | n/a | for dn in inc_dirs: |
|---|
| 1000 | n/a | std_variants.append(os.path.join(dn, 'db3')) |
|---|
| 1001 | n/a | std_variants.append(os.path.join(dn, 'db4')) |
|---|
| 1002 | n/a | for x in gen_db_minor_ver_nums(4): |
|---|
| 1003 | n/a | std_variants.append(os.path.join(dn, "db4%d"%x)) |
|---|
| 1004 | n/a | std_variants.append(os.path.join(dn, "db4.%d"%x)) |
|---|
| 1005 | n/a | for x in gen_db_minor_ver_nums(3): |
|---|
| 1006 | n/a | std_variants.append(os.path.join(dn, "db3%d"%x)) |
|---|
| 1007 | n/a | std_variants.append(os.path.join(dn, "db3.%d"%x)) |
|---|
| 1008 | n/a | |
|---|
| 1009 | n/a | db_inc_paths = std_variants + db_inc_paths |
|---|
| 1010 | n/a | db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)] |
|---|
| 1011 | n/a | |
|---|
| 1012 | n/a | db_ver_inc_map = {} |
|---|
| 1013 | n/a | |
|---|
| 1014 | n/a | if host_platform == 'darwin': |
|---|
| 1015 | n/a | sysroot = macosx_sdk_root() |
|---|
| 1016 | n/a | |
|---|
| 1017 | n/a | class db_found(Exception): pass |
|---|
| 1018 | n/a | try: |
|---|
| 1019 | n/a | # See whether there is a Sleepycat header in the standard |
|---|
| 1020 | n/a | # search path. |
|---|
| 1021 | n/a | for d in inc_dirs + db_inc_paths: |
|---|
| 1022 | n/a | f = os.path.join(d, "db.h") |
|---|
| 1023 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(d): |
|---|
| 1024 | n/a | f = os.path.join(sysroot, d[1:], "db.h") |
|---|
| 1025 | n/a | |
|---|
| 1026 | n/a | if db_setup_debug: print("db: looking for db.h in", f) |
|---|
| 1027 | n/a | if os.path.exists(f): |
|---|
| 1028 | n/a | with open(f, 'rb') as file: |
|---|
| 1029 | n/a | f = file.read() |
|---|
| 1030 | n/a | m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f) |
|---|
| 1031 | n/a | if m: |
|---|
| 1032 | n/a | db_major = int(m.group(1)) |
|---|
| 1033 | n/a | m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f) |
|---|
| 1034 | n/a | db_minor = int(m.group(1)) |
|---|
| 1035 | n/a | db_ver = (db_major, db_minor) |
|---|
| 1036 | n/a | |
|---|
| 1037 | n/a | # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug |
|---|
| 1038 | n/a | if db_ver == (4, 6): |
|---|
| 1039 | n/a | m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f) |
|---|
| 1040 | n/a | db_patch = int(m.group(1)) |
|---|
| 1041 | n/a | if db_patch < 21: |
|---|
| 1042 | n/a | print("db.h:", db_ver, "patch", db_patch, |
|---|
| 1043 | n/a | "being ignored (4.6.x must be >= 4.6.21)") |
|---|
| 1044 | n/a | continue |
|---|
| 1045 | n/a | |
|---|
| 1046 | n/a | if ( (db_ver not in db_ver_inc_map) and |
|---|
| 1047 | n/a | allow_db_ver(db_ver) ): |
|---|
| 1048 | n/a | # save the include directory with the db.h version |
|---|
| 1049 | n/a | # (first occurrence only) |
|---|
| 1050 | n/a | db_ver_inc_map[db_ver] = d |
|---|
| 1051 | n/a | if db_setup_debug: |
|---|
| 1052 | n/a | print("db.h: found", db_ver, "in", d) |
|---|
| 1053 | n/a | else: |
|---|
| 1054 | n/a | # we already found a header for this library version |
|---|
| 1055 | n/a | if db_setup_debug: print("db.h: ignoring", d) |
|---|
| 1056 | n/a | else: |
|---|
| 1057 | n/a | # ignore this header, it didn't contain a version number |
|---|
| 1058 | n/a | if db_setup_debug: |
|---|
| 1059 | n/a | print("db.h: no version number version in", d) |
|---|
| 1060 | n/a | |
|---|
| 1061 | n/a | db_found_vers = list(db_ver_inc_map.keys()) |
|---|
| 1062 | n/a | db_found_vers.sort() |
|---|
| 1063 | n/a | |
|---|
| 1064 | n/a | while db_found_vers: |
|---|
| 1065 | n/a | db_ver = db_found_vers.pop() |
|---|
| 1066 | n/a | db_incdir = db_ver_inc_map[db_ver] |
|---|
| 1067 | n/a | |
|---|
| 1068 | n/a | # check lib directories parallel to the location of the header |
|---|
| 1069 | n/a | db_dirs_to_check = [ |
|---|
| 1070 | n/a | db_incdir.replace("include", 'lib64'), |
|---|
| 1071 | n/a | db_incdir.replace("include", 'lib'), |
|---|
| 1072 | n/a | ] |
|---|
| 1073 | n/a | |
|---|
| 1074 | n/a | if host_platform != 'darwin': |
|---|
| 1075 | n/a | db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check)) |
|---|
| 1076 | n/a | |
|---|
| 1077 | n/a | else: |
|---|
| 1078 | n/a | # Same as other branch, but takes OSX SDK into account |
|---|
| 1079 | n/a | tmp = [] |
|---|
| 1080 | n/a | for dn in db_dirs_to_check: |
|---|
| 1081 | n/a | if is_macosx_sdk_path(dn): |
|---|
| 1082 | n/a | if os.path.isdir(os.path.join(sysroot, dn[1:])): |
|---|
| 1083 | n/a | tmp.append(dn) |
|---|
| 1084 | n/a | else: |
|---|
| 1085 | n/a | if os.path.isdir(dn): |
|---|
| 1086 | n/a | tmp.append(dn) |
|---|
| 1087 | n/a | db_dirs_to_check = tmp |
|---|
| 1088 | n/a | |
|---|
| 1089 | n/a | db_dirs_to_check = tmp |
|---|
| 1090 | n/a | |
|---|
| 1091 | n/a | # Look for a version specific db-X.Y before an ambiguous dbX |
|---|
| 1092 | n/a | # XXX should we -ever- look for a dbX name? Do any |
|---|
| 1093 | n/a | # systems really not name their library by version and |
|---|
| 1094 | n/a | # symlink to more general names? |
|---|
| 1095 | n/a | for dblib in (('db-%d.%d' % db_ver), |
|---|
| 1096 | n/a | ('db%d%d' % db_ver), |
|---|
| 1097 | n/a | ('db%d' % db_ver[0])): |
|---|
| 1098 | n/a | dblib_file = self.compiler.find_library_file( |
|---|
| 1099 | n/a | db_dirs_to_check + lib_dirs, dblib ) |
|---|
| 1100 | n/a | if dblib_file: |
|---|
| 1101 | n/a | dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ] |
|---|
| 1102 | n/a | raise db_found |
|---|
| 1103 | n/a | else: |
|---|
| 1104 | n/a | if db_setup_debug: print("db lib: ", dblib, "not found") |
|---|
| 1105 | n/a | |
|---|
| 1106 | n/a | except db_found: |
|---|
| 1107 | n/a | if db_setup_debug: |
|---|
| 1108 | n/a | print("bsddb using BerkeleyDB lib:", db_ver, dblib) |
|---|
| 1109 | n/a | print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir) |
|---|
| 1110 | n/a | dblibs = [dblib] |
|---|
| 1111 | n/a | # Only add the found library and include directories if they aren't |
|---|
| 1112 | n/a | # already being searched. This avoids an explicit runtime library |
|---|
| 1113 | n/a | # dependency. |
|---|
| 1114 | n/a | if db_incdir in inc_dirs: |
|---|
| 1115 | n/a | db_incs = None |
|---|
| 1116 | n/a | else: |
|---|
| 1117 | n/a | db_incs = [db_incdir] |
|---|
| 1118 | n/a | if dblib_dir[0] in lib_dirs: |
|---|
| 1119 | n/a | dblib_dir = None |
|---|
| 1120 | n/a | else: |
|---|
| 1121 | n/a | if db_setup_debug: print("db: no appropriate library found") |
|---|
| 1122 | n/a | db_incs = None |
|---|
| 1123 | n/a | dblibs = [] |
|---|
| 1124 | n/a | dblib_dir = None |
|---|
| 1125 | n/a | |
|---|
| 1126 | n/a | # The sqlite interface |
|---|
| 1127 | n/a | sqlite_setup_debug = False # verbose debug prints from this script? |
|---|
| 1128 | n/a | |
|---|
| 1129 | n/a | # We hunt for #define SQLITE_VERSION "n.n.n" |
|---|
| 1130 | n/a | # We need to find >= sqlite version 3.0.8 |
|---|
| 1131 | n/a | sqlite_incdir = sqlite_libdir = None |
|---|
| 1132 | n/a | sqlite_inc_paths = [ '/usr/include', |
|---|
| 1133 | n/a | '/usr/include/sqlite', |
|---|
| 1134 | n/a | '/usr/include/sqlite3', |
|---|
| 1135 | n/a | '/usr/local/include', |
|---|
| 1136 | n/a | '/usr/local/include/sqlite', |
|---|
| 1137 | n/a | '/usr/local/include/sqlite3', |
|---|
| 1138 | n/a | ] |
|---|
| 1139 | n/a | if cross_compiling: |
|---|
| 1140 | n/a | sqlite_inc_paths = [] |
|---|
| 1141 | n/a | MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) |
|---|
| 1142 | n/a | MIN_SQLITE_VERSION = ".".join([str(x) |
|---|
| 1143 | n/a | for x in MIN_SQLITE_VERSION_NUMBER]) |
|---|
| 1144 | n/a | |
|---|
| 1145 | n/a | # Scan the default include directories before the SQLite specific |
|---|
| 1146 | n/a | # ones. This allows one to override the copy of sqlite on OSX, |
|---|
| 1147 | n/a | # where /usr/include contains an old version of sqlite. |
|---|
| 1148 | n/a | if host_platform == 'darwin': |
|---|
| 1149 | n/a | sysroot = macosx_sdk_root() |
|---|
| 1150 | n/a | |
|---|
| 1151 | n/a | for d_ in inc_dirs + sqlite_inc_paths: |
|---|
| 1152 | n/a | d = d_ |
|---|
| 1153 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(d): |
|---|
| 1154 | n/a | d = os.path.join(sysroot, d[1:]) |
|---|
| 1155 | n/a | |
|---|
| 1156 | n/a | f = os.path.join(d, "sqlite3.h") |
|---|
| 1157 | n/a | if os.path.exists(f): |
|---|
| 1158 | n/a | if sqlite_setup_debug: print("sqlite: found %s"%f) |
|---|
| 1159 | n/a | with open(f) as file: |
|---|
| 1160 | n/a | incf = file.read() |
|---|
| 1161 | n/a | m = re.search( |
|---|
| 1162 | n/a | r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf) |
|---|
| 1163 | n/a | if m: |
|---|
| 1164 | n/a | sqlite_version = m.group(1) |
|---|
| 1165 | n/a | sqlite_version_tuple = tuple([int(x) |
|---|
| 1166 | n/a | for x in sqlite_version.split(".")]) |
|---|
| 1167 | n/a | if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: |
|---|
| 1168 | n/a | # we win! |
|---|
| 1169 | n/a | if sqlite_setup_debug: |
|---|
| 1170 | n/a | print("%s/sqlite3.h: version %s"%(d, sqlite_version)) |
|---|
| 1171 | n/a | sqlite_incdir = d |
|---|
| 1172 | n/a | break |
|---|
| 1173 | n/a | else: |
|---|
| 1174 | n/a | if sqlite_setup_debug: |
|---|
| 1175 | n/a | print("%s: version %d is too old, need >= %s"%(d, |
|---|
| 1176 | n/a | sqlite_version, MIN_SQLITE_VERSION)) |
|---|
| 1177 | n/a | elif sqlite_setup_debug: |
|---|
| 1178 | n/a | print("sqlite: %s had no SQLITE_VERSION"%(f,)) |
|---|
| 1179 | n/a | |
|---|
| 1180 | n/a | if sqlite_incdir: |
|---|
| 1181 | n/a | sqlite_dirs_to_check = [ |
|---|
| 1182 | n/a | os.path.join(sqlite_incdir, '..', 'lib64'), |
|---|
| 1183 | n/a | os.path.join(sqlite_incdir, '..', 'lib'), |
|---|
| 1184 | n/a | os.path.join(sqlite_incdir, '..', '..', 'lib64'), |
|---|
| 1185 | n/a | os.path.join(sqlite_incdir, '..', '..', 'lib'), |
|---|
| 1186 | n/a | ] |
|---|
| 1187 | n/a | sqlite_libfile = self.compiler.find_library_file( |
|---|
| 1188 | n/a | sqlite_dirs_to_check + lib_dirs, 'sqlite3') |
|---|
| 1189 | n/a | if sqlite_libfile: |
|---|
| 1190 | n/a | sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] |
|---|
| 1191 | n/a | |
|---|
| 1192 | n/a | if sqlite_incdir and sqlite_libdir: |
|---|
| 1193 | n/a | sqlite_srcs = ['_sqlite/cache.c', |
|---|
| 1194 | n/a | '_sqlite/connection.c', |
|---|
| 1195 | n/a | '_sqlite/cursor.c', |
|---|
| 1196 | n/a | '_sqlite/microprotocols.c', |
|---|
| 1197 | n/a | '_sqlite/module.c', |
|---|
| 1198 | n/a | '_sqlite/prepare_protocol.c', |
|---|
| 1199 | n/a | '_sqlite/row.c', |
|---|
| 1200 | n/a | '_sqlite/statement.c', |
|---|
| 1201 | n/a | '_sqlite/util.c', ] |
|---|
| 1202 | n/a | |
|---|
| 1203 | n/a | sqlite_defines = [] |
|---|
| 1204 | n/a | if host_platform != "win32": |
|---|
| 1205 | n/a | sqlite_defines.append(('MODULE_NAME', '"sqlite3"')) |
|---|
| 1206 | n/a | else: |
|---|
| 1207 | n/a | sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"')) |
|---|
| 1208 | n/a | |
|---|
| 1209 | n/a | # Enable support for loadable extensions in the sqlite3 module |
|---|
| 1210 | n/a | # if --enable-loadable-sqlite-extensions configure option is used. |
|---|
| 1211 | n/a | if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"): |
|---|
| 1212 | n/a | sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1")) |
|---|
| 1213 | n/a | |
|---|
| 1214 | n/a | if host_platform == 'darwin': |
|---|
| 1215 | n/a | # In every directory on the search path search for a dynamic |
|---|
| 1216 | n/a | # library and then a static library, instead of first looking |
|---|
| 1217 | n/a | # for dynamic libraries on the entire path. |
|---|
| 1218 | n/a | # This way a statically linked custom sqlite gets picked up |
|---|
| 1219 | n/a | # before the dynamic library in /usr/lib. |
|---|
| 1220 | n/a | sqlite_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 1221 | n/a | else: |
|---|
| 1222 | n/a | sqlite_extra_link_args = () |
|---|
| 1223 | n/a | |
|---|
| 1224 | n/a | include_dirs = ["Modules/_sqlite"] |
|---|
| 1225 | n/a | # Only include the directory where sqlite was found if it does |
|---|
| 1226 | n/a | # not already exist in set include directories, otherwise you |
|---|
| 1227 | n/a | # can end up with a bad search path order. |
|---|
| 1228 | n/a | if sqlite_incdir not in self.compiler.include_dirs: |
|---|
| 1229 | n/a | include_dirs.append(sqlite_incdir) |
|---|
| 1230 | n/a | # avoid a runtime library path for a system library dir |
|---|
| 1231 | n/a | if sqlite_libdir and sqlite_libdir[0] in lib_dirs: |
|---|
| 1232 | n/a | sqlite_libdir = None |
|---|
| 1233 | n/a | exts.append(Extension('_sqlite3', sqlite_srcs, |
|---|
| 1234 | n/a | define_macros=sqlite_defines, |
|---|
| 1235 | n/a | include_dirs=include_dirs, |
|---|
| 1236 | n/a | library_dirs=sqlite_libdir, |
|---|
| 1237 | n/a | extra_link_args=sqlite_extra_link_args, |
|---|
| 1238 | n/a | libraries=["sqlite3",])) |
|---|
| 1239 | n/a | else: |
|---|
| 1240 | n/a | missing.append('_sqlite3') |
|---|
| 1241 | n/a | |
|---|
| 1242 | n/a | dbm_setup_debug = False # verbose debug prints from this script? |
|---|
| 1243 | n/a | dbm_order = ['gdbm'] |
|---|
| 1244 | n/a | # The standard Unix dbm module: |
|---|
| 1245 | n/a | if host_platform not in ['cygwin']: |
|---|
| 1246 | n/a | config_args = [arg.strip("'") |
|---|
| 1247 | n/a | for arg in sysconfig.get_config_var("CONFIG_ARGS").split()] |
|---|
| 1248 | n/a | dbm_args = [arg for arg in config_args |
|---|
| 1249 | n/a | if arg.startswith('--with-dbmliborder=')] |
|---|
| 1250 | n/a | if dbm_args: |
|---|
| 1251 | n/a | dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":") |
|---|
| 1252 | n/a | else: |
|---|
| 1253 | n/a | dbm_order = "ndbm:gdbm:bdb".split(":") |
|---|
| 1254 | n/a | dbmext = None |
|---|
| 1255 | n/a | for cand in dbm_order: |
|---|
| 1256 | n/a | if cand == "ndbm": |
|---|
| 1257 | n/a | if find_file("ndbm.h", inc_dirs, []) is not None: |
|---|
| 1258 | n/a | # Some systems have -lndbm, others have -lgdbm_compat, |
|---|
| 1259 | n/a | # others don't have either |
|---|
| 1260 | n/a | if self.compiler.find_library_file(lib_dirs, |
|---|
| 1261 | n/a | 'ndbm'): |
|---|
| 1262 | n/a | ndbm_libs = ['ndbm'] |
|---|
| 1263 | n/a | elif self.compiler.find_library_file(lib_dirs, |
|---|
| 1264 | n/a | 'gdbm_compat'): |
|---|
| 1265 | n/a | ndbm_libs = ['gdbm_compat'] |
|---|
| 1266 | n/a | else: |
|---|
| 1267 | n/a | ndbm_libs = [] |
|---|
| 1268 | n/a | if dbm_setup_debug: print("building dbm using ndbm") |
|---|
| 1269 | n/a | dbmext = Extension('_dbm', ['_dbmmodule.c'], |
|---|
| 1270 | n/a | define_macros=[ |
|---|
| 1271 | n/a | ('HAVE_NDBM_H',None), |
|---|
| 1272 | n/a | ], |
|---|
| 1273 | n/a | libraries=ndbm_libs) |
|---|
| 1274 | n/a | break |
|---|
| 1275 | n/a | |
|---|
| 1276 | n/a | elif cand == "gdbm": |
|---|
| 1277 | n/a | if self.compiler.find_library_file(lib_dirs, 'gdbm'): |
|---|
| 1278 | n/a | gdbm_libs = ['gdbm'] |
|---|
| 1279 | n/a | if self.compiler.find_library_file(lib_dirs, |
|---|
| 1280 | n/a | 'gdbm_compat'): |
|---|
| 1281 | n/a | gdbm_libs.append('gdbm_compat') |
|---|
| 1282 | n/a | if find_file("gdbm/ndbm.h", inc_dirs, []) is not None: |
|---|
| 1283 | n/a | if dbm_setup_debug: print("building dbm using gdbm") |
|---|
| 1284 | n/a | dbmext = Extension( |
|---|
| 1285 | n/a | '_dbm', ['_dbmmodule.c'], |
|---|
| 1286 | n/a | define_macros=[ |
|---|
| 1287 | n/a | ('HAVE_GDBM_NDBM_H', None), |
|---|
| 1288 | n/a | ], |
|---|
| 1289 | n/a | libraries = gdbm_libs) |
|---|
| 1290 | n/a | break |
|---|
| 1291 | n/a | if find_file("gdbm-ndbm.h", inc_dirs, []) is not None: |
|---|
| 1292 | n/a | if dbm_setup_debug: print("building dbm using gdbm") |
|---|
| 1293 | n/a | dbmext = Extension( |
|---|
| 1294 | n/a | '_dbm', ['_dbmmodule.c'], |
|---|
| 1295 | n/a | define_macros=[ |
|---|
| 1296 | n/a | ('HAVE_GDBM_DASH_NDBM_H', None), |
|---|
| 1297 | n/a | ], |
|---|
| 1298 | n/a | libraries = gdbm_libs) |
|---|
| 1299 | n/a | break |
|---|
| 1300 | n/a | elif cand == "bdb": |
|---|
| 1301 | n/a | if dblibs: |
|---|
| 1302 | n/a | if dbm_setup_debug: print("building dbm using bdb") |
|---|
| 1303 | n/a | dbmext = Extension('_dbm', ['_dbmmodule.c'], |
|---|
| 1304 | n/a | library_dirs=dblib_dir, |
|---|
| 1305 | n/a | runtime_library_dirs=dblib_dir, |
|---|
| 1306 | n/a | include_dirs=db_incs, |
|---|
| 1307 | n/a | define_macros=[ |
|---|
| 1308 | n/a | ('HAVE_BERKDB_H', None), |
|---|
| 1309 | n/a | ('DB_DBM_HSEARCH', None), |
|---|
| 1310 | n/a | ], |
|---|
| 1311 | n/a | libraries=dblibs) |
|---|
| 1312 | n/a | break |
|---|
| 1313 | n/a | if dbmext is not None: |
|---|
| 1314 | n/a | exts.append(dbmext) |
|---|
| 1315 | n/a | else: |
|---|
| 1316 | n/a | missing.append('_dbm') |
|---|
| 1317 | n/a | |
|---|
| 1318 | n/a | # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: |
|---|
| 1319 | n/a | if ('gdbm' in dbm_order and |
|---|
| 1320 | n/a | self.compiler.find_library_file(lib_dirs, 'gdbm')): |
|---|
| 1321 | n/a | exts.append( Extension('_gdbm', ['_gdbmmodule.c'], |
|---|
| 1322 | n/a | libraries = ['gdbm'] ) ) |
|---|
| 1323 | n/a | else: |
|---|
| 1324 | n/a | missing.append('_gdbm') |
|---|
| 1325 | n/a | |
|---|
| 1326 | n/a | # Unix-only modules |
|---|
| 1327 | n/a | if host_platform != 'win32': |
|---|
| 1328 | n/a | # Steen Lumholt's termios module |
|---|
| 1329 | n/a | exts.append( Extension('termios', ['termios.c']) ) |
|---|
| 1330 | n/a | # Jeremy Hylton's rlimit interface |
|---|
| 1331 | n/a | exts.append( Extension('resource', ['resource.c']) ) |
|---|
| 1332 | n/a | |
|---|
| 1333 | n/a | # Sun yellow pages. Some systems have the functions in libc. |
|---|
| 1334 | n/a | if (host_platform not in ['cygwin', 'qnx6'] and |
|---|
| 1335 | n/a | find_file('rpcsvc/yp_prot.h', inc_dirs, []) is not None): |
|---|
| 1336 | n/a | if (self.compiler.find_library_file(lib_dirs, 'nsl')): |
|---|
| 1337 | n/a | libs = ['nsl'] |
|---|
| 1338 | n/a | else: |
|---|
| 1339 | n/a | libs = [] |
|---|
| 1340 | n/a | exts.append( Extension('nis', ['nismodule.c'], |
|---|
| 1341 | n/a | libraries = libs) ) |
|---|
| 1342 | n/a | else: |
|---|
| 1343 | n/a | missing.append('nis') |
|---|
| 1344 | n/a | else: |
|---|
| 1345 | n/a | missing.extend(['nis', 'resource', 'termios']) |
|---|
| 1346 | n/a | |
|---|
| 1347 | n/a | # Curses support, requiring the System V version of curses, often |
|---|
| 1348 | n/a | # provided by the ncurses library. |
|---|
| 1349 | n/a | curses_defines = [] |
|---|
| 1350 | n/a | curses_includes = [] |
|---|
| 1351 | n/a | panel_library = 'panel' |
|---|
| 1352 | n/a | if curses_library == 'ncursesw': |
|---|
| 1353 | n/a | curses_defines.append(('HAVE_NCURSESW', '1')) |
|---|
| 1354 | n/a | if not cross_compiling: |
|---|
| 1355 | n/a | curses_includes.append('/usr/include/ncursesw') |
|---|
| 1356 | n/a | # Bug 1464056: If _curses.so links with ncursesw, |
|---|
| 1357 | n/a | # _curses_panel.so must link with panelw. |
|---|
| 1358 | n/a | panel_library = 'panelw' |
|---|
| 1359 | n/a | if host_platform == 'darwin': |
|---|
| 1360 | n/a | # On OS X, there is no separate /usr/lib/libncursesw nor |
|---|
| 1361 | n/a | # libpanelw. If we are here, we found a locally-supplied |
|---|
| 1362 | n/a | # version of libncursesw. There should be also be a |
|---|
| 1363 | n/a | # libpanelw. _XOPEN_SOURCE defines are usually excluded |
|---|
| 1364 | n/a | # for OS X but we need _XOPEN_SOURCE_EXTENDED here for |
|---|
| 1365 | n/a | # ncurses wide char support |
|---|
| 1366 | n/a | curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1')) |
|---|
| 1367 | n/a | elif host_platform == 'darwin' and curses_library == 'ncurses': |
|---|
| 1368 | n/a | # Building with the system-suppied combined libncurses/libpanel |
|---|
| 1369 | n/a | curses_defines.append(('HAVE_NCURSESW', '1')) |
|---|
| 1370 | n/a | curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1')) |
|---|
| 1371 | n/a | |
|---|
| 1372 | n/a | if curses_library.startswith('ncurses'): |
|---|
| 1373 | n/a | curses_libs = [curses_library] |
|---|
| 1374 | n/a | exts.append( Extension('_curses', ['_cursesmodule.c'], |
|---|
| 1375 | n/a | include_dirs=curses_includes, |
|---|
| 1376 | n/a | define_macros=curses_defines, |
|---|
| 1377 | n/a | libraries = curses_libs) ) |
|---|
| 1378 | n/a | elif curses_library == 'curses' and host_platform != 'darwin': |
|---|
| 1379 | n/a | # OSX has an old Berkeley curses, not good enough for |
|---|
| 1380 | n/a | # the _curses module. |
|---|
| 1381 | n/a | if (self.compiler.find_library_file(lib_dirs, 'terminfo')): |
|---|
| 1382 | n/a | curses_libs = ['curses', 'terminfo'] |
|---|
| 1383 | n/a | elif (self.compiler.find_library_file(lib_dirs, 'termcap')): |
|---|
| 1384 | n/a | curses_libs = ['curses', 'termcap'] |
|---|
| 1385 | n/a | else: |
|---|
| 1386 | n/a | curses_libs = ['curses'] |
|---|
| 1387 | n/a | |
|---|
| 1388 | n/a | exts.append( Extension('_curses', ['_cursesmodule.c'], |
|---|
| 1389 | n/a | define_macros=curses_defines, |
|---|
| 1390 | n/a | libraries = curses_libs) ) |
|---|
| 1391 | n/a | else: |
|---|
| 1392 | n/a | missing.append('_curses') |
|---|
| 1393 | n/a | |
|---|
| 1394 | n/a | # If the curses module is enabled, check for the panel module |
|---|
| 1395 | n/a | if (module_enabled(exts, '_curses') and |
|---|
| 1396 | n/a | self.compiler.find_library_file(lib_dirs, panel_library)): |
|---|
| 1397 | n/a | exts.append( Extension('_curses_panel', ['_curses_panel.c'], |
|---|
| 1398 | n/a | include_dirs=curses_includes, |
|---|
| 1399 | n/a | define_macros=curses_defines, |
|---|
| 1400 | n/a | libraries = [panel_library] + curses_libs) ) |
|---|
| 1401 | n/a | else: |
|---|
| 1402 | n/a | missing.append('_curses_panel') |
|---|
| 1403 | n/a | |
|---|
| 1404 | n/a | # Andrew Kuchling's zlib module. Note that some versions of zlib |
|---|
| 1405 | n/a | # 1.1.3 have security problems. See CERT Advisory CA-2002-07: |
|---|
| 1406 | n/a | # http://www.cert.org/advisories/CA-2002-07.html |
|---|
| 1407 | n/a | # |
|---|
| 1408 | n/a | # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to |
|---|
| 1409 | n/a | # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For |
|---|
| 1410 | n/a | # now, we still accept 1.1.3, because we think it's difficult to |
|---|
| 1411 | n/a | # exploit this in Python, and we'd rather make it RedHat's problem |
|---|
| 1412 | n/a | # than our problem <wink>. |
|---|
| 1413 | n/a | # |
|---|
| 1414 | n/a | # You can upgrade zlib to version 1.1.4 yourself by going to |
|---|
| 1415 | n/a | # http://www.gzip.org/zlib/ |
|---|
| 1416 | n/a | zlib_inc = find_file('zlib.h', [], inc_dirs) |
|---|
| 1417 | n/a | have_zlib = False |
|---|
| 1418 | n/a | if zlib_inc is not None: |
|---|
| 1419 | n/a | zlib_h = zlib_inc[0] + '/zlib.h' |
|---|
| 1420 | n/a | version = '"0.0.0"' |
|---|
| 1421 | n/a | version_req = '"1.1.3"' |
|---|
| 1422 | n/a | if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h): |
|---|
| 1423 | n/a | zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:]) |
|---|
| 1424 | n/a | with open(zlib_h) as fp: |
|---|
| 1425 | n/a | while 1: |
|---|
| 1426 | n/a | line = fp.readline() |
|---|
| 1427 | n/a | if not line: |
|---|
| 1428 | n/a | break |
|---|
| 1429 | n/a | if line.startswith('#define ZLIB_VERSION'): |
|---|
| 1430 | n/a | version = line.split()[2] |
|---|
| 1431 | n/a | break |
|---|
| 1432 | n/a | if version >= version_req: |
|---|
| 1433 | n/a | if (self.compiler.find_library_file(lib_dirs, 'z')): |
|---|
| 1434 | n/a | if host_platform == "darwin": |
|---|
| 1435 | n/a | zlib_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 1436 | n/a | else: |
|---|
| 1437 | n/a | zlib_extra_link_args = () |
|---|
| 1438 | n/a | exts.append( Extension('zlib', ['zlibmodule.c'], |
|---|
| 1439 | n/a | libraries = ['z'], |
|---|
| 1440 | n/a | extra_link_args = zlib_extra_link_args)) |
|---|
| 1441 | n/a | have_zlib = True |
|---|
| 1442 | n/a | else: |
|---|
| 1443 | n/a | missing.append('zlib') |
|---|
| 1444 | n/a | else: |
|---|
| 1445 | n/a | missing.append('zlib') |
|---|
| 1446 | n/a | else: |
|---|
| 1447 | n/a | missing.append('zlib') |
|---|
| 1448 | n/a | |
|---|
| 1449 | n/a | # Helper module for various ascii-encoders. Uses zlib for an optimized |
|---|
| 1450 | n/a | # crc32 if we have it. Otherwise binascii uses its own. |
|---|
| 1451 | n/a | if have_zlib: |
|---|
| 1452 | n/a | extra_compile_args = ['-DUSE_ZLIB_CRC32'] |
|---|
| 1453 | n/a | libraries = ['z'] |
|---|
| 1454 | n/a | extra_link_args = zlib_extra_link_args |
|---|
| 1455 | n/a | else: |
|---|
| 1456 | n/a | extra_compile_args = [] |
|---|
| 1457 | n/a | libraries = [] |
|---|
| 1458 | n/a | extra_link_args = [] |
|---|
| 1459 | n/a | exts.append( Extension('binascii', ['binascii.c'], |
|---|
| 1460 | n/a | extra_compile_args = extra_compile_args, |
|---|
| 1461 | n/a | libraries = libraries, |
|---|
| 1462 | n/a | extra_link_args = extra_link_args) ) |
|---|
| 1463 | n/a | |
|---|
| 1464 | n/a | # Gustavo Niemeyer's bz2 module. |
|---|
| 1465 | n/a | if (self.compiler.find_library_file(lib_dirs, 'bz2')): |
|---|
| 1466 | n/a | if host_platform == "darwin": |
|---|
| 1467 | n/a | bz2_extra_link_args = ('-Wl,-search_paths_first',) |
|---|
| 1468 | n/a | else: |
|---|
| 1469 | n/a | bz2_extra_link_args = () |
|---|
| 1470 | n/a | exts.append( Extension('_bz2', ['_bz2module.c'], |
|---|
| 1471 | n/a | libraries = ['bz2'], |
|---|
| 1472 | n/a | extra_link_args = bz2_extra_link_args) ) |
|---|
| 1473 | n/a | else: |
|---|
| 1474 | n/a | missing.append('_bz2') |
|---|
| 1475 | n/a | |
|---|
| 1476 | n/a | # LZMA compression support. |
|---|
| 1477 | n/a | if self.compiler.find_library_file(lib_dirs, 'lzma'): |
|---|
| 1478 | n/a | exts.append( Extension('_lzma', ['_lzmamodule.c'], |
|---|
| 1479 | n/a | libraries = ['lzma']) ) |
|---|
| 1480 | n/a | else: |
|---|
| 1481 | n/a | missing.append('_lzma') |
|---|
| 1482 | n/a | |
|---|
| 1483 | n/a | # Interface to the Expat XML parser |
|---|
| 1484 | n/a | # |
|---|
| 1485 | n/a | # Expat was written by James Clark and is now maintained by a group of |
|---|
| 1486 | n/a | # developers on SourceForge; see www.libexpat.org for more information. |
|---|
| 1487 | n/a | # The pyexpat module was written by Paul Prescod after a prototype by |
|---|
| 1488 | n/a | # Jack Jansen. The Expat source is included in Modules/expat/. Usage |
|---|
| 1489 | n/a | # of a system shared libexpat.so is possible with --with-system-expat |
|---|
| 1490 | n/a | # configure option. |
|---|
| 1491 | n/a | # |
|---|
| 1492 | n/a | # More information on Expat can be found at www.libexpat.org. |
|---|
| 1493 | n/a | # |
|---|
| 1494 | n/a | if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"): |
|---|
| 1495 | n/a | expat_inc = [] |
|---|
| 1496 | n/a | define_macros = [] |
|---|
| 1497 | n/a | expat_lib = ['expat'] |
|---|
| 1498 | n/a | expat_sources = [] |
|---|
| 1499 | n/a | expat_depends = [] |
|---|
| 1500 | n/a | else: |
|---|
| 1501 | n/a | expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')] |
|---|
| 1502 | n/a | define_macros = [ |
|---|
| 1503 | n/a | ('HAVE_EXPAT_CONFIG_H', '1'), |
|---|
| 1504 | n/a | ] |
|---|
| 1505 | n/a | expat_lib = [] |
|---|
| 1506 | n/a | expat_sources = ['expat/xmlparse.c', |
|---|
| 1507 | n/a | 'expat/xmlrole.c', |
|---|
| 1508 | n/a | 'expat/xmltok.c'] |
|---|
| 1509 | n/a | expat_depends = ['expat/ascii.h', |
|---|
| 1510 | n/a | 'expat/asciitab.h', |
|---|
| 1511 | n/a | 'expat/expat.h', |
|---|
| 1512 | n/a | 'expat/expat_config.h', |
|---|
| 1513 | n/a | 'expat/expat_external.h', |
|---|
| 1514 | n/a | 'expat/internal.h', |
|---|
| 1515 | n/a | 'expat/latin1tab.h', |
|---|
| 1516 | n/a | 'expat/utf8tab.h', |
|---|
| 1517 | n/a | 'expat/xmlrole.h', |
|---|
| 1518 | n/a | 'expat/xmltok.h', |
|---|
| 1519 | n/a | 'expat/xmltok_impl.h' |
|---|
| 1520 | n/a | ] |
|---|
| 1521 | n/a | |
|---|
| 1522 | n/a | exts.append(Extension('pyexpat', |
|---|
| 1523 | n/a | define_macros = define_macros, |
|---|
| 1524 | n/a | include_dirs = expat_inc, |
|---|
| 1525 | n/a | libraries = expat_lib, |
|---|
| 1526 | n/a | sources = ['pyexpat.c'] + expat_sources, |
|---|
| 1527 | n/a | depends = expat_depends, |
|---|
| 1528 | n/a | )) |
|---|
| 1529 | n/a | |
|---|
| 1530 | n/a | # Fredrik Lundh's cElementTree module. Note that this also |
|---|
| 1531 | n/a | # uses expat (via the CAPI hook in pyexpat). |
|---|
| 1532 | n/a | |
|---|
| 1533 | n/a | if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')): |
|---|
| 1534 | n/a | define_macros.append(('USE_PYEXPAT_CAPI', None)) |
|---|
| 1535 | n/a | exts.append(Extension('_elementtree', |
|---|
| 1536 | n/a | define_macros = define_macros, |
|---|
| 1537 | n/a | include_dirs = expat_inc, |
|---|
| 1538 | n/a | libraries = expat_lib, |
|---|
| 1539 | n/a | sources = ['_elementtree.c'], |
|---|
| 1540 | n/a | depends = ['pyexpat.c'] + expat_sources + |
|---|
| 1541 | n/a | expat_depends, |
|---|
| 1542 | n/a | )) |
|---|
| 1543 | n/a | else: |
|---|
| 1544 | n/a | missing.append('_elementtree') |
|---|
| 1545 | n/a | |
|---|
| 1546 | n/a | # Hye-Shik Chang's CJKCodecs modules. |
|---|
| 1547 | n/a | exts.append(Extension('_multibytecodec', |
|---|
| 1548 | n/a | ['cjkcodecs/multibytecodec.c'])) |
|---|
| 1549 | n/a | for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): |
|---|
| 1550 | n/a | exts.append(Extension('_codecs_%s' % loc, |
|---|
| 1551 | n/a | ['cjkcodecs/_codecs_%s.c' % loc])) |
|---|
| 1552 | n/a | |
|---|
| 1553 | n/a | # Stefan Krah's _decimal module |
|---|
| 1554 | n/a | exts.append(self._decimal_ext()) |
|---|
| 1555 | n/a | |
|---|
| 1556 | n/a | # Thomas Heller's _ctypes module |
|---|
| 1557 | n/a | self.detect_ctypes(inc_dirs, lib_dirs) |
|---|
| 1558 | n/a | |
|---|
| 1559 | n/a | # Richard Oudkerk's multiprocessing module |
|---|
| 1560 | n/a | if host_platform == 'win32': # Windows |
|---|
| 1561 | n/a | macros = dict() |
|---|
| 1562 | n/a | libraries = ['ws2_32'] |
|---|
| 1563 | n/a | |
|---|
| 1564 | n/a | elif host_platform == 'darwin': # Mac OSX |
|---|
| 1565 | n/a | macros = dict() |
|---|
| 1566 | n/a | libraries = [] |
|---|
| 1567 | n/a | |
|---|
| 1568 | n/a | elif host_platform == 'cygwin': # Cygwin |
|---|
| 1569 | n/a | macros = dict() |
|---|
| 1570 | n/a | libraries = [] |
|---|
| 1571 | n/a | |
|---|
| 1572 | n/a | elif host_platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'): |
|---|
| 1573 | n/a | # FreeBSD's P1003.1b semaphore support is very experimental |
|---|
| 1574 | n/a | # and has many known problems. (as of June 2008) |
|---|
| 1575 | n/a | macros = dict() |
|---|
| 1576 | n/a | libraries = [] |
|---|
| 1577 | n/a | |
|---|
| 1578 | n/a | elif host_platform.startswith('openbsd'): |
|---|
| 1579 | n/a | macros = dict() |
|---|
| 1580 | n/a | libraries = [] |
|---|
| 1581 | n/a | |
|---|
| 1582 | n/a | elif host_platform.startswith('netbsd'): |
|---|
| 1583 | n/a | macros = dict() |
|---|
| 1584 | n/a | libraries = [] |
|---|
| 1585 | n/a | |
|---|
| 1586 | n/a | else: # Linux and other unices |
|---|
| 1587 | n/a | macros = dict() |
|---|
| 1588 | n/a | libraries = ['rt'] |
|---|
| 1589 | n/a | |
|---|
| 1590 | n/a | if host_platform == 'win32': |
|---|
| 1591 | n/a | multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', |
|---|
| 1592 | n/a | '_multiprocessing/semaphore.c', |
|---|
| 1593 | n/a | ] |
|---|
| 1594 | n/a | |
|---|
| 1595 | n/a | else: |
|---|
| 1596 | n/a | multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', |
|---|
| 1597 | n/a | ] |
|---|
| 1598 | n/a | if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not |
|---|
| 1599 | n/a | sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')): |
|---|
| 1600 | n/a | multiprocessing_srcs.append('_multiprocessing/semaphore.c') |
|---|
| 1601 | n/a | |
|---|
| 1602 | n/a | if sysconfig.get_config_var('WITH_THREAD'): |
|---|
| 1603 | n/a | exts.append ( Extension('_multiprocessing', multiprocessing_srcs, |
|---|
| 1604 | n/a | define_macros=list(macros.items()), |
|---|
| 1605 | n/a | include_dirs=["Modules/_multiprocessing"])) |
|---|
| 1606 | n/a | else: |
|---|
| 1607 | n/a | missing.append('_multiprocessing') |
|---|
| 1608 | n/a | # End multiprocessing |
|---|
| 1609 | n/a | |
|---|
| 1610 | n/a | # Platform-specific libraries |
|---|
| 1611 | n/a | if host_platform.startswith(('linux', 'freebsd', 'gnukfreebsd')): |
|---|
| 1612 | n/a | exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) |
|---|
| 1613 | n/a | else: |
|---|
| 1614 | n/a | missing.append('ossaudiodev') |
|---|
| 1615 | n/a | |
|---|
| 1616 | n/a | if host_platform == 'darwin': |
|---|
| 1617 | n/a | exts.append( |
|---|
| 1618 | n/a | Extension('_scproxy', ['_scproxy.c'], |
|---|
| 1619 | n/a | extra_link_args=[ |
|---|
| 1620 | n/a | '-framework', 'SystemConfiguration', |
|---|
| 1621 | n/a | '-framework', 'CoreFoundation', |
|---|
| 1622 | n/a | ])) |
|---|
| 1623 | n/a | |
|---|
| 1624 | n/a | self.extensions.extend(exts) |
|---|
| 1625 | n/a | |
|---|
| 1626 | n/a | # Call the method for detecting whether _tkinter can be compiled |
|---|
| 1627 | n/a | self.detect_tkinter(inc_dirs, lib_dirs) |
|---|
| 1628 | n/a | |
|---|
| 1629 | n/a | if '_tkinter' not in [e.name for e in self.extensions]: |
|---|
| 1630 | n/a | missing.append('_tkinter') |
|---|
| 1631 | n/a | |
|---|
| 1632 | n/a | ## # Uncomment these lines if you want to play with xxmodule.c |
|---|
| 1633 | n/a | ## ext = Extension('xx', ['xxmodule.c']) |
|---|
| 1634 | n/a | ## self.extensions.append(ext) |
|---|
| 1635 | n/a | |
|---|
| 1636 | n/a | if 'd' not in sysconfig.get_config_var('ABIFLAGS'): |
|---|
| 1637 | n/a | ext = Extension('xxlimited', ['xxlimited.c'], |
|---|
| 1638 | n/a | define_macros=[('Py_LIMITED_API', '0x03050000')]) |
|---|
| 1639 | n/a | self.extensions.append(ext) |
|---|
| 1640 | n/a | |
|---|
| 1641 | n/a | return missing |
|---|
| 1642 | n/a | |
|---|
| 1643 | n/a | def detect_tkinter_explicitly(self): |
|---|
| 1644 | n/a | # Build _tkinter using explicit locations for Tcl/Tk. |
|---|
| 1645 | n/a | # |
|---|
| 1646 | n/a | # This is enabled when both arguments are given to ./configure: |
|---|
| 1647 | n/a | # |
|---|
| 1648 | n/a | # --with-tcltk-includes="-I/path/to/tclincludes \ |
|---|
| 1649 | n/a | # -I/path/to/tkincludes" |
|---|
| 1650 | n/a | # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \ |
|---|
| 1651 | n/a | # -L/path/to/tklibs -ltkm.n" |
|---|
| 1652 | n/a | # |
|---|
| 1653 | n/a | # These values can also be specified or overridden via make: |
|---|
| 1654 | n/a | # make TCLTK_INCLUDES="..." TCLTK_LIBS="..." |
|---|
| 1655 | n/a | # |
|---|
| 1656 | n/a | # This can be useful for building and testing tkinter with multiple |
|---|
| 1657 | n/a | # versions of Tcl/Tk. Note that a build of Tk depends on a particular |
|---|
| 1658 | n/a | # build of Tcl so you need to specify both arguments and use care when |
|---|
| 1659 | n/a | # overriding. |
|---|
| 1660 | n/a | |
|---|
| 1661 | n/a | # The _TCLTK variables are created in the Makefile sharedmods target. |
|---|
| 1662 | n/a | tcltk_includes = os.environ.get('_TCLTK_INCLUDES') |
|---|
| 1663 | n/a | tcltk_libs = os.environ.get('_TCLTK_LIBS') |
|---|
| 1664 | n/a | if not (tcltk_includes and tcltk_libs): |
|---|
| 1665 | n/a | # Resume default configuration search. |
|---|
| 1666 | n/a | return 0 |
|---|
| 1667 | n/a | |
|---|
| 1668 | n/a | extra_compile_args = tcltk_includes.split() |
|---|
| 1669 | n/a | extra_link_args = tcltk_libs.split() |
|---|
| 1670 | n/a | ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
|---|
| 1671 | n/a | define_macros=[('WITH_APPINIT', 1)], |
|---|
| 1672 | n/a | extra_compile_args = extra_compile_args, |
|---|
| 1673 | n/a | extra_link_args = extra_link_args, |
|---|
| 1674 | n/a | ) |
|---|
| 1675 | n/a | self.extensions.append(ext) |
|---|
| 1676 | n/a | return 1 |
|---|
| 1677 | n/a | |
|---|
| 1678 | n/a | def detect_tkinter_darwin(self, inc_dirs, lib_dirs): |
|---|
| 1679 | n/a | # The _tkinter module, using frameworks. Since frameworks are quite |
|---|
| 1680 | n/a | # different the UNIX search logic is not sharable. |
|---|
| 1681 | n/a | from os.path import join, exists |
|---|
| 1682 | n/a | framework_dirs = [ |
|---|
| 1683 | n/a | '/Library/Frameworks', |
|---|
| 1684 | n/a | '/System/Library/Frameworks/', |
|---|
| 1685 | n/a | join(os.getenv('HOME'), '/Library/Frameworks') |
|---|
| 1686 | n/a | ] |
|---|
| 1687 | n/a | |
|---|
| 1688 | n/a | sysroot = macosx_sdk_root() |
|---|
| 1689 | n/a | |
|---|
| 1690 | n/a | # Find the directory that contains the Tcl.framework and Tk.framework |
|---|
| 1691 | n/a | # bundles. |
|---|
| 1692 | n/a | # XXX distutils should support -F! |
|---|
| 1693 | n/a | for F in framework_dirs: |
|---|
| 1694 | n/a | # both Tcl.framework and Tk.framework should be present |
|---|
| 1695 | n/a | |
|---|
| 1696 | n/a | |
|---|
| 1697 | n/a | for fw in 'Tcl', 'Tk': |
|---|
| 1698 | n/a | if is_macosx_sdk_path(F): |
|---|
| 1699 | n/a | if not exists(join(sysroot, F[1:], fw + '.framework')): |
|---|
| 1700 | n/a | break |
|---|
| 1701 | n/a | else: |
|---|
| 1702 | n/a | if not exists(join(F, fw + '.framework')): |
|---|
| 1703 | n/a | break |
|---|
| 1704 | n/a | else: |
|---|
| 1705 | n/a | # ok, F is now directory with both frameworks. Continure |
|---|
| 1706 | n/a | # building |
|---|
| 1707 | n/a | break |
|---|
| 1708 | n/a | else: |
|---|
| 1709 | n/a | # Tk and Tcl frameworks not found. Normal "unix" tkinter search |
|---|
| 1710 | n/a | # will now resume. |
|---|
| 1711 | n/a | return 0 |
|---|
| 1712 | n/a | |
|---|
| 1713 | n/a | # For 8.4a2, we must add -I options that point inside the Tcl and Tk |
|---|
| 1714 | n/a | # frameworks. In later release we should hopefully be able to pass |
|---|
| 1715 | n/a | # the -F option to gcc, which specifies a framework lookup path. |
|---|
| 1716 | n/a | # |
|---|
| 1717 | n/a | include_dirs = [ |
|---|
| 1718 | n/a | join(F, fw + '.framework', H) |
|---|
| 1719 | n/a | for fw in ('Tcl', 'Tk') |
|---|
| 1720 | n/a | for H in ('Headers', 'Versions/Current/PrivateHeaders') |
|---|
| 1721 | n/a | ] |
|---|
| 1722 | n/a | |
|---|
| 1723 | n/a | # For 8.4a2, the X11 headers are not included. Rather than include a |
|---|
| 1724 | n/a | # complicated search, this is a hard-coded path. It could bail out |
|---|
| 1725 | n/a | # if X11 libs are not found... |
|---|
| 1726 | n/a | include_dirs.append('/usr/X11R6/include') |
|---|
| 1727 | n/a | frameworks = ['-framework', 'Tcl', '-framework', 'Tk'] |
|---|
| 1728 | n/a | |
|---|
| 1729 | n/a | # All existing framework builds of Tcl/Tk don't support 64-bit |
|---|
| 1730 | n/a | # architectures. |
|---|
| 1731 | n/a | cflags = sysconfig.get_config_vars('CFLAGS')[0] |
|---|
| 1732 | n/a | archs = re.findall(r'-arch\s+(\w+)', cflags) |
|---|
| 1733 | n/a | |
|---|
| 1734 | n/a | tmpfile = os.path.join(self.build_temp, 'tk.arch') |
|---|
| 1735 | n/a | if not os.path.exists(self.build_temp): |
|---|
| 1736 | n/a | os.makedirs(self.build_temp) |
|---|
| 1737 | n/a | |
|---|
| 1738 | n/a | # Note: cannot use os.popen or subprocess here, that |
|---|
| 1739 | n/a | # requires extensions that are not available here. |
|---|
| 1740 | n/a | if is_macosx_sdk_path(F): |
|---|
| 1741 | n/a | os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile)) |
|---|
| 1742 | n/a | else: |
|---|
| 1743 | n/a | os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile)) |
|---|
| 1744 | n/a | |
|---|
| 1745 | n/a | with open(tmpfile) as fp: |
|---|
| 1746 | n/a | detected_archs = [] |
|---|
| 1747 | n/a | for ln in fp: |
|---|
| 1748 | n/a | a = ln.split()[-1] |
|---|
| 1749 | n/a | if a in archs: |
|---|
| 1750 | n/a | detected_archs.append(ln.split()[-1]) |
|---|
| 1751 | n/a | os.unlink(tmpfile) |
|---|
| 1752 | n/a | |
|---|
| 1753 | n/a | for a in detected_archs: |
|---|
| 1754 | n/a | frameworks.append('-arch') |
|---|
| 1755 | n/a | frameworks.append(a) |
|---|
| 1756 | n/a | |
|---|
| 1757 | n/a | ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
|---|
| 1758 | n/a | define_macros=[('WITH_APPINIT', 1)], |
|---|
| 1759 | n/a | include_dirs = include_dirs, |
|---|
| 1760 | n/a | libraries = [], |
|---|
| 1761 | n/a | extra_compile_args = frameworks[2:], |
|---|
| 1762 | n/a | extra_link_args = frameworks, |
|---|
| 1763 | n/a | ) |
|---|
| 1764 | n/a | self.extensions.append(ext) |
|---|
| 1765 | n/a | return 1 |
|---|
| 1766 | n/a | |
|---|
| 1767 | n/a | def detect_tkinter(self, inc_dirs, lib_dirs): |
|---|
| 1768 | n/a | # The _tkinter module. |
|---|
| 1769 | n/a | |
|---|
| 1770 | n/a | # Check whether --with-tcltk-includes and --with-tcltk-libs were |
|---|
| 1771 | n/a | # configured or passed into the make target. If so, use these values |
|---|
| 1772 | n/a | # to build tkinter and bypass the searches for Tcl and TK in standard |
|---|
| 1773 | n/a | # locations. |
|---|
| 1774 | n/a | if self.detect_tkinter_explicitly(): |
|---|
| 1775 | n/a | return |
|---|
| 1776 | n/a | |
|---|
| 1777 | n/a | # Rather than complicate the code below, detecting and building |
|---|
| 1778 | n/a | # AquaTk is a separate method. Only one Tkinter will be built on |
|---|
| 1779 | n/a | # Darwin - either AquaTk, if it is found, or X11 based Tk. |
|---|
| 1780 | n/a | if (host_platform == 'darwin' and |
|---|
| 1781 | n/a | self.detect_tkinter_darwin(inc_dirs, lib_dirs)): |
|---|
| 1782 | n/a | return |
|---|
| 1783 | n/a | |
|---|
| 1784 | n/a | # Assume we haven't found any of the libraries or include files |
|---|
| 1785 | n/a | # The versions with dots are used on Unix, and the versions without |
|---|
| 1786 | n/a | # dots on Windows, for detection by cygwin. |
|---|
| 1787 | n/a | tcllib = tklib = tcl_includes = tk_includes = None |
|---|
| 1788 | n/a | for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83', |
|---|
| 1789 | n/a | '8.2', '82', '8.1', '81', '8.0', '80']: |
|---|
| 1790 | n/a | tklib = self.compiler.find_library_file(lib_dirs, |
|---|
| 1791 | n/a | 'tk' + version) |
|---|
| 1792 | n/a | tcllib = self.compiler.find_library_file(lib_dirs, |
|---|
| 1793 | n/a | 'tcl' + version) |
|---|
| 1794 | n/a | if tklib and tcllib: |
|---|
| 1795 | n/a | # Exit the loop when we've found the Tcl/Tk libraries |
|---|
| 1796 | n/a | break |
|---|
| 1797 | n/a | |
|---|
| 1798 | n/a | # Now check for the header files |
|---|
| 1799 | n/a | if tklib and tcllib: |
|---|
| 1800 | n/a | # Check for the include files on Debian and {Free,Open}BSD, where |
|---|
| 1801 | n/a | # they're put in /usr/include/{tcl,tk}X.Y |
|---|
| 1802 | n/a | dotversion = version |
|---|
| 1803 | n/a | if '.' not in dotversion and "bsd" in host_platform.lower(): |
|---|
| 1804 | n/a | # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a, |
|---|
| 1805 | n/a | # but the include subdirs are named like .../include/tcl8.3. |
|---|
| 1806 | n/a | dotversion = dotversion[:-1] + '.' + dotversion[-1] |
|---|
| 1807 | n/a | tcl_include_sub = [] |
|---|
| 1808 | n/a | tk_include_sub = [] |
|---|
| 1809 | n/a | for dir in inc_dirs: |
|---|
| 1810 | n/a | tcl_include_sub += [dir + os.sep + "tcl" + dotversion] |
|---|
| 1811 | n/a | tk_include_sub += [dir + os.sep + "tk" + dotversion] |
|---|
| 1812 | n/a | tk_include_sub += tcl_include_sub |
|---|
| 1813 | n/a | tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub) |
|---|
| 1814 | n/a | tk_includes = find_file('tk.h', inc_dirs, tk_include_sub) |
|---|
| 1815 | n/a | |
|---|
| 1816 | n/a | if (tcllib is None or tklib is None or |
|---|
| 1817 | n/a | tcl_includes is None or tk_includes is None): |
|---|
| 1818 | n/a | self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2) |
|---|
| 1819 | n/a | return |
|---|
| 1820 | n/a | |
|---|
| 1821 | n/a | # OK... everything seems to be present for Tcl/Tk. |
|---|
| 1822 | n/a | |
|---|
| 1823 | n/a | include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] |
|---|
| 1824 | n/a | for dir in tcl_includes + tk_includes: |
|---|
| 1825 | n/a | if dir not in include_dirs: |
|---|
| 1826 | n/a | include_dirs.append(dir) |
|---|
| 1827 | n/a | |
|---|
| 1828 | n/a | # Check for various platform-specific directories |
|---|
| 1829 | n/a | if host_platform == 'sunos5': |
|---|
| 1830 | n/a | include_dirs.append('/usr/openwin/include') |
|---|
| 1831 | n/a | added_lib_dirs.append('/usr/openwin/lib') |
|---|
| 1832 | n/a | elif os.path.exists('/usr/X11R6/include'): |
|---|
| 1833 | n/a | include_dirs.append('/usr/X11R6/include') |
|---|
| 1834 | n/a | added_lib_dirs.append('/usr/X11R6/lib64') |
|---|
| 1835 | n/a | added_lib_dirs.append('/usr/X11R6/lib') |
|---|
| 1836 | n/a | elif os.path.exists('/usr/X11R5/include'): |
|---|
| 1837 | n/a | include_dirs.append('/usr/X11R5/include') |
|---|
| 1838 | n/a | added_lib_dirs.append('/usr/X11R5/lib') |
|---|
| 1839 | n/a | else: |
|---|
| 1840 | n/a | # Assume default location for X11 |
|---|
| 1841 | n/a | include_dirs.append('/usr/X11/include') |
|---|
| 1842 | n/a | added_lib_dirs.append('/usr/X11/lib') |
|---|
| 1843 | n/a | |
|---|
| 1844 | n/a | # If Cygwin, then verify that X is installed before proceeding |
|---|
| 1845 | n/a | if host_platform == 'cygwin': |
|---|
| 1846 | n/a | x11_inc = find_file('X11/Xlib.h', [], include_dirs) |
|---|
| 1847 | n/a | if x11_inc is None: |
|---|
| 1848 | n/a | return |
|---|
| 1849 | n/a | |
|---|
| 1850 | n/a | # Check for BLT extension |
|---|
| 1851 | n/a | if self.compiler.find_library_file(lib_dirs + added_lib_dirs, |
|---|
| 1852 | n/a | 'BLT8.0'): |
|---|
| 1853 | n/a | defs.append( ('WITH_BLT', 1) ) |
|---|
| 1854 | n/a | libs.append('BLT8.0') |
|---|
| 1855 | n/a | elif self.compiler.find_library_file(lib_dirs + added_lib_dirs, |
|---|
| 1856 | n/a | 'BLT'): |
|---|
| 1857 | n/a | defs.append( ('WITH_BLT', 1) ) |
|---|
| 1858 | n/a | libs.append('BLT') |
|---|
| 1859 | n/a | |
|---|
| 1860 | n/a | # Add the Tcl/Tk libraries |
|---|
| 1861 | n/a | libs.append('tk'+ version) |
|---|
| 1862 | n/a | libs.append('tcl'+ version) |
|---|
| 1863 | n/a | |
|---|
| 1864 | n/a | if host_platform in ['aix3', 'aix4']: |
|---|
| 1865 | n/a | libs.append('ld') |
|---|
| 1866 | n/a | |
|---|
| 1867 | n/a | # Finally, link with the X11 libraries (not appropriate on cygwin) |
|---|
| 1868 | n/a | if host_platform != "cygwin": |
|---|
| 1869 | n/a | libs.append('X11') |
|---|
| 1870 | n/a | |
|---|
| 1871 | n/a | ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
|---|
| 1872 | n/a | define_macros=[('WITH_APPINIT', 1)] + defs, |
|---|
| 1873 | n/a | include_dirs = include_dirs, |
|---|
| 1874 | n/a | libraries = libs, |
|---|
| 1875 | n/a | library_dirs = added_lib_dirs, |
|---|
| 1876 | n/a | ) |
|---|
| 1877 | n/a | self.extensions.append(ext) |
|---|
| 1878 | n/a | |
|---|
| 1879 | n/a | # XXX handle these, but how to detect? |
|---|
| 1880 | n/a | # *** Uncomment and edit for PIL (TkImaging) extension only: |
|---|
| 1881 | n/a | # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ |
|---|
| 1882 | n/a | # *** Uncomment and edit for TOGL extension only: |
|---|
| 1883 | n/a | # -DWITH_TOGL togl.c \ |
|---|
| 1884 | n/a | # *** Uncomment these for TOGL extension only: |
|---|
| 1885 | n/a | # -lGL -lGLU -lXext -lXmu \ |
|---|
| 1886 | n/a | |
|---|
| 1887 | n/a | def configure_ctypes_darwin(self, ext): |
|---|
| 1888 | n/a | # Darwin (OS X) uses preconfigured files, in |
|---|
| 1889 | n/a | # the Modules/_ctypes/libffi_osx directory. |
|---|
| 1890 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 1891 | n/a | ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', |
|---|
| 1892 | n/a | '_ctypes', 'libffi_osx')) |
|---|
| 1893 | n/a | sources = [os.path.join(ffi_srcdir, p) |
|---|
| 1894 | n/a | for p in ['ffi.c', |
|---|
| 1895 | n/a | 'x86/darwin64.S', |
|---|
| 1896 | n/a | 'x86/x86-darwin.S', |
|---|
| 1897 | n/a | 'x86/x86-ffi_darwin.c', |
|---|
| 1898 | n/a | 'x86/x86-ffi64.c', |
|---|
| 1899 | n/a | 'powerpc/ppc-darwin.S', |
|---|
| 1900 | n/a | 'powerpc/ppc-darwin_closure.S', |
|---|
| 1901 | n/a | 'powerpc/ppc-ffi_darwin.c', |
|---|
| 1902 | n/a | 'powerpc/ppc64-darwin_closure.S', |
|---|
| 1903 | n/a | ]] |
|---|
| 1904 | n/a | |
|---|
| 1905 | n/a | # Add .S (preprocessed assembly) to C compiler source extensions. |
|---|
| 1906 | n/a | self.compiler.src_extensions.append('.S') |
|---|
| 1907 | n/a | |
|---|
| 1908 | n/a | include_dirs = [os.path.join(ffi_srcdir, 'include'), |
|---|
| 1909 | n/a | os.path.join(ffi_srcdir, 'powerpc')] |
|---|
| 1910 | n/a | ext.include_dirs.extend(include_dirs) |
|---|
| 1911 | n/a | ext.sources.extend(sources) |
|---|
| 1912 | n/a | return True |
|---|
| 1913 | n/a | |
|---|
| 1914 | n/a | def configure_ctypes(self, ext): |
|---|
| 1915 | n/a | if not self.use_system_libffi: |
|---|
| 1916 | n/a | if host_platform == 'darwin': |
|---|
| 1917 | n/a | return self.configure_ctypes_darwin(ext) |
|---|
| 1918 | n/a | print('INFO: Could not locate ffi libs and/or headers') |
|---|
| 1919 | n/a | return False |
|---|
| 1920 | n/a | return True |
|---|
| 1921 | n/a | |
|---|
| 1922 | n/a | def detect_ctypes(self, inc_dirs, lib_dirs): |
|---|
| 1923 | n/a | self.use_system_libffi = False |
|---|
| 1924 | n/a | include_dirs = [] |
|---|
| 1925 | n/a | extra_compile_args = [] |
|---|
| 1926 | n/a | extra_link_args = [] |
|---|
| 1927 | n/a | sources = ['_ctypes/_ctypes.c', |
|---|
| 1928 | n/a | '_ctypes/callbacks.c', |
|---|
| 1929 | n/a | '_ctypes/callproc.c', |
|---|
| 1930 | n/a | '_ctypes/stgdict.c', |
|---|
| 1931 | n/a | '_ctypes/cfield.c'] |
|---|
| 1932 | n/a | depends = ['_ctypes/ctypes.h'] |
|---|
| 1933 | n/a | math_libs = self.detect_math_libs() |
|---|
| 1934 | n/a | |
|---|
| 1935 | n/a | if host_platform == 'darwin': |
|---|
| 1936 | n/a | sources.append('_ctypes/malloc_closure.c') |
|---|
| 1937 | n/a | sources.append('_ctypes/darwin/dlfcn_simple.c') |
|---|
| 1938 | n/a | extra_compile_args.append('-DMACOSX') |
|---|
| 1939 | n/a | include_dirs.append('_ctypes/darwin') |
|---|
| 1940 | n/a | # XXX Is this still needed? |
|---|
| 1941 | n/a | ## extra_link_args.extend(['-read_only_relocs', 'warning']) |
|---|
| 1942 | n/a | |
|---|
| 1943 | n/a | elif host_platform == 'sunos5': |
|---|
| 1944 | n/a | # XXX This shouldn't be necessary; it appears that some |
|---|
| 1945 | n/a | # of the assembler code is non-PIC (i.e. it has relocations |
|---|
| 1946 | n/a | # when it shouldn't. The proper fix would be to rewrite |
|---|
| 1947 | n/a | # the assembler code to be PIC. |
|---|
| 1948 | n/a | # This only works with GCC; the Sun compiler likely refuses |
|---|
| 1949 | n/a | # this option. If you want to compile ctypes with the Sun |
|---|
| 1950 | n/a | # compiler, please research a proper solution, instead of |
|---|
| 1951 | n/a | # finding some -z option for the Sun compiler. |
|---|
| 1952 | n/a | extra_link_args.append('-mimpure-text') |
|---|
| 1953 | n/a | |
|---|
| 1954 | n/a | elif host_platform.startswith('hp-ux'): |
|---|
| 1955 | n/a | extra_link_args.append('-fPIC') |
|---|
| 1956 | n/a | |
|---|
| 1957 | n/a | ext = Extension('_ctypes', |
|---|
| 1958 | n/a | include_dirs=include_dirs, |
|---|
| 1959 | n/a | extra_compile_args=extra_compile_args, |
|---|
| 1960 | n/a | extra_link_args=extra_link_args, |
|---|
| 1961 | n/a | libraries=[], |
|---|
| 1962 | n/a | sources=sources, |
|---|
| 1963 | n/a | depends=depends) |
|---|
| 1964 | n/a | # function my_sqrt() needs math library for sqrt() |
|---|
| 1965 | n/a | ext_test = Extension('_ctypes_test', |
|---|
| 1966 | n/a | sources=['_ctypes/_ctypes_test.c'], |
|---|
| 1967 | n/a | libraries=math_libs) |
|---|
| 1968 | n/a | self.extensions.extend([ext, ext_test]) |
|---|
| 1969 | n/a | |
|---|
| 1970 | n/a | if host_platform == 'darwin': |
|---|
| 1971 | n/a | if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"): |
|---|
| 1972 | n/a | return |
|---|
| 1973 | n/a | # OS X 10.5 comes with libffi.dylib; the include files are |
|---|
| 1974 | n/a | # in /usr/include/ffi |
|---|
| 1975 | n/a | inc_dirs.append('/usr/include/ffi') |
|---|
| 1976 | n/a | |
|---|
| 1977 | n/a | ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")] |
|---|
| 1978 | n/a | if not ffi_inc or ffi_inc[0] == '': |
|---|
| 1979 | n/a | ffi_inc = find_file('ffi.h', [], inc_dirs) |
|---|
| 1980 | n/a | if ffi_inc is not None: |
|---|
| 1981 | n/a | ffi_h = ffi_inc[0] + '/ffi.h' |
|---|
| 1982 | n/a | with open(ffi_h) as f: |
|---|
| 1983 | n/a | for line in f: |
|---|
| 1984 | n/a | line = line.strip() |
|---|
| 1985 | n/a | if line.startswith(('#define LIBFFI_H', |
|---|
| 1986 | n/a | '#define ffi_wrapper_h')): |
|---|
| 1987 | n/a | break |
|---|
| 1988 | n/a | else: |
|---|
| 1989 | n/a | ffi_inc = None |
|---|
| 1990 | n/a | print('Header file {} does not define LIBFFI_H or ' |
|---|
| 1991 | n/a | 'ffi_wrapper_h'.format(ffi_h)) |
|---|
| 1992 | n/a | ffi_lib = None |
|---|
| 1993 | n/a | if ffi_inc is not None: |
|---|
| 1994 | n/a | for lib_name in ('ffi', 'ffi_pic'): |
|---|
| 1995 | n/a | if (self.compiler.find_library_file(lib_dirs, lib_name)): |
|---|
| 1996 | n/a | ffi_lib = lib_name |
|---|
| 1997 | n/a | break |
|---|
| 1998 | n/a | |
|---|
| 1999 | n/a | if ffi_inc and ffi_lib: |
|---|
| 2000 | n/a | ext.include_dirs.extend(ffi_inc) |
|---|
| 2001 | n/a | ext.libraries.append(ffi_lib) |
|---|
| 2002 | n/a | self.use_system_libffi = True |
|---|
| 2003 | n/a | |
|---|
| 2004 | n/a | def _decimal_ext(self): |
|---|
| 2005 | n/a | extra_compile_args = [] |
|---|
| 2006 | n/a | undef_macros = [] |
|---|
| 2007 | n/a | if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"): |
|---|
| 2008 | n/a | include_dirs = [] |
|---|
| 2009 | n/a | libraries = [':libmpdec.so.2'] |
|---|
| 2010 | n/a | sources = ['_decimal/_decimal.c'] |
|---|
| 2011 | n/a | depends = ['_decimal/docstrings.h'] |
|---|
| 2012 | n/a | else: |
|---|
| 2013 | n/a | srcdir = sysconfig.get_config_var('srcdir') |
|---|
| 2014 | n/a | include_dirs = [os.path.abspath(os.path.join(srcdir, |
|---|
| 2015 | n/a | 'Modules', |
|---|
| 2016 | n/a | '_decimal', |
|---|
| 2017 | n/a | 'libmpdec'))] |
|---|
| 2018 | n/a | libraries = self.detect_math_libs() |
|---|
| 2019 | n/a | sources = [ |
|---|
| 2020 | n/a | '_decimal/_decimal.c', |
|---|
| 2021 | n/a | '_decimal/libmpdec/basearith.c', |
|---|
| 2022 | n/a | '_decimal/libmpdec/constants.c', |
|---|
| 2023 | n/a | '_decimal/libmpdec/context.c', |
|---|
| 2024 | n/a | '_decimal/libmpdec/convolute.c', |
|---|
| 2025 | n/a | '_decimal/libmpdec/crt.c', |
|---|
| 2026 | n/a | '_decimal/libmpdec/difradix2.c', |
|---|
| 2027 | n/a | '_decimal/libmpdec/fnt.c', |
|---|
| 2028 | n/a | '_decimal/libmpdec/fourstep.c', |
|---|
| 2029 | n/a | '_decimal/libmpdec/io.c', |
|---|
| 2030 | n/a | '_decimal/libmpdec/memory.c', |
|---|
| 2031 | n/a | '_decimal/libmpdec/mpdecimal.c', |
|---|
| 2032 | n/a | '_decimal/libmpdec/numbertheory.c', |
|---|
| 2033 | n/a | '_decimal/libmpdec/sixstep.c', |
|---|
| 2034 | n/a | '_decimal/libmpdec/transpose.c', |
|---|
| 2035 | n/a | ] |
|---|
| 2036 | n/a | depends = [ |
|---|
| 2037 | n/a | '_decimal/docstrings.h', |
|---|
| 2038 | n/a | '_decimal/libmpdec/basearith.h', |
|---|
| 2039 | n/a | '_decimal/libmpdec/bits.h', |
|---|
| 2040 | n/a | '_decimal/libmpdec/constants.h', |
|---|
| 2041 | n/a | '_decimal/libmpdec/convolute.h', |
|---|
| 2042 | n/a | '_decimal/libmpdec/crt.h', |
|---|
| 2043 | n/a | '_decimal/libmpdec/difradix2.h', |
|---|
| 2044 | n/a | '_decimal/libmpdec/fnt.h', |
|---|
| 2045 | n/a | '_decimal/libmpdec/fourstep.h', |
|---|
| 2046 | n/a | '_decimal/libmpdec/io.h', |
|---|
| 2047 | n/a | '_decimal/libmpdec/mpalloc.h', |
|---|
| 2048 | n/a | '_decimal/libmpdec/mpdecimal.h', |
|---|
| 2049 | n/a | '_decimal/libmpdec/numbertheory.h', |
|---|
| 2050 | n/a | '_decimal/libmpdec/sixstep.h', |
|---|
| 2051 | n/a | '_decimal/libmpdec/transpose.h', |
|---|
| 2052 | n/a | '_decimal/libmpdec/typearith.h', |
|---|
| 2053 | n/a | '_decimal/libmpdec/umodarith.h', |
|---|
| 2054 | n/a | ] |
|---|
| 2055 | n/a | |
|---|
| 2056 | n/a | config = { |
|---|
| 2057 | n/a | 'x64': [('CONFIG_64','1'), ('ASM','1')], |
|---|
| 2058 | n/a | 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')], |
|---|
| 2059 | n/a | 'ansi64': [('CONFIG_64','1'), ('ANSI','1')], |
|---|
| 2060 | n/a | 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')], |
|---|
| 2061 | n/a | 'ansi32': [('CONFIG_32','1'), ('ANSI','1')], |
|---|
| 2062 | n/a | 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'), |
|---|
| 2063 | n/a | ('LEGACY_COMPILER','1')], |
|---|
| 2064 | n/a | 'universal': [('UNIVERSAL','1')] |
|---|
| 2065 | n/a | } |
|---|
| 2066 | n/a | |
|---|
| 2067 | n/a | cc = sysconfig.get_config_var('CC') |
|---|
| 2068 | n/a | sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T') |
|---|
| 2069 | n/a | machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE') |
|---|
| 2070 | n/a | |
|---|
| 2071 | n/a | if machine: |
|---|
| 2072 | n/a | # Override automatic configuration to facilitate testing. |
|---|
| 2073 | n/a | define_macros = config[machine] |
|---|
| 2074 | n/a | elif host_platform == 'darwin': |
|---|
| 2075 | n/a | # Universal here means: build with the same options Python |
|---|
| 2076 | n/a | # was built with. |
|---|
| 2077 | n/a | define_macros = config['universal'] |
|---|
| 2078 | n/a | elif sizeof_size_t == 8: |
|---|
| 2079 | n/a | if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'): |
|---|
| 2080 | n/a | define_macros = config['x64'] |
|---|
| 2081 | n/a | elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'): |
|---|
| 2082 | n/a | define_macros = config['uint128'] |
|---|
| 2083 | n/a | else: |
|---|
| 2084 | n/a | define_macros = config['ansi64'] |
|---|
| 2085 | n/a | elif sizeof_size_t == 4: |
|---|
| 2086 | n/a | ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87') |
|---|
| 2087 | n/a | if ppro and ('gcc' in cc or 'clang' in cc) and \ |
|---|
| 2088 | n/a | not 'sunos' in host_platform: |
|---|
| 2089 | n/a | # solaris: problems with register allocation. |
|---|
| 2090 | n/a | # icc >= 11.0 works as well. |
|---|
| 2091 | n/a | define_macros = config['ppro'] |
|---|
| 2092 | n/a | extra_compile_args.append('-Wno-unknown-pragmas') |
|---|
| 2093 | n/a | else: |
|---|
| 2094 | n/a | define_macros = config['ansi32'] |
|---|
| 2095 | n/a | else: |
|---|
| 2096 | n/a | raise DistutilsError("_decimal: unsupported architecture") |
|---|
| 2097 | n/a | |
|---|
| 2098 | n/a | # Workarounds for toolchain bugs: |
|---|
| 2099 | n/a | if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'): |
|---|
| 2100 | n/a | # Some versions of gcc miscompile inline asm: |
|---|
| 2101 | n/a | # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 |
|---|
| 2102 | n/a | # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html |
|---|
| 2103 | n/a | extra_compile_args.append('-fno-ipa-pure-const') |
|---|
| 2104 | n/a | if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'): |
|---|
| 2105 | n/a | # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect: |
|---|
| 2106 | n/a | # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html |
|---|
| 2107 | n/a | undef_macros.append('_FORTIFY_SOURCE') |
|---|
| 2108 | n/a | |
|---|
| 2109 | n/a | # Faster version without thread local contexts: |
|---|
| 2110 | n/a | if not sysconfig.get_config_var('WITH_THREAD'): |
|---|
| 2111 | n/a | define_macros.append(('WITHOUT_THREADS', 1)) |
|---|
| 2112 | n/a | |
|---|
| 2113 | n/a | # Uncomment for extra functionality: |
|---|
| 2114 | n/a | #define_macros.append(('EXTRA_FUNCTIONALITY', 1)) |
|---|
| 2115 | n/a | ext = Extension ( |
|---|
| 2116 | n/a | '_decimal', |
|---|
| 2117 | n/a | include_dirs=include_dirs, |
|---|
| 2118 | n/a | libraries=libraries, |
|---|
| 2119 | n/a | define_macros=define_macros, |
|---|
| 2120 | n/a | undef_macros=undef_macros, |
|---|
| 2121 | n/a | extra_compile_args=extra_compile_args, |
|---|
| 2122 | n/a | sources=sources, |
|---|
| 2123 | n/a | depends=depends |
|---|
| 2124 | n/a | ) |
|---|
| 2125 | n/a | return ext |
|---|
| 2126 | n/a | |
|---|
| 2127 | n/a | class PyBuildInstall(install): |
|---|
| 2128 | n/a | # Suppress the warning about installation into the lib_dynload |
|---|
| 2129 | n/a | # directory, which is not in sys.path when running Python during |
|---|
| 2130 | n/a | # installation: |
|---|
| 2131 | n/a | def initialize_options (self): |
|---|
| 2132 | n/a | install.initialize_options(self) |
|---|
| 2133 | n/a | self.warn_dir=0 |
|---|
| 2134 | n/a | |
|---|
| 2135 | n/a | # Customize subcommands to not install an egg-info file for Python |
|---|
| 2136 | n/a | sub_commands = [('install_lib', install.has_lib), |
|---|
| 2137 | n/a | ('install_headers', install.has_headers), |
|---|
| 2138 | n/a | ('install_scripts', install.has_scripts), |
|---|
| 2139 | n/a | ('install_data', install.has_data)] |
|---|
| 2140 | n/a | |
|---|
| 2141 | n/a | |
|---|
| 2142 | n/a | class PyBuildInstallLib(install_lib): |
|---|
| 2143 | n/a | # Do exactly what install_lib does but make sure correct access modes get |
|---|
| 2144 | n/a | # set on installed directories and files. All installed files with get |
|---|
| 2145 | n/a | # mode 644 unless they are a shared library in which case they will get |
|---|
| 2146 | n/a | # mode 755. All installed directories will get mode 755. |
|---|
| 2147 | n/a | |
|---|
| 2148 | n/a | # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX |
|---|
| 2149 | n/a | shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX") |
|---|
| 2150 | n/a | |
|---|
| 2151 | n/a | def install(self): |
|---|
| 2152 | n/a | outfiles = install_lib.install(self) |
|---|
| 2153 | n/a | self.set_file_modes(outfiles, 0o644, 0o755) |
|---|
| 2154 | n/a | self.set_dir_modes(self.install_dir, 0o755) |
|---|
| 2155 | n/a | return outfiles |
|---|
| 2156 | n/a | |
|---|
| 2157 | n/a | def set_file_modes(self, files, defaultMode, sharedLibMode): |
|---|
| 2158 | n/a | if not self.is_chmod_supported(): return |
|---|
| 2159 | n/a | if not files: return |
|---|
| 2160 | n/a | |
|---|
| 2161 | n/a | for filename in files: |
|---|
| 2162 | n/a | if os.path.islink(filename): continue |
|---|
| 2163 | n/a | mode = defaultMode |
|---|
| 2164 | n/a | if filename.endswith(self.shlib_suffix): mode = sharedLibMode |
|---|
| 2165 | n/a | log.info("changing mode of %s to %o", filename, mode) |
|---|
| 2166 | n/a | if not self.dry_run: os.chmod(filename, mode) |
|---|
| 2167 | n/a | |
|---|
| 2168 | n/a | def set_dir_modes(self, dirname, mode): |
|---|
| 2169 | n/a | if not self.is_chmod_supported(): return |
|---|
| 2170 | n/a | for dirpath, dirnames, fnames in os.walk(dirname): |
|---|
| 2171 | n/a | if os.path.islink(dirpath): |
|---|
| 2172 | n/a | continue |
|---|
| 2173 | n/a | log.info("changing mode of %s to %o", dirpath, mode) |
|---|
| 2174 | n/a | if not self.dry_run: os.chmod(dirpath, mode) |
|---|
| 2175 | n/a | |
|---|
| 2176 | n/a | def is_chmod_supported(self): |
|---|
| 2177 | n/a | return hasattr(os, 'chmod') |
|---|
| 2178 | n/a | |
|---|
| 2179 | n/a | class PyBuildScripts(build_scripts): |
|---|
| 2180 | n/a | def copy_scripts(self): |
|---|
| 2181 | n/a | outfiles, updated_files = build_scripts.copy_scripts(self) |
|---|
| 2182 | n/a | fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info) |
|---|
| 2183 | n/a | minoronly = '.{0[1]}'.format(sys.version_info) |
|---|
| 2184 | n/a | newoutfiles = [] |
|---|
| 2185 | n/a | newupdated_files = [] |
|---|
| 2186 | n/a | for filename in outfiles: |
|---|
| 2187 | n/a | if filename.endswith(('2to3', 'pyvenv')): |
|---|
| 2188 | n/a | newfilename = filename + fullversion |
|---|
| 2189 | n/a | else: |
|---|
| 2190 | n/a | newfilename = filename + minoronly |
|---|
| 2191 | n/a | log.info('renaming %s to %s', filename, newfilename) |
|---|
| 2192 | n/a | os.rename(filename, newfilename) |
|---|
| 2193 | n/a | newoutfiles.append(newfilename) |
|---|
| 2194 | n/a | if filename in updated_files: |
|---|
| 2195 | n/a | newupdated_files.append(newfilename) |
|---|
| 2196 | n/a | return newoutfiles, newupdated_files |
|---|
| 2197 | n/a | |
|---|
| 2198 | n/a | SUMMARY = """ |
|---|
| 2199 | n/a | Python is an interpreted, interactive, object-oriented programming |
|---|
| 2200 | n/a | language. It is often compared to Tcl, Perl, Scheme or Java. |
|---|
| 2201 | n/a | |
|---|
| 2202 | n/a | Python combines remarkable power with very clear syntax. It has |
|---|
| 2203 | n/a | modules, classes, exceptions, very high level dynamic data types, and |
|---|
| 2204 | n/a | dynamic typing. There are interfaces to many system calls and |
|---|
| 2205 | n/a | libraries, as well as to various windowing systems (X11, Motif, Tk, |
|---|
| 2206 | n/a | Mac, MFC). New built-in modules are easily written in C or C++. Python |
|---|
| 2207 | n/a | is also usable as an extension language for applications that need a |
|---|
| 2208 | n/a | programmable interface. |
|---|
| 2209 | n/a | |
|---|
| 2210 | n/a | The Python implementation is portable: it runs on many brands of UNIX, |
|---|
| 2211 | n/a | on Windows, DOS, Mac, Amiga... If your favorite system isn't |
|---|
| 2212 | n/a | listed here, it may still be supported, if there's a C compiler for |
|---|
| 2213 | n/a | it. Ask around on comp.lang.python -- or just try compiling Python |
|---|
| 2214 | n/a | yourself. |
|---|
| 2215 | n/a | """ |
|---|
| 2216 | n/a | |
|---|
| 2217 | n/a | CLASSIFIERS = """ |
|---|
| 2218 | n/a | Development Status :: 6 - Mature |
|---|
| 2219 | n/a | License :: OSI Approved :: Python Software Foundation License |
|---|
| 2220 | n/a | Natural Language :: English |
|---|
| 2221 | n/a | Programming Language :: C |
|---|
| 2222 | n/a | Programming Language :: Python |
|---|
| 2223 | n/a | Topic :: Software Development |
|---|
| 2224 | n/a | """ |
|---|
| 2225 | n/a | |
|---|
| 2226 | n/a | def main(): |
|---|
| 2227 | n/a | # turn off warnings when deprecated modules are imported |
|---|
| 2228 | n/a | import warnings |
|---|
| 2229 | n/a | warnings.filterwarnings("ignore",category=DeprecationWarning) |
|---|
| 2230 | n/a | setup(# PyPI Metadata (PEP 301) |
|---|
| 2231 | n/a | name = "Python", |
|---|
| 2232 | n/a | version = sys.version.split()[0], |
|---|
| 2233 | n/a | url = "http://www.python.org/%d.%d" % sys.version_info[:2], |
|---|
| 2234 | n/a | maintainer = "Guido van Rossum and the Python community", |
|---|
| 2235 | n/a | maintainer_email = "python-dev@python.org", |
|---|
| 2236 | n/a | description = "A high-level object-oriented programming language", |
|---|
| 2237 | n/a | long_description = SUMMARY.strip(), |
|---|
| 2238 | n/a | license = "PSF license", |
|---|
| 2239 | n/a | classifiers = [x for x in CLASSIFIERS.split("\n") if x], |
|---|
| 2240 | n/a | platforms = ["Many"], |
|---|
| 2241 | n/a | |
|---|
| 2242 | n/a | # Build info |
|---|
| 2243 | n/a | cmdclass = {'build_ext': PyBuildExt, |
|---|
| 2244 | n/a | 'build_scripts': PyBuildScripts, |
|---|
| 2245 | n/a | 'install': PyBuildInstall, |
|---|
| 2246 | n/a | 'install_lib': PyBuildInstallLib}, |
|---|
| 2247 | n/a | # The struct module is defined here, because build_ext won't be |
|---|
| 2248 | n/a | # called unless there's at least one extension module defined. |
|---|
| 2249 | n/a | ext_modules=[Extension('_struct', ['_struct.c'])], |
|---|
| 2250 | n/a | |
|---|
| 2251 | n/a | # If you change the scripts installed here, you also need to |
|---|
| 2252 | n/a | # check the PyBuildScripts command above, and change the links |
|---|
| 2253 | n/a | # created by the bininstall target in Makefile.pre.in |
|---|
| 2254 | n/a | scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3", |
|---|
| 2255 | n/a | "Tools/scripts/2to3", "Tools/scripts/pyvenv"] |
|---|
| 2256 | n/a | ) |
|---|
| 2257 | n/a | |
|---|
| 2258 | n/a | # --install-platlib |
|---|
| 2259 | n/a | if __name__ == '__main__': |
|---|
| 2260 | n/a | main() |
|---|