blob: 605f7d628e73388d515732a72beed665ade35f02 [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
36 warnings.filterwarnings("ignore", "The distutils package is deprecated",
37 DeprecationWarning)
38
39 from distutils import log
40 from distutils.command.build_ext import build_ext
41 from distutils.command.build_scripts import build_scripts
42 from distutils.command.install import install
43 from distutils.command.install_lib import install_lib
44 from distutils.core import Extension, setup
45 from distutils.errors import CCompilerError, DistutilsError
46 from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000047
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020048
Victor Stinnercfe172d2019-03-01 18:21:49 +010049# Compile extensions used to test Python?
pxinwr277ce302020-12-30 20:50:39 +080050TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes')
Victor Stinnercfe172d2019-03-01 18:21:49 +010051
52# This global variable is used to hold the list of modules to be disabled.
53DISABLED_MODULE_LIST = []
54
Victor Stinnercad80202021-01-19 23:04:49 +010055# --list-module-names option used by Tools/scripts/generate_module_names.py
56LIST_MODULE_NAMES = False
57
Victor Stinnercfe172d2019-03-01 18:21:49 +010058
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020059def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010060 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020061 if "_PYTHON_HOST_PLATFORM" in os.environ:
62 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010063
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020064 # Get value of sys.platform
65 if sys.platform.startswith('osf1'):
66 return 'osf1'
67 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010068
69
70CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010071HOST_PLATFORM = get_platform()
72MS_WINDOWS = (HOST_PLATFORM == 'win32')
73CYGWIN = (HOST_PLATFORM == 'cygwin')
74MACOS = (HOST_PLATFORM == 'darwin')
Michael Felt08970cb2019-06-21 15:58:00 +020075AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 17:48:38 +010076VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080077
Victor Stinnerc991f242019-03-01 17:19:04 +010078
79SUMMARY = """
80Python is an interpreted, interactive, object-oriented programming
81language. It is often compared to Tcl, Perl, Scheme or Java.
82
83Python combines remarkable power with very clear syntax. It has
84modules, classes, exceptions, very high level dynamic data types, and
85dynamic typing. There are interfaces to many system calls and
86libraries, as well as to various windowing systems (X11, Motif, Tk,
87Mac, MFC). New built-in modules are easily written in C or C++. Python
88is also usable as an extension language for applications that need a
89programmable interface.
90
91The Python implementation is portable: it runs on many brands of UNIX,
92on Windows, DOS, Mac, Amiga... If your favorite system isn't
93listed here, it may still be supported, if there's a C compiler for
94it. Ask around on comp.lang.python -- or just try compiling Python
95yourself.
96"""
97
98CLASSIFIERS = """
99Development Status :: 6 - Mature
100License :: OSI Approved :: Python Software Foundation License
101Natural Language :: English
102Programming Language :: C
103Programming Language :: Python
104Topic :: Software Development
105"""
106
107
Victor Stinner6b982c22020-04-01 01:10:07 +0200108def run_command(cmd):
109 status = os.system(cmd)
Victor Stinner65a796e2020-04-01 18:49:29 +0200110 return os.waitstatus_to_exitcode(status)
Victor Stinner6b982c22020-04-01 01:10:07 +0200111
112
Victor Stinnerc991f242019-03-01 17:19:04 +0100113# Set common compiler and linker flags derived from the Makefile,
114# reserved for building the interpreter and the stdlib modules.
115# See bpo-21121 and bpo-35257
116def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
117 flags = sysconfig.get_config_var(compiler_flags)
118 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
119 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
120
121
Michael W. Hudson39230b32002-01-16 15:26:48 +0000122def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000123 """Add the directory 'dir' to the list 'dirlist' (after any relative
124 directories) if:
125
Michael W. Hudson39230b32002-01-16 15:26:48 +0000126 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000127 2) 'dir' actually exists, and is a directory.
128 """
129 if dir is None or not os.path.isdir(dir) or dir in dirlist:
130 return
131 for i, path in enumerate(dirlist):
132 if not os.path.isabs(path):
133 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000134 return
135 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000136
Victor Stinnerc991f242019-03-01 17:19:04 +0100137
xdegaye77f51392017-11-25 17:25:30 +0100138def sysroot_paths(make_vars, subdirs):
139 """Get the paths of sysroot sub-directories.
140
141 * make_vars: a sequence of names of variables of the Makefile where
142 sysroot may be set.
143 * subdirs: a sequence of names of subdirectories used as the location for
144 headers or libraries.
145 """
146
147 dirs = []
148 for var_name in make_vars:
149 var = sysconfig.get_config_var(var_name)
150 if var is not None:
151 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
152 if m is not None:
153 sysroot = m.group(1).strip('"')
154 for subdir in subdirs:
155 if os.path.isabs(subdir):
156 subdir = subdir[1:]
157 path = os.path.join(sysroot, subdir)
158 if os.path.isdir(path):
159 dirs.append(path)
160 break
161 return dirs
162
Ned Deily1731d6d2020-05-18 04:32:38 -0400163
Ned Deily0288dd62019-06-03 06:34:48 -0400164MACOS_SDK_ROOT = None
Ned Deily1731d6d2020-05-18 04:32:38 -0400165MACOS_SDK_SPECIFIED = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100166
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000167def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400168 """Return the directory of the current macOS SDK.
169
170 If no SDK was explicitly configured, call the compiler to find which
171 include files paths are being searched by default. Use '/' if the
172 compiler is searching /usr/include (meaning system header files are
173 installed) or use the root of an SDK if that is being searched.
174 (The SDK may be supplied via Xcode or via the Command Line Tools).
175 The SDK paths used by Apple-supplied tool chains depend on the
176 setting of various variables; see the xcrun man page for more info.
Ned Deily1731d6d2020-05-18 04:32:38 -0400177 Also sets MACOS_SDK_SPECIFIED for use by macosx_sdk_specified().
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000178 """
Ned Deily1731d6d2020-05-18 04:32:38 -0400179 global MACOS_SDK_ROOT, MACOS_SDK_SPECIFIED
Ned Deily0288dd62019-06-03 06:34:48 -0400180
181 # If already called, return cached result.
182 if MACOS_SDK_ROOT:
183 return MACOS_SDK_ROOT
184
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000185 cflags = sysconfig.get_config_var('CFLAGS')
Joshua Rootb3107002020-04-22 17:44:10 +1000186 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400187 if m is not None:
188 MACOS_SDK_ROOT = m.group(1)
Ned Deily29afab62020-12-04 23:02:09 -0500189 MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000190 else:
Ronald Oussoren404a7192020-11-22 06:14:25 +0100191 MACOS_SDK_ROOT = _osx_support._default_sysroot(
192 sysconfig.get_config_var('CC'))
Ned Deily29afab62020-12-04 23:02:09 -0500193 MACOS_SDK_SPECIFIED = False
Ned Deily0288dd62019-06-03 06:34:48 -0400194
195 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000196
Victor Stinnerc991f242019-03-01 17:19:04 +0100197
Ned Deily1731d6d2020-05-18 04:32:38 -0400198def macosx_sdk_specified():
199 """Returns true if an SDK was explicitly configured.
200
201 True if an SDK was selected at configure time, either by specifying
202 --enable-universalsdk=(something other than no or /) or by adding a
203 -isysroot option to CFLAGS. In some cases, like when making
204 decisions about macOS Tk framework paths, we need to be able to
205 know whether the user explicitly asked to build with an SDK versus
206 the implicit use of an SDK when header files are no longer
207 installed on a running system by the Command Line Tools.
208 """
209 global MACOS_SDK_SPECIFIED
210
211 # If already called, return cached result.
212 if MACOS_SDK_SPECIFIED:
213 return MACOS_SDK_SPECIFIED
214
215 # Find the sdk root and set MACOS_SDK_SPECIFIED
216 macosx_sdk_root()
217 return MACOS_SDK_SPECIFIED
218
219
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000220def is_macosx_sdk_path(path):
221 """
222 Returns True if 'path' can be located in an OSX SDK
223 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700224 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
225 or path.startswith('/System/')
226 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000227
Victor Stinnerc991f242019-03-01 17:19:04 +0100228
Ronald Oussoren41761932020-11-08 10:05:27 +0100229def grep_headers_for(function, headers):
230 for header in headers:
Ronald Oussoren7a27c7e2020-11-14 16:07:47 +0100231 with open(header, 'r', errors='surrogateescape') as f:
Ronald Oussoren41761932020-11-08 10:05:27 +0100232 if function in f.read():
233 return True
234 return False
235
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000236def find_file(filename, std_dirs, paths):
237 """Searches for the directory where a given file is located,
238 and returns a possibly-empty list of additional directories, or None
239 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000240
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000241 'filename' is the name of a file, such as readline.h or libcrypto.a.
242 'std_dirs' is the list of standard system directories; if the
243 file is found in one of them, no additional directives are needed.
244 'paths' is a list of additional locations to check; if the file is
245 found in one of them, the resulting list will contain the directory.
246 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100247 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000248 # Honor the MacOSX SDK setting when one was specified.
249 # An SDK is a directory with the same structure as a real
250 # system, but with only header files and libraries.
251 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000252
253 # Check the standard locations
254 for dir in std_dirs:
255 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000256
Victor Stinner4cbea512019-02-28 17:48:38 +0100257 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000258 f = os.path.join(sysroot, dir[1:], filename)
259
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000260 if os.path.exists(f): return []
261
262 # Check the additional directories
263 for dir in paths:
264 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000265
Victor Stinner4cbea512019-02-28 17:48:38 +0100266 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000267 f = os.path.join(sysroot, dir[1:], filename)
268
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000269 if os.path.exists(f):
270 return [dir]
271
272 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000273 return None
274
Victor Stinnerc991f242019-03-01 17:19:04 +0100275
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000276def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000277 result = compiler.find_library_file(std_dirs + paths, libname)
278 if result is None:
279 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000280
Victor Stinner4cbea512019-02-28 17:48:38 +0100281 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000282 sysroot = macosx_sdk_root()
283
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000284 # Check whether the found file is in one of the standard directories
285 dirname = os.path.dirname(result)
286 for p in std_dirs:
287 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000288 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000289
Victor Stinner4cbea512019-02-28 17:48:38 +0100290 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100291 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
292 # libraries with .tbd extensions rather than the normal .dylib
293 # shared libraries installed in /. The Apple compiler tool
294 # chain handles this transparently but it can cause problems
295 # for programs that are being built with an SDK and searching
296 # for specific libraries. Distutils find_library_file() now
297 # knows to also search for and return .tbd files. But callers
298 # of find_library_file need to keep in mind that the base filename
299 # of the returned SDK library file might have a different extension
300 # from that of the library file installed on the running system,
301 # for example:
302 # /Applications/Xcode.app/Contents/Developer/Platforms/
303 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
304 # usr/lib/libedit.tbd
305 # vs
306 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000307 if os.path.join(sysroot, p[1:]) == dirname:
308 return [ ]
309
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000310 if p == dirname:
311 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000312
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000313 # Otherwise, it must have been in one of the additional directories,
314 # so we have to figure out which one.
315 for p in paths:
316 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000317 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000318
Victor Stinner4cbea512019-02-28 17:48:38 +0100319 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000320 if os.path.join(sysroot, p[1:]) == dirname:
321 return [ p ]
322
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000323 if p == dirname:
324 return [p]
325 else:
326 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000327
Paul Ganssle62972d92020-05-16 04:20:06 -0400328def validate_tzpath():
329 base_tzpath = sysconfig.get_config_var('TZPATH')
330 if not base_tzpath:
331 return
332
333 tzpaths = base_tzpath.split(os.pathsep)
334 bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
335 if bad_paths:
336 raise ValueError('TZPATH must contain only absolute paths, '
337 + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
338 + f'{bad_paths!r}')
Victor Stinnerc991f242019-03-01 17:19:04 +0100339
Jack Jansen144ebcc2001-08-05 22:31:19 +0000340def find_module_file(module, dirlist):
341 """Find a module in a set of possible folders. If it is not found
342 return the unadorned filename"""
343 list = find_file(module, [], dirlist)
344 if not list:
345 return module
346 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100347 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000348 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000349
Victor Stinnerc991f242019-03-01 17:19:04 +0100350
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000351class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000352
Guido van Rossumd8faa362007-04-27 19:54:29 +0000353 def __init__(self, dist):
354 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100355 self.srcdir = None
356 self.lib_dirs = None
357 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100358 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000359 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400360 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100361 self.missing = []
Christian Heimes9b60e552020-05-15 23:54:53 +0200362 self.disabled_configure = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200363 if '-j' in os.environ.get('MAKEFLAGS', ''):
364 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000365
Victor Stinner8058bda2019-03-01 15:31:45 +0100366 def add(self, ext):
367 self.extensions.append(ext)
368
Victor Stinner00c77ae2020-03-04 18:44:49 +0100369 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100370 self.srcdir = sysconfig.get_config_var('srcdir')
371 if not self.srcdir:
372 # Maybe running on Windows but not using CYGWIN?
373 raise ValueError("No source directory; cannot proceed.")
374 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000375
Victor Stinner00c77ae2020-03-04 18:44:49 +0100376 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000377 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000378 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100379 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000380 # move ctypes to the end, it depends on other modules
381 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
382 if "_ctypes" in ext_map:
383 ctypes = extensions.pop(ext_map["_ctypes"])
384 extensions.append(ctypes)
385 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000386
Victor Stinner00c77ae2020-03-04 18:44:49 +0100387 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000388 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000389 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100390 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000391
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000392 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100393 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000394 for filename in self.distribution.scripts]
395
Christian Heimesaf98da12008-01-27 15:18:18 +0000396 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000397 headers = [sysconfig.get_config_h_filename()]
Serhiy Storchaka93558682020-06-20 11:10:31 +0300398 headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000399
Xavier de Gaye84968b72016-10-29 16:57:20 +0200400 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000401 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000402 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000403 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000404 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000405 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000406 else:
407 ext.depends = []
408 # re-compile extensions if a header file has been changed
409 ext.depends.extend(headers)
410
Victor Stinner00c77ae2020-03-04 18:44:49 +0100411 def remove_configured_extensions(self):
412 # The sysconfig variables built by makesetup that list the already
413 # built modules and the disabled modules as configured by the Setup
414 # files.
415 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
416 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
417
418 mods_built = []
419 mods_disabled = []
420 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200421 # If a module has already been built or has been disabled in the
422 # Setup files, don't build it here.
423 if ext.name in sysconf_built:
424 mods_built.append(ext)
425 if ext.name in sysconf_dis:
426 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000427
xdegayec0364fc2017-05-27 18:25:03 +0200428 mods_configured = mods_built + mods_disabled
429 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200430 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200431 mods_configured]
432 # Remove the shared libraries built by a previous build.
433 for ext in mods_configured:
434 fullpath = self.get_ext_fullpath(ext.name)
435 if os.path.exists(fullpath):
436 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000437
Victor Stinner00c77ae2020-03-04 18:44:49 +0100438 return (mods_built, mods_disabled)
439
440 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000441 # When you run "make CC=altcc" or something similar, you really want
442 # those environment variables passed into the setup.py phase. Here's
443 # a small set of useful ones.
444 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000445 args = {}
446 # unfortunately, distutils doesn't let us provide separate C and C++
447 # compilers
448 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000449 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
450 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000451 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000452
Victor Stinner00c77ae2020-03-04 18:44:49 +0100453 def build_extensions(self):
454 self.set_srcdir()
455
456 # Detect which modules should be compiled
457 self.detect_modules()
458
Victor Stinnercad80202021-01-19 23:04:49 +0100459 if not LIST_MODULE_NAMES:
460 self.remove_disabled()
Victor Stinner00c77ae2020-03-04 18:44:49 +0100461
462 self.update_sources_depends()
463 mods_built, mods_disabled = self.remove_configured_extensions()
464 self.set_compiler_executables()
465
Victor Stinnercad80202021-01-19 23:04:49 +0100466 if LIST_MODULE_NAMES:
467 for ext in self.extensions:
468 print(ext.name)
469 for name in self.missing:
470 print(name)
471 return
472
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000473 build_ext.build_extensions(self)
474
Victor Stinner1ec63b62020-03-04 14:50:19 +0100475 if SUBPROCESS_BOOTSTRAP:
476 # Drop our custom subprocess module:
477 # use the newly built subprocess module
478 del sys.modules['subprocess']
479
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200480 for ext in self.extensions:
481 self.check_extension_import(ext)
482
Victor Stinner00c77ae2020-03-04 18:44:49 +0100483 self.summary(mods_built, mods_disabled)
484
485 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300486 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400487 if self.failed or self.failed_on_import:
488 all_failed = self.failed + self.failed_on_import
489 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000490
491 def print_three_column(lst):
492 lst.sort(key=str.lower)
493 # guarantee zip() doesn't drop anything
494 while len(lst) % 3:
495 lst.append("")
496 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
497 print("%-*s %-*s %-*s" % (longest, e, longest, f,
498 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000499
Victor Stinner8058bda2019-03-01 15:31:45 +0100500 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000501 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400502 print("Python build finished successfully!")
503 print("The necessary bits to build these optional modules were not "
504 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100505 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000506 print("To find the necessary bits, look in setup.py in"
507 " detect_modules() for the module's name.")
508 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000509
xdegayec0364fc2017-05-27 18:25:03 +0200510 if mods_built:
511 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200512 print("The following modules found by detect_modules() in"
513 " setup.py, have been")
514 print("built by the Makefile instead, as configured by the"
515 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200516 print_three_column([ext.name for ext in mods_built])
517 print()
518
519 if mods_disabled:
520 print()
521 print("The following modules found by detect_modules() in"
522 " setup.py have not")
523 print("been built, they are *disabled* in the Setup files:")
524 print_three_column([ext.name for ext in mods_disabled])
525 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200526
Christian Heimes9b60e552020-05-15 23:54:53 +0200527 if self.disabled_configure:
528 print()
529 print("The following modules found by detect_modules() in"
530 " setup.py have not")
531 print("been built, they are *disabled* by configure:")
532 print_three_column(self.disabled_configure)
533 print()
534
Guido van Rossumd8faa362007-04-27 19:54:29 +0000535 if self.failed:
536 failed = self.failed[:]
537 print()
538 print("Failed to build these modules:")
539 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000540 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000541
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400542 if self.failed_on_import:
543 failed = self.failed_on_import[:]
544 print()
545 print("Following modules built successfully"
546 " but were removed because they could not be imported:")
547 print_three_column(failed)
548 print()
549
Christian Heimes61d478c2018-01-27 15:51:38 +0100550 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100551 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100552 print()
553 print("Could not build the ssl module!")
Christian Heimes39258d32021-04-17 11:36:35 +0200554 print("Python requires a OpenSSL 1.1.1 or newer")
Christian Heimes32eba612021-03-19 10:29:25 +0100555 if sysconfig.get_config_var("OPENSSL_LDFLAGS"):
556 print("Custom linker flags may require --with-openssl-rpath=auto")
Christian Heimes61d478c2018-01-27 15:51:38 +0100557 print()
558
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000559 def build_extension(self, ext):
560
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000561 if ext.name == '_ctypes':
562 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500563 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000564 return
565
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000566 try:
567 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000568 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000569 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100570 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000571 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000572 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200573
574 def check_extension_import(self, ext):
575 # Don't try to import an extension that has failed to compile
576 if ext.name in self.failed:
577 self.announce(
578 'WARNING: skipping import check for failed build "%s"' %
579 ext.name, level=1)
580 return
581
Jack Jansenf49c6f92001-11-01 14:44:15 +0000582 # Workaround for Mac OS X: The Carbon-based modules cannot be
583 # reliably imported into a command-line Python
584 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000585 self.announce(
586 'WARNING: skipping import check for Carbon-based "%s"' %
587 ext.name)
588 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000589
Victor Stinner4cbea512019-02-28 17:48:38 +0100590 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000591 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000592 # Don't bother doing an import check when an extension was
593 # build with an explicit '-arch' flag on OSX. That's currently
594 # only used to build 32-bit only extensions in a 4-way
595 # universal build and loading 32-bit code into a 64-bit
596 # process will fail.
597 self.announce(
598 'WARNING: skipping import check for "%s"' %
599 ext.name)
600 return
601
Jason Tishler24cf7762002-05-22 16:46:15 +0000602 # Workaround for Cygwin: Cygwin currently has fork issues when many
603 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100604 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000605 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
606 % ext.name)
607 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000608 ext_filename = os.path.join(
609 self.build_lib,
610 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000611
612 # If the build directory didn't exist when setup.py was
613 # started, sys.path_importer_cache has a negative result
614 # cached. Clear that cache before trying to import.
615 sys.path_importer_cache.clear()
616
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200617 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100618 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200619 return
620
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400621 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700622 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
623 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000624 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400625 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000626 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400627 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000628 self.announce('*** WARNING: renaming "%s" since importing it'
629 ' failed: %s' % (ext.name, why), level=3)
630 assert not self.inplace
631 basename, tail = os.path.splitext(ext_filename)
632 newname = basename + "_failed" + tail
633 if os.path.exists(newname):
634 os.remove(newname)
635 os.rename(ext_filename, newname)
636
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000637 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000638 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000639 self.announce('*** WARNING: importing extension "%s" '
640 'failed with %s: %s' % (ext.name, exc_type, why),
641 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000642 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000643
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400644 def add_multiarch_paths(self):
645 # Debian/Ubuntu multiarch support.
646 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200647 cc = sysconfig.get_config_var('CC')
648 tmpfile = os.path.join(self.build_temp, 'multiarch')
649 if not os.path.exists(self.build_temp):
650 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200651 ret = run_command(
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200652 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
653 multiarch_path_component = ''
654 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200655 if ret == 0:
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200656 with open(tmpfile) as fp:
657 multiarch_path_component = fp.readline().strip()
658 finally:
659 os.unlink(tmpfile)
660
661 if multiarch_path_component != '':
662 add_dir_to_list(self.compiler.library_dirs,
663 '/usr/lib/' + multiarch_path_component)
664 add_dir_to_list(self.compiler.include_dirs,
665 '/usr/include/' + multiarch_path_component)
666 return
667
Barry Warsaw88e19452011-04-07 10:40:36 -0400668 if not find_executable('dpkg-architecture'):
669 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200670 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100671 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200672 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400673 tmpfile = os.path.join(self.build_temp, 'multiarch')
674 if not os.path.exists(self.build_temp):
675 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200676 ret = run_command(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200677 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
678 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400679 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200680 if ret == 0:
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400681 with open(tmpfile) as fp:
682 multiarch_path_component = fp.readline().strip()
683 add_dir_to_list(self.compiler.library_dirs,
684 '/usr/lib/' + multiarch_path_component)
685 add_dir_to_list(self.compiler.include_dirs,
686 '/usr/include/' + multiarch_path_component)
687 finally:
688 os.unlink(tmpfile)
689
pxinwr5e45f1c2021-01-22 08:55:52 +0800690 def add_wrcc_search_dirs(self):
691 # add library search path by wr-cc, the compiler wrapper
692
693 def convert_mixed_path(path):
694 # convert path like C:\folder1\folder2/folder3/folder4
695 # to msys style /c/folder1/folder2/folder3/folder4
696 drive = path[0].lower()
697 left = path[2:].replace("\\", "/")
698 return "/" + drive + left
699
700 def add_search_path(line):
701 # On Windows building machine, VxWorks does
702 # cross builds under msys2 environment.
703 pathsep = (";" if sys.platform == "msys" else ":")
704 for d in line.strip().split("=")[1].split(pathsep):
705 d = d.strip()
706 if sys.platform == "msys":
707 # On Windows building machine, compiler
708 # returns mixed style path like:
709 # C:\folder1\folder2/folder3/folder4
710 d = convert_mixed_path(d)
711 d = os.path.normpath(d)
712 add_dir_to_list(self.compiler.library_dirs, d)
713
714 cc = sysconfig.get_config_var('CC')
715 tmpfile = os.path.join(self.build_temp, 'wrccpaths')
716 os.makedirs(self.build_temp, exist_ok=True)
717 try:
718 ret = run_command('%s --print-search-dirs >%s' % (cc, tmpfile))
719 if ret:
720 return
721 with open(tmpfile) as fp:
722 # Parse paths in libraries line. The line is like:
723 # On Linux, "libraries: = path1:path2:path3"
724 # On Windows, "libraries: = path1;path2;path3"
725 for line in fp:
726 if not line.startswith("libraries"):
727 continue
728 add_search_path(line)
729 finally:
730 try:
731 os.unlink(tmpfile)
732 except OSError:
733 pass
734
pxinwr32f5fdd2019-02-27 19:09:28 +0800735 def add_cross_compiling_paths(self):
736 cc = sysconfig.get_config_var('CC')
737 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200738 if not os.path.exists(self.build_temp):
739 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200740 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200741 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800742 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200743 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200744 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200745 if ret == 0:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200746 with open(tmpfile) as fp:
747 for line in fp.readlines():
748 if line.startswith("gcc version"):
749 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800750 elif line.startswith("clang version"):
751 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200752 elif line.startswith("#include <...>"):
753 in_incdirs = True
754 elif line.startswith("End of search list"):
755 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800756 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200757 for d in line.strip().split("=")[1].split(":"):
758 d = os.path.normpath(d)
759 if '/gcc/' not in d:
760 add_dir_to_list(self.compiler.library_dirs,
761 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800762 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 +0200763 add_dir_to_list(self.compiler.include_dirs,
764 line.strip())
765 finally:
766 os.unlink(tmpfile)
767
pxinwr5e45f1c2021-01-22 08:55:52 +0800768 if VXWORKS:
769 self.add_wrcc_search_dirs()
770
Victor Stinnercfe172d2019-03-01 18:21:49 +0100771 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000772 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000773 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000774 # We must get the values from the Makefile and not the environment
775 # directly since an inconsistently reproducible issue comes up where
776 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000777 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000778 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000779 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
780 ('LDFLAGS', '-L', self.compiler.library_dirs),
781 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000782 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000783 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800784 parser = argparse.ArgumentParser()
785 parser.add_argument(arg_name, dest="dirs", action="append")
786 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000787 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000788 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000789 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000790
Victor Stinnercfe172d2019-03-01 18:21:49 +0100791 def configure_compiler(self):
792 # Ensure that /usr/local is always used, but the local build
793 # directories (i.e. '.' and 'Include') must be first. See issue
794 # 10520.
795 if not CROSS_COMPILING:
796 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
797 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
798 # only change this for cross builds for 3.3, issues on Mageia
799 if CROSS_COMPILING:
800 self.add_cross_compiling_paths()
801 self.add_multiarch_paths()
802 self.add_ldflags_cppflags()
803
Victor Stinner5ec33a12019-03-01 16:43:28 +0100804 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100805 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100806 os.path.normpath(sys.base_prefix) != '/usr' and
807 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000808 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
809 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
810 # building a framework with different architectures than
811 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000812 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000813 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000814 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000815 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000816
xdegaye77f51392017-11-25 17:25:30 +0100817 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
818 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000819 # lib_dirs and inc_dirs are used to search for files;
820 # if a file is found in one of those directories, it can
821 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100822 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100823 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
824 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100825 else:
xdegaye77f51392017-11-25 17:25:30 +0100826 # Add the sysroot paths. 'sysroot' is a compiler option used to
827 # set the logical path of the standard system headers and
828 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100829 self.lib_dirs = (self.compiler.library_dirs +
830 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
831 self.inc_dirs = (self.compiler.include_dirs +
832 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
833 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000834
Brett Cannon4454a1f2005-04-15 20:32:39 +0000835 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000836 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100837 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000838
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000839 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100840 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100841 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000842
Charles-François Natali5739e102012-04-12 19:07:25 +0200843 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100844 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100845 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200846
Victor Stinner4cbea512019-02-28 17:48:38 +0100847 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000848 # This should work on any unixy platform ;-)
849 # If the user has bothered specifying additional -I and -L flags
850 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000851 #
852 # NOTE: using shlex.split would technically be more correct, but
853 # also gives a bootstrap problem. Let's hope nobody uses
854 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000855 cflags, ldflags = sysconfig.get_config_vars(
856 'CFLAGS', 'LDFLAGS')
857 for item in cflags.split():
858 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100859 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000860
861 for item in ldflags.split():
862 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100863 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000864
Victor Stinner5ec33a12019-03-01 16:43:28 +0100865 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000866 #
867 # The following modules are all pretty straightforward, and compile
868 # on pretty much any POSIXish platform.
869 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000870
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000871 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100872 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000873
Yury Selivanovf23746a2018-01-22 19:11:18 -0500874 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100875 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500876
Martin Panterc9deece2016-02-03 05:19:44 +0000877 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100878
879 # math library functions, e.g. sin()
880 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100881 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100882 extra_objects=[shared_math],
883 depends=['_math.h', shared_math],
884 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100885
886 # complex math library functions
887 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100888 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100889 extra_objects=[shared_math],
890 depends=['_math.h', shared_math],
891 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200892
893 # time libraries: librt may be needed for clock_gettime()
894 time_libs = []
895 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
896 if lib:
897 time_libs.append(lib)
898
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000899 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100900 self.add(Extension('time', ['timemodule.c'],
901 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800902 # libm is needed by delta_new() that uses round() and by accum() that
903 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100904 self.add(Extension('_datetime', ['_datetimemodule.c'],
Victor Stinner04fc4f22020-06-16 01:28:07 +0200905 libraries=['m'],
906 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Paul Ganssle62972d92020-05-16 04:20:06 -0400907 # zoneinfo module
Victor Stinner37834132020-10-27 17:12:53 +0100908 self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
909 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000910 # random number generator implemented in C
Victor Stinner9f5fe792020-04-17 19:05:35 +0200911 self.add(Extension("_random", ["_randommodule.c"],
912 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000913 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100914 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000915 # heapq
Victor Stinnerc45dbe932020-06-22 17:39:32 +0200916 self.add(Extension("_heapq", ["_heapqmodule.c"],
917 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000918 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200919 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200920 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimes90540002008-05-08 14:29:10 +0000921 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100922 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200923 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100924
Fred Drake0e474a82007-10-11 18:01:43 +0000925 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100926 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000927 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100928 self.add(Extension('unicodedata', ['unicodedata.c'],
Victor Stinner47e1afd2020-10-26 16:43:47 +0100929 depends=['unicodedata_db.h', 'unicodename_db.h'],
930 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Larry Hastings3a907972013-11-23 14:49:22 -0800931 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100932 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900933 # asyncio speedups
Chris Jerdonekda742ba2020-05-17 22:47:31 -0700934 self.add(Extension("_asyncio", ["_asynciomodule.c"],
935 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000936 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100937 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100938 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100939 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900940 # _statistics module
941 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000942
943 # Modules with some UNIX dependencies -- on by default:
944 # (If you have a really backward UNIX, select and socket may not be
945 # supported...)
946
947 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000948 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100949 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000950 # May be necessary on AIX for flock function
951 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100952 self.add(Extension('fcntl', ['fcntlmodule.c'],
953 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000954 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100955 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000956 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800957 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100958 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000959 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100960 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
961 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100962 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200963 # AIX has shadow passwords, but access is not via getspent(), etc.
964 # module support is not expected so it not 'missing'
965 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100966 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000967
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000968 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100969 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000970
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000971 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100972 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000973
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000974 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000975 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100976 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000977
Eric Snow7f8bfc92018-01-29 18:23:44 -0700978 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600979 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700980
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000981 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000982 # Here ends the simple stuff. From here on, modules need certain
983 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000984 #
985
986 # Multimedia modules
987 # These don't work for 64-bit platforms!!!
988 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200989 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000990 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000991 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000992 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200993 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800994 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100995 self.add(Extension('audioop', ['audioop.c'],
996 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000997
Victor Stinner5ec33a12019-03-01 16:43:28 +0100998 # CSV files
999 self.add(Extension('_csv', ['_csv.c']))
1000
1001 # POSIX subprocess module helper.
Kyle Evans79925792020-10-13 15:04:44 -05001002 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
1003 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner5ec33a12019-03-01 16:43:28 +01001004
Victor Stinnercfe172d2019-03-01 18:21:49 +01001005 def detect_test_extensions(self):
1006 # Python C API test module
1007 self.add(Extension('_testcapi', ['_testcapimodule.c'],
1008 depends=['testcapi_long.h']))
1009
Victor Stinner23bace22019-04-18 11:37:26 +02001010 # Python Internal C API test module
1011 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +02001012 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +02001013
Victor Stinnercfe172d2019-03-01 18:21:49 +01001014 # Python PEP-3118 (buffer protocol) test module
1015 self.add(Extension('_testbuffer', ['_testbuffer.c']))
1016
1017 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
1018 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
1019
1020 # Test multi-phase extension module init (PEP 489)
1021 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
1022
1023 # Fuzz tests.
1024 self.add(Extension('_xxtestfuzz',
1025 ['_xxtestfuzz/_xxtestfuzz.c',
1026 '_xxtestfuzz/fuzzer.c']))
1027
Victor Stinner5ec33a12019-03-01 16:43:28 +01001028 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001029 # readline
Stefan Krah095b2732010-06-08 13:41:44 +00001030 readline_termcap_library = ""
1031 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +02001032 # Cannot use os.popen here in py3k.
1033 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
1034 if not os.path.exists(self.build_temp):
1035 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +00001036 # Determine if readline is already linked against curses or tinfo.
Roland Hiebere1f77692021-02-09 02:05:25 +01001037 if sysconfig.get_config_var('HAVE_LIBREADLINE'):
1038 if sysconfig.get_config_var('WITH_EDITLINE'):
1039 readline_lib = 'edit'
1040 else:
1041 readline_lib = 'readline'
1042 do_readline = self.compiler.find_library_file(self.lib_dirs,
1043 readline_lib)
Victor Stinner4cbea512019-02-28 17:48:38 +01001044 if CROSS_COMPILING:
Victor Stinner6b982c22020-04-01 01:10:07 +02001045 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
doko@ubuntu.com58844492012-06-30 18:25:32 +02001046 % (sysconfig.get_config_var('READELF'),
1047 do_readline, tmpfile))
1048 elif find_executable('ldd'):
Victor Stinner6b982c22020-04-01 01:10:07 +02001049 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
doko@ubuntu.com58844492012-06-30 18:25:32 +02001050 else:
Victor Stinner6b982c22020-04-01 01:10:07 +02001051 ret = 1
1052 if ret == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +00001053 with open(tmpfile) as fp:
1054 for ln in fp:
1055 if 'curses' in ln:
1056 readline_termcap_library = re.sub(
1057 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
1058 ).rstrip()
1059 break
1060 # termcap interface split out from ncurses
1061 if 'tinfo' in ln:
1062 readline_termcap_library = 'tinfo'
1063 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +02001064 if os.path.exists(tmpfile):
1065 os.unlink(tmpfile)
Roland Hiebere1f77692021-02-09 02:05:25 +01001066 else:
1067 do_readline = False
Stefan Krah095b2732010-06-08 13:41:44 +00001068 # Issue 7384: If readline is already linked against curses,
1069 # use the same library for the readline and curses modules.
1070 if 'curses' in readline_termcap_library:
1071 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +01001072 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +00001073 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +02001074 # Issue 36210: OSS provided ncurses does not link on AIX
1075 # Use IBM supplied 'curses' for successful build of _curses
1076 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
1077 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001078 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001079 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001080 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001081 curses_library = 'curses'
1082
Victor Stinner4cbea512019-02-28 17:48:38 +01001083 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001084 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +00001085 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -07001086 if (dep_target and
Ronald Oussoren49926cf2021-02-01 04:29:44 +01001087 (tuple(int(n) for n in dep_target.split('.')[0:2])
Ned Deily04cdfa12014-06-25 13:36:14 -07001088 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +00001089 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001090 if os_release < 9:
1091 # MacOSX 10.4 has a broken readline. Don't try to build
1092 # the readline module unless the user has installed a fixed
1093 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +01001094 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001095 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +00001096 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +01001097 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001098 # In every directory on the search path search for a dynamic
1099 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +00001100 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +00001101 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001102 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +00001103 readline_extra_link_args = ('-Wl,-search_paths_first',)
1104 else:
1105 readline_extra_link_args = ()
1106
Roland Hiebere1f77692021-02-09 02:05:25 +01001107 readline_libs = [readline_lib]
Stefan Krah095b2732010-06-08 13:41:44 +00001108 if readline_termcap_library:
1109 pass # Issue 7384: Already linked against curses or tinfo.
1110 elif curses_library:
1111 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001112 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001113 ['/usr/lib/termcap'],
1114 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001115 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001116 self.add(Extension('readline', ['readline.c'],
1117 library_dirs=['/usr/lib/termcap'],
1118 extra_link_args=readline_extra_link_args,
1119 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001120 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001121 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001122
Victor Stinner5ec33a12019-03-01 16:43:28 +01001123 # Curses support, requiring the System V version of curses, often
1124 # provided by the ncurses library.
1125 curses_defines = []
1126 curses_includes = []
1127 panel_library = 'panel'
1128 if curses_library == 'ncursesw':
1129 curses_defines.append(('HAVE_NCURSESW', '1'))
1130 if not CROSS_COMPILING:
1131 curses_includes.append('/usr/include/ncursesw')
1132 # Bug 1464056: If _curses.so links with ncursesw,
1133 # _curses_panel.so must link with panelw.
1134 panel_library = 'panelw'
1135 if MACOS:
1136 # On OS X, there is no separate /usr/lib/libncursesw nor
1137 # libpanelw. If we are here, we found a locally-supplied
1138 # version of libncursesw. There should also be a
1139 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1140 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1141 # ncurses wide char support
1142 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1143 elif MACOS and curses_library == 'ncurses':
1144 # Building with the system-suppied combined libncurses/libpanel
1145 curses_defines.append(('HAVE_NCURSESW', '1'))
1146 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001147
Victor Stinnercfe172d2019-03-01 18:21:49 +01001148 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001149 if curses_library.startswith('ncurses'):
1150 curses_libs = [curses_library]
1151 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001152 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001153 include_dirs=curses_includes,
1154 define_macros=curses_defines,
1155 libraries=curses_libs))
1156 elif curses_library == 'curses' and not MACOS:
1157 # OSX has an old Berkeley curses, not good enough for
1158 # the _curses module.
1159 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1160 curses_libs = ['curses', 'terminfo']
1161 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1162 curses_libs = ['curses', 'termcap']
1163 else:
1164 curses_libs = ['curses']
1165
1166 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001167 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001168 define_macros=curses_defines,
1169 libraries=curses_libs))
1170 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001171 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001172 self.missing.append('_curses')
1173
1174 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001175 # _curses_panel needs some form of ncurses
1176 skip_curses_panel = True if AIX else False
1177 if (curses_enabled and not skip_curses_panel and
1178 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001179 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001180 include_dirs=curses_includes,
1181 define_macros=curses_defines,
1182 libraries=[panel_library, *curses_libs]))
1183 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001184 self.missing.append('_curses_panel')
1185
1186 def detect_crypt(self):
1187 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001188 if VXWORKS:
1189 # bpo-31904: crypt() function is not provided by VxWorks.
1190 # DES_crypt() OpenSSL provides is too weak to implement
1191 # the encryption.
Victor Stinnercad80202021-01-19 23:04:49 +01001192 self.missing.append('_crypt')
pxinwr236d0b72019-04-15 17:02:20 +08001193 return
1194
Victor Stinner625dbf22019-03-01 15:59:39 +01001195 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001196 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001197 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001198 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001199
Victor Stinnercad80202021-01-19 23:04:49 +01001200 self.add(Extension('_crypt', ['_cryptmodule.c'], libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001201
Victor Stinner5ec33a12019-03-01 16:43:28 +01001202 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001203 # socket(2)
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001204 kwargs = {'depends': ['socketmodule.h']}
pxinwr00a65682020-11-29 06:14:16 +08001205 if MACOS:
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001206 # Issue #35569: Expose RFC 3542 socket options.
1207 kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542']
Erlend Egeberg Aasland9a45bfe2020-05-17 08:32:46 +02001208
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001209 self.add(Extension('_socket', ['socketmodule.c'], **kwargs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001210
Victor Stinner5ec33a12019-03-01 16:43:28 +01001211 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001212 # Modules that provide persistent dictionary-like semantics. You will
1213 # probably want to arrange for at least one of them to be available on
1214 # your machine, though none are defined by default because of library
1215 # dependencies. The Python module dbm/__init__.py provides an
1216 # implementation independent wrapper for these; dbm/dumb.py provides
1217 # similar functionality (but slower of course) implemented in Python.
1218
1219 # Sleepycat^WOracle Berkeley DB interface.
1220 # http://www.oracle.com/database/berkeley-db/db/index.html
1221 #
1222 # This requires the Sleepycat^WOracle DB code. The supported versions
1223 # are set below. Visit the URL above to download
1224 # a release. Most open source OSes come with one or more
1225 # versions of BerkeleyDB already installed.
1226
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001227 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001228 min_db_ver = (3, 3)
1229 db_setup_debug = False # verbose debug prints from this script?
1230
1231 def allow_db_ver(db_ver):
1232 """Returns a boolean if the given BerkeleyDB version is acceptable.
1233
1234 Args:
1235 db_ver: A tuple of the version to verify.
1236 """
1237 if not (min_db_ver <= db_ver <= max_db_ver):
1238 return False
1239 return True
1240
1241 def gen_db_minor_ver_nums(major):
1242 if major == 4:
1243 for x in range(max_db_ver[1]+1):
1244 if allow_db_ver((4, x)):
1245 yield x
1246 elif major == 3:
1247 for x in (3,):
1248 if allow_db_ver((3, x)):
1249 yield x
1250 else:
1251 raise ValueError("unknown major BerkeleyDB version", major)
1252
1253 # construct a list of paths to look for the header file in on
1254 # top of the normal inc_dirs.
1255 db_inc_paths = [
1256 '/usr/include/db4',
1257 '/usr/local/include/db4',
1258 '/opt/sfw/include/db4',
1259 '/usr/include/db3',
1260 '/usr/local/include/db3',
1261 '/opt/sfw/include/db3',
1262 # Fink defaults (http://fink.sourceforge.net/)
1263 '/sw/include/db4',
1264 '/sw/include/db3',
1265 ]
1266 # 4.x minor number specific paths
1267 for x in gen_db_minor_ver_nums(4):
1268 db_inc_paths.append('/usr/include/db4%d' % x)
1269 db_inc_paths.append('/usr/include/db4.%d' % x)
1270 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1271 db_inc_paths.append('/usr/local/include/db4%d' % x)
1272 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1273 db_inc_paths.append('/opt/db-4.%d/include' % x)
1274 # MacPorts default (http://www.macports.org/)
1275 db_inc_paths.append('/opt/local/include/db4%d' % x)
1276 # 3.x minor number specific paths
1277 for x in gen_db_minor_ver_nums(3):
1278 db_inc_paths.append('/usr/include/db3%d' % x)
1279 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1280 db_inc_paths.append('/usr/local/include/db3%d' % x)
1281 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1282 db_inc_paths.append('/opt/db-3.%d/include' % x)
1283
Victor Stinner4cbea512019-02-28 17:48:38 +01001284 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001285 db_inc_paths = []
1286
Georg Brandl489cb4f2009-07-11 10:08:49 +00001287 # Add some common subdirectories for Sleepycat DB to the list,
1288 # based on the standard include directories. This way DB3/4 gets
1289 # picked up when it is installed in a non-standard prefix and
1290 # the user has added that prefix into inc_dirs.
1291 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001292 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001293 std_variants.append(os.path.join(dn, 'db3'))
1294 std_variants.append(os.path.join(dn, 'db4'))
1295 for x in gen_db_minor_ver_nums(4):
1296 std_variants.append(os.path.join(dn, "db4%d"%x))
1297 std_variants.append(os.path.join(dn, "db4.%d"%x))
1298 for x in gen_db_minor_ver_nums(3):
1299 std_variants.append(os.path.join(dn, "db3%d"%x))
1300 std_variants.append(os.path.join(dn, "db3.%d"%x))
1301
1302 db_inc_paths = std_variants + db_inc_paths
1303 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1304
1305 db_ver_inc_map = {}
1306
Victor Stinner4cbea512019-02-28 17:48:38 +01001307 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001308 sysroot = macosx_sdk_root()
1309
Georg Brandl489cb4f2009-07-11 10:08:49 +00001310 class db_found(Exception): pass
1311 try:
1312 # See whether there is a Sleepycat header in the standard
1313 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001314 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001315 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001316 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001317 f = os.path.join(sysroot, d[1:], "db.h")
1318
Georg Brandl489cb4f2009-07-11 10:08:49 +00001319 if db_setup_debug: print("db: looking for db.h in", f)
1320 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001321 with open(f, 'rb') as file:
1322 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001323 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001324 if m:
1325 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001326 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001327 db_minor = int(m.group(1))
1328 db_ver = (db_major, db_minor)
1329
1330 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1331 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001332 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001333 db_patch = int(m.group(1))
1334 if db_patch < 21:
1335 print("db.h:", db_ver, "patch", db_patch,
1336 "being ignored (4.6.x must be >= 4.6.21)")
1337 continue
1338
1339 if ( (db_ver not in db_ver_inc_map) and
1340 allow_db_ver(db_ver) ):
1341 # save the include directory with the db.h version
1342 # (first occurrence only)
1343 db_ver_inc_map[db_ver] = d
1344 if db_setup_debug:
1345 print("db.h: found", db_ver, "in", d)
1346 else:
1347 # we already found a header for this library version
1348 if db_setup_debug: print("db.h: ignoring", d)
1349 else:
1350 # ignore this header, it didn't contain a version number
1351 if db_setup_debug:
1352 print("db.h: no version number version in", d)
1353
1354 db_found_vers = list(db_ver_inc_map.keys())
1355 db_found_vers.sort()
1356
1357 while db_found_vers:
1358 db_ver = db_found_vers.pop()
1359 db_incdir = db_ver_inc_map[db_ver]
1360
1361 # check lib directories parallel to the location of the header
1362 db_dirs_to_check = [
1363 db_incdir.replace("include", 'lib64'),
1364 db_incdir.replace("include", 'lib'),
1365 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001366
Victor Stinner4cbea512019-02-28 17:48:38 +01001367 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001368 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1369
1370 else:
1371 # Same as other branch, but takes OSX SDK into account
1372 tmp = []
1373 for dn in db_dirs_to_check:
1374 if is_macosx_sdk_path(dn):
1375 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1376 tmp.append(dn)
1377 else:
1378 if os.path.isdir(dn):
1379 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001380 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001381
1382 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001383
Ezio Melotti42da6632011-03-15 05:18:48 +02001384 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001385 # XXX should we -ever- look for a dbX name? Do any
1386 # systems really not name their library by version and
1387 # symlink to more general names?
1388 for dblib in (('db-%d.%d' % db_ver),
1389 ('db%d%d' % db_ver),
1390 ('db%d' % db_ver[0])):
1391 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001392 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001393 if dblib_file:
1394 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1395 raise db_found
1396 else:
1397 if db_setup_debug: print("db lib: ", dblib, "not found")
1398
1399 except db_found:
1400 if db_setup_debug:
1401 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1402 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001403 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001404 # Only add the found library and include directories if they aren't
1405 # already being searched. This avoids an explicit runtime library
1406 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001407 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001408 db_incs = None
1409 else:
1410 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001411 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001412 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001413 else:
1414 if db_setup_debug: print("db: no appropriate library found")
1415 db_incs = None
1416 dblibs = []
1417 dblib_dir = None
1418
Victor Stinner5ec33a12019-03-01 16:43:28 +01001419 dbm_setup_debug = False # verbose debug prints from this script?
1420 dbm_order = ['gdbm']
1421 # The standard Unix dbm module:
1422 if not CYGWIN:
1423 config_args = [arg.strip("'")
1424 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1425 dbm_args = [arg for arg in config_args
1426 if arg.startswith('--with-dbmliborder=')]
1427 if dbm_args:
1428 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1429 else:
1430 dbm_order = "ndbm:gdbm:bdb".split(":")
1431 dbmext = None
1432 for cand in dbm_order:
1433 if cand == "ndbm":
1434 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1435 # Some systems have -lndbm, others have -lgdbm_compat,
1436 # others don't have either
1437 if self.compiler.find_library_file(self.lib_dirs,
1438 'ndbm'):
1439 ndbm_libs = ['ndbm']
1440 elif self.compiler.find_library_file(self.lib_dirs,
1441 'gdbm_compat'):
1442 ndbm_libs = ['gdbm_compat']
1443 else:
1444 ndbm_libs = []
1445 if dbm_setup_debug: print("building dbm using ndbm")
1446 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1447 define_macros=[
1448 ('HAVE_NDBM_H',None),
1449 ],
1450 libraries=ndbm_libs)
1451 break
1452
1453 elif cand == "gdbm":
1454 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1455 gdbm_libs = ['gdbm']
1456 if self.compiler.find_library_file(self.lib_dirs,
1457 'gdbm_compat'):
1458 gdbm_libs.append('gdbm_compat')
1459 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1460 if dbm_setup_debug: print("building dbm using gdbm")
1461 dbmext = Extension(
1462 '_dbm', ['_dbmmodule.c'],
1463 define_macros=[
1464 ('HAVE_GDBM_NDBM_H', None),
1465 ],
1466 libraries = gdbm_libs)
1467 break
1468 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1469 if dbm_setup_debug: print("building dbm using gdbm")
1470 dbmext = Extension(
1471 '_dbm', ['_dbmmodule.c'],
1472 define_macros=[
1473 ('HAVE_GDBM_DASH_NDBM_H', None),
1474 ],
1475 libraries = gdbm_libs)
1476 break
1477 elif cand == "bdb":
1478 if dblibs:
1479 if dbm_setup_debug: print("building dbm using bdb")
1480 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1481 library_dirs=dblib_dir,
1482 runtime_library_dirs=dblib_dir,
1483 include_dirs=db_incs,
1484 define_macros=[
1485 ('HAVE_BERKDB_H', None),
1486 ('DB_DBM_HSEARCH', None),
1487 ],
1488 libraries=dblibs)
1489 break
1490 if dbmext is not None:
1491 self.add(dbmext)
1492 else:
1493 self.missing.append('_dbm')
1494
1495 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1496 if ('gdbm' in dbm_order and
1497 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1498 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1499 libraries=['gdbm']))
1500 else:
1501 self.missing.append('_gdbm')
1502
1503 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001504 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001505 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001506
1507 # We hunt for #define SQLITE_VERSION "n.n.n"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001508 sqlite_incdir = sqlite_libdir = None
1509 sqlite_inc_paths = [ '/usr/include',
1510 '/usr/include/sqlite',
1511 '/usr/include/sqlite3',
1512 '/usr/local/include',
1513 '/usr/local/include/sqlite',
1514 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001515 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001516 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001517 sqlite_inc_paths = []
Erlend Egeberg Aaslandcf0b2392021-01-06 01:02:43 +01001518 MIN_SQLITE_VERSION_NUMBER = (3, 7, 15) # Issue 40810
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001519 MIN_SQLITE_VERSION = ".".join([str(x)
1520 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001521
1522 # Scan the default include directories before the SQLite specific
1523 # ones. This allows one to override the copy of sqlite on OSX,
1524 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001525 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001526 sysroot = macosx_sdk_root()
1527
Victor Stinner625dbf22019-03-01 15:59:39 +01001528 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001529 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001530 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001531 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001532
Ned Deily9b635832012-08-05 15:13:33 -07001533 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001534 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001535 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001536 with open(f) as file:
1537 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001538 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001539 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001540 if m:
1541 sqlite_version = m.group(1)
1542 sqlite_version_tuple = tuple([int(x)
1543 for x in sqlite_version.split(".")])
1544 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1545 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001546 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001547 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001548 sqlite_incdir = d
1549 break
1550 else:
1551 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001552 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001553 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001554 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001555 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001556
1557 if sqlite_incdir:
1558 sqlite_dirs_to_check = [
1559 os.path.join(sqlite_incdir, '..', 'lib64'),
1560 os.path.join(sqlite_incdir, '..', 'lib'),
1561 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1562 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1563 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001564 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001565 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001566 if sqlite_libfile:
1567 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001568
1569 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001570 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001571 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001572 '_sqlite/cursor.c',
1573 '_sqlite/microprotocols.c',
1574 '_sqlite/module.c',
1575 '_sqlite/prepare_protocol.c',
1576 '_sqlite/row.c',
1577 '_sqlite/statement.c',
1578 '_sqlite/util.c', ]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001579 sqlite_defines = []
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001580
Benjamin Peterson076ed002010-10-31 17:11:02 +00001581 # Enable support for loadable extensions in the sqlite3 module
1582 # if --enable-loadable-sqlite-extensions configure option is used.
1583 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1584 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001585
Victor Stinner4cbea512019-02-28 17:48:38 +01001586 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001587 # In every directory on the search path search for a dynamic
1588 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001589 # for dynamic libraries on the entire path.
1590 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001591 # before the dynamic library in /usr/lib.
1592 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1593 else:
1594 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001595
Brett Cannonc5011fe2011-06-06 20:09:10 -07001596 include_dirs = ["Modules/_sqlite"]
1597 # Only include the directory where sqlite was found if it does
1598 # not already exist in set include directories, otherwise you
1599 # can end up with a bad search path order.
1600 if sqlite_incdir not in self.compiler.include_dirs:
1601 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001602 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001603 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001604 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001605 self.add(Extension('_sqlite3', sqlite_srcs,
1606 define_macros=sqlite_defines,
1607 include_dirs=include_dirs,
1608 library_dirs=sqlite_libdir,
1609 extra_link_args=sqlite_extra_link_args,
1610 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001611 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001612 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001613
Victor Stinner5ec33a12019-03-01 16:43:28 +01001614 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001615 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001616 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001617 if not VXWORKS:
1618 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001619 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001620 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001621 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001622 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001623 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001624
Victor Stinner5ec33a12019-03-01 16:43:28 +01001625 # Platform-specific libraries
1626 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1627 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001628 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001629 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001630
Victor Stinner5ec33a12019-03-01 16:43:28 +01001631 if MACOS:
Ned Deily951ab582020-05-18 11:31:21 -04001632 self.add(Extension('_scproxy', ['_scproxy.c'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001633 extra_link_args=[
1634 '-framework', 'SystemConfiguration',
Ned Deily951ab582020-05-18 11:31:21 -04001635 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001636
Victor Stinner5ec33a12019-03-01 16:43:28 +01001637 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001638 # Andrew Kuchling's zlib module. Note that some versions of zlib
1639 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1640 # http://www.cert.org/advisories/CA-2002-07.html
1641 #
1642 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1643 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1644 # now, we still accept 1.1.3, because we think it's difficult to
1645 # exploit this in Python, and we'd rather make it RedHat's problem
1646 # than our problem <wink>.
1647 #
1648 # You can upgrade zlib to version 1.1.4 yourself by going to
1649 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001650 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001651 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001652 if zlib_inc is not None:
1653 zlib_h = zlib_inc[0] + '/zlib.h'
1654 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001655 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001656 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001657 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001658 with open(zlib_h) as fp:
1659 while 1:
1660 line = fp.readline()
1661 if not line:
1662 break
1663 if line.startswith('#define ZLIB_VERSION'):
1664 version = line.split()[2]
1665 break
Guido van Rossume6970912001-04-15 15:16:12 +00001666 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001667 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001668 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001669 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1670 else:
1671 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001672 self.add(Extension('zlib', ['zlibmodule.c'],
1673 libraries=['z'],
1674 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001675 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001676 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001677 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001678 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001679 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001680 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001681 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001682
Christian Heimes1dc54002008-03-24 02:19:29 +00001683 # Helper module for various ascii-encoders. Uses zlib for an optimized
1684 # crc32 if we have it. Otherwise binascii uses its own.
1685 if have_zlib:
1686 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1687 libraries = ['z']
1688 extra_link_args = zlib_extra_link_args
1689 else:
1690 extra_compile_args = []
1691 libraries = []
1692 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001693 self.add(Extension('binascii', ['binascii.c'],
1694 extra_compile_args=extra_compile_args,
1695 libraries=libraries,
1696 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001697
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001698 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001699 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001700 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001701 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1702 else:
1703 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001704 self.add(Extension('_bz2', ['_bz2module.c'],
1705 libraries=['bz2'],
1706 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001707 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001708 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001709
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001710 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001711 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001712 self.add(Extension('_lzma', ['_lzmamodule.c'],
1713 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001714 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001715 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001716
Victor Stinner5ec33a12019-03-01 16:43:28 +01001717 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001718 # Interface to the Expat XML parser
1719 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001720 # Expat was written by James Clark and is now maintained by a group of
1721 # developers on SourceForge; see www.libexpat.org for more information.
1722 # The pyexpat module was written by Paul Prescod after a prototype by
1723 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1724 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001725 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001726 #
1727 # More information on Expat can be found at www.libexpat.org.
1728 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001729 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1730 expat_inc = []
1731 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001732 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001733 expat_lib = ['expat']
1734 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001735 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001736 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001737 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001738 define_macros = [
1739 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001740 # bpo-30947: Python uses best available entropy sources to
1741 # call XML_SetHashSalt(), expat entropy sources are not needed
1742 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001743 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001744 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001745 expat_lib = []
1746 expat_sources = ['expat/xmlparse.c',
1747 'expat/xmlrole.c',
1748 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001749 expat_depends = ['expat/ascii.h',
1750 'expat/asciitab.h',
1751 'expat/expat.h',
1752 'expat/expat_config.h',
1753 'expat/expat_external.h',
1754 'expat/internal.h',
1755 'expat/latin1tab.h',
1756 'expat/utf8tab.h',
1757 'expat/xmlrole.h',
1758 'expat/xmltok.h',
1759 'expat/xmltok_impl.h'
1760 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001761
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001762 cc = sysconfig.get_config_var('CC').split()[0]
Victor Stinner6b982c22020-04-01 01:10:07 +02001763 ret = run_command(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001764 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Victor Stinner6b982c22020-04-01 01:10:07 +02001765 if ret == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001766 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001767
Victor Stinner8058bda2019-03-01 15:31:45 +01001768 self.add(Extension('pyexpat',
1769 define_macros=define_macros,
1770 extra_compile_args=extra_compile_args,
1771 include_dirs=expat_inc,
1772 libraries=expat_lib,
1773 sources=['pyexpat.c'] + expat_sources,
1774 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001775
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001776 # Fredrik Lundh's cElementTree module. Note that this also
1777 # uses expat (via the CAPI hook in pyexpat).
1778
Victor Stinner625dbf22019-03-01 15:59:39 +01001779 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001780 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001781 self.add(Extension('_elementtree',
1782 define_macros=define_macros,
1783 include_dirs=expat_inc,
1784 libraries=expat_lib,
1785 sources=['_elementtree.c'],
1786 depends=['pyexpat.c', *expat_sources,
1787 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001788 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001789 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001790
Victor Stinner5ec33a12019-03-01 16:43:28 +01001791 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001792 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001793 self.add(Extension('_multibytecodec',
1794 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001795 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001796 self.add(Extension('_codecs_%s' % loc,
1797 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001798
Victor Stinner5ec33a12019-03-01 16:43:28 +01001799 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001800 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001801 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001802 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1803 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001804 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001805 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001806 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1807 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001808 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Victor Stinner8058bda2019-03-01 15:31:45 +01001809 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001810 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001811
Victor Stinnercad80202021-01-19 23:04:49 +01001812 if (not MS_WINDOWS and
1813 sysconfig.get_config_var('HAVE_SHM_OPEN') and
1814 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
1815 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
1816 libs = []
1817 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1818 # need to link with librt to get shm_open()
1819 libs.append('rt')
1820 self.add(Extension('_posixshmem', posixshmem_srcs,
1821 define_macros={},
1822 libraries=libs,
1823 include_dirs=["Modules/_multiprocessing"]))
1824 else:
1825 self.missing.append('_posixshmem')
1826
Victor Stinner5ec33a12019-03-01 16:43:28 +01001827 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001828 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001829 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001830 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001831 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001832 uuid_libs = ['uuid']
1833 else:
1834 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001835 self.add(Extension('_uuid', ['_uuidmodule.c'],
1836 libraries=uuid_libs,
1837 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001838 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001839 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001840
Victor Stinner5ec33a12019-03-01 16:43:28 +01001841 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001842 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001843 self.init_inc_lib_dirs()
1844
1845 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001846 if TEST_EXTENSIONS:
1847 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001848 self.detect_readline_curses()
1849 self.detect_crypt()
1850 self.detect_socket()
1851 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001852 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001853 self.detect_dbm_gdbm()
1854 self.detect_sqlite()
1855 self.detect_platform_specific_exts()
1856 self.detect_nis()
1857 self.detect_compress_exts()
1858 self.detect_expat_elementtree()
1859 self.detect_multibytecodecs()
1860 self.detect_decimal()
1861 self.detect_ctypes()
1862 self.detect_multiprocessing()
1863 if not self.detect_tkinter():
1864 self.missing.append('_tkinter')
1865 self.detect_uuid()
1866
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001867## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001868## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001869
Hai Shi5787ba42021-04-06 20:55:13 +08001870 # The limited C API is not compatible with the Py_TRACE_REFS macro.
1871 if not sysconfig.get_config_var('Py_TRACE_REFS'):
1872 self.add(Extension('xxlimited', ['xxlimited.c']))
1873 self.add(Extension('xxlimited_35', ['xxlimited_35.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001874
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001875 def detect_tkinter_fromenv(self):
1876 # Build _tkinter using the Tcl/Tk locations specified by
1877 # the _TCLTK_INCLUDES and _TCLTK_LIBS environment variables.
1878 # This method is meant to be invoked by detect_tkinter().
Ned Deilyd819b932013-09-06 01:07:05 -07001879 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001880 # The variables can be set via one of the following ways.
Ned Deilyd819b932013-09-06 01:07:05 -07001881 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001882 # - Automatically, at configuration time, by using pkg-config.
1883 # The tool is called by the configure script.
1884 # Additional pkg-config configuration paths can be set via the
1885 # PKG_CONFIG_PATH environment variable.
1886 #
1887 # PKG_CONFIG_PATH=".../lib/pkgconfig" ./configure ...
1888 #
1889 # - Explicitly, at configuration time by setting both
1890 # --with-tcltk-includes and --with-tcltk-libs.
1891 #
1892 # ./configure ... \
Ned Deilyd819b932013-09-06 01:07:05 -07001893 # --with-tcltk-includes="-I/path/to/tclincludes \
1894 # -I/path/to/tkincludes"
1895 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1896 # -L/path/to/tklibs -ltkm.n"
1897 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001898 # - Explicitly, at compile time, by passing TCLTK_INCLUDES and
1899 # TCLTK_LIBS to the make target.
1900 # This will override any configuration-time option.
1901 #
1902 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
Ned Deilyd819b932013-09-06 01:07:05 -07001903 #
1904 # This can be useful for building and testing tkinter with multiple
1905 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1906 # build of Tcl so you need to specify both arguments and use care when
1907 # overriding.
1908
1909 # The _TCLTK variables are created in the Makefile sharedmods target.
1910 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1911 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1912 if not (tcltk_includes and tcltk_libs):
1913 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001914 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001915
1916 extra_compile_args = tcltk_includes.split()
1917 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001918 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1919 define_macros=[('WITH_APPINIT', 1)],
1920 extra_compile_args = extra_compile_args,
1921 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001922 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001923
Victor Stinner625dbf22019-03-01 15:59:39 +01001924 def detect_tkinter_darwin(self):
Ned Deily1731d6d2020-05-18 04:32:38 -04001925 # Build default _tkinter on macOS using Tcl and Tk frameworks.
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001926 # This method is meant to be invoked by detect_tkinter().
Ned Deily1731d6d2020-05-18 04:32:38 -04001927 #
1928 # The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
1929 # built and installed as macOS framework bundles. However,
1930 # for several reasons, we cannot take full advantage of the
1931 # Apple-supplied compiler chain's -framework options here.
1932 # Instead, we need to find and pass to the compiler the
1933 # absolute paths of the Tcl and Tk headers files we want to use
1934 # and the absolute path to the directory containing the Tcl
1935 # and Tk frameworks for linking.
1936 #
1937 # We want to handle here two common use cases on macOS:
1938 # 1. Build and link with system-wide third-party or user-built
1939 # Tcl and Tk frameworks installed in /Library/Frameworks.
1940 # 2. Build and link using a user-specified macOS SDK so that the
1941 # built Python can be exported to other systems. In this case,
1942 # search only the SDK's /Library/Frameworks (normally empty)
1943 # and /System/Library/Frameworks.
1944 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001945 # Any other use cases are handled either by detect_tkinter_fromenv(),
1946 # or detect_tkinter(). The former handles non-standard locations of
1947 # Tcl/Tk, defined via the _TCLTK_INCLUDES and _TCLTK_LIBS environment
1948 # variables. The latter handles any Tcl/Tk versions installed in
1949 # standard Unix directories.
1950 #
1951 # It would be desirable to also handle here the case where
Ned Deily1731d6d2020-05-18 04:32:38 -04001952 # you want to build and link with a framework build of Tcl and Tk
1953 # that is not in /Library/Frameworks, say, in your private
1954 # $HOME/Library/Frameworks directory or elsewhere. It turns
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301955 # out to be difficult to make that work automatically here
Ned Deily1731d6d2020-05-18 04:32:38 -04001956 # without bringing into play more tools and magic. That case
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301957 # can be handled using a recipe with the right arguments
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001958 # to detect_tkinter_fromenv().
Ned Deily1731d6d2020-05-18 04:32:38 -04001959 #
1960 # Note also that the fallback case here is to try to use the
1961 # Apple-supplied Tcl and Tk frameworks in /System/Library but
1962 # be forewarned that they are deprecated by Apple and typically
1963 # out-of-date and buggy; their use should be avoided if at
1964 # all possible by installing a newer version of Tcl and Tk in
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301965 # /Library/Frameworks before building Python without
Ned Deily1731d6d2020-05-18 04:32:38 -04001966 # an explicit SDK or by configuring build arguments explicitly.
1967
Jack Jansen0b06be72002-06-21 14:48:38 +00001968 from os.path import join, exists
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001969
Ned Deily1731d6d2020-05-18 04:32:38 -04001970 sysroot = macosx_sdk_root() # path to the SDK or '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001971
Ned Deily1731d6d2020-05-18 04:32:38 -04001972 if macosx_sdk_specified():
1973 # Use case #2: an SDK other than '/' was specified.
1974 # Only search there.
1975 framework_dirs = [
1976 join(sysroot, 'Library', 'Frameworks'),
1977 join(sysroot, 'System', 'Library', 'Frameworks'),
1978 ]
1979 else:
1980 # Use case #1: no explicit SDK selected.
1981 # Search the local system-wide /Library/Frameworks,
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301982 # not the one in the default SDK, otherwise fall back to
Ned Deily1731d6d2020-05-18 04:32:38 -04001983 # /System/Library/Frameworks whose header files may be in
1984 # the default SDK or, on older systems, actually installed.
1985 framework_dirs = [
1986 join('/', 'Library', 'Frameworks'),
1987 join(sysroot, 'System', 'Library', 'Frameworks'),
1988 ]
1989
1990 # Find the directory that contains the Tcl.framework and
1991 # Tk.framework bundles.
Jack Jansen0b06be72002-06-21 14:48:38 +00001992 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001993 # both Tcl.framework and Tk.framework should be present
Jack Jansen0b06be72002-06-21 14:48:38 +00001994 for fw in 'Tcl', 'Tk':
Ned Deily1731d6d2020-05-18 04:32:38 -04001995 if not exists(join(F, fw + '.framework')):
1996 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001997 else:
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301998 # ok, F is now directory with both frameworks. Continue
Jack Jansen0b06be72002-06-21 14:48:38 +00001999 # building
2000 break
2001 else:
2002 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
2003 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01002004 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00002005
Jack Jansen0b06be72002-06-21 14:48:38 +00002006 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00002007 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002008 for fw in ('Tcl', 'Tk')
Ned Deily1731d6d2020-05-18 04:32:38 -04002009 for H in ('Headers',)
Jack Jansen0b06be72002-06-21 14:48:38 +00002010 ]
2011
Ned Deily1731d6d2020-05-18 04:32:38 -04002012 # Add the base framework directory as well
2013 compile_args = ['-F', F]
Jack Jansen0b06be72002-06-21 14:48:38 +00002014
Ned Deily1731d6d2020-05-18 04:32:38 -04002015 # Do not build tkinter for archs that this Tk was not built with.
Georg Brandlfcaf9102008-07-16 02:17:56 +00002016 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04002017 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00002018
Ronald Oussorend097efe2009-09-15 19:07:58 +00002019 tmpfile = os.path.join(self.build_temp, 'tk.arch')
2020 if not os.path.exists(self.build_temp):
2021 os.makedirs(self.build_temp)
2022
Ned Deily1731d6d2020-05-18 04:32:38 -04002023 run_command(
2024 "file {}/Tk.framework/Tk | grep 'for architecture' > {}".format(F, tmpfile)
2025 )
Brett Cannon9f5db072010-10-29 20:19:27 +00002026 with open(tmpfile) as fp:
2027 detected_archs = []
2028 for ln in fp:
2029 a = ln.split()[-1]
2030 if a in archs:
2031 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00002032 os.unlink(tmpfile)
2033
Ned Deily1731d6d2020-05-18 04:32:38 -04002034 arch_args = []
Ronald Oussorend097efe2009-09-15 19:07:58 +00002035 for a in detected_archs:
Ned Deily1731d6d2020-05-18 04:32:38 -04002036 arch_args.append('-arch')
2037 arch_args.append(a)
2038
2039 compile_args += arch_args
2040 link_args = [','.join(['-Wl', '-F', F, '-framework', 'Tcl', '-framework', 'Tk']), *arch_args]
2041
2042 # The X11/xlib.h file bundled in the Tk sources can cause function
2043 # prototype warnings from the compiler. Since we cannot easily fix
2044 # that, suppress the warnings here instead.
2045 if '-Wstrict-prototypes' in cflags.split():
2046 compile_args.append('-Wno-strict-prototypes')
Georg Brandlfcaf9102008-07-16 02:17:56 +00002047
Victor Stinnercfe172d2019-03-01 18:21:49 +01002048 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2049 define_macros=[('WITH_APPINIT', 1)],
2050 include_dirs=include_dirs,
2051 libraries=[],
Ned Deily1731d6d2020-05-18 04:32:38 -04002052 extra_compile_args=compile_args,
2053 extra_link_args=link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01002054 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002055
Victor Stinner625dbf22019-03-01 15:59:39 +01002056 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002057 # The _tkinter module.
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01002058 #
2059 # Detection of Tcl/Tk is attempted in the following order:
2060 # - Through environment variables.
2061 # - Platform specific detection of Tcl/Tk (currently only macOS).
2062 # - Search of various standard Unix header/library paths.
2063 #
2064 # Detection stops at the first successful method.
Michael W. Hudson5b109102002-01-23 15:04:41 +00002065
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01002066 # Check for Tcl and Tk at the locations indicated by _TCLTK_INCLUDES
2067 # and _TCLTK_LIBS environment variables.
2068 if self.detect_tkinter_fromenv():
Victor Stinner5ec33a12019-03-01 16:43:28 +01002069 return True
Ned Deilyd819b932013-09-06 01:07:05 -07002070
Jack Jansen0b06be72002-06-21 14:48:38 +00002071 # Rather than complicate the code below, detecting and building
2072 # AquaTk is a separate method. Only one Tkinter will be built on
2073 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01002074 if (MACOS and self.detect_tkinter_darwin()):
2075 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002076
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002077 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002078 # The versions with dots are used on Unix, and the versions without
2079 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002080 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00002081 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
2082 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01002083 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002084 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01002085 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002086 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00002087 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002088 # Exit the loop when we've found the Tcl/Tk libraries
2089 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002090
Fredrik Lundhade711a2001-01-24 08:00:28 +00002091 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002092 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002093 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002094 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002095 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01002096 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002097 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
2098 # but the include subdirs are named like .../include/tcl8.3.
2099 dotversion = dotversion[:-1] + '.' + dotversion[-1]
2100 tcl_include_sub = []
2101 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01002102 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002103 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
2104 tk_include_sub += [dir + os.sep + "tk" + dotversion]
2105 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01002106 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
2107 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002108
Martin v. Löwise86a59a2003-05-03 08:45:51 +00002109 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002110 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002111 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01002112 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00002113
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002114 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002115
Victor Stinnercfe172d2019-03-01 18:21:49 +01002116 include_dirs = []
2117 libs = []
2118 defs = []
2119 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002120 for dir in tcl_includes + tk_includes:
2121 if dir not in include_dirs:
2122 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002123
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002124 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01002125 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002126 include_dirs.append('/usr/openwin/include')
2127 added_lib_dirs.append('/usr/openwin/lib')
2128 elif os.path.exists('/usr/X11R6/include'):
2129 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00002130 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002131 added_lib_dirs.append('/usr/X11R6/lib')
2132 elif os.path.exists('/usr/X11R5/include'):
2133 include_dirs.append('/usr/X11R5/include')
2134 added_lib_dirs.append('/usr/X11R5/lib')
2135 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002136 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002137 include_dirs.append('/usr/X11/include')
2138 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002139
Jason Tishler9181c942003-02-05 15:16:17 +00002140 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01002141 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00002142 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
2143 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01002144 return False
Jason Tishler9181c942003-02-05 15:16:17 +00002145
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002146 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01002147 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002148 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002149 defs.append( ('WITH_BLT', 1) )
2150 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01002151 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002152 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00002153 defs.append( ('WITH_BLT', 1) )
2154 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002155
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002156 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00002157 libs.append('tk'+ version)
2158 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002159
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002160 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01002161 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002162 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002163
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002164 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002165 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002166 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002167 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002168 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002169 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002170 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002171
Victor Stinnercfe172d2019-03-01 18:21:49 +01002172 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2173 define_macros=[('WITH_APPINIT', 1)] + defs,
2174 include_dirs=include_dirs,
2175 libraries=libs,
2176 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002177 return True
2178
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002179 def configure_ctypes(self, ext):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002180 return True
2181
Victor Stinner625dbf22019-03-01 15:59:39 +01002182 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002183 # Thomas Heller's _ctypes module
Ronald Oussoren41761932020-11-08 10:05:27 +01002184
2185 if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
2186 self.use_system_libffi = True
2187 else:
2188 self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
2189
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002190 include_dirs = []
Victor Stinner1ae035b2020-04-17 17:47:20 +02002191 extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002192 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002193 sources = ['_ctypes/_ctypes.c',
2194 '_ctypes/callbacks.c',
2195 '_ctypes/callproc.c',
2196 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002197 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002198 depends = ['_ctypes/ctypes.h']
2199
Victor Stinner4cbea512019-02-28 17:48:38 +01002200 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002201 sources.append('_ctypes/malloc_closure.c')
Ronald Oussoren41761932020-11-08 10:05:27 +01002202 extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
Christian Heimes78644762008-03-04 23:39:23 +00002203 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002204 include_dirs.append('_ctypes/darwin')
Thomas Hellercf567c12006-03-08 19:51:58 +00002205
Victor Stinner4cbea512019-02-28 17:48:38 +01002206 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002207 # XXX This shouldn't be necessary; it appears that some
2208 # of the assembler code is non-PIC (i.e. it has relocations
2209 # when it shouldn't. The proper fix would be to rewrite
2210 # the assembler code to be PIC.
2211 # This only works with GCC; the Sun compiler likely refuses
2212 # this option. If you want to compile ctypes with the Sun
2213 # compiler, please research a proper solution, instead of
2214 # finding some -z option for the Sun compiler.
2215 extra_link_args.append('-mimpure-text')
2216
Victor Stinner4cbea512019-02-28 17:48:38 +01002217 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002218 extra_link_args.append('-fPIC')
2219
Thomas Hellercf567c12006-03-08 19:51:58 +00002220 ext = Extension('_ctypes',
2221 include_dirs=include_dirs,
2222 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002223 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002224 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002225 sources=sources,
2226 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002227 self.add(ext)
2228 if TEST_EXTENSIONS:
2229 # function my_sqrt() needs libm for sqrt()
2230 self.add(Extension('_ctypes_test',
2231 sources=['_ctypes/_ctypes_test.c'],
2232 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002233
Ronald Oussoren41761932020-11-08 10:05:27 +01002234 ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
2235 ffi_lib = None
2236
Victor Stinner625dbf22019-03-01 15:59:39 +01002237 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002238 if MACOS:
Ronald Oussoren41761932020-11-08 10:05:27 +01002239 ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
Christian Heimes78644762008-03-04 23:39:23 +00002240
Ronald Oussoren41761932020-11-08 10:05:27 +01002241 if not ffi_inc:
2242 if os.path.exists(ffi_in_sdk):
2243 ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
2244 ffi_inc = ffi_in_sdk
2245 ffi_lib = 'ffi'
2246 else:
2247 # OS X 10.5 comes with libffi.dylib; the include files are
2248 # in /usr/include/ffi
2249 ffi_inc_dirs.append('/usr/include/ffi')
2250
2251 if not ffi_inc:
2252 found = find_file('ffi.h', [], ffi_inc_dirs)
2253 if found:
2254 ffi_inc = found[0]
2255 if ffi_inc:
2256 ffi_h = ffi_inc + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002257 if not os.path.exists(ffi_h):
2258 ffi_inc = None
2259 print('Header file {} does not exist'.format(ffi_h))
Ronald Oussoren41761932020-11-08 10:05:27 +01002260 if ffi_lib is None and ffi_inc:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002261 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002262 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002263 ffi_lib = lib_name
2264 break
2265
2266 if ffi_inc and ffi_lib:
Ronald Oussoren41761932020-11-08 10:05:27 +01002267 ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
2268 if grep_headers_for('ffi_prep_cif_var', ffi_headers):
2269 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
2270 if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
2271 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
2272 if grep_headers_for('ffi_closure_alloc', ffi_headers):
2273 ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
2274
2275 ext.include_dirs.append(ffi_inc)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002276 ext.libraries.append(ffi_lib)
2277 self.use_system_libffi = True
2278
Christian Heimes5bb96922018-02-25 10:22:14 +01002279 if sysconfig.get_config_var('HAVE_LIBDL'):
2280 # for dlopen, see bpo-32647
2281 ext.libraries.append('dl')
2282
Victor Stinner5ec33a12019-03-01 16:43:28 +01002283 def detect_decimal(self):
2284 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002285 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002286 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002287 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2288 include_dirs = []
Antoine Pitrou73b20ae2021-03-30 18:11:06 +02002289 libraries = ['mpdec']
Stefan Krah60187b52012-03-23 19:06:27 +01002290 sources = ['_decimal/_decimal.c']
2291 depends = ['_decimal/docstrings.h']
2292 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002293 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002294 'Modules',
2295 '_decimal',
2296 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002297 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002298 sources = [
2299 '_decimal/_decimal.c',
2300 '_decimal/libmpdec/basearith.c',
2301 '_decimal/libmpdec/constants.c',
2302 '_decimal/libmpdec/context.c',
2303 '_decimal/libmpdec/convolute.c',
2304 '_decimal/libmpdec/crt.c',
2305 '_decimal/libmpdec/difradix2.c',
2306 '_decimal/libmpdec/fnt.c',
2307 '_decimal/libmpdec/fourstep.c',
2308 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002309 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002310 '_decimal/libmpdec/mpdecimal.c',
2311 '_decimal/libmpdec/numbertheory.c',
2312 '_decimal/libmpdec/sixstep.c',
2313 '_decimal/libmpdec/transpose.c',
2314 ]
2315 depends = [
2316 '_decimal/docstrings.h',
2317 '_decimal/libmpdec/basearith.h',
2318 '_decimal/libmpdec/bits.h',
2319 '_decimal/libmpdec/constants.h',
2320 '_decimal/libmpdec/convolute.h',
2321 '_decimal/libmpdec/crt.h',
2322 '_decimal/libmpdec/difradix2.h',
2323 '_decimal/libmpdec/fnt.h',
2324 '_decimal/libmpdec/fourstep.h',
2325 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002326 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002327 '_decimal/libmpdec/mpdecimal.h',
2328 '_decimal/libmpdec/numbertheory.h',
2329 '_decimal/libmpdec/sixstep.h',
2330 '_decimal/libmpdec/transpose.h',
2331 '_decimal/libmpdec/typearith.h',
2332 '_decimal/libmpdec/umodarith.h',
2333 ]
2334
Stefan Krah1919b7e2012-03-21 18:25:23 +01002335 config = {
2336 'x64': [('CONFIG_64','1'), ('ASM','1')],
2337 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2338 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2339 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2340 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2341 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2342 ('LEGACY_COMPILER','1')],
2343 'universal': [('UNIVERSAL','1')]
2344 }
2345
Stefan Krah1919b7e2012-03-21 18:25:23 +01002346 cc = sysconfig.get_config_var('CC')
2347 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2348 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2349
2350 if machine:
2351 # Override automatic configuration to facilitate testing.
2352 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002353 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002354 # Universal here means: build with the same options Python
2355 # was built with.
2356 define_macros = config['universal']
2357 elif sizeof_size_t == 8:
2358 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2359 define_macros = config['x64']
2360 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2361 define_macros = config['uint128']
2362 else:
2363 define_macros = config['ansi64']
2364 elif sizeof_size_t == 4:
2365 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2366 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002367 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002368 # solaris: problems with register allocation.
2369 # icc >= 11.0 works as well.
2370 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002371 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002372 else:
2373 define_macros = config['ansi32']
2374 else:
2375 raise DistutilsError("_decimal: unsupported architecture")
2376
2377 # Workarounds for toolchain bugs:
2378 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2379 # Some versions of gcc miscompile inline asm:
2380 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2381 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2382 extra_compile_args.append('-fno-ipa-pure-const')
2383 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2384 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2385 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2386 undef_macros.append('_FORTIFY_SOURCE')
2387
Stefan Krah1919b7e2012-03-21 18:25:23 +01002388 # Uncomment for extra functionality:
2389 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002390 self.add(Extension('_decimal',
2391 include_dirs=include_dirs,
2392 libraries=libraries,
2393 define_macros=define_macros,
2394 undef_macros=undef_macros,
2395 extra_compile_args=extra_compile_args,
2396 sources=sources,
2397 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002398
Victor Stinner5ec33a12019-03-01 16:43:28 +01002399 def detect_openssl_hashlib(self):
2400 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002401 config_vars = sysconfig.get_config_vars()
2402
2403 def split_var(name, sep):
2404 # poor man's shlex, the re module is not available yet.
2405 value = config_vars.get(name)
2406 if not value:
2407 return ()
2408 # This trick works because ax_check_openssl uses --libs-only-L,
2409 # --libs-only-l, and --cflags-only-I.
2410 value = ' ' + value
2411 sep = ' ' + sep
2412 return [v.strip() for v in value.split(sep) if v.strip()]
2413
2414 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2415 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2416 openssl_libs = split_var('OPENSSL_LIBS', '-l')
Christian Heimes32eba612021-03-19 10:29:25 +01002417 openssl_rpath = config_vars.get('OPENSSL_RPATH')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002418 if not openssl_libs:
2419 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002420 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002421 return None, None
2422
2423 # Find OpenSSL includes
2424 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002425 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002426 )
2427 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002428 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002429 return None, None
2430
Christian Heimes39258d32021-04-17 11:36:35 +02002431 self.add(Extension(
2432 '_ssl', ['_ssl.c'],
2433 include_dirs=openssl_includes,
2434 library_dirs=openssl_libdirs,
2435 libraries=openssl_libs,
2436 depends=['socketmodule.h', '_ssl/debughelpers.c'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002437 )
Christian Heimesff5be6e2018-01-20 13:19:21 +01002438
Christian Heimes32eba612021-03-19 10:29:25 +01002439 if openssl_rpath == 'auto':
2440 runtime_library_dirs = openssl_libdirs[:]
2441 elif not openssl_rpath:
2442 runtime_library_dirs = []
2443 else:
2444 runtime_library_dirs = [openssl_rpath]
2445
Christian Heimesbacefbf2021-03-27 18:03:54 +01002446 openssl_extension_kwargs = dict(
2447 include_dirs=openssl_includes,
2448 library_dirs=openssl_libdirs,
2449 libraries=openssl_libs,
2450 runtime_library_dirs=runtime_library_dirs,
2451 )
2452
2453 # This static linking is NOT OFFICIALLY SUPPORTED.
2454 # Requires static OpenSSL build with position-independent code. Some
2455 # features like DSO engines or external OSSL providers don't work.
2456 # Only tested on GCC and clang on X86_64.
2457 if os.environ.get("PY_UNSUPPORTED_OPENSSL_BUILD") == "static":
2458 extra_linker_args = []
2459 for lib in openssl_extension_kwargs["libraries"]:
2460 # link statically
2461 extra_linker_args.append(f"-l:lib{lib}.a")
2462 # don't export symbols
2463 extra_linker_args.append(f"-Wl,--exclude-libs,lib{lib}.a")
2464 openssl_extension_kwargs["extra_link_args"] = extra_linker_args
2465 # don't link OpenSSL shared libraries.
2466 openssl_extension_kwargs["libraries"] = []
2467
Christian Heimes39258d32021-04-17 11:36:35 +02002468 self.add(
2469 Extension(
2470 '_ssl',
2471 ['_ssl.c'],
2472 depends=['socketmodule.h', '_ssl/debughelpers.c'],
2473 **openssl_extension_kwargs
Christian Heimesc7f70692019-05-31 11:44:05 +02002474 )
Christian Heimes39258d32021-04-17 11:36:35 +02002475 )
Christian Heimesbacefbf2021-03-27 18:03:54 +01002476 self.add(
2477 Extension(
2478 '_hashlib',
2479 ['_hashopenssl.c'],
2480 depends=['hashlib.h'],
2481 **openssl_extension_kwargs,
2482 )
2483 )
Christian Heimesff5be6e2018-01-20 13:19:21 +01002484
xdegaye2ee077f2019-04-09 17:20:08 +02002485 def detect_hash_builtins(self):
Christian Heimes9b60e552020-05-15 23:54:53 +02002486 # By default we always compile these even when OpenSSL is available
2487 # (issue #14693). It's harmless and the object code is tiny
2488 # (40-50 KiB per module, only loaded when actually used). Modules can
2489 # be disabled via the --with-builtin-hashlib-hashes configure flag.
2490 supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
Victor Stinner5ec33a12019-03-01 16:43:28 +01002491
Christian Heimes9b60e552020-05-15 23:54:53 +02002492 configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
2493 configured = configured.strip('"').lower()
2494 configured = {
2495 m.strip() for m in configured.split(",")
2496 }
Victor Stinner5ec33a12019-03-01 16:43:28 +01002497
Christian Heimes9b60e552020-05-15 23:54:53 +02002498 self.disabled_configure.extend(
2499 sorted(supported.difference(configured))
2500 )
Victor Stinner5ec33a12019-03-01 16:43:28 +01002501
Christian Heimes9b60e552020-05-15 23:54:53 +02002502 if "sha256" in configured:
2503 self.add(Extension(
2504 '_sha256', ['sha256module.c'],
2505 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2506 depends=['hashlib.h']
2507 ))
2508
2509 if "sha512" in configured:
2510 self.add(Extension(
2511 '_sha512', ['sha512module.c'],
2512 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2513 depends=['hashlib.h']
2514 ))
2515
2516 if "md5" in configured:
2517 self.add(Extension(
2518 '_md5', ['md5module.c'],
2519 depends=['hashlib.h']
2520 ))
2521
2522 if "sha1" in configured:
2523 self.add(Extension(
2524 '_sha1', ['sha1module.c'],
2525 depends=['hashlib.h']
2526 ))
2527
2528 if "blake2" in configured:
2529 blake2_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002530 os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002531 )
2532 blake2_deps.append('hashlib.h')
2533 self.add(Extension(
2534 '_blake2',
2535 [
2536 '_blake2/blake2module.c',
2537 '_blake2/blake2b_impl.c',
2538 '_blake2/blake2s_impl.c'
2539 ],
2540 depends=blake2_deps
2541 ))
2542
2543 if "sha3" in configured:
2544 sha3_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002545 os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002546 )
2547 sha3_deps.append('hashlib.h')
2548 self.add(Extension(
2549 '_sha3',
2550 ['_sha3/sha3module.c'],
2551 depends=sha3_deps
2552 ))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002553
2554 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002555 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002556 self.missing.append('nis')
2557 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002558
2559 libs = []
2560 library_dirs = []
2561 includes_dirs = []
2562
2563 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2564 # moved headers and libraries to libtirpc and libnsl. The headers
2565 # are in tircp and nsl sub directories.
2566 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002567 'rpcsvc/yp_prot.h', self.inc_dirs,
2568 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002569 )
2570 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002571 'rpc/rpc.h', self.inc_dirs,
2572 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002573 )
2574 if rpcsvc_inc is None or rpc_inc is None:
2575 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002576 self.missing.append('nis')
2577 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002578 includes_dirs.extend(rpcsvc_inc)
2579 includes_dirs.extend(rpc_inc)
2580
Victor Stinner625dbf22019-03-01 15:59:39 +01002581 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002582 libs.append('nsl')
2583 else:
2584 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002585 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002586 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2587 if libnsl is not None:
2588 library_dirs.append(os.path.dirname(libnsl))
2589 libs.append('nsl')
2590
Victor Stinner625dbf22019-03-01 15:59:39 +01002591 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002592 libs.append('tirpc')
2593
Victor Stinner8058bda2019-03-01 15:31:45 +01002594 self.add(Extension('nis', ['nismodule.c'],
2595 libraries=libs,
2596 library_dirs=library_dirs,
2597 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002598
Christian Heimesff5be6e2018-01-20 13:19:21 +01002599
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002600class PyBuildInstall(install):
2601 # Suppress the warning about installation into the lib_dynload
2602 # directory, which is not in sys.path when running Python during
2603 # installation:
2604 def initialize_options (self):
2605 install.initialize_options(self)
2606 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002607
Éric Araujoe6792c12011-06-09 14:07:02 +02002608 # Customize subcommands to not install an egg-info file for Python
2609 sub_commands = [('install_lib', install.has_lib),
2610 ('install_headers', install.has_headers),
2611 ('install_scripts', install.has_scripts),
2612 ('install_data', install.has_data)]
2613
2614
Michael W. Hudson529a5052002-12-17 16:47:17 +00002615class PyBuildInstallLib(install_lib):
2616 # Do exactly what install_lib does but make sure correct access modes get
2617 # set on installed directories and files. All installed files with get
2618 # mode 644 unless they are a shared library in which case they will get
2619 # mode 755. All installed directories will get mode 755.
2620
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002621 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2622 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002623
2624 def install(self):
2625 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002626 self.set_file_modes(outfiles, 0o644, 0o755)
2627 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002628 return outfiles
2629
2630 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002631 if not files: return
2632
2633 for filename in files:
2634 if os.path.islink(filename): continue
2635 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002636 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002637 log.info("changing mode of %s to %o", filename, mode)
2638 if not self.dry_run: os.chmod(filename, mode)
2639
2640 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002641 for dirpath, dirnames, fnames in os.walk(dirname):
2642 if os.path.islink(dirpath):
2643 continue
2644 log.info("changing mode of %s to %o", dirpath, mode)
2645 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002646
Victor Stinnerc991f242019-03-01 17:19:04 +01002647
Georg Brandlff52f762010-12-28 09:51:43 +00002648class PyBuildScripts(build_scripts):
2649 def copy_scripts(self):
2650 outfiles, updated_files = build_scripts.copy_scripts(self)
2651 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2652 minoronly = '.{0[1]}'.format(sys.version_info)
2653 newoutfiles = []
2654 newupdated_files = []
2655 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002656 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002657 newfilename = filename + fullversion
2658 else:
2659 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002660 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002661 os.rename(filename, newfilename)
2662 newoutfiles.append(newfilename)
2663 if filename in updated_files:
2664 newupdated_files.append(newfilename)
2665 return newoutfiles, newupdated_files
2666
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002667
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002668def main():
Victor Stinnercad80202021-01-19 23:04:49 +01002669 global LIST_MODULE_NAMES
2670
2671 if "--list-module-names" in sys.argv:
2672 LIST_MODULE_NAMES = True
2673 sys.argv.remove("--list-module-names")
2674
Victor Stinnerc991f242019-03-01 17:19:04 +01002675 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2676 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2677
2678 class DummyProcess:
2679 """Hack for parallel build"""
2680 ProcessPoolExecutor = None
2681
2682 sys.modules['concurrent.futures.process'] = DummyProcess
Paul Ganssle62972d92020-05-16 04:20:06 -04002683 validate_tzpath()
Victor Stinnerc991f242019-03-01 17:19:04 +01002684
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002685 # turn off warnings when deprecated modules are imported
2686 import warnings
2687 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002688 setup(# PyPI Metadata (PEP 301)
2689 name = "Python",
2690 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002691 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002692 maintainer = "Guido van Rossum and the Python community",
2693 maintainer_email = "python-dev@python.org",
2694 description = "A high-level object-oriented programming language",
2695 long_description = SUMMARY.strip(),
2696 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002697 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002698 platforms = ["Many"],
2699
2700 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002701 cmdclass = {'build_ext': PyBuildExt,
2702 'build_scripts': PyBuildScripts,
2703 'install': PyBuildInstall,
2704 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002705 # The struct module is defined here, because build_ext won't be
2706 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002707 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002708
Georg Brandlff52f762010-12-28 09:51:43 +00002709 # If you change the scripts installed here, you also need to
2710 # check the PyBuildScripts command above, and change the links
2711 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002712 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002713 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002714 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002715
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002716# --install-platlib
2717if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002718 main()