blob: 4f4b42d1d9d6acee9f9329a0330ec34346731519 [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +00002
Victor Stinner625dbf22019-03-01 15:59:39 +01003import argparse
Eric Snow335e14d2014-01-04 15:09:28 -07004import importlib._bootstrap
Victor Stinner625dbf22019-03-01 15:59:39 +01005import importlib.machinery
Eric Snow335e14d2014-01-04 15:09:28 -07006import importlib.util
Victor Stinner625dbf22019-03-01 15:59:39 +01007import os
8import re
9import sys
Tarek Ziadéedacea32010-01-29 11:41:03 +000010import sysconfig
Victor Stinnerd9ba9de2021-04-14 16:38:58 +020011import warnings
Serhiy Storchaka93558682020-06-20 11:10:31 +030012from glob import glob, escape
Ronald Oussoren404a7192020-11-22 06:14:25 +010013import _osx_support
Michael W. Hudson529a5052002-12-17 16:47:17 +000014
Victor Stinner1ec63b62020-03-04 14:50:19 +010015
16try:
17 import subprocess
18 del subprocess
19 SUBPROCESS_BOOTSTRAP = False
20except ImportError:
Victor Stinner1ec63b62020-03-04 14:50:19 +010021 # Bootstrap Python: distutils.spawn uses subprocess to build C extensions,
22 # subprocess requires C extensions built by setup.py like _posixsubprocess.
23 #
Victor Stinneraddaaaa2020-03-09 23:45:59 +010024 # Use _bootsubprocess which only uses the os module.
Victor Stinner1ec63b62020-03-04 14:50:19 +010025 #
26 # It is dropped from sys.modules as soon as all C extension modules
27 # are built.
Victor Stinneraddaaaa2020-03-09 23:45:59 +010028 import _bootsubprocess
29 sys.modules['subprocess'] = _bootsubprocess
30 del _bootsubprocess
31 SUBPROCESS_BOOTSTRAP = True
Victor Stinner1ec63b62020-03-04 14:50:19 +010032
33
Victor Stinnerd9ba9de2021-04-14 16:38:58 +020034with warnings.catch_warnings():
35 # bpo-41282 (PEP 632) deprecated distutils but setup.py still uses it
Christian Heimesa460ab32021-04-24 09:55:15 +020036 warnings.filterwarnings(
37 "ignore",
38 "The distutils package is deprecated",
39 DeprecationWarning
40 )
41 warnings.filterwarnings(
42 "ignore",
43 "The distutils.sysconfig module is deprecated, use sysconfig instead",
44 DeprecationWarning
45 )
Victor Stinnerd9ba9de2021-04-14 16:38:58 +020046
47 from distutils import log
48 from distutils.command.build_ext import build_ext
49 from distutils.command.build_scripts import build_scripts
50 from distutils.command.install import install
51 from distutils.command.install_lib import install_lib
52 from distutils.core import Extension, setup
53 from distutils.errors import CCompilerError, DistutilsError
54 from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000055
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020056
Victor Stinnercfe172d2019-03-01 18:21:49 +010057# Compile extensions used to test Python?
pxinwr277ce302020-12-30 20:50:39 +080058TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes')
Victor Stinnercfe172d2019-03-01 18:21:49 +010059
60# This global variable is used to hold the list of modules to be disabled.
61DISABLED_MODULE_LIST = []
62
Victor Stinnercad80202021-01-19 23:04:49 +010063# --list-module-names option used by Tools/scripts/generate_module_names.py
64LIST_MODULE_NAMES = False
65
Victor Stinnercfe172d2019-03-01 18:21:49 +010066
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020067def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010068 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020069 if "_PYTHON_HOST_PLATFORM" in os.environ:
70 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010071
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020072 # Get value of sys.platform
73 if sys.platform.startswith('osf1'):
74 return 'osf1'
75 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010076
77
78CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010079HOST_PLATFORM = get_platform()
80MS_WINDOWS = (HOST_PLATFORM == 'win32')
81CYGWIN = (HOST_PLATFORM == 'cygwin')
82MACOS = (HOST_PLATFORM == 'darwin')
Michael Felt08970cb2019-06-21 15:58:00 +020083AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 17:48:38 +010084VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080085
Victor Stinnerc991f242019-03-01 17:19:04 +010086
87SUMMARY = """
88Python is an interpreted, interactive, object-oriented programming
89language. It is often compared to Tcl, Perl, Scheme or Java.
90
91Python combines remarkable power with very clear syntax. It has
92modules, classes, exceptions, very high level dynamic data types, and
93dynamic typing. There are interfaces to many system calls and
94libraries, as well as to various windowing systems (X11, Motif, Tk,
95Mac, MFC). New built-in modules are easily written in C or C++. Python
96is also usable as an extension language for applications that need a
97programmable interface.
98
99The Python implementation is portable: it runs on many brands of UNIX,
100on Windows, DOS, Mac, Amiga... If your favorite system isn't
101listed here, it may still be supported, if there's a C compiler for
102it. Ask around on comp.lang.python -- or just try compiling Python
103yourself.
104"""
105
106CLASSIFIERS = """
107Development Status :: 6 - Mature
108License :: OSI Approved :: Python Software Foundation License
109Natural Language :: English
110Programming Language :: C
111Programming Language :: Python
112Topic :: Software Development
113"""
114
115
Victor Stinner6b982c22020-04-01 01:10:07 +0200116def run_command(cmd):
117 status = os.system(cmd)
Victor Stinner65a796e2020-04-01 18:49:29 +0200118 return os.waitstatus_to_exitcode(status)
Victor Stinner6b982c22020-04-01 01:10:07 +0200119
120
Victor Stinnerc991f242019-03-01 17:19:04 +0100121# Set common compiler and linker flags derived from the Makefile,
122# reserved for building the interpreter and the stdlib modules.
123# See bpo-21121 and bpo-35257
124def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
125 flags = sysconfig.get_config_var(compiler_flags)
126 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
127 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
128
129
Michael W. Hudson39230b32002-01-16 15:26:48 +0000130def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000131 """Add the directory 'dir' to the list 'dirlist' (after any relative
132 directories) if:
133
Michael W. Hudson39230b32002-01-16 15:26:48 +0000134 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000135 2) 'dir' actually exists, and is a directory.
136 """
137 if dir is None or not os.path.isdir(dir) or dir in dirlist:
138 return
139 for i, path in enumerate(dirlist):
140 if not os.path.isabs(path):
141 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000142 return
143 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000144
Victor Stinnerc991f242019-03-01 17:19:04 +0100145
xdegaye77f51392017-11-25 17:25:30 +0100146def sysroot_paths(make_vars, subdirs):
147 """Get the paths of sysroot sub-directories.
148
149 * make_vars: a sequence of names of variables of the Makefile where
150 sysroot may be set.
151 * subdirs: a sequence of names of subdirectories used as the location for
152 headers or libraries.
153 """
154
155 dirs = []
156 for var_name in make_vars:
157 var = sysconfig.get_config_var(var_name)
158 if var is not None:
159 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
160 if m is not None:
161 sysroot = m.group(1).strip('"')
162 for subdir in subdirs:
163 if os.path.isabs(subdir):
164 subdir = subdir[1:]
165 path = os.path.join(sysroot, subdir)
166 if os.path.isdir(path):
167 dirs.append(path)
168 break
169 return dirs
170
Ned Deily1731d6d2020-05-18 04:32:38 -0400171
Ned Deily0288dd62019-06-03 06:34:48 -0400172MACOS_SDK_ROOT = None
Ned Deily1731d6d2020-05-18 04:32:38 -0400173MACOS_SDK_SPECIFIED = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100174
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000175def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400176 """Return the directory of the current macOS SDK.
177
178 If no SDK was explicitly configured, call the compiler to find which
179 include files paths are being searched by default. Use '/' if the
180 compiler is searching /usr/include (meaning system header files are
181 installed) or use the root of an SDK if that is being searched.
182 (The SDK may be supplied via Xcode or via the Command Line Tools).
183 The SDK paths used by Apple-supplied tool chains depend on the
184 setting of various variables; see the xcrun man page for more info.
Ned Deily1731d6d2020-05-18 04:32:38 -0400185 Also sets MACOS_SDK_SPECIFIED for use by macosx_sdk_specified().
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000186 """
Ned Deily1731d6d2020-05-18 04:32:38 -0400187 global MACOS_SDK_ROOT, MACOS_SDK_SPECIFIED
Ned Deily0288dd62019-06-03 06:34:48 -0400188
189 # If already called, return cached result.
190 if MACOS_SDK_ROOT:
191 return MACOS_SDK_ROOT
192
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000193 cflags = sysconfig.get_config_var('CFLAGS')
Joshua Rootb3107002020-04-22 17:44:10 +1000194 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400195 if m is not None:
196 MACOS_SDK_ROOT = m.group(1)
Ned Deily29afab62020-12-04 23:02:09 -0500197 MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000198 else:
Ronald Oussoren404a7192020-11-22 06:14:25 +0100199 MACOS_SDK_ROOT = _osx_support._default_sysroot(
200 sysconfig.get_config_var('CC'))
Ned Deily29afab62020-12-04 23:02:09 -0500201 MACOS_SDK_SPECIFIED = False
Ned Deily0288dd62019-06-03 06:34:48 -0400202
203 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000204
Victor Stinnerc991f242019-03-01 17:19:04 +0100205
Ned Deily1731d6d2020-05-18 04:32:38 -0400206def macosx_sdk_specified():
207 """Returns true if an SDK was explicitly configured.
208
209 True if an SDK was selected at configure time, either by specifying
210 --enable-universalsdk=(something other than no or /) or by adding a
211 -isysroot option to CFLAGS. In some cases, like when making
212 decisions about macOS Tk framework paths, we need to be able to
213 know whether the user explicitly asked to build with an SDK versus
214 the implicit use of an SDK when header files are no longer
215 installed on a running system by the Command Line Tools.
216 """
217 global MACOS_SDK_SPECIFIED
218
219 # If already called, return cached result.
220 if MACOS_SDK_SPECIFIED:
221 return MACOS_SDK_SPECIFIED
222
223 # Find the sdk root and set MACOS_SDK_SPECIFIED
224 macosx_sdk_root()
225 return MACOS_SDK_SPECIFIED
226
227
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000228def is_macosx_sdk_path(path):
229 """
230 Returns True if 'path' can be located in an OSX SDK
231 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700232 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
233 or path.startswith('/System/')
234 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000235
Victor Stinnerc991f242019-03-01 17:19:04 +0100236
Ronald Oussoren41761932020-11-08 10:05:27 +0100237def grep_headers_for(function, headers):
238 for header in headers:
Ronald Oussoren7a27c7e2020-11-14 16:07:47 +0100239 with open(header, 'r', errors='surrogateescape') as f:
Ronald Oussoren41761932020-11-08 10:05:27 +0100240 if function in f.read():
241 return True
242 return False
243
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000244def find_file(filename, std_dirs, paths):
245 """Searches for the directory where a given file is located,
246 and returns a possibly-empty list of additional directories, or None
247 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000248
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000249 'filename' is the name of a file, such as readline.h or libcrypto.a.
250 'std_dirs' is the list of standard system directories; if the
251 file is found in one of them, no additional directives are needed.
252 'paths' is a list of additional locations to check; if the file is
253 found in one of them, the resulting list will contain the directory.
254 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100255 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000256 # Honor the MacOSX SDK setting when one was specified.
257 # An SDK is a directory with the same structure as a real
258 # system, but with only header files and libraries.
259 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000260
261 # Check the standard locations
262 for dir in std_dirs:
263 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000264
Victor Stinner4cbea512019-02-28 17:48:38 +0100265 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000266 f = os.path.join(sysroot, dir[1:], filename)
267
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000268 if os.path.exists(f): return []
269
270 # Check the additional directories
271 for dir in paths:
272 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000273
Victor Stinner4cbea512019-02-28 17:48:38 +0100274 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000275 f = os.path.join(sysroot, dir[1:], filename)
276
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000277 if os.path.exists(f):
278 return [dir]
279
280 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000281 return None
282
Victor Stinnerc991f242019-03-01 17:19:04 +0100283
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000284def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000285 result = compiler.find_library_file(std_dirs + paths, libname)
286 if result is None:
287 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000288
Victor Stinner4cbea512019-02-28 17:48:38 +0100289 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000290 sysroot = macosx_sdk_root()
291
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000292 # Check whether the found file is in one of the standard directories
293 dirname = os.path.dirname(result)
294 for p in std_dirs:
295 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000296 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000297
Victor Stinner4cbea512019-02-28 17:48:38 +0100298 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100299 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
300 # libraries with .tbd extensions rather than the normal .dylib
301 # shared libraries installed in /. The Apple compiler tool
302 # chain handles this transparently but it can cause problems
303 # for programs that are being built with an SDK and searching
304 # for specific libraries. Distutils find_library_file() now
305 # knows to also search for and return .tbd files. But callers
306 # of find_library_file need to keep in mind that the base filename
307 # of the returned SDK library file might have a different extension
308 # from that of the library file installed on the running system,
309 # for example:
310 # /Applications/Xcode.app/Contents/Developer/Platforms/
311 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
312 # usr/lib/libedit.tbd
313 # vs
314 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000315 if os.path.join(sysroot, p[1:]) == dirname:
316 return [ ]
317
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000318 if p == dirname:
319 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000320
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000321 # Otherwise, it must have been in one of the additional directories,
322 # so we have to figure out which one.
323 for p in paths:
324 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000325 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000326
Victor Stinner4cbea512019-02-28 17:48:38 +0100327 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000328 if os.path.join(sysroot, p[1:]) == dirname:
329 return [ p ]
330
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000331 if p == dirname:
332 return [p]
333 else:
334 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000335
Paul Ganssle62972d92020-05-16 04:20:06 -0400336def validate_tzpath():
337 base_tzpath = sysconfig.get_config_var('TZPATH')
338 if not base_tzpath:
339 return
340
341 tzpaths = base_tzpath.split(os.pathsep)
342 bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
343 if bad_paths:
344 raise ValueError('TZPATH must contain only absolute paths, '
345 + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
346 + f'{bad_paths!r}')
Victor Stinnerc991f242019-03-01 17:19:04 +0100347
Jack Jansen144ebcc2001-08-05 22:31:19 +0000348def find_module_file(module, dirlist):
349 """Find a module in a set of possible folders. If it is not found
350 return the unadorned filename"""
351 list = find_file(module, [], dirlist)
352 if not list:
353 return module
354 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100355 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000356 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000357
Victor Stinnerc991f242019-03-01 17:19:04 +0100358
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000359class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000360
Guido van Rossumd8faa362007-04-27 19:54:29 +0000361 def __init__(self, dist):
362 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100363 self.srcdir = None
364 self.lib_dirs = None
365 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100366 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000367 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400368 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100369 self.missing = []
Christian Heimes9b60e552020-05-15 23:54:53 +0200370 self.disabled_configure = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200371 if '-j' in os.environ.get('MAKEFLAGS', ''):
372 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000373
Victor Stinner8058bda2019-03-01 15:31:45 +0100374 def add(self, ext):
375 self.extensions.append(ext)
376
Victor Stinner00c77ae2020-03-04 18:44:49 +0100377 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100378 self.srcdir = sysconfig.get_config_var('srcdir')
379 if not self.srcdir:
380 # Maybe running on Windows but not using CYGWIN?
381 raise ValueError("No source directory; cannot proceed.")
382 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000383
Victor Stinner00c77ae2020-03-04 18:44:49 +0100384 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000385 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000386 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100387 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000388 # move ctypes to the end, it depends on other modules
389 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
390 if "_ctypes" in ext_map:
391 ctypes = extensions.pop(ext_map["_ctypes"])
392 extensions.append(ctypes)
393 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000394
Victor Stinner00c77ae2020-03-04 18:44:49 +0100395 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000396 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000397 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100398 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000399
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000400 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100401 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000402 for filename in self.distribution.scripts]
403
Christian Heimesaf98da12008-01-27 15:18:18 +0000404 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000405 headers = [sysconfig.get_config_h_filename()]
Serhiy Storchaka93558682020-06-20 11:10:31 +0300406 headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000407
Xavier de Gaye84968b72016-10-29 16:57:20 +0200408 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000409 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000410 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000411 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000412 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000413 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000414 else:
415 ext.depends = []
416 # re-compile extensions if a header file has been changed
417 ext.depends.extend(headers)
418
Victor Stinner00c77ae2020-03-04 18:44:49 +0100419 def remove_configured_extensions(self):
420 # The sysconfig variables built by makesetup that list the already
421 # built modules and the disabled modules as configured by the Setup
422 # files.
423 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
424 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
425
426 mods_built = []
427 mods_disabled = []
428 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200429 # If a module has already been built or has been disabled in the
430 # Setup files, don't build it here.
431 if ext.name in sysconf_built:
432 mods_built.append(ext)
433 if ext.name in sysconf_dis:
434 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000435
xdegayec0364fc2017-05-27 18:25:03 +0200436 mods_configured = mods_built + mods_disabled
437 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200438 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200439 mods_configured]
440 # Remove the shared libraries built by a previous build.
441 for ext in mods_configured:
442 fullpath = self.get_ext_fullpath(ext.name)
443 if os.path.exists(fullpath):
444 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000445
Victor Stinner00c77ae2020-03-04 18:44:49 +0100446 return (mods_built, mods_disabled)
447
448 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000449 # When you run "make CC=altcc" or something similar, you really want
450 # those environment variables passed into the setup.py phase. Here's
451 # a small set of useful ones.
452 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000453 args = {}
454 # unfortunately, distutils doesn't let us provide separate C and C++
455 # compilers
456 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000457 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
458 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000459 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000460
Victor Stinner00c77ae2020-03-04 18:44:49 +0100461 def build_extensions(self):
462 self.set_srcdir()
463
464 # Detect which modules should be compiled
465 self.detect_modules()
466
Victor Stinnercad80202021-01-19 23:04:49 +0100467 if not LIST_MODULE_NAMES:
468 self.remove_disabled()
Victor Stinner00c77ae2020-03-04 18:44:49 +0100469
470 self.update_sources_depends()
471 mods_built, mods_disabled = self.remove_configured_extensions()
472 self.set_compiler_executables()
473
Victor Stinnercad80202021-01-19 23:04:49 +0100474 if LIST_MODULE_NAMES:
475 for ext in self.extensions:
476 print(ext.name)
477 for name in self.missing:
478 print(name)
479 return
480
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000481 build_ext.build_extensions(self)
482
Victor Stinner1ec63b62020-03-04 14:50:19 +0100483 if SUBPROCESS_BOOTSTRAP:
484 # Drop our custom subprocess module:
485 # use the newly built subprocess module
486 del sys.modules['subprocess']
487
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200488 for ext in self.extensions:
489 self.check_extension_import(ext)
490
Victor Stinner00c77ae2020-03-04 18:44:49 +0100491 self.summary(mods_built, mods_disabled)
492
493 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300494 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400495 if self.failed or self.failed_on_import:
496 all_failed = self.failed + self.failed_on_import
497 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000498
499 def print_three_column(lst):
500 lst.sort(key=str.lower)
501 # guarantee zip() doesn't drop anything
502 while len(lst) % 3:
503 lst.append("")
504 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
505 print("%-*s %-*s %-*s" % (longest, e, longest, f,
506 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000507
Victor Stinner8058bda2019-03-01 15:31:45 +0100508 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000509 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400510 print("Python build finished successfully!")
511 print("The necessary bits to build these optional modules were not "
512 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100513 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000514 print("To find the necessary bits, look in setup.py in"
515 " detect_modules() for the module's name.")
516 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000517
xdegayec0364fc2017-05-27 18:25:03 +0200518 if mods_built:
519 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200520 print("The following modules found by detect_modules() in"
521 " setup.py, have been")
522 print("built by the Makefile instead, as configured by the"
523 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200524 print_three_column([ext.name for ext in mods_built])
525 print()
526
527 if mods_disabled:
528 print()
529 print("The following modules found by detect_modules() in"
530 " setup.py have not")
531 print("been built, they are *disabled* in the Setup files:")
532 print_three_column([ext.name for ext in mods_disabled])
533 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200534
Christian Heimes9b60e552020-05-15 23:54:53 +0200535 if self.disabled_configure:
536 print()
537 print("The following modules found by detect_modules() in"
538 " setup.py have not")
539 print("been built, they are *disabled* by configure:")
540 print_three_column(self.disabled_configure)
541 print()
542
Guido van Rossumd8faa362007-04-27 19:54:29 +0000543 if self.failed:
544 failed = self.failed[:]
545 print()
546 print("Failed to build these modules:")
547 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000548 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000549
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400550 if self.failed_on_import:
551 failed = self.failed_on_import[:]
552 print()
553 print("Following modules built successfully"
554 " but were removed because they could not be imported:")
555 print_three_column(failed)
556 print()
557
Christian Heimes61d478c2018-01-27 15:51:38 +0100558 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100559 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100560 print()
561 print("Could not build the ssl module!")
Christian Heimes39258d32021-04-17 11:36:35 +0200562 print("Python requires a OpenSSL 1.1.1 or newer")
Christian Heimes32eba612021-03-19 10:29:25 +0100563 if sysconfig.get_config_var("OPENSSL_LDFLAGS"):
564 print("Custom linker flags may require --with-openssl-rpath=auto")
Christian Heimes61d478c2018-01-27 15:51:38 +0100565 print()
566
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000567 def build_extension(self, ext):
568
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000569 if ext.name == '_ctypes':
570 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500571 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000572 return
573
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000574 try:
575 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000576 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000577 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100578 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000579 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000580 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200581
582 def check_extension_import(self, ext):
583 # Don't try to import an extension that has failed to compile
584 if ext.name in self.failed:
585 self.announce(
586 'WARNING: skipping import check for failed build "%s"' %
587 ext.name, level=1)
588 return
589
Jack Jansenf49c6f92001-11-01 14:44:15 +0000590 # Workaround for Mac OS X: The Carbon-based modules cannot be
591 # reliably imported into a command-line Python
592 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000593 self.announce(
594 'WARNING: skipping import check for Carbon-based "%s"' %
595 ext.name)
596 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000597
Victor Stinner4cbea512019-02-28 17:48:38 +0100598 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000599 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000600 # Don't bother doing an import check when an extension was
601 # build with an explicit '-arch' flag on OSX. That's currently
602 # only used to build 32-bit only extensions in a 4-way
603 # universal build and loading 32-bit code into a 64-bit
604 # process will fail.
605 self.announce(
606 'WARNING: skipping import check for "%s"' %
607 ext.name)
608 return
609
Jason Tishler24cf7762002-05-22 16:46:15 +0000610 # Workaround for Cygwin: Cygwin currently has fork issues when many
611 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100612 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000613 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
614 % ext.name)
615 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000616 ext_filename = os.path.join(
617 self.build_lib,
618 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000619
620 # If the build directory didn't exist when setup.py was
621 # started, sys.path_importer_cache has a negative result
622 # cached. Clear that cache before trying to import.
623 sys.path_importer_cache.clear()
624
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200625 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100626 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200627 return
628
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400629 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700630 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
631 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000632 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400633 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000634 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400635 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000636 self.announce('*** WARNING: renaming "%s" since importing it'
637 ' failed: %s' % (ext.name, why), level=3)
638 assert not self.inplace
639 basename, tail = os.path.splitext(ext_filename)
640 newname = basename + "_failed" + tail
641 if os.path.exists(newname):
642 os.remove(newname)
643 os.rename(ext_filename, newname)
644
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000645 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000646 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000647 self.announce('*** WARNING: importing extension "%s" '
648 'failed with %s: %s' % (ext.name, exc_type, why),
649 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000650 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000651
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400652 def add_multiarch_paths(self):
653 # Debian/Ubuntu multiarch support.
654 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200655 cc = sysconfig.get_config_var('CC')
656 tmpfile = os.path.join(self.build_temp, 'multiarch')
657 if not os.path.exists(self.build_temp):
658 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200659 ret = run_command(
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200660 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
661 multiarch_path_component = ''
662 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200663 if ret == 0:
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200664 with open(tmpfile) as fp:
665 multiarch_path_component = fp.readline().strip()
666 finally:
667 os.unlink(tmpfile)
668
669 if multiarch_path_component != '':
670 add_dir_to_list(self.compiler.library_dirs,
671 '/usr/lib/' + multiarch_path_component)
672 add_dir_to_list(self.compiler.include_dirs,
673 '/usr/include/' + multiarch_path_component)
674 return
675
Barry Warsaw88e19452011-04-07 10:40:36 -0400676 if not find_executable('dpkg-architecture'):
677 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200678 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100679 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200680 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400681 tmpfile = os.path.join(self.build_temp, 'multiarch')
682 if not os.path.exists(self.build_temp):
683 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200684 ret = run_command(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200685 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
686 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400687 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200688 if ret == 0:
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400689 with open(tmpfile) as fp:
690 multiarch_path_component = fp.readline().strip()
691 add_dir_to_list(self.compiler.library_dirs,
692 '/usr/lib/' + multiarch_path_component)
693 add_dir_to_list(self.compiler.include_dirs,
694 '/usr/include/' + multiarch_path_component)
695 finally:
696 os.unlink(tmpfile)
697
pxinwr5e45f1c2021-01-22 08:55:52 +0800698 def add_wrcc_search_dirs(self):
699 # add library search path by wr-cc, the compiler wrapper
700
701 def convert_mixed_path(path):
702 # convert path like C:\folder1\folder2/folder3/folder4
703 # to msys style /c/folder1/folder2/folder3/folder4
704 drive = path[0].lower()
705 left = path[2:].replace("\\", "/")
706 return "/" + drive + left
707
708 def add_search_path(line):
709 # On Windows building machine, VxWorks does
710 # cross builds under msys2 environment.
711 pathsep = (";" if sys.platform == "msys" else ":")
712 for d in line.strip().split("=")[1].split(pathsep):
713 d = d.strip()
714 if sys.platform == "msys":
715 # On Windows building machine, compiler
716 # returns mixed style path like:
717 # C:\folder1\folder2/folder3/folder4
718 d = convert_mixed_path(d)
719 d = os.path.normpath(d)
720 add_dir_to_list(self.compiler.library_dirs, d)
721
722 cc = sysconfig.get_config_var('CC')
723 tmpfile = os.path.join(self.build_temp, 'wrccpaths')
724 os.makedirs(self.build_temp, exist_ok=True)
725 try:
726 ret = run_command('%s --print-search-dirs >%s' % (cc, tmpfile))
727 if ret:
728 return
729 with open(tmpfile) as fp:
730 # Parse paths in libraries line. The line is like:
731 # On Linux, "libraries: = path1:path2:path3"
732 # On Windows, "libraries: = path1;path2;path3"
733 for line in fp:
734 if not line.startswith("libraries"):
735 continue
736 add_search_path(line)
737 finally:
738 try:
739 os.unlink(tmpfile)
740 except OSError:
741 pass
742
pxinwr32f5fdd2019-02-27 19:09:28 +0800743 def add_cross_compiling_paths(self):
744 cc = sysconfig.get_config_var('CC')
745 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200746 if not os.path.exists(self.build_temp):
747 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200748 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200749 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800750 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200751 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200752 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200753 if ret == 0:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200754 with open(tmpfile) as fp:
755 for line in fp.readlines():
756 if line.startswith("gcc version"):
757 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800758 elif line.startswith("clang version"):
759 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200760 elif line.startswith("#include <...>"):
761 in_incdirs = True
762 elif line.startswith("End of search list"):
763 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800764 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200765 for d in line.strip().split("=")[1].split(":"):
766 d = os.path.normpath(d)
767 if '/gcc/' not in d:
768 add_dir_to_list(self.compiler.library_dirs,
769 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800770 elif (is_gcc or is_clang) and in_incdirs and '/gcc/' not in line and '/clang/' not in line:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200771 add_dir_to_list(self.compiler.include_dirs,
772 line.strip())
773 finally:
774 os.unlink(tmpfile)
775
pxinwr5e45f1c2021-01-22 08:55:52 +0800776 if VXWORKS:
777 self.add_wrcc_search_dirs()
778
Victor Stinnercfe172d2019-03-01 18:21:49 +0100779 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000780 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000781 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000782 # We must get the values from the Makefile and not the environment
783 # directly since an inconsistently reproducible issue comes up where
784 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000785 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000786 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000787 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
788 ('LDFLAGS', '-L', self.compiler.library_dirs),
789 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000790 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000791 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800792 parser = argparse.ArgumentParser()
793 parser.add_argument(arg_name, dest="dirs", action="append")
794 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000795 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000796 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000797 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000798
Victor Stinnercfe172d2019-03-01 18:21:49 +0100799 def configure_compiler(self):
800 # Ensure that /usr/local is always used, but the local build
801 # directories (i.e. '.' and 'Include') must be first. See issue
802 # 10520.
803 if not CROSS_COMPILING:
804 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
805 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
806 # only change this for cross builds for 3.3, issues on Mageia
807 if CROSS_COMPILING:
808 self.add_cross_compiling_paths()
809 self.add_multiarch_paths()
810 self.add_ldflags_cppflags()
811
Victor Stinner5ec33a12019-03-01 16:43:28 +0100812 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100813 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100814 os.path.normpath(sys.base_prefix) != '/usr' and
815 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000816 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
817 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
818 # building a framework with different architectures than
819 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000820 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000821 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000822 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000823 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000824
xdegaye77f51392017-11-25 17:25:30 +0100825 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
826 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000827 # lib_dirs and inc_dirs are used to search for files;
828 # if a file is found in one of those directories, it can
829 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100830 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100831 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
832 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100833 else:
xdegaye77f51392017-11-25 17:25:30 +0100834 # Add the sysroot paths. 'sysroot' is a compiler option used to
835 # set the logical path of the standard system headers and
836 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100837 self.lib_dirs = (self.compiler.library_dirs +
838 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
839 self.inc_dirs = (self.compiler.include_dirs +
840 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
841 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000842
Brett Cannon4454a1f2005-04-15 20:32:39 +0000843 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000844 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100845 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000846
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000847 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100848 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100849 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000850
Charles-François Natali5739e102012-04-12 19:07:25 +0200851 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100852 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100853 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200854
Victor Stinner4cbea512019-02-28 17:48:38 +0100855 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000856 # This should work on any unixy platform ;-)
857 # If the user has bothered specifying additional -I and -L flags
858 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000859 #
860 # NOTE: using shlex.split would technically be more correct, but
861 # also gives a bootstrap problem. Let's hope nobody uses
862 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000863 cflags, ldflags = sysconfig.get_config_vars(
864 'CFLAGS', 'LDFLAGS')
865 for item in cflags.split():
866 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100867 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000868
869 for item in ldflags.split():
870 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100871 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000872
Victor Stinner5ec33a12019-03-01 16:43:28 +0100873 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000874 #
875 # The following modules are all pretty straightforward, and compile
876 # on pretty much any POSIXish platform.
877 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000878
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000879 # array objects
Victor Stinnercdad2722021-04-22 00:52:52 +0200880 self.add(Extension('array', ['arraymodule.c'],
881 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Martin Panterc9deece2016-02-03 05:19:44 +0000882
Yury Selivanovf23746a2018-01-22 19:11:18 -0500883 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100884 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500885
Martin Panterc9deece2016-02-03 05:19:44 +0000886 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100887
888 # math library functions, e.g. sin()
889 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100890 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100891 extra_objects=[shared_math],
892 depends=['_math.h', shared_math],
893 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100894
895 # complex math library functions
896 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100897 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100898 extra_objects=[shared_math],
899 depends=['_math.h', shared_math],
900 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200901
902 # time libraries: librt may be needed for clock_gettime()
903 time_libs = []
904 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
905 if lib:
906 time_libs.append(lib)
907
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000908 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100909 self.add(Extension('time', ['timemodule.c'],
910 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800911 # libm is needed by delta_new() that uses round() and by accum() that
912 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100913 self.add(Extension('_datetime', ['_datetimemodule.c'],
Victor Stinner04fc4f22020-06-16 01:28:07 +0200914 libraries=['m'],
915 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Paul Ganssle62972d92020-05-16 04:20:06 -0400916 # zoneinfo module
Victor Stinner37834132020-10-27 17:12:53 +0100917 self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
918 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000919 # random number generator implemented in C
Victor Stinner9f5fe792020-04-17 19:05:35 +0200920 self.add(Extension("_random", ["_randommodule.c"],
921 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000922 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100923 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000924 # heapq
Victor Stinnerc45dbe932020-06-22 17:39:32 +0200925 self.add(Extension("_heapq", ["_heapqmodule.c"],
926 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000927 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200928 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200929 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimes90540002008-05-08 14:29:10 +0000930 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100931 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200932 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100933
Fred Drake0e474a82007-10-11 18:01:43 +0000934 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100935 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000936 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100937 self.add(Extension('unicodedata', ['unicodedata.c'],
Victor Stinner47e1afd2020-10-26 16:43:47 +0100938 depends=['unicodedata_db.h', 'unicodename_db.h'],
939 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Larry Hastings3a907972013-11-23 14:49:22 -0800940 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100941 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900942 # asyncio speedups
Chris Jerdonekda742ba2020-05-17 22:47:31 -0700943 self.add(Extension("_asyncio", ["_asynciomodule.c"],
944 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000945 # _abc speedups
Victor Stinnercdad2722021-04-22 00:52:52 +0200946 self.add(Extension("_abc", ["_abc.c"],
947 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100948 # _queue module
Victor Stinnercdad2722021-04-22 00:52:52 +0200949 self.add(Extension("_queue", ["_queuemodule.c"],
950 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900951 # _statistics module
952 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000953
954 # Modules with some UNIX dependencies -- on by default:
955 # (If you have a really backward UNIX, select and socket may not be
956 # supported...)
957
958 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000959 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100960 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000961 # May be necessary on AIX for flock function
962 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100963 self.add(Extension('fcntl', ['fcntlmodule.c'],
964 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000965 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100966 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000967 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800968 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100969 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000970 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100971 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
972 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100973 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200974 # AIX has shadow passwords, but access is not via getspent(), etc.
975 # module support is not expected so it not 'missing'
976 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100977 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000978
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000979 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100980 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000981
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000982 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100983 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000984
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000985 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000986 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100987 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000988
Eric Snow7f8bfc92018-01-29 18:23:44 -0700989 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600990 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700991
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000992 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000993 # Here ends the simple stuff. From here on, modules need certain
994 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000995 #
996
997 # Multimedia modules
998 # These don't work for 64-bit platforms!!!
999 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +02001000 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +00001001 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +00001002 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +00001003 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +02001004 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -08001005 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +01001006 self.add(Extension('audioop', ['audioop.c'],
1007 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +00001008
Victor Stinner5ec33a12019-03-01 16:43:28 +01001009 # CSV files
1010 self.add(Extension('_csv', ['_csv.c']))
1011
1012 # POSIX subprocess module helper.
Kyle Evans79925792020-10-13 15:04:44 -05001013 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
1014 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner5ec33a12019-03-01 16:43:28 +01001015
Victor Stinnercfe172d2019-03-01 18:21:49 +01001016 def detect_test_extensions(self):
1017 # Python C API test module
1018 self.add(Extension('_testcapi', ['_testcapimodule.c'],
1019 depends=['testcapi_long.h']))
1020
Victor Stinner23bace22019-04-18 11:37:26 +02001021 # Python Internal C API test module
1022 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +02001023 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +02001024
Victor Stinnercfe172d2019-03-01 18:21:49 +01001025 # Python PEP-3118 (buffer protocol) test module
1026 self.add(Extension('_testbuffer', ['_testbuffer.c']))
1027
1028 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
1029 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
1030
1031 # Test multi-phase extension module init (PEP 489)
1032 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
1033
1034 # Fuzz tests.
1035 self.add(Extension('_xxtestfuzz',
1036 ['_xxtestfuzz/_xxtestfuzz.c',
1037 '_xxtestfuzz/fuzzer.c']))
1038
Victor Stinner5ec33a12019-03-01 16:43:28 +01001039 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001040 # readline
Stefan Krah095b2732010-06-08 13:41:44 +00001041 readline_termcap_library = ""
1042 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +02001043 # Cannot use os.popen here in py3k.
1044 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
1045 if not os.path.exists(self.build_temp):
1046 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +00001047 # Determine if readline is already linked against curses or tinfo.
Roland Hiebere1f77692021-02-09 02:05:25 +01001048 if sysconfig.get_config_var('HAVE_LIBREADLINE'):
1049 if sysconfig.get_config_var('WITH_EDITLINE'):
1050 readline_lib = 'edit'
1051 else:
1052 readline_lib = 'readline'
1053 do_readline = self.compiler.find_library_file(self.lib_dirs,
1054 readline_lib)
Victor Stinner4cbea512019-02-28 17:48:38 +01001055 if CROSS_COMPILING:
Victor Stinner6b982c22020-04-01 01:10:07 +02001056 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
doko@ubuntu.com58844492012-06-30 18:25:32 +02001057 % (sysconfig.get_config_var('READELF'),
1058 do_readline, tmpfile))
1059 elif find_executable('ldd'):
Victor Stinner6b982c22020-04-01 01:10:07 +02001060 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
doko@ubuntu.com58844492012-06-30 18:25:32 +02001061 else:
Victor Stinner6b982c22020-04-01 01:10:07 +02001062 ret = 1
1063 if ret == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +00001064 with open(tmpfile) as fp:
1065 for ln in fp:
1066 if 'curses' in ln:
1067 readline_termcap_library = re.sub(
1068 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
1069 ).rstrip()
1070 break
1071 # termcap interface split out from ncurses
1072 if 'tinfo' in ln:
1073 readline_termcap_library = 'tinfo'
1074 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +02001075 if os.path.exists(tmpfile):
1076 os.unlink(tmpfile)
Roland Hiebere1f77692021-02-09 02:05:25 +01001077 else:
1078 do_readline = False
Stefan Krah095b2732010-06-08 13:41:44 +00001079 # Issue 7384: If readline is already linked against curses,
1080 # use the same library for the readline and curses modules.
1081 if 'curses' in readline_termcap_library:
1082 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +01001083 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +00001084 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +02001085 # Issue 36210: OSS provided ncurses does not link on AIX
1086 # Use IBM supplied 'curses' for successful build of _curses
1087 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
1088 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001089 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001090 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001091 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001092 curses_library = 'curses'
1093
Victor Stinner4cbea512019-02-28 17:48:38 +01001094 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001095 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +00001096 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -07001097 if (dep_target and
Ronald Oussoren49926cf2021-02-01 04:29:44 +01001098 (tuple(int(n) for n in dep_target.split('.')[0:2])
Ned Deily04cdfa12014-06-25 13:36:14 -07001099 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +00001100 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001101 if os_release < 9:
1102 # MacOSX 10.4 has a broken readline. Don't try to build
1103 # the readline module unless the user has installed a fixed
1104 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +01001105 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001106 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +00001107 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +01001108 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001109 # In every directory on the search path search for a dynamic
1110 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +00001111 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +00001112 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001113 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +00001114 readline_extra_link_args = ('-Wl,-search_paths_first',)
1115 else:
1116 readline_extra_link_args = ()
1117
Roland Hiebere1f77692021-02-09 02:05:25 +01001118 readline_libs = [readline_lib]
Stefan Krah095b2732010-06-08 13:41:44 +00001119 if readline_termcap_library:
1120 pass # Issue 7384: Already linked against curses or tinfo.
1121 elif curses_library:
1122 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001123 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001124 ['/usr/lib/termcap'],
1125 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001126 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001127 self.add(Extension('readline', ['readline.c'],
1128 library_dirs=['/usr/lib/termcap'],
1129 extra_link_args=readline_extra_link_args,
1130 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001131 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001132 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001133
Victor Stinner5ec33a12019-03-01 16:43:28 +01001134 # Curses support, requiring the System V version of curses, often
1135 # provided by the ncurses library.
1136 curses_defines = []
1137 curses_includes = []
1138 panel_library = 'panel'
1139 if curses_library == 'ncursesw':
1140 curses_defines.append(('HAVE_NCURSESW', '1'))
1141 if not CROSS_COMPILING:
1142 curses_includes.append('/usr/include/ncursesw')
1143 # Bug 1464056: If _curses.so links with ncursesw,
1144 # _curses_panel.so must link with panelw.
1145 panel_library = 'panelw'
1146 if MACOS:
1147 # On OS X, there is no separate /usr/lib/libncursesw nor
1148 # libpanelw. If we are here, we found a locally-supplied
1149 # version of libncursesw. There should also be a
1150 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1151 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1152 # ncurses wide char support
1153 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1154 elif MACOS and curses_library == 'ncurses':
1155 # Building with the system-suppied combined libncurses/libpanel
1156 curses_defines.append(('HAVE_NCURSESW', '1'))
1157 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001158
Victor Stinnercfe172d2019-03-01 18:21:49 +01001159 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001160 if curses_library.startswith('ncurses'):
1161 curses_libs = [curses_library]
1162 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001163 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001164 include_dirs=curses_includes,
1165 define_macros=curses_defines,
1166 libraries=curses_libs))
1167 elif curses_library == 'curses' and not MACOS:
1168 # OSX has an old Berkeley curses, not good enough for
1169 # the _curses module.
1170 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1171 curses_libs = ['curses', 'terminfo']
1172 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1173 curses_libs = ['curses', 'termcap']
1174 else:
1175 curses_libs = ['curses']
1176
1177 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001178 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001179 define_macros=curses_defines,
1180 libraries=curses_libs))
1181 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001182 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001183 self.missing.append('_curses')
1184
1185 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001186 # _curses_panel needs some form of ncurses
1187 skip_curses_panel = True if AIX else False
1188 if (curses_enabled and not skip_curses_panel and
1189 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001190 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001191 include_dirs=curses_includes,
1192 define_macros=curses_defines,
1193 libraries=[panel_library, *curses_libs]))
1194 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001195 self.missing.append('_curses_panel')
1196
1197 def detect_crypt(self):
1198 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001199 if VXWORKS:
1200 # bpo-31904: crypt() function is not provided by VxWorks.
1201 # DES_crypt() OpenSSL provides is too weak to implement
1202 # the encryption.
Victor Stinnercad80202021-01-19 23:04:49 +01001203 self.missing.append('_crypt')
pxinwr236d0b72019-04-15 17:02:20 +08001204 return
1205
Victor Stinner625dbf22019-03-01 15:59:39 +01001206 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001207 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001208 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001209 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001210
Victor Stinnercad80202021-01-19 23:04:49 +01001211 self.add(Extension('_crypt', ['_cryptmodule.c'], libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001212
Victor Stinner5ec33a12019-03-01 16:43:28 +01001213 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001214 # socket(2)
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001215 kwargs = {'depends': ['socketmodule.h']}
pxinwr00a65682020-11-29 06:14:16 +08001216 if MACOS:
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001217 # Issue #35569: Expose RFC 3542 socket options.
1218 kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542']
Erlend Egeberg Aasland9a45bfe2020-05-17 08:32:46 +02001219
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001220 self.add(Extension('_socket', ['socketmodule.c'], **kwargs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001221
Victor Stinner5ec33a12019-03-01 16:43:28 +01001222 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001223 # Modules that provide persistent dictionary-like semantics. You will
1224 # probably want to arrange for at least one of them to be available on
1225 # your machine, though none are defined by default because of library
1226 # dependencies. The Python module dbm/__init__.py provides an
1227 # implementation independent wrapper for these; dbm/dumb.py provides
1228 # similar functionality (but slower of course) implemented in Python.
1229
1230 # Sleepycat^WOracle Berkeley DB interface.
1231 # http://www.oracle.com/database/berkeley-db/db/index.html
1232 #
1233 # This requires the Sleepycat^WOracle DB code. The supported versions
1234 # are set below. Visit the URL above to download
1235 # a release. Most open source OSes come with one or more
1236 # versions of BerkeleyDB already installed.
1237
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001238 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001239 min_db_ver = (3, 3)
1240 db_setup_debug = False # verbose debug prints from this script?
1241
1242 def allow_db_ver(db_ver):
1243 """Returns a boolean if the given BerkeleyDB version is acceptable.
1244
1245 Args:
1246 db_ver: A tuple of the version to verify.
1247 """
1248 if not (min_db_ver <= db_ver <= max_db_ver):
1249 return False
1250 return True
1251
1252 def gen_db_minor_ver_nums(major):
1253 if major == 4:
1254 for x in range(max_db_ver[1]+1):
1255 if allow_db_ver((4, x)):
1256 yield x
1257 elif major == 3:
1258 for x in (3,):
1259 if allow_db_ver((3, x)):
1260 yield x
1261 else:
1262 raise ValueError("unknown major BerkeleyDB version", major)
1263
1264 # construct a list of paths to look for the header file in on
1265 # top of the normal inc_dirs.
1266 db_inc_paths = [
1267 '/usr/include/db4',
1268 '/usr/local/include/db4',
1269 '/opt/sfw/include/db4',
1270 '/usr/include/db3',
1271 '/usr/local/include/db3',
1272 '/opt/sfw/include/db3',
1273 # Fink defaults (http://fink.sourceforge.net/)
1274 '/sw/include/db4',
1275 '/sw/include/db3',
1276 ]
1277 # 4.x minor number specific paths
1278 for x in gen_db_minor_ver_nums(4):
1279 db_inc_paths.append('/usr/include/db4%d' % x)
1280 db_inc_paths.append('/usr/include/db4.%d' % x)
1281 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1282 db_inc_paths.append('/usr/local/include/db4%d' % x)
1283 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1284 db_inc_paths.append('/opt/db-4.%d/include' % x)
1285 # MacPorts default (http://www.macports.org/)
1286 db_inc_paths.append('/opt/local/include/db4%d' % x)
1287 # 3.x minor number specific paths
1288 for x in gen_db_minor_ver_nums(3):
1289 db_inc_paths.append('/usr/include/db3%d' % x)
1290 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1291 db_inc_paths.append('/usr/local/include/db3%d' % x)
1292 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1293 db_inc_paths.append('/opt/db-3.%d/include' % x)
1294
Victor Stinner4cbea512019-02-28 17:48:38 +01001295 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001296 db_inc_paths = []
1297
Georg Brandl489cb4f2009-07-11 10:08:49 +00001298 # Add some common subdirectories for Sleepycat DB to the list,
1299 # based on the standard include directories. This way DB3/4 gets
1300 # picked up when it is installed in a non-standard prefix and
1301 # the user has added that prefix into inc_dirs.
1302 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001303 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001304 std_variants.append(os.path.join(dn, 'db3'))
1305 std_variants.append(os.path.join(dn, 'db4'))
1306 for x in gen_db_minor_ver_nums(4):
1307 std_variants.append(os.path.join(dn, "db4%d"%x))
1308 std_variants.append(os.path.join(dn, "db4.%d"%x))
1309 for x in gen_db_minor_ver_nums(3):
1310 std_variants.append(os.path.join(dn, "db3%d"%x))
1311 std_variants.append(os.path.join(dn, "db3.%d"%x))
1312
1313 db_inc_paths = std_variants + db_inc_paths
1314 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1315
1316 db_ver_inc_map = {}
1317
Victor Stinner4cbea512019-02-28 17:48:38 +01001318 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001319 sysroot = macosx_sdk_root()
1320
Georg Brandl489cb4f2009-07-11 10:08:49 +00001321 class db_found(Exception): pass
1322 try:
1323 # See whether there is a Sleepycat header in the standard
1324 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001325 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001326 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001327 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001328 f = os.path.join(sysroot, d[1:], "db.h")
1329
Georg Brandl489cb4f2009-07-11 10:08:49 +00001330 if db_setup_debug: print("db: looking for db.h in", f)
1331 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001332 with open(f, 'rb') as file:
1333 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001334 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001335 if m:
1336 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001337 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001338 db_minor = int(m.group(1))
1339 db_ver = (db_major, db_minor)
1340
1341 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1342 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001343 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001344 db_patch = int(m.group(1))
1345 if db_patch < 21:
1346 print("db.h:", db_ver, "patch", db_patch,
1347 "being ignored (4.6.x must be >= 4.6.21)")
1348 continue
1349
1350 if ( (db_ver not in db_ver_inc_map) and
1351 allow_db_ver(db_ver) ):
1352 # save the include directory with the db.h version
1353 # (first occurrence only)
1354 db_ver_inc_map[db_ver] = d
1355 if db_setup_debug:
1356 print("db.h: found", db_ver, "in", d)
1357 else:
1358 # we already found a header for this library version
1359 if db_setup_debug: print("db.h: ignoring", d)
1360 else:
1361 # ignore this header, it didn't contain a version number
1362 if db_setup_debug:
1363 print("db.h: no version number version in", d)
1364
1365 db_found_vers = list(db_ver_inc_map.keys())
1366 db_found_vers.sort()
1367
1368 while db_found_vers:
1369 db_ver = db_found_vers.pop()
1370 db_incdir = db_ver_inc_map[db_ver]
1371
1372 # check lib directories parallel to the location of the header
1373 db_dirs_to_check = [
1374 db_incdir.replace("include", 'lib64'),
1375 db_incdir.replace("include", 'lib'),
1376 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001377
Victor Stinner4cbea512019-02-28 17:48:38 +01001378 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001379 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1380
1381 else:
1382 # Same as other branch, but takes OSX SDK into account
1383 tmp = []
1384 for dn in db_dirs_to_check:
1385 if is_macosx_sdk_path(dn):
1386 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1387 tmp.append(dn)
1388 else:
1389 if os.path.isdir(dn):
1390 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001391 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001392
1393 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001394
Ezio Melotti42da6632011-03-15 05:18:48 +02001395 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001396 # XXX should we -ever- look for a dbX name? Do any
1397 # systems really not name their library by version and
1398 # symlink to more general names?
1399 for dblib in (('db-%d.%d' % db_ver),
1400 ('db%d%d' % db_ver),
1401 ('db%d' % db_ver[0])):
1402 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001403 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001404 if dblib_file:
1405 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1406 raise db_found
1407 else:
1408 if db_setup_debug: print("db lib: ", dblib, "not found")
1409
1410 except db_found:
1411 if db_setup_debug:
1412 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1413 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001414 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001415 # Only add the found library and include directories if they aren't
1416 # already being searched. This avoids an explicit runtime library
1417 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001418 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001419 db_incs = None
1420 else:
1421 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001422 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001423 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001424 else:
1425 if db_setup_debug: print("db: no appropriate library found")
1426 db_incs = None
1427 dblibs = []
1428 dblib_dir = None
1429
Victor Stinner5ec33a12019-03-01 16:43:28 +01001430 dbm_setup_debug = False # verbose debug prints from this script?
1431 dbm_order = ['gdbm']
1432 # The standard Unix dbm module:
1433 if not CYGWIN:
1434 config_args = [arg.strip("'")
1435 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1436 dbm_args = [arg for arg in config_args
1437 if arg.startswith('--with-dbmliborder=')]
1438 if dbm_args:
1439 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1440 else:
1441 dbm_order = "ndbm:gdbm:bdb".split(":")
1442 dbmext = None
1443 for cand in dbm_order:
1444 if cand == "ndbm":
1445 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1446 # Some systems have -lndbm, others have -lgdbm_compat,
1447 # others don't have either
1448 if self.compiler.find_library_file(self.lib_dirs,
1449 'ndbm'):
1450 ndbm_libs = ['ndbm']
1451 elif self.compiler.find_library_file(self.lib_dirs,
1452 'gdbm_compat'):
1453 ndbm_libs = ['gdbm_compat']
1454 else:
1455 ndbm_libs = []
1456 if dbm_setup_debug: print("building dbm using ndbm")
1457 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1458 define_macros=[
1459 ('HAVE_NDBM_H',None),
1460 ],
1461 libraries=ndbm_libs)
1462 break
1463
1464 elif cand == "gdbm":
1465 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1466 gdbm_libs = ['gdbm']
1467 if self.compiler.find_library_file(self.lib_dirs,
1468 'gdbm_compat'):
1469 gdbm_libs.append('gdbm_compat')
1470 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1471 if dbm_setup_debug: print("building dbm using gdbm")
1472 dbmext = Extension(
1473 '_dbm', ['_dbmmodule.c'],
1474 define_macros=[
1475 ('HAVE_GDBM_NDBM_H', None),
1476 ],
1477 libraries = gdbm_libs)
1478 break
1479 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1480 if dbm_setup_debug: print("building dbm using gdbm")
1481 dbmext = Extension(
1482 '_dbm', ['_dbmmodule.c'],
1483 define_macros=[
1484 ('HAVE_GDBM_DASH_NDBM_H', None),
1485 ],
1486 libraries = gdbm_libs)
1487 break
1488 elif cand == "bdb":
1489 if dblibs:
1490 if dbm_setup_debug: print("building dbm using bdb")
1491 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1492 library_dirs=dblib_dir,
1493 runtime_library_dirs=dblib_dir,
1494 include_dirs=db_incs,
1495 define_macros=[
1496 ('HAVE_BERKDB_H', None),
1497 ('DB_DBM_HSEARCH', None),
1498 ],
1499 libraries=dblibs)
1500 break
1501 if dbmext is not None:
1502 self.add(dbmext)
1503 else:
1504 self.missing.append('_dbm')
1505
1506 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1507 if ('gdbm' in dbm_order and
1508 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1509 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1510 libraries=['gdbm']))
1511 else:
1512 self.missing.append('_gdbm')
1513
1514 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001515 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001516 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001517
1518 # We hunt for #define SQLITE_VERSION "n.n.n"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001519 sqlite_incdir = sqlite_libdir = None
1520 sqlite_inc_paths = [ '/usr/include',
1521 '/usr/include/sqlite',
1522 '/usr/include/sqlite3',
1523 '/usr/local/include',
1524 '/usr/local/include/sqlite',
1525 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001526 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001527 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001528 sqlite_inc_paths = []
Erlend Egeberg Aaslandcf0b2392021-01-06 01:02:43 +01001529 MIN_SQLITE_VERSION_NUMBER = (3, 7, 15) # Issue 40810
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001530 MIN_SQLITE_VERSION = ".".join([str(x)
1531 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001532
1533 # Scan the default include directories before the SQLite specific
1534 # ones. This allows one to override the copy of sqlite on OSX,
1535 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001536 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001537 sysroot = macosx_sdk_root()
1538
Victor Stinner625dbf22019-03-01 15:59:39 +01001539 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001540 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001541 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001542 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001543
Ned Deily9b635832012-08-05 15:13:33 -07001544 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001545 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001546 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001547 with open(f) as file:
1548 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001549 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001550 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001551 if m:
1552 sqlite_version = m.group(1)
1553 sqlite_version_tuple = tuple([int(x)
1554 for x in sqlite_version.split(".")])
1555 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1556 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001557 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001558 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001559 sqlite_incdir = d
1560 break
1561 else:
1562 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001563 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001564 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001565 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001566 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001567
1568 if sqlite_incdir:
1569 sqlite_dirs_to_check = [
1570 os.path.join(sqlite_incdir, '..', 'lib64'),
1571 os.path.join(sqlite_incdir, '..', 'lib'),
1572 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1573 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1574 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001575 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001576 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001577 if sqlite_libfile:
1578 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001579
1580 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001581 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001582 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001583 '_sqlite/cursor.c',
1584 '_sqlite/microprotocols.c',
1585 '_sqlite/module.c',
1586 '_sqlite/prepare_protocol.c',
1587 '_sqlite/row.c',
1588 '_sqlite/statement.c',
1589 '_sqlite/util.c', ]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001590 sqlite_defines = []
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001591
Benjamin Peterson076ed002010-10-31 17:11:02 +00001592 # Enable support for loadable extensions in the sqlite3 module
1593 # if --enable-loadable-sqlite-extensions configure option is used.
1594 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1595 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001596
Victor Stinner4cbea512019-02-28 17:48:38 +01001597 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001598 # In every directory on the search path search for a dynamic
1599 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001600 # for dynamic libraries on the entire path.
1601 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001602 # before the dynamic library in /usr/lib.
1603 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1604 else:
1605 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001606
Brett Cannonc5011fe2011-06-06 20:09:10 -07001607 include_dirs = ["Modules/_sqlite"]
1608 # Only include the directory where sqlite was found if it does
1609 # not already exist in set include directories, otherwise you
1610 # can end up with a bad search path order.
1611 if sqlite_incdir not in self.compiler.include_dirs:
1612 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001613 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001614 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001615 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001616 self.add(Extension('_sqlite3', sqlite_srcs,
1617 define_macros=sqlite_defines,
1618 include_dirs=include_dirs,
1619 library_dirs=sqlite_libdir,
1620 extra_link_args=sqlite_extra_link_args,
1621 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001622 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001623 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001624
Victor Stinner5ec33a12019-03-01 16:43:28 +01001625 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001626 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001627 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001628 if not VXWORKS:
1629 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001630 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001631 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001632 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001633 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001634 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001635
Victor Stinner5ec33a12019-03-01 16:43:28 +01001636 # Platform-specific libraries
1637 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1638 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001639 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001640 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001641
Victor Stinner5ec33a12019-03-01 16:43:28 +01001642 if MACOS:
Ned Deily951ab582020-05-18 11:31:21 -04001643 self.add(Extension('_scproxy', ['_scproxy.c'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001644 extra_link_args=[
1645 '-framework', 'SystemConfiguration',
Ned Deily951ab582020-05-18 11:31:21 -04001646 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001647
Victor Stinner5ec33a12019-03-01 16:43:28 +01001648 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001649 # Andrew Kuchling's zlib module. Note that some versions of zlib
1650 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1651 # http://www.cert.org/advisories/CA-2002-07.html
1652 #
1653 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1654 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1655 # now, we still accept 1.1.3, because we think it's difficult to
1656 # exploit this in Python, and we'd rather make it RedHat's problem
1657 # than our problem <wink>.
1658 #
1659 # You can upgrade zlib to version 1.1.4 yourself by going to
1660 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001661 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001662 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001663 if zlib_inc is not None:
1664 zlib_h = zlib_inc[0] + '/zlib.h'
1665 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001666 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001667 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001668 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001669 with open(zlib_h) as fp:
1670 while 1:
1671 line = fp.readline()
1672 if not line:
1673 break
1674 if line.startswith('#define ZLIB_VERSION'):
1675 version = line.split()[2]
1676 break
Guido van Rossume6970912001-04-15 15:16:12 +00001677 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001678 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001679 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001680 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1681 else:
1682 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001683 self.add(Extension('zlib', ['zlibmodule.c'],
1684 libraries=['z'],
1685 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001686 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001687 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001688 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001689 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001690 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001691 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001692 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001693
Christian Heimes1dc54002008-03-24 02:19:29 +00001694 # Helper module for various ascii-encoders. Uses zlib for an optimized
1695 # crc32 if we have it. Otherwise binascii uses its own.
1696 if have_zlib:
1697 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1698 libraries = ['z']
1699 extra_link_args = zlib_extra_link_args
1700 else:
1701 extra_compile_args = []
1702 libraries = []
1703 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001704 self.add(Extension('binascii', ['binascii.c'],
1705 extra_compile_args=extra_compile_args,
1706 libraries=libraries,
1707 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001708
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001709 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001710 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001711 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001712 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1713 else:
1714 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001715 self.add(Extension('_bz2', ['_bz2module.c'],
1716 libraries=['bz2'],
1717 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001718 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001719 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001720
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001721 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001722 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001723 self.add(Extension('_lzma', ['_lzmamodule.c'],
1724 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001725 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001726 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001727
Victor Stinner5ec33a12019-03-01 16:43:28 +01001728 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001729 # Interface to the Expat XML parser
1730 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001731 # Expat was written by James Clark and is now maintained by a group of
1732 # developers on SourceForge; see www.libexpat.org for more information.
1733 # The pyexpat module was written by Paul Prescod after a prototype by
1734 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1735 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001736 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001737 #
1738 # More information on Expat can be found at www.libexpat.org.
1739 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001740 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1741 expat_inc = []
1742 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001743 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001744 expat_lib = ['expat']
1745 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001746 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001747 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001748 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001749 define_macros = [
1750 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001751 # bpo-30947: Python uses best available entropy sources to
1752 # call XML_SetHashSalt(), expat entropy sources are not needed
1753 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001754 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001755 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001756 expat_lib = []
1757 expat_sources = ['expat/xmlparse.c',
1758 'expat/xmlrole.c',
1759 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001760 expat_depends = ['expat/ascii.h',
1761 'expat/asciitab.h',
1762 'expat/expat.h',
1763 'expat/expat_config.h',
1764 'expat/expat_external.h',
1765 'expat/internal.h',
1766 'expat/latin1tab.h',
1767 'expat/utf8tab.h',
1768 'expat/xmlrole.h',
1769 'expat/xmltok.h',
1770 'expat/xmltok_impl.h'
1771 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001772
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001773 cc = sysconfig.get_config_var('CC').split()[0]
Victor Stinner6b982c22020-04-01 01:10:07 +02001774 ret = run_command(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001775 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Victor Stinner6b982c22020-04-01 01:10:07 +02001776 if ret == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001777 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001778
Victor Stinner8058bda2019-03-01 15:31:45 +01001779 self.add(Extension('pyexpat',
1780 define_macros=define_macros,
1781 extra_compile_args=extra_compile_args,
1782 include_dirs=expat_inc,
1783 libraries=expat_lib,
1784 sources=['pyexpat.c'] + expat_sources,
1785 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001786
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001787 # Fredrik Lundh's cElementTree module. Note that this also
1788 # uses expat (via the CAPI hook in pyexpat).
1789
Victor Stinner625dbf22019-03-01 15:59:39 +01001790 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001791 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001792 self.add(Extension('_elementtree',
1793 define_macros=define_macros,
1794 include_dirs=expat_inc,
1795 libraries=expat_lib,
1796 sources=['_elementtree.c'],
1797 depends=['pyexpat.c', *expat_sources,
1798 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001799 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001800 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001801
Victor Stinner5ec33a12019-03-01 16:43:28 +01001802 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001803 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001804 self.add(Extension('_multibytecodec',
1805 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001806 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001807 self.add(Extension('_codecs_%s' % loc,
1808 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001809
Victor Stinner5ec33a12019-03-01 16:43:28 +01001810 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001811 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001812 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001813 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1814 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001815 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001816 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001817 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1818 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001819 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Victor Stinner8058bda2019-03-01 15:31:45 +01001820 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001821 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001822
Victor Stinnercad80202021-01-19 23:04:49 +01001823 if (not MS_WINDOWS and
1824 sysconfig.get_config_var('HAVE_SHM_OPEN') and
1825 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
1826 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
1827 libs = []
1828 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1829 # need to link with librt to get shm_open()
1830 libs.append('rt')
1831 self.add(Extension('_posixshmem', posixshmem_srcs,
1832 define_macros={},
1833 libraries=libs,
1834 include_dirs=["Modules/_multiprocessing"]))
1835 else:
1836 self.missing.append('_posixshmem')
1837
Victor Stinner5ec33a12019-03-01 16:43:28 +01001838 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001839 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001840 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001841 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001842 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001843 uuid_libs = ['uuid']
1844 else:
1845 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001846 self.add(Extension('_uuid', ['_uuidmodule.c'],
1847 libraries=uuid_libs,
1848 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001849 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001850 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001851
Victor Stinner5ec33a12019-03-01 16:43:28 +01001852 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001853 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001854 self.init_inc_lib_dirs()
1855
1856 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001857 if TEST_EXTENSIONS:
1858 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001859 self.detect_readline_curses()
1860 self.detect_crypt()
1861 self.detect_socket()
1862 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001863 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001864 self.detect_dbm_gdbm()
1865 self.detect_sqlite()
1866 self.detect_platform_specific_exts()
1867 self.detect_nis()
1868 self.detect_compress_exts()
1869 self.detect_expat_elementtree()
1870 self.detect_multibytecodecs()
1871 self.detect_decimal()
1872 self.detect_ctypes()
1873 self.detect_multiprocessing()
1874 if not self.detect_tkinter():
1875 self.missing.append('_tkinter')
1876 self.detect_uuid()
1877
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001878## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001879## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001880
Hai Shi5787ba42021-04-06 20:55:13 +08001881 # The limited C API is not compatible with the Py_TRACE_REFS macro.
1882 if not sysconfig.get_config_var('Py_TRACE_REFS'):
1883 self.add(Extension('xxlimited', ['xxlimited.c']))
1884 self.add(Extension('xxlimited_35', ['xxlimited_35.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001885
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001886 def detect_tkinter_fromenv(self):
1887 # Build _tkinter using the Tcl/Tk locations specified by
1888 # the _TCLTK_INCLUDES and _TCLTK_LIBS environment variables.
1889 # This method is meant to be invoked by detect_tkinter().
Ned Deilyd819b932013-09-06 01:07:05 -07001890 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001891 # The variables can be set via one of the following ways.
Ned Deilyd819b932013-09-06 01:07:05 -07001892 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001893 # - Automatically, at configuration time, by using pkg-config.
1894 # The tool is called by the configure script.
1895 # Additional pkg-config configuration paths can be set via the
1896 # PKG_CONFIG_PATH environment variable.
1897 #
1898 # PKG_CONFIG_PATH=".../lib/pkgconfig" ./configure ...
1899 #
1900 # - Explicitly, at configuration time by setting both
1901 # --with-tcltk-includes and --with-tcltk-libs.
1902 #
1903 # ./configure ... \
Ned Deilyd819b932013-09-06 01:07:05 -07001904 # --with-tcltk-includes="-I/path/to/tclincludes \
1905 # -I/path/to/tkincludes"
1906 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1907 # -L/path/to/tklibs -ltkm.n"
1908 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001909 # - Explicitly, at compile time, by passing TCLTK_INCLUDES and
1910 # TCLTK_LIBS to the make target.
1911 # This will override any configuration-time option.
1912 #
1913 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
Ned Deilyd819b932013-09-06 01:07:05 -07001914 #
1915 # This can be useful for building and testing tkinter with multiple
1916 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1917 # build of Tcl so you need to specify both arguments and use care when
1918 # overriding.
1919
1920 # The _TCLTK variables are created in the Makefile sharedmods target.
1921 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1922 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1923 if not (tcltk_includes and tcltk_libs):
1924 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001925 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001926
1927 extra_compile_args = tcltk_includes.split()
1928 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001929 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1930 define_macros=[('WITH_APPINIT', 1)],
1931 extra_compile_args = extra_compile_args,
1932 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001933 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001934
Victor Stinner625dbf22019-03-01 15:59:39 +01001935 def detect_tkinter_darwin(self):
Ned Deily1731d6d2020-05-18 04:32:38 -04001936 # Build default _tkinter on macOS using Tcl and Tk frameworks.
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001937 # This method is meant to be invoked by detect_tkinter().
Ned Deily1731d6d2020-05-18 04:32:38 -04001938 #
1939 # The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
1940 # built and installed as macOS framework bundles. However,
1941 # for several reasons, we cannot take full advantage of the
1942 # Apple-supplied compiler chain's -framework options here.
1943 # Instead, we need to find and pass to the compiler the
1944 # absolute paths of the Tcl and Tk headers files we want to use
1945 # and the absolute path to the directory containing the Tcl
1946 # and Tk frameworks for linking.
1947 #
1948 # We want to handle here two common use cases on macOS:
1949 # 1. Build and link with system-wide third-party or user-built
1950 # Tcl and Tk frameworks installed in /Library/Frameworks.
1951 # 2. Build and link using a user-specified macOS SDK so that the
1952 # built Python can be exported to other systems. In this case,
1953 # search only the SDK's /Library/Frameworks (normally empty)
1954 # and /System/Library/Frameworks.
1955 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001956 # Any other use cases are handled either by detect_tkinter_fromenv(),
1957 # or detect_tkinter(). The former handles non-standard locations of
1958 # Tcl/Tk, defined via the _TCLTK_INCLUDES and _TCLTK_LIBS environment
1959 # variables. The latter handles any Tcl/Tk versions installed in
1960 # standard Unix directories.
1961 #
1962 # It would be desirable to also handle here the case where
Ned Deily1731d6d2020-05-18 04:32:38 -04001963 # you want to build and link with a framework build of Tcl and Tk
1964 # that is not in /Library/Frameworks, say, in your private
1965 # $HOME/Library/Frameworks directory or elsewhere. It turns
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301966 # out to be difficult to make that work automatically here
Ned Deily1731d6d2020-05-18 04:32:38 -04001967 # without bringing into play more tools and magic. That case
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301968 # can be handled using a recipe with the right arguments
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001969 # to detect_tkinter_fromenv().
Ned Deily1731d6d2020-05-18 04:32:38 -04001970 #
1971 # Note also that the fallback case here is to try to use the
1972 # Apple-supplied Tcl and Tk frameworks in /System/Library but
1973 # be forewarned that they are deprecated by Apple and typically
1974 # out-of-date and buggy; their use should be avoided if at
1975 # all possible by installing a newer version of Tcl and Tk in
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301976 # /Library/Frameworks before building Python without
Ned Deily1731d6d2020-05-18 04:32:38 -04001977 # an explicit SDK or by configuring build arguments explicitly.
1978
Jack Jansen0b06be72002-06-21 14:48:38 +00001979 from os.path import join, exists
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001980
Ned Deily1731d6d2020-05-18 04:32:38 -04001981 sysroot = macosx_sdk_root() # path to the SDK or '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001982
Ned Deily1731d6d2020-05-18 04:32:38 -04001983 if macosx_sdk_specified():
1984 # Use case #2: an SDK other than '/' was specified.
1985 # Only search there.
1986 framework_dirs = [
1987 join(sysroot, 'Library', 'Frameworks'),
1988 join(sysroot, 'System', 'Library', 'Frameworks'),
1989 ]
1990 else:
1991 # Use case #1: no explicit SDK selected.
1992 # Search the local system-wide /Library/Frameworks,
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301993 # not the one in the default SDK, otherwise fall back to
Ned Deily1731d6d2020-05-18 04:32:38 -04001994 # /System/Library/Frameworks whose header files may be in
1995 # the default SDK or, on older systems, actually installed.
1996 framework_dirs = [
1997 join('/', 'Library', 'Frameworks'),
1998 join(sysroot, 'System', 'Library', 'Frameworks'),
1999 ]
2000
2001 # Find the directory that contains the Tcl.framework and
2002 # Tk.framework bundles.
Jack Jansen0b06be72002-06-21 14:48:38 +00002003 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00002004 # both Tcl.framework and Tk.framework should be present
Jack Jansen0b06be72002-06-21 14:48:38 +00002005 for fw in 'Tcl', 'Tk':
Ned Deily1731d6d2020-05-18 04:32:38 -04002006 if not exists(join(F, fw + '.framework')):
2007 break
Jack Jansen0b06be72002-06-21 14:48:38 +00002008 else:
Manan Kumar Garg619f9802020-10-05 02:58:43 +05302009 # ok, F is now directory with both frameworks. Continue
Jack Jansen0b06be72002-06-21 14:48:38 +00002010 # building
2011 break
2012 else:
2013 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
2014 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01002015 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00002016
Jack Jansen0b06be72002-06-21 14:48:38 +00002017 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00002018 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002019 for fw in ('Tcl', 'Tk')
Ned Deily1731d6d2020-05-18 04:32:38 -04002020 for H in ('Headers',)
Jack Jansen0b06be72002-06-21 14:48:38 +00002021 ]
2022
Ned Deily1731d6d2020-05-18 04:32:38 -04002023 # Add the base framework directory as well
2024 compile_args = ['-F', F]
Jack Jansen0b06be72002-06-21 14:48:38 +00002025
Ned Deily1731d6d2020-05-18 04:32:38 -04002026 # Do not build tkinter for archs that this Tk was not built with.
Georg Brandlfcaf9102008-07-16 02:17:56 +00002027 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04002028 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00002029
Ronald Oussorend097efe2009-09-15 19:07:58 +00002030 tmpfile = os.path.join(self.build_temp, 'tk.arch')
2031 if not os.path.exists(self.build_temp):
2032 os.makedirs(self.build_temp)
2033
Ned Deily1731d6d2020-05-18 04:32:38 -04002034 run_command(
2035 "file {}/Tk.framework/Tk | grep 'for architecture' > {}".format(F, tmpfile)
2036 )
Brett Cannon9f5db072010-10-29 20:19:27 +00002037 with open(tmpfile) as fp:
2038 detected_archs = []
2039 for ln in fp:
2040 a = ln.split()[-1]
2041 if a in archs:
2042 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00002043 os.unlink(tmpfile)
2044
Ned Deily1731d6d2020-05-18 04:32:38 -04002045 arch_args = []
Ronald Oussorend097efe2009-09-15 19:07:58 +00002046 for a in detected_archs:
Ned Deily1731d6d2020-05-18 04:32:38 -04002047 arch_args.append('-arch')
2048 arch_args.append(a)
2049
2050 compile_args += arch_args
2051 link_args = [','.join(['-Wl', '-F', F, '-framework', 'Tcl', '-framework', 'Tk']), *arch_args]
2052
2053 # The X11/xlib.h file bundled in the Tk sources can cause function
2054 # prototype warnings from the compiler. Since we cannot easily fix
2055 # that, suppress the warnings here instead.
2056 if '-Wstrict-prototypes' in cflags.split():
2057 compile_args.append('-Wno-strict-prototypes')
Georg Brandlfcaf9102008-07-16 02:17:56 +00002058
Victor Stinnercfe172d2019-03-01 18:21:49 +01002059 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2060 define_macros=[('WITH_APPINIT', 1)],
2061 include_dirs=include_dirs,
2062 libraries=[],
Ned Deily1731d6d2020-05-18 04:32:38 -04002063 extra_compile_args=compile_args,
2064 extra_link_args=link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01002065 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002066
Victor Stinner625dbf22019-03-01 15:59:39 +01002067 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002068 # The _tkinter module.
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01002069 #
2070 # Detection of Tcl/Tk is attempted in the following order:
2071 # - Through environment variables.
2072 # - Platform specific detection of Tcl/Tk (currently only macOS).
2073 # - Search of various standard Unix header/library paths.
2074 #
2075 # Detection stops at the first successful method.
Michael W. Hudson5b109102002-01-23 15:04:41 +00002076
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01002077 # Check for Tcl and Tk at the locations indicated by _TCLTK_INCLUDES
2078 # and _TCLTK_LIBS environment variables.
2079 if self.detect_tkinter_fromenv():
Victor Stinner5ec33a12019-03-01 16:43:28 +01002080 return True
Ned Deilyd819b932013-09-06 01:07:05 -07002081
Jack Jansen0b06be72002-06-21 14:48:38 +00002082 # Rather than complicate the code below, detecting and building
2083 # AquaTk is a separate method. Only one Tkinter will be built on
2084 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01002085 if (MACOS and self.detect_tkinter_darwin()):
2086 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002087
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002088 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002089 # The versions with dots are used on Unix, and the versions without
2090 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002091 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00002092 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
2093 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01002094 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002095 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01002096 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002097 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00002098 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002099 # Exit the loop when we've found the Tcl/Tk libraries
2100 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002101
Fredrik Lundhade711a2001-01-24 08:00:28 +00002102 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002103 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002104 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002105 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002106 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01002107 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002108 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
2109 # but the include subdirs are named like .../include/tcl8.3.
2110 dotversion = dotversion[:-1] + '.' + dotversion[-1]
2111 tcl_include_sub = []
2112 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01002113 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002114 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
2115 tk_include_sub += [dir + os.sep + "tk" + dotversion]
2116 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01002117 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
2118 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002119
Martin v. Löwise86a59a2003-05-03 08:45:51 +00002120 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002121 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002122 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01002123 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00002124
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002125 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002126
Victor Stinnercfe172d2019-03-01 18:21:49 +01002127 include_dirs = []
2128 libs = []
2129 defs = []
2130 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002131 for dir in tcl_includes + tk_includes:
2132 if dir not in include_dirs:
2133 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002134
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002135 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01002136 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002137 include_dirs.append('/usr/openwin/include')
2138 added_lib_dirs.append('/usr/openwin/lib')
2139 elif os.path.exists('/usr/X11R6/include'):
2140 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00002141 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002142 added_lib_dirs.append('/usr/X11R6/lib')
2143 elif os.path.exists('/usr/X11R5/include'):
2144 include_dirs.append('/usr/X11R5/include')
2145 added_lib_dirs.append('/usr/X11R5/lib')
2146 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002147 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002148 include_dirs.append('/usr/X11/include')
2149 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002150
Jason Tishler9181c942003-02-05 15:16:17 +00002151 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01002152 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00002153 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
2154 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01002155 return False
Jason Tishler9181c942003-02-05 15:16:17 +00002156
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002157 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01002158 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002159 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002160 defs.append( ('WITH_BLT', 1) )
2161 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01002162 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002163 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00002164 defs.append( ('WITH_BLT', 1) )
2165 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002166
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002167 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00002168 libs.append('tk'+ version)
2169 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002170
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002171 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01002172 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002173 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002174
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002175 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002176 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002177 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002178 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002179 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002180 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002181 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002182
Victor Stinnercfe172d2019-03-01 18:21:49 +01002183 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2184 define_macros=[('WITH_APPINIT', 1)] + defs,
2185 include_dirs=include_dirs,
2186 libraries=libs,
2187 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002188 return True
2189
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002190 def configure_ctypes(self, ext):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002191 return True
2192
Victor Stinner625dbf22019-03-01 15:59:39 +01002193 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002194 # Thomas Heller's _ctypes module
Ronald Oussoren41761932020-11-08 10:05:27 +01002195
2196 if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
2197 self.use_system_libffi = True
2198 else:
2199 self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
2200
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002201 include_dirs = []
Victor Stinner1ae035b2020-04-17 17:47:20 +02002202 extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002203 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002204 sources = ['_ctypes/_ctypes.c',
2205 '_ctypes/callbacks.c',
2206 '_ctypes/callproc.c',
2207 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002208 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002209 depends = ['_ctypes/ctypes.h']
2210
Victor Stinner4cbea512019-02-28 17:48:38 +01002211 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002212 sources.append('_ctypes/malloc_closure.c')
Ronald Oussoren41761932020-11-08 10:05:27 +01002213 extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
Christian Heimes78644762008-03-04 23:39:23 +00002214 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002215 include_dirs.append('_ctypes/darwin')
Thomas Hellercf567c12006-03-08 19:51:58 +00002216
Victor Stinner4cbea512019-02-28 17:48:38 +01002217 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002218 # XXX This shouldn't be necessary; it appears that some
2219 # of the assembler code is non-PIC (i.e. it has relocations
2220 # when it shouldn't. The proper fix would be to rewrite
2221 # the assembler code to be PIC.
2222 # This only works with GCC; the Sun compiler likely refuses
2223 # this option. If you want to compile ctypes with the Sun
2224 # compiler, please research a proper solution, instead of
2225 # finding some -z option for the Sun compiler.
2226 extra_link_args.append('-mimpure-text')
2227
Victor Stinner4cbea512019-02-28 17:48:38 +01002228 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002229 extra_link_args.append('-fPIC')
2230
Thomas Hellercf567c12006-03-08 19:51:58 +00002231 ext = Extension('_ctypes',
2232 include_dirs=include_dirs,
2233 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002234 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002235 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002236 sources=sources,
2237 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002238 self.add(ext)
2239 if TEST_EXTENSIONS:
2240 # function my_sqrt() needs libm for sqrt()
2241 self.add(Extension('_ctypes_test',
2242 sources=['_ctypes/_ctypes_test.c'],
2243 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002244
Ronald Oussoren41761932020-11-08 10:05:27 +01002245 ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
2246 ffi_lib = None
2247
Victor Stinner625dbf22019-03-01 15:59:39 +01002248 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002249 if MACOS:
Ronald Oussoren41761932020-11-08 10:05:27 +01002250 ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
Christian Heimes78644762008-03-04 23:39:23 +00002251
Ronald Oussoren41761932020-11-08 10:05:27 +01002252 if not ffi_inc:
2253 if os.path.exists(ffi_in_sdk):
2254 ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
2255 ffi_inc = ffi_in_sdk
2256 ffi_lib = 'ffi'
2257 else:
2258 # OS X 10.5 comes with libffi.dylib; the include files are
2259 # in /usr/include/ffi
2260 ffi_inc_dirs.append('/usr/include/ffi')
2261
2262 if not ffi_inc:
2263 found = find_file('ffi.h', [], ffi_inc_dirs)
2264 if found:
2265 ffi_inc = found[0]
2266 if ffi_inc:
2267 ffi_h = ffi_inc + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002268 if not os.path.exists(ffi_h):
2269 ffi_inc = None
2270 print('Header file {} does not exist'.format(ffi_h))
Ronald Oussoren41761932020-11-08 10:05:27 +01002271 if ffi_lib is None and ffi_inc:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002272 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002273 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002274 ffi_lib = lib_name
2275 break
2276
2277 if ffi_inc and ffi_lib:
Ronald Oussoren41761932020-11-08 10:05:27 +01002278 ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
2279 if grep_headers_for('ffi_prep_cif_var', ffi_headers):
2280 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
2281 if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
2282 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
2283 if grep_headers_for('ffi_closure_alloc', ffi_headers):
2284 ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
2285
2286 ext.include_dirs.append(ffi_inc)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002287 ext.libraries.append(ffi_lib)
2288 self.use_system_libffi = True
2289
Christian Heimes5bb96922018-02-25 10:22:14 +01002290 if sysconfig.get_config_var('HAVE_LIBDL'):
2291 # for dlopen, see bpo-32647
2292 ext.libraries.append('dl')
2293
Victor Stinner5ec33a12019-03-01 16:43:28 +01002294 def detect_decimal(self):
2295 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002296 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002297 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002298 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2299 include_dirs = []
Antoine Pitrou73b20ae2021-03-30 18:11:06 +02002300 libraries = ['mpdec']
Stefan Krah60187b52012-03-23 19:06:27 +01002301 sources = ['_decimal/_decimal.c']
2302 depends = ['_decimal/docstrings.h']
2303 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002304 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002305 'Modules',
2306 '_decimal',
2307 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002308 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002309 sources = [
2310 '_decimal/_decimal.c',
2311 '_decimal/libmpdec/basearith.c',
2312 '_decimal/libmpdec/constants.c',
2313 '_decimal/libmpdec/context.c',
2314 '_decimal/libmpdec/convolute.c',
2315 '_decimal/libmpdec/crt.c',
2316 '_decimal/libmpdec/difradix2.c',
2317 '_decimal/libmpdec/fnt.c',
2318 '_decimal/libmpdec/fourstep.c',
2319 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002320 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002321 '_decimal/libmpdec/mpdecimal.c',
2322 '_decimal/libmpdec/numbertheory.c',
2323 '_decimal/libmpdec/sixstep.c',
2324 '_decimal/libmpdec/transpose.c',
2325 ]
2326 depends = [
2327 '_decimal/docstrings.h',
2328 '_decimal/libmpdec/basearith.h',
2329 '_decimal/libmpdec/bits.h',
2330 '_decimal/libmpdec/constants.h',
2331 '_decimal/libmpdec/convolute.h',
2332 '_decimal/libmpdec/crt.h',
2333 '_decimal/libmpdec/difradix2.h',
2334 '_decimal/libmpdec/fnt.h',
2335 '_decimal/libmpdec/fourstep.h',
2336 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002337 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002338 '_decimal/libmpdec/mpdecimal.h',
2339 '_decimal/libmpdec/numbertheory.h',
2340 '_decimal/libmpdec/sixstep.h',
2341 '_decimal/libmpdec/transpose.h',
2342 '_decimal/libmpdec/typearith.h',
2343 '_decimal/libmpdec/umodarith.h',
2344 ]
2345
Stefan Krah1919b7e2012-03-21 18:25:23 +01002346 config = {
2347 'x64': [('CONFIG_64','1'), ('ASM','1')],
2348 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2349 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2350 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2351 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2352 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2353 ('LEGACY_COMPILER','1')],
2354 'universal': [('UNIVERSAL','1')]
2355 }
2356
Stefan Krah1919b7e2012-03-21 18:25:23 +01002357 cc = sysconfig.get_config_var('CC')
2358 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2359 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2360
2361 if machine:
2362 # Override automatic configuration to facilitate testing.
2363 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002364 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002365 # Universal here means: build with the same options Python
2366 # was built with.
2367 define_macros = config['universal']
2368 elif sizeof_size_t == 8:
2369 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2370 define_macros = config['x64']
2371 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2372 define_macros = config['uint128']
2373 else:
2374 define_macros = config['ansi64']
2375 elif sizeof_size_t == 4:
2376 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2377 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002378 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002379 # solaris: problems with register allocation.
2380 # icc >= 11.0 works as well.
2381 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002382 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002383 else:
2384 define_macros = config['ansi32']
2385 else:
2386 raise DistutilsError("_decimal: unsupported architecture")
2387
2388 # Workarounds for toolchain bugs:
2389 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2390 # Some versions of gcc miscompile inline asm:
2391 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2392 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2393 extra_compile_args.append('-fno-ipa-pure-const')
2394 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2395 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2396 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2397 undef_macros.append('_FORTIFY_SOURCE')
2398
Stefan Krah1919b7e2012-03-21 18:25:23 +01002399 # Uncomment for extra functionality:
2400 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002401 self.add(Extension('_decimal',
2402 include_dirs=include_dirs,
2403 libraries=libraries,
2404 define_macros=define_macros,
2405 undef_macros=undef_macros,
2406 extra_compile_args=extra_compile_args,
2407 sources=sources,
2408 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002409
Victor Stinner5ec33a12019-03-01 16:43:28 +01002410 def detect_openssl_hashlib(self):
2411 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002412 config_vars = sysconfig.get_config_vars()
2413
2414 def split_var(name, sep):
2415 # poor man's shlex, the re module is not available yet.
2416 value = config_vars.get(name)
2417 if not value:
2418 return ()
2419 # This trick works because ax_check_openssl uses --libs-only-L,
2420 # --libs-only-l, and --cflags-only-I.
2421 value = ' ' + value
2422 sep = ' ' + sep
2423 return [v.strip() for v in value.split(sep) if v.strip()]
2424
2425 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2426 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2427 openssl_libs = split_var('OPENSSL_LIBS', '-l')
Christian Heimes32eba612021-03-19 10:29:25 +01002428 openssl_rpath = config_vars.get('OPENSSL_RPATH')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002429 if not openssl_libs:
2430 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002431 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002432 return None, None
2433
2434 # Find OpenSSL includes
2435 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002436 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002437 )
2438 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002439 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002440 return None, None
2441
Christian Heimes32eba612021-03-19 10:29:25 +01002442 if openssl_rpath == 'auto':
2443 runtime_library_dirs = openssl_libdirs[:]
2444 elif not openssl_rpath:
2445 runtime_library_dirs = []
2446 else:
2447 runtime_library_dirs = [openssl_rpath]
2448
Christian Heimesbacefbf2021-03-27 18:03:54 +01002449 openssl_extension_kwargs = dict(
2450 include_dirs=openssl_includes,
2451 library_dirs=openssl_libdirs,
2452 libraries=openssl_libs,
2453 runtime_library_dirs=runtime_library_dirs,
2454 )
2455
2456 # This static linking is NOT OFFICIALLY SUPPORTED.
2457 # Requires static OpenSSL build with position-independent code. Some
2458 # features like DSO engines or external OSSL providers don't work.
2459 # Only tested on GCC and clang on X86_64.
2460 if os.environ.get("PY_UNSUPPORTED_OPENSSL_BUILD") == "static":
2461 extra_linker_args = []
2462 for lib in openssl_extension_kwargs["libraries"]:
2463 # link statically
2464 extra_linker_args.append(f"-l:lib{lib}.a")
2465 # don't export symbols
2466 extra_linker_args.append(f"-Wl,--exclude-libs,lib{lib}.a")
2467 openssl_extension_kwargs["extra_link_args"] = extra_linker_args
2468 # don't link OpenSSL shared libraries.
2469 openssl_extension_kwargs["libraries"] = []
2470
Christian Heimes39258d32021-04-17 11:36:35 +02002471 self.add(
2472 Extension(
2473 '_ssl',
2474 ['_ssl.c'],
Christian Heimes7f1305e2021-04-17 20:06:38 +02002475 depends=['socketmodule.h', '_ssl/debughelpers.c', '_ssl.h'],
Christian Heimes39258d32021-04-17 11:36:35 +02002476 **openssl_extension_kwargs
Christian Heimesc7f70692019-05-31 11:44:05 +02002477 )
Christian Heimes39258d32021-04-17 11:36:35 +02002478 )
Christian Heimesbacefbf2021-03-27 18:03:54 +01002479 self.add(
2480 Extension(
2481 '_hashlib',
2482 ['_hashopenssl.c'],
2483 depends=['hashlib.h'],
2484 **openssl_extension_kwargs,
2485 )
2486 )
Christian Heimesff5be6e2018-01-20 13:19:21 +01002487
xdegaye2ee077f2019-04-09 17:20:08 +02002488 def detect_hash_builtins(self):
Christian Heimes9b60e552020-05-15 23:54:53 +02002489 # By default we always compile these even when OpenSSL is available
2490 # (issue #14693). It's harmless and the object code is tiny
2491 # (40-50 KiB per module, only loaded when actually used). Modules can
2492 # be disabled via the --with-builtin-hashlib-hashes configure flag.
2493 supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
Victor Stinner5ec33a12019-03-01 16:43:28 +01002494
Christian Heimes9b60e552020-05-15 23:54:53 +02002495 configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
2496 configured = configured.strip('"').lower()
2497 configured = {
2498 m.strip() for m in configured.split(",")
2499 }
Victor Stinner5ec33a12019-03-01 16:43:28 +01002500
Christian Heimes9b60e552020-05-15 23:54:53 +02002501 self.disabled_configure.extend(
2502 sorted(supported.difference(configured))
2503 )
Victor Stinner5ec33a12019-03-01 16:43:28 +01002504
Christian Heimes9b60e552020-05-15 23:54:53 +02002505 if "sha256" in configured:
2506 self.add(Extension(
2507 '_sha256', ['sha256module.c'],
2508 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2509 depends=['hashlib.h']
2510 ))
2511
2512 if "sha512" in configured:
2513 self.add(Extension(
2514 '_sha512', ['sha512module.c'],
2515 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2516 depends=['hashlib.h']
2517 ))
2518
2519 if "md5" in configured:
2520 self.add(Extension(
2521 '_md5', ['md5module.c'],
2522 depends=['hashlib.h']
2523 ))
2524
2525 if "sha1" in configured:
2526 self.add(Extension(
2527 '_sha1', ['sha1module.c'],
2528 depends=['hashlib.h']
2529 ))
2530
2531 if "blake2" in configured:
2532 blake2_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002533 os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002534 )
2535 blake2_deps.append('hashlib.h')
2536 self.add(Extension(
2537 '_blake2',
2538 [
2539 '_blake2/blake2module.c',
2540 '_blake2/blake2b_impl.c',
2541 '_blake2/blake2s_impl.c'
2542 ],
2543 depends=blake2_deps
2544 ))
2545
2546 if "sha3" in configured:
2547 sha3_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002548 os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002549 )
2550 sha3_deps.append('hashlib.h')
2551 self.add(Extension(
2552 '_sha3',
2553 ['_sha3/sha3module.c'],
2554 depends=sha3_deps
2555 ))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002556
2557 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002558 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002559 self.missing.append('nis')
2560 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002561
2562 libs = []
2563 library_dirs = []
2564 includes_dirs = []
2565
2566 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2567 # moved headers and libraries to libtirpc and libnsl. The headers
2568 # are in tircp and nsl sub directories.
2569 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002570 'rpcsvc/yp_prot.h', self.inc_dirs,
2571 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002572 )
2573 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002574 'rpc/rpc.h', self.inc_dirs,
2575 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002576 )
2577 if rpcsvc_inc is None or rpc_inc is None:
2578 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002579 self.missing.append('nis')
2580 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002581 includes_dirs.extend(rpcsvc_inc)
2582 includes_dirs.extend(rpc_inc)
2583
Victor Stinner625dbf22019-03-01 15:59:39 +01002584 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002585 libs.append('nsl')
2586 else:
2587 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002588 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002589 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2590 if libnsl is not None:
2591 library_dirs.append(os.path.dirname(libnsl))
2592 libs.append('nsl')
2593
Victor Stinner625dbf22019-03-01 15:59:39 +01002594 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002595 libs.append('tirpc')
2596
Victor Stinner8058bda2019-03-01 15:31:45 +01002597 self.add(Extension('nis', ['nismodule.c'],
2598 libraries=libs,
2599 library_dirs=library_dirs,
2600 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002601
Christian Heimesff5be6e2018-01-20 13:19:21 +01002602
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002603class PyBuildInstall(install):
2604 # Suppress the warning about installation into the lib_dynload
2605 # directory, which is not in sys.path when running Python during
2606 # installation:
2607 def initialize_options (self):
2608 install.initialize_options(self)
2609 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002610
Éric Araujoe6792c12011-06-09 14:07:02 +02002611 # Customize subcommands to not install an egg-info file for Python
2612 sub_commands = [('install_lib', install.has_lib),
2613 ('install_headers', install.has_headers),
2614 ('install_scripts', install.has_scripts),
2615 ('install_data', install.has_data)]
2616
2617
Michael W. Hudson529a5052002-12-17 16:47:17 +00002618class PyBuildInstallLib(install_lib):
2619 # Do exactly what install_lib does but make sure correct access modes get
2620 # set on installed directories and files. All installed files with get
2621 # mode 644 unless they are a shared library in which case they will get
2622 # mode 755. All installed directories will get mode 755.
2623
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002624 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2625 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002626
2627 def install(self):
2628 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002629 self.set_file_modes(outfiles, 0o644, 0o755)
2630 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002631 return outfiles
2632
2633 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002634 if not files: return
2635
2636 for filename in files:
2637 if os.path.islink(filename): continue
2638 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002639 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002640 log.info("changing mode of %s to %o", filename, mode)
2641 if not self.dry_run: os.chmod(filename, mode)
2642
2643 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002644 for dirpath, dirnames, fnames in os.walk(dirname):
2645 if os.path.islink(dirpath):
2646 continue
2647 log.info("changing mode of %s to %o", dirpath, mode)
2648 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002649
Victor Stinnerc991f242019-03-01 17:19:04 +01002650
Georg Brandlff52f762010-12-28 09:51:43 +00002651class PyBuildScripts(build_scripts):
2652 def copy_scripts(self):
2653 outfiles, updated_files = build_scripts.copy_scripts(self)
2654 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2655 minoronly = '.{0[1]}'.format(sys.version_info)
2656 newoutfiles = []
2657 newupdated_files = []
2658 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002659 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002660 newfilename = filename + fullversion
2661 else:
2662 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002663 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002664 os.rename(filename, newfilename)
2665 newoutfiles.append(newfilename)
2666 if filename in updated_files:
2667 newupdated_files.append(newfilename)
2668 return newoutfiles, newupdated_files
2669
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002670
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002671def main():
Victor Stinnercad80202021-01-19 23:04:49 +01002672 global LIST_MODULE_NAMES
2673
2674 if "--list-module-names" in sys.argv:
2675 LIST_MODULE_NAMES = True
2676 sys.argv.remove("--list-module-names")
2677
Victor Stinnerc991f242019-03-01 17:19:04 +01002678 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2679 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2680
2681 class DummyProcess:
2682 """Hack for parallel build"""
2683 ProcessPoolExecutor = None
2684
2685 sys.modules['concurrent.futures.process'] = DummyProcess
Paul Ganssle62972d92020-05-16 04:20:06 -04002686 validate_tzpath()
Victor Stinnerc991f242019-03-01 17:19:04 +01002687
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002688 # turn off warnings when deprecated modules are imported
2689 import warnings
2690 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002691 setup(# PyPI Metadata (PEP 301)
2692 name = "Python",
2693 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002694 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002695 maintainer = "Guido van Rossum and the Python community",
2696 maintainer_email = "python-dev@python.org",
2697 description = "A high-level object-oriented programming language",
2698 long_description = SUMMARY.strip(),
2699 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002700 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002701 platforms = ["Many"],
2702
2703 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002704 cmdclass = {'build_ext': PyBuildExt,
2705 'build_scripts': PyBuildScripts,
2706 'install': PyBuildInstall,
2707 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002708 # The struct module is defined here, because build_ext won't be
2709 # called unless there's at least one extension module defined.
Victor Stinnercdad2722021-04-22 00:52:52 +02002710 ext_modules=[Extension('_struct', ['_struct.c'],
2711 extra_compile_args=['-DPy_BUILD_CORE_MODULE'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002712
Georg Brandlff52f762010-12-28 09:51:43 +00002713 # If you change the scripts installed here, you also need to
2714 # check the PyBuildScripts command above, and change the links
2715 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002716 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002717 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002718 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002719
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002720# --install-platlib
2721if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002722 main()