blob: b3f47603f7ad690a1b01ac1b1d6911f7bdd1dba9 [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
Michael W. Hudson529a5052002-12-17 16:47:17 +000012
Victor Stinner1ec63b62020-03-04 14:50:19 +010013
14try:
15 import subprocess
16 del subprocess
17 SUBPROCESS_BOOTSTRAP = False
18except ImportError:
Victor Stinner1ec63b62020-03-04 14:50:19 +010019 # Bootstrap Python: distutils.spawn uses subprocess to build C extensions,
20 # subprocess requires C extensions built by setup.py like _posixsubprocess.
21 #
Victor Stinneraddaaaa2020-03-09 23:45:59 +010022 # Use _bootsubprocess which only uses the os module.
Victor Stinner1ec63b62020-03-04 14:50:19 +010023 #
24 # It is dropped from sys.modules as soon as all C extension modules
25 # are built.
Victor Stinneraddaaaa2020-03-09 23:45:59 +010026 import _bootsubprocess
27 sys.modules['subprocess'] = _bootsubprocess
28 del _bootsubprocess
29 SUBPROCESS_BOOTSTRAP = True
Victor Stinner1ec63b62020-03-04 14:50:19 +010030
31
Michael W. Hudson529a5052002-12-17 16:47:17 +000032from distutils import log
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000033from distutils.command.build_ext import build_ext
Victor Stinner625dbf22019-03-01 15:59:39 +010034from distutils.command.build_scripts import build_scripts
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000035from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:17 +000036from distutils.command.install_lib import install_lib
Victor Stinner625dbf22019-03-01 15:59:39 +010037from distutils.core import Extension, setup
38from distutils.errors import CCompilerError, DistutilsError
Stefan Krah095b2732010-06-08 13:41:44 +000039from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000040
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020041
Victor Stinnercfe172d2019-03-01 18:21:49 +010042# Compile extensions used to test Python?
43TEST_EXTENSIONS = True
44
45# This global variable is used to hold the list of modules to be disabled.
46DISABLED_MODULE_LIST = []
47
48
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020049def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010050 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020051 if "_PYTHON_HOST_PLATFORM" in os.environ:
52 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010053
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020054 # Get value of sys.platform
55 if sys.platform.startswith('osf1'):
56 return 'osf1'
57 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010058
59
60CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010061HOST_PLATFORM = get_platform()
62MS_WINDOWS = (HOST_PLATFORM == 'win32')
63CYGWIN = (HOST_PLATFORM == 'cygwin')
64MACOS = (HOST_PLATFORM == 'darwin')
Michael Felt08970cb2019-06-21 15:58:00 +020065AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 17:48:38 +010066VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080067
Victor Stinnerc991f242019-03-01 17:19:04 +010068
69SUMMARY = """
70Python is an interpreted, interactive, object-oriented programming
71language. It is often compared to Tcl, Perl, Scheme or Java.
72
73Python combines remarkable power with very clear syntax. It has
74modules, classes, exceptions, very high level dynamic data types, and
75dynamic typing. There are interfaces to many system calls and
76libraries, as well as to various windowing systems (X11, Motif, Tk,
77Mac, MFC). New built-in modules are easily written in C or C++. Python
78is also usable as an extension language for applications that need a
79programmable interface.
80
81The Python implementation is portable: it runs on many brands of UNIX,
82on Windows, DOS, Mac, Amiga... If your favorite system isn't
83listed here, it may still be supported, if there's a C compiler for
84it. Ask around on comp.lang.python -- or just try compiling Python
85yourself.
86"""
87
88CLASSIFIERS = """
89Development Status :: 6 - Mature
90License :: OSI Approved :: Python Software Foundation License
91Natural Language :: English
92Programming Language :: C
93Programming Language :: Python
94Topic :: Software Development
95"""
96
97
Victor Stinner6b982c22020-04-01 01:10:07 +020098def run_command(cmd):
99 status = os.system(cmd)
Victor Stinner65a796e2020-04-01 18:49:29 +0200100 return os.waitstatus_to_exitcode(status)
Victor Stinner6b982c22020-04-01 01:10:07 +0200101
102
Victor Stinnerc991f242019-03-01 17:19:04 +0100103# Set common compiler and linker flags derived from the Makefile,
104# reserved for building the interpreter and the stdlib modules.
105# See bpo-21121 and bpo-35257
106def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
107 flags = sysconfig.get_config_var(compiler_flags)
108 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
109 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
110
111
Michael W. Hudson39230b32002-01-16 15:26:48 +0000112def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000113 """Add the directory 'dir' to the list 'dirlist' (after any relative
114 directories) if:
115
Michael W. Hudson39230b32002-01-16 15:26:48 +0000116 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000117 2) 'dir' actually exists, and is a directory.
118 """
119 if dir is None or not os.path.isdir(dir) or dir in dirlist:
120 return
121 for i, path in enumerate(dirlist):
122 if not os.path.isabs(path):
123 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000124 return
125 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000126
Victor Stinnerc991f242019-03-01 17:19:04 +0100127
xdegaye77f51392017-11-25 17:25:30 +0100128def sysroot_paths(make_vars, subdirs):
129 """Get the paths of sysroot sub-directories.
130
131 * make_vars: a sequence of names of variables of the Makefile where
132 sysroot may be set.
133 * subdirs: a sequence of names of subdirectories used as the location for
134 headers or libraries.
135 """
136
137 dirs = []
138 for var_name in make_vars:
139 var = sysconfig.get_config_var(var_name)
140 if var is not None:
141 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
142 if m is not None:
143 sysroot = m.group(1).strip('"')
144 for subdir in subdirs:
145 if os.path.isabs(subdir):
146 subdir = subdir[1:]
147 path = os.path.join(sysroot, subdir)
148 if os.path.isdir(path):
149 dirs.append(path)
150 break
151 return dirs
152
Ned Deily1731d6d2020-05-18 04:32:38 -0400153
Ned Deily0288dd62019-06-03 06:34:48 -0400154MACOS_SDK_ROOT = None
Ned Deily1731d6d2020-05-18 04:32:38 -0400155MACOS_SDK_SPECIFIED = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100156
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000157def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400158 """Return the directory of the current macOS SDK.
159
160 If no SDK was explicitly configured, call the compiler to find which
161 include files paths are being searched by default. Use '/' if the
162 compiler is searching /usr/include (meaning system header files are
163 installed) or use the root of an SDK if that is being searched.
164 (The SDK may be supplied via Xcode or via the Command Line Tools).
165 The SDK paths used by Apple-supplied tool chains depend on the
166 setting of various variables; see the xcrun man page for more info.
Ned Deily1731d6d2020-05-18 04:32:38 -0400167 Also sets MACOS_SDK_SPECIFIED for use by macosx_sdk_specified().
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000168 """
Ned Deily1731d6d2020-05-18 04:32:38 -0400169 global MACOS_SDK_ROOT, MACOS_SDK_SPECIFIED
Ned Deily0288dd62019-06-03 06:34:48 -0400170
171 # If already called, return cached result.
172 if MACOS_SDK_ROOT:
173 return MACOS_SDK_ROOT
174
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000175 cflags = sysconfig.get_config_var('CFLAGS')
Joshua Rootb3107002020-04-22 17:44:10 +1000176 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400177 if m is not None:
178 MACOS_SDK_ROOT = m.group(1)
Ned Deily1731d6d2020-05-18 04:32:38 -0400179 MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000180 else:
Ned Deily0288dd62019-06-03 06:34:48 -0400181 MACOS_SDK_ROOT = '/'
Ned Deily1731d6d2020-05-18 04:32:38 -0400182 MACOS_SDK_SPECIFIED = False
Ned Deily0288dd62019-06-03 06:34:48 -0400183 cc = sysconfig.get_config_var('CC')
184 tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid()
185 try:
186 os.unlink(tmpfile)
187 except:
188 pass
Victor Stinner6b982c22020-04-01 01:10:07 +0200189 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
Ned Deily0288dd62019-06-03 06:34:48 -0400190 in_incdirs = False
191 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200192 if ret == 0:
Ned Deily0288dd62019-06-03 06:34:48 -0400193 with open(tmpfile) as fp:
194 for line in fp.readlines():
195 if line.startswith("#include <...>"):
196 in_incdirs = True
197 elif line.startswith("End of search list"):
198 in_incdirs = False
199 elif in_incdirs:
200 line = line.strip()
201 if line == '/usr/include':
202 MACOS_SDK_ROOT = '/'
203 elif line.endswith(".sdk/usr/include"):
204 MACOS_SDK_ROOT = line[:-12]
205 finally:
206 os.unlink(tmpfile)
207
208 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000209
Victor Stinnerc991f242019-03-01 17:19:04 +0100210
Ned Deily1731d6d2020-05-18 04:32:38 -0400211def macosx_sdk_specified():
212 """Returns true if an SDK was explicitly configured.
213
214 True if an SDK was selected at configure time, either by specifying
215 --enable-universalsdk=(something other than no or /) or by adding a
216 -isysroot option to CFLAGS. In some cases, like when making
217 decisions about macOS Tk framework paths, we need to be able to
218 know whether the user explicitly asked to build with an SDK versus
219 the implicit use of an SDK when header files are no longer
220 installed on a running system by the Command Line Tools.
221 """
222 global MACOS_SDK_SPECIFIED
223
224 # If already called, return cached result.
225 if MACOS_SDK_SPECIFIED:
226 return MACOS_SDK_SPECIFIED
227
228 # Find the sdk root and set MACOS_SDK_SPECIFIED
229 macosx_sdk_root()
230 return MACOS_SDK_SPECIFIED
231
232
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000233def is_macosx_sdk_path(path):
234 """
235 Returns True if 'path' can be located in an OSX SDK
236 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700237 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
238 or path.startswith('/System/')
239 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000240
Victor Stinnerc991f242019-03-01 17:19:04 +0100241
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000242def find_file(filename, std_dirs, paths):
243 """Searches for the directory where a given file is located,
244 and returns a possibly-empty list of additional directories, or None
245 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000246
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000247 'filename' is the name of a file, such as readline.h or libcrypto.a.
248 'std_dirs' is the list of standard system directories; if the
249 file is found in one of them, no additional directives are needed.
250 'paths' is a list of additional locations to check; if the file is
251 found in one of them, the resulting list will contain the directory.
252 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100253 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000254 # Honor the MacOSX SDK setting when one was specified.
255 # An SDK is a directory with the same structure as a real
256 # system, but with only header files and libraries.
257 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000258
259 # Check the standard locations
260 for dir in std_dirs:
261 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000262
Victor Stinner4cbea512019-02-28 17:48:38 +0100263 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000264 f = os.path.join(sysroot, dir[1:], filename)
265
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000266 if os.path.exists(f): return []
267
268 # Check the additional directories
269 for dir in paths:
270 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000271
Victor Stinner4cbea512019-02-28 17:48:38 +0100272 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000273 f = os.path.join(sysroot, dir[1:], filename)
274
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000275 if os.path.exists(f):
276 return [dir]
277
278 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000279 return None
280
Victor Stinnerc991f242019-03-01 17:19:04 +0100281
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000282def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000283 result = compiler.find_library_file(std_dirs + paths, libname)
284 if result is None:
285 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000286
Victor Stinner4cbea512019-02-28 17:48:38 +0100287 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000288 sysroot = macosx_sdk_root()
289
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000290 # Check whether the found file is in one of the standard directories
291 dirname = os.path.dirname(result)
292 for p in std_dirs:
293 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000294 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000295
Victor Stinner4cbea512019-02-28 17:48:38 +0100296 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100297 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
298 # libraries with .tbd extensions rather than the normal .dylib
299 # shared libraries installed in /. The Apple compiler tool
300 # chain handles this transparently but it can cause problems
301 # for programs that are being built with an SDK and searching
302 # for specific libraries. Distutils find_library_file() now
303 # knows to also search for and return .tbd files. But callers
304 # of find_library_file need to keep in mind that the base filename
305 # of the returned SDK library file might have a different extension
306 # from that of the library file installed on the running system,
307 # for example:
308 # /Applications/Xcode.app/Contents/Developer/Platforms/
309 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
310 # usr/lib/libedit.tbd
311 # vs
312 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000313 if os.path.join(sysroot, p[1:]) == dirname:
314 return [ ]
315
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000316 if p == dirname:
317 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000318
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000319 # Otherwise, it must have been in one of the additional directories,
320 # so we have to figure out which one.
321 for p in paths:
322 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000323 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000324
Victor Stinner4cbea512019-02-28 17:48:38 +0100325 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000326 if os.path.join(sysroot, p[1:]) == dirname:
327 return [ p ]
328
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000329 if p == dirname:
330 return [p]
331 else:
332 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000333
Paul Ganssle62972d92020-05-16 04:20:06 -0400334def validate_tzpath():
335 base_tzpath = sysconfig.get_config_var('TZPATH')
336 if not base_tzpath:
337 return
338
339 tzpaths = base_tzpath.split(os.pathsep)
340 bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
341 if bad_paths:
342 raise ValueError('TZPATH must contain only absolute paths, '
343 + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
344 + f'{bad_paths!r}')
Victor Stinnerc991f242019-03-01 17:19:04 +0100345
Jack Jansen144ebcc2001-08-05 22:31:19 +0000346def find_module_file(module, dirlist):
347 """Find a module in a set of possible folders. If it is not found
348 return the unadorned filename"""
349 list = find_file(module, [], dirlist)
350 if not list:
351 return module
352 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100353 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000354 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000355
Victor Stinnerc991f242019-03-01 17:19:04 +0100356
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000357class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000358
Guido van Rossumd8faa362007-04-27 19:54:29 +0000359 def __init__(self, dist):
360 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100361 self.srcdir = None
362 self.lib_dirs = None
363 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100364 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000365 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400366 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100367 self.missing = []
Christian Heimes9b60e552020-05-15 23:54:53 +0200368 self.disabled_configure = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200369 if '-j' in os.environ.get('MAKEFLAGS', ''):
370 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000371
Victor Stinner8058bda2019-03-01 15:31:45 +0100372 def add(self, ext):
373 self.extensions.append(ext)
374
Victor Stinner00c77ae2020-03-04 18:44:49 +0100375 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100376 self.srcdir = sysconfig.get_config_var('srcdir')
377 if not self.srcdir:
378 # Maybe running on Windows but not using CYGWIN?
379 raise ValueError("No source directory; cannot proceed.")
380 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000381
Victor Stinner00c77ae2020-03-04 18:44:49 +0100382 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000383 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000384 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100385 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000386 # move ctypes to the end, it depends on other modules
387 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
388 if "_ctypes" in ext_map:
389 ctypes = extensions.pop(ext_map["_ctypes"])
390 extensions.append(ctypes)
391 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000392
Victor Stinner00c77ae2020-03-04 18:44:49 +0100393 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000394 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000395 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100396 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000397
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000398 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100399 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000400 for filename in self.distribution.scripts]
401
Christian Heimesaf98da12008-01-27 15:18:18 +0000402 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000403 headers = [sysconfig.get_config_h_filename()]
Serhiy Storchaka93558682020-06-20 11:10:31 +0300404 headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000405
Xavier de Gaye84968b72016-10-29 16:57:20 +0200406 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000407 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000408 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000409 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000410 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000411 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000412 else:
413 ext.depends = []
414 # re-compile extensions if a header file has been changed
415 ext.depends.extend(headers)
416
Victor Stinner00c77ae2020-03-04 18:44:49 +0100417 def remove_configured_extensions(self):
418 # The sysconfig variables built by makesetup that list the already
419 # built modules and the disabled modules as configured by the Setup
420 # files.
421 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
422 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
423
424 mods_built = []
425 mods_disabled = []
426 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200427 # If a module has already been built or has been disabled in the
428 # Setup files, don't build it here.
429 if ext.name in sysconf_built:
430 mods_built.append(ext)
431 if ext.name in sysconf_dis:
432 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000433
xdegayec0364fc2017-05-27 18:25:03 +0200434 mods_configured = mods_built + mods_disabled
435 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200436 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200437 mods_configured]
438 # Remove the shared libraries built by a previous build.
439 for ext in mods_configured:
440 fullpath = self.get_ext_fullpath(ext.name)
441 if os.path.exists(fullpath):
442 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000443
Victor Stinner00c77ae2020-03-04 18:44:49 +0100444 return (mods_built, mods_disabled)
445
446 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000447 # When you run "make CC=altcc" or something similar, you really want
448 # those environment variables passed into the setup.py phase. Here's
449 # a small set of useful ones.
450 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000451 args = {}
452 # unfortunately, distutils doesn't let us provide separate C and C++
453 # compilers
454 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000455 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
456 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000457 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000458
Victor Stinner00c77ae2020-03-04 18:44:49 +0100459 def build_extensions(self):
460 self.set_srcdir()
461
462 # Detect which modules should be compiled
463 self.detect_modules()
464
465 self.remove_disabled()
466
467 self.update_sources_depends()
468 mods_built, mods_disabled = self.remove_configured_extensions()
469 self.set_compiler_executables()
470
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000471 build_ext.build_extensions(self)
472
Victor Stinner1ec63b62020-03-04 14:50:19 +0100473 if SUBPROCESS_BOOTSTRAP:
474 # Drop our custom subprocess module:
475 # use the newly built subprocess module
476 del sys.modules['subprocess']
477
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200478 for ext in self.extensions:
479 self.check_extension_import(ext)
480
Victor Stinner00c77ae2020-03-04 18:44:49 +0100481 self.summary(mods_built, mods_disabled)
482
483 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300484 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400485 if self.failed or self.failed_on_import:
486 all_failed = self.failed + self.failed_on_import
487 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000488
489 def print_three_column(lst):
490 lst.sort(key=str.lower)
491 # guarantee zip() doesn't drop anything
492 while len(lst) % 3:
493 lst.append("")
494 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
495 print("%-*s %-*s %-*s" % (longest, e, longest, f,
496 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000497
Victor Stinner8058bda2019-03-01 15:31:45 +0100498 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000499 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400500 print("Python build finished successfully!")
501 print("The necessary bits to build these optional modules were not "
502 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100503 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000504 print("To find the necessary bits, look in setup.py in"
505 " detect_modules() for the module's name.")
506 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000507
xdegayec0364fc2017-05-27 18:25:03 +0200508 if mods_built:
509 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200510 print("The following modules found by detect_modules() in"
511 " setup.py, have been")
512 print("built by the Makefile instead, as configured by the"
513 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200514 print_three_column([ext.name for ext in mods_built])
515 print()
516
517 if mods_disabled:
518 print()
519 print("The following modules found by detect_modules() in"
520 " setup.py have not")
521 print("been built, they are *disabled* in the Setup files:")
522 print_three_column([ext.name for ext in mods_disabled])
523 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200524
Christian Heimes9b60e552020-05-15 23:54:53 +0200525 if self.disabled_configure:
526 print()
527 print("The following modules found by detect_modules() in"
528 " setup.py have not")
529 print("been built, they are *disabled* by configure:")
530 print_three_column(self.disabled_configure)
531 print()
532
Guido van Rossumd8faa362007-04-27 19:54:29 +0000533 if self.failed:
534 failed = self.failed[:]
535 print()
536 print("Failed to build these modules:")
537 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000538 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000539
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400540 if self.failed_on_import:
541 failed = self.failed_on_import[:]
542 print()
543 print("Following modules built successfully"
544 " but were removed because they could not be imported:")
545 print_three_column(failed)
546 print()
547
Christian Heimes61d478c2018-01-27 15:51:38 +0100548 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100549 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100550 print()
551 print("Could not build the ssl module!")
552 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
553 "libssl with X509_VERIFY_PARAM_set1_host().")
554 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
555 "APIs, https://github.com/libressl-portable/portable/issues/381")
556 print()
557
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000558 def build_extension(self, ext):
559
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000560 if ext.name == '_ctypes':
561 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500562 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000563 return
564
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000565 try:
566 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000567 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000568 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100569 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000570 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000571 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200572
573 def check_extension_import(self, ext):
574 # Don't try to import an extension that has failed to compile
575 if ext.name in self.failed:
576 self.announce(
577 'WARNING: skipping import check for failed build "%s"' %
578 ext.name, level=1)
579 return
580
Jack Jansenf49c6f92001-11-01 14:44:15 +0000581 # Workaround for Mac OS X: The Carbon-based modules cannot be
582 # reliably imported into a command-line Python
583 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000584 self.announce(
585 'WARNING: skipping import check for Carbon-based "%s"' %
586 ext.name)
587 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000588
Victor Stinner4cbea512019-02-28 17:48:38 +0100589 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000590 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000591 # Don't bother doing an import check when an extension was
592 # build with an explicit '-arch' flag on OSX. That's currently
593 # only used to build 32-bit only extensions in a 4-way
594 # universal build and loading 32-bit code into a 64-bit
595 # process will fail.
596 self.announce(
597 'WARNING: skipping import check for "%s"' %
598 ext.name)
599 return
600
Jason Tishler24cf7762002-05-22 16:46:15 +0000601 # Workaround for Cygwin: Cygwin currently has fork issues when many
602 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100603 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000604 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
605 % ext.name)
606 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000607 ext_filename = os.path.join(
608 self.build_lib,
609 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000610
611 # If the build directory didn't exist when setup.py was
612 # started, sys.path_importer_cache has a negative result
613 # cached. Clear that cache before trying to import.
614 sys.path_importer_cache.clear()
615
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200616 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100617 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200618 return
619
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400620 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700621 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
622 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000623 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400624 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000625 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400626 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000627 self.announce('*** WARNING: renaming "%s" since importing it'
628 ' failed: %s' % (ext.name, why), level=3)
629 assert not self.inplace
630 basename, tail = os.path.splitext(ext_filename)
631 newname = basename + "_failed" + tail
632 if os.path.exists(newname):
633 os.remove(newname)
634 os.rename(ext_filename, newname)
635
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000636 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000637 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000638 self.announce('*** WARNING: importing extension "%s" '
639 'failed with %s: %s' % (ext.name, exc_type, why),
640 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000641 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000642
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400643 def add_multiarch_paths(self):
644 # Debian/Ubuntu multiarch support.
645 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200646 cc = sysconfig.get_config_var('CC')
647 tmpfile = os.path.join(self.build_temp, 'multiarch')
648 if not os.path.exists(self.build_temp):
649 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200650 ret = run_command(
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200651 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
652 multiarch_path_component = ''
653 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200654 if ret == 0:
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200655 with open(tmpfile) as fp:
656 multiarch_path_component = fp.readline().strip()
657 finally:
658 os.unlink(tmpfile)
659
660 if multiarch_path_component != '':
661 add_dir_to_list(self.compiler.library_dirs,
662 '/usr/lib/' + multiarch_path_component)
663 add_dir_to_list(self.compiler.include_dirs,
664 '/usr/include/' + multiarch_path_component)
665 return
666
Barry Warsaw88e19452011-04-07 10:40:36 -0400667 if not find_executable('dpkg-architecture'):
668 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200669 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100670 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200671 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400672 tmpfile = os.path.join(self.build_temp, 'multiarch')
673 if not os.path.exists(self.build_temp):
674 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200675 ret = run_command(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200676 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
677 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400678 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200679 if ret == 0:
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400680 with open(tmpfile) as fp:
681 multiarch_path_component = fp.readline().strip()
682 add_dir_to_list(self.compiler.library_dirs,
683 '/usr/lib/' + multiarch_path_component)
684 add_dir_to_list(self.compiler.include_dirs,
685 '/usr/include/' + multiarch_path_component)
686 finally:
687 os.unlink(tmpfile)
688
pxinwr32f5fdd2019-02-27 19:09:28 +0800689 def add_cross_compiling_paths(self):
690 cc = sysconfig.get_config_var('CC')
691 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200692 if not os.path.exists(self.build_temp):
693 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200694 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200695 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800696 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200697 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200698 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200699 if ret == 0:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200700 with open(tmpfile) as fp:
701 for line in fp.readlines():
702 if line.startswith("gcc version"):
703 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800704 elif line.startswith("clang version"):
705 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200706 elif line.startswith("#include <...>"):
707 in_incdirs = True
708 elif line.startswith("End of search list"):
709 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800710 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200711 for d in line.strip().split("=")[1].split(":"):
712 d = os.path.normpath(d)
713 if '/gcc/' not in d:
714 add_dir_to_list(self.compiler.library_dirs,
715 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800716 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 +0200717 add_dir_to_list(self.compiler.include_dirs,
718 line.strip())
719 finally:
720 os.unlink(tmpfile)
721
Victor Stinnercfe172d2019-03-01 18:21:49 +0100722 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000723 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000724 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000725 # We must get the values from the Makefile and not the environment
726 # directly since an inconsistently reproducible issue comes up where
727 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000728 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000729 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000730 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
731 ('LDFLAGS', '-L', self.compiler.library_dirs),
732 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000733 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000734 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800735 parser = argparse.ArgumentParser()
736 parser.add_argument(arg_name, dest="dirs", action="append")
737 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000738 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000739 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000740 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000741
Victor Stinnercfe172d2019-03-01 18:21:49 +0100742 def configure_compiler(self):
743 # Ensure that /usr/local is always used, but the local build
744 # directories (i.e. '.' and 'Include') must be first. See issue
745 # 10520.
746 if not CROSS_COMPILING:
747 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
748 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
749 # only change this for cross builds for 3.3, issues on Mageia
750 if CROSS_COMPILING:
751 self.add_cross_compiling_paths()
752 self.add_multiarch_paths()
753 self.add_ldflags_cppflags()
754
Victor Stinner5ec33a12019-03-01 16:43:28 +0100755 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100756 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100757 os.path.normpath(sys.base_prefix) != '/usr' and
758 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000759 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
760 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
761 # building a framework with different architectures than
762 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000763 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000764 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000765 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000766 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000767
xdegaye77f51392017-11-25 17:25:30 +0100768 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
769 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000770 # lib_dirs and inc_dirs are used to search for files;
771 # if a file is found in one of those directories, it can
772 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100773 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100774 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
775 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100776 else:
xdegaye77f51392017-11-25 17:25:30 +0100777 # Add the sysroot paths. 'sysroot' is a compiler option used to
778 # set the logical path of the standard system headers and
779 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100780 self.lib_dirs = (self.compiler.library_dirs +
781 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
782 self.inc_dirs = (self.compiler.include_dirs +
783 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
784 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000785
Brett Cannon4454a1f2005-04-15 20:32:39 +0000786 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000787 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100788 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000789
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000790 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100791 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100792 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000793
Charles-François Natali5739e102012-04-12 19:07:25 +0200794 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100795 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100796 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200797
Victor Stinner4cbea512019-02-28 17:48:38 +0100798 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000799 # This should work on any unixy platform ;-)
800 # If the user has bothered specifying additional -I and -L flags
801 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000802 #
803 # NOTE: using shlex.split would technically be more correct, but
804 # also gives a bootstrap problem. Let's hope nobody uses
805 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000806 cflags, ldflags = sysconfig.get_config_vars(
807 'CFLAGS', 'LDFLAGS')
808 for item in cflags.split():
809 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100810 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000811
812 for item in ldflags.split():
813 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100814 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000815
Victor Stinner5ec33a12019-03-01 16:43:28 +0100816 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000817 #
818 # The following modules are all pretty straightforward, and compile
819 # on pretty much any POSIXish platform.
820 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000821
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000822 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100823 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000824
Yury Selivanovf23746a2018-01-22 19:11:18 -0500825 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100826 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500827
Martin Panterc9deece2016-02-03 05:19:44 +0000828 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100829
830 # math library functions, e.g. sin()
831 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100832 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100833 extra_objects=[shared_math],
834 depends=['_math.h', shared_math],
835 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100836
837 # complex math library functions
838 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100839 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100840 extra_objects=[shared_math],
841 depends=['_math.h', shared_math],
842 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200843
844 # time libraries: librt may be needed for clock_gettime()
845 time_libs = []
846 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
847 if lib:
848 time_libs.append(lib)
849
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000850 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100851 self.add(Extension('time', ['timemodule.c'],
852 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800853 # libm is needed by delta_new() that uses round() and by accum() that
854 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100855 self.add(Extension('_datetime', ['_datetimemodule.c'],
Victor Stinner04fc4f22020-06-16 01:28:07 +0200856 libraries=['m'],
857 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Paul Ganssle62972d92020-05-16 04:20:06 -0400858 # zoneinfo module
Victor Stinner37834132020-10-27 17:12:53 +0100859 self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
860 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000861 # random number generator implemented in C
Victor Stinner9f5fe792020-04-17 19:05:35 +0200862 self.add(Extension("_random", ["_randommodule.c"],
863 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000864 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100865 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000866 # heapq
Victor Stinnerc45dbe932020-06-22 17:39:32 +0200867 self.add(Extension("_heapq", ["_heapqmodule.c"],
868 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000869 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200870 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200871 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Collin Winter670e6922007-03-21 02:57:17 +0000872 # atexit
Victor Stinner8058bda2019-03-01 15:31:45 +0100873 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10 +0000874 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100875 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200876 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100877
Fred Drake0e474a82007-10-11 18:01:43 +0000878 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100879 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000880 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100881 self.add(Extension('unicodedata', ['unicodedata.c'],
Victor Stinner47e1afd2020-10-26 16:43:47 +0100882 depends=['unicodedata_db.h', 'unicodename_db.h'],
883 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Larry Hastings3a907972013-11-23 14:49:22 -0800884 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100885 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900886 # asyncio speedups
Chris Jerdonekda742ba2020-05-17 22:47:31 -0700887 self.add(Extension("_asyncio", ["_asynciomodule.c"],
888 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000889 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100890 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100891 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100892 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900893 # _statistics module
894 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000895
896 # Modules with some UNIX dependencies -- on by default:
897 # (If you have a really backward UNIX, select and socket may not be
898 # supported...)
899
900 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000901 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100902 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000903 # May be necessary on AIX for flock function
904 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100905 self.add(Extension('fcntl', ['fcntlmodule.c'],
906 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000907 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100908 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000909 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800910 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100911 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000912 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100913 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
914 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100915 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200916 # AIX has shadow passwords, but access is not via getspent(), etc.
917 # module support is not expected so it not 'missing'
918 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100919 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000920
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000921 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100922 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000923
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000924 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100925 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000926
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000927 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000928 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100929 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000930
Eric Snow7f8bfc92018-01-29 18:23:44 -0700931 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600932 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700933
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000934 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000935 # Here ends the simple stuff. From here on, modules need certain
936 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000937 #
938
939 # Multimedia modules
940 # These don't work for 64-bit platforms!!!
941 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200942 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000943 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000944 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000945 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200946 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800947 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100948 self.add(Extension('audioop', ['audioop.c'],
949 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000950
Victor Stinner5ec33a12019-03-01 16:43:28 +0100951 # CSV files
952 self.add(Extension('_csv', ['_csv.c']))
953
954 # POSIX subprocess module helper.
Kyle Evans79925792020-10-13 15:04:44 -0500955 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
956 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner5ec33a12019-03-01 16:43:28 +0100957
Victor Stinnercfe172d2019-03-01 18:21:49 +0100958 def detect_test_extensions(self):
959 # Python C API test module
960 self.add(Extension('_testcapi', ['_testcapimodule.c'],
961 depends=['testcapi_long.h']))
962
Victor Stinner23bace22019-04-18 11:37:26 +0200963 # Python Internal C API test module
964 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +0200965 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +0200966
Victor Stinnercfe172d2019-03-01 18:21:49 +0100967 # Python PEP-3118 (buffer protocol) test module
968 self.add(Extension('_testbuffer', ['_testbuffer.c']))
969
970 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
971 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
972
973 # Test multi-phase extension module init (PEP 489)
974 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
975
976 # Fuzz tests.
977 self.add(Extension('_xxtestfuzz',
978 ['_xxtestfuzz/_xxtestfuzz.c',
979 '_xxtestfuzz/fuzzer.c']))
980
Victor Stinner5ec33a12019-03-01 16:43:28 +0100981 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000982 # readline
Victor Stinner625dbf22019-03-01 15:59:39 +0100983 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000984 readline_termcap_library = ""
985 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200986 # Cannot use os.popen here in py3k.
987 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
988 if not os.path.exists(self.build_temp):
989 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000990 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200991 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100992 if CROSS_COMPILING:
Victor Stinner6b982c22020-04-01 01:10:07 +0200993 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
doko@ubuntu.com58844492012-06-30 18:25:32 +0200994 % (sysconfig.get_config_var('READELF'),
995 do_readline, tmpfile))
996 elif find_executable('ldd'):
Victor Stinner6b982c22020-04-01 01:10:07 +0200997 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
doko@ubuntu.com58844492012-06-30 18:25:32 +0200998 else:
Victor Stinner6b982c22020-04-01 01:10:07 +0200999 ret = 1
1000 if ret == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +00001001 with open(tmpfile) as fp:
1002 for ln in fp:
1003 if 'curses' in ln:
1004 readline_termcap_library = re.sub(
1005 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
1006 ).rstrip()
1007 break
1008 # termcap interface split out from ncurses
1009 if 'tinfo' in ln:
1010 readline_termcap_library = 'tinfo'
1011 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +02001012 if os.path.exists(tmpfile):
1013 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +00001014 # Issue 7384: If readline is already linked against curses,
1015 # use the same library for the readline and curses modules.
1016 if 'curses' in readline_termcap_library:
1017 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +01001018 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +00001019 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +02001020 # Issue 36210: OSS provided ncurses does not link on AIX
1021 # Use IBM supplied 'curses' for successful build of _curses
1022 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
1023 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001024 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001025 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001026 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001027 curses_library = 'curses'
1028
Victor Stinner4cbea512019-02-28 17:48:38 +01001029 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001030 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +00001031 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -07001032 if (dep_target and
1033 (tuple(int(n) for n in dep_target.split('.')[0:2])
1034 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +00001035 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001036 if os_release < 9:
1037 # MacOSX 10.4 has a broken readline. Don't try to build
1038 # the readline module unless the user has installed a fixed
1039 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +01001040 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001041 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +00001042 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +01001043 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001044 # In every directory on the search path search for a dynamic
1045 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +00001046 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +00001047 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001048 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +00001049 readline_extra_link_args = ('-Wl,-search_paths_first',)
1050 else:
1051 readline_extra_link_args = ()
1052
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001053 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +00001054 if readline_termcap_library:
1055 pass # Issue 7384: Already linked against curses or tinfo.
1056 elif curses_library:
1057 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001058 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001059 ['/usr/lib/termcap'],
1060 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001061 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001062 self.add(Extension('readline', ['readline.c'],
1063 library_dirs=['/usr/lib/termcap'],
1064 extra_link_args=readline_extra_link_args,
1065 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001066 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001067 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001068
Victor Stinner5ec33a12019-03-01 16:43:28 +01001069 # Curses support, requiring the System V version of curses, often
1070 # provided by the ncurses library.
1071 curses_defines = []
1072 curses_includes = []
1073 panel_library = 'panel'
1074 if curses_library == 'ncursesw':
1075 curses_defines.append(('HAVE_NCURSESW', '1'))
1076 if not CROSS_COMPILING:
1077 curses_includes.append('/usr/include/ncursesw')
1078 # Bug 1464056: If _curses.so links with ncursesw,
1079 # _curses_panel.so must link with panelw.
1080 panel_library = 'panelw'
1081 if MACOS:
1082 # On OS X, there is no separate /usr/lib/libncursesw nor
1083 # libpanelw. If we are here, we found a locally-supplied
1084 # version of libncursesw. There should also be a
1085 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1086 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1087 # ncurses wide char support
1088 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1089 elif MACOS and curses_library == 'ncurses':
1090 # Building with the system-suppied combined libncurses/libpanel
1091 curses_defines.append(('HAVE_NCURSESW', '1'))
1092 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001093
Victor Stinnercfe172d2019-03-01 18:21:49 +01001094 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001095 if curses_library.startswith('ncurses'):
1096 curses_libs = [curses_library]
1097 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001098 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001099 include_dirs=curses_includes,
1100 define_macros=curses_defines,
1101 libraries=curses_libs))
1102 elif curses_library == 'curses' and not MACOS:
1103 # OSX has an old Berkeley curses, not good enough for
1104 # the _curses module.
1105 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1106 curses_libs = ['curses', 'terminfo']
1107 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1108 curses_libs = ['curses', 'termcap']
1109 else:
1110 curses_libs = ['curses']
1111
1112 self.add(Extension('_curses', ['_cursesmodule.c'],
Victor Stinner37834132020-10-27 17:12:53 +01001113 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001114 define_macros=curses_defines,
1115 libraries=curses_libs))
1116 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001117 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001118 self.missing.append('_curses')
1119
1120 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001121 # _curses_panel needs some form of ncurses
1122 skip_curses_panel = True if AIX else False
1123 if (curses_enabled and not skip_curses_panel and
1124 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001125 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001126 include_dirs=curses_includes,
1127 define_macros=curses_defines,
1128 libraries=[panel_library, *curses_libs]))
1129 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001130 self.missing.append('_curses_panel')
1131
1132 def detect_crypt(self):
1133 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001134 if VXWORKS:
1135 # bpo-31904: crypt() function is not provided by VxWorks.
1136 # DES_crypt() OpenSSL provides is too weak to implement
1137 # the encryption.
1138 return
1139
Victor Stinner625dbf22019-03-01 15:59:39 +01001140 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001141 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001142 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001143 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001144
pxinwr236d0b72019-04-15 17:02:20 +08001145 self.add(Extension('_crypt', ['_cryptmodule.c'],
Victor Stinner8058bda2019-03-01 15:31:45 +01001146 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001147
Victor Stinner5ec33a12019-03-01 16:43:28 +01001148 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001149 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +08001150 if not VXWORKS:
Erlend Egeberg Aasland9a45bfe2020-05-17 08:32:46 +02001151 kwargs = {'depends': ['socketmodule.h']}
1152 if MACOS:
1153 # Issue #35569: Expose RFC 3542 socket options.
1154 kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542']
1155
1156 self.add(Extension('_socket', ['socketmodule.c'], **kwargs))
Victor Stinner625dbf22019-03-01 15:59:39 +01001157 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 19:09:28 +08001158 libs = ['net']
Victor Stinner8058bda2019-03-01 15:31:45 +01001159 self.add(Extension('_socket', ['socketmodule.c'],
1160 depends=['socketmodule.h'],
1161 libraries=libs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001162
Victor Stinner5ec33a12019-03-01 16:43:28 +01001163 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001164 # Modules that provide persistent dictionary-like semantics. You will
1165 # probably want to arrange for at least one of them to be available on
1166 # your machine, though none are defined by default because of library
1167 # dependencies. The Python module dbm/__init__.py provides an
1168 # implementation independent wrapper for these; dbm/dumb.py provides
1169 # similar functionality (but slower of course) implemented in Python.
1170
1171 # Sleepycat^WOracle Berkeley DB interface.
1172 # http://www.oracle.com/database/berkeley-db/db/index.html
1173 #
1174 # This requires the Sleepycat^WOracle DB code. The supported versions
1175 # are set below. Visit the URL above to download
1176 # a release. Most open source OSes come with one or more
1177 # versions of BerkeleyDB already installed.
1178
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001179 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001180 min_db_ver = (3, 3)
1181 db_setup_debug = False # verbose debug prints from this script?
1182
1183 def allow_db_ver(db_ver):
1184 """Returns a boolean if the given BerkeleyDB version is acceptable.
1185
1186 Args:
1187 db_ver: A tuple of the version to verify.
1188 """
1189 if not (min_db_ver <= db_ver <= max_db_ver):
1190 return False
1191 return True
1192
1193 def gen_db_minor_ver_nums(major):
1194 if major == 4:
1195 for x in range(max_db_ver[1]+1):
1196 if allow_db_ver((4, x)):
1197 yield x
1198 elif major == 3:
1199 for x in (3,):
1200 if allow_db_ver((3, x)):
1201 yield x
1202 else:
1203 raise ValueError("unknown major BerkeleyDB version", major)
1204
1205 # construct a list of paths to look for the header file in on
1206 # top of the normal inc_dirs.
1207 db_inc_paths = [
1208 '/usr/include/db4',
1209 '/usr/local/include/db4',
1210 '/opt/sfw/include/db4',
1211 '/usr/include/db3',
1212 '/usr/local/include/db3',
1213 '/opt/sfw/include/db3',
1214 # Fink defaults (http://fink.sourceforge.net/)
1215 '/sw/include/db4',
1216 '/sw/include/db3',
1217 ]
1218 # 4.x minor number specific paths
1219 for x in gen_db_minor_ver_nums(4):
1220 db_inc_paths.append('/usr/include/db4%d' % x)
1221 db_inc_paths.append('/usr/include/db4.%d' % x)
1222 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1223 db_inc_paths.append('/usr/local/include/db4%d' % x)
1224 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1225 db_inc_paths.append('/opt/db-4.%d/include' % x)
1226 # MacPorts default (http://www.macports.org/)
1227 db_inc_paths.append('/opt/local/include/db4%d' % x)
1228 # 3.x minor number specific paths
1229 for x in gen_db_minor_ver_nums(3):
1230 db_inc_paths.append('/usr/include/db3%d' % x)
1231 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1232 db_inc_paths.append('/usr/local/include/db3%d' % x)
1233 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1234 db_inc_paths.append('/opt/db-3.%d/include' % x)
1235
Victor Stinner4cbea512019-02-28 17:48:38 +01001236 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001237 db_inc_paths = []
1238
Georg Brandl489cb4f2009-07-11 10:08:49 +00001239 # Add some common subdirectories for Sleepycat DB to the list,
1240 # based on the standard include directories. This way DB3/4 gets
1241 # picked up when it is installed in a non-standard prefix and
1242 # the user has added that prefix into inc_dirs.
1243 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001244 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001245 std_variants.append(os.path.join(dn, 'db3'))
1246 std_variants.append(os.path.join(dn, 'db4'))
1247 for x in gen_db_minor_ver_nums(4):
1248 std_variants.append(os.path.join(dn, "db4%d"%x))
1249 std_variants.append(os.path.join(dn, "db4.%d"%x))
1250 for x in gen_db_minor_ver_nums(3):
1251 std_variants.append(os.path.join(dn, "db3%d"%x))
1252 std_variants.append(os.path.join(dn, "db3.%d"%x))
1253
1254 db_inc_paths = std_variants + db_inc_paths
1255 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1256
1257 db_ver_inc_map = {}
1258
Victor Stinner4cbea512019-02-28 17:48:38 +01001259 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001260 sysroot = macosx_sdk_root()
1261
Georg Brandl489cb4f2009-07-11 10:08:49 +00001262 class db_found(Exception): pass
1263 try:
1264 # See whether there is a Sleepycat header in the standard
1265 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001266 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001267 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001268 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001269 f = os.path.join(sysroot, d[1:], "db.h")
1270
Georg Brandl489cb4f2009-07-11 10:08:49 +00001271 if db_setup_debug: print("db: looking for db.h in", f)
1272 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001273 with open(f, 'rb') as file:
1274 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001275 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001276 if m:
1277 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001278 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001279 db_minor = int(m.group(1))
1280 db_ver = (db_major, db_minor)
1281
1282 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1283 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001284 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001285 db_patch = int(m.group(1))
1286 if db_patch < 21:
1287 print("db.h:", db_ver, "patch", db_patch,
1288 "being ignored (4.6.x must be >= 4.6.21)")
1289 continue
1290
1291 if ( (db_ver not in db_ver_inc_map) and
1292 allow_db_ver(db_ver) ):
1293 # save the include directory with the db.h version
1294 # (first occurrence only)
1295 db_ver_inc_map[db_ver] = d
1296 if db_setup_debug:
1297 print("db.h: found", db_ver, "in", d)
1298 else:
1299 # we already found a header for this library version
1300 if db_setup_debug: print("db.h: ignoring", d)
1301 else:
1302 # ignore this header, it didn't contain a version number
1303 if db_setup_debug:
1304 print("db.h: no version number version in", d)
1305
1306 db_found_vers = list(db_ver_inc_map.keys())
1307 db_found_vers.sort()
1308
1309 while db_found_vers:
1310 db_ver = db_found_vers.pop()
1311 db_incdir = db_ver_inc_map[db_ver]
1312
1313 # check lib directories parallel to the location of the header
1314 db_dirs_to_check = [
1315 db_incdir.replace("include", 'lib64'),
1316 db_incdir.replace("include", 'lib'),
1317 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001318
Victor Stinner4cbea512019-02-28 17:48:38 +01001319 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001320 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1321
1322 else:
1323 # Same as other branch, but takes OSX SDK into account
1324 tmp = []
1325 for dn in db_dirs_to_check:
1326 if is_macosx_sdk_path(dn):
1327 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1328 tmp.append(dn)
1329 else:
1330 if os.path.isdir(dn):
1331 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001332 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001333
1334 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001335
Ezio Melotti42da6632011-03-15 05:18:48 +02001336 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001337 # XXX should we -ever- look for a dbX name? Do any
1338 # systems really not name their library by version and
1339 # symlink to more general names?
1340 for dblib in (('db-%d.%d' % db_ver),
1341 ('db%d%d' % db_ver),
1342 ('db%d' % db_ver[0])):
1343 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001344 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001345 if dblib_file:
1346 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1347 raise db_found
1348 else:
1349 if db_setup_debug: print("db lib: ", dblib, "not found")
1350
1351 except db_found:
1352 if db_setup_debug:
1353 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1354 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001355 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001356 # Only add the found library and include directories if they aren't
1357 # already being searched. This avoids an explicit runtime library
1358 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001359 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001360 db_incs = None
1361 else:
1362 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001363 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001364 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001365 else:
1366 if db_setup_debug: print("db: no appropriate library found")
1367 db_incs = None
1368 dblibs = []
1369 dblib_dir = None
1370
Victor Stinner5ec33a12019-03-01 16:43:28 +01001371 dbm_setup_debug = False # verbose debug prints from this script?
1372 dbm_order = ['gdbm']
1373 # The standard Unix dbm module:
1374 if not CYGWIN:
1375 config_args = [arg.strip("'")
1376 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1377 dbm_args = [arg for arg in config_args
1378 if arg.startswith('--with-dbmliborder=')]
1379 if dbm_args:
1380 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1381 else:
1382 dbm_order = "ndbm:gdbm:bdb".split(":")
1383 dbmext = None
1384 for cand in dbm_order:
1385 if cand == "ndbm":
1386 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1387 # Some systems have -lndbm, others have -lgdbm_compat,
1388 # others don't have either
1389 if self.compiler.find_library_file(self.lib_dirs,
1390 'ndbm'):
1391 ndbm_libs = ['ndbm']
1392 elif self.compiler.find_library_file(self.lib_dirs,
1393 'gdbm_compat'):
1394 ndbm_libs = ['gdbm_compat']
1395 else:
1396 ndbm_libs = []
1397 if dbm_setup_debug: print("building dbm using ndbm")
1398 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1399 define_macros=[
1400 ('HAVE_NDBM_H',None),
1401 ],
1402 libraries=ndbm_libs)
1403 break
1404
1405 elif cand == "gdbm":
1406 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1407 gdbm_libs = ['gdbm']
1408 if self.compiler.find_library_file(self.lib_dirs,
1409 'gdbm_compat'):
1410 gdbm_libs.append('gdbm_compat')
1411 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1412 if dbm_setup_debug: print("building dbm using gdbm")
1413 dbmext = Extension(
1414 '_dbm', ['_dbmmodule.c'],
1415 define_macros=[
1416 ('HAVE_GDBM_NDBM_H', None),
1417 ],
1418 libraries = gdbm_libs)
1419 break
1420 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1421 if dbm_setup_debug: print("building dbm using gdbm")
1422 dbmext = Extension(
1423 '_dbm', ['_dbmmodule.c'],
1424 define_macros=[
1425 ('HAVE_GDBM_DASH_NDBM_H', None),
1426 ],
1427 libraries = gdbm_libs)
1428 break
1429 elif cand == "bdb":
1430 if dblibs:
1431 if dbm_setup_debug: print("building dbm using bdb")
1432 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1433 library_dirs=dblib_dir,
1434 runtime_library_dirs=dblib_dir,
1435 include_dirs=db_incs,
1436 define_macros=[
1437 ('HAVE_BERKDB_H', None),
1438 ('DB_DBM_HSEARCH', None),
1439 ],
1440 libraries=dblibs)
1441 break
1442 if dbmext is not None:
1443 self.add(dbmext)
1444 else:
1445 self.missing.append('_dbm')
1446
1447 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1448 if ('gdbm' in dbm_order and
1449 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1450 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1451 libraries=['gdbm']))
1452 else:
1453 self.missing.append('_gdbm')
1454
1455 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001456 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001457 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001458
1459 # We hunt for #define SQLITE_VERSION "n.n.n"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001460 sqlite_incdir = sqlite_libdir = None
1461 sqlite_inc_paths = [ '/usr/include',
1462 '/usr/include/sqlite',
1463 '/usr/include/sqlite3',
1464 '/usr/local/include',
1465 '/usr/local/include/sqlite',
1466 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001467 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001468 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001469 sqlite_inc_paths = []
Erlend Egeberg Aasland207c3212020-09-07 23:26:54 +02001470 # We need to find >= sqlite version 3.7.3, for sqlite3_create_function_v2()
1471 MIN_SQLITE_VERSION_NUMBER = (3, 7, 3)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001472 MIN_SQLITE_VERSION = ".".join([str(x)
1473 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001474
1475 # Scan the default include directories before the SQLite specific
1476 # ones. This allows one to override the copy of sqlite on OSX,
1477 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001478 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001479 sysroot = macosx_sdk_root()
1480
Victor Stinner625dbf22019-03-01 15:59:39 +01001481 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001482 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001483 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001484 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001485
Ned Deily9b635832012-08-05 15:13:33 -07001486 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001487 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001488 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001489 with open(f) as file:
1490 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001491 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001492 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001493 if m:
1494 sqlite_version = m.group(1)
1495 sqlite_version_tuple = tuple([int(x)
1496 for x in sqlite_version.split(".")])
1497 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1498 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001499 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001500 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001501 sqlite_incdir = d
1502 break
1503 else:
1504 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001505 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001506 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001507 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001508 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001509
1510 if sqlite_incdir:
1511 sqlite_dirs_to_check = [
1512 os.path.join(sqlite_incdir, '..', 'lib64'),
1513 os.path.join(sqlite_incdir, '..', 'lib'),
1514 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1515 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1516 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001517 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001518 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001519 if sqlite_libfile:
1520 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001521
1522 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001523 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001524 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001525 '_sqlite/cursor.c',
1526 '_sqlite/microprotocols.c',
1527 '_sqlite/module.c',
1528 '_sqlite/prepare_protocol.c',
1529 '_sqlite/row.c',
1530 '_sqlite/statement.c',
1531 '_sqlite/util.c', ]
1532
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001533 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001534 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001535 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1536 else:
1537 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1538
Benjamin Peterson076ed002010-10-31 17:11:02 +00001539 # Enable support for loadable extensions in the sqlite3 module
1540 # if --enable-loadable-sqlite-extensions configure option is used.
1541 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1542 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001543
Victor Stinner4cbea512019-02-28 17:48:38 +01001544 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001545 # In every directory on the search path search for a dynamic
1546 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001547 # for dynamic libraries on the entire path.
1548 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001549 # before the dynamic library in /usr/lib.
1550 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1551 else:
1552 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001553
Brett Cannonc5011fe2011-06-06 20:09:10 -07001554 include_dirs = ["Modules/_sqlite"]
1555 # Only include the directory where sqlite was found if it does
1556 # not already exist in set include directories, otherwise you
1557 # can end up with a bad search path order.
1558 if sqlite_incdir not in self.compiler.include_dirs:
1559 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001560 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001561 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001562 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001563 self.add(Extension('_sqlite3', sqlite_srcs,
1564 define_macros=sqlite_defines,
1565 include_dirs=include_dirs,
1566 library_dirs=sqlite_libdir,
1567 extra_link_args=sqlite_extra_link_args,
1568 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001569 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001570 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001571
Victor Stinner5ec33a12019-03-01 16:43:28 +01001572 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001573 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001574 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001575 if not VXWORKS:
1576 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001577 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001578 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001579 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001580 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001581 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001582
Victor Stinner5ec33a12019-03-01 16:43:28 +01001583 # Platform-specific libraries
1584 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1585 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001586 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001587 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001588
Victor Stinner5ec33a12019-03-01 16:43:28 +01001589 if MACOS:
Ned Deily951ab582020-05-18 11:31:21 -04001590 self.add(Extension('_scproxy', ['_scproxy.c'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001591 extra_link_args=[
1592 '-framework', 'SystemConfiguration',
Ned Deily951ab582020-05-18 11:31:21 -04001593 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001594
Victor Stinner5ec33a12019-03-01 16:43:28 +01001595 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001596 # Andrew Kuchling's zlib module. Note that some versions of zlib
1597 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1598 # http://www.cert.org/advisories/CA-2002-07.html
1599 #
1600 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1601 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1602 # now, we still accept 1.1.3, because we think it's difficult to
1603 # exploit this in Python, and we'd rather make it RedHat's problem
1604 # than our problem <wink>.
1605 #
1606 # You can upgrade zlib to version 1.1.4 yourself by going to
1607 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001608 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001609 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001610 if zlib_inc is not None:
1611 zlib_h = zlib_inc[0] + '/zlib.h'
1612 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001613 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001614 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001615 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001616 with open(zlib_h) as fp:
1617 while 1:
1618 line = fp.readline()
1619 if not line:
1620 break
1621 if line.startswith('#define ZLIB_VERSION'):
1622 version = line.split()[2]
1623 break
Guido van Rossume6970912001-04-15 15:16:12 +00001624 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001625 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001626 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001627 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1628 else:
1629 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001630 self.add(Extension('zlib', ['zlibmodule.c'],
1631 libraries=['z'],
1632 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001633 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001634 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001635 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001636 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001637 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001638 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001639 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001640
Christian Heimes1dc54002008-03-24 02:19:29 +00001641 # Helper module for various ascii-encoders. Uses zlib for an optimized
1642 # crc32 if we have it. Otherwise binascii uses its own.
1643 if have_zlib:
1644 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1645 libraries = ['z']
1646 extra_link_args = zlib_extra_link_args
1647 else:
1648 extra_compile_args = []
1649 libraries = []
1650 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001651 self.add(Extension('binascii', ['binascii.c'],
1652 extra_compile_args=extra_compile_args,
1653 libraries=libraries,
1654 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001655
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001656 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001657 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001658 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001659 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1660 else:
1661 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001662 self.add(Extension('_bz2', ['_bz2module.c'],
1663 libraries=['bz2'],
1664 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001665 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001666 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001667
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001668 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001669 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001670 self.add(Extension('_lzma', ['_lzmamodule.c'],
1671 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001672 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001673 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001674
Victor Stinner5ec33a12019-03-01 16:43:28 +01001675 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001676 # Interface to the Expat XML parser
1677 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001678 # Expat was written by James Clark and is now maintained by a group of
1679 # developers on SourceForge; see www.libexpat.org for more information.
1680 # The pyexpat module was written by Paul Prescod after a prototype by
1681 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1682 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001683 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001684 #
1685 # More information on Expat can be found at www.libexpat.org.
1686 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001687 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1688 expat_inc = []
1689 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001690 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001691 expat_lib = ['expat']
1692 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001693 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001694 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001695 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001696 define_macros = [
1697 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001698 # bpo-30947: Python uses best available entropy sources to
1699 # call XML_SetHashSalt(), expat entropy sources are not needed
1700 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001701 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001702 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001703 expat_lib = []
1704 expat_sources = ['expat/xmlparse.c',
1705 'expat/xmlrole.c',
1706 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001707 expat_depends = ['expat/ascii.h',
1708 'expat/asciitab.h',
1709 'expat/expat.h',
1710 'expat/expat_config.h',
1711 'expat/expat_external.h',
1712 'expat/internal.h',
1713 'expat/latin1tab.h',
1714 'expat/utf8tab.h',
1715 'expat/xmlrole.h',
1716 'expat/xmltok.h',
1717 'expat/xmltok_impl.h'
1718 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001719
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001720 cc = sysconfig.get_config_var('CC').split()[0]
Victor Stinner6b982c22020-04-01 01:10:07 +02001721 ret = run_command(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001722 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Victor Stinner6b982c22020-04-01 01:10:07 +02001723 if ret == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001724 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001725
Victor Stinner8058bda2019-03-01 15:31:45 +01001726 self.add(Extension('pyexpat',
1727 define_macros=define_macros,
1728 extra_compile_args=extra_compile_args,
1729 include_dirs=expat_inc,
1730 libraries=expat_lib,
1731 sources=['pyexpat.c'] + expat_sources,
1732 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001733
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001734 # Fredrik Lundh's cElementTree module. Note that this also
1735 # uses expat (via the CAPI hook in pyexpat).
1736
Victor Stinner625dbf22019-03-01 15:59:39 +01001737 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001738 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001739 self.add(Extension('_elementtree',
1740 define_macros=define_macros,
1741 include_dirs=expat_inc,
1742 libraries=expat_lib,
1743 sources=['_elementtree.c'],
1744 depends=['pyexpat.c', *expat_sources,
1745 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001746 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001747 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001748
Victor Stinner5ec33a12019-03-01 16:43:28 +01001749 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001750 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001751 self.add(Extension('_multibytecodec',
1752 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001753 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001754 self.add(Extension('_codecs_%s' % loc,
1755 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001756
Victor Stinner5ec33a12019-03-01 16:43:28 +01001757 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001758 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001759 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001760 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1761 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001762
1763 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001764 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001765 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1766 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001767 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001768 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1769 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 17:19:04 +01001770 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-01 22:52:23 -06001771 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001772 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1773 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001774 libs.append('rt')
Victor Stinner8058bda2019-03-01 15:31:45 +01001775 self.add(Extension('_posixshmem', posixshmem_srcs,
1776 define_macros={},
1777 libraries=libs,
1778 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001779
Victor Stinner8058bda2019-03-01 15:31:45 +01001780 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001781 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001782
Victor Stinner5ec33a12019-03-01 16:43:28 +01001783 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001784 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001785 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001786 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001787 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001788 uuid_libs = ['uuid']
1789 else:
1790 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001791 self.add(Extension('_uuid', ['_uuidmodule.c'],
1792 libraries=uuid_libs,
1793 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001794 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001795 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001796
Victor Stinner5ec33a12019-03-01 16:43:28 +01001797 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001798 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001799 self.init_inc_lib_dirs()
1800
1801 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001802 if TEST_EXTENSIONS:
1803 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001804 self.detect_readline_curses()
1805 self.detect_crypt()
1806 self.detect_socket()
1807 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001808 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001809 self.detect_dbm_gdbm()
1810 self.detect_sqlite()
1811 self.detect_platform_specific_exts()
1812 self.detect_nis()
1813 self.detect_compress_exts()
1814 self.detect_expat_elementtree()
1815 self.detect_multibytecodecs()
1816 self.detect_decimal()
1817 self.detect_ctypes()
1818 self.detect_multiprocessing()
1819 if not self.detect_tkinter():
1820 self.missing.append('_tkinter')
1821 self.detect_uuid()
1822
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001823## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001824## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001825
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001826 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001827 self.add(Extension('xxlimited', ['xxlimited.c'],
1828 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001829
Ned Deilyd819b932013-09-06 01:07:05 -07001830 def detect_tkinter_explicitly(self):
1831 # Build _tkinter using explicit locations for Tcl/Tk.
1832 #
1833 # This is enabled when both arguments are given to ./configure:
1834 #
1835 # --with-tcltk-includes="-I/path/to/tclincludes \
1836 # -I/path/to/tkincludes"
1837 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1838 # -L/path/to/tklibs -ltkm.n"
1839 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001840 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001841 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1842 #
1843 # This can be useful for building and testing tkinter with multiple
1844 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1845 # build of Tcl so you need to specify both arguments and use care when
1846 # overriding.
1847
1848 # The _TCLTK variables are created in the Makefile sharedmods target.
1849 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1850 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1851 if not (tcltk_includes and tcltk_libs):
1852 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001853 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001854
1855 extra_compile_args = tcltk_includes.split()
1856 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001857 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1858 define_macros=[('WITH_APPINIT', 1)],
1859 extra_compile_args = extra_compile_args,
1860 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001861 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001862
Victor Stinner625dbf22019-03-01 15:59:39 +01001863 def detect_tkinter_darwin(self):
Ned Deily1731d6d2020-05-18 04:32:38 -04001864 # Build default _tkinter on macOS using Tcl and Tk frameworks.
1865 #
1866 # The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
1867 # built and installed as macOS framework bundles. However,
1868 # for several reasons, we cannot take full advantage of the
1869 # Apple-supplied compiler chain's -framework options here.
1870 # Instead, we need to find and pass to the compiler the
1871 # absolute paths of the Tcl and Tk headers files we want to use
1872 # and the absolute path to the directory containing the Tcl
1873 # and Tk frameworks for linking.
1874 #
1875 # We want to handle here two common use cases on macOS:
1876 # 1. Build and link with system-wide third-party or user-built
1877 # Tcl and Tk frameworks installed in /Library/Frameworks.
1878 # 2. Build and link using a user-specified macOS SDK so that the
1879 # built Python can be exported to other systems. In this case,
1880 # search only the SDK's /Library/Frameworks (normally empty)
1881 # and /System/Library/Frameworks.
1882 #
1883 # Any other use case should be able to be handled explicitly by
1884 # using the options described above in detect_tkinter_explicitly().
1885 # In particular it would be good to handle here the case where
1886 # you want to build and link with a framework build of Tcl and Tk
1887 # that is not in /Library/Frameworks, say, in your private
1888 # $HOME/Library/Frameworks directory or elsewhere. It turns
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301889 # out to be difficult to make that work automatically here
Ned Deily1731d6d2020-05-18 04:32:38 -04001890 # without bringing into play more tools and magic. That case
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301891 # can be handled using a recipe with the right arguments
Ned Deily1731d6d2020-05-18 04:32:38 -04001892 # to detect_tkinter_explicitly().
1893 #
1894 # Note also that the fallback case here is to try to use the
1895 # Apple-supplied Tcl and Tk frameworks in /System/Library but
1896 # be forewarned that they are deprecated by Apple and typically
1897 # out-of-date and buggy; their use should be avoided if at
1898 # all possible by installing a newer version of Tcl and Tk in
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301899 # /Library/Frameworks before building Python without
Ned Deily1731d6d2020-05-18 04:32:38 -04001900 # an explicit SDK or by configuring build arguments explicitly.
1901
Jack Jansen0b06be72002-06-21 14:48:38 +00001902 from os.path import join, exists
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001903
Ned Deily1731d6d2020-05-18 04:32:38 -04001904 sysroot = macosx_sdk_root() # path to the SDK or '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001905
Ned Deily1731d6d2020-05-18 04:32:38 -04001906 if macosx_sdk_specified():
1907 # Use case #2: an SDK other than '/' was specified.
1908 # Only search there.
1909 framework_dirs = [
1910 join(sysroot, 'Library', 'Frameworks'),
1911 join(sysroot, 'System', 'Library', 'Frameworks'),
1912 ]
1913 else:
1914 # Use case #1: no explicit SDK selected.
1915 # Search the local system-wide /Library/Frameworks,
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301916 # not the one in the default SDK, otherwise fall back to
Ned Deily1731d6d2020-05-18 04:32:38 -04001917 # /System/Library/Frameworks whose header files may be in
1918 # the default SDK or, on older systems, actually installed.
1919 framework_dirs = [
1920 join('/', 'Library', 'Frameworks'),
1921 join(sysroot, 'System', 'Library', 'Frameworks'),
1922 ]
1923
1924 # Find the directory that contains the Tcl.framework and
1925 # Tk.framework bundles.
Jack Jansen0b06be72002-06-21 14:48:38 +00001926 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001927 # both Tcl.framework and Tk.framework should be present
Jack Jansen0b06be72002-06-21 14:48:38 +00001928 for fw in 'Tcl', 'Tk':
Ned Deily1731d6d2020-05-18 04:32:38 -04001929 if not exists(join(F, fw + '.framework')):
1930 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001931 else:
Manan Kumar Garg619f9802020-10-05 02:58:43 +05301932 # ok, F is now directory with both frameworks. Continue
Jack Jansen0b06be72002-06-21 14:48:38 +00001933 # building
1934 break
1935 else:
1936 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1937 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001938 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001939
Jack Jansen0b06be72002-06-21 14:48:38 +00001940 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001941 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001942 for fw in ('Tcl', 'Tk')
Ned Deily1731d6d2020-05-18 04:32:38 -04001943 for H in ('Headers',)
Jack Jansen0b06be72002-06-21 14:48:38 +00001944 ]
1945
Ned Deily1731d6d2020-05-18 04:32:38 -04001946 # Add the base framework directory as well
1947 compile_args = ['-F', F]
Jack Jansen0b06be72002-06-21 14:48:38 +00001948
Ned Deily1731d6d2020-05-18 04:32:38 -04001949 # Do not build tkinter for archs that this Tk was not built with.
Georg Brandlfcaf9102008-07-16 02:17:56 +00001950 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001951 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001952
Ronald Oussorend097efe2009-09-15 19:07:58 +00001953 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1954 if not os.path.exists(self.build_temp):
1955 os.makedirs(self.build_temp)
1956
Ned Deily1731d6d2020-05-18 04:32:38 -04001957 run_command(
1958 "file {}/Tk.framework/Tk | grep 'for architecture' > {}".format(F, tmpfile)
1959 )
Brett Cannon9f5db072010-10-29 20:19:27 +00001960 with open(tmpfile) as fp:
1961 detected_archs = []
1962 for ln in fp:
1963 a = ln.split()[-1]
1964 if a in archs:
1965 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001966 os.unlink(tmpfile)
1967
Ned Deily1731d6d2020-05-18 04:32:38 -04001968 arch_args = []
Ronald Oussorend097efe2009-09-15 19:07:58 +00001969 for a in detected_archs:
Ned Deily1731d6d2020-05-18 04:32:38 -04001970 arch_args.append('-arch')
1971 arch_args.append(a)
1972
1973 compile_args += arch_args
1974 link_args = [','.join(['-Wl', '-F', F, '-framework', 'Tcl', '-framework', 'Tk']), *arch_args]
1975
1976 # The X11/xlib.h file bundled in the Tk sources can cause function
1977 # prototype warnings from the compiler. Since we cannot easily fix
1978 # that, suppress the warnings here instead.
1979 if '-Wstrict-prototypes' in cflags.split():
1980 compile_args.append('-Wno-strict-prototypes')
Georg Brandlfcaf9102008-07-16 02:17:56 +00001981
Victor Stinnercfe172d2019-03-01 18:21:49 +01001982 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1983 define_macros=[('WITH_APPINIT', 1)],
1984 include_dirs=include_dirs,
1985 libraries=[],
Ned Deily1731d6d2020-05-18 04:32:38 -04001986 extra_compile_args=compile_args,
1987 extra_link_args=link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001988 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001989
Victor Stinner625dbf22019-03-01 15:59:39 +01001990 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001991 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001992
Ned Deilyd819b932013-09-06 01:07:05 -07001993 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1994 # configured or passed into the make target. If so, use these values
1995 # to build tkinter and bypass the searches for Tcl and TK in standard
1996 # locations.
1997 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 16:43:28 +01001998 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001999
Jack Jansen0b06be72002-06-21 14:48:38 +00002000 # Rather than complicate the code below, detecting and building
2001 # AquaTk is a separate method. Only one Tkinter will be built on
2002 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01002003 if (MACOS and self.detect_tkinter_darwin()):
2004 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00002005
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002006 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002007 # The versions with dots are used on Unix, and the versions without
2008 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002009 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00002010 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
2011 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01002012 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002013 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01002014 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002015 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00002016 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002017 # Exit the loop when we've found the Tcl/Tk libraries
2018 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002019
Fredrik Lundhade711a2001-01-24 08:00:28 +00002020 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002021 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002022 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002023 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002024 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01002025 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002026 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
2027 # but the include subdirs are named like .../include/tcl8.3.
2028 dotversion = dotversion[:-1] + '.' + dotversion[-1]
2029 tcl_include_sub = []
2030 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01002031 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002032 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
2033 tk_include_sub += [dir + os.sep + "tk" + dotversion]
2034 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01002035 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
2036 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002037
Martin v. Löwise86a59a2003-05-03 08:45:51 +00002038 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002039 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002040 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01002041 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00002042
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002043 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002044
Victor Stinnercfe172d2019-03-01 18:21:49 +01002045 include_dirs = []
2046 libs = []
2047 defs = []
2048 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002049 for dir in tcl_includes + tk_includes:
2050 if dir not in include_dirs:
2051 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002052
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002053 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01002054 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002055 include_dirs.append('/usr/openwin/include')
2056 added_lib_dirs.append('/usr/openwin/lib')
2057 elif os.path.exists('/usr/X11R6/include'):
2058 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00002059 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002060 added_lib_dirs.append('/usr/X11R6/lib')
2061 elif os.path.exists('/usr/X11R5/include'):
2062 include_dirs.append('/usr/X11R5/include')
2063 added_lib_dirs.append('/usr/X11R5/lib')
2064 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002065 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002066 include_dirs.append('/usr/X11/include')
2067 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002068
Jason Tishler9181c942003-02-05 15:16:17 +00002069 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01002070 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00002071 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
2072 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01002073 return False
Jason Tishler9181c942003-02-05 15:16:17 +00002074
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002075 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01002076 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002077 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002078 defs.append( ('WITH_BLT', 1) )
2079 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01002080 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002081 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00002082 defs.append( ('WITH_BLT', 1) )
2083 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002084
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002085 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00002086 libs.append('tk'+ version)
2087 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002088
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002089 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01002090 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002091 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002092
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002093 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002094 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002095 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002096 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002097 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002098 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002099 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002100
Victor Stinnercfe172d2019-03-01 18:21:49 +01002101 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2102 define_macros=[('WITH_APPINIT', 1)] + defs,
2103 include_dirs=include_dirs,
2104 libraries=libs,
2105 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002106 return True
2107
Christian Heimes78644762008-03-04 23:39:23 +00002108 def configure_ctypes_darwin(self, ext):
2109 # Darwin (OS X) uses preconfigured files, in
2110 # the Modules/_ctypes/libffi_osx directory.
Victor Stinner625dbf22019-03-01 15:59:39 +01002111 ffi_srcdir = os.path.abspath(os.path.join(self.srcdir, 'Modules',
Christian Heimes78644762008-03-04 23:39:23 +00002112 '_ctypes', 'libffi_osx'))
2113 sources = [os.path.join(ffi_srcdir, p)
2114 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:56 +00002115 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:23 +00002116 'x86/x86-darwin.S',
2117 'x86/x86-ffi_darwin.c',
2118 'x86/x86-ffi64.c',
2119 'powerpc/ppc-darwin.S',
2120 'powerpc/ppc-darwin_closure.S',
2121 'powerpc/ppc-ffi_darwin.c',
2122 'powerpc/ppc64-darwin_closure.S',
2123 ]]
2124
2125 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:05 +00002126 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:23 +00002127
2128 include_dirs = [os.path.join(ffi_srcdir, 'include'),
2129 os.path.join(ffi_srcdir, 'powerpc')]
2130 ext.include_dirs.extend(include_dirs)
2131 ext.sources.extend(sources)
2132 return True
2133
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002134 def configure_ctypes(self, ext):
2135 if not self.use_system_libffi:
Victor Stinner4cbea512019-02-28 17:48:38 +01002136 if MACOS:
Christian Heimes78644762008-03-04 23:39:23 +00002137 return self.configure_ctypes_darwin(ext)
Zachary Waref40d4dd2016-09-17 01:25:24 -05002138 print('INFO: Could not locate ffi libs and/or headers')
2139 return False
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002140 return True
2141
Victor Stinner625dbf22019-03-01 15:59:39 +01002142 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002143 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002144 self.use_system_libffi = False
2145 include_dirs = []
Victor Stinner1ae035b2020-04-17 17:47:20 +02002146 extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002147 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002148 sources = ['_ctypes/_ctypes.c',
2149 '_ctypes/callbacks.c',
2150 '_ctypes/callproc.c',
2151 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002152 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002153 depends = ['_ctypes/ctypes.h']
2154
Victor Stinner4cbea512019-02-28 17:48:38 +01002155 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002156 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:58 +00002157 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:23 +00002158 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002159 include_dirs.append('_ctypes/darwin')
Victor Stinner5ec33a12019-03-01 16:43:28 +01002160 # XXX Is this still needed?
2161 # extra_link_args.extend(['-read_only_relocs', 'warning'])
Thomas Hellercf567c12006-03-08 19:51:58 +00002162
Victor Stinner4cbea512019-02-28 17:48:38 +01002163 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002164 # XXX This shouldn't be necessary; it appears that some
2165 # of the assembler code is non-PIC (i.e. it has relocations
2166 # when it shouldn't. The proper fix would be to rewrite
2167 # the assembler code to be PIC.
2168 # This only works with GCC; the Sun compiler likely refuses
2169 # this option. If you want to compile ctypes with the Sun
2170 # compiler, please research a proper solution, instead of
2171 # finding some -z option for the Sun compiler.
2172 extra_link_args.append('-mimpure-text')
2173
Victor Stinner4cbea512019-02-28 17:48:38 +01002174 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002175 extra_link_args.append('-fPIC')
2176
Thomas Hellercf567c12006-03-08 19:51:58 +00002177 ext = Extension('_ctypes',
2178 include_dirs=include_dirs,
2179 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002180 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002181 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002182 sources=sources,
2183 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002184 self.add(ext)
2185 if TEST_EXTENSIONS:
2186 # function my_sqrt() needs libm for sqrt()
2187 self.add(Extension('_ctypes_test',
2188 sources=['_ctypes/_ctypes_test.c'],
2189 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002190
Victor Stinner625dbf22019-03-01 15:59:39 +01002191 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002192 if MACOS:
Zachary Ware935043d2016-09-09 17:01:21 -07002193 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
2194 return
Christian Heimes78644762008-03-04 23:39:23 +00002195 # OS X 10.5 comes with libffi.dylib; the include files are
2196 # in /usr/include/ffi
Victor Stinner96d81582019-03-01 13:53:46 +01002197 ffi_inc_dirs.append('/usr/include/ffi')
Christian Heimes78644762008-03-04 23:39:23 +00002198
Benjamin Petersond78735d2010-01-01 16:04:23 +00002199 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:45 +00002200 if not ffi_inc or ffi_inc[0] == '':
Victor Stinner96d81582019-03-01 13:53:46 +01002201 ffi_inc = find_file('ffi.h', [], ffi_inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002202 if ffi_inc is not None:
2203 ffi_h = ffi_inc[0] + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002204 if not os.path.exists(ffi_h):
2205 ffi_inc = None
2206 print('Header file {} does not exist'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002207 ffi_lib = None
2208 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002209 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002210 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002211 ffi_lib = lib_name
2212 break
2213
2214 if ffi_inc and ffi_lib:
2215 ext.include_dirs.extend(ffi_inc)
2216 ext.libraries.append(ffi_lib)
2217 self.use_system_libffi = True
2218
Christian Heimes5bb96922018-02-25 10:22:14 +01002219 if sysconfig.get_config_var('HAVE_LIBDL'):
2220 # for dlopen, see bpo-32647
2221 ext.libraries.append('dl')
2222
Victor Stinner5ec33a12019-03-01 16:43:28 +01002223 def detect_decimal(self):
2224 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002225 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002226 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002227 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2228 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002229 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002230 sources = ['_decimal/_decimal.c']
2231 depends = ['_decimal/docstrings.h']
2232 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002233 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002234 'Modules',
2235 '_decimal',
2236 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002237 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002238 sources = [
2239 '_decimal/_decimal.c',
2240 '_decimal/libmpdec/basearith.c',
2241 '_decimal/libmpdec/constants.c',
2242 '_decimal/libmpdec/context.c',
2243 '_decimal/libmpdec/convolute.c',
2244 '_decimal/libmpdec/crt.c',
2245 '_decimal/libmpdec/difradix2.c',
2246 '_decimal/libmpdec/fnt.c',
2247 '_decimal/libmpdec/fourstep.c',
2248 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002249 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002250 '_decimal/libmpdec/mpdecimal.c',
2251 '_decimal/libmpdec/numbertheory.c',
2252 '_decimal/libmpdec/sixstep.c',
2253 '_decimal/libmpdec/transpose.c',
2254 ]
2255 depends = [
2256 '_decimal/docstrings.h',
2257 '_decimal/libmpdec/basearith.h',
2258 '_decimal/libmpdec/bits.h',
2259 '_decimal/libmpdec/constants.h',
2260 '_decimal/libmpdec/convolute.h',
2261 '_decimal/libmpdec/crt.h',
2262 '_decimal/libmpdec/difradix2.h',
2263 '_decimal/libmpdec/fnt.h',
2264 '_decimal/libmpdec/fourstep.h',
2265 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002266 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002267 '_decimal/libmpdec/mpdecimal.h',
2268 '_decimal/libmpdec/numbertheory.h',
2269 '_decimal/libmpdec/sixstep.h',
2270 '_decimal/libmpdec/transpose.h',
2271 '_decimal/libmpdec/typearith.h',
2272 '_decimal/libmpdec/umodarith.h',
2273 ]
2274
Stefan Krah1919b7e2012-03-21 18:25:23 +01002275 config = {
2276 'x64': [('CONFIG_64','1'), ('ASM','1')],
2277 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2278 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2279 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2280 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2281 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2282 ('LEGACY_COMPILER','1')],
2283 'universal': [('UNIVERSAL','1')]
2284 }
2285
Stefan Krah1919b7e2012-03-21 18:25:23 +01002286 cc = sysconfig.get_config_var('CC')
2287 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2288 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2289
2290 if machine:
2291 # Override automatic configuration to facilitate testing.
2292 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002293 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002294 # Universal here means: build with the same options Python
2295 # was built with.
2296 define_macros = config['universal']
2297 elif sizeof_size_t == 8:
2298 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2299 define_macros = config['x64']
2300 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2301 define_macros = config['uint128']
2302 else:
2303 define_macros = config['ansi64']
2304 elif sizeof_size_t == 4:
2305 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2306 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002307 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002308 # solaris: problems with register allocation.
2309 # icc >= 11.0 works as well.
2310 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002311 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002312 else:
2313 define_macros = config['ansi32']
2314 else:
2315 raise DistutilsError("_decimal: unsupported architecture")
2316
2317 # Workarounds for toolchain bugs:
2318 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2319 # Some versions of gcc miscompile inline asm:
2320 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2321 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2322 extra_compile_args.append('-fno-ipa-pure-const')
2323 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2324 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2325 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2326 undef_macros.append('_FORTIFY_SOURCE')
2327
Stefan Krah1919b7e2012-03-21 18:25:23 +01002328 # Uncomment for extra functionality:
2329 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002330 self.add(Extension('_decimal',
2331 include_dirs=include_dirs,
2332 libraries=libraries,
2333 define_macros=define_macros,
2334 undef_macros=undef_macros,
2335 extra_compile_args=extra_compile_args,
2336 sources=sources,
2337 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002338
Victor Stinner5ec33a12019-03-01 16:43:28 +01002339 def detect_openssl_hashlib(self):
2340 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002341 config_vars = sysconfig.get_config_vars()
2342
2343 def split_var(name, sep):
2344 # poor man's shlex, the re module is not available yet.
2345 value = config_vars.get(name)
2346 if not value:
2347 return ()
2348 # This trick works because ax_check_openssl uses --libs-only-L,
2349 # --libs-only-l, and --cflags-only-I.
2350 value = ' ' + value
2351 sep = ' ' + sep
2352 return [v.strip() for v in value.split(sep) if v.strip()]
2353
2354 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2355 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2356 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2357 if not openssl_libs:
2358 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002359 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002360 return None, None
2361
2362 # Find OpenSSL includes
2363 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002364 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002365 )
2366 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002367 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002368 return None, None
2369
2370 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2371 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002372 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002373 ['/usr/kerberos/include']
2374 )
2375 if krb5_h:
2376 ssl_incs.extend(krb5_h)
2377
Christian Heimes61d478c2018-01-27 15:51:38 +01002378 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 11:44:05 +02002379 self.add(Extension(
2380 '_ssl', ['_ssl.c'],
2381 include_dirs=openssl_includes,
2382 library_dirs=openssl_libdirs,
2383 libraries=openssl_libs,
2384 depends=['socketmodule.h', '_ssl/debughelpers.c'])
2385 )
Christian Heimes61d478c2018-01-27 15:51:38 +01002386 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002387 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002388
Victor Stinner8058bda2019-03-01 15:31:45 +01002389 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2390 depends=['hashlib.h'],
2391 include_dirs=openssl_includes,
2392 library_dirs=openssl_libdirs,
2393 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002394
xdegaye2ee077f2019-04-09 17:20:08 +02002395 def detect_hash_builtins(self):
Christian Heimes9b60e552020-05-15 23:54:53 +02002396 # By default we always compile these even when OpenSSL is available
2397 # (issue #14693). It's harmless and the object code is tiny
2398 # (40-50 KiB per module, only loaded when actually used). Modules can
2399 # be disabled via the --with-builtin-hashlib-hashes configure flag.
2400 supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
Victor Stinner5ec33a12019-03-01 16:43:28 +01002401
Christian Heimes9b60e552020-05-15 23:54:53 +02002402 configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
2403 configured = configured.strip('"').lower()
2404 configured = {
2405 m.strip() for m in configured.split(",")
2406 }
Victor Stinner5ec33a12019-03-01 16:43:28 +01002407
Christian Heimes9b60e552020-05-15 23:54:53 +02002408 self.disabled_configure.extend(
2409 sorted(supported.difference(configured))
2410 )
Victor Stinner5ec33a12019-03-01 16:43:28 +01002411
Christian Heimes9b60e552020-05-15 23:54:53 +02002412 if "sha256" in configured:
2413 self.add(Extension(
2414 '_sha256', ['sha256module.c'],
2415 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2416 depends=['hashlib.h']
2417 ))
2418
2419 if "sha512" in configured:
2420 self.add(Extension(
2421 '_sha512', ['sha512module.c'],
2422 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2423 depends=['hashlib.h']
2424 ))
2425
2426 if "md5" in configured:
2427 self.add(Extension(
2428 '_md5', ['md5module.c'],
2429 depends=['hashlib.h']
2430 ))
2431
2432 if "sha1" in configured:
2433 self.add(Extension(
2434 '_sha1', ['sha1module.c'],
2435 depends=['hashlib.h']
2436 ))
2437
2438 if "blake2" in configured:
2439 blake2_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002440 os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002441 )
2442 blake2_deps.append('hashlib.h')
2443 self.add(Extension(
2444 '_blake2',
2445 [
2446 '_blake2/blake2module.c',
2447 '_blake2/blake2b_impl.c',
2448 '_blake2/blake2s_impl.c'
2449 ],
2450 depends=blake2_deps
2451 ))
2452
2453 if "sha3" in configured:
2454 sha3_deps = glob(
Serhiy Storchaka93558682020-06-20 11:10:31 +03002455 os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002456 )
2457 sha3_deps.append('hashlib.h')
2458 self.add(Extension(
2459 '_sha3',
2460 ['_sha3/sha3module.c'],
2461 depends=sha3_deps
2462 ))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002463
2464 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002465 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002466 self.missing.append('nis')
2467 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002468
2469 libs = []
2470 library_dirs = []
2471 includes_dirs = []
2472
2473 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2474 # moved headers and libraries to libtirpc and libnsl. The headers
2475 # are in tircp and nsl sub directories.
2476 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002477 'rpcsvc/yp_prot.h', self.inc_dirs,
2478 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002479 )
2480 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002481 'rpc/rpc.h', self.inc_dirs,
2482 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002483 )
2484 if rpcsvc_inc is None or rpc_inc is None:
2485 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002486 self.missing.append('nis')
2487 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002488 includes_dirs.extend(rpcsvc_inc)
2489 includes_dirs.extend(rpc_inc)
2490
Victor Stinner625dbf22019-03-01 15:59:39 +01002491 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002492 libs.append('nsl')
2493 else:
2494 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002495 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002496 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2497 if libnsl is not None:
2498 library_dirs.append(os.path.dirname(libnsl))
2499 libs.append('nsl')
2500
Victor Stinner625dbf22019-03-01 15:59:39 +01002501 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002502 libs.append('tirpc')
2503
Victor Stinner8058bda2019-03-01 15:31:45 +01002504 self.add(Extension('nis', ['nismodule.c'],
2505 libraries=libs,
2506 library_dirs=library_dirs,
2507 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002508
Christian Heimesff5be6e2018-01-20 13:19:21 +01002509
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002510class PyBuildInstall(install):
2511 # Suppress the warning about installation into the lib_dynload
2512 # directory, which is not in sys.path when running Python during
2513 # installation:
2514 def initialize_options (self):
2515 install.initialize_options(self)
2516 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002517
Éric Araujoe6792c12011-06-09 14:07:02 +02002518 # Customize subcommands to not install an egg-info file for Python
2519 sub_commands = [('install_lib', install.has_lib),
2520 ('install_headers', install.has_headers),
2521 ('install_scripts', install.has_scripts),
2522 ('install_data', install.has_data)]
2523
2524
Michael W. Hudson529a5052002-12-17 16:47:17 +00002525class PyBuildInstallLib(install_lib):
2526 # Do exactly what install_lib does but make sure correct access modes get
2527 # set on installed directories and files. All installed files with get
2528 # mode 644 unless they are a shared library in which case they will get
2529 # mode 755. All installed directories will get mode 755.
2530
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002531 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2532 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002533
2534 def install(self):
2535 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002536 self.set_file_modes(outfiles, 0o644, 0o755)
2537 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002538 return outfiles
2539
2540 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002541 if not files: return
2542
2543 for filename in files:
2544 if os.path.islink(filename): continue
2545 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002546 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002547 log.info("changing mode of %s to %o", filename, mode)
2548 if not self.dry_run: os.chmod(filename, mode)
2549
2550 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002551 for dirpath, dirnames, fnames in os.walk(dirname):
2552 if os.path.islink(dirpath):
2553 continue
2554 log.info("changing mode of %s to %o", dirpath, mode)
2555 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002556
Victor Stinnerc991f242019-03-01 17:19:04 +01002557
Georg Brandlff52f762010-12-28 09:51:43 +00002558class PyBuildScripts(build_scripts):
2559 def copy_scripts(self):
2560 outfiles, updated_files = build_scripts.copy_scripts(self)
2561 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2562 minoronly = '.{0[1]}'.format(sys.version_info)
2563 newoutfiles = []
2564 newupdated_files = []
2565 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002566 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002567 newfilename = filename + fullversion
2568 else:
2569 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002570 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002571 os.rename(filename, newfilename)
2572 newoutfiles.append(newfilename)
2573 if filename in updated_files:
2574 newupdated_files.append(newfilename)
2575 return newoutfiles, newupdated_files
2576
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002577
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002578def main():
Victor Stinnerc991f242019-03-01 17:19:04 +01002579 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2580 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2581
2582 class DummyProcess:
2583 """Hack for parallel build"""
2584 ProcessPoolExecutor = None
2585
2586 sys.modules['concurrent.futures.process'] = DummyProcess
Paul Ganssle62972d92020-05-16 04:20:06 -04002587 validate_tzpath()
Victor Stinnerc991f242019-03-01 17:19:04 +01002588
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002589 # turn off warnings when deprecated modules are imported
2590 import warnings
2591 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002592 setup(# PyPI Metadata (PEP 301)
2593 name = "Python",
2594 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002595 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002596 maintainer = "Guido van Rossum and the Python community",
2597 maintainer_email = "python-dev@python.org",
2598 description = "A high-level object-oriented programming language",
2599 long_description = SUMMARY.strip(),
2600 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002601 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002602 platforms = ["Many"],
2603
2604 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002605 cmdclass = {'build_ext': PyBuildExt,
2606 'build_scripts': PyBuildScripts,
2607 'install': PyBuildInstall,
2608 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002609 # The struct module is defined here, because build_ext won't be
2610 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002611 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002612
Georg Brandlff52f762010-12-28 09:51:43 +00002613 # If you change the scripts installed here, you also need to
2614 # check the PyBuildScripts command above, and change the links
2615 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002616 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002617 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002618 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002619
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002620# --install-platlib
2621if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002622 main()