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