blob: 68fc3120cc317910ee26d54cc44ef7fab8a9a3dc [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +00002
Victor Stinner625dbf22019-03-01 15:59:39 +01003import argparse
Eric Snow335e14d2014-01-04 15:09:28 -07004import importlib._bootstrap
Victor Stinner625dbf22019-03-01 15:59:39 +01005import importlib.machinery
Eric Snow335e14d2014-01-04 15:09:28 -07006import importlib.util
Victor Stinner625dbf22019-03-01 15:59:39 +01007import os
8import re
9import sys
Tarek Ziadéedacea32010-01-29 11:41:03 +000010import sysconfig
Victor Stinner625dbf22019-03-01 15:59:39 +010011from glob import glob
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 Deily0288dd62019-06-03 06:34:48 -0400153MACOS_SDK_ROOT = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100154
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000155def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400156 """Return the directory of the current macOS SDK.
157
158 If no SDK was explicitly configured, call the compiler to find which
159 include files paths are being searched by default. Use '/' if the
160 compiler is searching /usr/include (meaning system header files are
161 installed) or use the root of an SDK if that is being searched.
162 (The SDK may be supplied via Xcode or via the Command Line Tools).
163 The SDK paths used by Apple-supplied tool chains depend on the
164 setting of various variables; see the xcrun man page for more info.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000165 """
Ned Deily0288dd62019-06-03 06:34:48 -0400166 global MACOS_SDK_ROOT
167
168 # If already called, return cached result.
169 if MACOS_SDK_ROOT:
170 return MACOS_SDK_ROOT
171
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000172 cflags = sysconfig.get_config_var('CFLAGS')
Joshua Rootb3107002020-04-22 17:44:10 +1000173 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400174 if m is not None:
175 MACOS_SDK_ROOT = m.group(1)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000176 else:
Ned Deily0288dd62019-06-03 06:34:48 -0400177 MACOS_SDK_ROOT = '/'
178 cc = sysconfig.get_config_var('CC')
179 tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid()
180 try:
181 os.unlink(tmpfile)
182 except:
183 pass
Victor Stinner6b982c22020-04-01 01:10:07 +0200184 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
Ned Deily0288dd62019-06-03 06:34:48 -0400185 in_incdirs = False
186 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200187 if ret == 0:
Ned Deily0288dd62019-06-03 06:34:48 -0400188 with open(tmpfile) as fp:
189 for line in fp.readlines():
190 if line.startswith("#include <...>"):
191 in_incdirs = True
192 elif line.startswith("End of search list"):
193 in_incdirs = False
194 elif in_incdirs:
195 line = line.strip()
196 if line == '/usr/include':
197 MACOS_SDK_ROOT = '/'
198 elif line.endswith(".sdk/usr/include"):
199 MACOS_SDK_ROOT = line[:-12]
200 finally:
201 os.unlink(tmpfile)
202
203 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000204
Victor Stinnerc991f242019-03-01 17:19:04 +0100205
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000206def is_macosx_sdk_path(path):
207 """
208 Returns True if 'path' can be located in an OSX SDK
209 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700210 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
211 or path.startswith('/System/')
212 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000213
Victor Stinnerc991f242019-03-01 17:19:04 +0100214
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000215def find_file(filename, std_dirs, paths):
216 """Searches for the directory where a given file is located,
217 and returns a possibly-empty list of additional directories, or None
218 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000219
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000220 'filename' is the name of a file, such as readline.h or libcrypto.a.
221 'std_dirs' is the list of standard system directories; if the
222 file is found in one of them, no additional directives are needed.
223 'paths' is a list of additional locations to check; if the file is
224 found in one of them, the resulting list will contain the directory.
225 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100226 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000227 # Honor the MacOSX SDK setting when one was specified.
228 # An SDK is a directory with the same structure as a real
229 # system, but with only header files and libraries.
230 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000231
232 # Check the standard locations
233 for dir in std_dirs:
234 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000235
Victor Stinner4cbea512019-02-28 17:48:38 +0100236 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000237 f = os.path.join(sysroot, dir[1:], filename)
238
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000239 if os.path.exists(f): return []
240
241 # Check the additional directories
242 for dir in paths:
243 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000244
Victor Stinner4cbea512019-02-28 17:48:38 +0100245 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000246 f = os.path.join(sysroot, dir[1:], filename)
247
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000248 if os.path.exists(f):
249 return [dir]
250
251 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000252 return None
253
Victor Stinnerc991f242019-03-01 17:19:04 +0100254
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000255def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000256 result = compiler.find_library_file(std_dirs + paths, libname)
257 if result is None:
258 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000259
Victor Stinner4cbea512019-02-28 17:48:38 +0100260 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000261 sysroot = macosx_sdk_root()
262
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000263 # Check whether the found file is in one of the standard directories
264 dirname = os.path.dirname(result)
265 for p in std_dirs:
266 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000267 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000268
Victor Stinner4cbea512019-02-28 17:48:38 +0100269 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100270 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
271 # libraries with .tbd extensions rather than the normal .dylib
272 # shared libraries installed in /. The Apple compiler tool
273 # chain handles this transparently but it can cause problems
274 # for programs that are being built with an SDK and searching
275 # for specific libraries. Distutils find_library_file() now
276 # knows to also search for and return .tbd files. But callers
277 # of find_library_file need to keep in mind that the base filename
278 # of the returned SDK library file might have a different extension
279 # from that of the library file installed on the running system,
280 # for example:
281 # /Applications/Xcode.app/Contents/Developer/Platforms/
282 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
283 # usr/lib/libedit.tbd
284 # vs
285 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000286 if os.path.join(sysroot, p[1:]) == dirname:
287 return [ ]
288
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000289 if p == dirname:
290 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000291
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000292 # Otherwise, it must have been in one of the additional directories,
293 # so we have to figure out which one.
294 for p in paths:
295 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000296 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000297
Victor Stinner4cbea512019-02-28 17:48:38 +0100298 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000299 if os.path.join(sysroot, p[1:]) == dirname:
300 return [ p ]
301
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000302 if p == dirname:
303 return [p]
304 else:
305 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000306
Paul Ganssle62972d92020-05-16 04:20:06 -0400307def validate_tzpath():
308 base_tzpath = sysconfig.get_config_var('TZPATH')
309 if not base_tzpath:
310 return
311
312 tzpaths = base_tzpath.split(os.pathsep)
313 bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
314 if bad_paths:
315 raise ValueError('TZPATH must contain only absolute paths, '
316 + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
317 + f'{bad_paths!r}')
Victor Stinnerc991f242019-03-01 17:19:04 +0100318
Jack Jansen144ebcc2001-08-05 22:31:19 +0000319def find_module_file(module, dirlist):
320 """Find a module in a set of possible folders. If it is not found
321 return the unadorned filename"""
322 list = find_file(module, [], dirlist)
323 if not list:
324 return module
325 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100326 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000327 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000328
Victor Stinnerc991f242019-03-01 17:19:04 +0100329
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000330class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000331
Guido van Rossumd8faa362007-04-27 19:54:29 +0000332 def __init__(self, dist):
333 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100334 self.srcdir = None
335 self.lib_dirs = None
336 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100337 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000338 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400339 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100340 self.missing = []
Christian Heimes9b60e552020-05-15 23:54:53 +0200341 self.disabled_configure = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200342 if '-j' in os.environ.get('MAKEFLAGS', ''):
343 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000344
Victor Stinner8058bda2019-03-01 15:31:45 +0100345 def add(self, ext):
346 self.extensions.append(ext)
347
Victor Stinner00c77ae2020-03-04 18:44:49 +0100348 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100349 self.srcdir = sysconfig.get_config_var('srcdir')
350 if not self.srcdir:
351 # Maybe running on Windows but not using CYGWIN?
352 raise ValueError("No source directory; cannot proceed.")
353 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000354
Victor Stinner00c77ae2020-03-04 18:44:49 +0100355 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000356 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000357 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100358 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000359 # move ctypes to the end, it depends on other modules
360 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
361 if "_ctypes" in ext_map:
362 ctypes = extensions.pop(ext_map["_ctypes"])
363 extensions.append(ctypes)
364 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000365
Victor Stinner00c77ae2020-03-04 18:44:49 +0100366 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000367 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000368 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100369 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000370
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000371 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100372 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000373 for filename in self.distribution.scripts]
374
Christian Heimesaf98da12008-01-27 15:18:18 +0000375 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000376 headers = [sysconfig.get_config_h_filename()]
Stefan Kraheb977da2012-02-29 14:10:53 +0100377 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000378
Xavier de Gaye84968b72016-10-29 16:57:20 +0200379 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000380 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000381 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000382 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000383 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000384 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000385 else:
386 ext.depends = []
387 # re-compile extensions if a header file has been changed
388 ext.depends.extend(headers)
389
Victor Stinner00c77ae2020-03-04 18:44:49 +0100390 def remove_configured_extensions(self):
391 # The sysconfig variables built by makesetup that list the already
392 # built modules and the disabled modules as configured by the Setup
393 # files.
394 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
395 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
396
397 mods_built = []
398 mods_disabled = []
399 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200400 # If a module has already been built or has been disabled in the
401 # Setup files, don't build it here.
402 if ext.name in sysconf_built:
403 mods_built.append(ext)
404 if ext.name in sysconf_dis:
405 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000406
xdegayec0364fc2017-05-27 18:25:03 +0200407 mods_configured = mods_built + mods_disabled
408 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200409 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200410 mods_configured]
411 # Remove the shared libraries built by a previous build.
412 for ext in mods_configured:
413 fullpath = self.get_ext_fullpath(ext.name)
414 if os.path.exists(fullpath):
415 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000416
Victor Stinner00c77ae2020-03-04 18:44:49 +0100417 return (mods_built, mods_disabled)
418
419 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000420 # When you run "make CC=altcc" or something similar, you really want
421 # those environment variables passed into the setup.py phase. Here's
422 # a small set of useful ones.
423 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000424 args = {}
425 # unfortunately, distutils doesn't let us provide separate C and C++
426 # compilers
427 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000428 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
429 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000430 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000431
Victor Stinner00c77ae2020-03-04 18:44:49 +0100432 def build_extensions(self):
433 self.set_srcdir()
434
435 # Detect which modules should be compiled
436 self.detect_modules()
437
438 self.remove_disabled()
439
440 self.update_sources_depends()
441 mods_built, mods_disabled = self.remove_configured_extensions()
442 self.set_compiler_executables()
443
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000444 build_ext.build_extensions(self)
445
Victor Stinner1ec63b62020-03-04 14:50:19 +0100446 if SUBPROCESS_BOOTSTRAP:
447 # Drop our custom subprocess module:
448 # use the newly built subprocess module
449 del sys.modules['subprocess']
450
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200451 for ext in self.extensions:
452 self.check_extension_import(ext)
453
Victor Stinner00c77ae2020-03-04 18:44:49 +0100454 self.summary(mods_built, mods_disabled)
455
456 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300457 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400458 if self.failed or self.failed_on_import:
459 all_failed = self.failed + self.failed_on_import
460 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000461
462 def print_three_column(lst):
463 lst.sort(key=str.lower)
464 # guarantee zip() doesn't drop anything
465 while len(lst) % 3:
466 lst.append("")
467 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
468 print("%-*s %-*s %-*s" % (longest, e, longest, f,
469 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000470
Victor Stinner8058bda2019-03-01 15:31:45 +0100471 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000472 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400473 print("Python build finished successfully!")
474 print("The necessary bits to build these optional modules were not "
475 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100476 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000477 print("To find the necessary bits, look in setup.py in"
478 " detect_modules() for the module's name.")
479 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000480
xdegayec0364fc2017-05-27 18:25:03 +0200481 if mods_built:
482 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200483 print("The following modules found by detect_modules() in"
484 " setup.py, have been")
485 print("built by the Makefile instead, as configured by the"
486 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200487 print_three_column([ext.name for ext in mods_built])
488 print()
489
490 if mods_disabled:
491 print()
492 print("The following modules found by detect_modules() in"
493 " setup.py have not")
494 print("been built, they are *disabled* in the Setup files:")
495 print_three_column([ext.name for ext in mods_disabled])
496 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200497
Christian Heimes9b60e552020-05-15 23:54:53 +0200498 if self.disabled_configure:
499 print()
500 print("The following modules found by detect_modules() in"
501 " setup.py have not")
502 print("been built, they are *disabled* by configure:")
503 print_three_column(self.disabled_configure)
504 print()
505
Guido van Rossumd8faa362007-04-27 19:54:29 +0000506 if self.failed:
507 failed = self.failed[:]
508 print()
509 print("Failed to build these modules:")
510 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000511 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000512
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400513 if self.failed_on_import:
514 failed = self.failed_on_import[:]
515 print()
516 print("Following modules built successfully"
517 " but were removed because they could not be imported:")
518 print_three_column(failed)
519 print()
520
Christian Heimes61d478c2018-01-27 15:51:38 +0100521 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100522 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100523 print()
524 print("Could not build the ssl module!")
525 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
526 "libssl with X509_VERIFY_PARAM_set1_host().")
527 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
528 "APIs, https://github.com/libressl-portable/portable/issues/381")
529 print()
530
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000531 def build_extension(self, ext):
532
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000533 if ext.name == '_ctypes':
534 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500535 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000536 return
537
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000538 try:
539 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000540 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000541 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100542 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000543 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000544 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200545
546 def check_extension_import(self, ext):
547 # Don't try to import an extension that has failed to compile
548 if ext.name in self.failed:
549 self.announce(
550 'WARNING: skipping import check for failed build "%s"' %
551 ext.name, level=1)
552 return
553
Jack Jansenf49c6f92001-11-01 14:44:15 +0000554 # Workaround for Mac OS X: The Carbon-based modules cannot be
555 # reliably imported into a command-line Python
556 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000557 self.announce(
558 'WARNING: skipping import check for Carbon-based "%s"' %
559 ext.name)
560 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000561
Victor Stinner4cbea512019-02-28 17:48:38 +0100562 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000563 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000564 # Don't bother doing an import check when an extension was
565 # build with an explicit '-arch' flag on OSX. That's currently
566 # only used to build 32-bit only extensions in a 4-way
567 # universal build and loading 32-bit code into a 64-bit
568 # process will fail.
569 self.announce(
570 'WARNING: skipping import check for "%s"' %
571 ext.name)
572 return
573
Jason Tishler24cf7762002-05-22 16:46:15 +0000574 # Workaround for Cygwin: Cygwin currently has fork issues when many
575 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100576 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000577 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
578 % ext.name)
579 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000580 ext_filename = os.path.join(
581 self.build_lib,
582 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000583
584 # If the build directory didn't exist when setup.py was
585 # started, sys.path_importer_cache has a negative result
586 # cached. Clear that cache before trying to import.
587 sys.path_importer_cache.clear()
588
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200589 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100590 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200591 return
592
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400593 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700594 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
595 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000596 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400597 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000598 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400599 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000600 self.announce('*** WARNING: renaming "%s" since importing it'
601 ' failed: %s' % (ext.name, why), level=3)
602 assert not self.inplace
603 basename, tail = os.path.splitext(ext_filename)
604 newname = basename + "_failed" + tail
605 if os.path.exists(newname):
606 os.remove(newname)
607 os.rename(ext_filename, newname)
608
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000609 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000610 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000611 self.announce('*** WARNING: importing extension "%s" '
612 'failed with %s: %s' % (ext.name, exc_type, why),
613 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000614 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000615
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400616 def add_multiarch_paths(self):
617 # Debian/Ubuntu multiarch support.
618 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200619 cc = sysconfig.get_config_var('CC')
620 tmpfile = os.path.join(self.build_temp, 'multiarch')
621 if not os.path.exists(self.build_temp):
622 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200623 ret = run_command(
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200624 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
625 multiarch_path_component = ''
626 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200627 if ret == 0:
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200628 with open(tmpfile) as fp:
629 multiarch_path_component = fp.readline().strip()
630 finally:
631 os.unlink(tmpfile)
632
633 if multiarch_path_component != '':
634 add_dir_to_list(self.compiler.library_dirs,
635 '/usr/lib/' + multiarch_path_component)
636 add_dir_to_list(self.compiler.include_dirs,
637 '/usr/include/' + multiarch_path_component)
638 return
639
Barry Warsaw88e19452011-04-07 10:40:36 -0400640 if not find_executable('dpkg-architecture'):
641 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200642 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100643 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200644 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400645 tmpfile = os.path.join(self.build_temp, 'multiarch')
646 if not os.path.exists(self.build_temp):
647 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200648 ret = run_command(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200649 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
650 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400651 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200652 if ret == 0:
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400653 with open(tmpfile) as fp:
654 multiarch_path_component = fp.readline().strip()
655 add_dir_to_list(self.compiler.library_dirs,
656 '/usr/lib/' + multiarch_path_component)
657 add_dir_to_list(self.compiler.include_dirs,
658 '/usr/include/' + multiarch_path_component)
659 finally:
660 os.unlink(tmpfile)
661
pxinwr32f5fdd2019-02-27 19:09:28 +0800662 def add_cross_compiling_paths(self):
663 cc = sysconfig.get_config_var('CC')
664 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200665 if not os.path.exists(self.build_temp):
666 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200667 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200668 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800669 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200670 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200671 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200672 if ret == 0:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200673 with open(tmpfile) as fp:
674 for line in fp.readlines():
675 if line.startswith("gcc version"):
676 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800677 elif line.startswith("clang version"):
678 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200679 elif line.startswith("#include <...>"):
680 in_incdirs = True
681 elif line.startswith("End of search list"):
682 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800683 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200684 for d in line.strip().split("=")[1].split(":"):
685 d = os.path.normpath(d)
686 if '/gcc/' not in d:
687 add_dir_to_list(self.compiler.library_dirs,
688 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800689 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 +0200690 add_dir_to_list(self.compiler.include_dirs,
691 line.strip())
692 finally:
693 os.unlink(tmpfile)
694
Victor Stinnercfe172d2019-03-01 18:21:49 +0100695 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000696 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000697 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000698 # We must get the values from the Makefile and not the environment
699 # directly since an inconsistently reproducible issue comes up where
700 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000701 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000702 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000703 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
704 ('LDFLAGS', '-L', self.compiler.library_dirs),
705 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000706 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000707 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800708 parser = argparse.ArgumentParser()
709 parser.add_argument(arg_name, dest="dirs", action="append")
710 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000711 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000712 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000713 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000714
Victor Stinnercfe172d2019-03-01 18:21:49 +0100715 def configure_compiler(self):
716 # Ensure that /usr/local is always used, but the local build
717 # directories (i.e. '.' and 'Include') must be first. See issue
718 # 10520.
719 if not CROSS_COMPILING:
720 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
721 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
722 # only change this for cross builds for 3.3, issues on Mageia
723 if CROSS_COMPILING:
724 self.add_cross_compiling_paths()
725 self.add_multiarch_paths()
726 self.add_ldflags_cppflags()
727
Victor Stinner5ec33a12019-03-01 16:43:28 +0100728 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100729 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100730 os.path.normpath(sys.base_prefix) != '/usr' and
731 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000732 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
733 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
734 # building a framework with different architectures than
735 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000736 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000737 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000738 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000739 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000740
xdegaye77f51392017-11-25 17:25:30 +0100741 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
742 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000743 # lib_dirs and inc_dirs are used to search for files;
744 # if a file is found in one of those directories, it can
745 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100746 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100747 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
748 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100749 else:
xdegaye77f51392017-11-25 17:25:30 +0100750 # Add the sysroot paths. 'sysroot' is a compiler option used to
751 # set the logical path of the standard system headers and
752 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100753 self.lib_dirs = (self.compiler.library_dirs +
754 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
755 self.inc_dirs = (self.compiler.include_dirs +
756 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
757 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000758
Brett Cannon4454a1f2005-04-15 20:32:39 +0000759 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000760 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100761 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000762
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000763 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100764 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100765 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000766
Charles-François Natali5739e102012-04-12 19:07:25 +0200767 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100768 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100769 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200770
Victor Stinner4cbea512019-02-28 17:48:38 +0100771 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000772 # This should work on any unixy platform ;-)
773 # If the user has bothered specifying additional -I and -L flags
774 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000775 #
776 # NOTE: using shlex.split would technically be more correct, but
777 # also gives a bootstrap problem. Let's hope nobody uses
778 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000779 cflags, ldflags = sysconfig.get_config_vars(
780 'CFLAGS', 'LDFLAGS')
781 for item in cflags.split():
782 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100783 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000784
785 for item in ldflags.split():
786 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100787 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000788
Victor Stinner5ec33a12019-03-01 16:43:28 +0100789 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000790 #
791 # The following modules are all pretty straightforward, and compile
792 # on pretty much any POSIXish platform.
793 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000794
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000795 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100796 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000797
Yury Selivanovf23746a2018-01-22 19:11:18 -0500798 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100799 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500800
Martin Panterc9deece2016-02-03 05:19:44 +0000801 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100802
803 # math library functions, e.g. sin()
804 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100805 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100806 extra_objects=[shared_math],
807 depends=['_math.h', shared_math],
808 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100809
810 # complex math library functions
811 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100812 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100813 extra_objects=[shared_math],
814 depends=['_math.h', shared_math],
815 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200816
817 # time libraries: librt may be needed for clock_gettime()
818 time_libs = []
819 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
820 if lib:
821 time_libs.append(lib)
822
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000823 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100824 self.add(Extension('time', ['timemodule.c'],
825 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800826 # libm is needed by delta_new() that uses round() and by accum() that
827 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100828 self.add(Extension('_datetime', ['_datetimemodule.c'],
829 libraries=['m']))
Paul Ganssle62972d92020-05-16 04:20:06 -0400830 # zoneinfo module
831 self.add(Extension('_zoneinfo', ['_zoneinfo.c'])),
Christian Heimesfe337bf2008-03-23 21:54:12 +0000832 # random number generator implemented in C
Victor Stinner9f5fe792020-04-17 19:05:35 +0200833 self.add(Extension("_random", ["_randommodule.c"],
834 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000835 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100836 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000837 # heapq
Victor Stinner8058bda2019-03-01 15:31:45 +0100838 self.add(Extension("_heapq", ["_heapqmodule.c"]))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000839 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200840 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200841 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Collin Winter670e6922007-03-21 02:57:17 +0000842 # atexit
Victor Stinner8058bda2019-03-01 15:31:45 +0100843 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10 +0000844 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100845 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200846 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100847
Fred Drake0e474a82007-10-11 18:01:43 +0000848 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100849 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000850 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100851 self.add(Extension('unicodedata', ['unicodedata.c'],
852 depends=['unicodedata_db.h', 'unicodename_db.h']))
Larry Hastings3a907972013-11-23 14:49:22 -0800853 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100854 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900855 # asyncio speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100856 self.add(Extension("_asyncio", ["_asynciomodule.c"]))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000857 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100858 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100859 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100860 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900861 # _statistics module
862 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000863
864 # Modules with some UNIX dependencies -- on by default:
865 # (If you have a really backward UNIX, select and socket may not be
866 # supported...)
867
868 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000869 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100870 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000871 # May be necessary on AIX for flock function
872 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100873 self.add(Extension('fcntl', ['fcntlmodule.c'],
874 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000875 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100876 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000877 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800878 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100879 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000880 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100881 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
882 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100883 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200884 # AIX has shadow passwords, but access is not via getspent(), etc.
885 # module support is not expected so it not 'missing'
886 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100887 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000888
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000889 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100890 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000891
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000892 # Fred Drake's interface to the Python parser
Victor Stinner8058bda2019-03-01 15:31:45 +0100893 self.add(Extension('parser', ['parsermodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000894
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000895 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100896 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000897
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000898 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000899 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100900 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000901
Eric Snow7f8bfc92018-01-29 18:23:44 -0700902 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600903 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700904
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000905 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000906 # Here ends the simple stuff. From here on, modules need certain
907 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000908 #
909
910 # Multimedia modules
911 # These don't work for 64-bit platforms!!!
912 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200913 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000914 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000915 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000916 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200917 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800918 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100919 self.add(Extension('audioop', ['audioop.c'],
920 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000921
Victor Stinner5ec33a12019-03-01 16:43:28 +0100922 # CSV files
923 self.add(Extension('_csv', ['_csv.c']))
924
925 # POSIX subprocess module helper.
926 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
927
Victor Stinnercfe172d2019-03-01 18:21:49 +0100928 def detect_test_extensions(self):
929 # Python C API test module
930 self.add(Extension('_testcapi', ['_testcapimodule.c'],
931 depends=['testcapi_long.h']))
932
Victor Stinner23bace22019-04-18 11:37:26 +0200933 # Python Internal C API test module
934 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +0200935 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +0200936
Victor Stinnercfe172d2019-03-01 18:21:49 +0100937 # Python PEP-3118 (buffer protocol) test module
938 self.add(Extension('_testbuffer', ['_testbuffer.c']))
939
940 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
941 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
942
943 # Test multi-phase extension module init (PEP 489)
944 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
945
946 # Fuzz tests.
947 self.add(Extension('_xxtestfuzz',
948 ['_xxtestfuzz/_xxtestfuzz.c',
949 '_xxtestfuzz/fuzzer.c']))
950
Victor Stinner5ec33a12019-03-01 16:43:28 +0100951 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000952 # readline
Victor Stinner625dbf22019-03-01 15:59:39 +0100953 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000954 readline_termcap_library = ""
955 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200956 # Cannot use os.popen here in py3k.
957 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
958 if not os.path.exists(self.build_temp):
959 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000960 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200961 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100962 if CROSS_COMPILING:
Victor Stinner6b982c22020-04-01 01:10:07 +0200963 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
doko@ubuntu.com58844492012-06-30 18:25:32 +0200964 % (sysconfig.get_config_var('READELF'),
965 do_readline, tmpfile))
966 elif find_executable('ldd'):
Victor Stinner6b982c22020-04-01 01:10:07 +0200967 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
doko@ubuntu.com58844492012-06-30 18:25:32 +0200968 else:
Victor Stinner6b982c22020-04-01 01:10:07 +0200969 ret = 1
970 if ret == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +0000971 with open(tmpfile) as fp:
972 for ln in fp:
973 if 'curses' in ln:
974 readline_termcap_library = re.sub(
975 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
976 ).rstrip()
977 break
978 # termcap interface split out from ncurses
979 if 'tinfo' in ln:
980 readline_termcap_library = 'tinfo'
981 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200982 if os.path.exists(tmpfile):
983 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +0000984 # Issue 7384: If readline is already linked against curses,
985 # use the same library for the readline and curses modules.
986 if 'curses' in readline_termcap_library:
987 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +0100988 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +0000989 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +0200990 # Issue 36210: OSS provided ncurses does not link on AIX
991 # Use IBM supplied 'curses' for successful build of _curses
992 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
993 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100994 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000995 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100996 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000997 curses_library = 'curses'
998
Victor Stinner4cbea512019-02-28 17:48:38 +0100999 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001000 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +00001001 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -07001002 if (dep_target and
1003 (tuple(int(n) for n in dep_target.split('.')[0:2])
1004 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +00001005 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001006 if os_release < 9:
1007 # MacOSX 10.4 has a broken readline. Don't try to build
1008 # the readline module unless the user has installed a fixed
1009 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +01001010 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001011 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +00001012 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +01001013 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001014 # In every directory on the search path search for a dynamic
1015 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +00001016 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +00001017 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001018 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +00001019 readline_extra_link_args = ('-Wl,-search_paths_first',)
1020 else:
1021 readline_extra_link_args = ()
1022
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001023 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +00001024 if readline_termcap_library:
1025 pass # Issue 7384: Already linked against curses or tinfo.
1026 elif curses_library:
1027 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001028 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001029 ['/usr/lib/termcap'],
1030 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001031 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001032 self.add(Extension('readline', ['readline.c'],
1033 library_dirs=['/usr/lib/termcap'],
1034 extra_link_args=readline_extra_link_args,
1035 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001036 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001037 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001038
Victor Stinner5ec33a12019-03-01 16:43:28 +01001039 # Curses support, requiring the System V version of curses, often
1040 # provided by the ncurses library.
1041 curses_defines = []
1042 curses_includes = []
1043 panel_library = 'panel'
1044 if curses_library == 'ncursesw':
1045 curses_defines.append(('HAVE_NCURSESW', '1'))
1046 if not CROSS_COMPILING:
1047 curses_includes.append('/usr/include/ncursesw')
1048 # Bug 1464056: If _curses.so links with ncursesw,
1049 # _curses_panel.so must link with panelw.
1050 panel_library = 'panelw'
1051 if MACOS:
1052 # On OS X, there is no separate /usr/lib/libncursesw nor
1053 # libpanelw. If we are here, we found a locally-supplied
1054 # version of libncursesw. There should also be a
1055 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1056 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1057 # ncurses wide char support
1058 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1059 elif MACOS and curses_library == 'ncurses':
1060 # Building with the system-suppied combined libncurses/libpanel
1061 curses_defines.append(('HAVE_NCURSESW', '1'))
1062 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001063
Victor Stinnercfe172d2019-03-01 18:21:49 +01001064 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001065 if curses_library.startswith('ncurses'):
1066 curses_libs = [curses_library]
1067 self.add(Extension('_curses', ['_cursesmodule.c'],
1068 include_dirs=curses_includes,
1069 define_macros=curses_defines,
1070 libraries=curses_libs))
1071 elif curses_library == 'curses' and not MACOS:
1072 # OSX has an old Berkeley curses, not good enough for
1073 # the _curses module.
1074 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1075 curses_libs = ['curses', 'terminfo']
1076 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1077 curses_libs = ['curses', 'termcap']
1078 else:
1079 curses_libs = ['curses']
1080
1081 self.add(Extension('_curses', ['_cursesmodule.c'],
1082 define_macros=curses_defines,
1083 libraries=curses_libs))
1084 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001085 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001086 self.missing.append('_curses')
1087
1088 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001089 # _curses_panel needs some form of ncurses
1090 skip_curses_panel = True if AIX else False
1091 if (curses_enabled and not skip_curses_panel and
1092 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001093 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001094 include_dirs=curses_includes,
1095 define_macros=curses_defines,
1096 libraries=[panel_library, *curses_libs]))
1097 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001098 self.missing.append('_curses_panel')
1099
1100 def detect_crypt(self):
1101 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001102 if VXWORKS:
1103 # bpo-31904: crypt() function is not provided by VxWorks.
1104 # DES_crypt() OpenSSL provides is too weak to implement
1105 # the encryption.
1106 return
1107
Victor Stinner625dbf22019-03-01 15:59:39 +01001108 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001109 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001110 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001111 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001112
pxinwr236d0b72019-04-15 17:02:20 +08001113 self.add(Extension('_crypt', ['_cryptmodule.c'],
Victor Stinner8058bda2019-03-01 15:31:45 +01001114 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001115
Victor Stinner5ec33a12019-03-01 16:43:28 +01001116 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001117 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +08001118 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +01001119 self.add(Extension('_socket', ['socketmodule.c'],
1120 depends=['socketmodule.h']))
Victor Stinner625dbf22019-03-01 15:59:39 +01001121 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 19:09:28 +08001122 libs = ['net']
Victor Stinner8058bda2019-03-01 15:31:45 +01001123 self.add(Extension('_socket', ['socketmodule.c'],
1124 depends=['socketmodule.h'],
1125 libraries=libs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001126
Victor Stinner5ec33a12019-03-01 16:43:28 +01001127 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001128 # Modules that provide persistent dictionary-like semantics. You will
1129 # probably want to arrange for at least one of them to be available on
1130 # your machine, though none are defined by default because of library
1131 # dependencies. The Python module dbm/__init__.py provides an
1132 # implementation independent wrapper for these; dbm/dumb.py provides
1133 # similar functionality (but slower of course) implemented in Python.
1134
1135 # Sleepycat^WOracle Berkeley DB interface.
1136 # http://www.oracle.com/database/berkeley-db/db/index.html
1137 #
1138 # This requires the Sleepycat^WOracle DB code. The supported versions
1139 # are set below. Visit the URL above to download
1140 # a release. Most open source OSes come with one or more
1141 # versions of BerkeleyDB already installed.
1142
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001143 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001144 min_db_ver = (3, 3)
1145 db_setup_debug = False # verbose debug prints from this script?
1146
1147 def allow_db_ver(db_ver):
1148 """Returns a boolean if the given BerkeleyDB version is acceptable.
1149
1150 Args:
1151 db_ver: A tuple of the version to verify.
1152 """
1153 if not (min_db_ver <= db_ver <= max_db_ver):
1154 return False
1155 return True
1156
1157 def gen_db_minor_ver_nums(major):
1158 if major == 4:
1159 for x in range(max_db_ver[1]+1):
1160 if allow_db_ver((4, x)):
1161 yield x
1162 elif major == 3:
1163 for x in (3,):
1164 if allow_db_ver((3, x)):
1165 yield x
1166 else:
1167 raise ValueError("unknown major BerkeleyDB version", major)
1168
1169 # construct a list of paths to look for the header file in on
1170 # top of the normal inc_dirs.
1171 db_inc_paths = [
1172 '/usr/include/db4',
1173 '/usr/local/include/db4',
1174 '/opt/sfw/include/db4',
1175 '/usr/include/db3',
1176 '/usr/local/include/db3',
1177 '/opt/sfw/include/db3',
1178 # Fink defaults (http://fink.sourceforge.net/)
1179 '/sw/include/db4',
1180 '/sw/include/db3',
1181 ]
1182 # 4.x minor number specific paths
1183 for x in gen_db_minor_ver_nums(4):
1184 db_inc_paths.append('/usr/include/db4%d' % x)
1185 db_inc_paths.append('/usr/include/db4.%d' % x)
1186 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1187 db_inc_paths.append('/usr/local/include/db4%d' % x)
1188 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1189 db_inc_paths.append('/opt/db-4.%d/include' % x)
1190 # MacPorts default (http://www.macports.org/)
1191 db_inc_paths.append('/opt/local/include/db4%d' % x)
1192 # 3.x minor number specific paths
1193 for x in gen_db_minor_ver_nums(3):
1194 db_inc_paths.append('/usr/include/db3%d' % x)
1195 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1196 db_inc_paths.append('/usr/local/include/db3%d' % x)
1197 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1198 db_inc_paths.append('/opt/db-3.%d/include' % x)
1199
Victor Stinner4cbea512019-02-28 17:48:38 +01001200 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001201 db_inc_paths = []
1202
Georg Brandl489cb4f2009-07-11 10:08:49 +00001203 # Add some common subdirectories for Sleepycat DB to the list,
1204 # based on the standard include directories. This way DB3/4 gets
1205 # picked up when it is installed in a non-standard prefix and
1206 # the user has added that prefix into inc_dirs.
1207 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001208 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001209 std_variants.append(os.path.join(dn, 'db3'))
1210 std_variants.append(os.path.join(dn, 'db4'))
1211 for x in gen_db_minor_ver_nums(4):
1212 std_variants.append(os.path.join(dn, "db4%d"%x))
1213 std_variants.append(os.path.join(dn, "db4.%d"%x))
1214 for x in gen_db_minor_ver_nums(3):
1215 std_variants.append(os.path.join(dn, "db3%d"%x))
1216 std_variants.append(os.path.join(dn, "db3.%d"%x))
1217
1218 db_inc_paths = std_variants + db_inc_paths
1219 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1220
1221 db_ver_inc_map = {}
1222
Victor Stinner4cbea512019-02-28 17:48:38 +01001223 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001224 sysroot = macosx_sdk_root()
1225
Georg Brandl489cb4f2009-07-11 10:08:49 +00001226 class db_found(Exception): pass
1227 try:
1228 # See whether there is a Sleepycat header in the standard
1229 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001230 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001231 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001232 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001233 f = os.path.join(sysroot, d[1:], "db.h")
1234
Georg Brandl489cb4f2009-07-11 10:08:49 +00001235 if db_setup_debug: print("db: looking for db.h in", f)
1236 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001237 with open(f, 'rb') as file:
1238 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001239 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001240 if m:
1241 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001242 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001243 db_minor = int(m.group(1))
1244 db_ver = (db_major, db_minor)
1245
1246 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1247 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001248 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001249 db_patch = int(m.group(1))
1250 if db_patch < 21:
1251 print("db.h:", db_ver, "patch", db_patch,
1252 "being ignored (4.6.x must be >= 4.6.21)")
1253 continue
1254
1255 if ( (db_ver not in db_ver_inc_map) and
1256 allow_db_ver(db_ver) ):
1257 # save the include directory with the db.h version
1258 # (first occurrence only)
1259 db_ver_inc_map[db_ver] = d
1260 if db_setup_debug:
1261 print("db.h: found", db_ver, "in", d)
1262 else:
1263 # we already found a header for this library version
1264 if db_setup_debug: print("db.h: ignoring", d)
1265 else:
1266 # ignore this header, it didn't contain a version number
1267 if db_setup_debug:
1268 print("db.h: no version number version in", d)
1269
1270 db_found_vers = list(db_ver_inc_map.keys())
1271 db_found_vers.sort()
1272
1273 while db_found_vers:
1274 db_ver = db_found_vers.pop()
1275 db_incdir = db_ver_inc_map[db_ver]
1276
1277 # check lib directories parallel to the location of the header
1278 db_dirs_to_check = [
1279 db_incdir.replace("include", 'lib64'),
1280 db_incdir.replace("include", 'lib'),
1281 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001282
Victor Stinner4cbea512019-02-28 17:48:38 +01001283 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001284 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1285
1286 else:
1287 # Same as other branch, but takes OSX SDK into account
1288 tmp = []
1289 for dn in db_dirs_to_check:
1290 if is_macosx_sdk_path(dn):
1291 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1292 tmp.append(dn)
1293 else:
1294 if os.path.isdir(dn):
1295 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001296 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001297
1298 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001299
Ezio Melotti42da6632011-03-15 05:18:48 +02001300 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001301 # XXX should we -ever- look for a dbX name? Do any
1302 # systems really not name their library by version and
1303 # symlink to more general names?
1304 for dblib in (('db-%d.%d' % db_ver),
1305 ('db%d%d' % db_ver),
1306 ('db%d' % db_ver[0])):
1307 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001308 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001309 if dblib_file:
1310 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1311 raise db_found
1312 else:
1313 if db_setup_debug: print("db lib: ", dblib, "not found")
1314
1315 except db_found:
1316 if db_setup_debug:
1317 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1318 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001319 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001320 # Only add the found library and include directories if they aren't
1321 # already being searched. This avoids an explicit runtime library
1322 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001323 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001324 db_incs = None
1325 else:
1326 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001327 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001328 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001329 else:
1330 if db_setup_debug: print("db: no appropriate library found")
1331 db_incs = None
1332 dblibs = []
1333 dblib_dir = None
1334
Victor Stinner5ec33a12019-03-01 16:43:28 +01001335 dbm_setup_debug = False # verbose debug prints from this script?
1336 dbm_order = ['gdbm']
1337 # The standard Unix dbm module:
1338 if not CYGWIN:
1339 config_args = [arg.strip("'")
1340 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1341 dbm_args = [arg for arg in config_args
1342 if arg.startswith('--with-dbmliborder=')]
1343 if dbm_args:
1344 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1345 else:
1346 dbm_order = "ndbm:gdbm:bdb".split(":")
1347 dbmext = None
1348 for cand in dbm_order:
1349 if cand == "ndbm":
1350 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1351 # Some systems have -lndbm, others have -lgdbm_compat,
1352 # others don't have either
1353 if self.compiler.find_library_file(self.lib_dirs,
1354 'ndbm'):
1355 ndbm_libs = ['ndbm']
1356 elif self.compiler.find_library_file(self.lib_dirs,
1357 'gdbm_compat'):
1358 ndbm_libs = ['gdbm_compat']
1359 else:
1360 ndbm_libs = []
1361 if dbm_setup_debug: print("building dbm using ndbm")
1362 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1363 define_macros=[
1364 ('HAVE_NDBM_H',None),
1365 ],
1366 libraries=ndbm_libs)
1367 break
1368
1369 elif cand == "gdbm":
1370 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1371 gdbm_libs = ['gdbm']
1372 if self.compiler.find_library_file(self.lib_dirs,
1373 'gdbm_compat'):
1374 gdbm_libs.append('gdbm_compat')
1375 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1376 if dbm_setup_debug: print("building dbm using gdbm")
1377 dbmext = Extension(
1378 '_dbm', ['_dbmmodule.c'],
1379 define_macros=[
1380 ('HAVE_GDBM_NDBM_H', None),
1381 ],
1382 libraries = gdbm_libs)
1383 break
1384 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1385 if dbm_setup_debug: print("building dbm using gdbm")
1386 dbmext = Extension(
1387 '_dbm', ['_dbmmodule.c'],
1388 define_macros=[
1389 ('HAVE_GDBM_DASH_NDBM_H', None),
1390 ],
1391 libraries = gdbm_libs)
1392 break
1393 elif cand == "bdb":
1394 if dblibs:
1395 if dbm_setup_debug: print("building dbm using bdb")
1396 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1397 library_dirs=dblib_dir,
1398 runtime_library_dirs=dblib_dir,
1399 include_dirs=db_incs,
1400 define_macros=[
1401 ('HAVE_BERKDB_H', None),
1402 ('DB_DBM_HSEARCH', None),
1403 ],
1404 libraries=dblibs)
1405 break
1406 if dbmext is not None:
1407 self.add(dbmext)
1408 else:
1409 self.missing.append('_dbm')
1410
1411 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1412 if ('gdbm' in dbm_order and
1413 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1414 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1415 libraries=['gdbm']))
1416 else:
1417 self.missing.append('_gdbm')
1418
1419 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001420 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001421 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001422
1423 # We hunt for #define SQLITE_VERSION "n.n.n"
Charles Pigottad0daf52019-04-26 16:38:12 +01001424 # We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001425 sqlite_incdir = sqlite_libdir = None
1426 sqlite_inc_paths = [ '/usr/include',
1427 '/usr/include/sqlite',
1428 '/usr/include/sqlite3',
1429 '/usr/local/include',
1430 '/usr/local/include/sqlite',
1431 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001432 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001433 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001434 sqlite_inc_paths = []
gescheitb9a03762019-07-13 06:15:49 +03001435 MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001436 MIN_SQLITE_VERSION = ".".join([str(x)
1437 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001438
1439 # Scan the default include directories before the SQLite specific
1440 # ones. This allows one to override the copy of sqlite on OSX,
1441 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001442 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001443 sysroot = macosx_sdk_root()
1444
Victor Stinner625dbf22019-03-01 15:59:39 +01001445 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001446 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001447 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001448 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001449
Ned Deily9b635832012-08-05 15:13:33 -07001450 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001451 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001452 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001453 with open(f) as file:
1454 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001455 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001456 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001457 if m:
1458 sqlite_version = m.group(1)
1459 sqlite_version_tuple = tuple([int(x)
1460 for x in sqlite_version.split(".")])
1461 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1462 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001463 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001464 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001465 sqlite_incdir = d
1466 break
1467 else:
1468 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001469 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001470 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001471 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001472 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001473
1474 if sqlite_incdir:
1475 sqlite_dirs_to_check = [
1476 os.path.join(sqlite_incdir, '..', 'lib64'),
1477 os.path.join(sqlite_incdir, '..', 'lib'),
1478 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1479 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1480 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001481 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001482 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001483 if sqlite_libfile:
1484 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001485
1486 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001487 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001488 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001489 '_sqlite/cursor.c',
1490 '_sqlite/microprotocols.c',
1491 '_sqlite/module.c',
1492 '_sqlite/prepare_protocol.c',
1493 '_sqlite/row.c',
1494 '_sqlite/statement.c',
1495 '_sqlite/util.c', ]
1496
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001497 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001498 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001499 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1500 else:
1501 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1502
Benjamin Peterson076ed002010-10-31 17:11:02 +00001503 # Enable support for loadable extensions in the sqlite3 module
1504 # if --enable-loadable-sqlite-extensions configure option is used.
1505 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1506 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001507
Victor Stinner4cbea512019-02-28 17:48:38 +01001508 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001509 # In every directory on the search path search for a dynamic
1510 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001511 # for dynamic libraries on the entire path.
1512 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001513 # before the dynamic library in /usr/lib.
1514 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1515 else:
1516 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001517
Brett Cannonc5011fe2011-06-06 20:09:10 -07001518 include_dirs = ["Modules/_sqlite"]
1519 # Only include the directory where sqlite was found if it does
1520 # not already exist in set include directories, otherwise you
1521 # can end up with a bad search path order.
1522 if sqlite_incdir not in self.compiler.include_dirs:
1523 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001524 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001525 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001526 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001527 self.add(Extension('_sqlite3', sqlite_srcs,
1528 define_macros=sqlite_defines,
1529 include_dirs=include_dirs,
1530 library_dirs=sqlite_libdir,
1531 extra_link_args=sqlite_extra_link_args,
1532 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001533 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001534 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001535
Victor Stinner5ec33a12019-03-01 16:43:28 +01001536 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001537 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001538 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001539 if not VXWORKS:
1540 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001541 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001542 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001543 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001544 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001545 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001546
Victor Stinner5ec33a12019-03-01 16:43:28 +01001547 # Platform-specific libraries
1548 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1549 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001550 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001551 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001552
Victor Stinner5ec33a12019-03-01 16:43:28 +01001553 if MACOS:
1554 self.add(Extension('_scproxy', ['_scproxy.c'],
1555 extra_link_args=[
1556 '-framework', 'SystemConfiguration',
1557 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001558
Victor Stinner5ec33a12019-03-01 16:43:28 +01001559 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001560 # Andrew Kuchling's zlib module. Note that some versions of zlib
1561 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1562 # http://www.cert.org/advisories/CA-2002-07.html
1563 #
1564 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1565 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1566 # now, we still accept 1.1.3, because we think it's difficult to
1567 # exploit this in Python, and we'd rather make it RedHat's problem
1568 # than our problem <wink>.
1569 #
1570 # You can upgrade zlib to version 1.1.4 yourself by going to
1571 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001572 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001573 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001574 if zlib_inc is not None:
1575 zlib_h = zlib_inc[0] + '/zlib.h'
1576 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001577 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001578 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001579 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001580 with open(zlib_h) as fp:
1581 while 1:
1582 line = fp.readline()
1583 if not line:
1584 break
1585 if line.startswith('#define ZLIB_VERSION'):
1586 version = line.split()[2]
1587 break
Guido van Rossume6970912001-04-15 15:16:12 +00001588 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001589 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001590 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001591 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1592 else:
1593 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001594 self.add(Extension('zlib', ['zlibmodule.c'],
1595 libraries=['z'],
1596 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001597 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001598 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001599 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001600 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001601 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001602 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001603 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001604
Christian Heimes1dc54002008-03-24 02:19:29 +00001605 # Helper module for various ascii-encoders. Uses zlib for an optimized
1606 # crc32 if we have it. Otherwise binascii uses its own.
1607 if have_zlib:
1608 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1609 libraries = ['z']
1610 extra_link_args = zlib_extra_link_args
1611 else:
1612 extra_compile_args = []
1613 libraries = []
1614 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001615 self.add(Extension('binascii', ['binascii.c'],
1616 extra_compile_args=extra_compile_args,
1617 libraries=libraries,
1618 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001619
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001620 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001621 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001622 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001623 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1624 else:
1625 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001626 self.add(Extension('_bz2', ['_bz2module.c'],
1627 libraries=['bz2'],
1628 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001629 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001630 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001631
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001632 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001633 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001634 self.add(Extension('_lzma', ['_lzmamodule.c'],
1635 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001636 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001637 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001638
Victor Stinner5ec33a12019-03-01 16:43:28 +01001639 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001640 # Interface to the Expat XML parser
1641 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001642 # Expat was written by James Clark and is now maintained by a group of
1643 # developers on SourceForge; see www.libexpat.org for more information.
1644 # The pyexpat module was written by Paul Prescod after a prototype by
1645 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1646 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001647 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001648 #
1649 # More information on Expat can be found at www.libexpat.org.
1650 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001651 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1652 expat_inc = []
1653 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001654 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001655 expat_lib = ['expat']
1656 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001657 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001658 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001659 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001660 define_macros = [
1661 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001662 # bpo-30947: Python uses best available entropy sources to
1663 # call XML_SetHashSalt(), expat entropy sources are not needed
1664 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001665 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001666 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001667 expat_lib = []
1668 expat_sources = ['expat/xmlparse.c',
1669 'expat/xmlrole.c',
1670 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001671 expat_depends = ['expat/ascii.h',
1672 'expat/asciitab.h',
1673 'expat/expat.h',
1674 'expat/expat_config.h',
1675 'expat/expat_external.h',
1676 'expat/internal.h',
1677 'expat/latin1tab.h',
1678 'expat/utf8tab.h',
1679 'expat/xmlrole.h',
1680 'expat/xmltok.h',
1681 'expat/xmltok_impl.h'
1682 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001683
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001684 cc = sysconfig.get_config_var('CC').split()[0]
Victor Stinner6b982c22020-04-01 01:10:07 +02001685 ret = run_command(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001686 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Victor Stinner6b982c22020-04-01 01:10:07 +02001687 if ret == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001688 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001689
Victor Stinner8058bda2019-03-01 15:31:45 +01001690 self.add(Extension('pyexpat',
1691 define_macros=define_macros,
1692 extra_compile_args=extra_compile_args,
1693 include_dirs=expat_inc,
1694 libraries=expat_lib,
1695 sources=['pyexpat.c'] + expat_sources,
1696 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001697
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001698 # Fredrik Lundh's cElementTree module. Note that this also
1699 # uses expat (via the CAPI hook in pyexpat).
1700
Victor Stinner625dbf22019-03-01 15:59:39 +01001701 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001702 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001703 self.add(Extension('_elementtree',
1704 define_macros=define_macros,
1705 include_dirs=expat_inc,
1706 libraries=expat_lib,
1707 sources=['_elementtree.c'],
1708 depends=['pyexpat.c', *expat_sources,
1709 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001710 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001711 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001712
Victor Stinner5ec33a12019-03-01 16:43:28 +01001713 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001714 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001715 self.add(Extension('_multibytecodec',
1716 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001717 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001718 self.add(Extension('_codecs_%s' % loc,
1719 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001720
Victor Stinner5ec33a12019-03-01 16:43:28 +01001721 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001722 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001723 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001724 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1725 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001726
1727 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001728 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001729 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1730 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001731 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001732 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1733 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 17:19:04 +01001734 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-01 22:52:23 -06001735 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001736 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1737 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001738 libs.append('rt')
Victor Stinner8058bda2019-03-01 15:31:45 +01001739 self.add(Extension('_posixshmem', posixshmem_srcs,
1740 define_macros={},
1741 libraries=libs,
1742 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001743
Victor Stinner8058bda2019-03-01 15:31:45 +01001744 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001745 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001746
Victor Stinner5ec33a12019-03-01 16:43:28 +01001747 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001748 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001749 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001750 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001751 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001752 uuid_libs = ['uuid']
1753 else:
1754 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001755 self.add(Extension('_uuid', ['_uuidmodule.c'],
1756 libraries=uuid_libs,
1757 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001758 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001759 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001760
Victor Stinner5ec33a12019-03-01 16:43:28 +01001761 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001762 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001763 self.init_inc_lib_dirs()
1764
1765 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001766 if TEST_EXTENSIONS:
1767 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001768 self.detect_readline_curses()
1769 self.detect_crypt()
1770 self.detect_socket()
1771 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001772 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001773 self.detect_dbm_gdbm()
1774 self.detect_sqlite()
1775 self.detect_platform_specific_exts()
1776 self.detect_nis()
1777 self.detect_compress_exts()
1778 self.detect_expat_elementtree()
1779 self.detect_multibytecodecs()
1780 self.detect_decimal()
1781 self.detect_ctypes()
1782 self.detect_multiprocessing()
1783 if not self.detect_tkinter():
1784 self.missing.append('_tkinter')
1785 self.detect_uuid()
1786
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001787## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001788## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001789
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001790 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001791 self.add(Extension('xxlimited', ['xxlimited.c'],
1792 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001793
Ned Deilyd819b932013-09-06 01:07:05 -07001794 def detect_tkinter_explicitly(self):
1795 # Build _tkinter using explicit locations for Tcl/Tk.
1796 #
1797 # This is enabled when both arguments are given to ./configure:
1798 #
1799 # --with-tcltk-includes="-I/path/to/tclincludes \
1800 # -I/path/to/tkincludes"
1801 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1802 # -L/path/to/tklibs -ltkm.n"
1803 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001804 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001805 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1806 #
1807 # This can be useful for building and testing tkinter with multiple
1808 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1809 # build of Tcl so you need to specify both arguments and use care when
1810 # overriding.
1811
1812 # The _TCLTK variables are created in the Makefile sharedmods target.
1813 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1814 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1815 if not (tcltk_includes and tcltk_libs):
1816 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001817 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001818
1819 extra_compile_args = tcltk_includes.split()
1820 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001821 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1822 define_macros=[('WITH_APPINIT', 1)],
1823 extra_compile_args = extra_compile_args,
1824 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001825 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001826
Victor Stinner625dbf22019-03-01 15:59:39 +01001827 def detect_tkinter_darwin(self):
Jack Jansen0b06be72002-06-21 14:48:38 +00001828 # The _tkinter module, using frameworks. Since frameworks are quite
1829 # different the UNIX search logic is not sharable.
1830 from os.path import join, exists
1831 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001832 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:48 +00001833 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:38 +00001834 join(os.getenv('HOME'), '/Library/Frameworks')
1835 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001836
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001837 sysroot = macosx_sdk_root()
1838
Skip Montanaro0174ddd2005-12-30 05:01:26 +00001839 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:38 +00001840 # bundles.
1841 # XXX distutils should support -F!
1842 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001843 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001844
1845
Jack Jansen0b06be72002-06-21 14:48:38 +00001846 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001847 if is_macosx_sdk_path(F):
1848 if not exists(join(sysroot, F[1:], fw + '.framework')):
1849 break
1850 else:
1851 if not exists(join(F, fw + '.framework')):
1852 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001853 else:
1854 # ok, F is now directory with both frameworks. Continure
1855 # building
1856 break
1857 else:
1858 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1859 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001860 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001861
Jack Jansen0b06be72002-06-21 14:48:38 +00001862 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1863 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:43 +00001864 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:38 +00001865 #
1866 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001867 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001868 for fw in ('Tcl', 'Tk')
1869 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:38 +00001870 ]
1871
Tim Peters2c60f7a2003-01-29 03:49:43 +00001872 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:38 +00001873 # complicated search, this is a hard-coded path. It could bail out
1874 # if X11 libs are not found...
1875 include_dirs.append('/usr/X11R6/include')
1876 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1877
Georg Brandlfcaf9102008-07-16 02:17:56 +00001878 # All existing framework builds of Tcl/Tk don't support 64-bit
1879 # architectures.
1880 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001881 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001882
Ronald Oussorend097efe2009-09-15 19:07:58 +00001883 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1884 if not os.path.exists(self.build_temp):
1885 os.makedirs(self.build_temp)
1886
1887 # Note: cannot use os.popen or subprocess here, that
1888 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001889 if is_macosx_sdk_path(F):
Victor Stinner6b982c22020-04-01 01:10:07 +02001890 run_command("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001891 else:
Victor Stinner6b982c22020-04-01 01:10:07 +02001892 run_command("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001893
Brett Cannon9f5db072010-10-29 20:19:27 +00001894 with open(tmpfile) as fp:
1895 detected_archs = []
1896 for ln in fp:
1897 a = ln.split()[-1]
1898 if a in archs:
1899 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001900 os.unlink(tmpfile)
1901
1902 for a in detected_archs:
1903 frameworks.append('-arch')
1904 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001905
Victor Stinnercfe172d2019-03-01 18:21:49 +01001906 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1907 define_macros=[('WITH_APPINIT', 1)],
1908 include_dirs=include_dirs,
1909 libraries=[],
1910 extra_compile_args=frameworks[2:],
1911 extra_link_args=frameworks))
Victor Stinner4cbea512019-02-28 17:48:38 +01001912 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001913
Victor Stinner625dbf22019-03-01 15:59:39 +01001914 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001915 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001916
Ned Deilyd819b932013-09-06 01:07:05 -07001917 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1918 # configured or passed into the make target. If so, use these values
1919 # to build tkinter and bypass the searches for Tcl and TK in standard
1920 # locations.
1921 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 16:43:28 +01001922 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001923
Jack Jansen0b06be72002-06-21 14:48:38 +00001924 # Rather than complicate the code below, detecting and building
1925 # AquaTk is a separate method. Only one Tkinter will be built on
1926 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01001927 if (MACOS and self.detect_tkinter_darwin()):
1928 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001929
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001930 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001931 # The versions with dots are used on Unix, and the versions without
1932 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001933 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00001934 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1935 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01001936 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001937 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01001938 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001939 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00001940 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001941 # Exit the loop when we've found the Tcl/Tk libraries
1942 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001943
Fredrik Lundhade711a2001-01-24 08:00:28 +00001944 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001945 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001946 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001947 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001948 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01001949 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001950 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1951 # but the include subdirs are named like .../include/tcl8.3.
1952 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1953 tcl_include_sub = []
1954 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001955 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001956 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1957 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1958 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01001959 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
1960 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001961
Martin v. Löwise86a59a2003-05-03 08:45:51 +00001962 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001963 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001964 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01001965 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00001966
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001967 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001968
Victor Stinnercfe172d2019-03-01 18:21:49 +01001969 include_dirs = []
1970 libs = []
1971 defs = []
1972 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001973 for dir in tcl_includes + tk_includes:
1974 if dir not in include_dirs:
1975 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001976
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001977 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01001978 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001979 include_dirs.append('/usr/openwin/include')
1980 added_lib_dirs.append('/usr/openwin/lib')
1981 elif os.path.exists('/usr/X11R6/include'):
1982 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00001983 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001984 added_lib_dirs.append('/usr/X11R6/lib')
1985 elif os.path.exists('/usr/X11R5/include'):
1986 include_dirs.append('/usr/X11R5/include')
1987 added_lib_dirs.append('/usr/X11R5/lib')
1988 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001989 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001990 include_dirs.append('/usr/X11/include')
1991 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001992
Jason Tishler9181c942003-02-05 15:16:17 +00001993 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01001994 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00001995 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1996 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001997 return False
Jason Tishler9181c942003-02-05 15:16:17 +00001998
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001999 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01002000 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002001 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002002 defs.append( ('WITH_BLT', 1) )
2003 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01002004 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002005 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00002006 defs.append( ('WITH_BLT', 1) )
2007 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002008
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002009 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00002010 libs.append('tk'+ version)
2011 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002012
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002013 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01002014 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002015 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002016
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002017 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002018 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002019 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002020 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002021 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002022 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002023 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002024
Victor Stinnercfe172d2019-03-01 18:21:49 +01002025 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2026 define_macros=[('WITH_APPINIT', 1)] + defs,
2027 include_dirs=include_dirs,
2028 libraries=libs,
2029 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002030 return True
2031
Christian Heimes78644762008-03-04 23:39:23 +00002032 def configure_ctypes_darwin(self, ext):
2033 # Darwin (OS X) uses preconfigured files, in
2034 # the Modules/_ctypes/libffi_osx directory.
Victor Stinner625dbf22019-03-01 15:59:39 +01002035 ffi_srcdir = os.path.abspath(os.path.join(self.srcdir, 'Modules',
Christian Heimes78644762008-03-04 23:39:23 +00002036 '_ctypes', 'libffi_osx'))
2037 sources = [os.path.join(ffi_srcdir, p)
2038 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:56 +00002039 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:23 +00002040 'x86/x86-darwin.S',
2041 'x86/x86-ffi_darwin.c',
2042 'x86/x86-ffi64.c',
2043 'powerpc/ppc-darwin.S',
2044 'powerpc/ppc-darwin_closure.S',
2045 'powerpc/ppc-ffi_darwin.c',
2046 'powerpc/ppc64-darwin_closure.S',
2047 ]]
2048
2049 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:05 +00002050 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:23 +00002051
2052 include_dirs = [os.path.join(ffi_srcdir, 'include'),
2053 os.path.join(ffi_srcdir, 'powerpc')]
2054 ext.include_dirs.extend(include_dirs)
2055 ext.sources.extend(sources)
2056 return True
2057
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002058 def configure_ctypes(self, ext):
2059 if not self.use_system_libffi:
Victor Stinner4cbea512019-02-28 17:48:38 +01002060 if MACOS:
Christian Heimes78644762008-03-04 23:39:23 +00002061 return self.configure_ctypes_darwin(ext)
Zachary Waref40d4dd2016-09-17 01:25:24 -05002062 print('INFO: Could not locate ffi libs and/or headers')
2063 return False
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002064 return True
2065
Victor Stinner625dbf22019-03-01 15:59:39 +01002066 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002067 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002068 self.use_system_libffi = False
2069 include_dirs = []
Victor Stinner1ae035b2020-04-17 17:47:20 +02002070 extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002071 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002072 sources = ['_ctypes/_ctypes.c',
2073 '_ctypes/callbacks.c',
2074 '_ctypes/callproc.c',
2075 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002076 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002077 depends = ['_ctypes/ctypes.h']
2078
Victor Stinner4cbea512019-02-28 17:48:38 +01002079 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002080 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:58 +00002081 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:23 +00002082 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002083 include_dirs.append('_ctypes/darwin')
Victor Stinner5ec33a12019-03-01 16:43:28 +01002084 # XXX Is this still needed?
2085 # extra_link_args.extend(['-read_only_relocs', 'warning'])
Thomas Hellercf567c12006-03-08 19:51:58 +00002086
Victor Stinner4cbea512019-02-28 17:48:38 +01002087 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002088 # XXX This shouldn't be necessary; it appears that some
2089 # of the assembler code is non-PIC (i.e. it has relocations
2090 # when it shouldn't. The proper fix would be to rewrite
2091 # the assembler code to be PIC.
2092 # This only works with GCC; the Sun compiler likely refuses
2093 # this option. If you want to compile ctypes with the Sun
2094 # compiler, please research a proper solution, instead of
2095 # finding some -z option for the Sun compiler.
2096 extra_link_args.append('-mimpure-text')
2097
Victor Stinner4cbea512019-02-28 17:48:38 +01002098 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002099 extra_link_args.append('-fPIC')
2100
Thomas Hellercf567c12006-03-08 19:51:58 +00002101 ext = Extension('_ctypes',
2102 include_dirs=include_dirs,
2103 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002104 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002105 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002106 sources=sources,
2107 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002108 self.add(ext)
2109 if TEST_EXTENSIONS:
2110 # function my_sqrt() needs libm for sqrt()
2111 self.add(Extension('_ctypes_test',
2112 sources=['_ctypes/_ctypes_test.c'],
2113 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002114
Victor Stinner625dbf22019-03-01 15:59:39 +01002115 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002116 if MACOS:
Zachary Ware935043d2016-09-09 17:01:21 -07002117 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
2118 return
Christian Heimes78644762008-03-04 23:39:23 +00002119 # OS X 10.5 comes with libffi.dylib; the include files are
2120 # in /usr/include/ffi
Victor Stinner96d81582019-03-01 13:53:46 +01002121 ffi_inc_dirs.append('/usr/include/ffi')
Christian Heimes78644762008-03-04 23:39:23 +00002122
Benjamin Petersond78735d2010-01-01 16:04:23 +00002123 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:45 +00002124 if not ffi_inc or ffi_inc[0] == '':
Victor Stinner96d81582019-03-01 13:53:46 +01002125 ffi_inc = find_file('ffi.h', [], ffi_inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002126 if ffi_inc is not None:
2127 ffi_h = ffi_inc[0] + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002128 if not os.path.exists(ffi_h):
2129 ffi_inc = None
2130 print('Header file {} does not exist'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002131 ffi_lib = None
2132 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002133 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002134 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002135 ffi_lib = lib_name
2136 break
2137
2138 if ffi_inc and ffi_lib:
2139 ext.include_dirs.extend(ffi_inc)
2140 ext.libraries.append(ffi_lib)
2141 self.use_system_libffi = True
2142
Christian Heimes5bb96922018-02-25 10:22:14 +01002143 if sysconfig.get_config_var('HAVE_LIBDL'):
2144 # for dlopen, see bpo-32647
2145 ext.libraries.append('dl')
2146
Victor Stinner5ec33a12019-03-01 16:43:28 +01002147 def detect_decimal(self):
2148 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002149 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002150 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002151 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2152 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002153 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002154 sources = ['_decimal/_decimal.c']
2155 depends = ['_decimal/docstrings.h']
2156 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002157 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002158 'Modules',
2159 '_decimal',
2160 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002161 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002162 sources = [
2163 '_decimal/_decimal.c',
2164 '_decimal/libmpdec/basearith.c',
2165 '_decimal/libmpdec/constants.c',
2166 '_decimal/libmpdec/context.c',
2167 '_decimal/libmpdec/convolute.c',
2168 '_decimal/libmpdec/crt.c',
2169 '_decimal/libmpdec/difradix2.c',
2170 '_decimal/libmpdec/fnt.c',
2171 '_decimal/libmpdec/fourstep.c',
2172 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002173 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002174 '_decimal/libmpdec/mpdecimal.c',
2175 '_decimal/libmpdec/numbertheory.c',
2176 '_decimal/libmpdec/sixstep.c',
2177 '_decimal/libmpdec/transpose.c',
2178 ]
2179 depends = [
2180 '_decimal/docstrings.h',
2181 '_decimal/libmpdec/basearith.h',
2182 '_decimal/libmpdec/bits.h',
2183 '_decimal/libmpdec/constants.h',
2184 '_decimal/libmpdec/convolute.h',
2185 '_decimal/libmpdec/crt.h',
2186 '_decimal/libmpdec/difradix2.h',
2187 '_decimal/libmpdec/fnt.h',
2188 '_decimal/libmpdec/fourstep.h',
2189 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002190 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002191 '_decimal/libmpdec/mpdecimal.h',
2192 '_decimal/libmpdec/numbertheory.h',
2193 '_decimal/libmpdec/sixstep.h',
2194 '_decimal/libmpdec/transpose.h',
2195 '_decimal/libmpdec/typearith.h',
2196 '_decimal/libmpdec/umodarith.h',
2197 ]
2198
Stefan Krah1919b7e2012-03-21 18:25:23 +01002199 config = {
2200 'x64': [('CONFIG_64','1'), ('ASM','1')],
2201 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2202 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2203 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2204 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2205 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2206 ('LEGACY_COMPILER','1')],
2207 'universal': [('UNIVERSAL','1')]
2208 }
2209
Stefan Krah1919b7e2012-03-21 18:25:23 +01002210 cc = sysconfig.get_config_var('CC')
2211 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2212 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2213
2214 if machine:
2215 # Override automatic configuration to facilitate testing.
2216 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002217 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002218 # Universal here means: build with the same options Python
2219 # was built with.
2220 define_macros = config['universal']
2221 elif sizeof_size_t == 8:
2222 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2223 define_macros = config['x64']
2224 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2225 define_macros = config['uint128']
2226 else:
2227 define_macros = config['ansi64']
2228 elif sizeof_size_t == 4:
2229 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2230 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002231 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002232 # solaris: problems with register allocation.
2233 # icc >= 11.0 works as well.
2234 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002235 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002236 else:
2237 define_macros = config['ansi32']
2238 else:
2239 raise DistutilsError("_decimal: unsupported architecture")
2240
2241 # Workarounds for toolchain bugs:
2242 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2243 # Some versions of gcc miscompile inline asm:
2244 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2245 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2246 extra_compile_args.append('-fno-ipa-pure-const')
2247 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2248 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2249 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2250 undef_macros.append('_FORTIFY_SOURCE')
2251
Stefan Krah1919b7e2012-03-21 18:25:23 +01002252 # Uncomment for extra functionality:
2253 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002254 self.add(Extension('_decimal',
2255 include_dirs=include_dirs,
2256 libraries=libraries,
2257 define_macros=define_macros,
2258 undef_macros=undef_macros,
2259 extra_compile_args=extra_compile_args,
2260 sources=sources,
2261 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002262
Victor Stinner5ec33a12019-03-01 16:43:28 +01002263 def detect_openssl_hashlib(self):
2264 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002265 config_vars = sysconfig.get_config_vars()
2266
2267 def split_var(name, sep):
2268 # poor man's shlex, the re module is not available yet.
2269 value = config_vars.get(name)
2270 if not value:
2271 return ()
2272 # This trick works because ax_check_openssl uses --libs-only-L,
2273 # --libs-only-l, and --cflags-only-I.
2274 value = ' ' + value
2275 sep = ' ' + sep
2276 return [v.strip() for v in value.split(sep) if v.strip()]
2277
2278 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2279 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2280 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2281 if not openssl_libs:
2282 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002283 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002284 return None, None
2285
2286 # Find OpenSSL includes
2287 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002288 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002289 )
2290 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002291 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002292 return None, None
2293
2294 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2295 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002296 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002297 ['/usr/kerberos/include']
2298 )
2299 if krb5_h:
2300 ssl_incs.extend(krb5_h)
2301
Christian Heimes61d478c2018-01-27 15:51:38 +01002302 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 11:44:05 +02002303 self.add(Extension(
2304 '_ssl', ['_ssl.c'],
2305 include_dirs=openssl_includes,
2306 library_dirs=openssl_libdirs,
2307 libraries=openssl_libs,
2308 depends=['socketmodule.h', '_ssl/debughelpers.c'])
2309 )
Christian Heimes61d478c2018-01-27 15:51:38 +01002310 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002311 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002312
Victor Stinner8058bda2019-03-01 15:31:45 +01002313 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2314 depends=['hashlib.h'],
2315 include_dirs=openssl_includes,
2316 library_dirs=openssl_libdirs,
2317 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002318
xdegaye2ee077f2019-04-09 17:20:08 +02002319 def detect_hash_builtins(self):
Christian Heimes9b60e552020-05-15 23:54:53 +02002320 # By default we always compile these even when OpenSSL is available
2321 # (issue #14693). It's harmless and the object code is tiny
2322 # (40-50 KiB per module, only loaded when actually used). Modules can
2323 # be disabled via the --with-builtin-hashlib-hashes configure flag.
2324 supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
Victor Stinner5ec33a12019-03-01 16:43:28 +01002325
Christian Heimes9b60e552020-05-15 23:54:53 +02002326 configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
2327 configured = configured.strip('"').lower()
2328 configured = {
2329 m.strip() for m in configured.split(",")
2330 }
Victor Stinner5ec33a12019-03-01 16:43:28 +01002331
Christian Heimes9b60e552020-05-15 23:54:53 +02002332 self.disabled_configure.extend(
2333 sorted(supported.difference(configured))
2334 )
Victor Stinner5ec33a12019-03-01 16:43:28 +01002335
Christian Heimes9b60e552020-05-15 23:54:53 +02002336 if "sha256" in configured:
2337 self.add(Extension(
2338 '_sha256', ['sha256module.c'],
2339 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2340 depends=['hashlib.h']
2341 ))
2342
2343 if "sha512" in configured:
2344 self.add(Extension(
2345 '_sha512', ['sha512module.c'],
2346 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2347 depends=['hashlib.h']
2348 ))
2349
2350 if "md5" in configured:
2351 self.add(Extension(
2352 '_md5', ['md5module.c'],
2353 depends=['hashlib.h']
2354 ))
2355
2356 if "sha1" in configured:
2357 self.add(Extension(
2358 '_sha1', ['sha1module.c'],
2359 depends=['hashlib.h']
2360 ))
2361
2362 if "blake2" in configured:
2363 blake2_deps = glob(
2364 os.path.join(self.srcdir, 'Modules/_blake2/impl/*')
2365 )
2366 blake2_deps.append('hashlib.h')
2367 self.add(Extension(
2368 '_blake2',
2369 [
2370 '_blake2/blake2module.c',
2371 '_blake2/blake2b_impl.c',
2372 '_blake2/blake2s_impl.c'
2373 ],
2374 depends=blake2_deps
2375 ))
2376
2377 if "sha3" in configured:
2378 sha3_deps = glob(
2379 os.path.join(self.srcdir, 'Modules/_sha3/kcp/*')
2380 )
2381 sha3_deps.append('hashlib.h')
2382 self.add(Extension(
2383 '_sha3',
2384 ['_sha3/sha3module.c'],
2385 depends=sha3_deps
2386 ))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002387
2388 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002389 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002390 self.missing.append('nis')
2391 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002392
2393 libs = []
2394 library_dirs = []
2395 includes_dirs = []
2396
2397 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2398 # moved headers and libraries to libtirpc and libnsl. The headers
2399 # are in tircp and nsl sub directories.
2400 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002401 'rpcsvc/yp_prot.h', self.inc_dirs,
2402 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002403 )
2404 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002405 'rpc/rpc.h', self.inc_dirs,
2406 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002407 )
2408 if rpcsvc_inc is None or rpc_inc is None:
2409 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002410 self.missing.append('nis')
2411 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002412 includes_dirs.extend(rpcsvc_inc)
2413 includes_dirs.extend(rpc_inc)
2414
Victor Stinner625dbf22019-03-01 15:59:39 +01002415 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002416 libs.append('nsl')
2417 else:
2418 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002419 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002420 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2421 if libnsl is not None:
2422 library_dirs.append(os.path.dirname(libnsl))
2423 libs.append('nsl')
2424
Victor Stinner625dbf22019-03-01 15:59:39 +01002425 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002426 libs.append('tirpc')
2427
Victor Stinner8058bda2019-03-01 15:31:45 +01002428 self.add(Extension('nis', ['nismodule.c'],
2429 libraries=libs,
2430 library_dirs=library_dirs,
2431 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002432
Christian Heimesff5be6e2018-01-20 13:19:21 +01002433
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002434class PyBuildInstall(install):
2435 # Suppress the warning about installation into the lib_dynload
2436 # directory, which is not in sys.path when running Python during
2437 # installation:
2438 def initialize_options (self):
2439 install.initialize_options(self)
2440 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002441
Éric Araujoe6792c12011-06-09 14:07:02 +02002442 # Customize subcommands to not install an egg-info file for Python
2443 sub_commands = [('install_lib', install.has_lib),
2444 ('install_headers', install.has_headers),
2445 ('install_scripts', install.has_scripts),
2446 ('install_data', install.has_data)]
2447
2448
Michael W. Hudson529a5052002-12-17 16:47:17 +00002449class PyBuildInstallLib(install_lib):
2450 # Do exactly what install_lib does but make sure correct access modes get
2451 # set on installed directories and files. All installed files with get
2452 # mode 644 unless they are a shared library in which case they will get
2453 # mode 755. All installed directories will get mode 755.
2454
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002455 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2456 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002457
2458 def install(self):
2459 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002460 self.set_file_modes(outfiles, 0o644, 0o755)
2461 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002462 return outfiles
2463
2464 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002465 if not files: return
2466
2467 for filename in files:
2468 if os.path.islink(filename): continue
2469 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002470 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002471 log.info("changing mode of %s to %o", filename, mode)
2472 if not self.dry_run: os.chmod(filename, mode)
2473
2474 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002475 for dirpath, dirnames, fnames in os.walk(dirname):
2476 if os.path.islink(dirpath):
2477 continue
2478 log.info("changing mode of %s to %o", dirpath, mode)
2479 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002480
Victor Stinnerc991f242019-03-01 17:19:04 +01002481
Georg Brandlff52f762010-12-28 09:51:43 +00002482class PyBuildScripts(build_scripts):
2483 def copy_scripts(self):
2484 outfiles, updated_files = build_scripts.copy_scripts(self)
2485 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2486 minoronly = '.{0[1]}'.format(sys.version_info)
2487 newoutfiles = []
2488 newupdated_files = []
2489 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002490 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002491 newfilename = filename + fullversion
2492 else:
2493 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002494 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002495 os.rename(filename, newfilename)
2496 newoutfiles.append(newfilename)
2497 if filename in updated_files:
2498 newupdated_files.append(newfilename)
2499 return newoutfiles, newupdated_files
2500
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002501
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002502def main():
Victor Stinnerc991f242019-03-01 17:19:04 +01002503 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2504 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2505
2506 class DummyProcess:
2507 """Hack for parallel build"""
2508 ProcessPoolExecutor = None
2509
2510 sys.modules['concurrent.futures.process'] = DummyProcess
Paul Ganssle62972d92020-05-16 04:20:06 -04002511 validate_tzpath()
Victor Stinnerc991f242019-03-01 17:19:04 +01002512
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002513 # turn off warnings when deprecated modules are imported
2514 import warnings
2515 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002516 setup(# PyPI Metadata (PEP 301)
2517 name = "Python",
2518 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002519 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002520 maintainer = "Guido van Rossum and the Python community",
2521 maintainer_email = "python-dev@python.org",
2522 description = "A high-level object-oriented programming language",
2523 long_description = SUMMARY.strip(),
2524 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002525 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002526 platforms = ["Many"],
2527
2528 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002529 cmdclass = {'build_ext': PyBuildExt,
2530 'build_scripts': PyBuildScripts,
2531 'install': PyBuildInstall,
2532 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002533 # The struct module is defined here, because build_ext won't be
2534 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002535 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002536
Georg Brandlff52f762010-12-28 09:51:43 +00002537 # If you change the scripts installed here, you also need to
2538 # check the PyBuildScripts command above, and change the links
2539 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002540 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002541 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002542 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002543
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002544# --install-platlib
2545if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002546 main()