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