blob: 6aa607f1e334c0faa028f7d7e384a8c0cbf7e032 [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +00002
Victor Stinner625dbf22019-03-01 15:59:39 +01003import argparse
Eric Snow335e14d2014-01-04 15:09:28 -07004import importlib._bootstrap
Victor Stinner625dbf22019-03-01 15:59:39 +01005import importlib.machinery
Eric Snow335e14d2014-01-04 15:09:28 -07006import importlib.util
Victor Stinner625dbf22019-03-01 15:59:39 +01007import os
8import re
9import sys
Tarek Ziadéedacea32010-01-29 11:41:03 +000010import sysconfig
Victor Stinner625dbf22019-03-01 15:59:39 +010011from glob import glob
Michael W. Hudson529a5052002-12-17 16:47:17 +000012
13from distutils import log
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000014from distutils.command.build_ext import build_ext
Victor Stinner625dbf22019-03-01 15:59:39 +010015from distutils.command.build_scripts import build_scripts
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000016from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:17 +000017from distutils.command.install_lib import install_lib
Victor Stinner625dbf22019-03-01 15:59:39 +010018from distutils.core import Extension, setup
19from distutils.errors import CCompilerError, DistutilsError
Stefan Krah095b2732010-06-08 13:41:44 +000020from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000021
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020022
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020023def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010024 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020025 if "_PYTHON_HOST_PLATFORM" in os.environ:
26 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010027
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020028 # Get value of sys.platform
29 if sys.platform.startswith('osf1'):
30 return 'osf1'
31 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010032
33
34CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010035HOST_PLATFORM = get_platform()
36MS_WINDOWS = (HOST_PLATFORM == 'win32')
37CYGWIN = (HOST_PLATFORM == 'cygwin')
38MACOS = (HOST_PLATFORM == 'darwin')
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020039
Victor Stinner4cbea512019-02-28 17:48:38 +010040VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080041
Gregory P. Smithb04ded42010-01-03 00:38:10 +000042# Were we compiled --with-pydebug or with #define Py_DEBUG?
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020043COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
Gregory P. Smithb04ded42010-01-03 00:38:10 +000044
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000045# This global variable is used to hold the list of modules to be disabled.
Victor Stinner4cbea512019-02-28 17:48:38 +010046DISABLED_MODULE_LIST = []
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000047
Victor Stinnerc991f242019-03-01 17:19:04 +010048
49SUMMARY = """
50Python is an interpreted, interactive, object-oriented programming
51language. It is often compared to Tcl, Perl, Scheme or Java.
52
53Python combines remarkable power with very clear syntax. It has
54modules, classes, exceptions, very high level dynamic data types, and
55dynamic typing. There are interfaces to many system calls and
56libraries, as well as to various windowing systems (X11, Motif, Tk,
57Mac, MFC). New built-in modules are easily written in C or C++. Python
58is also usable as an extension language for applications that need a
59programmable interface.
60
61The Python implementation is portable: it runs on many brands of UNIX,
62on Windows, DOS, Mac, Amiga... If your favorite system isn't
63listed here, it may still be supported, if there's a C compiler for
64it. Ask around on comp.lang.python -- or just try compiling Python
65yourself.
66"""
67
68CLASSIFIERS = """
69Development Status :: 6 - Mature
70License :: OSI Approved :: Python Software Foundation License
71Natural Language :: English
72Programming Language :: C
73Programming Language :: Python
74Topic :: Software Development
75"""
76
77
78# Set common compiler and linker flags derived from the Makefile,
79# reserved for building the interpreter and the stdlib modules.
80# See bpo-21121 and bpo-35257
81def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
82 flags = sysconfig.get_config_var(compiler_flags)
83 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
84 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
85
86
Michael W. Hudson39230b32002-01-16 15:26:48 +000087def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +000088 """Add the directory 'dir' to the list 'dirlist' (after any relative
89 directories) if:
90
Michael W. Hudson39230b32002-01-16 15:26:48 +000091 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +000092 2) 'dir' actually exists, and is a directory.
93 """
94 if dir is None or not os.path.isdir(dir) or dir in dirlist:
95 return
96 for i, path in enumerate(dirlist):
97 if not os.path.isabs(path):
98 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +000099 return
100 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000101
Victor Stinnerc991f242019-03-01 17:19:04 +0100102
xdegaye77f51392017-11-25 17:25:30 +0100103def sysroot_paths(make_vars, subdirs):
104 """Get the paths of sysroot sub-directories.
105
106 * make_vars: a sequence of names of variables of the Makefile where
107 sysroot may be set.
108 * subdirs: a sequence of names of subdirectories used as the location for
109 headers or libraries.
110 """
111
112 dirs = []
113 for var_name in make_vars:
114 var = sysconfig.get_config_var(var_name)
115 if var is not None:
116 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
117 if m is not None:
118 sysroot = m.group(1).strip('"')
119 for subdir in subdirs:
120 if os.path.isabs(subdir):
121 subdir = subdir[1:]
122 path = os.path.join(sysroot, subdir)
123 if os.path.isdir(path):
124 dirs.append(path)
125 break
126 return dirs
127
Victor Stinnerc991f242019-03-01 17:19:04 +0100128
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000129def macosx_sdk_root():
130 """
131 Return the directory of the current OSX SDK,
132 or '/' if no SDK was specified.
133 """
134 cflags = sysconfig.get_config_var('CFLAGS')
135 m = re.search(r'-isysroot\s+(\S+)', cflags)
136 if m is None:
137 sysroot = '/'
138 else:
139 sysroot = m.group(1)
140 return sysroot
141
Victor Stinnerc991f242019-03-01 17:19:04 +0100142
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000143def is_macosx_sdk_path(path):
144 """
145 Returns True if 'path' can be located in an OSX SDK
146 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700147 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
148 or path.startswith('/System/')
149 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000150
Victor Stinnerc991f242019-03-01 17:19:04 +0100151
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000152def find_file(filename, std_dirs, paths):
153 """Searches for the directory where a given file is located,
154 and returns a possibly-empty list of additional directories, or None
155 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000156
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000157 'filename' is the name of a file, such as readline.h or libcrypto.a.
158 'std_dirs' is the list of standard system directories; if the
159 file is found in one of them, no additional directives are needed.
160 'paths' is a list of additional locations to check; if the file is
161 found in one of them, the resulting list will contain the directory.
162 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100163 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000164 # Honor the MacOSX SDK setting when one was specified.
165 # An SDK is a directory with the same structure as a real
166 # system, but with only header files and libraries.
167 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000168
169 # Check the standard locations
170 for dir in std_dirs:
171 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000172
Victor Stinner4cbea512019-02-28 17:48:38 +0100173 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000174 f = os.path.join(sysroot, dir[1:], filename)
175
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000176 if os.path.exists(f): return []
177
178 # Check the additional directories
179 for dir in paths:
180 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000181
Victor Stinner4cbea512019-02-28 17:48:38 +0100182 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000183 f = os.path.join(sysroot, dir[1:], filename)
184
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000185 if os.path.exists(f):
186 return [dir]
187
188 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000189 return None
190
Victor Stinnerc991f242019-03-01 17:19:04 +0100191
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000192def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000193 result = compiler.find_library_file(std_dirs + paths, libname)
194 if result is None:
195 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000196
Victor Stinner4cbea512019-02-28 17:48:38 +0100197 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000198 sysroot = macosx_sdk_root()
199
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000200 # Check whether the found file is in one of the standard directories
201 dirname = os.path.dirname(result)
202 for p in std_dirs:
203 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000204 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000205
Victor Stinner4cbea512019-02-28 17:48:38 +0100206 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100207 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
208 # libraries with .tbd extensions rather than the normal .dylib
209 # shared libraries installed in /. The Apple compiler tool
210 # chain handles this transparently but it can cause problems
211 # for programs that are being built with an SDK and searching
212 # for specific libraries. Distutils find_library_file() now
213 # knows to also search for and return .tbd files. But callers
214 # of find_library_file need to keep in mind that the base filename
215 # of the returned SDK library file might have a different extension
216 # from that of the library file installed on the running system,
217 # for example:
218 # /Applications/Xcode.app/Contents/Developer/Platforms/
219 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
220 # usr/lib/libedit.tbd
221 # vs
222 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000223 if os.path.join(sysroot, p[1:]) == dirname:
224 return [ ]
225
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000226 if p == dirname:
227 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000228
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000229 # Otherwise, it must have been in one of the additional directories,
230 # so we have to figure out which one.
231 for p in paths:
232 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000233 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000234
Victor Stinner4cbea512019-02-28 17:48:38 +0100235 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000236 if os.path.join(sysroot, p[1:]) == dirname:
237 return [ p ]
238
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000239 if p == dirname:
240 return [p]
241 else:
242 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000243
Victor Stinnerc991f242019-03-01 17:19:04 +0100244
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000245def module_enabled(extlist, modname):
246 """Returns whether the module 'modname' is present in the list
247 of extensions 'extlist'."""
248 extlist = [ext for ext in extlist if ext.name == modname]
249 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000250
Victor Stinnerc991f242019-03-01 17:19:04 +0100251
Jack Jansen144ebcc2001-08-05 22:31:19 +0000252def find_module_file(module, dirlist):
253 """Find a module in a set of possible folders. If it is not found
254 return the unadorned filename"""
255 list = find_file(module, [], dirlist)
256 if not list:
257 return module
258 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100259 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000260 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000261
Victor Stinnerc991f242019-03-01 17:19:04 +0100262
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000263class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000264
Guido van Rossumd8faa362007-04-27 19:54:29 +0000265 def __init__(self, dist):
266 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100267 self.srcdir = None
268 self.lib_dirs = None
269 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100270 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000271 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400272 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100273 self.missing = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200274 if '-j' in os.environ.get('MAKEFLAGS', ''):
275 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000276
Victor Stinner8058bda2019-03-01 15:31:45 +0100277 def add(self, ext):
278 self.extensions.append(ext)
279
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000280 def build_extensions(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100281 self.srcdir = sysconfig.get_config_var('srcdir')
282 if not self.srcdir:
283 # Maybe running on Windows but not using CYGWIN?
284 raise ValueError("No source directory; cannot proceed.")
285 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000286
287 # Detect which modules should be compiled
Victor Stinner8058bda2019-03-01 15:31:45 +0100288 self.detect_modules()
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000289
290 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000291 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100292 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000293 # move ctypes to the end, it depends on other modules
294 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
295 if "_ctypes" in ext_map:
296 ctypes = extensions.pop(ext_map["_ctypes"])
297 extensions.append(ctypes)
298 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000299
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000300 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000301 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100302 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000303
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000304 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100305 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000306 for filename in self.distribution.scripts]
307
Christian Heimesaf98da12008-01-27 15:18:18 +0000308 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000309 headers = [sysconfig.get_config_h_filename()]
Stefan Kraheb977da2012-02-29 14:10:53 +0100310 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000311
xdegayec0364fc2017-05-27 18:25:03 +0200312 # The sysconfig variables built by makesetup that list the already
313 # built modules and the disabled modules as configured by the Setup
314 # files.
315 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
316 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200317
xdegayec0364fc2017-05-27 18:25:03 +0200318 mods_built = []
319 mods_disabled = []
Xavier de Gaye84968b72016-10-29 16:57:20 +0200320 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000321 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000322 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000323 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000324 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000325 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000326 else:
327 ext.depends = []
328 # re-compile extensions if a header file has been changed
329 ext.depends.extend(headers)
330
xdegayec0364fc2017-05-27 18:25:03 +0200331 # If a module has already been built or has been disabled in the
332 # Setup files, don't build it here.
333 if ext.name in sysconf_built:
334 mods_built.append(ext)
335 if ext.name in sysconf_dis:
336 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000337
xdegayec0364fc2017-05-27 18:25:03 +0200338 mods_configured = mods_built + mods_disabled
339 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200340 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200341 mods_configured]
342 # Remove the shared libraries built by a previous build.
343 for ext in mods_configured:
344 fullpath = self.get_ext_fullpath(ext.name)
345 if os.path.exists(fullpath):
346 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000347
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000348 # When you run "make CC=altcc" or something similar, you really want
349 # those environment variables passed into the setup.py phase. Here's
350 # a small set of useful ones.
351 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000352 args = {}
353 # unfortunately, distutils doesn't let us provide separate C and C++
354 # compilers
355 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000356 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
357 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000358 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000359
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000360 build_ext.build_extensions(self)
361
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200362 for ext in self.extensions:
363 self.check_extension_import(ext)
364
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300365 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400366 if self.failed or self.failed_on_import:
367 all_failed = self.failed + self.failed_on_import
368 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000369
370 def print_three_column(lst):
371 lst.sort(key=str.lower)
372 # guarantee zip() doesn't drop anything
373 while len(lst) % 3:
374 lst.append("")
375 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
376 print("%-*s %-*s %-*s" % (longest, e, longest, f,
377 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000378
Victor Stinner8058bda2019-03-01 15:31:45 +0100379 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000380 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400381 print("Python build finished successfully!")
382 print("The necessary bits to build these optional modules were not "
383 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100384 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000385 print("To find the necessary bits, look in setup.py in"
386 " detect_modules() for the module's name.")
387 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000388
xdegayec0364fc2017-05-27 18:25:03 +0200389 if mods_built:
390 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200391 print("The following modules found by detect_modules() in"
392 " setup.py, have been")
393 print("built by the Makefile instead, as configured by the"
394 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200395 print_three_column([ext.name for ext in mods_built])
396 print()
397
398 if mods_disabled:
399 print()
400 print("The following modules found by detect_modules() in"
401 " setup.py have not")
402 print("been built, they are *disabled* in the Setup files:")
403 print_three_column([ext.name for ext in mods_disabled])
404 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200405
Guido van Rossumd8faa362007-04-27 19:54:29 +0000406 if self.failed:
407 failed = self.failed[:]
408 print()
409 print("Failed to build these modules:")
410 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000411 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000412
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400413 if self.failed_on_import:
414 failed = self.failed_on_import[:]
415 print()
416 print("Following modules built successfully"
417 " but were removed because they could not be imported:")
418 print_three_column(failed)
419 print()
420
Christian Heimes61d478c2018-01-27 15:51:38 +0100421 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100422 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100423 print()
424 print("Could not build the ssl module!")
425 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
426 "libssl with X509_VERIFY_PARAM_set1_host().")
427 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
428 "APIs, https://github.com/libressl-portable/portable/issues/381")
429 print()
430
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000431 def build_extension(self, ext):
432
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000433 if ext.name == '_ctypes':
434 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500435 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000436 return
437
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000438 try:
439 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000440 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000441 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100442 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000443 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000444 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200445
446 def check_extension_import(self, ext):
447 # Don't try to import an extension that has failed to compile
448 if ext.name in self.failed:
449 self.announce(
450 'WARNING: skipping import check for failed build "%s"' %
451 ext.name, level=1)
452 return
453
Jack Jansenf49c6f92001-11-01 14:44:15 +0000454 # Workaround for Mac OS X: The Carbon-based modules cannot be
455 # reliably imported into a command-line Python
456 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000457 self.announce(
458 'WARNING: skipping import check for Carbon-based "%s"' %
459 ext.name)
460 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000461
Victor Stinner4cbea512019-02-28 17:48:38 +0100462 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000463 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000464 # Don't bother doing an import check when an extension was
465 # build with an explicit '-arch' flag on OSX. That's currently
466 # only used to build 32-bit only extensions in a 4-way
467 # universal build and loading 32-bit code into a 64-bit
468 # process will fail.
469 self.announce(
470 'WARNING: skipping import check for "%s"' %
471 ext.name)
472 return
473
Jason Tishler24cf7762002-05-22 16:46:15 +0000474 # Workaround for Cygwin: Cygwin currently has fork issues when many
475 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100476 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000477 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
478 % ext.name)
479 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000480 ext_filename = os.path.join(
481 self.build_lib,
482 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000483
484 # If the build directory didn't exist when setup.py was
485 # started, sys.path_importer_cache has a negative result
486 # cached. Clear that cache before trying to import.
487 sys.path_importer_cache.clear()
488
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200489 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100490 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200491 return
492
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400493 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700494 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
495 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000496 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400497 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000498 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400499 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000500 self.announce('*** WARNING: renaming "%s" since importing it'
501 ' failed: %s' % (ext.name, why), level=3)
502 assert not self.inplace
503 basename, tail = os.path.splitext(ext_filename)
504 newname = basename + "_failed" + tail
505 if os.path.exists(newname):
506 os.remove(newname)
507 os.rename(ext_filename, newname)
508
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000509 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000510 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000511 self.announce('*** WARNING: importing extension "%s" '
512 'failed with %s: %s' % (ext.name, exc_type, why),
513 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000514 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000515
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400516 def add_multiarch_paths(self):
517 # Debian/Ubuntu multiarch support.
518 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200519 cc = sysconfig.get_config_var('CC')
520 tmpfile = os.path.join(self.build_temp, 'multiarch')
521 if not os.path.exists(self.build_temp):
522 os.makedirs(self.build_temp)
523 ret = os.system(
524 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
525 multiarch_path_component = ''
526 try:
527 if ret >> 8 == 0:
528 with open(tmpfile) as fp:
529 multiarch_path_component = fp.readline().strip()
530 finally:
531 os.unlink(tmpfile)
532
533 if multiarch_path_component != '':
534 add_dir_to_list(self.compiler.library_dirs,
535 '/usr/lib/' + multiarch_path_component)
536 add_dir_to_list(self.compiler.include_dirs,
537 '/usr/include/' + multiarch_path_component)
538 return
539
Barry Warsaw88e19452011-04-07 10:40:36 -0400540 if not find_executable('dpkg-architecture'):
541 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200542 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100543 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200544 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400545 tmpfile = os.path.join(self.build_temp, 'multiarch')
546 if not os.path.exists(self.build_temp):
547 os.makedirs(self.build_temp)
548 ret = os.system(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200549 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
550 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400551 try:
552 if ret >> 8 == 0:
553 with open(tmpfile) as fp:
554 multiarch_path_component = fp.readline().strip()
555 add_dir_to_list(self.compiler.library_dirs,
556 '/usr/lib/' + multiarch_path_component)
557 add_dir_to_list(self.compiler.include_dirs,
558 '/usr/include/' + multiarch_path_component)
559 finally:
560 os.unlink(tmpfile)
561
pxinwr32f5fdd2019-02-27 19:09:28 +0800562 def add_cross_compiling_paths(self):
563 cc = sysconfig.get_config_var('CC')
564 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200565 if not os.path.exists(self.build_temp):
566 os.makedirs(self.build_temp)
pxinwr32f5fdd2019-02-27 19:09:28 +0800567 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200568 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800569 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200570 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200571 try:
572 if ret >> 8 == 0:
573 with open(tmpfile) as fp:
574 for line in fp.readlines():
575 if line.startswith("gcc version"):
576 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800577 elif line.startswith("clang version"):
578 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200579 elif line.startswith("#include <...>"):
580 in_incdirs = True
581 elif line.startswith("End of search list"):
582 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800583 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200584 for d in line.strip().split("=")[1].split(":"):
585 d = os.path.normpath(d)
586 if '/gcc/' not in d:
587 add_dir_to_list(self.compiler.library_dirs,
588 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800589 elif (is_gcc or is_clang) and in_incdirs and '/gcc/' not in line and '/clang/' not in line:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200590 add_dir_to_list(self.compiler.include_dirs,
591 line.strip())
592 finally:
593 os.unlink(tmpfile)
594
Victor Stinner5ec33a12019-03-01 16:43:28 +0100595 def add_compiler_directories(self):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000596 # Ensure that /usr/local is always used, but the local build
597 # directories (i.e. '.' and 'Include') must be first. See issue
598 # 10520.
Victor Stinner4cbea512019-02-28 17:48:38 +0100599 if not CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200600 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
601 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
doko@ubuntu.comcc5addd2012-07-01 00:23:51 +0200602 # only change this for cross builds for 3.3, issues on Mageia
Victor Stinner4cbea512019-02-28 17:48:38 +0100603 if CROSS_COMPILING:
pxinwr32f5fdd2019-02-27 19:09:28 +0800604 self.add_cross_compiling_paths()
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400605 self.add_multiarch_paths()
Michael W. Hudson39230b32002-01-16 15:26:48 +0000606
Brett Cannon516592f2004-12-07 00:42:59 +0000607 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000608 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000609 # We must get the values from the Makefile and not the environment
610 # directly since an inconsistently reproducible issue comes up where
611 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000612 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000613 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000614 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
615 ('LDFLAGS', '-L', self.compiler.library_dirs),
616 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000617 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000618 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800619 parser = argparse.ArgumentParser()
620 parser.add_argument(arg_name, dest="dirs", action="append")
621 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000622 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000623 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000624 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000625
Victor Stinner5ec33a12019-03-01 16:43:28 +0100626 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100627 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100628 os.path.normpath(sys.base_prefix) != '/usr' and
629 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000630 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
631 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
632 # building a framework with different architectures than
633 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000634 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000635 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000636 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000637 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000638
xdegaye77f51392017-11-25 17:25:30 +0100639 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
640 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000641 # lib_dirs and inc_dirs are used to search for files;
642 # if a file is found in one of those directories, it can
643 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100644 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100645 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
646 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100647 else:
xdegaye77f51392017-11-25 17:25:30 +0100648 # Add the sysroot paths. 'sysroot' is a compiler option used to
649 # set the logical path of the standard system headers and
650 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100651 self.lib_dirs = (self.compiler.library_dirs +
652 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
653 self.inc_dirs = (self.compiler.include_dirs +
654 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
655 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000656
Brett Cannon4454a1f2005-04-15 20:32:39 +0000657 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000658 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100659 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000660
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000661 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100662 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100663 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000664
Charles-François Natali5739e102012-04-12 19:07:25 +0200665 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100666 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100667 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200668
Victor Stinner4cbea512019-02-28 17:48:38 +0100669 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000670 # This should work on any unixy platform ;-)
671 # If the user has bothered specifying additional -I and -L flags
672 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000673 #
674 # NOTE: using shlex.split would technically be more correct, but
675 # also gives a bootstrap problem. Let's hope nobody uses
676 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000677 cflags, ldflags = sysconfig.get_config_vars(
678 'CFLAGS', 'LDFLAGS')
679 for item in cflags.split():
680 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100681 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000682
683 for item in ldflags.split():
684 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100685 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000686
Victor Stinner5ec33a12019-03-01 16:43:28 +0100687 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000688 #
689 # The following modules are all pretty straightforward, and compile
690 # on pretty much any POSIXish platform.
691 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000692
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000693 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100694 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000695
Yury Selivanovf23746a2018-01-22 19:11:18 -0500696 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100697 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500698
Martin Panterc9deece2016-02-03 05:19:44 +0000699 shared_math = 'Modules/_math.o'
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000700 # complex math library functions
Victor Stinner8058bda2019-03-01 15:31:45 +0100701 self.add(Extension('cmath', ['cmathmodule.c'],
702 extra_objects=[shared_math],
703 depends=['_math.h', shared_math],
704 libraries=['m']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000705 # math library functions, e.g. sin()
Victor Stinner8058bda2019-03-01 15:31:45 +0100706 self.add(Extension('math', ['mathmodule.c'],
707 extra_objects=[shared_math],
708 depends=['_math.h', shared_math],
709 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200710
711 # time libraries: librt may be needed for clock_gettime()
712 time_libs = []
713 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
714 if lib:
715 time_libs.append(lib)
716
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000717 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100718 self.add(Extension('time', ['timemodule.c'],
719 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800720 # libm is needed by delta_new() that uses round() and by accum() that
721 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100722 self.add(Extension('_datetime', ['_datetimemodule.c'],
723 libraries=['m']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000724 # random number generator implemented in C
Victor Stinner8058bda2019-03-01 15:31:45 +0100725 self.add(Extension("_random", ["_randommodule.c"]))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000726 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100727 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000728 # heapq
Victor Stinner8058bda2019-03-01 15:31:45 +0100729 self.add(Extension("_heapq", ["_heapqmodule.c"]))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000730 # C-optimized pickle replacement
Victor Stinner8058bda2019-03-01 15:31:45 +0100731 self.add(Extension("_pickle", ["_pickle.c"]))
Collin Winter670e6922007-03-21 02:57:17 +0000732 # atexit
Victor Stinner8058bda2019-03-01 15:31:45 +0100733 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10 +0000734 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100735 self.add(Extension("_json", ["_json.c"],
736 # pycore_accu.h requires Py_BUILD_CORE_BUILTIN
737 extra_compile_args=['-DPy_BUILD_CORE_BUILTIN']))
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000738 # Python C API test module
Victor Stinner8058bda2019-03-01 15:31:45 +0100739 self.add(Extension('_testcapi', ['_testcapimodule.c'],
740 depends=['testcapi_long.h']))
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100741 # Python PEP-3118 (buffer protocol) test module
Victor Stinner8058bda2019-03-01 15:31:45 +0100742 self.add(Extension('_testbuffer', ['_testbuffer.c']))
Andrew Svetlov6b2cbeb2012-12-14 17:04:59 +0200743 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
Victor Stinner8058bda2019-03-01 15:31:45 +0100744 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
Nick Coghland5cacbb2015-05-23 22:24:10 +1000745 # Test multi-phase extension module init (PEP 489)
Victor Stinner8058bda2019-03-01 15:31:45 +0100746 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
Fred Drake0e474a82007-10-11 18:01:43 +0000747 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100748 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000749 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100750 self.add(Extension('unicodedata', ['unicodedata.c'],
751 depends=['unicodedata_db.h', 'unicodename_db.h']))
Larry Hastings3a907972013-11-23 14:49:22 -0800752 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100753 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900754 # asyncio speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100755 self.add(Extension("_asyncio", ["_asynciomodule.c"]))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000756 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100757 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100758 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100759 self.add(Extension("_queue", ["_queuemodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000760
761 # Modules with some UNIX dependencies -- on by default:
762 # (If you have a really backward UNIX, select and socket may not be
763 # supported...)
764
765 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000766 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100767 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000768 # May be necessary on AIX for flock function
769 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100770 self.add(Extension('fcntl', ['fcntlmodule.c'],
771 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000772 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100773 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000774 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800775 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100776 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000777 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100778 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
779 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100780 self.add(Extension('spwd', ['spwdmodule.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000781 else:
Victor Stinner8058bda2019-03-01 15:31:45 +0100782 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000783
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000784 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100785 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000786
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000787 # Fred Drake's interface to the Python parser
Victor Stinner8058bda2019-03-01 15:31:45 +0100788 self.add(Extension('parser', ['parsermodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000789
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000790 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100791 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000792
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000793 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000794 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100795 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000796
Devin Jeanpierrec5bace22017-09-06 11:15:35 -0700797 # Fuzz tests.
Victor Stinner8058bda2019-03-01 15:31:45 +0100798 self.add(Extension('_xxtestfuzz',
799 ['_xxtestfuzz/_xxtestfuzz.c',
800 '_xxtestfuzz/fuzzer.c']))
Devin Jeanpierrec5bace22017-09-06 11:15:35 -0700801
Eric Snow7f8bfc92018-01-29 18:23:44 -0700802 # Python interface to subinterpreter C-API.
Victor Stinner8058bda2019-03-01 15:31:45 +0100803 self.add(Extension('_xxsubinterpreters',
804 ['_xxsubinterpretersmodule.c'],
805 define_macros=[('Py_BUILD_CORE', '')]))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700806
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000807 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000808 # Here ends the simple stuff. From here on, modules need certain
809 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000810 #
811
812 # Multimedia modules
813 # These don't work for 64-bit platforms!!!
814 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200815 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000816 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000817 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000818 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200819 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800820 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100821 self.add(Extension('audioop', ['audioop.c'],
822 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000823
Victor Stinner5ec33a12019-03-01 16:43:28 +0100824 # CSV files
825 self.add(Extension('_csv', ['_csv.c']))
826
827 # POSIX subprocess module helper.
828 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
829
830 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000831 # readline
Victor Stinner625dbf22019-03-01 15:59:39 +0100832 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000833 readline_termcap_library = ""
834 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200835 # Cannot use os.popen here in py3k.
836 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
837 if not os.path.exists(self.build_temp):
838 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000839 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200840 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100841 if CROSS_COMPILING:
doko@ubuntu.com58844492012-06-30 18:25:32 +0200842 ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
843 % (sysconfig.get_config_var('READELF'),
844 do_readline, tmpfile))
845 elif find_executable('ldd'):
846 ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
847 else:
848 ret = 256
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200849 if ret >> 8 == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +0000850 with open(tmpfile) as fp:
851 for ln in fp:
852 if 'curses' in ln:
853 readline_termcap_library = re.sub(
854 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
855 ).rstrip()
856 break
857 # termcap interface split out from ncurses
858 if 'tinfo' in ln:
859 readline_termcap_library = 'tinfo'
860 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200861 if os.path.exists(tmpfile):
862 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +0000863 # Issue 7384: If readline is already linked against curses,
864 # use the same library for the readline and curses modules.
865 if 'curses' in readline_termcap_library:
866 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +0100867 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +0000868 curses_library = 'ncursesw'
Victor Stinner625dbf22019-03-01 15:59:39 +0100869 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000870 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100871 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000872 curses_library = 'curses'
873
Victor Stinner4cbea512019-02-28 17:48:38 +0100874 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000875 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +0000876 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -0700877 if (dep_target and
878 (tuple(int(n) for n in dep_target.split('.')[0:2])
879 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +0000880 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000881 if os_release < 9:
882 # MacOSX 10.4 has a broken readline. Don't try to build
883 # the readline module unless the user has installed a fixed
884 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +0100885 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000886 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +0000887 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100888 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000889 # In every directory on the search path search for a dynamic
890 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +0000891 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +0000892 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000893 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000894 readline_extra_link_args = ('-Wl,-search_paths_first',)
895 else:
896 readline_extra_link_args = ()
897
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000898 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +0000899 if readline_termcap_library:
900 pass # Issue 7384: Already linked against curses or tinfo.
901 elif curses_library:
902 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +0100903 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +0000904 ['/usr/lib/termcap'],
905 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000906 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +0100907 self.add(Extension('readline', ['readline.c'],
908 library_dirs=['/usr/lib/termcap'],
909 extra_link_args=readline_extra_link_args,
910 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000911 else:
Victor Stinner8058bda2019-03-01 15:31:45 +0100912 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000913
Victor Stinner5ec33a12019-03-01 16:43:28 +0100914 # Curses support, requiring the System V version of curses, often
915 # provided by the ncurses library.
916 curses_defines = []
917 curses_includes = []
918 panel_library = 'panel'
919 if curses_library == 'ncursesw':
920 curses_defines.append(('HAVE_NCURSESW', '1'))
921 if not CROSS_COMPILING:
922 curses_includes.append('/usr/include/ncursesw')
923 # Bug 1464056: If _curses.so links with ncursesw,
924 # _curses_panel.so must link with panelw.
925 panel_library = 'panelw'
926 if MACOS:
927 # On OS X, there is no separate /usr/lib/libncursesw nor
928 # libpanelw. If we are here, we found a locally-supplied
929 # version of libncursesw. There should also be a
930 # libpanelw. _XOPEN_SOURCE defines are usually excluded
931 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
932 # ncurses wide char support
933 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
934 elif MACOS and curses_library == 'ncurses':
935 # Building with the system-suppied combined libncurses/libpanel
936 curses_defines.append(('HAVE_NCURSESW', '1'))
937 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +0000938
Victor Stinner5ec33a12019-03-01 16:43:28 +0100939 if curses_library.startswith('ncurses'):
940 curses_libs = [curses_library]
941 self.add(Extension('_curses', ['_cursesmodule.c'],
942 include_dirs=curses_includes,
943 define_macros=curses_defines,
944 libraries=curses_libs))
945 elif curses_library == 'curses' and not MACOS:
946 # OSX has an old Berkeley curses, not good enough for
947 # the _curses module.
948 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
949 curses_libs = ['curses', 'terminfo']
950 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
951 curses_libs = ['curses', 'termcap']
952 else:
953 curses_libs = ['curses']
954
955 self.add(Extension('_curses', ['_cursesmodule.c'],
956 define_macros=curses_defines,
957 libraries=curses_libs))
958 else:
959 self.missing.append('_curses')
960
961 # If the curses module is enabled, check for the panel module
962 if (module_enabled(self.extensions, '_curses') and
963 self.compiler.find_library_file(self.lib_dirs, panel_library)):
964 self.add(Extension('_curses_panel', ['_curses_panel.c'],
965 include_dirs=curses_includes,
966 define_macros=curses_defines,
967 libraries=[panel_library, *curses_libs]))
968 else:
969 self.missing.append('_curses_panel')
970
971 def detect_crypt(self):
972 # crypt module.
Victor Stinner625dbf22019-03-01 15:59:39 +0100973 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +0000974 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +0000975 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +0000976 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +0800977
978 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100979 self.add(Extension('_crypt', ['_cryptmodule.c'],
980 libraries=libs))
Victor Stinner625dbf22019-03-01 15:59:39 +0100981 elif self.compiler.find_library_file(self.lib_dirs, 'OPENSSL'):
pxinwr32f5fdd2019-02-27 19:09:28 +0800982 libs = ['OPENSSL']
Victor Stinner8058bda2019-03-01 15:31:45 +0100983 self.add(Extension('_crypt', ['_cryptmodule.c'],
984 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000985
Victor Stinner5ec33a12019-03-01 16:43:28 +0100986 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000987 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +0800988 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100989 self.add(Extension('_socket', ['socketmodule.c'],
990 depends=['socketmodule.h']))
Victor Stinner625dbf22019-03-01 15:59:39 +0100991 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 19:09:28 +0800992 libs = ['net']
Victor Stinner8058bda2019-03-01 15:31:45 +0100993 self.add(Extension('_socket', ['socketmodule.c'],
994 depends=['socketmodule.h'],
995 libraries=libs))
pxinwr32f5fdd2019-02-27 19:09:28 +0800996
Victor Stinner5ec33a12019-03-01 16:43:28 +0100997 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +0000998 # Modules that provide persistent dictionary-like semantics. You will
999 # probably want to arrange for at least one of them to be available on
1000 # your machine, though none are defined by default because of library
1001 # dependencies. The Python module dbm/__init__.py provides an
1002 # implementation independent wrapper for these; dbm/dumb.py provides
1003 # similar functionality (but slower of course) implemented in Python.
1004
1005 # Sleepycat^WOracle Berkeley DB interface.
1006 # http://www.oracle.com/database/berkeley-db/db/index.html
1007 #
1008 # This requires the Sleepycat^WOracle DB code. The supported versions
1009 # are set below. Visit the URL above to download
1010 # a release. Most open source OSes come with one or more
1011 # versions of BerkeleyDB already installed.
1012
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001013 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001014 min_db_ver = (3, 3)
1015 db_setup_debug = False # verbose debug prints from this script?
1016
1017 def allow_db_ver(db_ver):
1018 """Returns a boolean if the given BerkeleyDB version is acceptable.
1019
1020 Args:
1021 db_ver: A tuple of the version to verify.
1022 """
1023 if not (min_db_ver <= db_ver <= max_db_ver):
1024 return False
1025 return True
1026
1027 def gen_db_minor_ver_nums(major):
1028 if major == 4:
1029 for x in range(max_db_ver[1]+1):
1030 if allow_db_ver((4, x)):
1031 yield x
1032 elif major == 3:
1033 for x in (3,):
1034 if allow_db_ver((3, x)):
1035 yield x
1036 else:
1037 raise ValueError("unknown major BerkeleyDB version", major)
1038
1039 # construct a list of paths to look for the header file in on
1040 # top of the normal inc_dirs.
1041 db_inc_paths = [
1042 '/usr/include/db4',
1043 '/usr/local/include/db4',
1044 '/opt/sfw/include/db4',
1045 '/usr/include/db3',
1046 '/usr/local/include/db3',
1047 '/opt/sfw/include/db3',
1048 # Fink defaults (http://fink.sourceforge.net/)
1049 '/sw/include/db4',
1050 '/sw/include/db3',
1051 ]
1052 # 4.x minor number specific paths
1053 for x in gen_db_minor_ver_nums(4):
1054 db_inc_paths.append('/usr/include/db4%d' % x)
1055 db_inc_paths.append('/usr/include/db4.%d' % x)
1056 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1057 db_inc_paths.append('/usr/local/include/db4%d' % x)
1058 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1059 db_inc_paths.append('/opt/db-4.%d/include' % x)
1060 # MacPorts default (http://www.macports.org/)
1061 db_inc_paths.append('/opt/local/include/db4%d' % x)
1062 # 3.x minor number specific paths
1063 for x in gen_db_minor_ver_nums(3):
1064 db_inc_paths.append('/usr/include/db3%d' % x)
1065 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1066 db_inc_paths.append('/usr/local/include/db3%d' % x)
1067 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1068 db_inc_paths.append('/opt/db-3.%d/include' % x)
1069
Victor Stinner4cbea512019-02-28 17:48:38 +01001070 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001071 db_inc_paths = []
1072
Georg Brandl489cb4f2009-07-11 10:08:49 +00001073 # Add some common subdirectories for Sleepycat DB to the list,
1074 # based on the standard include directories. This way DB3/4 gets
1075 # picked up when it is installed in a non-standard prefix and
1076 # the user has added that prefix into inc_dirs.
1077 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001078 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001079 std_variants.append(os.path.join(dn, 'db3'))
1080 std_variants.append(os.path.join(dn, 'db4'))
1081 for x in gen_db_minor_ver_nums(4):
1082 std_variants.append(os.path.join(dn, "db4%d"%x))
1083 std_variants.append(os.path.join(dn, "db4.%d"%x))
1084 for x in gen_db_minor_ver_nums(3):
1085 std_variants.append(os.path.join(dn, "db3%d"%x))
1086 std_variants.append(os.path.join(dn, "db3.%d"%x))
1087
1088 db_inc_paths = std_variants + db_inc_paths
1089 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1090
1091 db_ver_inc_map = {}
1092
Victor Stinner4cbea512019-02-28 17:48:38 +01001093 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001094 sysroot = macosx_sdk_root()
1095
Georg Brandl489cb4f2009-07-11 10:08:49 +00001096 class db_found(Exception): pass
1097 try:
1098 # See whether there is a Sleepycat header in the standard
1099 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001100 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001101 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001102 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001103 f = os.path.join(sysroot, d[1:], "db.h")
1104
Georg Brandl489cb4f2009-07-11 10:08:49 +00001105 if db_setup_debug: print("db: looking for db.h in", f)
1106 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001107 with open(f, 'rb') as file:
1108 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001109 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001110 if m:
1111 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001112 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001113 db_minor = int(m.group(1))
1114 db_ver = (db_major, db_minor)
1115
1116 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1117 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001118 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001119 db_patch = int(m.group(1))
1120 if db_patch < 21:
1121 print("db.h:", db_ver, "patch", db_patch,
1122 "being ignored (4.6.x must be >= 4.6.21)")
1123 continue
1124
1125 if ( (db_ver not in db_ver_inc_map) and
1126 allow_db_ver(db_ver) ):
1127 # save the include directory with the db.h version
1128 # (first occurrence only)
1129 db_ver_inc_map[db_ver] = d
1130 if db_setup_debug:
1131 print("db.h: found", db_ver, "in", d)
1132 else:
1133 # we already found a header for this library version
1134 if db_setup_debug: print("db.h: ignoring", d)
1135 else:
1136 # ignore this header, it didn't contain a version number
1137 if db_setup_debug:
1138 print("db.h: no version number version in", d)
1139
1140 db_found_vers = list(db_ver_inc_map.keys())
1141 db_found_vers.sort()
1142
1143 while db_found_vers:
1144 db_ver = db_found_vers.pop()
1145 db_incdir = db_ver_inc_map[db_ver]
1146
1147 # check lib directories parallel to the location of the header
1148 db_dirs_to_check = [
1149 db_incdir.replace("include", 'lib64'),
1150 db_incdir.replace("include", 'lib'),
1151 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001152
Victor Stinner4cbea512019-02-28 17:48:38 +01001153 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001154 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1155
1156 else:
1157 # Same as other branch, but takes OSX SDK into account
1158 tmp = []
1159 for dn in db_dirs_to_check:
1160 if is_macosx_sdk_path(dn):
1161 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1162 tmp.append(dn)
1163 else:
1164 if os.path.isdir(dn):
1165 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001166 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001167
1168 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001169
Ezio Melotti42da6632011-03-15 05:18:48 +02001170 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001171 # XXX should we -ever- look for a dbX name? Do any
1172 # systems really not name their library by version and
1173 # symlink to more general names?
1174 for dblib in (('db-%d.%d' % db_ver),
1175 ('db%d%d' % db_ver),
1176 ('db%d' % db_ver[0])):
1177 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001178 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001179 if dblib_file:
1180 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1181 raise db_found
1182 else:
1183 if db_setup_debug: print("db lib: ", dblib, "not found")
1184
1185 except db_found:
1186 if db_setup_debug:
1187 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1188 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001189 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001190 # Only add the found library and include directories if they aren't
1191 # already being searched. This avoids an explicit runtime library
1192 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001193 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001194 db_incs = None
1195 else:
1196 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001197 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001198 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001199 else:
1200 if db_setup_debug: print("db: no appropriate library found")
1201 db_incs = None
1202 dblibs = []
1203 dblib_dir = None
1204
Victor Stinner5ec33a12019-03-01 16:43:28 +01001205 dbm_setup_debug = False # verbose debug prints from this script?
1206 dbm_order = ['gdbm']
1207 # The standard Unix dbm module:
1208 if not CYGWIN:
1209 config_args = [arg.strip("'")
1210 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1211 dbm_args = [arg for arg in config_args
1212 if arg.startswith('--with-dbmliborder=')]
1213 if dbm_args:
1214 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1215 else:
1216 dbm_order = "ndbm:gdbm:bdb".split(":")
1217 dbmext = None
1218 for cand in dbm_order:
1219 if cand == "ndbm":
1220 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1221 # Some systems have -lndbm, others have -lgdbm_compat,
1222 # others don't have either
1223 if self.compiler.find_library_file(self.lib_dirs,
1224 'ndbm'):
1225 ndbm_libs = ['ndbm']
1226 elif self.compiler.find_library_file(self.lib_dirs,
1227 'gdbm_compat'):
1228 ndbm_libs = ['gdbm_compat']
1229 else:
1230 ndbm_libs = []
1231 if dbm_setup_debug: print("building dbm using ndbm")
1232 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1233 define_macros=[
1234 ('HAVE_NDBM_H',None),
1235 ],
1236 libraries=ndbm_libs)
1237 break
1238
1239 elif cand == "gdbm":
1240 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1241 gdbm_libs = ['gdbm']
1242 if self.compiler.find_library_file(self.lib_dirs,
1243 'gdbm_compat'):
1244 gdbm_libs.append('gdbm_compat')
1245 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1246 if dbm_setup_debug: print("building dbm using gdbm")
1247 dbmext = Extension(
1248 '_dbm', ['_dbmmodule.c'],
1249 define_macros=[
1250 ('HAVE_GDBM_NDBM_H', None),
1251 ],
1252 libraries = gdbm_libs)
1253 break
1254 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1255 if dbm_setup_debug: print("building dbm using gdbm")
1256 dbmext = Extension(
1257 '_dbm', ['_dbmmodule.c'],
1258 define_macros=[
1259 ('HAVE_GDBM_DASH_NDBM_H', None),
1260 ],
1261 libraries = gdbm_libs)
1262 break
1263 elif cand == "bdb":
1264 if dblibs:
1265 if dbm_setup_debug: print("building dbm using bdb")
1266 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1267 library_dirs=dblib_dir,
1268 runtime_library_dirs=dblib_dir,
1269 include_dirs=db_incs,
1270 define_macros=[
1271 ('HAVE_BERKDB_H', None),
1272 ('DB_DBM_HSEARCH', None),
1273 ],
1274 libraries=dblibs)
1275 break
1276 if dbmext is not None:
1277 self.add(dbmext)
1278 else:
1279 self.missing.append('_dbm')
1280
1281 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1282 if ('gdbm' in dbm_order and
1283 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1284 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1285 libraries=['gdbm']))
1286 else:
1287 self.missing.append('_gdbm')
1288
1289 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001290 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001291 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001292
1293 # We hunt for #define SQLITE_VERSION "n.n.n"
1294 # We need to find >= sqlite version 3.0.8
1295 sqlite_incdir = sqlite_libdir = None
1296 sqlite_inc_paths = [ '/usr/include',
1297 '/usr/include/sqlite',
1298 '/usr/include/sqlite3',
1299 '/usr/local/include',
1300 '/usr/local/include/sqlite',
1301 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001302 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001303 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001304 sqlite_inc_paths = []
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001305 MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
1306 MIN_SQLITE_VERSION = ".".join([str(x)
1307 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001308
1309 # Scan the default include directories before the SQLite specific
1310 # ones. This allows one to override the copy of sqlite on OSX,
1311 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001312 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001313 sysroot = macosx_sdk_root()
1314
Victor Stinner625dbf22019-03-01 15:59:39 +01001315 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001316 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001317 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001318 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001319
Ned Deily9b635832012-08-05 15:13:33 -07001320 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001321 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001322 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001323 with open(f) as file:
1324 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001325 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001326 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001327 if m:
1328 sqlite_version = m.group(1)
1329 sqlite_version_tuple = tuple([int(x)
1330 for x in sqlite_version.split(".")])
1331 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1332 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001333 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001334 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001335 sqlite_incdir = d
1336 break
1337 else:
1338 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001339 print("%s: version %d is too old, need >= %s"%(d,
1340 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001341 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001342 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001343
1344 if sqlite_incdir:
1345 sqlite_dirs_to_check = [
1346 os.path.join(sqlite_incdir, '..', 'lib64'),
1347 os.path.join(sqlite_incdir, '..', 'lib'),
1348 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1349 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1350 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001351 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001352 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001353 if sqlite_libfile:
1354 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001355
1356 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001357 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001358 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001359 '_sqlite/cursor.c',
1360 '_sqlite/microprotocols.c',
1361 '_sqlite/module.c',
1362 '_sqlite/prepare_protocol.c',
1363 '_sqlite/row.c',
1364 '_sqlite/statement.c',
1365 '_sqlite/util.c', ]
1366
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001367 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001368 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001369 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1370 else:
1371 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1372
Benjamin Peterson076ed002010-10-31 17:11:02 +00001373 # Enable support for loadable extensions in the sqlite3 module
1374 # if --enable-loadable-sqlite-extensions configure option is used.
1375 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1376 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001377
Victor Stinner4cbea512019-02-28 17:48:38 +01001378 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001379 # In every directory on the search path search for a dynamic
1380 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001381 # for dynamic libraries on the entire path.
1382 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001383 # before the dynamic library in /usr/lib.
1384 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1385 else:
1386 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001387
Brett Cannonc5011fe2011-06-06 20:09:10 -07001388 include_dirs = ["Modules/_sqlite"]
1389 # Only include the directory where sqlite was found if it does
1390 # not already exist in set include directories, otherwise you
1391 # can end up with a bad search path order.
1392 if sqlite_incdir not in self.compiler.include_dirs:
1393 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001394 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001395 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001396 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001397 self.add(Extension('_sqlite3', sqlite_srcs,
1398 define_macros=sqlite_defines,
1399 include_dirs=include_dirs,
1400 library_dirs=sqlite_libdir,
1401 extra_link_args=sqlite_extra_link_args,
1402 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001403 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001404 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001405
Victor Stinner5ec33a12019-03-01 16:43:28 +01001406 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001407 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001408 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001409 if not VXWORKS:
1410 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001411 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001412 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001413 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001414 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001415 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001416
Victor Stinner5ec33a12019-03-01 16:43:28 +01001417 # Platform-specific libraries
1418 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1419 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001420 else:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001421 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001422
Victor Stinner5ec33a12019-03-01 16:43:28 +01001423 if MACOS:
1424 self.add(Extension('_scproxy', ['_scproxy.c'],
1425 extra_link_args=[
1426 '-framework', 'SystemConfiguration',
1427 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001428
Victor Stinner5ec33a12019-03-01 16:43:28 +01001429 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001430 # Andrew Kuchling's zlib module. Note that some versions of zlib
1431 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1432 # http://www.cert.org/advisories/CA-2002-07.html
1433 #
1434 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1435 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1436 # now, we still accept 1.1.3, because we think it's difficult to
1437 # exploit this in Python, and we'd rather make it RedHat's problem
1438 # than our problem <wink>.
1439 #
1440 # You can upgrade zlib to version 1.1.4 yourself by going to
1441 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001442 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001443 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001444 if zlib_inc is not None:
1445 zlib_h = zlib_inc[0] + '/zlib.h'
1446 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001447 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001448 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001449 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001450 with open(zlib_h) as fp:
1451 while 1:
1452 line = fp.readline()
1453 if not line:
1454 break
1455 if line.startswith('#define ZLIB_VERSION'):
1456 version = line.split()[2]
1457 break
Guido van Rossume6970912001-04-15 15:16:12 +00001458 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001459 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001460 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001461 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1462 else:
1463 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001464 self.add(Extension('zlib', ['zlibmodule.c'],
1465 libraries=['z'],
1466 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001467 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001468 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001469 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001470 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001471 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001472 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001473 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001474
Christian Heimes1dc54002008-03-24 02:19:29 +00001475 # Helper module for various ascii-encoders. Uses zlib for an optimized
1476 # crc32 if we have it. Otherwise binascii uses its own.
1477 if have_zlib:
1478 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1479 libraries = ['z']
1480 extra_link_args = zlib_extra_link_args
1481 else:
1482 extra_compile_args = []
1483 libraries = []
1484 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001485 self.add(Extension('binascii', ['binascii.c'],
1486 extra_compile_args=extra_compile_args,
1487 libraries=libraries,
1488 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001489
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001490 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001491 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001492 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001493 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1494 else:
1495 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001496 self.add(Extension('_bz2', ['_bz2module.c'],
1497 libraries=['bz2'],
1498 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001499 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001500 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001501
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001502 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001503 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001504 self.add(Extension('_lzma', ['_lzmamodule.c'],
1505 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001506 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001507 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001508
Victor Stinner5ec33a12019-03-01 16:43:28 +01001509 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001510 # Interface to the Expat XML parser
1511 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001512 # Expat was written by James Clark and is now maintained by a group of
1513 # developers on SourceForge; see www.libexpat.org for more information.
1514 # The pyexpat module was written by Paul Prescod after a prototype by
1515 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1516 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001517 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001518 #
1519 # More information on Expat can be found at www.libexpat.org.
1520 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001521 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1522 expat_inc = []
1523 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001524 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001525 expat_lib = ['expat']
1526 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001527 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001528 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001529 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001530 define_macros = [
1531 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001532 # bpo-30947: Python uses best available entropy sources to
1533 # call XML_SetHashSalt(), expat entropy sources are not needed
1534 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001535 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001536 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001537 expat_lib = []
1538 expat_sources = ['expat/xmlparse.c',
1539 'expat/xmlrole.c',
1540 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001541 expat_depends = ['expat/ascii.h',
1542 'expat/asciitab.h',
1543 'expat/expat.h',
1544 'expat/expat_config.h',
1545 'expat/expat_external.h',
1546 'expat/internal.h',
1547 'expat/latin1tab.h',
1548 'expat/utf8tab.h',
1549 'expat/xmlrole.h',
1550 'expat/xmltok.h',
1551 'expat/xmltok_impl.h'
1552 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001553
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001554 cc = sysconfig.get_config_var('CC').split()[0]
1555 ret = os.system(
1556 '"%s" -Werror -Wimplicit-fallthrough -E -xc /dev/null >/dev/null 2>&1' % cc)
1557 if ret >> 8 == 0:
1558 extra_compile_args.append('-Wno-implicit-fallthrough')
1559
Victor Stinner8058bda2019-03-01 15:31:45 +01001560 self.add(Extension('pyexpat',
1561 define_macros=define_macros,
1562 extra_compile_args=extra_compile_args,
1563 include_dirs=expat_inc,
1564 libraries=expat_lib,
1565 sources=['pyexpat.c'] + expat_sources,
1566 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001567
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001568 # Fredrik Lundh's cElementTree module. Note that this also
1569 # uses expat (via the CAPI hook in pyexpat).
1570
Victor Stinner625dbf22019-03-01 15:59:39 +01001571 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001572 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001573 self.add(Extension('_elementtree',
1574 define_macros=define_macros,
1575 include_dirs=expat_inc,
1576 libraries=expat_lib,
1577 sources=['_elementtree.c'],
1578 depends=['pyexpat.c', *expat_sources,
1579 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001580 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001581 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001582
Victor Stinner5ec33a12019-03-01 16:43:28 +01001583 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001584 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001585 self.add(Extension('_multibytecodec',
1586 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001587 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001588 self.add(Extension('_codecs_%s' % loc,
1589 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001590
Victor Stinner5ec33a12019-03-01 16:43:28 +01001591 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001592 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001593 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001594 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1595 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001596
1597 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001598 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001599 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1600 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001601 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001602 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1603 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 17:19:04 +01001604 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-01 22:52:23 -06001605 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001606 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1607 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001608 libs.append('rt')
Victor Stinner8058bda2019-03-01 15:31:45 +01001609 self.add(Extension('_posixshmem', posixshmem_srcs,
1610 define_macros={},
1611 libraries=libs,
1612 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001613
Victor Stinner8058bda2019-03-01 15:31:45 +01001614 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001615 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001616
Victor Stinner5ec33a12019-03-01 16:43:28 +01001617 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001618 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001619 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001620 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001621 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001622 uuid_libs = ['uuid']
1623 else:
1624 uuid_libs = []
Antoine Pitroua106aec2017-09-28 23:03:06 +02001625 self.extensions.append(Extension('_uuid', ['_uuidmodule.c'],
1626 libraries=uuid_libs,
1627 include_dirs=uuid_incs))
1628 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001629 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001630
Victor Stinner5ec33a12019-03-01 16:43:28 +01001631 def detect_modules(self):
1632 self.add_compiler_directories()
1633 self.init_inc_lib_dirs()
1634
1635 self.detect_simple_extensions()
1636 self.detect_readline_curses()
1637 self.detect_crypt()
1638 self.detect_socket()
1639 self.detect_openssl_hashlib()
1640 self.detect_dbm_gdbm()
1641 self.detect_sqlite()
1642 self.detect_platform_specific_exts()
1643 self.detect_nis()
1644 self.detect_compress_exts()
1645 self.detect_expat_elementtree()
1646 self.detect_multibytecodecs()
1647 self.detect_decimal()
1648 self.detect_ctypes()
1649 self.detect_multiprocessing()
1650 if not self.detect_tkinter():
1651 self.missing.append('_tkinter')
1652 self.detect_uuid()
1653
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001654## # Uncomment these lines if you want to play with xxmodule.c
1655## ext = Extension('xx', ['xxmodule.c'])
1656## self.extensions.append(ext)
1657
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001658 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001659 ext = Extension('xxlimited', ['xxlimited.c'],
Benjamin Peterson24ac8772015-06-03 00:04:46 -05001660 define_macros=[('Py_LIMITED_API', '0x03050000')])
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001661 self.extensions.append(ext)
1662
Ned Deilyd819b932013-09-06 01:07:05 -07001663 def detect_tkinter_explicitly(self):
1664 # Build _tkinter using explicit locations for Tcl/Tk.
1665 #
1666 # This is enabled when both arguments are given to ./configure:
1667 #
1668 # --with-tcltk-includes="-I/path/to/tclincludes \
1669 # -I/path/to/tkincludes"
1670 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1671 # -L/path/to/tklibs -ltkm.n"
1672 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001673 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001674 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1675 #
1676 # This can be useful for building and testing tkinter with multiple
1677 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1678 # build of Tcl so you need to specify both arguments and use care when
1679 # overriding.
1680
1681 # The _TCLTK variables are created in the Makefile sharedmods target.
1682 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1683 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1684 if not (tcltk_includes and tcltk_libs):
1685 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001686 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001687
1688 extra_compile_args = tcltk_includes.split()
1689 extra_link_args = tcltk_libs.split()
1690 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1691 define_macros=[('WITH_APPINIT', 1)],
1692 extra_compile_args = extra_compile_args,
1693 extra_link_args = extra_link_args,
1694 )
1695 self.extensions.append(ext)
Victor Stinner4cbea512019-02-28 17:48:38 +01001696 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001697
Victor Stinner625dbf22019-03-01 15:59:39 +01001698 def detect_tkinter_darwin(self):
Jack Jansen0b06be72002-06-21 14:48:38 +00001699 # The _tkinter module, using frameworks. Since frameworks are quite
1700 # different the UNIX search logic is not sharable.
1701 from os.path import join, exists
1702 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001703 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:48 +00001704 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:38 +00001705 join(os.getenv('HOME'), '/Library/Frameworks')
1706 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001707
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001708 sysroot = macosx_sdk_root()
1709
Skip Montanaro0174ddd2005-12-30 05:01:26 +00001710 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:38 +00001711 # bundles.
1712 # XXX distutils should support -F!
1713 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001714 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001715
1716
Jack Jansen0b06be72002-06-21 14:48:38 +00001717 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001718 if is_macosx_sdk_path(F):
1719 if not exists(join(sysroot, F[1:], fw + '.framework')):
1720 break
1721 else:
1722 if not exists(join(F, fw + '.framework')):
1723 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001724 else:
1725 # ok, F is now directory with both frameworks. Continure
1726 # building
1727 break
1728 else:
1729 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1730 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001731 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001732
Jack Jansen0b06be72002-06-21 14:48:38 +00001733 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1734 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:43 +00001735 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:38 +00001736 #
1737 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001738 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001739 for fw in ('Tcl', 'Tk')
1740 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:38 +00001741 ]
1742
Tim Peters2c60f7a2003-01-29 03:49:43 +00001743 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:38 +00001744 # complicated search, this is a hard-coded path. It could bail out
1745 # if X11 libs are not found...
1746 include_dirs.append('/usr/X11R6/include')
1747 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1748
Georg Brandlfcaf9102008-07-16 02:17:56 +00001749 # All existing framework builds of Tcl/Tk don't support 64-bit
1750 # architectures.
1751 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001752 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001753
Ronald Oussorend097efe2009-09-15 19:07:58 +00001754 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1755 if not os.path.exists(self.build_temp):
1756 os.makedirs(self.build_temp)
1757
1758 # Note: cannot use os.popen or subprocess here, that
1759 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001760 if is_macosx_sdk_path(F):
1761 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1762 else:
1763 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001764
Brett Cannon9f5db072010-10-29 20:19:27 +00001765 with open(tmpfile) as fp:
1766 detected_archs = []
1767 for ln in fp:
1768 a = ln.split()[-1]
1769 if a in archs:
1770 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001771 os.unlink(tmpfile)
1772
1773 for a in detected_archs:
1774 frameworks.append('-arch')
1775 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001776
Jack Jansen0b06be72002-06-21 14:48:38 +00001777 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1778 define_macros=[('WITH_APPINIT', 1)],
1779 include_dirs = include_dirs,
1780 libraries = [],
Georg Brandlfcaf9102008-07-16 02:17:56 +00001781 extra_compile_args = frameworks[2:],
Jack Jansen0b06be72002-06-21 14:48:38 +00001782 extra_link_args = frameworks,
1783 )
1784 self.extensions.append(ext)
Victor Stinner4cbea512019-02-28 17:48:38 +01001785 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001786
Victor Stinner625dbf22019-03-01 15:59:39 +01001787 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001788 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001789
Ned Deilyd819b932013-09-06 01:07:05 -07001790 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1791 # configured or passed into the make target. If so, use these values
1792 # to build tkinter and bypass the searches for Tcl and TK in standard
1793 # locations.
1794 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 16:43:28 +01001795 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001796
Jack Jansen0b06be72002-06-21 14:48:38 +00001797 # Rather than complicate the code below, detecting and building
1798 # AquaTk is a separate method. Only one Tkinter will be built on
1799 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01001800 if (MACOS and self.detect_tkinter_darwin()):
1801 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001802
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001803 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001804 # The versions with dots are used on Unix, and the versions without
1805 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001806 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00001807 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1808 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01001809 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001810 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01001811 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001812 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00001813 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001814 # Exit the loop when we've found the Tcl/Tk libraries
1815 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001816
Fredrik Lundhade711a2001-01-24 08:00:28 +00001817 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001818 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001819 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001820 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001821 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01001822 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001823 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1824 # but the include subdirs are named like .../include/tcl8.3.
1825 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1826 tcl_include_sub = []
1827 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001828 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001829 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1830 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1831 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01001832 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
1833 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001834
Martin v. Löwise86a59a2003-05-03 08:45:51 +00001835 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001836 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001837 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01001838 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00001839
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001840 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001841
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001842 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
1843 for dir in tcl_includes + tk_includes:
1844 if dir not in include_dirs:
1845 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001846
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001847 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01001848 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001849 include_dirs.append('/usr/openwin/include')
1850 added_lib_dirs.append('/usr/openwin/lib')
1851 elif os.path.exists('/usr/X11R6/include'):
1852 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00001853 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001854 added_lib_dirs.append('/usr/X11R6/lib')
1855 elif os.path.exists('/usr/X11R5/include'):
1856 include_dirs.append('/usr/X11R5/include')
1857 added_lib_dirs.append('/usr/X11R5/lib')
1858 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001859 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001860 include_dirs.append('/usr/X11/include')
1861 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001862
Jason Tishler9181c942003-02-05 15:16:17 +00001863 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01001864 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00001865 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1866 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001867 return False
Jason Tishler9181c942003-02-05 15:16:17 +00001868
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001869 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01001870 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001871 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001872 defs.append( ('WITH_BLT', 1) )
1873 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01001874 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001875 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00001876 defs.append( ('WITH_BLT', 1) )
1877 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001878
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001879 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00001880 libs.append('tk'+ version)
1881 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001882
Victor Stinner4cbea512019-02-28 17:48:38 +01001883 if HOST_PLATFORM in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001884 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001885
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001886 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01001887 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001888 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001889
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001890 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001891 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001892 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001893 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001894 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001895 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001896 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001897
Victor Stinner5ec33a12019-03-01 16:43:28 +01001898 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1899 define_macros=[('WITH_APPINIT', 1)] + defs,
1900 include_dirs = include_dirs,
1901 libraries = libs,
1902 library_dirs = added_lib_dirs,
1903 )
1904 self.extensions.append(ext)
1905 return True
1906
Christian Heimes78644762008-03-04 23:39:23 +00001907 def configure_ctypes_darwin(self, ext):
1908 # Darwin (OS X) uses preconfigured files, in
1909 # the Modules/_ctypes/libffi_osx directory.
Victor Stinner625dbf22019-03-01 15:59:39 +01001910 ffi_srcdir = os.path.abspath(os.path.join(self.srcdir, 'Modules',
Christian Heimes78644762008-03-04 23:39:23 +00001911 '_ctypes', 'libffi_osx'))
1912 sources = [os.path.join(ffi_srcdir, p)
1913 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:56 +00001914 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:23 +00001915 'x86/x86-darwin.S',
1916 'x86/x86-ffi_darwin.c',
1917 'x86/x86-ffi64.c',
1918 'powerpc/ppc-darwin.S',
1919 'powerpc/ppc-darwin_closure.S',
1920 'powerpc/ppc-ffi_darwin.c',
1921 'powerpc/ppc64-darwin_closure.S',
1922 ]]
1923
1924 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:05 +00001925 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:23 +00001926
1927 include_dirs = [os.path.join(ffi_srcdir, 'include'),
1928 os.path.join(ffi_srcdir, 'powerpc')]
1929 ext.include_dirs.extend(include_dirs)
1930 ext.sources.extend(sources)
1931 return True
1932
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001933 def configure_ctypes(self, ext):
1934 if not self.use_system_libffi:
Victor Stinner4cbea512019-02-28 17:48:38 +01001935 if MACOS:
Christian Heimes78644762008-03-04 23:39:23 +00001936 return self.configure_ctypes_darwin(ext)
Zachary Waref40d4dd2016-09-17 01:25:24 -05001937 print('INFO: Could not locate ffi libs and/or headers')
1938 return False
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001939 return True
1940
Victor Stinner625dbf22019-03-01 15:59:39 +01001941 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001942 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001943 self.use_system_libffi = False
1944 include_dirs = []
1945 extra_compile_args = []
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001946 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00001947 sources = ['_ctypes/_ctypes.c',
1948 '_ctypes/callbacks.c',
1949 '_ctypes/callproc.c',
1950 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00001951 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00001952 depends = ['_ctypes/ctypes.h']
1953
Victor Stinner4cbea512019-02-28 17:48:38 +01001954 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00001955 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:58 +00001956 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:23 +00001957 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00001958 include_dirs.append('_ctypes/darwin')
Victor Stinner5ec33a12019-03-01 16:43:28 +01001959 # XXX Is this still needed?
1960 # extra_link_args.extend(['-read_only_relocs', 'warning'])
Thomas Hellercf567c12006-03-08 19:51:58 +00001961
Victor Stinner4cbea512019-02-28 17:48:38 +01001962 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001963 # XXX This shouldn't be necessary; it appears that some
1964 # of the assembler code is non-PIC (i.e. it has relocations
1965 # when it shouldn't. The proper fix would be to rewrite
1966 # the assembler code to be PIC.
1967 # This only works with GCC; the Sun compiler likely refuses
1968 # this option. If you want to compile ctypes with the Sun
1969 # compiler, please research a proper solution, instead of
1970 # finding some -z option for the Sun compiler.
1971 extra_link_args.append('-mimpure-text')
1972
Victor Stinner4cbea512019-02-28 17:48:38 +01001973 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00001974 extra_link_args.append('-fPIC')
1975
Thomas Hellercf567c12006-03-08 19:51:58 +00001976 ext = Extension('_ctypes',
1977 include_dirs=include_dirs,
1978 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001979 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001980 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00001981 sources=sources,
1982 depends=depends)
Benjamin Peterson8acaa312017-11-12 20:53:39 -08001983 # function my_sqrt() needs libm for sqrt()
Thomas Hellercf567c12006-03-08 19:51:58 +00001984 ext_test = Extension('_ctypes_test',
Victor Stinnerdef80722016-04-19 15:58:11 +02001985 sources=['_ctypes/_ctypes_test.c'],
Benjamin Peterson8acaa312017-11-12 20:53:39 -08001986 libraries=['m'])
Thomas Hellercf567c12006-03-08 19:51:58 +00001987 self.extensions.extend([ext, ext_test])
1988
Victor Stinner625dbf22019-03-01 15:59:39 +01001989 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01001990 if MACOS:
Zachary Ware935043d2016-09-09 17:01:21 -07001991 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
1992 return
Christian Heimes78644762008-03-04 23:39:23 +00001993 # OS X 10.5 comes with libffi.dylib; the include files are
1994 # in /usr/include/ffi
Victor Stinner96d81582019-03-01 13:53:46 +01001995 ffi_inc_dirs.append('/usr/include/ffi')
Christian Heimes78644762008-03-04 23:39:23 +00001996
Benjamin Petersond78735d2010-01-01 16:04:23 +00001997 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:45 +00001998 if not ffi_inc or ffi_inc[0] == '':
Victor Stinner96d81582019-03-01 13:53:46 +01001999 ffi_inc = find_file('ffi.h', [], ffi_inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002000 if ffi_inc is not None:
2001 ffi_h = ffi_inc[0] + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002002 if not os.path.exists(ffi_h):
2003 ffi_inc = None
2004 print('Header file {} does not exist'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002005 ffi_lib = None
2006 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002007 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002008 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002009 ffi_lib = lib_name
2010 break
2011
2012 if ffi_inc and ffi_lib:
2013 ext.include_dirs.extend(ffi_inc)
2014 ext.libraries.append(ffi_lib)
2015 self.use_system_libffi = True
2016
Christian Heimes5bb96922018-02-25 10:22:14 +01002017 if sysconfig.get_config_var('HAVE_LIBDL'):
2018 # for dlopen, see bpo-32647
2019 ext.libraries.append('dl')
2020
Victor Stinner5ec33a12019-03-01 16:43:28 +01002021 def detect_decimal(self):
2022 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002023 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002024 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002025 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2026 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002027 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002028 sources = ['_decimal/_decimal.c']
2029 depends = ['_decimal/docstrings.h']
2030 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002031 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002032 'Modules',
2033 '_decimal',
2034 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002035 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002036 sources = [
2037 '_decimal/_decimal.c',
2038 '_decimal/libmpdec/basearith.c',
2039 '_decimal/libmpdec/constants.c',
2040 '_decimal/libmpdec/context.c',
2041 '_decimal/libmpdec/convolute.c',
2042 '_decimal/libmpdec/crt.c',
2043 '_decimal/libmpdec/difradix2.c',
2044 '_decimal/libmpdec/fnt.c',
2045 '_decimal/libmpdec/fourstep.c',
2046 '_decimal/libmpdec/io.c',
2047 '_decimal/libmpdec/memory.c',
2048 '_decimal/libmpdec/mpdecimal.c',
2049 '_decimal/libmpdec/numbertheory.c',
2050 '_decimal/libmpdec/sixstep.c',
2051 '_decimal/libmpdec/transpose.c',
2052 ]
2053 depends = [
2054 '_decimal/docstrings.h',
2055 '_decimal/libmpdec/basearith.h',
2056 '_decimal/libmpdec/bits.h',
2057 '_decimal/libmpdec/constants.h',
2058 '_decimal/libmpdec/convolute.h',
2059 '_decimal/libmpdec/crt.h',
2060 '_decimal/libmpdec/difradix2.h',
2061 '_decimal/libmpdec/fnt.h',
2062 '_decimal/libmpdec/fourstep.h',
2063 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002064 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002065 '_decimal/libmpdec/mpdecimal.h',
2066 '_decimal/libmpdec/numbertheory.h',
2067 '_decimal/libmpdec/sixstep.h',
2068 '_decimal/libmpdec/transpose.h',
2069 '_decimal/libmpdec/typearith.h',
2070 '_decimal/libmpdec/umodarith.h',
2071 ]
2072
Stefan Krah1919b7e2012-03-21 18:25:23 +01002073 config = {
2074 'x64': [('CONFIG_64','1'), ('ASM','1')],
2075 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2076 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2077 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2078 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2079 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2080 ('LEGACY_COMPILER','1')],
2081 'universal': [('UNIVERSAL','1')]
2082 }
2083
Stefan Krah1919b7e2012-03-21 18:25:23 +01002084 cc = sysconfig.get_config_var('CC')
2085 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2086 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2087
2088 if machine:
2089 # Override automatic configuration to facilitate testing.
2090 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002091 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002092 # Universal here means: build with the same options Python
2093 # was built with.
2094 define_macros = config['universal']
2095 elif sizeof_size_t == 8:
2096 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2097 define_macros = config['x64']
2098 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2099 define_macros = config['uint128']
2100 else:
2101 define_macros = config['ansi64']
2102 elif sizeof_size_t == 4:
2103 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2104 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002105 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002106 # solaris: problems with register allocation.
2107 # icc >= 11.0 works as well.
2108 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002109 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002110 else:
2111 define_macros = config['ansi32']
2112 else:
2113 raise DistutilsError("_decimal: unsupported architecture")
2114
2115 # Workarounds for toolchain bugs:
2116 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2117 # Some versions of gcc miscompile inline asm:
2118 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2119 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2120 extra_compile_args.append('-fno-ipa-pure-const')
2121 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2122 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2123 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2124 undef_macros.append('_FORTIFY_SOURCE')
2125
Stefan Krah1919b7e2012-03-21 18:25:23 +01002126 # Uncomment for extra functionality:
2127 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002128 self.add(Extension('_decimal',
2129 include_dirs=include_dirs,
2130 libraries=libraries,
2131 define_macros=define_macros,
2132 undef_macros=undef_macros,
2133 extra_compile_args=extra_compile_args,
2134 sources=sources,
2135 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002136
Victor Stinner5ec33a12019-03-01 16:43:28 +01002137 def detect_openssl_hashlib(self):
2138 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002139 config_vars = sysconfig.get_config_vars()
2140
2141 def split_var(name, sep):
2142 # poor man's shlex, the re module is not available yet.
2143 value = config_vars.get(name)
2144 if not value:
2145 return ()
2146 # This trick works because ax_check_openssl uses --libs-only-L,
2147 # --libs-only-l, and --cflags-only-I.
2148 value = ' ' + value
2149 sep = ' ' + sep
2150 return [v.strip() for v in value.split(sep) if v.strip()]
2151
2152 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2153 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2154 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2155 if not openssl_libs:
2156 # libssl and libcrypto not found
2157 return None, None
2158
2159 # Find OpenSSL includes
2160 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002161 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002162 )
2163 if ssl_incs is None:
2164 return None, None
2165
2166 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2167 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002168 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002169 ['/usr/kerberos/include']
2170 )
2171 if krb5_h:
2172 ssl_incs.extend(krb5_h)
2173
Christian Heimes61d478c2018-01-27 15:51:38 +01002174 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Victor Stinner8058bda2019-03-01 15:31:45 +01002175 self.add(Extension('_ssl', ['_ssl.c'],
2176 include_dirs=openssl_includes,
2177 library_dirs=openssl_libdirs,
2178 libraries=openssl_libs,
2179 depends=['socketmodule.h']))
Christian Heimes61d478c2018-01-27 15:51:38 +01002180 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002181 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002182
Victor Stinner8058bda2019-03-01 15:31:45 +01002183 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2184 depends=['hashlib.h'],
2185 include_dirs=openssl_includes,
2186 library_dirs=openssl_libdirs,
2187 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002188
Victor Stinner5ec33a12019-03-01 16:43:28 +01002189 # We always compile these even when OpenSSL is available (issue #14693).
2190 # It's harmless and the object code is tiny (40-50 KiB per module,
2191 # only loaded when actually used).
2192 self.add(Extension('_sha256', ['sha256module.c'],
2193 depends=['hashlib.h']))
2194 self.add(Extension('_sha512', ['sha512module.c'],
2195 depends=['hashlib.h']))
2196 self.add(Extension('_md5', ['md5module.c'],
2197 depends=['hashlib.h']))
2198 self.add(Extension('_sha1', ['sha1module.c'],
2199 depends=['hashlib.h']))
2200
2201 blake2_deps = glob(os.path.join(self.srcdir,
2202 'Modules/_blake2/impl/*'))
2203 blake2_deps.append('hashlib.h')
2204
2205 self.add(Extension('_blake2',
2206 ['_blake2/blake2module.c',
2207 '_blake2/blake2b_impl.c',
2208 '_blake2/blake2s_impl.c'],
2209 depends=blake2_deps))
2210
2211 sha3_deps = glob(os.path.join(self.srcdir,
2212 'Modules/_sha3/kcp/*'))
2213 sha3_deps.append('hashlib.h')
2214 self.add(Extension('_sha3',
2215 ['_sha3/sha3module.c'],
2216 depends=sha3_deps))
2217
2218 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002219 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002220 self.missing.append('nis')
2221 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002222
2223 libs = []
2224 library_dirs = []
2225 includes_dirs = []
2226
2227 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2228 # moved headers and libraries to libtirpc and libnsl. The headers
2229 # are in tircp and nsl sub directories.
2230 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002231 'rpcsvc/yp_prot.h', self.inc_dirs,
2232 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002233 )
2234 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002235 'rpc/rpc.h', self.inc_dirs,
2236 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002237 )
2238 if rpcsvc_inc is None or rpc_inc is None:
2239 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002240 self.missing.append('nis')
2241 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002242 includes_dirs.extend(rpcsvc_inc)
2243 includes_dirs.extend(rpc_inc)
2244
Victor Stinner625dbf22019-03-01 15:59:39 +01002245 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002246 libs.append('nsl')
2247 else:
2248 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002249 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002250 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2251 if libnsl is not None:
2252 library_dirs.append(os.path.dirname(libnsl))
2253 libs.append('nsl')
2254
Victor Stinner625dbf22019-03-01 15:59:39 +01002255 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002256 libs.append('tirpc')
2257
Victor Stinner8058bda2019-03-01 15:31:45 +01002258 self.add(Extension('nis', ['nismodule.c'],
2259 libraries=libs,
2260 library_dirs=library_dirs,
2261 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002262
Christian Heimesff5be6e2018-01-20 13:19:21 +01002263
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002264class PyBuildInstall(install):
2265 # Suppress the warning about installation into the lib_dynload
2266 # directory, which is not in sys.path when running Python during
2267 # installation:
2268 def initialize_options (self):
2269 install.initialize_options(self)
2270 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002271
Éric Araujoe6792c12011-06-09 14:07:02 +02002272 # Customize subcommands to not install an egg-info file for Python
2273 sub_commands = [('install_lib', install.has_lib),
2274 ('install_headers', install.has_headers),
2275 ('install_scripts', install.has_scripts),
2276 ('install_data', install.has_data)]
2277
2278
Michael W. Hudson529a5052002-12-17 16:47:17 +00002279class PyBuildInstallLib(install_lib):
2280 # Do exactly what install_lib does but make sure correct access modes get
2281 # set on installed directories and files. All installed files with get
2282 # mode 644 unless they are a shared library in which case they will get
2283 # mode 755. All installed directories will get mode 755.
2284
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002285 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2286 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002287
2288 def install(self):
2289 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002290 self.set_file_modes(outfiles, 0o644, 0o755)
2291 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002292 return outfiles
2293
2294 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002295 if not files: return
2296
2297 for filename in files:
2298 if os.path.islink(filename): continue
2299 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002300 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002301 log.info("changing mode of %s to %o", filename, mode)
2302 if not self.dry_run: os.chmod(filename, mode)
2303
2304 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002305 for dirpath, dirnames, fnames in os.walk(dirname):
2306 if os.path.islink(dirpath):
2307 continue
2308 log.info("changing mode of %s to %o", dirpath, mode)
2309 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002310
Victor Stinnerc991f242019-03-01 17:19:04 +01002311
Georg Brandlff52f762010-12-28 09:51:43 +00002312class PyBuildScripts(build_scripts):
2313 def copy_scripts(self):
2314 outfiles, updated_files = build_scripts.copy_scripts(self)
2315 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2316 minoronly = '.{0[1]}'.format(sys.version_info)
2317 newoutfiles = []
2318 newupdated_files = []
2319 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002320 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002321 newfilename = filename + fullversion
2322 else:
2323 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002324 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002325 os.rename(filename, newfilename)
2326 newoutfiles.append(newfilename)
2327 if filename in updated_files:
2328 newupdated_files.append(newfilename)
2329 return newoutfiles, newupdated_files
2330
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002331
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002332def main():
Victor Stinnerc991f242019-03-01 17:19:04 +01002333 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2334 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2335
2336 class DummyProcess:
2337 """Hack for parallel build"""
2338 ProcessPoolExecutor = None
2339
2340 sys.modules['concurrent.futures.process'] = DummyProcess
2341
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002342 # turn off warnings when deprecated modules are imported
2343 import warnings
2344 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002345 setup(# PyPI Metadata (PEP 301)
2346 name = "Python",
2347 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002348 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002349 maintainer = "Guido van Rossum and the Python community",
2350 maintainer_email = "python-dev@python.org",
2351 description = "A high-level object-oriented programming language",
2352 long_description = SUMMARY.strip(),
2353 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002354 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002355 platforms = ["Many"],
2356
2357 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002358 cmdclass = {'build_ext': PyBuildExt,
2359 'build_scripts': PyBuildScripts,
2360 'install': PyBuildInstall,
2361 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002362 # The struct module is defined here, because build_ext won't be
2363 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002364 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002365
Georg Brandlff52f762010-12-28 09:51:43 +00002366 # If you change the scripts installed here, you also need to
2367 # check the PyBuildScripts command above, and change the links
2368 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002369 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002370 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002371 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002372
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002373# --install-platlib
2374if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002375 main()