blob: 57be07a7e0f824471451ab9f02a9679c1552397a [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:581# Autodetecting setup.py script for building the Python extensions
Fredrik Lundhade711a2001-01-24 08:00:282
Victor Stinner625dbf22019-03-01 14:59:393import argparse
Eric Snow335e14d2014-01-04 22:09:284import importlib._bootstrap
Victor Stinner625dbf22019-03-01 14:59:395import importlib.machinery
Eric Snow335e14d2014-01-04 22:09:286import importlib.util
Victor Stinner625dbf22019-03-01 14:59:397import os
8import re
9import sys
Tarek Ziadéedacea32010-01-29 11:41:0310import sysconfig
Serhiy Storchakae7389622020-07-02 07:05:3511from glob import glob, escape
Ned Deilyb29d0a52021-05-02 09:18:5812import _osx_support
Michael W. Hudson529a5052002-12-17 16:47:1713
14from distutils import log
Andrew M. Kuchling00e0f212001-01-17 15:23:2315from distutils.command.build_ext import build_ext
Victor Stinner625dbf22019-03-01 14:59:3916from distutils.command.build_scripts import build_scripts
Andrew M. Kuchlingf52d27e2001-05-21 20:29:2717from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:1718from distutils.command.install_lib import install_lib
Victor Stinner625dbf22019-03-01 14:59:3919from distutils.core import Extension, setup
20from distutils.errors import CCompilerError, DistutilsError
Stefan Krah095b2732010-06-08 13:41:4421from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:2322
Antoine Pitrou2c0a9162014-09-26 21:31:5923
Victor Stinnercfe172d2019-03-01 17:21:4924# Compile extensions used to test Python?
25TEST_EXTENSIONS = True
26
27# This global variable is used to hold the list of modules to be disabled.
28DISABLED_MODULE_LIST = []
29
30
doko@ubuntu.com93df16b2012-06-30 12:32:0831def get_platform():
Victor Stinnerc991f242019-03-01 16:19:0432 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 18:42:4533 if "_PYTHON_HOST_PLATFORM" in os.environ:
34 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 16:19:0435
doko@ubuntu.com93df16b2012-06-30 12:32:0836 # Get value of sys.platform
37 if sys.platform.startswith('osf1'):
38 return 'osf1'
39 return sys.platform
Victor Stinnerc991f242019-03-01 16:19:0440
41
42CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 16:48:3843HOST_PLATFORM = get_platform()
44MS_WINDOWS = (HOST_PLATFORM == 'win32')
45CYGWIN = (HOST_PLATFORM == 'cygwin')
46MACOS = (HOST_PLATFORM == 'darwin')
Michael Felte4be8c92019-09-25 14:14:0947AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 16:48:3848VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 11:09:2849
Victor Stinnerc991f242019-03-01 16:19:0450
51SUMMARY = """
52Python is an interpreted, interactive, object-oriented programming
53language. It is often compared to Tcl, Perl, Scheme or Java.
54
55Python combines remarkable power with very clear syntax. It has
56modules, classes, exceptions, very high level dynamic data types, and
57dynamic typing. There are interfaces to many system calls and
58libraries, as well as to various windowing systems (X11, Motif, Tk,
59Mac, MFC). New built-in modules are easily written in C or C++. Python
60is also usable as an extension language for applications that need a
61programmable interface.
62
63The Python implementation is portable: it runs on many brands of UNIX,
64on Windows, DOS, Mac, Amiga... If your favorite system isn't
65listed here, it may still be supported, if there's a C compiler for
66it. Ask around on comp.lang.python -- or just try compiling Python
67yourself.
68"""
69
70CLASSIFIERS = """
71Development Status :: 6 - Mature
72License :: OSI Approved :: Python Software Foundation License
73Natural Language :: English
74Programming Language :: C
75Programming Language :: Python
76Topic :: Software Development
77"""
78
79
80# Set common compiler and linker flags derived from the Makefile,
81# reserved for building the interpreter and the stdlib modules.
82# See bpo-21121 and bpo-35257
83def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
84 flags = sysconfig.get_config_var(compiler_flags)
85 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
86 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
87
88
Michael W. Hudson39230b32002-01-16 15:26:4889def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:0090 """Add the directory 'dir' to the list 'dirlist' (after any relative
91 directories) if:
92
Michael W. Hudson39230b32002-01-16 15:26:4893 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:0094 2) 'dir' actually exists, and is a directory.
95 """
96 if dir is None or not os.path.isdir(dir) or dir in dirlist:
97 return
98 for i, path in enumerate(dirlist):
99 if not os.path.isabs(path):
100 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03101 return
102 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48103
Victor Stinnerc991f242019-03-01 16:19:04104
xdegaye77f51392017-11-25 16:25:30105def sysroot_paths(make_vars, subdirs):
106 """Get the paths of sysroot sub-directories.
107
108 * make_vars: a sequence of names of variables of the Makefile where
109 sysroot may be set.
110 * subdirs: a sequence of names of subdirectories used as the location for
111 headers or libraries.
112 """
113
114 dirs = []
115 for var_name in make_vars:
116 var = sysconfig.get_config_var(var_name)
117 if var is not None:
118 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
119 if m is not None:
120 sysroot = m.group(1).strip('"')
121 for subdir in subdirs:
122 if os.path.isabs(subdir):
123 subdir = subdir[1:]
124 path = os.path.join(sysroot, subdir)
125 if os.path.isdir(path):
126 dirs.append(path)
127 break
128 return dirs
129
Ned Deily0288dd62019-06-03 10:34:48130MACOS_SDK_ROOT = None
Victor Stinnerc991f242019-03-01 16:19:04131
Ronald Oussoren2c12ab12010-06-03 14:42:25132def macosx_sdk_root():
Ned Deily0288dd62019-06-03 10:34:48133 """Return the directory of the current macOS SDK.
134
135 If no SDK was explicitly configured, call the compiler to find which
136 include files paths are being searched by default. Use '/' if the
137 compiler is searching /usr/include (meaning system header files are
138 installed) or use the root of an SDK if that is being searched.
139 (The SDK may be supplied via Xcode or via the Command Line Tools).
140 The SDK paths used by Apple-supplied tool chains depend on the
141 setting of various variables; see the xcrun man page for more info.
Ronald Oussoren2c12ab12010-06-03 14:42:25142 """
Ned Deily0288dd62019-06-03 10:34:48143 global MACOS_SDK_ROOT
144
145 # If already called, return cached result.
146 if MACOS_SDK_ROOT:
147 return MACOS_SDK_ROOT
148
Ronald Oussoren2c12ab12010-06-03 14:42:25149 cflags = sysconfig.get_config_var('CFLAGS')
Miss Islington (bot)4a6da0b2020-04-22 17:13:47150 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 10:34:48151 if m is not None:
152 MACOS_SDK_ROOT = m.group(1)
Ronald Oussoren2c12ab12010-06-03 14:42:25153 else:
Ned Deilyb29d0a52021-05-02 09:18:58154 MACOS_SDK_ROOT = _osx_support._default_sysroot(
155 sysconfig.get_config_var('CC'))
Ned Deily0288dd62019-06-03 10:34:48156
157 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25158
Victor Stinnerc991f242019-03-01 16:19:04159
Ronald Oussoren2c12ab12010-06-03 14:42:25160def is_macosx_sdk_path(path):
161 """
162 Returns True if 'path' can be located in an OSX SDK
163 """
Ned Deily2910a7b2012-07-30 09:35:58164 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
165 or path.startswith('/System/')
166 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25167
Victor Stinnerc991f242019-03-01 16:19:04168
Ned Deilyb29d0a52021-05-02 09:18:58169def grep_headers_for(function, headers):
170 for header in headers:
171 with open(header, 'r', errors='surrogateescape') as f:
172 if function in f.read():
173 return True
174 return False
175
Andrew M. Kuchlingfbe73762001-01-18 18:44:20176def find_file(filename, std_dirs, paths):
177 """Searches for the directory where a given file is located,
178 and returns a possibly-empty list of additional directories, or None
179 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28180
Andrew M. Kuchlingfbe73762001-01-18 18:44:20181 'filename' is the name of a file, such as readline.h or libcrypto.a.
182 'std_dirs' is the list of standard system directories; if the
183 file is found in one of them, no additional directives are needed.
184 'paths' is a list of additional locations to check; if the file is
185 found in one of them, the resulting list will contain the directory.
186 """
Victor Stinner4cbea512019-02-28 16:48:38187 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25188 # Honor the MacOSX SDK setting when one was specified.
189 # An SDK is a directory with the same structure as a real
190 # system, but with only header files and libraries.
191 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20192
193 # Check the standard locations
194 for dir in std_dirs:
195 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25196
Victor Stinner4cbea512019-02-28 16:48:38197 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25198 f = os.path.join(sysroot, dir[1:], filename)
199
Andrew M. Kuchlingfbe73762001-01-18 18:44:20200 if os.path.exists(f): return []
201
202 # Check the additional directories
203 for dir in paths:
204 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25205
Victor Stinner4cbea512019-02-28 16:48:38206 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25207 f = os.path.join(sysroot, dir[1:], filename)
208
Andrew M. Kuchlingfbe73762001-01-18 18:44:20209 if os.path.exists(f):
210 return [dir]
211
212 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23213 return None
214
Victor Stinnerc991f242019-03-01 16:19:04215
Andrew M. Kuchlingfbe73762001-01-18 18:44:20216def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46217 result = compiler.find_library_file(std_dirs + paths, libname)
218 if result is None:
219 return None
Fredrik Lundhade711a2001-01-24 08:00:28220
Victor Stinner4cbea512019-02-28 16:48:38221 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25222 sysroot = macosx_sdk_root()
223
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46224 # Check whether the found file is in one of the standard directories
225 dirname = os.path.dirname(result)
226 for p in std_dirs:
227 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57228 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25229
Victor Stinner4cbea512019-02-28 16:48:38230 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-24 13:56:38231 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
232 # libraries with .tbd extensions rather than the normal .dylib
233 # shared libraries installed in /. The Apple compiler tool
234 # chain handles this transparently but it can cause problems
235 # for programs that are being built with an SDK and searching
236 # for specific libraries. Distutils find_library_file() now
237 # knows to also search for and return .tbd files. But callers
238 # of find_library_file need to keep in mind that the base filename
239 # of the returned SDK library file might have a different extension
240 # from that of the library file installed on the running system,
241 # for example:
242 # /Applications/Xcode.app/Contents/Developer/Platforms/
243 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
244 # usr/lib/libedit.tbd
245 # vs
246 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25247 if os.path.join(sysroot, p[1:]) == dirname:
248 return [ ]
249
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46250 if p == dirname:
251 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20252
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46253 # Otherwise, it must have been in one of the additional directories,
254 # so we have to figure out which one.
255 for p in paths:
256 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57257 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25258
Victor Stinner4cbea512019-02-28 16:48:38259 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25260 if os.path.join(sysroot, p[1:]) == dirname:
261 return [ p ]
262
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46263 if p == dirname:
264 return [p]
265 else:
266 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43267
Victor Stinnerc991f242019-03-01 16:19:04268
Jack Jansen144ebcc2001-08-05 22:31:19269def find_module_file(module, dirlist):
270 """Find a module in a set of possible folders. If it is not found
271 return the unadorned filename"""
272 list = find_file(module, [], dirlist)
273 if not list:
274 return module
275 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 07:22:29276 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19277 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41278
Victor Stinnerc991f242019-03-01 16:19:04279
Andrew M. Kuchling00e0f212001-01-17 15:23:23280class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28281
Guido van Rossumd8faa362007-04-27 19:54:29282 def __init__(self, dist):
283 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 14:59:39284 self.srcdir = None
285 self.lib_dirs = None
286 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 15:43:28287 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29288 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 15:06:16289 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 14:31:45290 self.missing = []
Antoine Pitrou2c0a9162014-09-26 21:31:59291 if '-j' in os.environ.get('MAKEFLAGS', ''):
292 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29293
Victor Stinner8058bda2019-03-01 14:31:45294 def add(self, ext):
295 self.extensions.append(ext)
296
Andrew M. Kuchling00e0f212001-01-17 15:23:23297 def build_extensions(self):
Victor Stinner625dbf22019-03-01 14:59:39298 self.srcdir = sysconfig.get_config_var('srcdir')
299 if not self.srcdir:
300 # Maybe running on Windows but not using CYGWIN?
301 raise ValueError("No source directory; cannot proceed.")
302 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23303
304 # Detect which modules should be compiled
Victor Stinner8058bda2019-03-01 14:31:45305 self.detect_modules()
Andrew M. Kuchling00e0f212001-01-17 15:23:23306
307 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22308 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 16:48:38309 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22310 # move ctypes to the end, it depends on other modules
311 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
312 if "_ctypes" in ext_map:
313 ctypes = extensions.pop(ext_map["_ctypes"])
314 extensions.append(ctypes)
315 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28316
Andrew M. Kuchling00e0f212001-01-17 15:23:23317 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45318 # with Modules/.
Victor Stinner625dbf22019-03-01 14:59:39319 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41320
Andrew M. Kuchling3da989c2001-02-28 22:49:26321 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 14:59:39322 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26323 for filename in self.distribution.scripts]
324
Christian Heimesaf98da12008-01-27 15:18:18325 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45326 headers = [sysconfig.get_config_h_filename()]
Serhiy Storchakae7389622020-07-02 07:05:35327 headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18328
xdegayec0364fc2017-05-27 16:25:03329 # The sysconfig variables built by makesetup that list the already
330 # built modules and the disabled modules as configured by the Setup
331 # files.
332 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
333 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
Xavier de Gaye84968b72016-10-29 14:57:20334
xdegayec0364fc2017-05-27 16:25:03335 mods_built = []
336 mods_disabled = []
Xavier de Gaye84968b72016-10-29 14:57:20337 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19338 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23339 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11340 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45341 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11342 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18343 else:
344 ext.depends = []
345 # re-compile extensions if a header file has been changed
346 ext.depends.extend(headers)
347
xdegayec0364fc2017-05-27 16:25:03348 # If a module has already been built or has been disabled in the
349 # Setup files, don't build it here.
350 if ext.name in sysconf_built:
351 mods_built.append(ext)
352 if ext.name in sysconf_dis:
353 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34354
xdegayec0364fc2017-05-27 16:25:03355 mods_configured = mods_built + mods_disabled
356 if mods_configured:
Xavier de Gaye84968b72016-10-29 14:57:20357 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 16:25:03358 mods_configured]
359 # Remove the shared libraries built by a previous build.
360 for ext in mods_configured:
361 fullpath = self.get_ext_fullpath(ext.name)
362 if os.path.exists(fullpath):
363 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41364
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34365 # When you run "make CC=altcc" or something similar, you really want
366 # those environment variables passed into the setup.py phase. Here's
367 # a small set of useful ones.
368 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34369 args = {}
370 # unfortunately, distutils doesn't let us provide separate C and C++
371 # compilers
372 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03373 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
374 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05375 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34376
Andrew M. Kuchling00e0f212001-01-17 15:23:23377 build_ext.build_extensions(self)
378
Antoine Pitrou2c0a9162014-09-26 21:31:59379 for ext in self.extensions:
380 self.check_extension_import(ext)
381
Berker Peksag1d82a9c2014-10-01 02:11:13382 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 15:06:16383 if self.failed or self.failed_on_import:
384 all_failed = self.failed + self.failed_on_import
385 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29386
387 def print_three_column(lst):
388 lst.sort(key=str.lower)
389 # guarantee zip() doesn't drop anything
390 while len(lst) % 3:
391 lst.append("")
392 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
393 print("%-*s %-*s %-*s" % (longest, e, longest, f,
394 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29395
Victor Stinner8058bda2019-03-01 14:31:45396 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29397 print()
Brett Cannonae95b4f2013-07-12 15:30:32398 print("Python build finished successfully!")
399 print("The necessary bits to build these optional modules were not "
400 "found:")
Victor Stinner8058bda2019-03-01 14:31:45401 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05402 print("To find the necessary bits, look in setup.py in"
403 " detect_modules() for the module's name.")
404 print()
Guido van Rossumd8faa362007-04-27 19:54:29405
xdegayec0364fc2017-05-27 16:25:03406 if mods_built:
407 print()
Xavier de Gaye84968b72016-10-29 14:57:20408 print("The following modules found by detect_modules() in"
409 " setup.py, have been")
410 print("built by the Makefile instead, as configured by the"
411 " Setup files:")
xdegayec0364fc2017-05-27 16:25:03412 print_three_column([ext.name for ext in mods_built])
413 print()
414
415 if mods_disabled:
416 print()
417 print("The following modules found by detect_modules() in"
418 " setup.py have not")
419 print("been built, they are *disabled* in the Setup files:")
420 print_three_column([ext.name for ext in mods_disabled])
421 print()
Xavier de Gaye84968b72016-10-29 14:57:20422
Guido van Rossumd8faa362007-04-27 19:54:29423 if self.failed:
424 failed = self.failed[:]
425 print()
426 print("Failed to build these modules:")
427 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05428 print()
Guido van Rossumd8faa362007-04-27 19:54:29429
Benjamin Peterson5c2ac8c2014-04-30 15:06:16430 if self.failed_on_import:
431 failed = self.failed_on_import[:]
432 print()
433 print("Following modules built successfully"
434 " but were removed because they could not be imported:")
435 print_three_column(failed)
436 print()
437
Christian Heimes61d478c2018-01-27 14:51:38438 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 14:31:45439 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 14:51:38440 print()
441 print("Could not build the ssl module!")
442 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
443 "libssl with X509_VERIFY_PARAM_set1_host().")
444 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
445 "APIs, https://github.com/libressl-portable/portable/issues/381")
446 print()
447
Marc-André Lemburg7c6fcda2001-01-26 18:03:24448 def build_extension(self, ext):
449
Thomas Wouters49fd7fa2006-04-21 10:40:58450 if ext.name == '_ctypes':
451 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 06:25:24452 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58453 return
454
Marc-André Lemburg7c6fcda2001-01-26 18:03:24455 try:
456 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56457 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24458 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 14:59:39459 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29460 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09461 return
Antoine Pitrou2c0a9162014-09-26 21:31:59462
463 def check_extension_import(self, ext):
464 # Don't try to import an extension that has failed to compile
465 if ext.name in self.failed:
466 self.announce(
467 'WARNING: skipping import check for failed build "%s"' %
468 ext.name, level=1)
469 return
470
Jack Jansenf49c6f92001-11-01 14:44:15471 # Workaround for Mac OS X: The Carbon-based modules cannot be
472 # reliably imported into a command-line Python
473 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41474 self.announce(
475 'WARNING: skipping import check for Carbon-based "%s"' %
476 ext.name)
477 return
Georg Brandlfcaf9102008-07-16 02:17:56478
Victor Stinner4cbea512019-02-28 16:48:38479 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02480 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56481 # Don't bother doing an import check when an extension was
482 # build with an explicit '-arch' flag on OSX. That's currently
483 # only used to build 32-bit only extensions in a 4-way
484 # universal build and loading 32-bit code into a 64-bit
485 # process will fail.
486 self.announce(
487 'WARNING: skipping import check for "%s"' %
488 ext.name)
489 return
490
Jason Tishler24cf7762002-05-22 16:46:15491 # Workaround for Cygwin: Cygwin currently has fork issues when many
492 # modules have been imported
Victor Stinner4cbea512019-02-28 16:48:38493 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15494 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
495 % ext.name)
496 return
Michael W. Hudsonaf142892002-01-23 15:07:46497 ext_filename = os.path.join(
498 self.build_lib,
499 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53500
501 # If the build directory didn't exist when setup.py was
502 # started, sys.path_importer_cache has a negative result
503 # cached. Clear that cache before trying to import.
504 sys.path_importer_cache.clear()
505
doko@ubuntu.com1abe1c52012-06-30 18:42:45506 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 16:48:38507 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 18:42:45508 return
509
Brett Cannonca5ff3a2013-06-15 21:52:59510 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 22:09:28511 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
512 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09513 try:
Brett Cannon2a17bde2014-05-30 18:55:29514 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56515 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 15:06:16516 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42517 self.announce('*** WARNING: renaming "%s" since importing it'
518 ' failed: %s' % (ext.name, why), level=3)
519 assert not self.inplace
520 basename, tail = os.path.splitext(ext_filename)
521 newname = basename + "_failed" + tail
522 if os.path.exists(newname):
523 os.remove(newname)
524 os.rename(ext_filename, newname)
525
Neal Norwitz3f5fcc82003-02-28 17:21:39526 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39527 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42528 self.announce('*** WARNING: importing extension "%s" '
529 'failed with %s: %s' % (ext.name, exc_type, why),
530 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29531 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54532
Barry Warsaw5ca305a2011-04-06 19:18:12533 def add_multiarch_paths(self):
534 # Debian/Ubuntu multiarch support.
535 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 10:15:55536 cc = sysconfig.get_config_var('CC')
537 tmpfile = os.path.join(self.build_temp, 'multiarch')
538 if not os.path.exists(self.build_temp):
539 os.makedirs(self.build_temp)
540 ret = os.system(
541 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
542 multiarch_path_component = ''
543 try:
544 if ret >> 8 == 0:
545 with open(tmpfile) as fp:
546 multiarch_path_component = fp.readline().strip()
547 finally:
548 os.unlink(tmpfile)
549
550 if multiarch_path_component != '':
551 add_dir_to_list(self.compiler.library_dirs,
552 '/usr/lib/' + multiarch_path_component)
553 add_dir_to_list(self.compiler.include_dirs,
554 '/usr/include/' + multiarch_path_component)
555 return
556
Barry Warsaw88e19452011-04-07 14:40:36557 if not find_executable('dpkg-architecture'):
558 return
doko@ubuntu.com1abe1c52012-06-30 18:42:45559 opt = ''
Victor Stinner4cbea512019-02-28 16:48:38560 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 18:42:45561 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 19:18:12562 tmpfile = os.path.join(self.build_temp, 'multiarch')
563 if not os.path.exists(self.build_temp):
564 os.makedirs(self.build_temp)
565 ret = os.system(
doko@ubuntu.com1abe1c52012-06-30 18:42:45566 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
567 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 19:18:12568 try:
569 if ret >> 8 == 0:
570 with open(tmpfile) as fp:
571 multiarch_path_component = fp.readline().strip()
572 add_dir_to_list(self.compiler.library_dirs,
573 '/usr/lib/' + multiarch_path_component)
574 add_dir_to_list(self.compiler.include_dirs,
575 '/usr/include/' + multiarch_path_component)
576 finally:
577 os.unlink(tmpfile)
578
pxinwr32f5fdd2019-02-27 11:09:28579 def add_cross_compiling_paths(self):
580 cc = sysconfig.get_config_var('CC')
581 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 18:42:45582 if not os.path.exists(self.build_temp):
583 os.makedirs(self.build_temp)
pxinwr32f5fdd2019-02-27 11:09:28584 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 18:42:45585 is_gcc = False
pxinwr32f5fdd2019-02-27 11:09:28586 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 18:42:45587 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 18:42:45588 try:
589 if ret >> 8 == 0:
590 with open(tmpfile) as fp:
591 for line in fp.readlines():
592 if line.startswith("gcc version"):
593 is_gcc = True
pxinwr32f5fdd2019-02-27 11:09:28594 elif line.startswith("clang version"):
595 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 18:42:45596 elif line.startswith("#include <...>"):
597 in_incdirs = True
598 elif line.startswith("End of search list"):
599 in_incdirs = False
pxinwr32f5fdd2019-02-27 11:09:28600 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 18:42:45601 for d in line.strip().split("=")[1].split(":"):
602 d = os.path.normpath(d)
603 if '/gcc/' not in d:
604 add_dir_to_list(self.compiler.library_dirs,
605 d)
pxinwr32f5fdd2019-02-27 11:09:28606 elif (is_gcc or is_clang) and in_incdirs and '/gcc/' not in line and '/clang/' not in line:
doko@ubuntu.com1abe1c52012-06-30 18:42:45607 add_dir_to_list(self.compiler.include_dirs,
608 line.strip())
609 finally:
610 os.unlink(tmpfile)
611
Victor Stinnercfe172d2019-03-01 17:21:49612 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59613 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21614 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09615 # We must get the values from the Makefile and not the environment
616 # directly since an inconsistently reproducible issue comes up where
617 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21618 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59619 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05620 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
621 ('LDFLAGS', '-L', self.compiler.library_dirs),
622 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09623 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59624 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 08:48:43625 parser = argparse.ArgumentParser()
626 parser.add_argument(arg_name, dest="dirs", action="append")
627 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07628 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08629 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07630 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49631
Victor Stinnercfe172d2019-03-01 17:21:49632 def configure_compiler(self):
633 # Ensure that /usr/local is always used, but the local build
634 # directories (i.e. '.' and 'Include') must be first. See issue
635 # 10520.
636 if not CROSS_COMPILING:
637 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
638 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
639 # only change this for cross builds for 3.3, issues on Mageia
640 if CROSS_COMPILING:
641 self.add_cross_compiling_paths()
642 self.add_multiarch_paths()
643 self.add_ldflags_cppflags()
644
Victor Stinner5ec33a12019-03-01 15:43:28645 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 16:48:38646 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 10:14:33647 os.path.normpath(sys.base_prefix) != '/usr' and
648 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12649 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
650 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
651 # building a framework with different architectures than
652 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05653 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50654 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05655 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50656 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20657
xdegaye77f51392017-11-25 16:25:30658 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
659 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20660 # lib_dirs and inc_dirs are used to search for files;
661 # if a file is found in one of those directories, it can
662 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 16:48:38663 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 14:59:39664 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
665 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 11:41:00666 else:
xdegaye77f51392017-11-25 16:25:30667 # Add the sysroot paths. 'sysroot' is a compiler option used to
668 # set the logical path of the standard system headers and
669 # libraries.
Victor Stinner625dbf22019-03-01 14:59:39670 self.lib_dirs = (self.compiler.library_dirs +
671 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
672 self.inc_dirs = (self.compiler.include_dirs +
673 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
674 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23675
Brett Cannon4454a1f2005-04-15 20:32:39676 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27677 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 15:43:28678 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39679
Andrew M. Kuchling7883dc82003-10-24 18:26:26680 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 16:48:38681 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 14:59:39682 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34683
Charles-François Natali5739e102012-04-12 17:07:25684 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 16:48:38685 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 14:59:39686 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 17:07:25687
Victor Stinner4cbea512019-02-28 16:48:38688 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47689 # This should work on any unixy platform ;-)
690 # If the user has bothered specifying additional -I and -L flags
691 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00692 #
693 # NOTE: using shlex.split would technically be more correct, but
694 # also gives a bootstrap problem. Let's hope nobody uses
695 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47696 cflags, ldflags = sysconfig.get_config_vars(
697 'CFLAGS', 'LDFLAGS')
698 for item in cflags.split():
699 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 14:59:39700 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47701
702 for item in ldflags.split():
703 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 14:59:39704 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47705
Victor Stinner5ec33a12019-03-01 15:43:28706 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23707 #
708 # The following modules are all pretty straightforward, and compile
709 # on pretty much any POSIXish platform.
710 #
Fredrik Lundhade711a2001-01-24 08:00:28711
Andrew M. Kuchling00e0f212001-01-17 15:23:23712 # array objects
Victor Stinner8058bda2019-03-01 14:31:45713 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44714
Yury Selivanovf23746a2018-01-23 00:11:18715 # Context Variables
Victor Stinner8058bda2019-03-01 14:31:45716 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-23 00:11:18717
Martin Panterc9deece2016-02-03 05:19:44718 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 17:21:49719
720 # math library functions, e.g. sin()
721 self.add(Extension('math', ['mathmodule.c'],
Victor Stinner8058bda2019-03-01 14:31:45722 extra_objects=[shared_math],
723 depends=['_math.h', shared_math],
724 libraries=['m']))
Victor Stinnercfe172d2019-03-01 17:21:49725
726 # complex math library functions
727 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinner8058bda2019-03-01 14:31:45728 extra_objects=[shared_math],
729 depends=['_math.h', shared_math],
730 libraries=['m']))
Victor Stinnere0be4232011-10-25 11:06:09731
732 # time libraries: librt may be needed for clock_gettime()
733 time_libs = []
734 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
735 if lib:
736 time_libs.append(lib)
737
Andrew M. Kuchling00e0f212001-01-17 15:23:23738 # time operations and variables
Victor Stinner8058bda2019-03-01 14:31:45739 self.add(Extension('time', ['timemodule.c'],
740 libraries=time_libs))
Benjamin Peterson8acaa312017-11-13 04:53:39741 # libm is needed by delta_new() that uses round() and by accum() that
742 # uses modf().
Victor Stinner8058bda2019-03-01 14:31:45743 self.add(Extension('_datetime', ['_datetimemodule.c'],
744 libraries=['m']))
Christian Heimesfe337bf2008-03-23 21:54:12745 # random number generator implemented in C
Victor Stinner8058bda2019-03-01 14:31:45746 self.add(Extension("_random", ["_randommodule.c"]))
Raymond Hettinger0c410272004-01-05 10:13:35747 # bisect
Victor Stinner8058bda2019-03-01 14:31:45748 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38749 # heapq
Victor Stinner8058bda2019-03-01 14:31:45750 self.add(Extension("_heapq", ["_heapqmodule.c"]))
Alexandre Vassalottica2d6102008-06-12 18:26:05751 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 21:02:26752 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 10:26:33753 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Collin Winter670e6922007-03-21 02:57:17754 # atexit
Victor Stinner8058bda2019-03-01 14:31:45755 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10756 # _json speedups
Victor Stinner8058bda2019-03-01 14:31:45757 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 10:26:33758 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 17:21:49759
Fred Drake0e474a82007-10-11 18:01:43760 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 14:31:45761 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23762 # static Unicode character database
Victor Stinner8058bda2019-03-01 14:31:45763 self.add(Extension('unicodedata', ['unicodedata.c'],
764 depends=['unicodedata_db.h', 'unicodename_db.h']))
Larry Hastings3a907972013-11-23 22:49:22765 # _opcode module
Victor Stinner8058bda2019-03-01 14:31:45766 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 06:39:19767 # asyncio speedups
Victor Stinner8058bda2019-03-01 14:31:45768 self.add(Extension("_asyncio", ["_asynciomodule.c"]))
Ivan Levkivskyi03e3c342018-02-18 12:41:58769 # _abc speedups
Victor Stinner8058bda2019-03-01 14:31:45770 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-15 23:27:16771 # _queue module
Victor Stinner8058bda2019-03-01 14:31:45772 self.add(Extension("_queue", ["_queuemodule.c"]))
Miss Islington (bot)5779c532019-08-23 22:39:27773 # _statistics module
774 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23775
776 # Modules with some UNIX dependencies -- on by default:
777 # (If you have a really backward UNIX, select and socket may not be
778 # supported...)
779
780 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42781 libs = []
Victor Stinner5ec33a12019-03-01 15:43:28782 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42783 # May be necessary on AIX for flock function
784 libs = ['bsd']
Victor Stinner8058bda2019-03-01 14:31:45785 self.add(Extension('fcntl', ['fcntlmodule.c'],
786 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21787 # pwd(3)
Victor Stinner8058bda2019-03-01 14:31:45788 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21789 # grp(3)
pxinwr32f5fdd2019-02-27 11:09:28790 if not VXWORKS:
Victor Stinner8058bda2019-03-01 14:31:45791 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21792 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 15:43:28793 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
794 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 14:31:45795 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felte4be8c92019-09-25 14:14:09796 # AIX has shadow passwords, but access is not via getspent(), etc.
797 # module support is not expected so it not 'missing'
798 elif not AIX:
Victor Stinner8058bda2019-03-01 14:31:45799 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29800
Andrew M. Kuchling00e0f212001-01-17 15:23:23801 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 14:31:45802 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23803
Andrew M. Kuchling00e0f212001-01-17 15:23:23804 # Fred Drake's interface to the Python parser
Victor Stinner8058bda2019-03-01 14:31:45805 self.add(Extension('parser', ['parsermodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23806
Andrew M. Kuchling00e0f212001-01-17 15:23:23807 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 14:31:45808 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23809
Andrew M. Kuchling57269d02004-08-31 13:37:25810 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21811 # syslog daemon interface
Victor Stinner8058bda2019-03-01 14:31:45812 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23813
Eric Snow7f8bfc92018-01-30 01:23:44814 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 22:35:46815 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-30 01:23:44816
Andrew M. Kuchling00e0f212001-01-17 15:23:23817 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34818 # Here ends the simple stuff. From here on, modules need certain
819 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23820 #
821
822 # Multimedia modules
823 # These don't work for 64-bit platforms!!!
824 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 13:58:11825 #
Neal Norwitz5e4a3b82004-07-19 16:55:07826 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10827 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20828 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 13:58:11829 #
Benjamin Peterson8acaa312017-11-13 04:53:39830 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 14:31:45831 self.add(Extension('audioop', ['audioop.c'],
832 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20833
Victor Stinner5ec33a12019-03-01 15:43:28834 # CSV files
835 self.add(Extension('_csv', ['_csv.c']))
836
837 # POSIX subprocess module helper.
838 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
839
Victor Stinnercfe172d2019-03-01 17:21:49840 def detect_test_extensions(self):
841 # Python C API test module
842 self.add(Extension('_testcapi', ['_testcapimodule.c'],
843 depends=['testcapi_long.h']))
844
Victor Stinner23bace22019-04-18 09:37:26845 # Python Internal C API test module
846 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 10:26:33847 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 09:37:26848
Victor Stinnercfe172d2019-03-01 17:21:49849 # Python PEP-3118 (buffer protocol) test module
850 self.add(Extension('_testbuffer', ['_testbuffer.c']))
851
852 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
853 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
854
855 # Test multi-phase extension module init (PEP 489)
856 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
857
858 # Fuzz tests.
859 self.add(Extension('_xxtestfuzz',
860 ['_xxtestfuzz/_xxtestfuzz.c',
861 '_xxtestfuzz/fuzzer.c']))
862
Victor Stinner5ec33a12019-03-01 15:43:28863 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23864 # readline
Victor Stinner625dbf22019-03-01 14:59:39865 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44866 readline_termcap_library = ""
867 curses_library = ""
doko@ubuntu.com58844492012-06-30 16:25:32868 # Cannot use os.popen here in py3k.
869 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
870 if not os.path.exists(self.build_temp):
871 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44872 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 16:25:32873 if do_readline:
Victor Stinner4cbea512019-02-28 16:48:38874 if CROSS_COMPILING:
doko@ubuntu.com58844492012-06-30 16:25:32875 ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
876 % (sysconfig.get_config_var('READELF'),
877 do_readline, tmpfile))
878 elif find_executable('ldd'):
879 ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
880 else:
881 ret = 256
doko@ubuntu.com4c990712012-06-30 21:28:09882 if ret >> 8 == 0:
Brett Cannon9f5db072010-10-29 20:19:27883 with open(tmpfile) as fp:
884 for ln in fp:
885 if 'curses' in ln:
886 readline_termcap_library = re.sub(
887 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
888 ).rstrip()
889 break
890 # termcap interface split out from ncurses
891 if 'tinfo' in ln:
892 readline_termcap_library = 'tinfo'
893 break
doko@ubuntu.com4c990712012-06-30 21:28:09894 if os.path.exists(tmpfile):
895 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44896 # Issue 7384: If readline is already linked against curses,
897 # use the same library for the readline and curses modules.
898 if 'curses' in readline_termcap_library:
899 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 14:59:39900 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44901 curses_library = 'ncursesw'
Michael Felte4be8c92019-09-25 14:14:09902 # Issue 36210: OSS provided ncurses does not link on AIX
903 # Use IBM supplied 'curses' for successful build of _curses
904 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
905 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 14:59:39906 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44907 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 14:59:39908 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44909 curses_library = 'curses'
910
Victor Stinner4cbea512019-02-28 16:48:38911 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22912 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59913 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 20:36:14914 if (dep_target and
915 (tuple(int(n) for n in dep_target.split('.')[0:2])
916 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59917 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22918 if os_release < 9:
919 # MacOSX 10.4 has a broken readline. Don't try to build
920 # the readline module unless the user has installed a fixed
921 # readline package
Victor Stinner625dbf22019-03-01 14:59:39922 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22923 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23924 if do_readline:
Victor Stinner4cbea512019-02-28 16:48:38925 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47926 # In every directory on the search path search for a dynamic
927 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19928 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09929 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25930 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47931 readline_extra_link_args = ('-Wl,-search_paths_first',)
932 else:
933 readline_extra_link_args = ()
934
Marc-André Lemburg2efc3232001-01-26 18:23:02935 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44936 if readline_termcap_library:
937 pass # Issue 7384: Already linked against curses or tinfo.
938 elif curses_library:
939 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 14:59:39940 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17941 ['/usr/lib/termcap'],
942 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02943 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 14:31:45944 self.add(Extension('readline', ['readline.c'],
945 library_dirs=['/usr/lib/termcap'],
946 extra_link_args=readline_extra_link_args,
947 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29948 else:
Victor Stinner8058bda2019-03-01 14:31:45949 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29950
Victor Stinner5ec33a12019-03-01 15:43:28951 # Curses support, requiring the System V version of curses, often
952 # provided by the ncurses library.
953 curses_defines = []
954 curses_includes = []
955 panel_library = 'panel'
956 if curses_library == 'ncursesw':
957 curses_defines.append(('HAVE_NCURSESW', '1'))
958 if not CROSS_COMPILING:
959 curses_includes.append('/usr/include/ncursesw')
960 # Bug 1464056: If _curses.so links with ncursesw,
961 # _curses_panel.so must link with panelw.
962 panel_library = 'panelw'
963 if MACOS:
964 # On OS X, there is no separate /usr/lib/libncursesw nor
965 # libpanelw. If we are here, we found a locally-supplied
966 # version of libncursesw. There should also be a
967 # libpanelw. _XOPEN_SOURCE defines are usually excluded
968 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
969 # ncurses wide char support
970 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
971 elif MACOS and curses_library == 'ncurses':
972 # Building with the system-suppied combined libncurses/libpanel
973 curses_defines.append(('HAVE_NCURSESW', '1'))
974 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43975
Victor Stinnercfe172d2019-03-01 17:21:49976 curses_enabled = True
Victor Stinner5ec33a12019-03-01 15:43:28977 if curses_library.startswith('ncurses'):
978 curses_libs = [curses_library]
979 self.add(Extension('_curses', ['_cursesmodule.c'],
980 include_dirs=curses_includes,
981 define_macros=curses_defines,
982 libraries=curses_libs))
983 elif curses_library == 'curses' and not MACOS:
984 # OSX has an old Berkeley curses, not good enough for
985 # the _curses module.
986 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
987 curses_libs = ['curses', 'terminfo']
988 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
989 curses_libs = ['curses', 'termcap']
990 else:
991 curses_libs = ['curses']
992
993 self.add(Extension('_curses', ['_cursesmodule.c'],
994 define_macros=curses_defines,
995 libraries=curses_libs))
996 else:
Victor Stinnercfe172d2019-03-01 17:21:49997 curses_enabled = False
Victor Stinner5ec33a12019-03-01 15:43:28998 self.missing.append('_curses')
999
1000 # If the curses module is enabled, check for the panel module
Michael Felte4be8c92019-09-25 14:14:091001 # _curses_panel needs some form of ncurses
1002 skip_curses_panel = True if AIX else False
1003 if (curses_enabled and not skip_curses_panel and
1004 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 15:43:281005 self.add(Extension('_curses_panel', ['_curses_panel.c'],
1006 include_dirs=curses_includes,
1007 define_macros=curses_defines,
1008 libraries=[panel_library, *curses_libs]))
Michael Felte4be8c92019-09-25 14:14:091009 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 15:43:281010 self.missing.append('_curses_panel')
1011
1012 def detect_crypt(self):
1013 # crypt module.
pxinwr236d0b72019-04-15 09:02:201014 if VXWORKS:
1015 # bpo-31904: crypt() function is not provided by VxWorks.
1016 # DES_crypt() OpenSSL provides is too weak to implement
1017 # the encryption.
1018 return
1019
Victor Stinner625dbf22019-03-01 14:59:391020 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:211021 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:291022 else:
Ronald Oussoren94f25282010-05-05 19:11:211023 libs = []
pxinwr32f5fdd2019-02-27 11:09:281024
pxinwr236d0b72019-04-15 09:02:201025 self.add(Extension('_crypt', ['_cryptmodule.c'],
Victor Stinner8058bda2019-03-01 14:31:451026 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:231027
Victor Stinner5ec33a12019-03-01 15:43:281028 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:231029 # socket(2)
pxinwr32f5fdd2019-02-27 11:09:281030 if not VXWORKS:
Victor Stinner8058bda2019-03-01 14:31:451031 self.add(Extension('_socket', ['socketmodule.c'],
1032 depends=['socketmodule.h']))
Victor Stinner625dbf22019-03-01 14:59:391033 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 11:09:281034 libs = ['net']
Victor Stinner8058bda2019-03-01 14:31:451035 self.add(Extension('_socket', ['socketmodule.c'],
1036 depends=['socketmodule.h'],
1037 libraries=libs))
pxinwr32f5fdd2019-02-27 11:09:281038
Victor Stinner5ec33a12019-03-01 15:43:281039 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:491040 # Modules that provide persistent dictionary-like semantics. You will
1041 # probably want to arrange for at least one of them to be available on
1042 # your machine, though none are defined by default because of library
1043 # dependencies. The Python module dbm/__init__.py provides an
1044 # implementation independent wrapper for these; dbm/dumb.py provides
1045 # similar functionality (but slower of course) implemented in Python.
1046
1047 # Sleepycat^WOracle Berkeley DB interface.
1048 # http://www.oracle.com/database/berkeley-db/db/index.html
1049 #
1050 # This requires the Sleepycat^WOracle DB code. The supported versions
1051 # are set below. Visit the URL above to download
1052 # a release. Most open source OSes come with one or more
1053 # versions of BerkeleyDB already installed.
1054
doko@ubuntu.com15bac0f2012-07-01 08:35:541055 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:491056 min_db_ver = (3, 3)
1057 db_setup_debug = False # verbose debug prints from this script?
1058
1059 def allow_db_ver(db_ver):
1060 """Returns a boolean if the given BerkeleyDB version is acceptable.
1061
1062 Args:
1063 db_ver: A tuple of the version to verify.
1064 """
1065 if not (min_db_ver <= db_ver <= max_db_ver):
1066 return False
1067 return True
1068
1069 def gen_db_minor_ver_nums(major):
1070 if major == 4:
1071 for x in range(max_db_ver[1]+1):
1072 if allow_db_ver((4, x)):
1073 yield x
1074 elif major == 3:
1075 for x in (3,):
1076 if allow_db_ver((3, x)):
1077 yield x
1078 else:
1079 raise ValueError("unknown major BerkeleyDB version", major)
1080
1081 # construct a list of paths to look for the header file in on
1082 # top of the normal inc_dirs.
1083 db_inc_paths = [
1084 '/usr/include/db4',
1085 '/usr/local/include/db4',
1086 '/opt/sfw/include/db4',
1087 '/usr/include/db3',
1088 '/usr/local/include/db3',
1089 '/opt/sfw/include/db3',
1090 # Fink defaults (http://fink.sourceforge.net/)
1091 '/sw/include/db4',
1092 '/sw/include/db3',
1093 ]
1094 # 4.x minor number specific paths
1095 for x in gen_db_minor_ver_nums(4):
1096 db_inc_paths.append('/usr/include/db4%d' % x)
1097 db_inc_paths.append('/usr/include/db4.%d' % x)
1098 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1099 db_inc_paths.append('/usr/local/include/db4%d' % x)
1100 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1101 db_inc_paths.append('/opt/db-4.%d/include' % x)
1102 # MacPorts default (http://www.macports.org/)
1103 db_inc_paths.append('/opt/local/include/db4%d' % x)
1104 # 3.x minor number specific paths
1105 for x in gen_db_minor_ver_nums(3):
1106 db_inc_paths.append('/usr/include/db3%d' % x)
1107 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1108 db_inc_paths.append('/usr/local/include/db3%d' % x)
1109 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1110 db_inc_paths.append('/opt/db-3.%d/include' % x)
1111
Victor Stinner4cbea512019-02-28 16:48:381112 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 18:42:451113 db_inc_paths = []
1114
Georg Brandl489cb4f2009-07-11 10:08:491115 # Add some common subdirectories for Sleepycat DB to the list,
1116 # based on the standard include directories. This way DB3/4 gets
1117 # picked up when it is installed in a non-standard prefix and
1118 # the user has added that prefix into inc_dirs.
1119 std_variants = []
Victor Stinner625dbf22019-03-01 14:59:391120 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:491121 std_variants.append(os.path.join(dn, 'db3'))
1122 std_variants.append(os.path.join(dn, 'db4'))
1123 for x in gen_db_minor_ver_nums(4):
1124 std_variants.append(os.path.join(dn, "db4%d"%x))
1125 std_variants.append(os.path.join(dn, "db4.%d"%x))
1126 for x in gen_db_minor_ver_nums(3):
1127 std_variants.append(os.path.join(dn, "db3%d"%x))
1128 std_variants.append(os.path.join(dn, "db3.%d"%x))
1129
1130 db_inc_paths = std_variants + db_inc_paths
1131 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1132
1133 db_ver_inc_map = {}
1134
Victor Stinner4cbea512019-02-28 16:48:381135 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:251136 sysroot = macosx_sdk_root()
1137
Georg Brandl489cb4f2009-07-11 10:08:491138 class db_found(Exception): pass
1139 try:
1140 # See whether there is a Sleepycat header in the standard
1141 # search path.
Victor Stinner625dbf22019-03-01 14:59:391142 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:491143 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 16:48:381144 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:251145 f = os.path.join(sysroot, d[1:], "db.h")
1146
Georg Brandl489cb4f2009-07-11 10:08:491147 if db_setup_debug: print("db: looking for db.h in", f)
1148 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:271149 with open(f, 'rb') as file:
1150 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:031151 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:491152 if m:
1153 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:031154 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:491155 db_minor = int(m.group(1))
1156 db_ver = (db_major, db_minor)
1157
1158 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1159 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:031160 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:491161 db_patch = int(m.group(1))
1162 if db_patch < 21:
1163 print("db.h:", db_ver, "patch", db_patch,
1164 "being ignored (4.6.x must be >= 4.6.21)")
1165 continue
1166
1167 if ( (db_ver not in db_ver_inc_map) and
1168 allow_db_ver(db_ver) ):
1169 # save the include directory with the db.h version
1170 # (first occurrence only)
1171 db_ver_inc_map[db_ver] = d
1172 if db_setup_debug:
1173 print("db.h: found", db_ver, "in", d)
1174 else:
1175 # we already found a header for this library version
1176 if db_setup_debug: print("db.h: ignoring", d)
1177 else:
1178 # ignore this header, it didn't contain a version number
1179 if db_setup_debug:
1180 print("db.h: no version number version in", d)
1181
1182 db_found_vers = list(db_ver_inc_map.keys())
1183 db_found_vers.sort()
1184
1185 while db_found_vers:
1186 db_ver = db_found_vers.pop()
1187 db_incdir = db_ver_inc_map[db_ver]
1188
1189 # check lib directories parallel to the location of the header
1190 db_dirs_to_check = [
1191 db_incdir.replace("include", 'lib64'),
1192 db_incdir.replace("include", 'lib'),
1193 ]
Ronald Oussoren2c12ab12010-06-03 14:42:251194
Victor Stinner4cbea512019-02-28 16:48:381195 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:251196 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1197
1198 else:
1199 # Same as other branch, but takes OSX SDK into account
1200 tmp = []
1201 for dn in db_dirs_to_check:
1202 if is_macosx_sdk_path(dn):
1203 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1204 tmp.append(dn)
1205 else:
1206 if os.path.isdir(dn):
1207 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:461208 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:251209
1210 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:491211
Ezio Melotti42da6632011-03-15 03:18:481212 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:491213 # XXX should we -ever- look for a dbX name? Do any
1214 # systems really not name their library by version and
1215 # symlink to more general names?
1216 for dblib in (('db-%d.%d' % db_ver),
1217 ('db%d%d' % db_ver),
1218 ('db%d' % db_ver[0])):
1219 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 14:59:391220 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:491221 if dblib_file:
1222 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1223 raise db_found
1224 else:
1225 if db_setup_debug: print("db lib: ", dblib, "not found")
1226
1227 except db_found:
1228 if db_setup_debug:
1229 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1230 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:491231 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 15:52:481232 # Only add the found library and include directories if they aren't
1233 # already being searched. This avoids an explicit runtime library
1234 # dependency.
Victor Stinner625dbf22019-03-01 14:59:391235 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 15:52:481236 db_incs = None
1237 else:
1238 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 14:59:391239 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 15:52:481240 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:491241 else:
1242 if db_setup_debug: print("db: no appropriate library found")
1243 db_incs = None
1244 dblibs = []
1245 dblib_dir = None
1246
Victor Stinner5ec33a12019-03-01 15:43:281247 dbm_setup_debug = False # verbose debug prints from this script?
1248 dbm_order = ['gdbm']
1249 # The standard Unix dbm module:
1250 if not CYGWIN:
1251 config_args = [arg.strip("'")
1252 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1253 dbm_args = [arg for arg in config_args
1254 if arg.startswith('--with-dbmliborder=')]
1255 if dbm_args:
1256 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1257 else:
1258 dbm_order = "ndbm:gdbm:bdb".split(":")
1259 dbmext = None
1260 for cand in dbm_order:
1261 if cand == "ndbm":
1262 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1263 # Some systems have -lndbm, others have -lgdbm_compat,
1264 # others don't have either
1265 if self.compiler.find_library_file(self.lib_dirs,
1266 'ndbm'):
1267 ndbm_libs = ['ndbm']
1268 elif self.compiler.find_library_file(self.lib_dirs,
1269 'gdbm_compat'):
1270 ndbm_libs = ['gdbm_compat']
1271 else:
1272 ndbm_libs = []
1273 if dbm_setup_debug: print("building dbm using ndbm")
1274 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1275 define_macros=[
1276 ('HAVE_NDBM_H',None),
1277 ],
1278 libraries=ndbm_libs)
1279 break
1280
1281 elif cand == "gdbm":
1282 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1283 gdbm_libs = ['gdbm']
1284 if self.compiler.find_library_file(self.lib_dirs,
1285 'gdbm_compat'):
1286 gdbm_libs.append('gdbm_compat')
1287 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1288 if dbm_setup_debug: print("building dbm using gdbm")
1289 dbmext = Extension(
1290 '_dbm', ['_dbmmodule.c'],
1291 define_macros=[
1292 ('HAVE_GDBM_NDBM_H', None),
1293 ],
1294 libraries = gdbm_libs)
1295 break
1296 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1297 if dbm_setup_debug: print("building dbm using gdbm")
1298 dbmext = Extension(
1299 '_dbm', ['_dbmmodule.c'],
1300 define_macros=[
1301 ('HAVE_GDBM_DASH_NDBM_H', None),
1302 ],
1303 libraries = gdbm_libs)
1304 break
1305 elif cand == "bdb":
1306 if dblibs:
1307 if dbm_setup_debug: print("building dbm using bdb")
1308 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1309 library_dirs=dblib_dir,
1310 runtime_library_dirs=dblib_dir,
1311 include_dirs=db_incs,
1312 define_macros=[
1313 ('HAVE_BERKDB_H', None),
1314 ('DB_DBM_HSEARCH', None),
1315 ],
1316 libraries=dblibs)
1317 break
1318 if dbmext is not None:
1319 self.add(dbmext)
1320 else:
1321 self.missing.append('_dbm')
1322
1323 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1324 if ('gdbm' in dbm_order and
1325 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1326 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1327 libraries=['gdbm']))
1328 else:
1329 self.missing.append('_gdbm')
1330
1331 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:581332 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:301333 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:581334
1335 # We hunt for #define SQLITE_VERSION "n.n.n"
Charles Pigottad0daf52019-04-26 15:38:121336 # We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
Thomas Wouters49fd7fa2006-04-21 10:40:581337 sqlite_incdir = sqlite_libdir = None
1338 sqlite_inc_paths = [ '/usr/include',
1339 '/usr/include/sqlite',
1340 '/usr/include/sqlite3',
1341 '/usr/local/include',
1342 '/usr/local/include/sqlite',
1343 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 18:42:451344 ]
Victor Stinner4cbea512019-02-28 16:48:381345 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 18:42:451346 sqlite_inc_paths = []
Miss Islington (bot)36101c22019-07-13 03:33:531347 MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
Thomas Wouters49fd7fa2006-04-21 10:40:581348 MIN_SQLITE_VERSION = ".".join([str(x)
1349 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:471350
1351 # Scan the default include directories before the SQLite specific
1352 # ones. This allows one to override the copy of sqlite on OSX,
1353 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 16:48:381354 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:251355 sysroot = macosx_sdk_root()
1356
Victor Stinner625dbf22019-03-01 14:59:391357 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 22:13:331358 d = d_
Victor Stinner4cbea512019-02-28 16:48:381359 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 22:13:331360 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:251361
Ned Deily9b635832012-08-05 22:13:331362 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:581363 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:431364 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:271365 with open(f) as file:
1366 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:581367 m = re.search(
Petri Lehtinened909bc2013-02-23 16:05:281368 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:581369 if m:
1370 sqlite_version = m.group(1)
1371 sqlite_version_tuple = tuple([int(x)
1372 for x in sqlite_version.split(".")])
1373 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1374 # we win!
Thomas Wouters89f507f2006-12-13 04:49:301375 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:431376 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:581377 sqlite_incdir = d
1378 break
1379 else:
1380 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 15:38:121381 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:431382 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:581383 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:431384 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:581385
1386 if sqlite_incdir:
1387 sqlite_dirs_to_check = [
1388 os.path.join(sqlite_incdir, '..', 'lib64'),
1389 os.path.join(sqlite_incdir, '..', 'lib'),
1390 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1391 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1392 ]
Tarek Ziadé36797272010-07-22 12:50:051393 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 14:59:391394 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:571395 if sqlite_libfile:
1396 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:581397
1398 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:471399 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:581400 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:581401 '_sqlite/cursor.c',
1402 '_sqlite/microprotocols.c',
1403 '_sqlite/module.c',
1404 '_sqlite/prepare_protocol.c',
1405 '_sqlite/row.c',
1406 '_sqlite/statement.c',
1407 '_sqlite/util.c', ]
1408
Thomas Wouters49fd7fa2006-04-21 10:40:581409 sqlite_defines = []
Victor Stinner4cbea512019-02-28 16:48:381410 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:581411 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1412 else:
1413 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1414
Benjamin Peterson076ed002010-10-31 17:11:021415 # Enable support for loadable extensions in the sqlite3 module
1416 # if --enable-loadable-sqlite-extensions configure option is used.
1417 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1418 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Miss Islington (bot)9c746782021-08-27 11:27:451419 elif MACOS and sqlite_incdir == os.path.join(MACOS_SDK_ROOT, "usr/include"):
1420 raise DistutilsError("System version of SQLite does not support loadable extensions")
Thomas Wouters477c8d52006-05-27 19:21:471421
Victor Stinner4cbea512019-02-28 16:48:381422 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:471423 # In every directory on the search path search for a dynamic
1424 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 09:05:331425 # for dynamic libraries on the entire path.
1426 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:471427 # before the dynamic library in /usr/lib.
1428 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1429 else:
1430 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:581431
Brett Cannonc5011fe2011-06-07 03:09:101432 include_dirs = ["Modules/_sqlite"]
1433 # Only include the directory where sqlite was found if it does
1434 # not already exist in set include directories, otherwise you
1435 # can end up with a bad search path order.
1436 if sqlite_incdir not in self.compiler.include_dirs:
1437 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 15:52:481438 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 14:59:391439 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 15:52:481440 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 14:31:451441 self.add(Extension('_sqlite3', sqlite_srcs,
1442 define_macros=sqlite_defines,
1443 include_dirs=include_dirs,
1444 library_dirs=sqlite_libdir,
1445 extra_link_args=sqlite_extra_link_args,
1446 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:291447 else:
Victor Stinner8058bda2019-03-01 14:31:451448 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:341449
Victor Stinner5ec33a12019-03-01 15:43:281450 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:231451 # Unix-only modules
Victor Stinner4cbea512019-02-28 16:48:381452 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 11:09:281453 if not VXWORKS:
1454 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 14:31:451455 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 11:09:281456 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 14:31:451457 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:291458 else:
Victor Stinner8058bda2019-03-01 14:31:451459 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 22:28:461460
Victor Stinner5ec33a12019-03-01 15:43:281461 # Platform-specific libraries
1462 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1463 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felte4be8c92019-09-25 14:14:091464 elif not AIX:
Victor Stinner5ec33a12019-03-01 15:43:281465 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:281466
Victor Stinner5ec33a12019-03-01 15:43:281467 if MACOS:
1468 self.add(Extension('_scproxy', ['_scproxy.c'],
1469 extra_link_args=[
1470 '-framework', 'SystemConfiguration',
1471 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:281472
Victor Stinner5ec33a12019-03-01 15:43:281473 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:261474 # Andrew Kuchling's zlib module. Note that some versions of zlib
1475 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1476 # http://www.cert.org/advisories/CA-2002-07.html
1477 #
1478 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1479 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1480 # now, we still accept 1.1.3, because we think it's difficult to
1481 # exploit this in Python, and we'd rather make it RedHat's problem
1482 # than our problem <wink>.
1483 #
1484 # You can upgrade zlib to version 1.1.4 yourself by going to
1485 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 14:59:391486 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:291487 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:121488 if zlib_inc is not None:
1489 zlib_h = zlib_inc[0] + '/zlib.h'
1490 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:261491 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 16:48:381492 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-19 04:32:001493 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:271494 with open(zlib_h) as fp:
1495 while 1:
1496 line = fp.readline()
1497 if not line:
1498 break
1499 if line.startswith('#define ZLIB_VERSION'):
1500 version = line.split()[2]
1501 break
Guido van Rossume6970912001-04-15 15:16:121502 if version >= version_req:
Victor Stinner625dbf22019-03-01 14:59:391503 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 16:48:381504 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:121505 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1506 else:
1507 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 14:31:451508 self.add(Extension('zlib', ['zlibmodule.c'],
1509 libraries=['z'],
1510 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:291511 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:291512 else:
Victor Stinner8058bda2019-03-01 14:31:451513 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:291514 else:
Victor Stinner8058bda2019-03-01 14:31:451515 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:291516 else:
Victor Stinner8058bda2019-03-01 14:31:451517 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:231518
Christian Heimes1dc54002008-03-24 02:19:291519 # Helper module for various ascii-encoders. Uses zlib for an optimized
1520 # crc32 if we have it. Otherwise binascii uses its own.
1521 if have_zlib:
1522 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1523 libraries = ['z']
1524 extra_link_args = zlib_extra_link_args
1525 else:
1526 extra_compile_args = []
1527 libraries = []
1528 extra_link_args = []
Victor Stinner8058bda2019-03-01 14:31:451529 self.add(Extension('binascii', ['binascii.c'],
1530 extra_compile_args=extra_compile_args,
1531 libraries=libraries,
1532 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:291533
Gustavo Niemeyerf8ca8362002-11-05 16:50:051534 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 14:59:391535 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 16:48:381536 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:121537 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1538 else:
1539 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 14:31:451540 self.add(Extension('_bz2', ['_bz2module.c'],
1541 libraries=['bz2'],
1542 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:291543 else:
Victor Stinner8058bda2019-03-01 14:31:451544 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:051545
Nadeem Vawda3ff069e2011-11-29 22:25:061546 # LZMA compression support.
Victor Stinner625dbf22019-03-01 14:59:391547 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 14:31:451548 self.add(Extension('_lzma', ['_lzmamodule.c'],
1549 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-29 22:25:061550 else:
Victor Stinner8058bda2019-03-01 14:31:451551 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-29 22:25:061552
Victor Stinner5ec33a12019-03-01 15:43:281553 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:231554 # Interface to the Expat XML parser
1555 #
Benjamin Petersona28e7022010-01-09 18:53:061556 # Expat was written by James Clark and is now maintained by a group of
1557 # developers on SourceForge; see www.libexpat.org for more information.
1558 # The pyexpat module was written by Paul Prescod after a prototype by
1559 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1560 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:191561 # configure option.
Fred Drakefc8341d2002-06-17 17:55:301562 #
1563 # More information on Expat can be found at www.libexpat.org.
1564 #
Benjamin Petersonb2d90462009-12-31 03:23:101565 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1566 expat_inc = []
1567 define_macros = []
Stefan Krah9e1e6f52017-08-25 12:07:501568 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:101569 expat_lib = ['expat']
1570 expat_sources = []
Christian Heimesd489c7a2013-02-09 16:02:061571 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:101572 else:
Victor Stinner625dbf22019-03-01 14:59:391573 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:101574 define_macros = [
1575 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 21:43:541576 # bpo-30947: Python uses best available entropy sources to
1577 # call XML_SetHashSalt(), expat entropy sources are not needed
1578 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:101579 ]
Stefan Krah9e1e6f52017-08-25 12:07:501580 extra_compile_args = []
Miss Islington (bot)90004fc2021-09-29 14:35:531581 # bpo-44394: libexpat uses isnan() of math.h and needs linkage
1582 # against the libm
1583 expat_lib = ['m']
Benjamin Petersonb2d90462009-12-31 03:23:101584 expat_sources = ['expat/xmlparse.c',
1585 'expat/xmlrole.c',
1586 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 16:02:061587 expat_depends = ['expat/ascii.h',
1588 'expat/asciitab.h',
1589 'expat/expat.h',
1590 'expat/expat_config.h',
1591 'expat/expat_external.h',
1592 'expat/internal.h',
1593 'expat/latin1tab.h',
1594 'expat/utf8tab.h',
1595 'expat/xmlrole.h',
1596 'expat/xmltok.h',
1597 'expat/xmltok_impl.h'
1598 ]
Thomas Wouters477c8d52006-05-27 19:21:471599
Stefan Krah9e1e6f52017-08-25 12:07:501600 cc = sysconfig.get_config_var('CC').split()[0]
1601 ret = os.system(
Benjamin Peterson66c42f82019-06-29 23:51:591602 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Stefan Krah9e1e6f52017-08-25 12:07:501603 if ret >> 8 == 0:
Benjamin Peterson66c42f82019-06-29 23:51:591604 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 12:07:501605
Victor Stinner8058bda2019-03-01 14:31:451606 self.add(Extension('pyexpat',
1607 define_macros=define_macros,
1608 extra_compile_args=extra_compile_args,
1609 include_dirs=expat_inc,
1610 libraries=expat_lib,
1611 sources=['pyexpat.c'] + expat_sources,
1612 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:231613
Fredrik Lundh4c86ec62005-12-14 18:46:161614 # Fredrik Lundh's cElementTree module. Note that this also
1615 # uses expat (via the CAPI hook in pyexpat).
1616
Victor Stinner625dbf22019-03-01 14:59:391617 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:161618 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 14:31:451619 self.add(Extension('_elementtree',
1620 define_macros=define_macros,
1621 include_dirs=expat_inc,
1622 libraries=expat_lib,
1623 sources=['_elementtree.c'],
1624 depends=['pyexpat.c', *expat_sources,
1625 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:291626 else:
Victor Stinner8058bda2019-03-01 14:31:451627 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:161628
Victor Stinner5ec33a12019-03-01 15:43:281629 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:291630 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 14:31:451631 self.add(Extension('_multibytecodec',
1632 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:131633 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 14:31:451634 self.add(Extension('_codecs_%s' % loc,
1635 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:291636
Victor Stinner5ec33a12019-03-01 15:43:281637 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:041638 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 16:48:381639 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 16:19:041640 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1641 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:041642
1643 else:
Victor Stinnerc991f242019-03-01 16:19:041644 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:431645 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1646 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:041647 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 18:48:461648 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1649 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 16:19:041650 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-02 04:52:231651 libs = []
Neil Schemenauer5741c452019-02-08 18:48:461652 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1653 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-02 04:52:231654 libs.append('rt')
Victor Stinner8058bda2019-03-01 14:31:451655 self.add(Extension('_posixshmem', posixshmem_srcs,
1656 define_macros={},
1657 libraries=libs,
1658 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:041659
Victor Stinner8058bda2019-03-01 14:31:451660 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 14:31:451661 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:481662
Victor Stinner5ec33a12019-03-01 15:43:281663 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 21:03:061664 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 14:59:391665 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 03:04:461666 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 14:59:391667 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 21:03:061668 uuid_libs = ['uuid']
1669 else:
1670 uuid_libs = []
Victor Stinnercfe172d2019-03-01 17:21:491671 self.add(Extension('_uuid', ['_uuidmodule.c'],
1672 libraries=uuid_libs,
1673 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 21:03:061674 else:
Victor Stinner8058bda2019-03-01 14:31:451675 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 21:03:061676
Victor Stinner5ec33a12019-03-01 15:43:281677 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 17:21:491678 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 15:43:281679 self.init_inc_lib_dirs()
1680
1681 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 17:21:491682 if TEST_EXTENSIONS:
1683 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 15:43:281684 self.detect_readline_curses()
1685 self.detect_crypt()
1686 self.detect_socket()
1687 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 15:20:081688 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 15:43:281689 self.detect_dbm_gdbm()
1690 self.detect_sqlite()
1691 self.detect_platform_specific_exts()
1692 self.detect_nis()
1693 self.detect_compress_exts()
1694 self.detect_expat_elementtree()
1695 self.detect_multibytecodecs()
1696 self.detect_decimal()
1697 self.detect_ctypes()
1698 self.detect_multiprocessing()
1699 if not self.detect_tkinter():
1700 self.missing.append('_tkinter')
1701 self.detect_uuid()
1702
Ned Deilycd3d8fb2013-08-02 06:51:271703## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 17:21:491704## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-02 06:51:271705
Xavier de Gaye13f1c332016-12-10 15:45:531706 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Victor Stinnercfe172d2019-03-01 17:21:491707 self.add(Extension('xxlimited', ['xxlimited.c'],
1708 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Ned Deilycd3d8fb2013-08-02 06:51:271709
Ned Deilyd819b932013-09-06 08:07:051710 def detect_tkinter_explicitly(self):
1711 # Build _tkinter using explicit locations for Tcl/Tk.
1712 #
1713 # This is enabled when both arguments are given to ./configure:
1714 #
1715 # --with-tcltk-includes="-I/path/to/tclincludes \
1716 # -I/path/to/tkincludes"
1717 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1718 # -L/path/to/tklibs -ltkm.n"
1719 #
Martin Pantere26da7c2016-06-02 10:07:091720 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 08:07:051721 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1722 #
1723 # This can be useful for building and testing tkinter with multiple
1724 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1725 # build of Tcl so you need to specify both arguments and use care when
1726 # overriding.
1727
1728 # The _TCLTK variables are created in the Makefile sharedmods target.
1729 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1730 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1731 if not (tcltk_includes and tcltk_libs):
1732 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 16:48:381733 return False
Ned Deilyd819b932013-09-06 08:07:051734
1735 extra_compile_args = tcltk_includes.split()
1736 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 17:21:491737 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1738 define_macros=[('WITH_APPINIT', 1)],
1739 extra_compile_args = extra_compile_args,
1740 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 16:48:381741 return True
Ned Deilyd819b932013-09-06 08:07:051742
Victor Stinner625dbf22019-03-01 14:59:391743 def detect_tkinter_darwin(self):
Jack Jansen0b06be72002-06-21 14:48:381744 # The _tkinter module, using frameworks. Since frameworks are quite
1745 # different the UNIX search logic is not sharable.
1746 from os.path import join, exists
1747 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:431748 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:481749 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:381750 join(os.getenv('HOME'), '/Library/Frameworks')
1751 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:201752
Ronald Oussoren2c12ab12010-06-03 14:42:251753 sysroot = macosx_sdk_root()
1754
Skip Montanaro0174ddd2005-12-30 05:01:261755 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:381756 # bundles.
1757 # XXX distutils should support -F!
1758 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:431759 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:251760
1761
Jack Jansen0b06be72002-06-21 14:48:381762 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:251763 if is_macosx_sdk_path(F):
1764 if not exists(join(sysroot, F[1:], fw + '.framework')):
1765 break
1766 else:
1767 if not exists(join(F, fw + '.framework')):
1768 break
Jack Jansen0b06be72002-06-21 14:48:381769 else:
1770 # ok, F is now directory with both frameworks. Continure
1771 # building
1772 break
1773 else:
1774 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1775 # will now resume.
Victor Stinner4cbea512019-02-28 16:48:381776 return False
Tim Peters2c60f7a2003-01-29 03:49:431777
Jack Jansen0b06be72002-06-21 14:48:381778 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1779 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:431780 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:381781 #
1782 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:431783 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:431784 for fw in ('Tcl', 'Tk')
1785 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:381786 ]
1787
Tim Peters2c60f7a2003-01-29 03:49:431788 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:381789 # complicated search, this is a hard-coded path. It could bail out
1790 # if X11 libs are not found...
1791 include_dirs.append('/usr/X11R6/include')
1792 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1793
Georg Brandlfcaf9102008-07-16 02:17:561794 # All existing framework builds of Tcl/Tk don't support 64-bit
1795 # architectures.
1796 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 17:59:531797 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:561798
Ronald Oussorend097efe2009-09-15 19:07:581799 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1800 if not os.path.exists(self.build_temp):
1801 os.makedirs(self.build_temp)
1802
1803 # Note: cannot use os.popen or subprocess here, that
1804 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:251805 if is_macosx_sdk_path(F):
1806 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1807 else:
1808 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:251809
Brett Cannon9f5db072010-10-29 20:19:271810 with open(tmpfile) as fp:
1811 detected_archs = []
1812 for ln in fp:
1813 a = ln.split()[-1]
1814 if a in archs:
1815 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:581816 os.unlink(tmpfile)
1817
1818 for a in detected_archs:
1819 frameworks.append('-arch')
1820 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:561821
Victor Stinnercfe172d2019-03-01 17:21:491822 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1823 define_macros=[('WITH_APPINIT', 1)],
1824 include_dirs=include_dirs,
1825 libraries=[],
1826 extra_compile_args=frameworks[2:],
1827 extra_link_args=frameworks))
Victor Stinner4cbea512019-02-28 16:48:381828 return True
Jack Jansen0b06be72002-06-21 14:48:381829
Victor Stinner625dbf22019-03-01 14:59:391830 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:231831 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:411832
Ned Deilyd819b932013-09-06 08:07:051833 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1834 # configured or passed into the make target. If so, use these values
1835 # to build tkinter and bypass the searches for Tcl and TK in standard
1836 # locations.
1837 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 15:43:281838 return True
Ned Deilyd819b932013-09-06 08:07:051839
Jack Jansen0b06be72002-06-21 14:48:381840 # Rather than complicate the code below, detecting and building
1841 # AquaTk is a separate method. Only one Tkinter will be built on
1842 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 15:43:281843 if (MACOS and self.detect_tkinter_darwin()):
1844 return True
Jack Jansen0b06be72002-06-21 14:48:381845
Andrew M. Kuchlingfbe73762001-01-18 18:44:201846 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:011847 # The versions with dots are used on Unix, and the versions without
1848 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:201849 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:141850 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1851 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 14:59:391852 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171853 'tk' + version)
Victor Stinner625dbf22019-03-01 14:59:391854 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171855 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:411856 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:231857 # Exit the loop when we've found the Tcl/Tk libraries
1858 break
Andrew M. Kuchling00e0f212001-01-17 15:23:231859
Fredrik Lundhade711a2001-01-24 08:00:281860 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:201861 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351862 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:201863 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351864 dotversion = version
Victor Stinner4cbea512019-02-28 16:48:381865 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351866 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1867 # but the include subdirs are named like .../include/tcl8.3.
1868 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1869 tcl_include_sub = []
1870 tk_include_sub = []
Victor Stinner625dbf22019-03-01 14:59:391871 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351872 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1873 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1874 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 14:59:391875 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
1876 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:231877
Martin v. Löwise86a59a2003-05-03 08:45:511878 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:201879 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351880 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 15:43:281881 return False
Fredrik Lundhade711a2001-01-24 08:00:281882
Andrew M. Kuchlingfbe73762001-01-18 18:44:201883 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:231884
Victor Stinnercfe172d2019-03-01 17:21:491885 include_dirs = []
1886 libs = []
1887 defs = []
1888 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:201889 for dir in tcl_includes + tk_includes:
1890 if dir not in include_dirs:
1891 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:281892
Andrew M. Kuchlingfbe73762001-01-18 18:44:201893 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 16:48:381894 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:201895 include_dirs.append('/usr/openwin/include')
1896 added_lib_dirs.append('/usr/openwin/lib')
1897 elif os.path.exists('/usr/X11R6/include'):
1898 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:351899 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:201900 added_lib_dirs.append('/usr/X11R6/lib')
1901 elif os.path.exists('/usr/X11R5/include'):
1902 include_dirs.append('/usr/X11R5/include')
1903 added_lib_dirs.append('/usr/X11R5/lib')
1904 else:
Fredrik Lundhade711a2001-01-24 08:00:281905 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:201906 include_dirs.append('/usr/X11/include')
1907 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:231908
Jason Tishler9181c942003-02-05 15:16:171909 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 16:48:381910 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:171911 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1912 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 15:43:281913 return False
Jason Tishler9181c942003-02-05 15:16:171914
Andrew M. Kuchlingfbe73762001-01-18 18:44:201915 # Check for BLT extension
Victor Stinner625dbf22019-03-01 14:59:391916 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171917 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:201918 defs.append( ('WITH_BLT', 1) )
1919 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 14:59:391920 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171921 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:381922 defs.append( ('WITH_BLT', 1) )
1923 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:231924
Andrew M. Kuchlingfbe73762001-01-18 18:44:201925 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:461926 libs.append('tk'+ version)
1927 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:281928
Martin v. Löwis3db5b8c2001-07-24 06:54:011929 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 16:48:381930 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:011931 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:231932
Andrew M. Kuchlingfbe73762001-01-18 18:44:201933 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:231934 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:281935 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:231936 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:281937 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:231938 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:281939 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:231940
Victor Stinnercfe172d2019-03-01 17:21:491941 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1942 define_macros=[('WITH_APPINIT', 1)] + defs,
1943 include_dirs=include_dirs,
1944 libraries=libs,
1945 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 15:43:281946 return True
1947
Thomas Wouters49fd7fa2006-04-21 10:40:581948 def configure_ctypes(self, ext):
Thomas Wouters49fd7fa2006-04-21 10:40:581949 return True
1950
Victor Stinner625dbf22019-03-01 14:59:391951 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 15:43:281952 # Thomas Heller's _ctypes module
Ned Deilyb29d0a52021-05-02 09:18:581953
1954 if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
1955 self.use_system_libffi = True
1956 else:
1957 self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
1958
Thomas Wouters49fd7fa2006-04-21 10:40:581959 include_dirs = []
1960 extra_compile_args = []
Thomas Wouters0e3f5912006-08-11 14:57:121961 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:581962 sources = ['_ctypes/_ctypes.c',
1963 '_ctypes/callbacks.c',
1964 '_ctypes/callproc.c',
1965 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:531966 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:581967 depends = ['_ctypes/ctypes.h']
1968
Victor Stinner4cbea512019-02-28 16:48:381969 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:591970 sources.append('_ctypes/malloc_closure.c')
Ned Deilyb29d0a52021-05-02 09:18:581971 extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
Christian Heimes78644762008-03-04 23:39:231972 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:581973 include_dirs.append('_ctypes/darwin')
Thomas Hellercf567c12006-03-08 19:51:581974
Victor Stinner4cbea512019-02-28 16:48:381975 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:121976 # XXX This shouldn't be necessary; it appears that some
1977 # of the assembler code is non-PIC (i.e. it has relocations
1978 # when it shouldn't. The proper fix would be to rewrite
1979 # the assembler code to be PIC.
1980 # This only works with GCC; the Sun compiler likely refuses
1981 # this option. If you want to compile ctypes with the Sun
1982 # compiler, please research a proper solution, instead of
1983 # finding some -z option for the Sun compiler.
1984 extra_link_args.append('-mimpure-text')
1985
Victor Stinner4cbea512019-02-28 16:48:381986 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:461987 extra_link_args.append('-fPIC')
1988
Thomas Hellercf567c12006-03-08 19:51:581989 ext = Extension('_ctypes',
1990 include_dirs=include_dirs,
1991 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:121992 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:581993 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:581994 sources=sources,
1995 depends=depends)
Victor Stinnercfe172d2019-03-01 17:21:491996 self.add(ext)
1997 if TEST_EXTENSIONS:
1998 # function my_sqrt() needs libm for sqrt()
1999 self.add(Extension('_ctypes_test',
2000 sources=['_ctypes/_ctypes_test.c'],
2001 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:582002
Ned Deilyb29d0a52021-05-02 09:18:582003 ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
2004 ffi_lib = None
2005
Victor Stinner625dbf22019-03-01 14:59:392006 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 16:48:382007 if MACOS:
Ned Deilyb29d0a52021-05-02 09:18:582008 ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
Christian Heimes78644762008-03-04 23:39:232009
Ned Deilyb29d0a52021-05-02 09:18:582010 if not ffi_inc:
2011 if os.path.exists(ffi_in_sdk):
2012 ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
2013 ffi_inc = ffi_in_sdk
2014 ffi_lib = 'ffi'
2015 else:
2016 # OS X 10.5 comes with libffi.dylib; the include files are
2017 # in /usr/include/ffi
2018 ffi_inc_dirs.append('/usr/include/ffi')
2019
2020 if not ffi_inc:
2021 found = find_file('ffi.h', [], ffi_inc_dirs)
2022 if found:
2023 ffi_inc = found[0]
2024 if ffi_inc:
2025 ffi_h = ffi_inc + '/ffi.h'
Shlomi Fish6d51b872017-09-06 20:19:192026 if not os.path.exists(ffi_h):
2027 ffi_inc = None
2028 print('Header file {} does not exist'.format(ffi_h))
Ned Deilyb29d0a52021-05-02 09:18:582029 if ffi_lib is None and ffi_inc:
doko@ubuntu.comae683652016-06-04 23:38:292030 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 14:59:392031 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:582032 ffi_lib = lib_name
2033 break
2034
2035 if ffi_inc and ffi_lib:
Ned Deilyb29d0a52021-05-02 09:18:582036 ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
2037 if grep_headers_for('ffi_prep_cif_var', ffi_headers):
2038 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
2039 if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
2040 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
2041 if grep_headers_for('ffi_closure_alloc', ffi_headers):
2042 ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
2043
2044 ext.include_dirs.append(ffi_inc)
Thomas Wouters49fd7fa2006-04-21 10:40:582045 ext.libraries.append(ffi_lib)
2046 self.use_system_libffi = True
2047
Christian Heimes5bb96922018-02-25 09:22:142048 if sysconfig.get_config_var('HAVE_LIBDL'):
2049 # for dlopen, see bpo-32647
2050 ext.libraries.append('dl')
2051
Victor Stinner5ec33a12019-03-01 15:43:282052 def detect_decimal(self):
2053 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 18:06:272054 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 12:21:222055 undef_macros = []
Stefan Krah60187b52012-03-23 18:06:272056 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2057 include_dirs = []
Stefan Krah45059eb2013-11-24 18:44:572058 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 18:06:272059 sources = ['_decimal/_decimal.c']
2060 depends = ['_decimal/docstrings.h']
2061 else:
Victor Stinner625dbf22019-03-01 14:59:392062 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 09:30:462063 'Modules',
2064 '_decimal',
2065 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 17:24:172066 libraries = ['m']
Stefan Krah60187b52012-03-23 18:06:272067 sources = [
2068 '_decimal/_decimal.c',
2069 '_decimal/libmpdec/basearith.c',
2070 '_decimal/libmpdec/constants.c',
2071 '_decimal/libmpdec/context.c',
2072 '_decimal/libmpdec/convolute.c',
2073 '_decimal/libmpdec/crt.c',
2074 '_decimal/libmpdec/difradix2.c',
2075 '_decimal/libmpdec/fnt.c',
2076 '_decimal/libmpdec/fourstep.c',
2077 '_decimal/libmpdec/io.c',
2078 '_decimal/libmpdec/memory.c',
2079 '_decimal/libmpdec/mpdecimal.c',
2080 '_decimal/libmpdec/numbertheory.c',
2081 '_decimal/libmpdec/sixstep.c',
2082 '_decimal/libmpdec/transpose.c',
2083 ]
2084 depends = [
2085 '_decimal/docstrings.h',
2086 '_decimal/libmpdec/basearith.h',
2087 '_decimal/libmpdec/bits.h',
2088 '_decimal/libmpdec/constants.h',
2089 '_decimal/libmpdec/convolute.h',
2090 '_decimal/libmpdec/crt.h',
2091 '_decimal/libmpdec/difradix2.h',
2092 '_decimal/libmpdec/fnt.h',
2093 '_decimal/libmpdec/fourstep.h',
2094 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 14:34:412095 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 18:06:272096 '_decimal/libmpdec/mpdecimal.h',
2097 '_decimal/libmpdec/numbertheory.h',
2098 '_decimal/libmpdec/sixstep.h',
2099 '_decimal/libmpdec/transpose.h',
2100 '_decimal/libmpdec/typearith.h',
2101 '_decimal/libmpdec/umodarith.h',
2102 ]
2103
Stefan Krah1919b7e2012-03-21 17:25:232104 config = {
2105 'x64': [('CONFIG_64','1'), ('ASM','1')],
2106 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2107 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2108 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2109 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2110 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2111 ('LEGACY_COMPILER','1')],
2112 'universal': [('UNIVERSAL','1')]
2113 }
2114
Stefan Krah1919b7e2012-03-21 17:25:232115 cc = sysconfig.get_config_var('CC')
2116 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2117 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2118
2119 if machine:
2120 # Override automatic configuration to facilitate testing.
2121 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 16:48:382122 elif MACOS:
Stefan Krah1919b7e2012-03-21 17:25:232123 # Universal here means: build with the same options Python
2124 # was built with.
2125 define_macros = config['universal']
2126 elif sizeof_size_t == 8:
2127 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2128 define_macros = config['x64']
2129 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2130 define_macros = config['uint128']
2131 else:
2132 define_macros = config['ansi64']
2133 elif sizeof_size_t == 4:
2134 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2135 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 16:48:382136 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 17:25:232137 # solaris: problems with register allocation.
2138 # icc >= 11.0 works as well.
2139 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 19:12:532140 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 17:25:232141 else:
2142 define_macros = config['ansi32']
2143 else:
2144 raise DistutilsError("_decimal: unsupported architecture")
2145
2146 # Workarounds for toolchain bugs:
2147 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2148 # Some versions of gcc miscompile inline asm:
2149 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2150 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2151 extra_compile_args.append('-fno-ipa-pure-const')
2152 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2153 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2154 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2155 undef_macros.append('_FORTIFY_SOURCE')
2156
Stefan Krah1919b7e2012-03-21 17:25:232157 # Uncomment for extra functionality:
2158 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 14:31:452159 self.add(Extension('_decimal',
2160 include_dirs=include_dirs,
2161 libraries=libraries,
2162 define_macros=define_macros,
2163 undef_macros=undef_macros,
2164 extra_compile_args=extra_compile_args,
2165 sources=sources,
2166 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:582167
Victor Stinner5ec33a12019-03-01 15:43:282168 def detect_openssl_hashlib(self):
2169 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 12:19:212170 config_vars = sysconfig.get_config_vars()
2171
2172 def split_var(name, sep):
2173 # poor man's shlex, the re module is not available yet.
2174 value = config_vars.get(name)
2175 if not value:
2176 return ()
2177 # This trick works because ax_check_openssl uses --libs-only-L,
2178 # --libs-only-l, and --cflags-only-I.
2179 value = ' ' + value
2180 sep = ' ' + sep
2181 return [v.strip() for v in value.split(sep) if v.strip()]
2182
2183 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2184 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2185 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2186 if not openssl_libs:
2187 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 16:40:122188 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 12:19:212189 return None, None
2190
2191 # Find OpenSSL includes
2192 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 14:59:392193 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 12:19:212194 )
2195 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 16:40:122196 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 12:19:212197 return None, None
2198
2199 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2200 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 14:59:392201 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 12:19:212202 ['/usr/kerberos/include']
2203 )
2204 if krb5_h:
2205 ssl_incs.extend(krb5_h)
2206
Christian Heimes61d478c2018-01-27 14:51:382207 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 09:44:052208 self.add(Extension(
2209 '_ssl', ['_ssl.c'],
2210 include_dirs=openssl_includes,
2211 library_dirs=openssl_libdirs,
2212 libraries=openssl_libs,
Christian Heimes70f2ca72021-04-09 16:34:542213 depends=[
2214 'socketmodule.h',
2215 '_ssl/debughelpers.c',
2216 '_ssl_data.h',
2217 '_ssl_data_111.h',
2218 '_ssl_data_300.h',
2219 ]))
Christian Heimes61d478c2018-01-27 14:51:382220 else:
Victor Stinner8058bda2019-03-01 14:31:452221 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 12:19:212222
Victor Stinner8058bda2019-03-01 14:31:452223 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2224 depends=['hashlib.h'],
2225 include_dirs=openssl_includes,
2226 library_dirs=openssl_libdirs,
2227 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 12:19:212228
xdegaye2ee077f2019-04-09 15:20:082229 def detect_hash_builtins(self):
Victor Stinner5ec33a12019-03-01 15:43:282230 # We always compile these even when OpenSSL is available (issue #14693).
2231 # It's harmless and the object code is tiny (40-50 KiB per module,
2232 # only loaded when actually used).
2233 self.add(Extension('_sha256', ['sha256module.c'],
2234 depends=['hashlib.h']))
2235 self.add(Extension('_sha512', ['sha512module.c'],
2236 depends=['hashlib.h']))
2237 self.add(Extension('_md5', ['md5module.c'],
2238 depends=['hashlib.h']))
2239 self.add(Extension('_sha1', ['sha1module.c'],
2240 depends=['hashlib.h']))
2241
Serhiy Storchakae7389622020-07-02 07:05:352242 blake2_deps = glob(os.path.join(escape(self.srcdir),
Victor Stinner5ec33a12019-03-01 15:43:282243 'Modules/_blake2/impl/*'))
2244 blake2_deps.append('hashlib.h')
2245
2246 self.add(Extension('_blake2',
2247 ['_blake2/blake2module.c',
2248 '_blake2/blake2b_impl.c',
2249 '_blake2/blake2s_impl.c'],
2250 depends=blake2_deps))
2251
Serhiy Storchakae7389622020-07-02 07:05:352252 sha3_deps = glob(os.path.join(escape(self.srcdir),
Victor Stinner5ec33a12019-03-01 15:43:282253 'Modules/_sha3/kcp/*'))
2254 sha3_deps.append('hashlib.h')
2255 self.add(Extension('_sha3',
2256 ['_sha3/sha3module.c'],
2257 depends=sha3_deps))
2258
2259 def detect_nis(self):
Victor Stinner4cbea512019-02-28 16:48:382260 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 14:31:452261 self.missing.append('nis')
2262 return
Christian Heimes29a7df72018-01-26 22:28:462263
2264 libs = []
2265 library_dirs = []
2266 includes_dirs = []
2267
2268 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2269 # moved headers and libraries to libtirpc and libnsl. The headers
2270 # are in tircp and nsl sub directories.
2271 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 14:59:392272 'rpcsvc/yp_prot.h', self.inc_dirs,
2273 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 22:28:462274 )
2275 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 14:59:392276 'rpc/rpc.h', self.inc_dirs,
2277 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 22:28:462278 )
2279 if rpcsvc_inc is None or rpc_inc is None:
2280 # not found
Victor Stinner8058bda2019-03-01 14:31:452281 self.missing.append('nis')
2282 return
Christian Heimes29a7df72018-01-26 22:28:462283 includes_dirs.extend(rpcsvc_inc)
2284 includes_dirs.extend(rpc_inc)
2285
Victor Stinner625dbf22019-03-01 14:59:392286 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 22:28:462287 libs.append('nsl')
2288 else:
2289 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 14:59:392290 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 22:28:462291 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2292 if libnsl is not None:
2293 library_dirs.append(os.path.dirname(libnsl))
2294 libs.append('nsl')
2295
Victor Stinner625dbf22019-03-01 14:59:392296 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 22:28:462297 libs.append('tirpc')
2298
Victor Stinner8058bda2019-03-01 14:31:452299 self.add(Extension('nis', ['nismodule.c'],
2300 libraries=libs,
2301 library_dirs=library_dirs,
2302 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 22:28:462303
Christian Heimesff5be6e2018-01-20 12:19:212304
Andrew M. Kuchlingf52d27e2001-05-21 20:29:272305class PyBuildInstall(install):
2306 # Suppress the warning about installation into the lib_dynload
2307 # directory, which is not in sys.path when running Python during
2308 # installation:
2309 def initialize_options (self):
2310 install.initialize_options(self)
2311 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:412312
Éric Araujoe6792c12011-06-09 12:07:022313 # Customize subcommands to not install an egg-info file for Python
2314 sub_commands = [('install_lib', install.has_lib),
2315 ('install_headers', install.has_headers),
2316 ('install_scripts', install.has_scripts),
2317 ('install_data', install.has_data)]
2318
2319
Michael W. Hudson529a5052002-12-17 16:47:172320class PyBuildInstallLib(install_lib):
2321 # Do exactly what install_lib does but make sure correct access modes get
2322 # set on installed directories and files. All installed files with get
2323 # mode 644 unless they are a shared library in which case they will get
2324 # mode 755. All installed directories will get mode 755.
2325
doko@ubuntu.comd5537d02013-03-21 20:21:492326 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2327 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:172328
2329 def install(self):
2330 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:492331 self.set_file_modes(outfiles, 0o644, 0o755)
2332 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:172333 return outfiles
2334
2335 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:172336 if not files: return
2337
2338 for filename in files:
2339 if os.path.islink(filename): continue
2340 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 20:21:492341 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:172342 log.info("changing mode of %s to %o", filename, mode)
2343 if not self.dry_run: os.chmod(filename, mode)
2344
2345 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:452346 for dirpath, dirnames, fnames in os.walk(dirname):
2347 if os.path.islink(dirpath):
2348 continue
2349 log.info("changing mode of %s to %o", dirpath, mode)
2350 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:172351
Victor Stinnerc991f242019-03-01 16:19:042352
Georg Brandlff52f762010-12-28 09:51:432353class PyBuildScripts(build_scripts):
2354 def copy_scripts(self):
2355 outfiles, updated_files = build_scripts.copy_scripts(self)
2356 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2357 minoronly = '.{0[1]}'.format(sys.version_info)
2358 newoutfiles = []
2359 newupdated_files = []
2360 for filename in outfiles:
Brett Cannona8c34242018-04-20 21:15:402361 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:432362 newfilename = filename + fullversion
2363 else:
2364 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 07:22:292365 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:432366 os.rename(filename, newfilename)
2367 newoutfiles.append(newfilename)
2368 if filename in updated_files:
2369 newupdated_files.append(newfilename)
2370 return newoutfiles, newupdated_files
2371
Guido van Rossum14ee89c2003-02-20 02:52:042372
Andrew M. Kuchling00e0f212001-01-17 15:23:232373def main():
Victor Stinnerc991f242019-03-01 16:19:042374 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2375 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2376
2377 class DummyProcess:
2378 """Hack for parallel build"""
2379 ProcessPoolExecutor = None
2380
2381 sys.modules['concurrent.futures.process'] = DummyProcess
2382
Andrew M. Kuchling62686692001-05-21 20:48:092383 # turn off warnings when deprecated modules are imported
2384 import warnings
2385 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:042386 setup(# PyPI Metadata (PEP 301)
2387 name = "Python",
2388 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 11:10:362389 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:042390 maintainer = "Guido van Rossum and the Python community",
2391 maintainer_email = "python-dev@python.org",
2392 description = "A high-level object-oriented programming language",
2393 long_description = SUMMARY.strip(),
2394 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:582395 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:042396 platforms = ["Many"],
2397
2398 # Build info
Georg Brandlff52f762010-12-28 09:51:432399 cmdclass = {'build_ext': PyBuildExt,
2400 'build_scripts': PyBuildScripts,
2401 'install': PyBuildInstall,
2402 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:232403 # The struct module is defined here, because build_ext won't be
2404 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:472405 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:492406
Georg Brandlff52f762010-12-28 09:51:432407 # If you change the scripts installed here, you also need to
2408 # check the PyBuildScripts command above, and change the links
2409 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:142410 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 21:15:402411 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:232412 )
Fredrik Lundhade711a2001-01-24 08:00:282413
Andrew M. Kuchling00e0f212001-01-17 15:23:232414# --install-platlib
2415if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:232416 main()