blob: 24ce9a632dd907d3c4cdc147e538e3b8c6e33ebb [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
98# Set common compiler and linker flags derived from the Makefile,
99# reserved for building the interpreter and the stdlib modules.
100# See bpo-21121 and bpo-35257
101def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
102 flags = sysconfig.get_config_var(compiler_flags)
103 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
104 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
105
106
Michael W. Hudson39230b32002-01-16 15:26:48 +0000107def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000108 """Add the directory 'dir' to the list 'dirlist' (after any relative
109 directories) if:
110
Michael W. Hudson39230b32002-01-16 15:26:48 +0000111 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000112 2) 'dir' actually exists, and is a directory.
113 """
114 if dir is None or not os.path.isdir(dir) or dir in dirlist:
115 return
116 for i, path in enumerate(dirlist):
117 if not os.path.isabs(path):
118 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000119 return
120 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000121
Victor Stinnerc991f242019-03-01 17:19:04 +0100122
xdegaye77f51392017-11-25 17:25:30 +0100123def sysroot_paths(make_vars, subdirs):
124 """Get the paths of sysroot sub-directories.
125
126 * make_vars: a sequence of names of variables of the Makefile where
127 sysroot may be set.
128 * subdirs: a sequence of names of subdirectories used as the location for
129 headers or libraries.
130 """
131
132 dirs = []
133 for var_name in make_vars:
134 var = sysconfig.get_config_var(var_name)
135 if var is not None:
136 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
137 if m is not None:
138 sysroot = m.group(1).strip('"')
139 for subdir in subdirs:
140 if os.path.isabs(subdir):
141 subdir = subdir[1:]
142 path = os.path.join(sysroot, subdir)
143 if os.path.isdir(path):
144 dirs.append(path)
145 break
146 return dirs
147
Ned Deily0288dd62019-06-03 06:34:48 -0400148MACOS_SDK_ROOT = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100149
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000150def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400151 """Return the directory of the current macOS SDK.
152
153 If no SDK was explicitly configured, call the compiler to find which
154 include files paths are being searched by default. Use '/' if the
155 compiler is searching /usr/include (meaning system header files are
156 installed) or use the root of an SDK if that is being searched.
157 (The SDK may be supplied via Xcode or via the Command Line Tools).
158 The SDK paths used by Apple-supplied tool chains depend on the
159 setting of various variables; see the xcrun man page for more info.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000160 """
Ned Deily0288dd62019-06-03 06:34:48 -0400161 global MACOS_SDK_ROOT
162
163 # If already called, return cached result.
164 if MACOS_SDK_ROOT:
165 return MACOS_SDK_ROOT
166
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000167 cflags = sysconfig.get_config_var('CFLAGS')
168 m = re.search(r'-isysroot\s+(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400169 if m is not None:
170 MACOS_SDK_ROOT = m.group(1)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000171 else:
Ned Deily0288dd62019-06-03 06:34:48 -0400172 MACOS_SDK_ROOT = '/'
173 cc = sysconfig.get_config_var('CC')
174 tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid()
175 try:
176 os.unlink(tmpfile)
177 except:
178 pass
179 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
180 in_incdirs = False
181 try:
182 if ret >> 8 == 0:
183 with open(tmpfile) as fp:
184 for line in fp.readlines():
185 if line.startswith("#include <...>"):
186 in_incdirs = True
187 elif line.startswith("End of search list"):
188 in_incdirs = False
189 elif in_incdirs:
190 line = line.strip()
191 if line == '/usr/include':
192 MACOS_SDK_ROOT = '/'
193 elif line.endswith(".sdk/usr/include"):
194 MACOS_SDK_ROOT = line[:-12]
195 finally:
196 os.unlink(tmpfile)
197
198 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000199
Victor Stinnerc991f242019-03-01 17:19:04 +0100200
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000201def is_macosx_sdk_path(path):
202 """
203 Returns True if 'path' can be located in an OSX SDK
204 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700205 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
206 or path.startswith('/System/')
207 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000208
Victor Stinnerc991f242019-03-01 17:19:04 +0100209
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000210def find_file(filename, std_dirs, paths):
211 """Searches for the directory where a given file is located,
212 and returns a possibly-empty list of additional directories, or None
213 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000214
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000215 'filename' is the name of a file, such as readline.h or libcrypto.a.
216 'std_dirs' is the list of standard system directories; if the
217 file is found in one of them, no additional directives are needed.
218 'paths' is a list of additional locations to check; if the file is
219 found in one of them, the resulting list will contain the directory.
220 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100221 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000222 # Honor the MacOSX SDK setting when one was specified.
223 # An SDK is a directory with the same structure as a real
224 # system, but with only header files and libraries.
225 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000226
227 # Check the standard locations
228 for dir in std_dirs:
229 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000230
Victor Stinner4cbea512019-02-28 17:48:38 +0100231 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000232 f = os.path.join(sysroot, dir[1:], filename)
233
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000234 if os.path.exists(f): return []
235
236 # Check the additional directories
237 for dir in paths:
238 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000239
Victor Stinner4cbea512019-02-28 17:48:38 +0100240 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000241 f = os.path.join(sysroot, dir[1:], filename)
242
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000243 if os.path.exists(f):
244 return [dir]
245
246 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000247 return None
248
Victor Stinnerc991f242019-03-01 17:19:04 +0100249
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000250def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000251 result = compiler.find_library_file(std_dirs + paths, libname)
252 if result is None:
253 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000254
Victor Stinner4cbea512019-02-28 17:48:38 +0100255 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000256 sysroot = macosx_sdk_root()
257
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000258 # Check whether the found file is in one of the standard directories
259 dirname = os.path.dirname(result)
260 for p in std_dirs:
261 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000262 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000263
Victor Stinner4cbea512019-02-28 17:48:38 +0100264 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100265 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
266 # libraries with .tbd extensions rather than the normal .dylib
267 # shared libraries installed in /. The Apple compiler tool
268 # chain handles this transparently but it can cause problems
269 # for programs that are being built with an SDK and searching
270 # for specific libraries. Distutils find_library_file() now
271 # knows to also search for and return .tbd files. But callers
272 # of find_library_file need to keep in mind that the base filename
273 # of the returned SDK library file might have a different extension
274 # from that of the library file installed on the running system,
275 # for example:
276 # /Applications/Xcode.app/Contents/Developer/Platforms/
277 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
278 # usr/lib/libedit.tbd
279 # vs
280 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000281 if os.path.join(sysroot, p[1:]) == dirname:
282 return [ ]
283
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000284 if p == dirname:
285 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000286
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000287 # Otherwise, it must have been in one of the additional directories,
288 # so we have to figure out which one.
289 for p in paths:
290 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000291 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000292
Victor Stinner4cbea512019-02-28 17:48:38 +0100293 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000294 if os.path.join(sysroot, p[1:]) == dirname:
295 return [ p ]
296
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000297 if p == dirname:
298 return [p]
299 else:
300 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000301
Victor Stinnerc991f242019-03-01 17:19:04 +0100302
Jack Jansen144ebcc2001-08-05 22:31:19 +0000303def find_module_file(module, dirlist):
304 """Find a module in a set of possible folders. If it is not found
305 return the unadorned filename"""
306 list = find_file(module, [], dirlist)
307 if not list:
308 return module
309 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100310 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000311 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000312
Victor Stinnerc991f242019-03-01 17:19:04 +0100313
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000314class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000315
Guido van Rossumd8faa362007-04-27 19:54:29 +0000316 def __init__(self, dist):
317 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100318 self.srcdir = None
319 self.lib_dirs = None
320 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100321 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000322 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400323 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100324 self.missing = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200325 if '-j' in os.environ.get('MAKEFLAGS', ''):
326 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000327
Victor Stinner8058bda2019-03-01 15:31:45 +0100328 def add(self, ext):
329 self.extensions.append(ext)
330
Victor Stinner00c77ae2020-03-04 18:44:49 +0100331 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100332 self.srcdir = sysconfig.get_config_var('srcdir')
333 if not self.srcdir:
334 # Maybe running on Windows but not using CYGWIN?
335 raise ValueError("No source directory; cannot proceed.")
336 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000337
Victor Stinner00c77ae2020-03-04 18:44:49 +0100338 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000339 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000340 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100341 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000342 # move ctypes to the end, it depends on other modules
343 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
344 if "_ctypes" in ext_map:
345 ctypes = extensions.pop(ext_map["_ctypes"])
346 extensions.append(ctypes)
347 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000348
Victor Stinner00c77ae2020-03-04 18:44:49 +0100349 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000350 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000351 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100352 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000353
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000354 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100355 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000356 for filename in self.distribution.scripts]
357
Christian Heimesaf98da12008-01-27 15:18:18 +0000358 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000359 headers = [sysconfig.get_config_h_filename()]
Stefan Kraheb977da2012-02-29 14:10:53 +0100360 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000361
Xavier de Gaye84968b72016-10-29 16:57:20 +0200362 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000363 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000364 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000365 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000366 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000367 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000368 else:
369 ext.depends = []
370 # re-compile extensions if a header file has been changed
371 ext.depends.extend(headers)
372
Victor Stinner00c77ae2020-03-04 18:44:49 +0100373 def remove_configured_extensions(self):
374 # The sysconfig variables built by makesetup that list the already
375 # built modules and the disabled modules as configured by the Setup
376 # files.
377 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
378 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
379
380 mods_built = []
381 mods_disabled = []
382 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200383 # If a module has already been built or has been disabled in the
384 # Setup files, don't build it here.
385 if ext.name in sysconf_built:
386 mods_built.append(ext)
387 if ext.name in sysconf_dis:
388 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000389
xdegayec0364fc2017-05-27 18:25:03 +0200390 mods_configured = mods_built + mods_disabled
391 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200392 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200393 mods_configured]
394 # Remove the shared libraries built by a previous build.
395 for ext in mods_configured:
396 fullpath = self.get_ext_fullpath(ext.name)
397 if os.path.exists(fullpath):
398 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000399
Victor Stinner00c77ae2020-03-04 18:44:49 +0100400 return (mods_built, mods_disabled)
401
402 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000403 # When you run "make CC=altcc" or something similar, you really want
404 # those environment variables passed into the setup.py phase. Here's
405 # a small set of useful ones.
406 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000407 args = {}
408 # unfortunately, distutils doesn't let us provide separate C and C++
409 # compilers
410 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000411 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
412 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000413 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000414
Victor Stinner00c77ae2020-03-04 18:44:49 +0100415 def build_extensions(self):
416 self.set_srcdir()
417
418 # Detect which modules should be compiled
419 self.detect_modules()
420
421 self.remove_disabled()
422
423 self.update_sources_depends()
424 mods_built, mods_disabled = self.remove_configured_extensions()
425 self.set_compiler_executables()
426
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000427 build_ext.build_extensions(self)
428
Victor Stinner1ec63b62020-03-04 14:50:19 +0100429 if SUBPROCESS_BOOTSTRAP:
430 # Drop our custom subprocess module:
431 # use the newly built subprocess module
432 del sys.modules['subprocess']
433
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200434 for ext in self.extensions:
435 self.check_extension_import(ext)
436
Victor Stinner00c77ae2020-03-04 18:44:49 +0100437 self.summary(mods_built, mods_disabled)
438
439 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300440 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400441 if self.failed or self.failed_on_import:
442 all_failed = self.failed + self.failed_on_import
443 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000444
445 def print_three_column(lst):
446 lst.sort(key=str.lower)
447 # guarantee zip() doesn't drop anything
448 while len(lst) % 3:
449 lst.append("")
450 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
451 print("%-*s %-*s %-*s" % (longest, e, longest, f,
452 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000453
Victor Stinner8058bda2019-03-01 15:31:45 +0100454 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000455 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400456 print("Python build finished successfully!")
457 print("The necessary bits to build these optional modules were not "
458 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100459 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000460 print("To find the necessary bits, look in setup.py in"
461 " detect_modules() for the module's name.")
462 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000463
xdegayec0364fc2017-05-27 18:25:03 +0200464 if mods_built:
465 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200466 print("The following modules found by detect_modules() in"
467 " setup.py, have been")
468 print("built by the Makefile instead, as configured by the"
469 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200470 print_three_column([ext.name for ext in mods_built])
471 print()
472
473 if mods_disabled:
474 print()
475 print("The following modules found by detect_modules() in"
476 " setup.py have not")
477 print("been built, they are *disabled* in the Setup files:")
478 print_three_column([ext.name for ext in mods_disabled])
479 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200480
Guido van Rossumd8faa362007-04-27 19:54:29 +0000481 if self.failed:
482 failed = self.failed[:]
483 print()
484 print("Failed to build these modules:")
485 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000486 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000487
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400488 if self.failed_on_import:
489 failed = self.failed_on_import[:]
490 print()
491 print("Following modules built successfully"
492 " but were removed because they could not be imported:")
493 print_three_column(failed)
494 print()
495
Christian Heimes61d478c2018-01-27 15:51:38 +0100496 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100497 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100498 print()
499 print("Could not build the ssl module!")
500 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
501 "libssl with X509_VERIFY_PARAM_set1_host().")
502 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
503 "APIs, https://github.com/libressl-portable/portable/issues/381")
504 print()
505
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000506 def build_extension(self, ext):
507
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000508 if ext.name == '_ctypes':
509 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500510 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000511 return
512
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000513 try:
514 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000515 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000516 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100517 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000518 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000519 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200520
521 def check_extension_import(self, ext):
522 # Don't try to import an extension that has failed to compile
523 if ext.name in self.failed:
524 self.announce(
525 'WARNING: skipping import check for failed build "%s"' %
526 ext.name, level=1)
527 return
528
Jack Jansenf49c6f92001-11-01 14:44:15 +0000529 # Workaround for Mac OS X: The Carbon-based modules cannot be
530 # reliably imported into a command-line Python
531 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000532 self.announce(
533 'WARNING: skipping import check for Carbon-based "%s"' %
534 ext.name)
535 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000536
Victor Stinner4cbea512019-02-28 17:48:38 +0100537 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000538 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000539 # Don't bother doing an import check when an extension was
540 # build with an explicit '-arch' flag on OSX. That's currently
541 # only used to build 32-bit only extensions in a 4-way
542 # universal build and loading 32-bit code into a 64-bit
543 # process will fail.
544 self.announce(
545 'WARNING: skipping import check for "%s"' %
546 ext.name)
547 return
548
Jason Tishler24cf7762002-05-22 16:46:15 +0000549 # Workaround for Cygwin: Cygwin currently has fork issues when many
550 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100551 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000552 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
553 % ext.name)
554 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000555 ext_filename = os.path.join(
556 self.build_lib,
557 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000558
559 # If the build directory didn't exist when setup.py was
560 # started, sys.path_importer_cache has a negative result
561 # cached. Clear that cache before trying to import.
562 sys.path_importer_cache.clear()
563
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200564 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100565 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200566 return
567
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400568 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700569 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
570 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000571 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400572 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000573 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400574 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000575 self.announce('*** WARNING: renaming "%s" since importing it'
576 ' failed: %s' % (ext.name, why), level=3)
577 assert not self.inplace
578 basename, tail = os.path.splitext(ext_filename)
579 newname = basename + "_failed" + tail
580 if os.path.exists(newname):
581 os.remove(newname)
582 os.rename(ext_filename, newname)
583
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000584 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000585 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000586 self.announce('*** WARNING: importing extension "%s" '
587 'failed with %s: %s' % (ext.name, exc_type, why),
588 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000589 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000590
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400591 def add_multiarch_paths(self):
592 # Debian/Ubuntu multiarch support.
593 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200594 cc = sysconfig.get_config_var('CC')
595 tmpfile = os.path.join(self.build_temp, 'multiarch')
596 if not os.path.exists(self.build_temp):
597 os.makedirs(self.build_temp)
598 ret = os.system(
599 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
600 multiarch_path_component = ''
601 try:
602 if ret >> 8 == 0:
603 with open(tmpfile) as fp:
604 multiarch_path_component = fp.readline().strip()
605 finally:
606 os.unlink(tmpfile)
607
608 if multiarch_path_component != '':
609 add_dir_to_list(self.compiler.library_dirs,
610 '/usr/lib/' + multiarch_path_component)
611 add_dir_to_list(self.compiler.include_dirs,
612 '/usr/include/' + multiarch_path_component)
613 return
614
Barry Warsaw88e19452011-04-07 10:40:36 -0400615 if not find_executable('dpkg-architecture'):
616 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200617 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100618 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200619 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400620 tmpfile = os.path.join(self.build_temp, 'multiarch')
621 if not os.path.exists(self.build_temp):
622 os.makedirs(self.build_temp)
623 ret = os.system(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200624 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
625 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400626 try:
627 if ret >> 8 == 0:
628 with open(tmpfile) as fp:
629 multiarch_path_component = fp.readline().strip()
630 add_dir_to_list(self.compiler.library_dirs,
631 '/usr/lib/' + multiarch_path_component)
632 add_dir_to_list(self.compiler.include_dirs,
633 '/usr/include/' + multiarch_path_component)
634 finally:
635 os.unlink(tmpfile)
636
pxinwr32f5fdd2019-02-27 19:09:28 +0800637 def add_cross_compiling_paths(self):
638 cc = sysconfig.get_config_var('CC')
639 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200640 if not os.path.exists(self.build_temp):
641 os.makedirs(self.build_temp)
pxinwr32f5fdd2019-02-27 19:09:28 +0800642 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200643 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800644 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200645 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200646 try:
647 if ret >> 8 == 0:
648 with open(tmpfile) as fp:
649 for line in fp.readlines():
650 if line.startswith("gcc version"):
651 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800652 elif line.startswith("clang version"):
653 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200654 elif line.startswith("#include <...>"):
655 in_incdirs = True
656 elif line.startswith("End of search list"):
657 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800658 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200659 for d in line.strip().split("=")[1].split(":"):
660 d = os.path.normpath(d)
661 if '/gcc/' not in d:
662 add_dir_to_list(self.compiler.library_dirs,
663 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800664 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 +0200665 add_dir_to_list(self.compiler.include_dirs,
666 line.strip())
667 finally:
668 os.unlink(tmpfile)
669
Victor Stinnercfe172d2019-03-01 18:21:49 +0100670 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000671 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000672 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000673 # We must get the values from the Makefile and not the environment
674 # directly since an inconsistently reproducible issue comes up where
675 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000676 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000677 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000678 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
679 ('LDFLAGS', '-L', self.compiler.library_dirs),
680 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000681 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000682 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800683 parser = argparse.ArgumentParser()
684 parser.add_argument(arg_name, dest="dirs", action="append")
685 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000686 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000687 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000688 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000689
Victor Stinnercfe172d2019-03-01 18:21:49 +0100690 def configure_compiler(self):
691 # Ensure that /usr/local is always used, but the local build
692 # directories (i.e. '.' and 'Include') must be first. See issue
693 # 10520.
694 if not CROSS_COMPILING:
695 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
696 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
697 # only change this for cross builds for 3.3, issues on Mageia
698 if CROSS_COMPILING:
699 self.add_cross_compiling_paths()
700 self.add_multiarch_paths()
701 self.add_ldflags_cppflags()
702
Victor Stinner5ec33a12019-03-01 16:43:28 +0100703 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100704 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100705 os.path.normpath(sys.base_prefix) != '/usr' and
706 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000707 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
708 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
709 # building a framework with different architectures than
710 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000711 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000712 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000713 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000714 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000715
xdegaye77f51392017-11-25 17:25:30 +0100716 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
717 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000718 # lib_dirs and inc_dirs are used to search for files;
719 # if a file is found in one of those directories, it can
720 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100721 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100722 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
723 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100724 else:
xdegaye77f51392017-11-25 17:25:30 +0100725 # Add the sysroot paths. 'sysroot' is a compiler option used to
726 # set the logical path of the standard system headers and
727 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100728 self.lib_dirs = (self.compiler.library_dirs +
729 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
730 self.inc_dirs = (self.compiler.include_dirs +
731 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
732 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000733
Brett Cannon4454a1f2005-04-15 20:32:39 +0000734 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000735 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100736 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000737
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000738 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100739 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100740 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000741
Charles-François Natali5739e102012-04-12 19:07:25 +0200742 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100743 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100744 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200745
Victor Stinner4cbea512019-02-28 17:48:38 +0100746 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000747 # This should work on any unixy platform ;-)
748 # If the user has bothered specifying additional -I and -L flags
749 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000750 #
751 # NOTE: using shlex.split would technically be more correct, but
752 # also gives a bootstrap problem. Let's hope nobody uses
753 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000754 cflags, ldflags = sysconfig.get_config_vars(
755 'CFLAGS', 'LDFLAGS')
756 for item in cflags.split():
757 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100758 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000759
760 for item in ldflags.split():
761 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100762 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000763
Victor Stinner5ec33a12019-03-01 16:43:28 +0100764 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000765 #
766 # The following modules are all pretty straightforward, and compile
767 # on pretty much any POSIXish platform.
768 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000769
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000770 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100771 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000772
Yury Selivanovf23746a2018-01-22 19:11:18 -0500773 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100774 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500775
Martin Panterc9deece2016-02-03 05:19:44 +0000776 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100777
778 # math library functions, e.g. sin()
779 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100780 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100781 extra_objects=[shared_math],
782 depends=['_math.h', shared_math],
783 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100784
785 # complex math library functions
786 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100787 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100788 extra_objects=[shared_math],
789 depends=['_math.h', shared_math],
790 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200791
792 # time libraries: librt may be needed for clock_gettime()
793 time_libs = []
794 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
795 if lib:
796 time_libs.append(lib)
797
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000798 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100799 self.add(Extension('time', ['timemodule.c'],
800 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800801 # libm is needed by delta_new() that uses round() and by accum() that
802 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100803 self.add(Extension('_datetime', ['_datetimemodule.c'],
804 libraries=['m']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000805 # random number generator implemented in C
Victor Stinner8058bda2019-03-01 15:31:45 +0100806 self.add(Extension("_random", ["_randommodule.c"]))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000807 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100808 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000809 # heapq
Victor Stinner8058bda2019-03-01 15:31:45 +0100810 self.add(Extension("_heapq", ["_heapqmodule.c"]))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000811 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200812 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200813 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Collin Winter670e6922007-03-21 02:57:17 +0000814 # atexit
Victor Stinner8058bda2019-03-01 15:31:45 +0100815 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10 +0000816 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100817 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200818 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100819
Fred Drake0e474a82007-10-11 18:01:43 +0000820 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100821 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000822 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100823 self.add(Extension('unicodedata', ['unicodedata.c'],
824 depends=['unicodedata_db.h', 'unicodename_db.h']))
Larry Hastings3a907972013-11-23 14:49:22 -0800825 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100826 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900827 # asyncio speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100828 self.add(Extension("_asyncio", ["_asynciomodule.c"]))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000829 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100830 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100831 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100832 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900833 # _statistics module
834 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000835
836 # Modules with some UNIX dependencies -- on by default:
837 # (If you have a really backward UNIX, select and socket may not be
838 # supported...)
839
840 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000841 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100842 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000843 # May be necessary on AIX for flock function
844 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100845 self.add(Extension('fcntl', ['fcntlmodule.c'],
846 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000847 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100848 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000849 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800850 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100851 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000852 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100853 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
854 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100855 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200856 # AIX has shadow passwords, but access is not via getspent(), etc.
857 # module support is not expected so it not 'missing'
858 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100859 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000860
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000861 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100862 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000863
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000864 # Fred Drake's interface to the Python parser
Victor Stinner8058bda2019-03-01 15:31:45 +0100865 self.add(Extension('parser', ['parsermodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000866
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000867 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100868 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000869
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000870 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000871 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100872 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000873
Eric Snow7f8bfc92018-01-29 18:23:44 -0700874 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600875 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700876
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000877 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000878 # Here ends the simple stuff. From here on, modules need certain
879 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000880 #
881
882 # Multimedia modules
883 # These don't work for 64-bit platforms!!!
884 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200885 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000886 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000887 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000888 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200889 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800890 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100891 self.add(Extension('audioop', ['audioop.c'],
892 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000893
Victor Stinner5ec33a12019-03-01 16:43:28 +0100894 # CSV files
895 self.add(Extension('_csv', ['_csv.c']))
896
897 # POSIX subprocess module helper.
898 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
899
Victor Stinnercfe172d2019-03-01 18:21:49 +0100900 def detect_test_extensions(self):
901 # Python C API test module
902 self.add(Extension('_testcapi', ['_testcapimodule.c'],
903 depends=['testcapi_long.h']))
904
Victor Stinner23bace22019-04-18 11:37:26 +0200905 # Python Internal C API test module
906 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +0200907 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +0200908
Victor Stinnercfe172d2019-03-01 18:21:49 +0100909 # Python PEP-3118 (buffer protocol) test module
910 self.add(Extension('_testbuffer', ['_testbuffer.c']))
911
912 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
913 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
914
915 # Test multi-phase extension module init (PEP 489)
916 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
917
918 # Fuzz tests.
919 self.add(Extension('_xxtestfuzz',
920 ['_xxtestfuzz/_xxtestfuzz.c',
921 '_xxtestfuzz/fuzzer.c']))
922
Victor Stinner5ec33a12019-03-01 16:43:28 +0100923 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000924 # readline
Victor Stinner625dbf22019-03-01 15:59:39 +0100925 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000926 readline_termcap_library = ""
927 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200928 # Cannot use os.popen here in py3k.
929 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
930 if not os.path.exists(self.build_temp):
931 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000932 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200933 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100934 if CROSS_COMPILING:
doko@ubuntu.com58844492012-06-30 18:25:32 +0200935 ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
936 % (sysconfig.get_config_var('READELF'),
937 do_readline, tmpfile))
938 elif find_executable('ldd'):
939 ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
940 else:
941 ret = 256
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200942 if ret >> 8 == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +0000943 with open(tmpfile) as fp:
944 for ln in fp:
945 if 'curses' in ln:
946 readline_termcap_library = re.sub(
947 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
948 ).rstrip()
949 break
950 # termcap interface split out from ncurses
951 if 'tinfo' in ln:
952 readline_termcap_library = 'tinfo'
953 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200954 if os.path.exists(tmpfile):
955 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +0000956 # Issue 7384: If readline is already linked against curses,
957 # use the same library for the readline and curses modules.
958 if 'curses' in readline_termcap_library:
959 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +0100960 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +0000961 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +0200962 # Issue 36210: OSS provided ncurses does not link on AIX
963 # Use IBM supplied 'curses' for successful build of _curses
964 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
965 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100966 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000967 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100968 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000969 curses_library = 'curses'
970
Victor Stinner4cbea512019-02-28 17:48:38 +0100971 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000972 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +0000973 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -0700974 if (dep_target and
975 (tuple(int(n) for n in dep_target.split('.')[0:2])
976 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +0000977 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000978 if os_release < 9:
979 # MacOSX 10.4 has a broken readline. Don't try to build
980 # the readline module unless the user has installed a fixed
981 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +0100982 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000983 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +0000984 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100985 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000986 # In every directory on the search path search for a dynamic
987 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +0000988 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +0000989 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000990 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000991 readline_extra_link_args = ('-Wl,-search_paths_first',)
992 else:
993 readline_extra_link_args = ()
994
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000995 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +0000996 if readline_termcap_library:
997 pass # Issue 7384: Already linked against curses or tinfo.
998 elif curses_library:
999 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001000 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001001 ['/usr/lib/termcap'],
1002 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001003 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001004 self.add(Extension('readline', ['readline.c'],
1005 library_dirs=['/usr/lib/termcap'],
1006 extra_link_args=readline_extra_link_args,
1007 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001008 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001009 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001010
Victor Stinner5ec33a12019-03-01 16:43:28 +01001011 # Curses support, requiring the System V version of curses, often
1012 # provided by the ncurses library.
1013 curses_defines = []
1014 curses_includes = []
1015 panel_library = 'panel'
1016 if curses_library == 'ncursesw':
1017 curses_defines.append(('HAVE_NCURSESW', '1'))
1018 if not CROSS_COMPILING:
1019 curses_includes.append('/usr/include/ncursesw')
1020 # Bug 1464056: If _curses.so links with ncursesw,
1021 # _curses_panel.so must link with panelw.
1022 panel_library = 'panelw'
1023 if MACOS:
1024 # On OS X, there is no separate /usr/lib/libncursesw nor
1025 # libpanelw. If we are here, we found a locally-supplied
1026 # version of libncursesw. There should also be a
1027 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1028 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1029 # ncurses wide char support
1030 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1031 elif MACOS and curses_library == 'ncurses':
1032 # Building with the system-suppied combined libncurses/libpanel
1033 curses_defines.append(('HAVE_NCURSESW', '1'))
1034 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001035
Victor Stinnercfe172d2019-03-01 18:21:49 +01001036 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001037 if curses_library.startswith('ncurses'):
1038 curses_libs = [curses_library]
1039 self.add(Extension('_curses', ['_cursesmodule.c'],
1040 include_dirs=curses_includes,
1041 define_macros=curses_defines,
1042 libraries=curses_libs))
1043 elif curses_library == 'curses' and not MACOS:
1044 # OSX has an old Berkeley curses, not good enough for
1045 # the _curses module.
1046 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1047 curses_libs = ['curses', 'terminfo']
1048 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1049 curses_libs = ['curses', 'termcap']
1050 else:
1051 curses_libs = ['curses']
1052
1053 self.add(Extension('_curses', ['_cursesmodule.c'],
1054 define_macros=curses_defines,
1055 libraries=curses_libs))
1056 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001057 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001058 self.missing.append('_curses')
1059
1060 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001061 # _curses_panel needs some form of ncurses
1062 skip_curses_panel = True if AIX else False
1063 if (curses_enabled and not skip_curses_panel and
1064 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001065 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001066 include_dirs=curses_includes,
1067 define_macros=curses_defines,
1068 libraries=[panel_library, *curses_libs]))
1069 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001070 self.missing.append('_curses_panel')
1071
1072 def detect_crypt(self):
1073 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001074 if VXWORKS:
1075 # bpo-31904: crypt() function is not provided by VxWorks.
1076 # DES_crypt() OpenSSL provides is too weak to implement
1077 # the encryption.
1078 return
1079
Victor Stinner625dbf22019-03-01 15:59:39 +01001080 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001081 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001082 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001083 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001084
pxinwr236d0b72019-04-15 17:02:20 +08001085 self.add(Extension('_crypt', ['_cryptmodule.c'],
Victor Stinner8058bda2019-03-01 15:31:45 +01001086 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001087
Victor Stinner5ec33a12019-03-01 16:43:28 +01001088 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001089 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +08001090 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +01001091 self.add(Extension('_socket', ['socketmodule.c'],
1092 depends=['socketmodule.h']))
Victor Stinner625dbf22019-03-01 15:59:39 +01001093 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 19:09:28 +08001094 libs = ['net']
Victor Stinner8058bda2019-03-01 15:31:45 +01001095 self.add(Extension('_socket', ['socketmodule.c'],
1096 depends=['socketmodule.h'],
1097 libraries=libs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001098
Victor Stinner5ec33a12019-03-01 16:43:28 +01001099 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001100 # Modules that provide persistent dictionary-like semantics. You will
1101 # probably want to arrange for at least one of them to be available on
1102 # your machine, though none are defined by default because of library
1103 # dependencies. The Python module dbm/__init__.py provides an
1104 # implementation independent wrapper for these; dbm/dumb.py provides
1105 # similar functionality (but slower of course) implemented in Python.
1106
1107 # Sleepycat^WOracle Berkeley DB interface.
1108 # http://www.oracle.com/database/berkeley-db/db/index.html
1109 #
1110 # This requires the Sleepycat^WOracle DB code. The supported versions
1111 # are set below. Visit the URL above to download
1112 # a release. Most open source OSes come with one or more
1113 # versions of BerkeleyDB already installed.
1114
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001115 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001116 min_db_ver = (3, 3)
1117 db_setup_debug = False # verbose debug prints from this script?
1118
1119 def allow_db_ver(db_ver):
1120 """Returns a boolean if the given BerkeleyDB version is acceptable.
1121
1122 Args:
1123 db_ver: A tuple of the version to verify.
1124 """
1125 if not (min_db_ver <= db_ver <= max_db_ver):
1126 return False
1127 return True
1128
1129 def gen_db_minor_ver_nums(major):
1130 if major == 4:
1131 for x in range(max_db_ver[1]+1):
1132 if allow_db_ver((4, x)):
1133 yield x
1134 elif major == 3:
1135 for x in (3,):
1136 if allow_db_ver((3, x)):
1137 yield x
1138 else:
1139 raise ValueError("unknown major BerkeleyDB version", major)
1140
1141 # construct a list of paths to look for the header file in on
1142 # top of the normal inc_dirs.
1143 db_inc_paths = [
1144 '/usr/include/db4',
1145 '/usr/local/include/db4',
1146 '/opt/sfw/include/db4',
1147 '/usr/include/db3',
1148 '/usr/local/include/db3',
1149 '/opt/sfw/include/db3',
1150 # Fink defaults (http://fink.sourceforge.net/)
1151 '/sw/include/db4',
1152 '/sw/include/db3',
1153 ]
1154 # 4.x minor number specific paths
1155 for x in gen_db_minor_ver_nums(4):
1156 db_inc_paths.append('/usr/include/db4%d' % x)
1157 db_inc_paths.append('/usr/include/db4.%d' % x)
1158 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1159 db_inc_paths.append('/usr/local/include/db4%d' % x)
1160 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1161 db_inc_paths.append('/opt/db-4.%d/include' % x)
1162 # MacPorts default (http://www.macports.org/)
1163 db_inc_paths.append('/opt/local/include/db4%d' % x)
1164 # 3.x minor number specific paths
1165 for x in gen_db_minor_ver_nums(3):
1166 db_inc_paths.append('/usr/include/db3%d' % x)
1167 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1168 db_inc_paths.append('/usr/local/include/db3%d' % x)
1169 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1170 db_inc_paths.append('/opt/db-3.%d/include' % x)
1171
Victor Stinner4cbea512019-02-28 17:48:38 +01001172 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001173 db_inc_paths = []
1174
Georg Brandl489cb4f2009-07-11 10:08:49 +00001175 # Add some common subdirectories for Sleepycat DB to the list,
1176 # based on the standard include directories. This way DB3/4 gets
1177 # picked up when it is installed in a non-standard prefix and
1178 # the user has added that prefix into inc_dirs.
1179 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001180 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001181 std_variants.append(os.path.join(dn, 'db3'))
1182 std_variants.append(os.path.join(dn, 'db4'))
1183 for x in gen_db_minor_ver_nums(4):
1184 std_variants.append(os.path.join(dn, "db4%d"%x))
1185 std_variants.append(os.path.join(dn, "db4.%d"%x))
1186 for x in gen_db_minor_ver_nums(3):
1187 std_variants.append(os.path.join(dn, "db3%d"%x))
1188 std_variants.append(os.path.join(dn, "db3.%d"%x))
1189
1190 db_inc_paths = std_variants + db_inc_paths
1191 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1192
1193 db_ver_inc_map = {}
1194
Victor Stinner4cbea512019-02-28 17:48:38 +01001195 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001196 sysroot = macosx_sdk_root()
1197
Georg Brandl489cb4f2009-07-11 10:08:49 +00001198 class db_found(Exception): pass
1199 try:
1200 # See whether there is a Sleepycat header in the standard
1201 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001202 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001203 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001204 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001205 f = os.path.join(sysroot, d[1:], "db.h")
1206
Georg Brandl489cb4f2009-07-11 10:08:49 +00001207 if db_setup_debug: print("db: looking for db.h in", f)
1208 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001209 with open(f, 'rb') as file:
1210 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001211 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001212 if m:
1213 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001214 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001215 db_minor = int(m.group(1))
1216 db_ver = (db_major, db_minor)
1217
1218 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1219 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001220 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001221 db_patch = int(m.group(1))
1222 if db_patch < 21:
1223 print("db.h:", db_ver, "patch", db_patch,
1224 "being ignored (4.6.x must be >= 4.6.21)")
1225 continue
1226
1227 if ( (db_ver not in db_ver_inc_map) and
1228 allow_db_ver(db_ver) ):
1229 # save the include directory with the db.h version
1230 # (first occurrence only)
1231 db_ver_inc_map[db_ver] = d
1232 if db_setup_debug:
1233 print("db.h: found", db_ver, "in", d)
1234 else:
1235 # we already found a header for this library version
1236 if db_setup_debug: print("db.h: ignoring", d)
1237 else:
1238 # ignore this header, it didn't contain a version number
1239 if db_setup_debug:
1240 print("db.h: no version number version in", d)
1241
1242 db_found_vers = list(db_ver_inc_map.keys())
1243 db_found_vers.sort()
1244
1245 while db_found_vers:
1246 db_ver = db_found_vers.pop()
1247 db_incdir = db_ver_inc_map[db_ver]
1248
1249 # check lib directories parallel to the location of the header
1250 db_dirs_to_check = [
1251 db_incdir.replace("include", 'lib64'),
1252 db_incdir.replace("include", 'lib'),
1253 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001254
Victor Stinner4cbea512019-02-28 17:48:38 +01001255 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001256 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1257
1258 else:
1259 # Same as other branch, but takes OSX SDK into account
1260 tmp = []
1261 for dn in db_dirs_to_check:
1262 if is_macosx_sdk_path(dn):
1263 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1264 tmp.append(dn)
1265 else:
1266 if os.path.isdir(dn):
1267 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001268 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001269
1270 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001271
Ezio Melotti42da6632011-03-15 05:18:48 +02001272 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001273 # XXX should we -ever- look for a dbX name? Do any
1274 # systems really not name their library by version and
1275 # symlink to more general names?
1276 for dblib in (('db-%d.%d' % db_ver),
1277 ('db%d%d' % db_ver),
1278 ('db%d' % db_ver[0])):
1279 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001280 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001281 if dblib_file:
1282 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1283 raise db_found
1284 else:
1285 if db_setup_debug: print("db lib: ", dblib, "not found")
1286
1287 except db_found:
1288 if db_setup_debug:
1289 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1290 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001291 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001292 # Only add the found library and include directories if they aren't
1293 # already being searched. This avoids an explicit runtime library
1294 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001295 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001296 db_incs = None
1297 else:
1298 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001299 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001300 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001301 else:
1302 if db_setup_debug: print("db: no appropriate library found")
1303 db_incs = None
1304 dblibs = []
1305 dblib_dir = None
1306
Victor Stinner5ec33a12019-03-01 16:43:28 +01001307 dbm_setup_debug = False # verbose debug prints from this script?
1308 dbm_order = ['gdbm']
1309 # The standard Unix dbm module:
1310 if not CYGWIN:
1311 config_args = [arg.strip("'")
1312 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1313 dbm_args = [arg for arg in config_args
1314 if arg.startswith('--with-dbmliborder=')]
1315 if dbm_args:
1316 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1317 else:
1318 dbm_order = "ndbm:gdbm:bdb".split(":")
1319 dbmext = None
1320 for cand in dbm_order:
1321 if cand == "ndbm":
1322 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1323 # Some systems have -lndbm, others have -lgdbm_compat,
1324 # others don't have either
1325 if self.compiler.find_library_file(self.lib_dirs,
1326 'ndbm'):
1327 ndbm_libs = ['ndbm']
1328 elif self.compiler.find_library_file(self.lib_dirs,
1329 'gdbm_compat'):
1330 ndbm_libs = ['gdbm_compat']
1331 else:
1332 ndbm_libs = []
1333 if dbm_setup_debug: print("building dbm using ndbm")
1334 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1335 define_macros=[
1336 ('HAVE_NDBM_H',None),
1337 ],
1338 libraries=ndbm_libs)
1339 break
1340
1341 elif cand == "gdbm":
1342 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1343 gdbm_libs = ['gdbm']
1344 if self.compiler.find_library_file(self.lib_dirs,
1345 'gdbm_compat'):
1346 gdbm_libs.append('gdbm_compat')
1347 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1348 if dbm_setup_debug: print("building dbm using gdbm")
1349 dbmext = Extension(
1350 '_dbm', ['_dbmmodule.c'],
1351 define_macros=[
1352 ('HAVE_GDBM_NDBM_H', None),
1353 ],
1354 libraries = gdbm_libs)
1355 break
1356 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1357 if dbm_setup_debug: print("building dbm using gdbm")
1358 dbmext = Extension(
1359 '_dbm', ['_dbmmodule.c'],
1360 define_macros=[
1361 ('HAVE_GDBM_DASH_NDBM_H', None),
1362 ],
1363 libraries = gdbm_libs)
1364 break
1365 elif cand == "bdb":
1366 if dblibs:
1367 if dbm_setup_debug: print("building dbm using bdb")
1368 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1369 library_dirs=dblib_dir,
1370 runtime_library_dirs=dblib_dir,
1371 include_dirs=db_incs,
1372 define_macros=[
1373 ('HAVE_BERKDB_H', None),
1374 ('DB_DBM_HSEARCH', None),
1375 ],
1376 libraries=dblibs)
1377 break
1378 if dbmext is not None:
1379 self.add(dbmext)
1380 else:
1381 self.missing.append('_dbm')
1382
1383 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1384 if ('gdbm' in dbm_order and
1385 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1386 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1387 libraries=['gdbm']))
1388 else:
1389 self.missing.append('_gdbm')
1390
1391 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001392 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001393 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001394
1395 # We hunt for #define SQLITE_VERSION "n.n.n"
Charles Pigottad0daf52019-04-26 16:38:12 +01001396 # We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001397 sqlite_incdir = sqlite_libdir = None
1398 sqlite_inc_paths = [ '/usr/include',
1399 '/usr/include/sqlite',
1400 '/usr/include/sqlite3',
1401 '/usr/local/include',
1402 '/usr/local/include/sqlite',
1403 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001404 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001405 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001406 sqlite_inc_paths = []
gescheitb9a03762019-07-13 06:15:49 +03001407 MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001408 MIN_SQLITE_VERSION = ".".join([str(x)
1409 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001410
1411 # Scan the default include directories before the SQLite specific
1412 # ones. This allows one to override the copy of sqlite on OSX,
1413 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001414 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001415 sysroot = macosx_sdk_root()
1416
Victor Stinner625dbf22019-03-01 15:59:39 +01001417 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001418 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001419 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001420 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001421
Ned Deily9b635832012-08-05 15:13:33 -07001422 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001423 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001424 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001425 with open(f) as file:
1426 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001427 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001428 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001429 if m:
1430 sqlite_version = m.group(1)
1431 sqlite_version_tuple = tuple([int(x)
1432 for x in sqlite_version.split(".")])
1433 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1434 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001435 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001436 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001437 sqlite_incdir = d
1438 break
1439 else:
1440 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001441 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001442 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001443 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001444 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001445
1446 if sqlite_incdir:
1447 sqlite_dirs_to_check = [
1448 os.path.join(sqlite_incdir, '..', 'lib64'),
1449 os.path.join(sqlite_incdir, '..', 'lib'),
1450 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1451 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1452 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001453 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001454 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001455 if sqlite_libfile:
1456 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001457
1458 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001459 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001460 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001461 '_sqlite/cursor.c',
1462 '_sqlite/microprotocols.c',
1463 '_sqlite/module.c',
1464 '_sqlite/prepare_protocol.c',
1465 '_sqlite/row.c',
1466 '_sqlite/statement.c',
1467 '_sqlite/util.c', ]
1468
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001469 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001470 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001471 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1472 else:
1473 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1474
Benjamin Peterson076ed002010-10-31 17:11:02 +00001475 # Enable support for loadable extensions in the sqlite3 module
1476 # if --enable-loadable-sqlite-extensions configure option is used.
1477 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1478 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001479
Victor Stinner4cbea512019-02-28 17:48:38 +01001480 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001481 # In every directory on the search path search for a dynamic
1482 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001483 # for dynamic libraries on the entire path.
1484 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001485 # before the dynamic library in /usr/lib.
1486 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1487 else:
1488 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001489
Brett Cannonc5011fe2011-06-06 20:09:10 -07001490 include_dirs = ["Modules/_sqlite"]
1491 # Only include the directory where sqlite was found if it does
1492 # not already exist in set include directories, otherwise you
1493 # can end up with a bad search path order.
1494 if sqlite_incdir not in self.compiler.include_dirs:
1495 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001496 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001497 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001498 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001499 self.add(Extension('_sqlite3', sqlite_srcs,
1500 define_macros=sqlite_defines,
1501 include_dirs=include_dirs,
1502 library_dirs=sqlite_libdir,
1503 extra_link_args=sqlite_extra_link_args,
1504 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001505 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001506 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001507
Victor Stinner5ec33a12019-03-01 16:43:28 +01001508 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001509 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001510 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001511 if not VXWORKS:
1512 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001513 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001514 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001515 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001516 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001517 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001518
Victor Stinner5ec33a12019-03-01 16:43:28 +01001519 # Platform-specific libraries
1520 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1521 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001522 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001523 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001524
Victor Stinner5ec33a12019-03-01 16:43:28 +01001525 if MACOS:
1526 self.add(Extension('_scproxy', ['_scproxy.c'],
1527 extra_link_args=[
1528 '-framework', 'SystemConfiguration',
1529 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001530
Victor Stinner5ec33a12019-03-01 16:43:28 +01001531 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001532 # Andrew Kuchling's zlib module. Note that some versions of zlib
1533 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1534 # http://www.cert.org/advisories/CA-2002-07.html
1535 #
1536 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1537 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1538 # now, we still accept 1.1.3, because we think it's difficult to
1539 # exploit this in Python, and we'd rather make it RedHat's problem
1540 # than our problem <wink>.
1541 #
1542 # You can upgrade zlib to version 1.1.4 yourself by going to
1543 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001544 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001545 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001546 if zlib_inc is not None:
1547 zlib_h = zlib_inc[0] + '/zlib.h'
1548 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001549 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001550 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001551 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001552 with open(zlib_h) as fp:
1553 while 1:
1554 line = fp.readline()
1555 if not line:
1556 break
1557 if line.startswith('#define ZLIB_VERSION'):
1558 version = line.split()[2]
1559 break
Guido van Rossume6970912001-04-15 15:16:12 +00001560 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001561 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001562 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001563 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1564 else:
1565 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001566 self.add(Extension('zlib', ['zlibmodule.c'],
1567 libraries=['z'],
1568 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001569 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001570 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001571 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001572 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001573 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001574 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001575 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001576
Christian Heimes1dc54002008-03-24 02:19:29 +00001577 # Helper module for various ascii-encoders. Uses zlib for an optimized
1578 # crc32 if we have it. Otherwise binascii uses its own.
1579 if have_zlib:
1580 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1581 libraries = ['z']
1582 extra_link_args = zlib_extra_link_args
1583 else:
1584 extra_compile_args = []
1585 libraries = []
1586 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001587 self.add(Extension('binascii', ['binascii.c'],
1588 extra_compile_args=extra_compile_args,
1589 libraries=libraries,
1590 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001591
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001592 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001593 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001594 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001595 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1596 else:
1597 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001598 self.add(Extension('_bz2', ['_bz2module.c'],
1599 libraries=['bz2'],
1600 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001601 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001602 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001603
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001604 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001605 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001606 self.add(Extension('_lzma', ['_lzmamodule.c'],
1607 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001608 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001609 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001610
Victor Stinner5ec33a12019-03-01 16:43:28 +01001611 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001612 # Interface to the Expat XML parser
1613 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001614 # Expat was written by James Clark and is now maintained by a group of
1615 # developers on SourceForge; see www.libexpat.org for more information.
1616 # The pyexpat module was written by Paul Prescod after a prototype by
1617 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1618 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001619 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001620 #
1621 # More information on Expat can be found at www.libexpat.org.
1622 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001623 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1624 expat_inc = []
1625 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001626 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001627 expat_lib = ['expat']
1628 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001629 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001630 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001631 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001632 define_macros = [
1633 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001634 # bpo-30947: Python uses best available entropy sources to
1635 # call XML_SetHashSalt(), expat entropy sources are not needed
1636 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001637 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001638 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001639 expat_lib = []
1640 expat_sources = ['expat/xmlparse.c',
1641 'expat/xmlrole.c',
1642 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001643 expat_depends = ['expat/ascii.h',
1644 'expat/asciitab.h',
1645 'expat/expat.h',
1646 'expat/expat_config.h',
1647 'expat/expat_external.h',
1648 'expat/internal.h',
1649 'expat/latin1tab.h',
1650 'expat/utf8tab.h',
1651 'expat/xmlrole.h',
1652 'expat/xmltok.h',
1653 'expat/xmltok_impl.h'
1654 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001655
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001656 cc = sysconfig.get_config_var('CC').split()[0]
1657 ret = os.system(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001658 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001659 if ret >> 8 == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001660 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001661
Victor Stinner8058bda2019-03-01 15:31:45 +01001662 self.add(Extension('pyexpat',
1663 define_macros=define_macros,
1664 extra_compile_args=extra_compile_args,
1665 include_dirs=expat_inc,
1666 libraries=expat_lib,
1667 sources=['pyexpat.c'] + expat_sources,
1668 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001669
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001670 # Fredrik Lundh's cElementTree module. Note that this also
1671 # uses expat (via the CAPI hook in pyexpat).
1672
Victor Stinner625dbf22019-03-01 15:59:39 +01001673 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001674 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001675 self.add(Extension('_elementtree',
1676 define_macros=define_macros,
1677 include_dirs=expat_inc,
1678 libraries=expat_lib,
1679 sources=['_elementtree.c'],
1680 depends=['pyexpat.c', *expat_sources,
1681 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001682 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001683 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001684
Victor Stinner5ec33a12019-03-01 16:43:28 +01001685 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001686 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001687 self.add(Extension('_multibytecodec',
1688 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001689 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001690 self.add(Extension('_codecs_%s' % loc,
1691 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001692
Victor Stinner5ec33a12019-03-01 16:43:28 +01001693 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001694 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001695 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001696 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1697 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001698
1699 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001700 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001701 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1702 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001703 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001704 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1705 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 17:19:04 +01001706 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-01 22:52:23 -06001707 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001708 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1709 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001710 libs.append('rt')
Victor Stinner8058bda2019-03-01 15:31:45 +01001711 self.add(Extension('_posixshmem', posixshmem_srcs,
1712 define_macros={},
1713 libraries=libs,
1714 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001715
Victor Stinner8058bda2019-03-01 15:31:45 +01001716 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001717 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001718
Victor Stinner5ec33a12019-03-01 16:43:28 +01001719 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001720 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001721 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001722 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001723 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001724 uuid_libs = ['uuid']
1725 else:
1726 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001727 self.add(Extension('_uuid', ['_uuidmodule.c'],
1728 libraries=uuid_libs,
1729 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001730 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001731 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001732
Victor Stinner5ec33a12019-03-01 16:43:28 +01001733 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001734 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001735 self.init_inc_lib_dirs()
1736
1737 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001738 if TEST_EXTENSIONS:
1739 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001740 self.detect_readline_curses()
1741 self.detect_crypt()
1742 self.detect_socket()
1743 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001744 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001745 self.detect_dbm_gdbm()
1746 self.detect_sqlite()
1747 self.detect_platform_specific_exts()
1748 self.detect_nis()
1749 self.detect_compress_exts()
1750 self.detect_expat_elementtree()
1751 self.detect_multibytecodecs()
1752 self.detect_decimal()
1753 self.detect_ctypes()
1754 self.detect_multiprocessing()
1755 if not self.detect_tkinter():
1756 self.missing.append('_tkinter')
1757 self.detect_uuid()
1758
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001759## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001760## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001761
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001762 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001763 self.add(Extension('xxlimited', ['xxlimited.c'],
1764 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001765
Ned Deilyd819b932013-09-06 01:07:05 -07001766 def detect_tkinter_explicitly(self):
1767 # Build _tkinter using explicit locations for Tcl/Tk.
1768 #
1769 # This is enabled when both arguments are given to ./configure:
1770 #
1771 # --with-tcltk-includes="-I/path/to/tclincludes \
1772 # -I/path/to/tkincludes"
1773 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1774 # -L/path/to/tklibs -ltkm.n"
1775 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001776 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001777 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1778 #
1779 # This can be useful for building and testing tkinter with multiple
1780 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1781 # build of Tcl so you need to specify both arguments and use care when
1782 # overriding.
1783
1784 # The _TCLTK variables are created in the Makefile sharedmods target.
1785 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1786 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1787 if not (tcltk_includes and tcltk_libs):
1788 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001789 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001790
1791 extra_compile_args = tcltk_includes.split()
1792 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001793 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1794 define_macros=[('WITH_APPINIT', 1)],
1795 extra_compile_args = extra_compile_args,
1796 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001797 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001798
Victor Stinner625dbf22019-03-01 15:59:39 +01001799 def detect_tkinter_darwin(self):
Jack Jansen0b06be72002-06-21 14:48:38 +00001800 # The _tkinter module, using frameworks. Since frameworks are quite
1801 # different the UNIX search logic is not sharable.
1802 from os.path import join, exists
1803 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001804 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:48 +00001805 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:38 +00001806 join(os.getenv('HOME'), '/Library/Frameworks')
1807 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001808
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001809 sysroot = macosx_sdk_root()
1810
Skip Montanaro0174ddd2005-12-30 05:01:26 +00001811 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:38 +00001812 # bundles.
1813 # XXX distutils should support -F!
1814 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001815 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001816
1817
Jack Jansen0b06be72002-06-21 14:48:38 +00001818 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001819 if is_macosx_sdk_path(F):
1820 if not exists(join(sysroot, F[1:], fw + '.framework')):
1821 break
1822 else:
1823 if not exists(join(F, fw + '.framework')):
1824 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001825 else:
1826 # ok, F is now directory with both frameworks. Continure
1827 # building
1828 break
1829 else:
1830 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1831 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001832 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001833
Jack Jansen0b06be72002-06-21 14:48:38 +00001834 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1835 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:43 +00001836 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:38 +00001837 #
1838 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001839 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001840 for fw in ('Tcl', 'Tk')
1841 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:38 +00001842 ]
1843
Tim Peters2c60f7a2003-01-29 03:49:43 +00001844 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:38 +00001845 # complicated search, this is a hard-coded path. It could bail out
1846 # if X11 libs are not found...
1847 include_dirs.append('/usr/X11R6/include')
1848 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1849
Georg Brandlfcaf9102008-07-16 02:17:56 +00001850 # All existing framework builds of Tcl/Tk don't support 64-bit
1851 # architectures.
1852 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001853 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001854
Ronald Oussorend097efe2009-09-15 19:07:58 +00001855 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1856 if not os.path.exists(self.build_temp):
1857 os.makedirs(self.build_temp)
1858
1859 # Note: cannot use os.popen or subprocess here, that
1860 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001861 if is_macosx_sdk_path(F):
1862 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1863 else:
1864 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001865
Brett Cannon9f5db072010-10-29 20:19:27 +00001866 with open(tmpfile) as fp:
1867 detected_archs = []
1868 for ln in fp:
1869 a = ln.split()[-1]
1870 if a in archs:
1871 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001872 os.unlink(tmpfile)
1873
1874 for a in detected_archs:
1875 frameworks.append('-arch')
1876 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001877
Victor Stinnercfe172d2019-03-01 18:21:49 +01001878 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1879 define_macros=[('WITH_APPINIT', 1)],
1880 include_dirs=include_dirs,
1881 libraries=[],
1882 extra_compile_args=frameworks[2:],
1883 extra_link_args=frameworks))
Victor Stinner4cbea512019-02-28 17:48:38 +01001884 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001885
Victor Stinner625dbf22019-03-01 15:59:39 +01001886 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001887 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001888
Ned Deilyd819b932013-09-06 01:07:05 -07001889 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1890 # configured or passed into the make target. If so, use these values
1891 # to build tkinter and bypass the searches for Tcl and TK in standard
1892 # locations.
1893 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 16:43:28 +01001894 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001895
Jack Jansen0b06be72002-06-21 14:48:38 +00001896 # Rather than complicate the code below, detecting and building
1897 # AquaTk is a separate method. Only one Tkinter will be built on
1898 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01001899 if (MACOS and self.detect_tkinter_darwin()):
1900 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001901
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001902 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001903 # The versions with dots are used on Unix, and the versions without
1904 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001905 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00001906 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1907 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01001908 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001909 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01001910 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001911 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00001912 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001913 # Exit the loop when we've found the Tcl/Tk libraries
1914 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001915
Fredrik Lundhade711a2001-01-24 08:00:28 +00001916 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001917 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001918 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001919 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001920 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01001921 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001922 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1923 # but the include subdirs are named like .../include/tcl8.3.
1924 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1925 tcl_include_sub = []
1926 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001927 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001928 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1929 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1930 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01001931 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
1932 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001933
Martin v. Löwise86a59a2003-05-03 08:45:51 +00001934 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001935 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001936 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01001937 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00001938
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001939 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001940
Victor Stinnercfe172d2019-03-01 18:21:49 +01001941 include_dirs = []
1942 libs = []
1943 defs = []
1944 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001945 for dir in tcl_includes + tk_includes:
1946 if dir not in include_dirs:
1947 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001948
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001949 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01001950 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001951 include_dirs.append('/usr/openwin/include')
1952 added_lib_dirs.append('/usr/openwin/lib')
1953 elif os.path.exists('/usr/X11R6/include'):
1954 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00001955 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001956 added_lib_dirs.append('/usr/X11R6/lib')
1957 elif os.path.exists('/usr/X11R5/include'):
1958 include_dirs.append('/usr/X11R5/include')
1959 added_lib_dirs.append('/usr/X11R5/lib')
1960 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001961 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001962 include_dirs.append('/usr/X11/include')
1963 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001964
Jason Tishler9181c942003-02-05 15:16:17 +00001965 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01001966 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00001967 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1968 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001969 return False
Jason Tishler9181c942003-02-05 15:16:17 +00001970
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001971 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01001972 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001973 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001974 defs.append( ('WITH_BLT', 1) )
1975 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01001976 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001977 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00001978 defs.append( ('WITH_BLT', 1) )
1979 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001980
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001981 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00001982 libs.append('tk'+ version)
1983 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001984
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001985 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01001986 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001987 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001988
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001989 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001990 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001991 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001992 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001993 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001994 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001995 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001996
Victor Stinnercfe172d2019-03-01 18:21:49 +01001997 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1998 define_macros=[('WITH_APPINIT', 1)] + defs,
1999 include_dirs=include_dirs,
2000 libraries=libs,
2001 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002002 return True
2003
Christian Heimes78644762008-03-04 23:39:23 +00002004 def configure_ctypes_darwin(self, ext):
2005 # Darwin (OS X) uses preconfigured files, in
2006 # the Modules/_ctypes/libffi_osx directory.
Victor Stinner625dbf22019-03-01 15:59:39 +01002007 ffi_srcdir = os.path.abspath(os.path.join(self.srcdir, 'Modules',
Christian Heimes78644762008-03-04 23:39:23 +00002008 '_ctypes', 'libffi_osx'))
2009 sources = [os.path.join(ffi_srcdir, p)
2010 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:56 +00002011 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:23 +00002012 'x86/x86-darwin.S',
2013 'x86/x86-ffi_darwin.c',
2014 'x86/x86-ffi64.c',
2015 'powerpc/ppc-darwin.S',
2016 'powerpc/ppc-darwin_closure.S',
2017 'powerpc/ppc-ffi_darwin.c',
2018 'powerpc/ppc64-darwin_closure.S',
2019 ]]
2020
2021 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:05 +00002022 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:23 +00002023
2024 include_dirs = [os.path.join(ffi_srcdir, 'include'),
2025 os.path.join(ffi_srcdir, 'powerpc')]
2026 ext.include_dirs.extend(include_dirs)
2027 ext.sources.extend(sources)
2028 return True
2029
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002030 def configure_ctypes(self, ext):
2031 if not self.use_system_libffi:
Victor Stinner4cbea512019-02-28 17:48:38 +01002032 if MACOS:
Christian Heimes78644762008-03-04 23:39:23 +00002033 return self.configure_ctypes_darwin(ext)
Zachary Waref40d4dd2016-09-17 01:25:24 -05002034 print('INFO: Could not locate ffi libs and/or headers')
2035 return False
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002036 return True
2037
Victor Stinner625dbf22019-03-01 15:59:39 +01002038 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002039 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002040 self.use_system_libffi = False
2041 include_dirs = []
2042 extra_compile_args = []
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002043 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002044 sources = ['_ctypes/_ctypes.c',
2045 '_ctypes/callbacks.c',
2046 '_ctypes/callproc.c',
2047 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002048 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002049 depends = ['_ctypes/ctypes.h']
2050
Victor Stinner4cbea512019-02-28 17:48:38 +01002051 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002052 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:58 +00002053 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:23 +00002054 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002055 include_dirs.append('_ctypes/darwin')
Victor Stinner5ec33a12019-03-01 16:43:28 +01002056 # XXX Is this still needed?
2057 # extra_link_args.extend(['-read_only_relocs', 'warning'])
Thomas Hellercf567c12006-03-08 19:51:58 +00002058
Victor Stinner4cbea512019-02-28 17:48:38 +01002059 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002060 # XXX This shouldn't be necessary; it appears that some
2061 # of the assembler code is non-PIC (i.e. it has relocations
2062 # when it shouldn't. The proper fix would be to rewrite
2063 # the assembler code to be PIC.
2064 # This only works with GCC; the Sun compiler likely refuses
2065 # this option. If you want to compile ctypes with the Sun
2066 # compiler, please research a proper solution, instead of
2067 # finding some -z option for the Sun compiler.
2068 extra_link_args.append('-mimpure-text')
2069
Victor Stinner4cbea512019-02-28 17:48:38 +01002070 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002071 extra_link_args.append('-fPIC')
2072
Thomas Hellercf567c12006-03-08 19:51:58 +00002073 ext = Extension('_ctypes',
2074 include_dirs=include_dirs,
2075 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002076 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002077 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002078 sources=sources,
2079 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002080 self.add(ext)
2081 if TEST_EXTENSIONS:
2082 # function my_sqrt() needs libm for sqrt()
2083 self.add(Extension('_ctypes_test',
2084 sources=['_ctypes/_ctypes_test.c'],
2085 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002086
Victor Stinner625dbf22019-03-01 15:59:39 +01002087 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002088 if MACOS:
Zachary Ware935043d2016-09-09 17:01:21 -07002089 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
2090 return
Christian Heimes78644762008-03-04 23:39:23 +00002091 # OS X 10.5 comes with libffi.dylib; the include files are
2092 # in /usr/include/ffi
Victor Stinner96d81582019-03-01 13:53:46 +01002093 ffi_inc_dirs.append('/usr/include/ffi')
Christian Heimes78644762008-03-04 23:39:23 +00002094
Benjamin Petersond78735d2010-01-01 16:04:23 +00002095 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:45 +00002096 if not ffi_inc or ffi_inc[0] == '':
Victor Stinner96d81582019-03-01 13:53:46 +01002097 ffi_inc = find_file('ffi.h', [], ffi_inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002098 if ffi_inc is not None:
2099 ffi_h = ffi_inc[0] + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002100 if not os.path.exists(ffi_h):
2101 ffi_inc = None
2102 print('Header file {} does not exist'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002103 ffi_lib = None
2104 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002105 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002106 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002107 ffi_lib = lib_name
2108 break
2109
2110 if ffi_inc and ffi_lib:
2111 ext.include_dirs.extend(ffi_inc)
2112 ext.libraries.append(ffi_lib)
2113 self.use_system_libffi = True
2114
Christian Heimes5bb96922018-02-25 10:22:14 +01002115 if sysconfig.get_config_var('HAVE_LIBDL'):
2116 # for dlopen, see bpo-32647
2117 ext.libraries.append('dl')
2118
Victor Stinner5ec33a12019-03-01 16:43:28 +01002119 def detect_decimal(self):
2120 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002121 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002122 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002123 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2124 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002125 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002126 sources = ['_decimal/_decimal.c']
2127 depends = ['_decimal/docstrings.h']
2128 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002129 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002130 'Modules',
2131 '_decimal',
2132 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002133 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002134 sources = [
2135 '_decimal/_decimal.c',
2136 '_decimal/libmpdec/basearith.c',
2137 '_decimal/libmpdec/constants.c',
2138 '_decimal/libmpdec/context.c',
2139 '_decimal/libmpdec/convolute.c',
2140 '_decimal/libmpdec/crt.c',
2141 '_decimal/libmpdec/difradix2.c',
2142 '_decimal/libmpdec/fnt.c',
2143 '_decimal/libmpdec/fourstep.c',
2144 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002145 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002146 '_decimal/libmpdec/mpdecimal.c',
2147 '_decimal/libmpdec/numbertheory.c',
2148 '_decimal/libmpdec/sixstep.c',
2149 '_decimal/libmpdec/transpose.c',
2150 ]
2151 depends = [
2152 '_decimal/docstrings.h',
2153 '_decimal/libmpdec/basearith.h',
2154 '_decimal/libmpdec/bits.h',
2155 '_decimal/libmpdec/constants.h',
2156 '_decimal/libmpdec/convolute.h',
2157 '_decimal/libmpdec/crt.h',
2158 '_decimal/libmpdec/difradix2.h',
2159 '_decimal/libmpdec/fnt.h',
2160 '_decimal/libmpdec/fourstep.h',
2161 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002162 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002163 '_decimal/libmpdec/mpdecimal.h',
2164 '_decimal/libmpdec/numbertheory.h',
2165 '_decimal/libmpdec/sixstep.h',
2166 '_decimal/libmpdec/transpose.h',
2167 '_decimal/libmpdec/typearith.h',
2168 '_decimal/libmpdec/umodarith.h',
2169 ]
2170
Stefan Krah1919b7e2012-03-21 18:25:23 +01002171 config = {
2172 'x64': [('CONFIG_64','1'), ('ASM','1')],
2173 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2174 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2175 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2176 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2177 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2178 ('LEGACY_COMPILER','1')],
2179 'universal': [('UNIVERSAL','1')]
2180 }
2181
Stefan Krah1919b7e2012-03-21 18:25:23 +01002182 cc = sysconfig.get_config_var('CC')
2183 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2184 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2185
2186 if machine:
2187 # Override automatic configuration to facilitate testing.
2188 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002189 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002190 # Universal here means: build with the same options Python
2191 # was built with.
2192 define_macros = config['universal']
2193 elif sizeof_size_t == 8:
2194 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2195 define_macros = config['x64']
2196 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2197 define_macros = config['uint128']
2198 else:
2199 define_macros = config['ansi64']
2200 elif sizeof_size_t == 4:
2201 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2202 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002203 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002204 # solaris: problems with register allocation.
2205 # icc >= 11.0 works as well.
2206 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002207 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002208 else:
2209 define_macros = config['ansi32']
2210 else:
2211 raise DistutilsError("_decimal: unsupported architecture")
2212
2213 # Workarounds for toolchain bugs:
2214 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2215 # Some versions of gcc miscompile inline asm:
2216 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2217 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2218 extra_compile_args.append('-fno-ipa-pure-const')
2219 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2220 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2221 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2222 undef_macros.append('_FORTIFY_SOURCE')
2223
Stefan Krah1919b7e2012-03-21 18:25:23 +01002224 # Uncomment for extra functionality:
2225 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002226 self.add(Extension('_decimal',
2227 include_dirs=include_dirs,
2228 libraries=libraries,
2229 define_macros=define_macros,
2230 undef_macros=undef_macros,
2231 extra_compile_args=extra_compile_args,
2232 sources=sources,
2233 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002234
Victor Stinner5ec33a12019-03-01 16:43:28 +01002235 def detect_openssl_hashlib(self):
2236 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002237 config_vars = sysconfig.get_config_vars()
2238
2239 def split_var(name, sep):
2240 # poor man's shlex, the re module is not available yet.
2241 value = config_vars.get(name)
2242 if not value:
2243 return ()
2244 # This trick works because ax_check_openssl uses --libs-only-L,
2245 # --libs-only-l, and --cflags-only-I.
2246 value = ' ' + value
2247 sep = ' ' + sep
2248 return [v.strip() for v in value.split(sep) if v.strip()]
2249
2250 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2251 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2252 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2253 if not openssl_libs:
2254 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002255 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002256 return None, None
2257
2258 # Find OpenSSL includes
2259 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002260 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002261 )
2262 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002263 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002264 return None, None
2265
2266 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2267 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002268 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002269 ['/usr/kerberos/include']
2270 )
2271 if krb5_h:
2272 ssl_incs.extend(krb5_h)
2273
Christian Heimes61d478c2018-01-27 15:51:38 +01002274 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 11:44:05 +02002275 self.add(Extension(
2276 '_ssl', ['_ssl.c'],
2277 include_dirs=openssl_includes,
2278 library_dirs=openssl_libdirs,
2279 libraries=openssl_libs,
2280 depends=['socketmodule.h', '_ssl/debughelpers.c'])
2281 )
Christian Heimes61d478c2018-01-27 15:51:38 +01002282 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002283 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002284
Victor Stinner8058bda2019-03-01 15:31:45 +01002285 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2286 depends=['hashlib.h'],
2287 include_dirs=openssl_includes,
2288 library_dirs=openssl_libdirs,
2289 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002290
xdegaye2ee077f2019-04-09 17:20:08 +02002291 def detect_hash_builtins(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002292 # We always compile these even when OpenSSL is available (issue #14693).
2293 # It's harmless and the object code is tiny (40-50 KiB per module,
2294 # only loaded when actually used).
2295 self.add(Extension('_sha256', ['sha256module.c'],
2296 depends=['hashlib.h']))
2297 self.add(Extension('_sha512', ['sha512module.c'],
2298 depends=['hashlib.h']))
2299 self.add(Extension('_md5', ['md5module.c'],
2300 depends=['hashlib.h']))
2301 self.add(Extension('_sha1', ['sha1module.c'],
2302 depends=['hashlib.h']))
2303
2304 blake2_deps = glob(os.path.join(self.srcdir,
2305 'Modules/_blake2/impl/*'))
2306 blake2_deps.append('hashlib.h')
2307
2308 self.add(Extension('_blake2',
2309 ['_blake2/blake2module.c',
2310 '_blake2/blake2b_impl.c',
2311 '_blake2/blake2s_impl.c'],
2312 depends=blake2_deps))
2313
2314 sha3_deps = glob(os.path.join(self.srcdir,
2315 'Modules/_sha3/kcp/*'))
2316 sha3_deps.append('hashlib.h')
2317 self.add(Extension('_sha3',
2318 ['_sha3/sha3module.c'],
2319 depends=sha3_deps))
2320
2321 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002322 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002323 self.missing.append('nis')
2324 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002325
2326 libs = []
2327 library_dirs = []
2328 includes_dirs = []
2329
2330 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2331 # moved headers and libraries to libtirpc and libnsl. The headers
2332 # are in tircp and nsl sub directories.
2333 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002334 'rpcsvc/yp_prot.h', self.inc_dirs,
2335 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002336 )
2337 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002338 'rpc/rpc.h', self.inc_dirs,
2339 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002340 )
2341 if rpcsvc_inc is None or rpc_inc is None:
2342 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002343 self.missing.append('nis')
2344 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002345 includes_dirs.extend(rpcsvc_inc)
2346 includes_dirs.extend(rpc_inc)
2347
Victor Stinner625dbf22019-03-01 15:59:39 +01002348 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002349 libs.append('nsl')
2350 else:
2351 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002352 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002353 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2354 if libnsl is not None:
2355 library_dirs.append(os.path.dirname(libnsl))
2356 libs.append('nsl')
2357
Victor Stinner625dbf22019-03-01 15:59:39 +01002358 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002359 libs.append('tirpc')
2360
Victor Stinner8058bda2019-03-01 15:31:45 +01002361 self.add(Extension('nis', ['nismodule.c'],
2362 libraries=libs,
2363 library_dirs=library_dirs,
2364 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002365
Christian Heimesff5be6e2018-01-20 13:19:21 +01002366
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002367class PyBuildInstall(install):
2368 # Suppress the warning about installation into the lib_dynload
2369 # directory, which is not in sys.path when running Python during
2370 # installation:
2371 def initialize_options (self):
2372 install.initialize_options(self)
2373 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002374
Éric Araujoe6792c12011-06-09 14:07:02 +02002375 # Customize subcommands to not install an egg-info file for Python
2376 sub_commands = [('install_lib', install.has_lib),
2377 ('install_headers', install.has_headers),
2378 ('install_scripts', install.has_scripts),
2379 ('install_data', install.has_data)]
2380
2381
Michael W. Hudson529a5052002-12-17 16:47:17 +00002382class PyBuildInstallLib(install_lib):
2383 # Do exactly what install_lib does but make sure correct access modes get
2384 # set on installed directories and files. All installed files with get
2385 # mode 644 unless they are a shared library in which case they will get
2386 # mode 755. All installed directories will get mode 755.
2387
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002388 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2389 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002390
2391 def install(self):
2392 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002393 self.set_file_modes(outfiles, 0o644, 0o755)
2394 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002395 return outfiles
2396
2397 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002398 if not files: return
2399
2400 for filename in files:
2401 if os.path.islink(filename): continue
2402 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002403 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002404 log.info("changing mode of %s to %o", filename, mode)
2405 if not self.dry_run: os.chmod(filename, mode)
2406
2407 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002408 for dirpath, dirnames, fnames in os.walk(dirname):
2409 if os.path.islink(dirpath):
2410 continue
2411 log.info("changing mode of %s to %o", dirpath, mode)
2412 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002413
Victor Stinnerc991f242019-03-01 17:19:04 +01002414
Georg Brandlff52f762010-12-28 09:51:43 +00002415class PyBuildScripts(build_scripts):
2416 def copy_scripts(self):
2417 outfiles, updated_files = build_scripts.copy_scripts(self)
2418 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2419 minoronly = '.{0[1]}'.format(sys.version_info)
2420 newoutfiles = []
2421 newupdated_files = []
2422 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002423 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002424 newfilename = filename + fullversion
2425 else:
2426 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002427 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002428 os.rename(filename, newfilename)
2429 newoutfiles.append(newfilename)
2430 if filename in updated_files:
2431 newupdated_files.append(newfilename)
2432 return newoutfiles, newupdated_files
2433
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002434
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002435def main():
Victor Stinnerc991f242019-03-01 17:19:04 +01002436 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2437 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2438
2439 class DummyProcess:
2440 """Hack for parallel build"""
2441 ProcessPoolExecutor = None
2442
2443 sys.modules['concurrent.futures.process'] = DummyProcess
2444
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002445 # turn off warnings when deprecated modules are imported
2446 import warnings
2447 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002448 setup(# PyPI Metadata (PEP 301)
2449 name = "Python",
2450 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002451 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002452 maintainer = "Guido van Rossum and the Python community",
2453 maintainer_email = "python-dev@python.org",
2454 description = "A high-level object-oriented programming language",
2455 long_description = SUMMARY.strip(),
2456 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002457 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002458 platforms = ["Many"],
2459
2460 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002461 cmdclass = {'build_ext': PyBuildExt,
2462 'build_scripts': PyBuildScripts,
2463 'install': PyBuildInstall,
2464 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002465 # The struct module is defined here, because build_ext won't be
2466 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002467 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002468
Georg Brandlff52f762010-12-28 09:51:43 +00002469 # If you change the scripts installed here, you also need to
2470 # check the PyBuildScripts command above, and change the links
2471 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002472 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002473 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002474 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002475
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002476# --install-platlib
2477if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002478 main()