blob: 554772217785db9c396c71886e672cb0da52c0ee [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
Serhiy Storchaka93558682020-06-20 11:10:31 +030011from glob import glob, escape
Ronald Oussoren404a7192020-11-22 06:14:25 +010012import _osx_support
Michael W. Hudson529a5052002-12-17 16:47:17 +000013
Victor Stinner1ec63b62020-03-04 14:50:19 +010014
15try:
16 import subprocess
17 del subprocess
18 SUBPROCESS_BOOTSTRAP = False
19except ImportError:
Victor Stinner1ec63b62020-03-04 14:50:19 +010020 # Bootstrap Python: distutils.spawn uses subprocess to build C extensions,
21 # subprocess requires C extensions built by setup.py like _posixsubprocess.
22 #
Victor Stinneraddaaaa2020-03-09 23:45:59 +010023 # Use _bootsubprocess which only uses the os module.
Victor Stinner1ec63b62020-03-04 14:50:19 +010024 #
25 # It is dropped from sys.modules as soon as all C extension modules
26 # are built.
Victor Stinneraddaaaa2020-03-09 23:45:59 +010027 import _bootsubprocess
28 sys.modules['subprocess'] = _bootsubprocess
29 del _bootsubprocess
30 SUBPROCESS_BOOTSTRAP = True
Victor Stinner1ec63b62020-03-04 14:50:19 +010031
32
Michael W. Hudson529a5052002-12-17 16:47:17 +000033from distutils import log
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000034from distutils.command.build_ext import build_ext
Victor Stinner625dbf22019-03-01 15:59:39 +010035from distutils.command.build_scripts import build_scripts
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000036from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:17 +000037from distutils.command.install_lib import install_lib
Victor Stinner625dbf22019-03-01 15:59:39 +010038from distutils.core import Extension, setup
39from distutils.errors import CCompilerError, DistutilsError
Stefan Krah095b2732010-06-08 13:41:44 +000040from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000041
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020042
Victor Stinnercfe172d2019-03-01 18:21:49 +010043# Compile extensions used to test Python?
pxinwr277ce302020-12-30 20:50:39 +080044TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes')
Victor Stinnercfe172d2019-03-01 18:21:49 +010045
46# This global variable is used to hold the list of modules to be disabled.
47DISABLED_MODULE_LIST = []
48
Victor Stinnercad80202021-01-19 23:04:49 +010049# --list-module-names option used by Tools/scripts/generate_module_names.py
50LIST_MODULE_NAMES = False
51
Victor Stinnercfe172d2019-03-01 18:21:49 +010052
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020053def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010054 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020055 if "_PYTHON_HOST_PLATFORM" in os.environ:
56 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010057
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020058 # Get value of sys.platform
59 if sys.platform.startswith('osf1'):
60 return 'osf1'
61 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010062
63
64CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010065HOST_PLATFORM = get_platform()
66MS_WINDOWS = (HOST_PLATFORM == 'win32')
67CYGWIN = (HOST_PLATFORM == 'cygwin')
68MACOS = (HOST_PLATFORM == 'darwin')
Michael Felt08970cb2019-06-21 15:58:00 +020069AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 17:48:38 +010070VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080071
Victor Stinnerc991f242019-03-01 17:19:04 +010072
73SUMMARY = """
74Python is an interpreted, interactive, object-oriented programming
75language. It is often compared to Tcl, Perl, Scheme or Java.
76
77Python combines remarkable power with very clear syntax. It has
78modules, classes, exceptions, very high level dynamic data types, and
79dynamic typing. There are interfaces to many system calls and
80libraries, as well as to various windowing systems (X11, Motif, Tk,
81Mac, MFC). New built-in modules are easily written in C or C++. Python
82is also usable as an extension language for applications that need a
83programmable interface.
84
85The Python implementation is portable: it runs on many brands of UNIX,
86on Windows, DOS, Mac, Amiga... If your favorite system isn't
87listed here, it may still be supported, if there's a C compiler for
88it. Ask around on comp.lang.python -- or just try compiling Python
89yourself.
90"""
91
92CLASSIFIERS = """
93Development Status :: 6 - Mature
94License :: OSI Approved :: Python Software Foundation License
95Natural Language :: English
96Programming Language :: C
97Programming Language :: Python
98Topic :: Software Development
99"""
100
101
Victor Stinner6b982c22020-04-01 01:10:07 +0200102def run_command(cmd):
103 status = os.system(cmd)
Victor Stinner65a796e2020-04-01 18:49:29 +0200104 return os.waitstatus_to_exitcode(status)
Victor Stinner6b982c22020-04-01 01:10:07 +0200105
106
Victor Stinnerc991f242019-03-01 17:19:04 +0100107# Set common compiler and linker flags derived from the Makefile,
108# reserved for building the interpreter and the stdlib modules.
109# See bpo-21121 and bpo-35257
110def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
111 flags = sysconfig.get_config_var(compiler_flags)
112 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
113 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
114
115
Michael W. Hudson39230b32002-01-16 15:26:48 +0000116def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000117 """Add the directory 'dir' to the list 'dirlist' (after any relative
118 directories) if:
119
Michael W. Hudson39230b32002-01-16 15:26:48 +0000120 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000121 2) 'dir' actually exists, and is a directory.
122 """
123 if dir is None or not os.path.isdir(dir) or dir in dirlist:
124 return
125 for i, path in enumerate(dirlist):
126 if not os.path.isabs(path):
127 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000128 return
129 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000130
Victor Stinnerc991f242019-03-01 17:19:04 +0100131
xdegaye77f51392017-11-25 17:25:30 +0100132def sysroot_paths(make_vars, subdirs):
133 """Get the paths of sysroot sub-directories.
134
135 * make_vars: a sequence of names of variables of the Makefile where
136 sysroot may be set.
137 * subdirs: a sequence of names of subdirectories used as the location for
138 headers or libraries.
139 """
140
141 dirs = []
142 for var_name in make_vars:
143 var = sysconfig.get_config_var(var_name)
144 if var is not None:
145 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
146 if m is not None:
147 sysroot = m.group(1).strip('"')
148 for subdir in subdirs:
149 if os.path.isabs(subdir):
150 subdir = subdir[1:]
151 path = os.path.join(sysroot, subdir)
152 if os.path.isdir(path):
153 dirs.append(path)
154 break
155 return dirs
156
Ned Deily1731d6d2020-05-18 04:32:38 -0400157
Ned Deily0288dd62019-06-03 06:34:48 -0400158MACOS_SDK_ROOT = None
Ned Deily1731d6d2020-05-18 04:32:38 -0400159MACOS_SDK_SPECIFIED = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100160
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000161def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400162 """Return the directory of the current macOS SDK.
163
164 If no SDK was explicitly configured, call the compiler to find which
165 include files paths are being searched by default. Use '/' if the
166 compiler is searching /usr/include (meaning system header files are
167 installed) or use the root of an SDK if that is being searched.
168 (The SDK may be supplied via Xcode or via the Command Line Tools).
169 The SDK paths used by Apple-supplied tool chains depend on the
170 setting of various variables; see the xcrun man page for more info.
Ned Deily1731d6d2020-05-18 04:32:38 -0400171 Also sets MACOS_SDK_SPECIFIED for use by macosx_sdk_specified().
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000172 """
Ned Deily1731d6d2020-05-18 04:32:38 -0400173 global MACOS_SDK_ROOT, MACOS_SDK_SPECIFIED
Ned Deily0288dd62019-06-03 06:34:48 -0400174
175 # If already called, return cached result.
176 if MACOS_SDK_ROOT:
177 return MACOS_SDK_ROOT
178
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000179 cflags = sysconfig.get_config_var('CFLAGS')
Joshua Rootb3107002020-04-22 17:44:10 +1000180 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400181 if m is not None:
182 MACOS_SDK_ROOT = m.group(1)
Ned Deily29afab62020-12-04 23:02:09 -0500183 MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000184 else:
Ronald Oussoren404a7192020-11-22 06:14:25 +0100185 MACOS_SDK_ROOT = _osx_support._default_sysroot(
186 sysconfig.get_config_var('CC'))
Ned Deily29afab62020-12-04 23:02:09 -0500187 MACOS_SDK_SPECIFIED = False
Ned Deily0288dd62019-06-03 06:34:48 -0400188
189 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000190
Victor Stinnerc991f242019-03-01 17:19:04 +0100191
Ned Deily1731d6d2020-05-18 04:32:38 -0400192def macosx_sdk_specified():
193 """Returns true if an SDK was explicitly configured.
194
195 True if an SDK was selected at configure time, either by specifying
196 --enable-universalsdk=(something other than no or /) or by adding a
197 -isysroot option to CFLAGS. In some cases, like when making
198 decisions about macOS Tk framework paths, we need to be able to
199 know whether the user explicitly asked to build with an SDK versus
200 the implicit use of an SDK when header files are no longer
201 installed on a running system by the Command Line Tools.
202 """
203 global MACOS_SDK_SPECIFIED
204
205 # If already called, return cached result.
206 if MACOS_SDK_SPECIFIED:
207 return MACOS_SDK_SPECIFIED
208
209 # Find the sdk root and set MACOS_SDK_SPECIFIED
210 macosx_sdk_root()
211 return MACOS_SDK_SPECIFIED
212
213
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000214def is_macosx_sdk_path(path):
215 """
216 Returns True if 'path' can be located in an OSX SDK
217 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700218 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
219 or path.startswith('/System/')
220 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000221
Victor Stinnerc991f242019-03-01 17:19:04 +0100222
Ronald Oussoren41761932020-11-08 10:05:27 +0100223def grep_headers_for(function, headers):
224 for header in headers:
Ronald Oussoren7a27c7e2020-11-14 16:07:47 +0100225 with open(header, 'r', errors='surrogateescape') as f:
Ronald Oussoren41761932020-11-08 10:05:27 +0100226 if function in f.read():
227 return True
228 return False
229
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000230def find_file(filename, std_dirs, paths):
231 """Searches for the directory where a given file is located,
232 and returns a possibly-empty list of additional directories, or None
233 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000234
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000235 'filename' is the name of a file, such as readline.h or libcrypto.a.
236 'std_dirs' is the list of standard system directories; if the
237 file is found in one of them, no additional directives are needed.
238 'paths' is a list of additional locations to check; if the file is
239 found in one of them, the resulting list will contain the directory.
240 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100241 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000242 # Honor the MacOSX SDK setting when one was specified.
243 # An SDK is a directory with the same structure as a real
244 # system, but with only header files and libraries.
245 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000246
247 # Check the standard locations
248 for dir in std_dirs:
249 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000250
Victor Stinner4cbea512019-02-28 17:48:38 +0100251 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000252 f = os.path.join(sysroot, dir[1:], filename)
253
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000254 if os.path.exists(f): return []
255
256 # Check the additional directories
257 for dir in paths:
258 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000259
Victor Stinner4cbea512019-02-28 17:48:38 +0100260 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000261 f = os.path.join(sysroot, dir[1:], filename)
262
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000263 if os.path.exists(f):
264 return [dir]
265
266 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000267 return None
268
Victor Stinnerc991f242019-03-01 17:19:04 +0100269
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000270def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000271 result = compiler.find_library_file(std_dirs + paths, libname)
272 if result is None:
273 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000274
Victor Stinner4cbea512019-02-28 17:48:38 +0100275 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000276 sysroot = macosx_sdk_root()
277
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000278 # Check whether the found file is in one of the standard directories
279 dirname = os.path.dirname(result)
280 for p in std_dirs:
281 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000282 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000283
Victor Stinner4cbea512019-02-28 17:48:38 +0100284 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100285 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
286 # libraries with .tbd extensions rather than the normal .dylib
287 # shared libraries installed in /. The Apple compiler tool
288 # chain handles this transparently but it can cause problems
289 # for programs that are being built with an SDK and searching
290 # for specific libraries. Distutils find_library_file() now
291 # knows to also search for and return .tbd files. But callers
292 # of find_library_file need to keep in mind that the base filename
293 # of the returned SDK library file might have a different extension
294 # from that of the library file installed on the running system,
295 # for example:
296 # /Applications/Xcode.app/Contents/Developer/Platforms/
297 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
298 # usr/lib/libedit.tbd
299 # vs
300 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000301 if os.path.join(sysroot, p[1:]) == dirname:
302 return [ ]
303
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000304 if p == dirname:
305 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000306
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000307 # Otherwise, it must have been in one of the additional directories,
308 # so we have to figure out which one.
309 for p in paths:
310 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000311 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000312
Victor Stinner4cbea512019-02-28 17:48:38 +0100313 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000314 if os.path.join(sysroot, p[1:]) == dirname:
315 return [ p ]
316
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000317 if p == dirname:
318 return [p]
319 else:
320 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000321
Paul Ganssle62972d92020-05-16 04:20:06 -0400322def validate_tzpath():
323 base_tzpath = sysconfig.get_config_var('TZPATH')
324 if not base_tzpath:
325 return
326
327 tzpaths = base_tzpath.split(os.pathsep)
328 bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
329 if bad_paths:
330 raise ValueError('TZPATH must contain only absolute paths, '
331 + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
332 + f'{bad_paths!r}')
Victor Stinnerc991f242019-03-01 17:19:04 +0100333
Jack Jansen144ebcc2001-08-05 22:31:19 +0000334def find_module_file(module, dirlist):
335 """Find a module in a set of possible folders. If it is not found
336 return the unadorned filename"""
337 list = find_file(module, [], dirlist)
338 if not list:
339 return module
340 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100341 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000342 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000343
Victor Stinnerc991f242019-03-01 17:19:04 +0100344
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000345class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000346
Guido van Rossumd8faa362007-04-27 19:54:29 +0000347 def __init__(self, dist):
348 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100349 self.srcdir = None
350 self.lib_dirs = None
351 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100352 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000353 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400354 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100355 self.missing = []
Christian Heimes9b60e552020-05-15 23:54:53 +0200356 self.disabled_configure = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200357 if '-j' in os.environ.get('MAKEFLAGS', ''):
358 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000359
Victor Stinner8058bda2019-03-01 15:31:45 +0100360 def add(self, ext):
361 self.extensions.append(ext)
362
Victor Stinner00c77ae2020-03-04 18:44:49 +0100363 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100364 self.srcdir = sysconfig.get_config_var('srcdir')
365 if not self.srcdir:
366 # Maybe running on Windows but not using CYGWIN?
367 raise ValueError("No source directory; cannot proceed.")
368 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000369
Victor Stinner00c77ae2020-03-04 18:44:49 +0100370 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000371 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000372 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100373 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000374 # move ctypes to the end, it depends on other modules
375 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
376 if "_ctypes" in ext_map:
377 ctypes = extensions.pop(ext_map["_ctypes"])
378 extensions.append(ctypes)
379 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000380
Victor Stinner00c77ae2020-03-04 18:44:49 +0100381 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000382 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000383 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100384 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000385
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000386 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100387 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000388 for filename in self.distribution.scripts]
389
Christian Heimesaf98da12008-01-27 15:18:18 +0000390 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000391 headers = [sysconfig.get_config_h_filename()]
Serhiy Storchaka93558682020-06-20 11:10:31 +0300392 headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000393
Xavier de Gaye84968b72016-10-29 16:57:20 +0200394 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000395 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000396 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000397 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000398 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000399 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000400 else:
401 ext.depends = []
402 # re-compile extensions if a header file has been changed
403 ext.depends.extend(headers)
404
Victor Stinner00c77ae2020-03-04 18:44:49 +0100405 def remove_configured_extensions(self):
406 # The sysconfig variables built by makesetup that list the already
407 # built modules and the disabled modules as configured by the Setup
408 # files.
409 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
410 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
411
412 mods_built = []
413 mods_disabled = []
414 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200415 # If a module has already been built or has been disabled in the
416 # Setup files, don't build it here.
417 if ext.name in sysconf_built:
418 mods_built.append(ext)
419 if ext.name in sysconf_dis:
420 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000421
xdegayec0364fc2017-05-27 18:25:03 +0200422 mods_configured = mods_built + mods_disabled
423 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200424 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200425 mods_configured]
426 # Remove the shared libraries built by a previous build.
427 for ext in mods_configured:
428 fullpath = self.get_ext_fullpath(ext.name)
429 if os.path.exists(fullpath):
430 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000431
Victor Stinner00c77ae2020-03-04 18:44:49 +0100432 return (mods_built, mods_disabled)
433
434 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000435 # When you run "make CC=altcc" or something similar, you really want
436 # those environment variables passed into the setup.py phase. Here's
437 # a small set of useful ones.
438 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000439 args = {}
440 # unfortunately, distutils doesn't let us provide separate C and C++
441 # compilers
442 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000443 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
444 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000445 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000446
Victor Stinner00c77ae2020-03-04 18:44:49 +0100447 def build_extensions(self):
448 self.set_srcdir()
449
450 # Detect which modules should be compiled
451 self.detect_modules()
452
Victor Stinnercad80202021-01-19 23:04:49 +0100453 if not LIST_MODULE_NAMES:
454 self.remove_disabled()
Victor Stinner00c77ae2020-03-04 18:44:49 +0100455
456 self.update_sources_depends()
457 mods_built, mods_disabled = self.remove_configured_extensions()
458 self.set_compiler_executables()
459
Victor Stinnercad80202021-01-19 23:04:49 +0100460 if LIST_MODULE_NAMES:
461 for ext in self.extensions:
462 print(ext.name)
463 for name in self.missing:
464 print(name)
465 return
466
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000467 build_ext.build_extensions(self)
468
Victor Stinner1ec63b62020-03-04 14:50:19 +0100469 if SUBPROCESS_BOOTSTRAP:
470 # Drop our custom subprocess module:
471 # use the newly built subprocess module
472 del sys.modules['subprocess']
473
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200474 for ext in self.extensions:
475 self.check_extension_import(ext)
476
Victor Stinner00c77ae2020-03-04 18:44:49 +0100477 self.summary(mods_built, mods_disabled)
478
479 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300480 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400481 if self.failed or self.failed_on_import:
482 all_failed = self.failed + self.failed_on_import
483 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000484
485 def print_three_column(lst):
486 lst.sort(key=str.lower)
487 # guarantee zip() doesn't drop anything
488 while len(lst) % 3:
489 lst.append("")
490 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
491 print("%-*s %-*s %-*s" % (longest, e, longest, f,
492 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000493
Victor Stinner8058bda2019-03-01 15:31:45 +0100494 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000495 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400496 print("Python build finished successfully!")
497 print("The necessary bits to build these optional modules were not "
498 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100499 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000500 print("To find the necessary bits, look in setup.py in"
501 " detect_modules() for the module's name.")
502 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000503
xdegayec0364fc2017-05-27 18:25:03 +0200504 if mods_built:
505 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200506 print("The following modules found by detect_modules() in"
507 " setup.py, have been")
508 print("built by the Makefile instead, as configured by the"
509 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200510 print_three_column([ext.name for ext in mods_built])
511 print()
512
513 if mods_disabled:
514 print()
515 print("The following modules found by detect_modules() in"
516 " setup.py have not")
517 print("been built, they are *disabled* in the Setup files:")
518 print_three_column([ext.name for ext in mods_disabled])
519 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200520
Christian Heimes9b60e552020-05-15 23:54:53 +0200521 if self.disabled_configure:
522 print()
523 print("The following modules found by detect_modules() in"
524 " setup.py have not")
525 print("been built, they are *disabled* by configure:")
526 print_three_column(self.disabled_configure)
527 print()
528
Guido van Rossumd8faa362007-04-27 19:54:29 +0000529 if self.failed:
530 failed = self.failed[:]
531 print()
532 print("Failed to build these modules:")
533 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000534 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000535
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400536 if self.failed_on_import:
537 failed = self.failed_on_import[:]
538 print()
539 print("Following modules built successfully"
540 " but were removed because they could not be imported:")
541 print_three_column(failed)
542 print()
543
Christian Heimes61d478c2018-01-27 15:51:38 +0100544 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100545 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100546 print()
547 print("Could not build the ssl module!")
548 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
549 "libssl with X509_VERIFY_PARAM_set1_host().")
550 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
551 "APIs, https://github.com/libressl-portable/portable/issues/381")
552 print()
553
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000554 def build_extension(self, ext):
555
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000556 if ext.name == '_ctypes':
557 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500558 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000559 return
560
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000561 try:
562 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000563 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000564 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100565 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000566 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000567 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200568
569 def check_extension_import(self, ext):
570 # Don't try to import an extension that has failed to compile
571 if ext.name in self.failed:
572 self.announce(
573 'WARNING: skipping import check for failed build "%s"' %
574 ext.name, level=1)
575 return
576
Jack Jansenf49c6f92001-11-01 14:44:15 +0000577 # Workaround for Mac OS X: The Carbon-based modules cannot be
578 # reliably imported into a command-line Python
579 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000580 self.announce(
581 'WARNING: skipping import check for Carbon-based "%s"' %
582 ext.name)
583 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000584
Victor Stinner4cbea512019-02-28 17:48:38 +0100585 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000586 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000587 # Don't bother doing an import check when an extension was
588 # build with an explicit '-arch' flag on OSX. That's currently
589 # only used to build 32-bit only extensions in a 4-way
590 # universal build and loading 32-bit code into a 64-bit
591 # process will fail.
592 self.announce(
593 'WARNING: skipping import check for "%s"' %
594 ext.name)
595 return
596
Jason Tishler24cf7762002-05-22 16:46:15 +0000597 # Workaround for Cygwin: Cygwin currently has fork issues when many
598 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100599 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000600 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
601 % ext.name)
602 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000603 ext_filename = os.path.join(
604 self.build_lib,
605 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000606
607 # If the build directory didn't exist when setup.py was
608 # started, sys.path_importer_cache has a negative result
609 # cached. Clear that cache before trying to import.
610 sys.path_importer_cache.clear()
611
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200612 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100613 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200614 return
615
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400616 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700617 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
618 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000619 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400620 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000621 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400622 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000623 self.announce('*** WARNING: renaming "%s" since importing it'
624 ' failed: %s' % (ext.name, why), level=3)
625 assert not self.inplace
626 basename, tail = os.path.splitext(ext_filename)
627 newname = basename + "_failed" + tail
628 if os.path.exists(newname):
629 os.remove(newname)
630 os.rename(ext_filename, newname)
631
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000632 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000633 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000634 self.announce('*** WARNING: importing extension "%s" '
635 'failed with %s: %s' % (ext.name, exc_type, why),
636 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000637 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000638
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400639 def add_multiarch_paths(self):
640 # Debian/Ubuntu multiarch support.
641 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200642 cc = sysconfig.get_config_var('CC')
643 tmpfile = os.path.join(self.build_temp, 'multiarch')
644 if not os.path.exists(self.build_temp):
645 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200646 ret = run_command(
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200647 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
648 multiarch_path_component = ''
649 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200650 if ret == 0:
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200651 with open(tmpfile) as fp:
652 multiarch_path_component = fp.readline().strip()
653 finally:
654 os.unlink(tmpfile)
655
656 if multiarch_path_component != '':
657 add_dir_to_list(self.compiler.library_dirs,
658 '/usr/lib/' + multiarch_path_component)
659 add_dir_to_list(self.compiler.include_dirs,
660 '/usr/include/' + multiarch_path_component)
661 return
662
Barry Warsaw88e19452011-04-07 10:40:36 -0400663 if not find_executable('dpkg-architecture'):
664 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200665 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100666 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200667 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400668 tmpfile = os.path.join(self.build_temp, 'multiarch')
669 if not os.path.exists(self.build_temp):
670 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200671 ret = run_command(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200672 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
673 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400674 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200675 if ret == 0:
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400676 with open(tmpfile) as fp:
677 multiarch_path_component = fp.readline().strip()
678 add_dir_to_list(self.compiler.library_dirs,
679 '/usr/lib/' + multiarch_path_component)
680 add_dir_to_list(self.compiler.include_dirs,
681 '/usr/include/' + multiarch_path_component)
682 finally:
683 os.unlink(tmpfile)
684
pxinwr5e45f1c2021-01-22 08:55:52 +0800685 def add_wrcc_search_dirs(self):
686 # add library search path by wr-cc, the compiler wrapper
687
688 def convert_mixed_path(path):
689 # convert path like C:\folder1\folder2/folder3/folder4
690 # to msys style /c/folder1/folder2/folder3/folder4
691 drive = path[0].lower()
692 left = path[2:].replace("\\", "/")
693 return "/" + drive + left
694
695 def add_search_path(line):
696 # On Windows building machine, VxWorks does
697 # cross builds under msys2 environment.
698 pathsep = (";" if sys.platform == "msys" else ":")
699 for d in line.strip().split("=")[1].split(pathsep):
700 d = d.strip()
701 if sys.platform == "msys":
702 # On Windows building machine, compiler
703 # returns mixed style path like:
704 # C:\folder1\folder2/folder3/folder4
705 d = convert_mixed_path(d)
706 d = os.path.normpath(d)
707 add_dir_to_list(self.compiler.library_dirs, d)
708
709 cc = sysconfig.get_config_var('CC')
710 tmpfile = os.path.join(self.build_temp, 'wrccpaths')
711 os.makedirs(self.build_temp, exist_ok=True)
712 try:
713 ret = run_command('%s --print-search-dirs >%s' % (cc, tmpfile))
714 if ret:
715 return
716 with open(tmpfile) as fp:
717 # Parse paths in libraries line. The line is like:
718 # On Linux, "libraries: = path1:path2:path3"
719 # On Windows, "libraries: = path1;path2;path3"
720 for line in fp:
721 if not line.startswith("libraries"):
722 continue
723 add_search_path(line)
724 finally:
725 try:
726 os.unlink(tmpfile)
727 except OSError:
728 pass
729
pxinwr32f5fdd2019-02-27 19:09:28 +0800730 def add_cross_compiling_paths(self):
731 cc = sysconfig.get_config_var('CC')
732 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200733 if not os.path.exists(self.build_temp):
734 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200735 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200736 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800737 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200738 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200739 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200740 if ret == 0:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200741 with open(tmpfile) as fp:
742 for line in fp.readlines():
743 if line.startswith("gcc version"):
744 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800745 elif line.startswith("clang version"):
746 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200747 elif line.startswith("#include <...>"):
748 in_incdirs = True
749 elif line.startswith("End of search list"):
750 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800751 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200752 for d in line.strip().split("=")[1].split(":"):
753 d = os.path.normpath(d)
754 if '/gcc/' not in d:
755 add_dir_to_list(self.compiler.library_dirs,
756 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800757 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 +0200758 add_dir_to_list(self.compiler.include_dirs,
759 line.strip())
760 finally:
761 os.unlink(tmpfile)
762
pxinwr5e45f1c2021-01-22 08:55:52 +0800763 if VXWORKS:
764 self.add_wrcc_search_dirs()
765
Victor Stinnercfe172d2019-03-01 18:21:49 +0100766 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000767 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000768 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000769 # We must get the values from the Makefile and not the environment
770 # directly since an inconsistently reproducible issue comes up where
771 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000772 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000773 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000774 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
775 ('LDFLAGS', '-L', self.compiler.library_dirs),
776 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000777 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000778 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800779 parser = argparse.ArgumentParser()
780 parser.add_argument(arg_name, dest="dirs", action="append")
781 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000782 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000783 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000784 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000785
Victor Stinnercfe172d2019-03-01 18:21:49 +0100786 def configure_compiler(self):
787 # Ensure that /usr/local is always used, but the local build
788 # directories (i.e. '.' and 'Include') must be first. See issue
789 # 10520.
790 if not CROSS_COMPILING:
791 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
792 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
793 # only change this for cross builds for 3.3, issues on Mageia
794 if CROSS_COMPILING:
795 self.add_cross_compiling_paths()
796 self.add_multiarch_paths()
797 self.add_ldflags_cppflags()
798
Victor Stinner5ec33a12019-03-01 16:43:28 +0100799 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100800 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100801 os.path.normpath(sys.base_prefix) != '/usr' and
802 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000803 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
804 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
805 # building a framework with different architectures than
806 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000807 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000808 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000809 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000810 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000811
xdegaye77f51392017-11-25 17:25:30 +0100812 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
813 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000814 # lib_dirs and inc_dirs are used to search for files;
815 # if a file is found in one of those directories, it can
816 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100817 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100818 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
819 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100820 else:
xdegaye77f51392017-11-25 17:25:30 +0100821 # Add the sysroot paths. 'sysroot' is a compiler option used to
822 # set the logical path of the standard system headers and
823 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100824 self.lib_dirs = (self.compiler.library_dirs +
825 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
826 self.inc_dirs = (self.compiler.include_dirs +
827 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
828 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000829
Brett Cannon4454a1f2005-04-15 20:32:39 +0000830 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000831 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100832 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000833
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000834 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100835 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100836 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000837
Charles-François Natali5739e102012-04-12 19:07:25 +0200838 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100839 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100840 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200841
Victor Stinner4cbea512019-02-28 17:48:38 +0100842 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000843 # This should work on any unixy platform ;-)
844 # If the user has bothered specifying additional -I and -L flags
845 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000846 #
847 # NOTE: using shlex.split would technically be more correct, but
848 # also gives a bootstrap problem. Let's hope nobody uses
849 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000850 cflags, ldflags = sysconfig.get_config_vars(
851 'CFLAGS', 'LDFLAGS')
852 for item in cflags.split():
853 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100854 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000855
856 for item in ldflags.split():
857 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100858 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000859
Victor Stinner5ec33a12019-03-01 16:43:28 +0100860 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000861 #
862 # The following modules are all pretty straightforward, and compile
863 # on pretty much any POSIXish platform.
864 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000865
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000866 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100867 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000868
Yury Selivanovf23746a2018-01-22 19:11:18 -0500869 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100870 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500871
Martin Panterc9deece2016-02-03 05:19:44 +0000872 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100873
874 # math library functions, e.g. sin()
875 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100876 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100877 extra_objects=[shared_math],
878 depends=['_math.h', shared_math],
879 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100880
881 # complex math library functions
882 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100883 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100884 extra_objects=[shared_math],
885 depends=['_math.h', shared_math],
886 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200887
888 # time libraries: librt may be needed for clock_gettime()
889 time_libs = []
890 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
891 if lib:
892 time_libs.append(lib)
893
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000894 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100895 self.add(Extension('time', ['timemodule.c'],
896 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800897 # libm is needed by delta_new() that uses round() and by accum() that
898 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100899 self.add(Extension('_datetime', ['_datetimemodule.c'],
Victor Stinner04fc4f22020-06-16 01:28:07 +0200900 libraries=['m'],
901 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Paul Ganssle62972d92020-05-16 04:20:06 -0400902 # zoneinfo module
Victor Stinner37834132020-10-27 17:12:53 +0100903 self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
904 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000905 # random number generator implemented in C
Victor Stinner9f5fe792020-04-17 19:05:35 +0200906 self.add(Extension("_random", ["_randommodule.c"],
907 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000908 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100909 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000910 # heapq
Victor Stinnerc45dbe932020-06-22 17:39:32 +0200911 self.add(Extension("_heapq", ["_heapqmodule.c"],
912 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000913 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200914 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200915 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimes90540002008-05-08 14:29:10 +0000916 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100917 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200918 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100919
Fred Drake0e474a82007-10-11 18:01:43 +0000920 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100921 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000922 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100923 self.add(Extension('unicodedata', ['unicodedata.c'],
Victor Stinner47e1afd2020-10-26 16:43:47 +0100924 depends=['unicodedata_db.h', 'unicodename_db.h'],
925 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Larry Hastings3a907972013-11-23 14:49:22 -0800926 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100927 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900928 # asyncio speedups
Chris Jerdonekda742ba2020-05-17 22:47:31 -0700929 self.add(Extension("_asyncio", ["_asynciomodule.c"],
930 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000931 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100932 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100933 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100934 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900935 # _statistics module
936 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000937
938 # Modules with some UNIX dependencies -- on by default:
939 # (If you have a really backward UNIX, select and socket may not be
940 # supported...)
941
942 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000943 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100944 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000945 # May be necessary on AIX for flock function
946 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100947 self.add(Extension('fcntl', ['fcntlmodule.c'],
948 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000949 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100950 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000951 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800952 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100953 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000954 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100955 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
956 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100957 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200958 # AIX has shadow passwords, but access is not via getspent(), etc.
959 # module support is not expected so it not 'missing'
960 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100961 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000962
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000963 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100964 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000965
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000966 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100967 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000968
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000969 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000970 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100971 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000972
Eric Snow7f8bfc92018-01-29 18:23:44 -0700973 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600974 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700975
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000976 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000977 # Here ends the simple stuff. From here on, modules need certain
978 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000979 #
980
981 # Multimedia modules
982 # These don't work for 64-bit platforms!!!
983 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200984 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000985 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000986 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000987 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200988 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800989 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100990 self.add(Extension('audioop', ['audioop.c'],
991 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000992
Victor Stinner5ec33a12019-03-01 16:43:28 +0100993 # CSV files
994 self.add(Extension('_csv', ['_csv.c']))
995
996 # POSIX subprocess module helper.
Kyle Evans79925792020-10-13 15:04:44 -0500997 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
998 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner5ec33a12019-03-01 16:43:28 +0100999
Victor Stinnercfe172d2019-03-01 18:21:49 +01001000 def detect_test_extensions(self):
1001 # Python C API test module
1002 self.add(Extension('_testcapi', ['_testcapimodule.c'],
1003 depends=['testcapi_long.h']))
1004
Victor Stinner23bace22019-04-18 11:37:26 +02001005 # Python Internal C API test module
1006 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +02001007 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +02001008
Victor Stinnercfe172d2019-03-01 18:21:49 +01001009 # Python PEP-3118 (buffer protocol) test module
1010 self.add(Extension('_testbuffer', ['_testbuffer.c']))
1011
1012 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
1013 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
1014
1015 # Test multi-phase extension module init (PEP 489)
1016 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
1017
1018 # Fuzz tests.
1019 self.add(Extension('_xxtestfuzz',
1020 ['_xxtestfuzz/_xxtestfuzz.c',
1021 '_xxtestfuzz/fuzzer.c']))
1022
Victor Stinner5ec33a12019-03-01 16:43:28 +01001023 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001024 # readline
Stefan Krah095b2732010-06-08 13:41:44 +00001025 readline_termcap_library = ""
1026 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +02001027 # Cannot use os.popen here in py3k.
1028 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
1029 if not os.path.exists(self.build_temp):
1030 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +00001031 # Determine if readline is already linked against curses or tinfo.
Roland Hiebere1f77692021-02-09 02:05:25 +01001032 if sysconfig.get_config_var('HAVE_LIBREADLINE'):
1033 if sysconfig.get_config_var('WITH_EDITLINE'):
1034 readline_lib = 'edit'
1035 else:
1036 readline_lib = 'readline'
1037 do_readline = self.compiler.find_library_file(self.lib_dirs,
1038 readline_lib)
Victor Stinner4cbea512019-02-28 17:48:38 +01001039 if CROSS_COMPILING:
Victor Stinner6b982c22020-04-01 01:10:07 +02001040 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
doko@ubuntu.com58844492012-06-30 18:25:32 +02001041 % (sysconfig.get_config_var('READELF'),
1042 do_readline, tmpfile))
1043 elif find_executable('ldd'):
Victor Stinner6b982c22020-04-01 01:10:07 +02001044 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
doko@ubuntu.com58844492012-06-30 18:25:32 +02001045 else:
Victor Stinner6b982c22020-04-01 01:10:07 +02001046 ret = 1
1047 if ret == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +00001048 with open(tmpfile) as fp:
1049 for ln in fp:
1050 if 'curses' in ln:
1051 readline_termcap_library = re.sub(
1052 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
1053 ).rstrip()
1054 break
1055 # termcap interface split out from ncurses
1056 if 'tinfo' in ln:
1057 readline_termcap_library = 'tinfo'
1058 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +02001059 if os.path.exists(tmpfile):
1060 os.unlink(tmpfile)
Roland Hiebere1f77692021-02-09 02:05:25 +01001061 else:
1062 do_readline = False
Stefan Krah095b2732010-06-08 13:41:44 +00001063 # Issue 7384: If readline is already linked against curses,
1064 # use the same library for the readline and curses modules.
1065 if 'curses' in readline_termcap_library:
1066 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +01001067 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +00001068 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +02001069 # Issue 36210: OSS provided ncurses does not link on AIX
1070 # Use IBM supplied 'curses' for successful build of _curses
1071 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
1072 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001073 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001074 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001075 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001076 curses_library = 'curses'
1077
Victor Stinner4cbea512019-02-28 17:48:38 +01001078 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001079 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +00001080 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -07001081 if (dep_target and
Ronald Oussoren49926cf2021-02-01 04:29:44 +01001082 (tuple(int(n) for n in dep_target.split('.')[0:2])
Ned Deily04cdfa12014-06-25 13:36:14 -07001083 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +00001084 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001085 if os_release < 9:
1086 # MacOSX 10.4 has a broken readline. Don't try to build
1087 # the readline module unless the user has installed a fixed
1088 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +01001089 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001090 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +00001091 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +01001092 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001093 # In every directory on the search path search for a dynamic
1094 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +00001095 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +00001096 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001097 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +00001098 readline_extra_link_args = ('-Wl,-search_paths_first',)
1099 else:
1100 readline_extra_link_args = ()
1101
Roland Hiebere1f77692021-02-09 02:05:25 +01001102 readline_libs = [readline_lib]
Stefan Krah095b2732010-06-08 13:41:44 +00001103 if readline_termcap_library:
1104 pass # Issue 7384: Already linked against curses or tinfo.
1105 elif curses_library:
1106 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001107 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001108 ['/usr/lib/termcap'],
1109 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001110 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001111 self.add(Extension('readline', ['readline.c'],
1112 library_dirs=['/usr/lib/termcap'],
1113 extra_link_args=readline_extra_link_args,
1114 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001115 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001116 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001117
Victor Stinner5ec33a12019-03-01 16:43:28 +01001118 # Curses support, requiring the System V version of curses, often
1119 # provided by the ncurses library.
1120 curses_defines = []
1121 curses_includes = []
1122 panel_library = 'panel'
1123 if curses_library == 'ncursesw':
1124 curses_defines.append(('HAVE_NCURSESW', '1'))
1125 if not CROSS_COMPILING:
1126 curses_includes.append('/usr/include/ncursesw')
1127 # Bug 1464056: If _curses.so links with ncursesw,
1128 # _curses_panel.so must link with panelw.
1129 panel_library = 'panelw'
1130 if MACOS:
1131 # On OS X, there is no separate /usr/lib/libncursesw nor
1132 # libpanelw. If we are here, we found a locally-supplied
1133 # version of libncursesw. There should also be a
1134 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1135 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1136 # ncurses wide char support
1137 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1138 elif MACOS and curses_library == 'ncurses':
1139 # Building with the system-suppied combined libncurses/libpanel
1140 curses_defines.append(('HAVE_NCURSESW', '1'))
1141 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001142
Victor Stinnercfe172d2019-03-01 18:21:49 +01001143 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001144 if curses_library.startswith('ncurses'):
1145 curses_libs = [curses_library]
1146 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001147 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001148 include_dirs=curses_includes,
1149 define_macros=curses_defines,
1150 libraries=curses_libs))
1151 elif curses_library == 'curses' and not MACOS:
1152 # OSX has an old Berkeley curses, not good enough for
1153 # the _curses module.
1154 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1155 curses_libs = ['curses', 'terminfo']
1156 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1157 curses_libs = ['curses', 'termcap']
1158 else:
1159 curses_libs = ['curses']
1160
1161 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001162 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001163 define_macros=curses_defines,
1164 libraries=curses_libs))
1165 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001166 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001167 self.missing.append('_curses')
1168
1169 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001170 # _curses_panel needs some form of ncurses
1171 skip_curses_panel = True if AIX else False
1172 if (curses_enabled and not skip_curses_panel and
1173 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001174 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001175 include_dirs=curses_includes,
1176 define_macros=curses_defines,
1177 libraries=[panel_library, *curses_libs]))
1178 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001179 self.missing.append('_curses_panel')
1180
1181 def detect_crypt(self):
1182 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001183 if VXWORKS:
1184 # bpo-31904: crypt() function is not provided by VxWorks.
1185 # DES_crypt() OpenSSL provides is too weak to implement
1186 # the encryption.
Victor Stinnercad80202021-01-19 23:04:49 +01001187 self.missing.append('_crypt')
pxinwr236d0b72019-04-15 17:02:20 +08001188 return
1189
Victor Stinner625dbf22019-03-01 15:59:39 +01001190 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001191 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001192 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001193 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001194
Victor Stinnercad80202021-01-19 23:04:49 +01001195 self.add(Extension('_crypt', ['_cryptmodule.c'], libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001196
Victor Stinner5ec33a12019-03-01 16:43:28 +01001197 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001198 # socket(2)
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001199 kwargs = {'depends': ['socketmodule.h']}
pxinwr00a65682020-11-29 06:14:16 +08001200 if MACOS:
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001201 # Issue #35569: Expose RFC 3542 socket options.
1202 kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542']
Erlend Egeberg Aasland9a45bfe2020-05-17 08:32:46 +02001203
Erlend Egeberg Aaslandccdcb202020-11-18 01:08:58 +01001204 self.add(Extension('_socket', ['socketmodule.c'], **kwargs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001205
Victor Stinner5ec33a12019-03-01 16:43:28 +01001206 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001207 # Modules that provide persistent dictionary-like semantics. You will
1208 # probably want to arrange for at least one of them to be available on
1209 # your machine, though none are defined by default because of library
1210 # dependencies. The Python module dbm/__init__.py provides an
1211 # implementation independent wrapper for these; dbm/dumb.py provides
1212 # similar functionality (but slower of course) implemented in Python.
1213
1214 # Sleepycat^WOracle Berkeley DB interface.
1215 # http://www.oracle.com/database/berkeley-db/db/index.html
1216 #
1217 # This requires the Sleepycat^WOracle DB code. The supported versions
1218 # are set below. Visit the URL above to download
1219 # a release. Most open source OSes come with one or more
1220 # versions of BerkeleyDB already installed.
1221
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001222 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001223 min_db_ver = (3, 3)
1224 db_setup_debug = False # verbose debug prints from this script?
1225
1226 def allow_db_ver(db_ver):
1227 """Returns a boolean if the given BerkeleyDB version is acceptable.
1228
1229 Args:
1230 db_ver: A tuple of the version to verify.
1231 """
1232 if not (min_db_ver <= db_ver <= max_db_ver):
1233 return False
1234 return True
1235
1236 def gen_db_minor_ver_nums(major):
1237 if major == 4:
1238 for x in range(max_db_ver[1]+1):
1239 if allow_db_ver((4, x)):
1240 yield x
1241 elif major == 3:
1242 for x in (3,):
1243 if allow_db_ver((3, x)):
1244 yield x
1245 else:
1246 raise ValueError("unknown major BerkeleyDB version", major)
1247
1248 # construct a list of paths to look for the header file in on
1249 # top of the normal inc_dirs.
1250 db_inc_paths = [
1251 '/usr/include/db4',
1252 '/usr/local/include/db4',
1253 '/opt/sfw/include/db4',
1254 '/usr/include/db3',
1255 '/usr/local/include/db3',
1256 '/opt/sfw/include/db3',
1257 # Fink defaults (http://fink.sourceforge.net/)
1258 '/sw/include/db4',
1259 '/sw/include/db3',
1260 ]
1261 # 4.x minor number specific paths
1262 for x in gen_db_minor_ver_nums(4):
1263 db_inc_paths.append('/usr/include/db4%d' % x)
1264 db_inc_paths.append('/usr/include/db4.%d' % x)
1265 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1266 db_inc_paths.append('/usr/local/include/db4%d' % x)
1267 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1268 db_inc_paths.append('/opt/db-4.%d/include' % x)
1269 # MacPorts default (http://www.macports.org/)
1270 db_inc_paths.append('/opt/local/include/db4%d' % x)
1271 # 3.x minor number specific paths
1272 for x in gen_db_minor_ver_nums(3):
1273 db_inc_paths.append('/usr/include/db3%d' % x)
1274 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1275 db_inc_paths.append('/usr/local/include/db3%d' % x)
1276 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1277 db_inc_paths.append('/opt/db-3.%d/include' % x)
1278
Victor Stinner4cbea512019-02-28 17:48:38 +01001279 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001280 db_inc_paths = []
1281
Georg Brandl489cb4f2009-07-11 10:08:49 +00001282 # Add some common subdirectories for Sleepycat DB to the list,
1283 # based on the standard include directories. This way DB3/4 gets
1284 # picked up when it is installed in a non-standard prefix and
1285 # the user has added that prefix into inc_dirs.
1286 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001287 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001288 std_variants.append(os.path.join(dn, 'db3'))
1289 std_variants.append(os.path.join(dn, 'db4'))
1290 for x in gen_db_minor_ver_nums(4):
1291 std_variants.append(os.path.join(dn, "db4%d"%x))
1292 std_variants.append(os.path.join(dn, "db4.%d"%x))
1293 for x in gen_db_minor_ver_nums(3):
1294 std_variants.append(os.path.join(dn, "db3%d"%x))
1295 std_variants.append(os.path.join(dn, "db3.%d"%x))
1296
1297 db_inc_paths = std_variants + db_inc_paths
1298 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1299
1300 db_ver_inc_map = {}
1301
Victor Stinner4cbea512019-02-28 17:48:38 +01001302 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001303 sysroot = macosx_sdk_root()
1304
Georg Brandl489cb4f2009-07-11 10:08:49 +00001305 class db_found(Exception): pass
1306 try:
1307 # See whether there is a Sleepycat header in the standard
1308 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001309 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001310 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001311 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001312 f = os.path.join(sysroot, d[1:], "db.h")
1313
Georg Brandl489cb4f2009-07-11 10:08:49 +00001314 if db_setup_debug: print("db: looking for db.h in", f)
1315 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001316 with open(f, 'rb') as file:
1317 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001318 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001319 if m:
1320 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001321 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001322 db_minor = int(m.group(1))
1323 db_ver = (db_major, db_minor)
1324
1325 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1326 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001327 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001328 db_patch = int(m.group(1))
1329 if db_patch < 21:
1330 print("db.h:", db_ver, "patch", db_patch,
1331 "being ignored (4.6.x must be >= 4.6.21)")
1332 continue
1333
1334 if ( (db_ver not in db_ver_inc_map) and
1335 allow_db_ver(db_ver) ):
1336 # save the include directory with the db.h version
1337 # (first occurrence only)
1338 db_ver_inc_map[db_ver] = d
1339 if db_setup_debug:
1340 print("db.h: found", db_ver, "in", d)
1341 else:
1342 # we already found a header for this library version
1343 if db_setup_debug: print("db.h: ignoring", d)
1344 else:
1345 # ignore this header, it didn't contain a version number
1346 if db_setup_debug:
1347 print("db.h: no version number version in", d)
1348
1349 db_found_vers = list(db_ver_inc_map.keys())
1350 db_found_vers.sort()
1351
1352 while db_found_vers:
1353 db_ver = db_found_vers.pop()
1354 db_incdir = db_ver_inc_map[db_ver]
1355
1356 # check lib directories parallel to the location of the header
1357 db_dirs_to_check = [
1358 db_incdir.replace("include", 'lib64'),
1359 db_incdir.replace("include", 'lib'),
1360 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001361
Victor Stinner4cbea512019-02-28 17:48:38 +01001362 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001363 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1364
1365 else:
1366 # Same as other branch, but takes OSX SDK into account
1367 tmp = []
1368 for dn in db_dirs_to_check:
1369 if is_macosx_sdk_path(dn):
1370 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1371 tmp.append(dn)
1372 else:
1373 if os.path.isdir(dn):
1374 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001375 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001376
1377 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001378
Ezio Melotti42da6632011-03-15 05:18:48 +02001379 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001380 # XXX should we -ever- look for a dbX name? Do any
1381 # systems really not name their library by version and
1382 # symlink to more general names?
1383 for dblib in (('db-%d.%d' % db_ver),
1384 ('db%d%d' % db_ver),
1385 ('db%d' % db_ver[0])):
1386 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001387 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001388 if dblib_file:
1389 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1390 raise db_found
1391 else:
1392 if db_setup_debug: print("db lib: ", dblib, "not found")
1393
1394 except db_found:
1395 if db_setup_debug:
1396 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1397 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001398 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001399 # Only add the found library and include directories if they aren't
1400 # already being searched. This avoids an explicit runtime library
1401 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001402 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001403 db_incs = None
1404 else:
1405 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001406 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001407 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001408 else:
1409 if db_setup_debug: print("db: no appropriate library found")
1410 db_incs = None
1411 dblibs = []
1412 dblib_dir = None
1413
Victor Stinner5ec33a12019-03-01 16:43:28 +01001414 dbm_setup_debug = False # verbose debug prints from this script?
1415 dbm_order = ['gdbm']
1416 # The standard Unix dbm module:
1417 if not CYGWIN:
1418 config_args = [arg.strip("'")
1419 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1420 dbm_args = [arg for arg in config_args
1421 if arg.startswith('--with-dbmliborder=')]
1422 if dbm_args:
1423 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1424 else:
1425 dbm_order = "ndbm:gdbm:bdb".split(":")
1426 dbmext = None
1427 for cand in dbm_order:
1428 if cand == "ndbm":
1429 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1430 # Some systems have -lndbm, others have -lgdbm_compat,
1431 # others don't have either
1432 if self.compiler.find_library_file(self.lib_dirs,
1433 'ndbm'):
1434 ndbm_libs = ['ndbm']
1435 elif self.compiler.find_library_file(self.lib_dirs,
1436 'gdbm_compat'):
1437 ndbm_libs = ['gdbm_compat']
1438 else:
1439 ndbm_libs = []
1440 if dbm_setup_debug: print("building dbm using ndbm")
1441 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1442 define_macros=[
1443 ('HAVE_NDBM_H',None),
1444 ],
1445 libraries=ndbm_libs)
1446 break
1447
1448 elif cand == "gdbm":
1449 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1450 gdbm_libs = ['gdbm']
1451 if self.compiler.find_library_file(self.lib_dirs,
1452 'gdbm_compat'):
1453 gdbm_libs.append('gdbm_compat')
1454 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1455 if dbm_setup_debug: print("building dbm using gdbm")
1456 dbmext = Extension(
1457 '_dbm', ['_dbmmodule.c'],
1458 define_macros=[
1459 ('HAVE_GDBM_NDBM_H', None),
1460 ],
1461 libraries = gdbm_libs)
1462 break
1463 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1464 if dbm_setup_debug: print("building dbm using gdbm")
1465 dbmext = Extension(
1466 '_dbm', ['_dbmmodule.c'],
1467 define_macros=[
1468 ('HAVE_GDBM_DASH_NDBM_H', None),
1469 ],
1470 libraries = gdbm_libs)
1471 break
1472 elif cand == "bdb":
1473 if dblibs:
1474 if dbm_setup_debug: print("building dbm using bdb")
1475 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1476 library_dirs=dblib_dir,
1477 runtime_library_dirs=dblib_dir,
1478 include_dirs=db_incs,
1479 define_macros=[
1480 ('HAVE_BERKDB_H', None),
1481 ('DB_DBM_HSEARCH', None),
1482 ],
1483 libraries=dblibs)
1484 break
1485 if dbmext is not None:
1486 self.add(dbmext)
1487 else:
1488 self.missing.append('_dbm')
1489
1490 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1491 if ('gdbm' in dbm_order and
1492 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1493 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1494 libraries=['gdbm']))
1495 else:
1496 self.missing.append('_gdbm')
1497
1498 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001499 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001500 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001501
1502 # We hunt for #define SQLITE_VERSION "n.n.n"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001503 sqlite_incdir = sqlite_libdir = None
1504 sqlite_inc_paths = [ '/usr/include',
1505 '/usr/include/sqlite',
1506 '/usr/include/sqlite3',
1507 '/usr/local/include',
1508 '/usr/local/include/sqlite',
1509 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001510 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001511 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001512 sqlite_inc_paths = []
Erlend Egeberg Aaslandcf0b2392021-01-06 01:02:43 +01001513 MIN_SQLITE_VERSION_NUMBER = (3, 7, 15) # Issue 40810
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001514 MIN_SQLITE_VERSION = ".".join([str(x)
1515 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001516
1517 # Scan the default include directories before the SQLite specific
1518 # ones. This allows one to override the copy of sqlite on OSX,
1519 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001520 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001521 sysroot = macosx_sdk_root()
1522
Victor Stinner625dbf22019-03-01 15:59:39 +01001523 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001524 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001525 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001526 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001527
Ned Deily9b635832012-08-05 15:13:33 -07001528 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001529 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001530 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001531 with open(f) as file:
1532 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001533 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001534 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001535 if m:
1536 sqlite_version = m.group(1)
1537 sqlite_version_tuple = tuple([int(x)
1538 for x in sqlite_version.split(".")])
1539 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1540 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001541 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001542 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001543 sqlite_incdir = d
1544 break
1545 else:
1546 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001547 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001548 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001549 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001550 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001551
1552 if sqlite_incdir:
1553 sqlite_dirs_to_check = [
1554 os.path.join(sqlite_incdir, '..', 'lib64'),
1555 os.path.join(sqlite_incdir, '..', 'lib'),
1556 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1557 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1558 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001559 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001560 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001561 if sqlite_libfile:
1562 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001563
1564 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001565 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001566 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001567 '_sqlite/cursor.c',
1568 '_sqlite/microprotocols.c',
1569 '_sqlite/module.c',
1570 '_sqlite/prepare_protocol.c',
1571 '_sqlite/row.c',
1572 '_sqlite/statement.c',
1573 '_sqlite/util.c', ]
1574
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001575 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001576 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001577 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1578 else:
1579 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1580
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
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001870 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Petr Viktorinc168b502020-12-08 17:36:53 +01001871 # Non-debug mode: Build xxlimited with limited API
Victor Stinnercfe172d2019-03-01 18:21:49 +01001872 self.add(Extension('xxlimited', ['xxlimited.c'],
Petr Viktorinc168b502020-12-08 17:36:53 +01001873 define_macros=[('Py_LIMITED_API', '0x03100000')]))
1874 self.add(Extension('xxlimited_35', ['xxlimited_35.c'],
Victor Stinnercfe172d2019-03-01 18:21:49 +01001875 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Petr Viktorinc168b502020-12-08 17:36:53 +01001876 else:
1877 # Debug mode: Build xxlimited with the full API
1878 # (which is compatible with the limited one)
1879 self.add(Extension('xxlimited', ['xxlimited.c']))
1880 self.add(Extension('xxlimited_35', ['xxlimited_35.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001881
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001882 def detect_tkinter_fromenv(self):
1883 # Build _tkinter using the Tcl/Tk locations specified by
1884 # the _TCLTK_INCLUDES and _TCLTK_LIBS environment variables.
1885 # This method is meant to be invoked by detect_tkinter().
Ned Deilyd819b932013-09-06 01:07:05 -07001886 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001887 # The variables can be set via one of the following ways.
Ned Deilyd819b932013-09-06 01:07:05 -07001888 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001889 # - Automatically, at configuration time, by using pkg-config.
1890 # The tool is called by the configure script.
1891 # Additional pkg-config configuration paths can be set via the
1892 # PKG_CONFIG_PATH environment variable.
1893 #
1894 # PKG_CONFIG_PATH=".../lib/pkgconfig" ./configure ...
1895 #
1896 # - Explicitly, at configuration time by setting both
1897 # --with-tcltk-includes and --with-tcltk-libs.
1898 #
1899 # ./configure ... \
Ned Deilyd819b932013-09-06 01:07:05 -07001900 # --with-tcltk-includes="-I/path/to/tclincludes \
1901 # -I/path/to/tkincludes"
1902 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1903 # -L/path/to/tklibs -ltkm.n"
1904 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001905 # - Explicitly, at compile time, by passing TCLTK_INCLUDES and
1906 # TCLTK_LIBS to the make target.
1907 # This will override any configuration-time option.
1908 #
1909 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
Ned Deilyd819b932013-09-06 01:07:05 -07001910 #
1911 # This can be useful for building and testing tkinter with multiple
1912 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1913 # build of Tcl so you need to specify both arguments and use care when
1914 # overriding.
1915
1916 # The _TCLTK variables are created in the Makefile sharedmods target.
1917 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1918 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1919 if not (tcltk_includes and tcltk_libs):
1920 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001921 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001922
1923 extra_compile_args = tcltk_includes.split()
1924 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001925 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1926 define_macros=[('WITH_APPINIT', 1)],
1927 extra_compile_args = extra_compile_args,
1928 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001929 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001930
Victor Stinner625dbf22019-03-01 15:59:39 +01001931 def detect_tkinter_darwin(self):
Ned Deily1731d6d2020-05-18 04:32:38 -04001932 # Build default _tkinter on macOS using Tcl and Tk frameworks.
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001933 # This method is meant to be invoked by detect_tkinter().
Ned Deily1731d6d2020-05-18 04:32:38 -04001934 #
1935 # The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
1936 # built and installed as macOS framework bundles. However,
1937 # for several reasons, we cannot take full advantage of the
1938 # Apple-supplied compiler chain's -framework options here.
1939 # Instead, we need to find and pass to the compiler the
1940 # absolute paths of the Tcl and Tk headers files we want to use
1941 # and the absolute path to the directory containing the Tcl
1942 # and Tk frameworks for linking.
1943 #
1944 # We want to handle here two common use cases on macOS:
1945 # 1. Build and link with system-wide third-party or user-built
1946 # Tcl and Tk frameworks installed in /Library/Frameworks.
1947 # 2. Build and link using a user-specified macOS SDK so that the
1948 # built Python can be exported to other systems. In this case,
1949 # search only the SDK's /Library/Frameworks (normally empty)
1950 # and /System/Library/Frameworks.
1951 #
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001952 # Any other use cases are handled either by detect_tkinter_fromenv(),
1953 # or detect_tkinter(). The former handles non-standard locations of
1954 # Tcl/Tk, defined via the _TCLTK_INCLUDES and _TCLTK_LIBS environment
1955 # variables. The latter handles any Tcl/Tk versions installed in
1956 # standard Unix directories.
1957 #
1958 # It would be desirable to also handle here the case where
Ned Deily1731d6d2020-05-18 04:32:38 -04001959 # you want to build and link with a framework build of Tcl and Tk
1960 # that is not in /Library/Frameworks, say, in your private
1961 # $HOME/Library/Frameworks directory or elsewhere. It turns
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301962 # out to be difficult to make that work automatically here
Ned Deily1731d6d2020-05-18 04:32:38 -04001963 # without bringing into play more tools and magic. That case
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301964 # can be handled using a recipe with the right arguments
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01001965 # to detect_tkinter_fromenv().
Ned Deily1731d6d2020-05-18 04:32:38 -04001966 #
1967 # Note also that the fallback case here is to try to use the
1968 # Apple-supplied Tcl and Tk frameworks in /System/Library but
1969 # be forewarned that they are deprecated by Apple and typically
1970 # out-of-date and buggy; their use should be avoided if at
1971 # all possible by installing a newer version of Tcl and Tk in
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301972 # /Library/Frameworks before building Python without
Ned Deily1731d6d2020-05-18 04:32:38 -04001973 # an explicit SDK or by configuring build arguments explicitly.
1974
Jack Jansen0b06be72002-06-21 14:48:38 +00001975 from os.path import join, exists
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001976
Ned Deily1731d6d2020-05-18 04:32:38 -04001977 sysroot = macosx_sdk_root() # path to the SDK or '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001978
Ned Deily1731d6d2020-05-18 04:32:38 -04001979 if macosx_sdk_specified():
1980 # Use case #2: an SDK other than '/' was specified.
1981 # Only search there.
1982 framework_dirs = [
1983 join(sysroot, 'Library', 'Frameworks'),
1984 join(sysroot, 'System', 'Library', 'Frameworks'),
1985 ]
1986 else:
1987 # Use case #1: no explicit SDK selected.
1988 # Search the local system-wide /Library/Frameworks,
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301989 # not the one in the default SDK, otherwise fall back to
Ned Deily1731d6d2020-05-18 04:32:38 -04001990 # /System/Library/Frameworks whose header files may be in
1991 # the default SDK or, on older systems, actually installed.
1992 framework_dirs = [
1993 join('/', 'Library', 'Frameworks'),
1994 join(sysroot, 'System', 'Library', 'Frameworks'),
1995 ]
1996
1997 # Find the directory that contains the Tcl.framework and
1998 # Tk.framework bundles.
Jack Jansen0b06be72002-06-21 14:48:38 +00001999 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00002000 # both Tcl.framework and Tk.framework should be present
Jack Jansen0b06be72002-06-21 14:48:38 +00002001 for fw in 'Tcl', 'Tk':
Ned Deily1731d6d2020-05-18 04:32:38 -04002002 if not exists(join(F, fw + '.framework')):
2003 break
Jack Jansen0b06be72002-06-21 14:48:38 +00002004 else:
Manan Kumar Garg619f9802020-10-05 02:58:43 +05302005 # ok, F is now directory with both frameworks. Continue
Jack Jansen0b06be72002-06-21 14:48:38 +00002006 # building
2007 break
2008 else:
2009 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
2010 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01002011 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00002012
Jack Jansen0b06be72002-06-21 14:48:38 +00002013 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00002014 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002015 for fw in ('Tcl', 'Tk')
Ned Deily1731d6d2020-05-18 04:32:38 -04002016 for H in ('Headers',)
Jack Jansen0b06be72002-06-21 14:48:38 +00002017 ]
2018
Ned Deily1731d6d2020-05-18 04:32:38 -04002019 # Add the base framework directory as well
2020 compile_args = ['-F', F]
Jack Jansen0b06be72002-06-21 14:48:38 +00002021
Ned Deily1731d6d2020-05-18 04:32:38 -04002022 # Do not build tkinter for archs that this Tk was not built with.
Georg Brandlfcaf9102008-07-16 02:17:56 +00002023 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04002024 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00002025
Ronald Oussorend097efe2009-09-15 19:07:58 +00002026 tmpfile = os.path.join(self.build_temp, 'tk.arch')
2027 if not os.path.exists(self.build_temp):
2028 os.makedirs(self.build_temp)
2029
Ned Deily1731d6d2020-05-18 04:32:38 -04002030 run_command(
2031 "file {}/Tk.framework/Tk | grep 'for architecture' > {}".format(F, tmpfile)
2032 )
Brett Cannon9f5db072010-10-29 20:19:27 +00002033 with open(tmpfile) as fp:
2034 detected_archs = []
2035 for ln in fp:
2036 a = ln.split()[-1]
2037 if a in archs:
2038 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00002039 os.unlink(tmpfile)
2040
Ned Deily1731d6d2020-05-18 04:32:38 -04002041 arch_args = []
Ronald Oussorend097efe2009-09-15 19:07:58 +00002042 for a in detected_archs:
Ned Deily1731d6d2020-05-18 04:32:38 -04002043 arch_args.append('-arch')
2044 arch_args.append(a)
2045
2046 compile_args += arch_args
2047 link_args = [','.join(['-Wl', '-F', F, '-framework', 'Tcl', '-framework', 'Tk']), *arch_args]
2048
2049 # The X11/xlib.h file bundled in the Tk sources can cause function
2050 # prototype warnings from the compiler. Since we cannot easily fix
2051 # that, suppress the warnings here instead.
2052 if '-Wstrict-prototypes' in cflags.split():
2053 compile_args.append('-Wno-strict-prototypes')
Georg Brandlfcaf9102008-07-16 02:17:56 +00002054
Victor Stinnercfe172d2019-03-01 18:21:49 +01002055 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2056 define_macros=[('WITH_APPINIT', 1)],
2057 include_dirs=include_dirs,
2058 libraries=[],
Ned Deily1731d6d2020-05-18 04:32:38 -04002059 extra_compile_args=compile_args,
2060 extra_link_args=link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01002061 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002062
Victor Stinner625dbf22019-03-01 15:59:39 +01002063 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002064 # The _tkinter module.
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01002065 #
2066 # Detection of Tcl/Tk is attempted in the following order:
2067 # - Through environment variables.
2068 # - Platform specific detection of Tcl/Tk (currently only macOS).
2069 # - Search of various standard Unix header/library paths.
2070 #
2071 # Detection stops at the first successful method.
Michael W. Hudson5b109102002-01-23 15:04:41 +00002072
Manolis Stamatogiannakisd2027942021-03-01 04:29:57 +01002073 # Check for Tcl and Tk at the locations indicated by _TCLTK_INCLUDES
2074 # and _TCLTK_LIBS environment variables.
2075 if self.detect_tkinter_fromenv():
Victor Stinner5ec33a12019-03-01 16:43:28 +01002076 return True
Ned Deilyd819b932013-09-06 01:07:05 -07002077
Jack Jansen0b06be72002-06-21 14:48:38 +00002078 # Rather than complicate the code below, detecting and building
2079 # AquaTk is a separate method. Only one Tkinter will be built on
2080 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01002081 if (MACOS and self.detect_tkinter_darwin()):
2082 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002083
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002084 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002085 # The versions with dots are used on Unix, and the versions without
2086 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002087 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00002088 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
2089 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01002090 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002091 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01002092 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002093 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00002094 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002095 # Exit the loop when we've found the Tcl/Tk libraries
2096 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002097
Fredrik Lundhade711a2001-01-24 08:00:28 +00002098 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002099 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002100 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002101 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002102 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01002103 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002104 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
2105 # but the include subdirs are named like .../include/tcl8.3.
2106 dotversion = dotversion[:-1] + '.' + dotversion[-1]
2107 tcl_include_sub = []
2108 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01002109 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002110 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
2111 tk_include_sub += [dir + os.sep + "tk" + dotversion]
2112 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01002113 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
2114 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002115
Martin v. Löwise86a59a2003-05-03 08:45:51 +00002116 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002117 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002118 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01002119 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00002120
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002121 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002122
Victor Stinnercfe172d2019-03-01 18:21:49 +01002123 include_dirs = []
2124 libs = []
2125 defs = []
2126 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002127 for dir in tcl_includes + tk_includes:
2128 if dir not in include_dirs:
2129 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002130
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002131 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01002132 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002133 include_dirs.append('/usr/openwin/include')
2134 added_lib_dirs.append('/usr/openwin/lib')
2135 elif os.path.exists('/usr/X11R6/include'):
2136 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00002137 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002138 added_lib_dirs.append('/usr/X11R6/lib')
2139 elif os.path.exists('/usr/X11R5/include'):
2140 include_dirs.append('/usr/X11R5/include')
2141 added_lib_dirs.append('/usr/X11R5/lib')
2142 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002143 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002144 include_dirs.append('/usr/X11/include')
2145 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002146
Jason Tishler9181c942003-02-05 15:16:17 +00002147 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01002148 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00002149 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
2150 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01002151 return False
Jason Tishler9181c942003-02-05 15:16:17 +00002152
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002153 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01002154 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002155 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002156 defs.append( ('WITH_BLT', 1) )
2157 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01002158 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002159 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00002160 defs.append( ('WITH_BLT', 1) )
2161 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002162
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002163 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00002164 libs.append('tk'+ version)
2165 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002166
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002167 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01002168 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002169 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002170
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002171 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002172 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002173 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002174 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002175 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002176 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002177 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002178
Victor Stinnercfe172d2019-03-01 18:21:49 +01002179 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2180 define_macros=[('WITH_APPINIT', 1)] + defs,
2181 include_dirs=include_dirs,
2182 libraries=libs,
2183 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002184 return True
2185
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002186 def configure_ctypes(self, ext):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002187 return True
2188
Victor Stinner625dbf22019-03-01 15:59:39 +01002189 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002190 # Thomas Heller's _ctypes module
Ronald Oussoren41761932020-11-08 10:05:27 +01002191
2192 if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
2193 self.use_system_libffi = True
2194 else:
2195 self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
2196
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002197 include_dirs = []
Victor Stinner1ae035b2020-04-17 17:47:20 +02002198 extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002199 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002200 sources = ['_ctypes/_ctypes.c',
2201 '_ctypes/callbacks.c',
2202 '_ctypes/callproc.c',
2203 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002204 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002205 depends = ['_ctypes/ctypes.h']
2206
Victor Stinner4cbea512019-02-28 17:48:38 +01002207 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002208 sources.append('_ctypes/malloc_closure.c')
Ronald Oussoren41761932020-11-08 10:05:27 +01002209 extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
Christian Heimes78644762008-03-04 23:39:23 +00002210 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002211 include_dirs.append('_ctypes/darwin')
Thomas Hellercf567c12006-03-08 19:51:58 +00002212
Victor Stinner4cbea512019-02-28 17:48:38 +01002213 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002214 # XXX This shouldn't be necessary; it appears that some
2215 # of the assembler code is non-PIC (i.e. it has relocations
2216 # when it shouldn't. The proper fix would be to rewrite
2217 # the assembler code to be PIC.
2218 # This only works with GCC; the Sun compiler likely refuses
2219 # this option. If you want to compile ctypes with the Sun
2220 # compiler, please research a proper solution, instead of
2221 # finding some -z option for the Sun compiler.
2222 extra_link_args.append('-mimpure-text')
2223
Victor Stinner4cbea512019-02-28 17:48:38 +01002224 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002225 extra_link_args.append('-fPIC')
2226
Thomas Hellercf567c12006-03-08 19:51:58 +00002227 ext = Extension('_ctypes',
2228 include_dirs=include_dirs,
2229 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002230 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002231 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002232 sources=sources,
2233 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002234 self.add(ext)
2235 if TEST_EXTENSIONS:
2236 # function my_sqrt() needs libm for sqrt()
2237 self.add(Extension('_ctypes_test',
2238 sources=['_ctypes/_ctypes_test.c'],
2239 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002240
Ronald Oussoren41761932020-11-08 10:05:27 +01002241 ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
2242 ffi_lib = None
2243
Victor Stinner625dbf22019-03-01 15:59:39 +01002244 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002245 if MACOS:
Ronald Oussoren41761932020-11-08 10:05:27 +01002246 ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
Christian Heimes78644762008-03-04 23:39:23 +00002247
Ronald Oussoren41761932020-11-08 10:05:27 +01002248 if not ffi_inc:
2249 if os.path.exists(ffi_in_sdk):
2250 ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
2251 ffi_inc = ffi_in_sdk
2252 ffi_lib = 'ffi'
2253 else:
2254 # OS X 10.5 comes with libffi.dylib; the include files are
2255 # in /usr/include/ffi
2256 ffi_inc_dirs.append('/usr/include/ffi')
2257
2258 if not ffi_inc:
2259 found = find_file('ffi.h', [], ffi_inc_dirs)
2260 if found:
2261 ffi_inc = found[0]
2262 if ffi_inc:
2263 ffi_h = ffi_inc + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002264 if not os.path.exists(ffi_h):
2265 ffi_inc = None
2266 print('Header file {} does not exist'.format(ffi_h))
Ronald Oussoren41761932020-11-08 10:05:27 +01002267 if ffi_lib is None and ffi_inc:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002268 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002269 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002270 ffi_lib = lib_name
2271 break
2272
2273 if ffi_inc and ffi_lib:
Ronald Oussoren41761932020-11-08 10:05:27 +01002274 ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
2275 if grep_headers_for('ffi_prep_cif_var', ffi_headers):
2276 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
2277 if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
2278 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
2279 if grep_headers_for('ffi_closure_alloc', ffi_headers):
2280 ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
2281
2282 ext.include_dirs.append(ffi_inc)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002283 ext.libraries.append(ffi_lib)
2284 self.use_system_libffi = True
2285
Christian Heimes5bb96922018-02-25 10:22:14 +01002286 if sysconfig.get_config_var('HAVE_LIBDL'):
2287 # for dlopen, see bpo-32647
2288 ext.libraries.append('dl')
2289
Victor Stinner5ec33a12019-03-01 16:43:28 +01002290 def detect_decimal(self):
2291 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002292 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002293 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002294 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2295 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002296 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002297 sources = ['_decimal/_decimal.c']
2298 depends = ['_decimal/docstrings.h']
2299 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002300 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002301 'Modules',
2302 '_decimal',
2303 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002304 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002305 sources = [
2306 '_decimal/_decimal.c',
2307 '_decimal/libmpdec/basearith.c',
2308 '_decimal/libmpdec/constants.c',
2309 '_decimal/libmpdec/context.c',
2310 '_decimal/libmpdec/convolute.c',
2311 '_decimal/libmpdec/crt.c',
2312 '_decimal/libmpdec/difradix2.c',
2313 '_decimal/libmpdec/fnt.c',
2314 '_decimal/libmpdec/fourstep.c',
2315 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002316 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002317 '_decimal/libmpdec/mpdecimal.c',
2318 '_decimal/libmpdec/numbertheory.c',
2319 '_decimal/libmpdec/sixstep.c',
2320 '_decimal/libmpdec/transpose.c',
2321 ]
2322 depends = [
2323 '_decimal/docstrings.h',
2324 '_decimal/libmpdec/basearith.h',
2325 '_decimal/libmpdec/bits.h',
2326 '_decimal/libmpdec/constants.h',
2327 '_decimal/libmpdec/convolute.h',
2328 '_decimal/libmpdec/crt.h',
2329 '_decimal/libmpdec/difradix2.h',
2330 '_decimal/libmpdec/fnt.h',
2331 '_decimal/libmpdec/fourstep.h',
2332 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002333 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002334 '_decimal/libmpdec/mpdecimal.h',
2335 '_decimal/libmpdec/numbertheory.h',
2336 '_decimal/libmpdec/sixstep.h',
2337 '_decimal/libmpdec/transpose.h',
2338 '_decimal/libmpdec/typearith.h',
2339 '_decimal/libmpdec/umodarith.h',
2340 ]
2341
Stefan Krah1919b7e2012-03-21 18:25:23 +01002342 config = {
2343 'x64': [('CONFIG_64','1'), ('ASM','1')],
2344 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2345 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2346 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2347 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2348 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2349 ('LEGACY_COMPILER','1')],
2350 'universal': [('UNIVERSAL','1')]
2351 }
2352
Stefan Krah1919b7e2012-03-21 18:25:23 +01002353 cc = sysconfig.get_config_var('CC')
2354 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2355 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2356
2357 if machine:
2358 # Override automatic configuration to facilitate testing.
2359 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002360 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002361 # Universal here means: build with the same options Python
2362 # was built with.
2363 define_macros = config['universal']
2364 elif sizeof_size_t == 8:
2365 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2366 define_macros = config['x64']
2367 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2368 define_macros = config['uint128']
2369 else:
2370 define_macros = config['ansi64']
2371 elif sizeof_size_t == 4:
2372 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2373 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002374 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002375 # solaris: problems with register allocation.
2376 # icc >= 11.0 works as well.
2377 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002378 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002379 else:
2380 define_macros = config['ansi32']
2381 else:
2382 raise DistutilsError("_decimal: unsupported architecture")
2383
2384 # Workarounds for toolchain bugs:
2385 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2386 # Some versions of gcc miscompile inline asm:
2387 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2388 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2389 extra_compile_args.append('-fno-ipa-pure-const')
2390 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2391 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2392 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2393 undef_macros.append('_FORTIFY_SOURCE')
2394
Stefan Krah1919b7e2012-03-21 18:25:23 +01002395 # Uncomment for extra functionality:
2396 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002397 self.add(Extension('_decimal',
2398 include_dirs=include_dirs,
2399 libraries=libraries,
2400 define_macros=define_macros,
2401 undef_macros=undef_macros,
2402 extra_compile_args=extra_compile_args,
2403 sources=sources,
2404 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002405
Victor Stinner5ec33a12019-03-01 16:43:28 +01002406 def detect_openssl_hashlib(self):
2407 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002408 config_vars = sysconfig.get_config_vars()
2409
2410 def split_var(name, sep):
2411 # poor man's shlex, the re module is not available yet.
2412 value = config_vars.get(name)
2413 if not value:
2414 return ()
2415 # This trick works because ax_check_openssl uses --libs-only-L,
2416 # --libs-only-l, and --cflags-only-I.
2417 value = ' ' + value
2418 sep = ' ' + sep
2419 return [v.strip() for v in value.split(sep) if v.strip()]
2420
2421 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2422 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2423 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2424 if not openssl_libs:
2425 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002426 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002427 return None, None
2428
2429 # Find OpenSSL includes
2430 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002431 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002432 )
2433 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002434 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002435 return None, None
2436
2437 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2438 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002439 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002440 ['/usr/kerberos/include']
2441 )
2442 if krb5_h:
2443 ssl_incs.extend(krb5_h)
2444
Christian Heimes61d478c2018-01-27 15:51:38 +01002445 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 11:44:05 +02002446 self.add(Extension(
2447 '_ssl', ['_ssl.c'],
2448 include_dirs=openssl_includes,
2449 library_dirs=openssl_libdirs,
2450 libraries=openssl_libs,
2451 depends=['socketmodule.h', '_ssl/debughelpers.c'])
2452 )
Christian Heimes61d478c2018-01-27 15:51:38 +01002453 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002454 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002455
Victor Stinner8058bda2019-03-01 15:31:45 +01002456 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2457 depends=['hashlib.h'],
2458 include_dirs=openssl_includes,
2459 library_dirs=openssl_libdirs,
2460 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002461
xdegaye2ee077f2019-04-09 17:20:08 +02002462 def detect_hash_builtins(self):
Christian Heimes9b60e552020-05-15 23:54:53 +02002463 # By default we always compile these even when OpenSSL is available
2464 # (issue #14693). It's harmless and the object code is tiny
2465 # (40-50 KiB per module, only loaded when actually used). Modules can
2466 # be disabled via the --with-builtin-hashlib-hashes configure flag.
2467 supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
Victor Stinner5ec33a12019-03-01 16:43:28 +01002468
Christian Heimes9b60e552020-05-15 23:54:53 +02002469 configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
2470 configured = configured.strip('"').lower()
2471 configured = {
2472 m.strip() for m in configured.split(",")
2473 }
Victor Stinner5ec33a12019-03-01 16:43:28 +01002474
Christian Heimes9b60e552020-05-15 23:54:53 +02002475 self.disabled_configure.extend(
2476 sorted(supported.difference(configured))
2477 )
Victor Stinner5ec33a12019-03-01 16:43:28 +01002478
Christian Heimes9b60e552020-05-15 23:54:53 +02002479 if "sha256" in configured:
2480 self.add(Extension(
2481 '_sha256', ['sha256module.c'],
2482 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2483 depends=['hashlib.h']
2484 ))
2485
2486 if "sha512" in configured:
2487 self.add(Extension(
2488 '_sha512', ['sha512module.c'],
2489 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2490 depends=['hashlib.h']
2491 ))
2492
2493 if "md5" in configured:
2494 self.add(Extension(
2495 '_md5', ['md5module.c'],
2496 depends=['hashlib.h']
2497 ))
2498
2499 if "sha1" in configured:
2500 self.add(Extension(
2501 '_sha1', ['sha1module.c'],
2502 depends=['hashlib.h']
2503 ))
2504
2505 if "blake2" in configured:
2506 blake2_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002507 os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002508 )
2509 blake2_deps.append('hashlib.h')
2510 self.add(Extension(
2511 '_blake2',
2512 [
2513 '_blake2/blake2module.c',
2514 '_blake2/blake2b_impl.c',
2515 '_blake2/blake2s_impl.c'
2516 ],
2517 depends=blake2_deps
2518 ))
2519
2520 if "sha3" in configured:
2521 sha3_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002522 os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002523 )
2524 sha3_deps.append('hashlib.h')
2525 self.add(Extension(
2526 '_sha3',
2527 ['_sha3/sha3module.c'],
2528 depends=sha3_deps
2529 ))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002530
2531 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002532 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002533 self.missing.append('nis')
2534 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002535
2536 libs = []
2537 library_dirs = []
2538 includes_dirs = []
2539
2540 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2541 # moved headers and libraries to libtirpc and libnsl. The headers
2542 # are in tircp and nsl sub directories.
2543 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002544 'rpcsvc/yp_prot.h', self.inc_dirs,
2545 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002546 )
2547 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002548 'rpc/rpc.h', self.inc_dirs,
2549 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002550 )
2551 if rpcsvc_inc is None or rpc_inc is None:
2552 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002553 self.missing.append('nis')
2554 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002555 includes_dirs.extend(rpcsvc_inc)
2556 includes_dirs.extend(rpc_inc)
2557
Victor Stinner625dbf22019-03-01 15:59:39 +01002558 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002559 libs.append('nsl')
2560 else:
2561 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002562 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002563 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2564 if libnsl is not None:
2565 library_dirs.append(os.path.dirname(libnsl))
2566 libs.append('nsl')
2567
Victor Stinner625dbf22019-03-01 15:59:39 +01002568 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002569 libs.append('tirpc')
2570
Victor Stinner8058bda2019-03-01 15:31:45 +01002571 self.add(Extension('nis', ['nismodule.c'],
2572 libraries=libs,
2573 library_dirs=library_dirs,
2574 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002575
Christian Heimesff5be6e2018-01-20 13:19:21 +01002576
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002577class PyBuildInstall(install):
2578 # Suppress the warning about installation into the lib_dynload
2579 # directory, which is not in sys.path when running Python during
2580 # installation:
2581 def initialize_options (self):
2582 install.initialize_options(self)
2583 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002584
Éric Araujoe6792c12011-06-09 14:07:02 +02002585 # Customize subcommands to not install an egg-info file for Python
2586 sub_commands = [('install_lib', install.has_lib),
2587 ('install_headers', install.has_headers),
2588 ('install_scripts', install.has_scripts),
2589 ('install_data', install.has_data)]
2590
2591
Michael W. Hudson529a5052002-12-17 16:47:17 +00002592class PyBuildInstallLib(install_lib):
2593 # Do exactly what install_lib does but make sure correct access modes get
2594 # set on installed directories and files. All installed files with get
2595 # mode 644 unless they are a shared library in which case they will get
2596 # mode 755. All installed directories will get mode 755.
2597
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002598 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2599 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002600
2601 def install(self):
2602 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002603 self.set_file_modes(outfiles, 0o644, 0o755)
2604 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002605 return outfiles
2606
2607 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002608 if not files: return
2609
2610 for filename in files:
2611 if os.path.islink(filename): continue
2612 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002613 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002614 log.info("changing mode of %s to %o", filename, mode)
2615 if not self.dry_run: os.chmod(filename, mode)
2616
2617 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002618 for dirpath, dirnames, fnames in os.walk(dirname):
2619 if os.path.islink(dirpath):
2620 continue
2621 log.info("changing mode of %s to %o", dirpath, mode)
2622 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002623
Victor Stinnerc991f242019-03-01 17:19:04 +01002624
Georg Brandlff52f762010-12-28 09:51:43 +00002625class PyBuildScripts(build_scripts):
2626 def copy_scripts(self):
2627 outfiles, updated_files = build_scripts.copy_scripts(self)
2628 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2629 minoronly = '.{0[1]}'.format(sys.version_info)
2630 newoutfiles = []
2631 newupdated_files = []
2632 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002633 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002634 newfilename = filename + fullversion
2635 else:
2636 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002637 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002638 os.rename(filename, newfilename)
2639 newoutfiles.append(newfilename)
2640 if filename in updated_files:
2641 newupdated_files.append(newfilename)
2642 return newoutfiles, newupdated_files
2643
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002644
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002645def main():
Victor Stinnercad80202021-01-19 23:04:49 +01002646 global LIST_MODULE_NAMES
2647
2648 if "--list-module-names" in sys.argv:
2649 LIST_MODULE_NAMES = True
2650 sys.argv.remove("--list-module-names")
2651
Victor Stinnerc991f242019-03-01 17:19:04 +01002652 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2653 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2654
2655 class DummyProcess:
2656 """Hack for parallel build"""
2657 ProcessPoolExecutor = None
2658
2659 sys.modules['concurrent.futures.process'] = DummyProcess
Paul Ganssle62972d92020-05-16 04:20:06 -04002660 validate_tzpath()
Victor Stinnerc991f242019-03-01 17:19:04 +01002661
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002662 # turn off warnings when deprecated modules are imported
2663 import warnings
2664 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002665 setup(# PyPI Metadata (PEP 301)
2666 name = "Python",
2667 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002668 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002669 maintainer = "Guido van Rossum and the Python community",
2670 maintainer_email = "python-dev@python.org",
2671 description = "A high-level object-oriented programming language",
2672 long_description = SUMMARY.strip(),
2673 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002674 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002675 platforms = ["Many"],
2676
2677 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002678 cmdclass = {'build_ext': PyBuildExt,
2679 'build_scripts': PyBuildScripts,
2680 'install': PyBuildInstall,
2681 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002682 # The struct module is defined here, because build_ext won't be
2683 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002684 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002685
Georg Brandlff52f762010-12-28 09:51:43 +00002686 # If you change the scripts installed here, you also need to
2687 # check the PyBuildScripts command above, and change the links
2688 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002689 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002690 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002691 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002692
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002693# --install-platlib
2694if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002695 main()