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