blob: 51e67fe4a558b8ef29b5bbf59ac5e000cf527814 [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
Victor Stinnercfe172d2019-03-01 18:21:49 +010023# Compile extensions used to test Python?
24TEST_EXTENSIONS = True
25
26# This global variable is used to hold the list of modules to be disabled.
27DISABLED_MODULE_LIST = []
28
29
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020030def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010031 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020032 if "_PYTHON_HOST_PLATFORM" in os.environ:
33 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010034
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020035 # Get value of sys.platform
36 if sys.platform.startswith('osf1'):
37 return 'osf1'
38 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010039
40
41CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010042HOST_PLATFORM = get_platform()
43MS_WINDOWS = (HOST_PLATFORM == 'win32')
44CYGWIN = (HOST_PLATFORM == 'cygwin')
45MACOS = (HOST_PLATFORM == 'darwin')
Michael Felt08970cb2019-06-21 15:58:00 +020046AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 17:48:38 +010047VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080048
Victor Stinnerc991f242019-03-01 17:19:04 +010049
50SUMMARY = """
51Python is an interpreted, interactive, object-oriented programming
52language. It is often compared to Tcl, Perl, Scheme or Java.
53
54Python combines remarkable power with very clear syntax. It has
55modules, classes, exceptions, very high level dynamic data types, and
56dynamic typing. There are interfaces to many system calls and
57libraries, as well as to various windowing systems (X11, Motif, Tk,
58Mac, MFC). New built-in modules are easily written in C or C++. Python
59is also usable as an extension language for applications that need a
60programmable interface.
61
62The Python implementation is portable: it runs on many brands of UNIX,
63on Windows, DOS, Mac, Amiga... If your favorite system isn't
64listed here, it may still be supported, if there's a C compiler for
65it. Ask around on comp.lang.python -- or just try compiling Python
66yourself.
67"""
68
69CLASSIFIERS = """
70Development Status :: 6 - Mature
71License :: OSI Approved :: Python Software Foundation License
72Natural Language :: English
73Programming Language :: C
74Programming Language :: Python
75Topic :: Software Development
76"""
77
78
79# Set common compiler and linker flags derived from the Makefile,
80# reserved for building the interpreter and the stdlib modules.
81# See bpo-21121 and bpo-35257
82def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
83 flags = sysconfig.get_config_var(compiler_flags)
84 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
85 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
86
87
Michael W. Hudson39230b32002-01-16 15:26:48 +000088def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +000089 """Add the directory 'dir' to the list 'dirlist' (after any relative
90 directories) if:
91
Michael W. Hudson39230b32002-01-16 15:26:48 +000092 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +000093 2) 'dir' actually exists, and is a directory.
94 """
95 if dir is None or not os.path.isdir(dir) or dir in dirlist:
96 return
97 for i, path in enumerate(dirlist):
98 if not os.path.isabs(path):
99 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000100 return
101 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000102
Victor Stinnerc991f242019-03-01 17:19:04 +0100103
xdegaye77f51392017-11-25 17:25:30 +0100104def sysroot_paths(make_vars, subdirs):
105 """Get the paths of sysroot sub-directories.
106
107 * make_vars: a sequence of names of variables of the Makefile where
108 sysroot may be set.
109 * subdirs: a sequence of names of subdirectories used as the location for
110 headers or libraries.
111 """
112
113 dirs = []
114 for var_name in make_vars:
115 var = sysconfig.get_config_var(var_name)
116 if var is not None:
117 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
118 if m is not None:
119 sysroot = m.group(1).strip('"')
120 for subdir in subdirs:
121 if os.path.isabs(subdir):
122 subdir = subdir[1:]
123 path = os.path.join(sysroot, subdir)
124 if os.path.isdir(path):
125 dirs.append(path)
126 break
127 return dirs
128
Ned Deily0288dd62019-06-03 06:34:48 -0400129MACOS_SDK_ROOT = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100130
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000131def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400132 """Return the directory of the current macOS SDK.
133
134 If no SDK was explicitly configured, call the compiler to find which
135 include files paths are being searched by default. Use '/' if the
136 compiler is searching /usr/include (meaning system header files are
137 installed) or use the root of an SDK if that is being searched.
138 (The SDK may be supplied via Xcode or via the Command Line Tools).
139 The SDK paths used by Apple-supplied tool chains depend on the
140 setting of various variables; see the xcrun man page for more info.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000141 """
Ned Deily0288dd62019-06-03 06:34:48 -0400142 global MACOS_SDK_ROOT
143
144 # If already called, return cached result.
145 if MACOS_SDK_ROOT:
146 return MACOS_SDK_ROOT
147
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000148 cflags = sysconfig.get_config_var('CFLAGS')
149 m = re.search(r'-isysroot\s+(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400150 if m is not None:
151 MACOS_SDK_ROOT = m.group(1)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000152 else:
Ned Deily0288dd62019-06-03 06:34:48 -0400153 MACOS_SDK_ROOT = '/'
154 cc = sysconfig.get_config_var('CC')
155 tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid()
156 try:
157 os.unlink(tmpfile)
158 except:
159 pass
160 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
161 in_incdirs = False
162 try:
163 if ret >> 8 == 0:
164 with open(tmpfile) as fp:
165 for line in fp.readlines():
166 if line.startswith("#include <...>"):
167 in_incdirs = True
168 elif line.startswith("End of search list"):
169 in_incdirs = False
170 elif in_incdirs:
171 line = line.strip()
172 if line == '/usr/include':
173 MACOS_SDK_ROOT = '/'
174 elif line.endswith(".sdk/usr/include"):
175 MACOS_SDK_ROOT = line[:-12]
176 finally:
177 os.unlink(tmpfile)
178
179 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000180
Victor Stinnerc991f242019-03-01 17:19:04 +0100181
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000182def is_macosx_sdk_path(path):
183 """
184 Returns True if 'path' can be located in an OSX SDK
185 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700186 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
187 or path.startswith('/System/')
188 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000189
Victor Stinnerc991f242019-03-01 17:19:04 +0100190
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000191def find_file(filename, std_dirs, paths):
192 """Searches for the directory where a given file is located,
193 and returns a possibly-empty list of additional directories, or None
194 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000195
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000196 'filename' is the name of a file, such as readline.h or libcrypto.a.
197 'std_dirs' is the list of standard system directories; if the
198 file is found in one of them, no additional directives are needed.
199 'paths' is a list of additional locations to check; if the file is
200 found in one of them, the resulting list will contain the directory.
201 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100202 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000203 # Honor the MacOSX SDK setting when one was specified.
204 # An SDK is a directory with the same structure as a real
205 # system, but with only header files and libraries.
206 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000207
208 # Check the standard locations
209 for dir in std_dirs:
210 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000211
Victor Stinner4cbea512019-02-28 17:48:38 +0100212 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000213 f = os.path.join(sysroot, dir[1:], filename)
214
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000215 if os.path.exists(f): return []
216
217 # Check the additional directories
218 for dir in paths:
219 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000220
Victor Stinner4cbea512019-02-28 17:48:38 +0100221 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000222 f = os.path.join(sysroot, dir[1:], filename)
223
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000224 if os.path.exists(f):
225 return [dir]
226
227 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000228 return None
229
Victor Stinnerc991f242019-03-01 17:19:04 +0100230
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000231def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000232 result = compiler.find_library_file(std_dirs + paths, libname)
233 if result is None:
234 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000235
Victor Stinner4cbea512019-02-28 17:48:38 +0100236 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000237 sysroot = macosx_sdk_root()
238
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000239 # Check whether the found file is in one of the standard directories
240 dirname = os.path.dirname(result)
241 for p in std_dirs:
242 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000243 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000244
Victor Stinner4cbea512019-02-28 17:48:38 +0100245 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100246 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
247 # libraries with .tbd extensions rather than the normal .dylib
248 # shared libraries installed in /. The Apple compiler tool
249 # chain handles this transparently but it can cause problems
250 # for programs that are being built with an SDK and searching
251 # for specific libraries. Distutils find_library_file() now
252 # knows to also search for and return .tbd files. But callers
253 # of find_library_file need to keep in mind that the base filename
254 # of the returned SDK library file might have a different extension
255 # from that of the library file installed on the running system,
256 # for example:
257 # /Applications/Xcode.app/Contents/Developer/Platforms/
258 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
259 # usr/lib/libedit.tbd
260 # vs
261 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000262 if os.path.join(sysroot, p[1:]) == dirname:
263 return [ ]
264
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000265 if p == dirname:
266 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000267
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000268 # Otherwise, it must have been in one of the additional directories,
269 # so we have to figure out which one.
270 for p in paths:
271 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000272 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000273
Victor Stinner4cbea512019-02-28 17:48:38 +0100274 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000275 if os.path.join(sysroot, p[1:]) == dirname:
276 return [ p ]
277
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000278 if p == dirname:
279 return [p]
280 else:
281 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000282
Victor Stinnerc991f242019-03-01 17:19:04 +0100283
Jack Jansen144ebcc2001-08-05 22:31:19 +0000284def find_module_file(module, dirlist):
285 """Find a module in a set of possible folders. If it is not found
286 return the unadorned filename"""
287 list = find_file(module, [], dirlist)
288 if not list:
289 return module
290 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100291 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000292 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000293
Victor Stinnerc991f242019-03-01 17:19:04 +0100294
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000295class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000296
Guido van Rossumd8faa362007-04-27 19:54:29 +0000297 def __init__(self, dist):
298 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100299 self.srcdir = None
300 self.lib_dirs = None
301 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100302 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000303 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400304 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100305 self.missing = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200306 if '-j' in os.environ.get('MAKEFLAGS', ''):
307 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000308
Victor Stinner8058bda2019-03-01 15:31:45 +0100309 def add(self, ext):
310 self.extensions.append(ext)
311
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000312 def build_extensions(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100313 self.srcdir = sysconfig.get_config_var('srcdir')
314 if not self.srcdir:
315 # Maybe running on Windows but not using CYGWIN?
316 raise ValueError("No source directory; cannot proceed.")
317 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000318
319 # Detect which modules should be compiled
Victor Stinner8058bda2019-03-01 15:31:45 +0100320 self.detect_modules()
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000321
322 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000323 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100324 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000325 # move ctypes to the end, it depends on other modules
326 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
327 if "_ctypes" in ext_map:
328 ctypes = extensions.pop(ext_map["_ctypes"])
329 extensions.append(ctypes)
330 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000331
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000332 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000333 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100334 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000335
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000336 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100337 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000338 for filename in self.distribution.scripts]
339
Christian Heimesaf98da12008-01-27 15:18:18 +0000340 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000341 headers = [sysconfig.get_config_h_filename()]
Stefan Kraheb977da2012-02-29 14:10:53 +0100342 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000343
xdegayec0364fc2017-05-27 18:25:03 +0200344 # The sysconfig variables built by makesetup that list the already
345 # built modules and the disabled modules as configured by the Setup
346 # files.
347 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
348 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200349
xdegayec0364fc2017-05-27 18:25:03 +0200350 mods_built = []
351 mods_disabled = []
Xavier de Gaye84968b72016-10-29 16:57:20 +0200352 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000353 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000354 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000355 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000356 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000357 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000358 else:
359 ext.depends = []
360 # re-compile extensions if a header file has been changed
361 ext.depends.extend(headers)
362
xdegayec0364fc2017-05-27 18:25:03 +0200363 # If a module has already been built or has been disabled in the
364 # Setup files, don't build it here.
365 if ext.name in sysconf_built:
366 mods_built.append(ext)
367 if ext.name in sysconf_dis:
368 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000369
xdegayec0364fc2017-05-27 18:25:03 +0200370 mods_configured = mods_built + mods_disabled
371 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200372 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200373 mods_configured]
374 # Remove the shared libraries built by a previous build.
375 for ext in mods_configured:
376 fullpath = self.get_ext_fullpath(ext.name)
377 if os.path.exists(fullpath):
378 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000379
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000380 # When you run "make CC=altcc" or something similar, you really want
381 # those environment variables passed into the setup.py phase. Here's
382 # a small set of useful ones.
383 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000384 args = {}
385 # unfortunately, distutils doesn't let us provide separate C and C++
386 # compilers
387 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000388 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
389 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000390 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000391
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000392 build_ext.build_extensions(self)
393
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200394 for ext in self.extensions:
395 self.check_extension_import(ext)
396
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300397 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400398 if self.failed or self.failed_on_import:
399 all_failed = self.failed + self.failed_on_import
400 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000401
402 def print_three_column(lst):
403 lst.sort(key=str.lower)
404 # guarantee zip() doesn't drop anything
405 while len(lst) % 3:
406 lst.append("")
407 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
408 print("%-*s %-*s %-*s" % (longest, e, longest, f,
409 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000410
Victor Stinner8058bda2019-03-01 15:31:45 +0100411 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000412 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400413 print("Python build finished successfully!")
414 print("The necessary bits to build these optional modules were not "
415 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100416 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000417 print("To find the necessary bits, look in setup.py in"
418 " detect_modules() for the module's name.")
419 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000420
xdegayec0364fc2017-05-27 18:25:03 +0200421 if mods_built:
422 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200423 print("The following modules found by detect_modules() in"
424 " setup.py, have been")
425 print("built by the Makefile instead, as configured by the"
426 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200427 print_three_column([ext.name for ext in mods_built])
428 print()
429
430 if mods_disabled:
431 print()
432 print("The following modules found by detect_modules() in"
433 " setup.py have not")
434 print("been built, they are *disabled* in the Setup files:")
435 print_three_column([ext.name for ext in mods_disabled])
436 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200437
Guido van Rossumd8faa362007-04-27 19:54:29 +0000438 if self.failed:
439 failed = self.failed[:]
440 print()
441 print("Failed to build these modules:")
442 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000443 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000444
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400445 if self.failed_on_import:
446 failed = self.failed_on_import[:]
447 print()
448 print("Following modules built successfully"
449 " but were removed because they could not be imported:")
450 print_three_column(failed)
451 print()
452
Christian Heimes61d478c2018-01-27 15:51:38 +0100453 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100454 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100455 print()
456 print("Could not build the ssl module!")
457 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
458 "libssl with X509_VERIFY_PARAM_set1_host().")
459 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
460 "APIs, https://github.com/libressl-portable/portable/issues/381")
461 print()
462
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000463 def build_extension(self, ext):
464
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000465 if ext.name == '_ctypes':
466 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500467 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000468 return
469
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000470 try:
471 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000472 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000473 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100474 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000475 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000476 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200477
478 def check_extension_import(self, ext):
479 # Don't try to import an extension that has failed to compile
480 if ext.name in self.failed:
481 self.announce(
482 'WARNING: skipping import check for failed build "%s"' %
483 ext.name, level=1)
484 return
485
Jack Jansenf49c6f92001-11-01 14:44:15 +0000486 # Workaround for Mac OS X: The Carbon-based modules cannot be
487 # reliably imported into a command-line Python
488 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000489 self.announce(
490 'WARNING: skipping import check for Carbon-based "%s"' %
491 ext.name)
492 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000493
Victor Stinner4cbea512019-02-28 17:48:38 +0100494 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000495 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000496 # Don't bother doing an import check when an extension was
497 # build with an explicit '-arch' flag on OSX. That's currently
498 # only used to build 32-bit only extensions in a 4-way
499 # universal build and loading 32-bit code into a 64-bit
500 # process will fail.
501 self.announce(
502 'WARNING: skipping import check for "%s"' %
503 ext.name)
504 return
505
Jason Tishler24cf7762002-05-22 16:46:15 +0000506 # Workaround for Cygwin: Cygwin currently has fork issues when many
507 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100508 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000509 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
510 % ext.name)
511 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000512 ext_filename = os.path.join(
513 self.build_lib,
514 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000515
516 # If the build directory didn't exist when setup.py was
517 # started, sys.path_importer_cache has a negative result
518 # cached. Clear that cache before trying to import.
519 sys.path_importer_cache.clear()
520
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200521 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100522 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200523 return
524
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400525 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700526 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
527 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000528 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400529 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000530 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400531 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000532 self.announce('*** WARNING: renaming "%s" since importing it'
533 ' failed: %s' % (ext.name, why), level=3)
534 assert not self.inplace
535 basename, tail = os.path.splitext(ext_filename)
536 newname = basename + "_failed" + tail
537 if os.path.exists(newname):
538 os.remove(newname)
539 os.rename(ext_filename, newname)
540
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000541 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000542 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000543 self.announce('*** WARNING: importing extension "%s" '
544 'failed with %s: %s' % (ext.name, exc_type, why),
545 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000546 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000547
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400548 def add_multiarch_paths(self):
549 # Debian/Ubuntu multiarch support.
550 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200551 cc = sysconfig.get_config_var('CC')
552 tmpfile = os.path.join(self.build_temp, 'multiarch')
553 if not os.path.exists(self.build_temp):
554 os.makedirs(self.build_temp)
555 ret = os.system(
556 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
557 multiarch_path_component = ''
558 try:
559 if ret >> 8 == 0:
560 with open(tmpfile) as fp:
561 multiarch_path_component = fp.readline().strip()
562 finally:
563 os.unlink(tmpfile)
564
565 if multiarch_path_component != '':
566 add_dir_to_list(self.compiler.library_dirs,
567 '/usr/lib/' + multiarch_path_component)
568 add_dir_to_list(self.compiler.include_dirs,
569 '/usr/include/' + multiarch_path_component)
570 return
571
Barry Warsaw88e19452011-04-07 10:40:36 -0400572 if not find_executable('dpkg-architecture'):
573 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200574 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100575 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200576 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400577 tmpfile = os.path.join(self.build_temp, 'multiarch')
578 if not os.path.exists(self.build_temp):
579 os.makedirs(self.build_temp)
580 ret = os.system(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200581 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
582 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400583 try:
584 if ret >> 8 == 0:
585 with open(tmpfile) as fp:
586 multiarch_path_component = fp.readline().strip()
587 add_dir_to_list(self.compiler.library_dirs,
588 '/usr/lib/' + multiarch_path_component)
589 add_dir_to_list(self.compiler.include_dirs,
590 '/usr/include/' + multiarch_path_component)
591 finally:
592 os.unlink(tmpfile)
593
pxinwr32f5fdd2019-02-27 19:09:28 +0800594 def add_cross_compiling_paths(self):
595 cc = sysconfig.get_config_var('CC')
596 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200597 if not os.path.exists(self.build_temp):
598 os.makedirs(self.build_temp)
pxinwr32f5fdd2019-02-27 19:09:28 +0800599 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200600 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800601 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200602 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200603 try:
604 if ret >> 8 == 0:
605 with open(tmpfile) as fp:
606 for line in fp.readlines():
607 if line.startswith("gcc version"):
608 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800609 elif line.startswith("clang version"):
610 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200611 elif line.startswith("#include <...>"):
612 in_incdirs = True
613 elif line.startswith("End of search list"):
614 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800615 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200616 for d in line.strip().split("=")[1].split(":"):
617 d = os.path.normpath(d)
618 if '/gcc/' not in d:
619 add_dir_to_list(self.compiler.library_dirs,
620 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800621 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 +0200622 add_dir_to_list(self.compiler.include_dirs,
623 line.strip())
624 finally:
625 os.unlink(tmpfile)
626
Victor Stinnercfe172d2019-03-01 18:21:49 +0100627 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000628 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000629 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000630 # We must get the values from the Makefile and not the environment
631 # directly since an inconsistently reproducible issue comes up where
632 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000633 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000634 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000635 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
636 ('LDFLAGS', '-L', self.compiler.library_dirs),
637 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000638 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000639 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800640 parser = argparse.ArgumentParser()
641 parser.add_argument(arg_name, dest="dirs", action="append")
642 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000643 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000644 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000645 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000646
Victor Stinnercfe172d2019-03-01 18:21:49 +0100647 def configure_compiler(self):
648 # Ensure that /usr/local is always used, but the local build
649 # directories (i.e. '.' and 'Include') must be first. See issue
650 # 10520.
651 if not CROSS_COMPILING:
652 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
653 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
654 # only change this for cross builds for 3.3, issues on Mageia
655 if CROSS_COMPILING:
656 self.add_cross_compiling_paths()
657 self.add_multiarch_paths()
658 self.add_ldflags_cppflags()
659
Victor Stinner5ec33a12019-03-01 16:43:28 +0100660 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100661 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100662 os.path.normpath(sys.base_prefix) != '/usr' and
663 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000664 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
665 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
666 # building a framework with different architectures than
667 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000668 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000669 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000670 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000671 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000672
xdegaye77f51392017-11-25 17:25:30 +0100673 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
674 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000675 # lib_dirs and inc_dirs are used to search for files;
676 # if a file is found in one of those directories, it can
677 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100678 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100679 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
680 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100681 else:
xdegaye77f51392017-11-25 17:25:30 +0100682 # Add the sysroot paths. 'sysroot' is a compiler option used to
683 # set the logical path of the standard system headers and
684 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100685 self.lib_dirs = (self.compiler.library_dirs +
686 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
687 self.inc_dirs = (self.compiler.include_dirs +
688 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
689 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000690
Brett Cannon4454a1f2005-04-15 20:32:39 +0000691 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000692 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100693 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000694
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000695 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100696 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100697 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000698
Charles-François Natali5739e102012-04-12 19:07:25 +0200699 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100700 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100701 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200702
Victor Stinner4cbea512019-02-28 17:48:38 +0100703 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000704 # This should work on any unixy platform ;-)
705 # If the user has bothered specifying additional -I and -L flags
706 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000707 #
708 # NOTE: using shlex.split would technically be more correct, but
709 # also gives a bootstrap problem. Let's hope nobody uses
710 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000711 cflags, ldflags = sysconfig.get_config_vars(
712 'CFLAGS', 'LDFLAGS')
713 for item in cflags.split():
714 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100715 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000716
717 for item in ldflags.split():
718 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100719 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000720
Victor Stinner5ec33a12019-03-01 16:43:28 +0100721 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000722 #
723 # The following modules are all pretty straightforward, and compile
724 # on pretty much any POSIXish platform.
725 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000726
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000727 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100728 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000729
Yury Selivanovf23746a2018-01-22 19:11:18 -0500730 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100731 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500732
Martin Panterc9deece2016-02-03 05:19:44 +0000733 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100734
735 # math library functions, e.g. sin()
736 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100737 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100738 extra_objects=[shared_math],
739 depends=['_math.h', shared_math],
740 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100741
742 # complex math library functions
743 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100744 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100745 extra_objects=[shared_math],
746 depends=['_math.h', shared_math],
747 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200748
749 # time libraries: librt may be needed for clock_gettime()
750 time_libs = []
751 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
752 if lib:
753 time_libs.append(lib)
754
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000755 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100756 self.add(Extension('time', ['timemodule.c'],
757 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800758 # libm is needed by delta_new() that uses round() and by accum() that
759 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100760 self.add(Extension('_datetime', ['_datetimemodule.c'],
761 libraries=['m']))
Christian Heimesfe337bf2008-03-23 21:54:12 +0000762 # random number generator implemented in C
Victor Stinner8058bda2019-03-01 15:31:45 +0100763 self.add(Extension("_random", ["_randommodule.c"]))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000764 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100765 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000766 # heapq
Victor Stinner8058bda2019-03-01 15:31:45 +0100767 self.add(Extension("_heapq", ["_heapqmodule.c"]))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000768 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200769 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200770 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Collin Winter670e6922007-03-21 02:57:17 +0000771 # atexit
Victor Stinner8058bda2019-03-01 15:31:45 +0100772 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10 +0000773 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100774 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200775 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100776
Fred Drake0e474a82007-10-11 18:01:43 +0000777 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100778 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000779 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100780 self.add(Extension('unicodedata', ['unicodedata.c'],
781 depends=['unicodedata_db.h', 'unicodename_db.h']))
Larry Hastings3a907972013-11-23 14:49:22 -0800782 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100783 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900784 # asyncio speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100785 self.add(Extension("_asyncio", ["_asynciomodule.c"]))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000786 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100787 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100788 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100789 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900790 # _statistics module
791 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000792
793 # Modules with some UNIX dependencies -- on by default:
794 # (If you have a really backward UNIX, select and socket may not be
795 # supported...)
796
797 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000798 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100799 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000800 # May be necessary on AIX for flock function
801 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100802 self.add(Extension('fcntl', ['fcntlmodule.c'],
803 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000804 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100805 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000806 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800807 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100808 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000809 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100810 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
811 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100812 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200813 # AIX has shadow passwords, but access is not via getspent(), etc.
814 # module support is not expected so it not 'missing'
815 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100816 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000817
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000818 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100819 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000820
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000821 # Fred Drake's interface to the Python parser
Victor Stinner8058bda2019-03-01 15:31:45 +0100822 self.add(Extension('parser', ['parsermodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000823
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000824 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100825 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000826
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000827 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000828 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100829 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000830
Eric Snow7f8bfc92018-01-29 18:23:44 -0700831 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600832 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700833
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000834 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000835 # Here ends the simple stuff. From here on, modules need certain
836 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000837 #
838
839 # Multimedia modules
840 # These don't work for 64-bit platforms!!!
841 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200842 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000843 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000844 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000845 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200846 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800847 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100848 self.add(Extension('audioop', ['audioop.c'],
849 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000850
Victor Stinner5ec33a12019-03-01 16:43:28 +0100851 # CSV files
852 self.add(Extension('_csv', ['_csv.c']))
853
854 # POSIX subprocess module helper.
855 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
856
Victor Stinnercfe172d2019-03-01 18:21:49 +0100857 def detect_test_extensions(self):
858 # Python C API test module
859 self.add(Extension('_testcapi', ['_testcapimodule.c'],
860 depends=['testcapi_long.h']))
861
Victor Stinner23bace22019-04-18 11:37:26 +0200862 # Python Internal C API test module
863 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +0200864 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +0200865
Victor Stinnercfe172d2019-03-01 18:21:49 +0100866 # Python PEP-3118 (buffer protocol) test module
867 self.add(Extension('_testbuffer', ['_testbuffer.c']))
868
869 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
870 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
871
872 # Test multi-phase extension module init (PEP 489)
873 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
874
875 # Fuzz tests.
876 self.add(Extension('_xxtestfuzz',
877 ['_xxtestfuzz/_xxtestfuzz.c',
878 '_xxtestfuzz/fuzzer.c']))
879
Victor Stinner5ec33a12019-03-01 16:43:28 +0100880 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000881 # readline
Victor Stinner625dbf22019-03-01 15:59:39 +0100882 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000883 readline_termcap_library = ""
884 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200885 # Cannot use os.popen here in py3k.
886 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
887 if not os.path.exists(self.build_temp):
888 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000889 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200890 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100891 if CROSS_COMPILING:
doko@ubuntu.com58844492012-06-30 18:25:32 +0200892 ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
893 % (sysconfig.get_config_var('READELF'),
894 do_readline, tmpfile))
895 elif find_executable('ldd'):
896 ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
897 else:
898 ret = 256
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200899 if ret >> 8 == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +0000900 with open(tmpfile) as fp:
901 for ln in fp:
902 if 'curses' in ln:
903 readline_termcap_library = re.sub(
904 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
905 ).rstrip()
906 break
907 # termcap interface split out from ncurses
908 if 'tinfo' in ln:
909 readline_termcap_library = 'tinfo'
910 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200911 if os.path.exists(tmpfile):
912 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +0000913 # Issue 7384: If readline is already linked against curses,
914 # use the same library for the readline and curses modules.
915 if 'curses' in readline_termcap_library:
916 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +0100917 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +0000918 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +0200919 # Issue 36210: OSS provided ncurses does not link on AIX
920 # Use IBM supplied 'curses' for successful build of _curses
921 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
922 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100923 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000924 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +0100925 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000926 curses_library = 'curses'
927
Victor Stinner4cbea512019-02-28 17:48:38 +0100928 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000929 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +0000930 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -0700931 if (dep_target and
932 (tuple(int(n) for n in dep_target.split('.')[0:2])
933 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +0000934 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000935 if os_release < 9:
936 # MacOSX 10.4 has a broken readline. Don't try to build
937 # the readline module unless the user has installed a fixed
938 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +0100939 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000940 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +0000941 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100942 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000943 # In every directory on the search path search for a dynamic
944 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +0000945 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +0000946 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000947 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000948 readline_extra_link_args = ('-Wl,-search_paths_first',)
949 else:
950 readline_extra_link_args = ()
951
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000952 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +0000953 if readline_termcap_library:
954 pass # Issue 7384: Already linked against curses or tinfo.
955 elif curses_library:
956 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +0100957 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +0000958 ['/usr/lib/termcap'],
959 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000960 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +0100961 self.add(Extension('readline', ['readline.c'],
962 library_dirs=['/usr/lib/termcap'],
963 extra_link_args=readline_extra_link_args,
964 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000965 else:
Victor Stinner8058bda2019-03-01 15:31:45 +0100966 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000967
Victor Stinner5ec33a12019-03-01 16:43:28 +0100968 # Curses support, requiring the System V version of curses, often
969 # provided by the ncurses library.
970 curses_defines = []
971 curses_includes = []
972 panel_library = 'panel'
973 if curses_library == 'ncursesw':
974 curses_defines.append(('HAVE_NCURSESW', '1'))
975 if not CROSS_COMPILING:
976 curses_includes.append('/usr/include/ncursesw')
977 # Bug 1464056: If _curses.so links with ncursesw,
978 # _curses_panel.so must link with panelw.
979 panel_library = 'panelw'
980 if MACOS:
981 # On OS X, there is no separate /usr/lib/libncursesw nor
982 # libpanelw. If we are here, we found a locally-supplied
983 # version of libncursesw. There should also be a
984 # libpanelw. _XOPEN_SOURCE defines are usually excluded
985 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
986 # ncurses wide char support
987 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
988 elif MACOS and curses_library == 'ncurses':
989 # Building with the system-suppied combined libncurses/libpanel
990 curses_defines.append(('HAVE_NCURSESW', '1'))
991 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +0000992
Victor Stinnercfe172d2019-03-01 18:21:49 +0100993 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +0100994 if curses_library.startswith('ncurses'):
995 curses_libs = [curses_library]
996 self.add(Extension('_curses', ['_cursesmodule.c'],
997 include_dirs=curses_includes,
998 define_macros=curses_defines,
999 libraries=curses_libs))
1000 elif curses_library == 'curses' and not MACOS:
1001 # OSX has an old Berkeley curses, not good enough for
1002 # the _curses module.
1003 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1004 curses_libs = ['curses', 'terminfo']
1005 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1006 curses_libs = ['curses', 'termcap']
1007 else:
1008 curses_libs = ['curses']
1009
1010 self.add(Extension('_curses', ['_cursesmodule.c'],
1011 define_macros=curses_defines,
1012 libraries=curses_libs))
1013 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001014 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001015 self.missing.append('_curses')
1016
1017 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001018 # _curses_panel needs some form of ncurses
1019 skip_curses_panel = True if AIX else False
1020 if (curses_enabled and not skip_curses_panel and
1021 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001022 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001023 include_dirs=curses_includes,
1024 define_macros=curses_defines,
1025 libraries=[panel_library, *curses_libs]))
1026 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001027 self.missing.append('_curses_panel')
1028
1029 def detect_crypt(self):
1030 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001031 if VXWORKS:
1032 # bpo-31904: crypt() function is not provided by VxWorks.
1033 # DES_crypt() OpenSSL provides is too weak to implement
1034 # the encryption.
1035 return
1036
Victor Stinner625dbf22019-03-01 15:59:39 +01001037 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001038 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001039 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001040 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001041
pxinwr236d0b72019-04-15 17:02:20 +08001042 self.add(Extension('_crypt', ['_cryptmodule.c'],
Victor Stinner8058bda2019-03-01 15:31:45 +01001043 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001044
Victor Stinner5ec33a12019-03-01 16:43:28 +01001045 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001046 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +08001047 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +01001048 self.add(Extension('_socket', ['socketmodule.c'],
1049 depends=['socketmodule.h']))
Victor Stinner625dbf22019-03-01 15:59:39 +01001050 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 19:09:28 +08001051 libs = ['net']
Victor Stinner8058bda2019-03-01 15:31:45 +01001052 self.add(Extension('_socket', ['socketmodule.c'],
1053 depends=['socketmodule.h'],
1054 libraries=libs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001055
Victor Stinner5ec33a12019-03-01 16:43:28 +01001056 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001057 # Modules that provide persistent dictionary-like semantics. You will
1058 # probably want to arrange for at least one of them to be available on
1059 # your machine, though none are defined by default because of library
1060 # dependencies. The Python module dbm/__init__.py provides an
1061 # implementation independent wrapper for these; dbm/dumb.py provides
1062 # similar functionality (but slower of course) implemented in Python.
1063
1064 # Sleepycat^WOracle Berkeley DB interface.
1065 # http://www.oracle.com/database/berkeley-db/db/index.html
1066 #
1067 # This requires the Sleepycat^WOracle DB code. The supported versions
1068 # are set below. Visit the URL above to download
1069 # a release. Most open source OSes come with one or more
1070 # versions of BerkeleyDB already installed.
1071
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001072 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001073 min_db_ver = (3, 3)
1074 db_setup_debug = False # verbose debug prints from this script?
1075
1076 def allow_db_ver(db_ver):
1077 """Returns a boolean if the given BerkeleyDB version is acceptable.
1078
1079 Args:
1080 db_ver: A tuple of the version to verify.
1081 """
1082 if not (min_db_ver <= db_ver <= max_db_ver):
1083 return False
1084 return True
1085
1086 def gen_db_minor_ver_nums(major):
1087 if major == 4:
1088 for x in range(max_db_ver[1]+1):
1089 if allow_db_ver((4, x)):
1090 yield x
1091 elif major == 3:
1092 for x in (3,):
1093 if allow_db_ver((3, x)):
1094 yield x
1095 else:
1096 raise ValueError("unknown major BerkeleyDB version", major)
1097
1098 # construct a list of paths to look for the header file in on
1099 # top of the normal inc_dirs.
1100 db_inc_paths = [
1101 '/usr/include/db4',
1102 '/usr/local/include/db4',
1103 '/opt/sfw/include/db4',
1104 '/usr/include/db3',
1105 '/usr/local/include/db3',
1106 '/opt/sfw/include/db3',
1107 # Fink defaults (http://fink.sourceforge.net/)
1108 '/sw/include/db4',
1109 '/sw/include/db3',
1110 ]
1111 # 4.x minor number specific paths
1112 for x in gen_db_minor_ver_nums(4):
1113 db_inc_paths.append('/usr/include/db4%d' % x)
1114 db_inc_paths.append('/usr/include/db4.%d' % x)
1115 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1116 db_inc_paths.append('/usr/local/include/db4%d' % x)
1117 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1118 db_inc_paths.append('/opt/db-4.%d/include' % x)
1119 # MacPorts default (http://www.macports.org/)
1120 db_inc_paths.append('/opt/local/include/db4%d' % x)
1121 # 3.x minor number specific paths
1122 for x in gen_db_minor_ver_nums(3):
1123 db_inc_paths.append('/usr/include/db3%d' % x)
1124 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1125 db_inc_paths.append('/usr/local/include/db3%d' % x)
1126 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1127 db_inc_paths.append('/opt/db-3.%d/include' % x)
1128
Victor Stinner4cbea512019-02-28 17:48:38 +01001129 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001130 db_inc_paths = []
1131
Georg Brandl489cb4f2009-07-11 10:08:49 +00001132 # Add some common subdirectories for Sleepycat DB to the list,
1133 # based on the standard include directories. This way DB3/4 gets
1134 # picked up when it is installed in a non-standard prefix and
1135 # the user has added that prefix into inc_dirs.
1136 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001137 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001138 std_variants.append(os.path.join(dn, 'db3'))
1139 std_variants.append(os.path.join(dn, 'db4'))
1140 for x in gen_db_minor_ver_nums(4):
1141 std_variants.append(os.path.join(dn, "db4%d"%x))
1142 std_variants.append(os.path.join(dn, "db4.%d"%x))
1143 for x in gen_db_minor_ver_nums(3):
1144 std_variants.append(os.path.join(dn, "db3%d"%x))
1145 std_variants.append(os.path.join(dn, "db3.%d"%x))
1146
1147 db_inc_paths = std_variants + db_inc_paths
1148 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1149
1150 db_ver_inc_map = {}
1151
Victor Stinner4cbea512019-02-28 17:48:38 +01001152 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001153 sysroot = macosx_sdk_root()
1154
Georg Brandl489cb4f2009-07-11 10:08:49 +00001155 class db_found(Exception): pass
1156 try:
1157 # See whether there is a Sleepycat header in the standard
1158 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001159 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001160 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001161 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001162 f = os.path.join(sysroot, d[1:], "db.h")
1163
Georg Brandl489cb4f2009-07-11 10:08:49 +00001164 if db_setup_debug: print("db: looking for db.h in", f)
1165 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001166 with open(f, 'rb') as file:
1167 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001168 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001169 if m:
1170 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001171 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001172 db_minor = int(m.group(1))
1173 db_ver = (db_major, db_minor)
1174
1175 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1176 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001177 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001178 db_patch = int(m.group(1))
1179 if db_patch < 21:
1180 print("db.h:", db_ver, "patch", db_patch,
1181 "being ignored (4.6.x must be >= 4.6.21)")
1182 continue
1183
1184 if ( (db_ver not in db_ver_inc_map) and
1185 allow_db_ver(db_ver) ):
1186 # save the include directory with the db.h version
1187 # (first occurrence only)
1188 db_ver_inc_map[db_ver] = d
1189 if db_setup_debug:
1190 print("db.h: found", db_ver, "in", d)
1191 else:
1192 # we already found a header for this library version
1193 if db_setup_debug: print("db.h: ignoring", d)
1194 else:
1195 # ignore this header, it didn't contain a version number
1196 if db_setup_debug:
1197 print("db.h: no version number version in", d)
1198
1199 db_found_vers = list(db_ver_inc_map.keys())
1200 db_found_vers.sort()
1201
1202 while db_found_vers:
1203 db_ver = db_found_vers.pop()
1204 db_incdir = db_ver_inc_map[db_ver]
1205
1206 # check lib directories parallel to the location of the header
1207 db_dirs_to_check = [
1208 db_incdir.replace("include", 'lib64'),
1209 db_incdir.replace("include", 'lib'),
1210 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001211
Victor Stinner4cbea512019-02-28 17:48:38 +01001212 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001213 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1214
1215 else:
1216 # Same as other branch, but takes OSX SDK into account
1217 tmp = []
1218 for dn in db_dirs_to_check:
1219 if is_macosx_sdk_path(dn):
1220 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1221 tmp.append(dn)
1222 else:
1223 if os.path.isdir(dn):
1224 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001225 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001226
1227 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001228
Ezio Melotti42da6632011-03-15 05:18:48 +02001229 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001230 # XXX should we -ever- look for a dbX name? Do any
1231 # systems really not name their library by version and
1232 # symlink to more general names?
1233 for dblib in (('db-%d.%d' % db_ver),
1234 ('db%d%d' % db_ver),
1235 ('db%d' % db_ver[0])):
1236 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001237 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001238 if dblib_file:
1239 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1240 raise db_found
1241 else:
1242 if db_setup_debug: print("db lib: ", dblib, "not found")
1243
1244 except db_found:
1245 if db_setup_debug:
1246 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1247 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001248 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001249 # Only add the found library and include directories if they aren't
1250 # already being searched. This avoids an explicit runtime library
1251 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001252 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001253 db_incs = None
1254 else:
1255 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001256 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001257 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001258 else:
1259 if db_setup_debug: print("db: no appropriate library found")
1260 db_incs = None
1261 dblibs = []
1262 dblib_dir = None
1263
Victor Stinner5ec33a12019-03-01 16:43:28 +01001264 dbm_setup_debug = False # verbose debug prints from this script?
1265 dbm_order = ['gdbm']
1266 # The standard Unix dbm module:
1267 if not CYGWIN:
1268 config_args = [arg.strip("'")
1269 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1270 dbm_args = [arg for arg in config_args
1271 if arg.startswith('--with-dbmliborder=')]
1272 if dbm_args:
1273 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1274 else:
1275 dbm_order = "ndbm:gdbm:bdb".split(":")
1276 dbmext = None
1277 for cand in dbm_order:
1278 if cand == "ndbm":
1279 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1280 # Some systems have -lndbm, others have -lgdbm_compat,
1281 # others don't have either
1282 if self.compiler.find_library_file(self.lib_dirs,
1283 'ndbm'):
1284 ndbm_libs = ['ndbm']
1285 elif self.compiler.find_library_file(self.lib_dirs,
1286 'gdbm_compat'):
1287 ndbm_libs = ['gdbm_compat']
1288 else:
1289 ndbm_libs = []
1290 if dbm_setup_debug: print("building dbm using ndbm")
1291 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1292 define_macros=[
1293 ('HAVE_NDBM_H',None),
1294 ],
1295 libraries=ndbm_libs)
1296 break
1297
1298 elif cand == "gdbm":
1299 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1300 gdbm_libs = ['gdbm']
1301 if self.compiler.find_library_file(self.lib_dirs,
1302 'gdbm_compat'):
1303 gdbm_libs.append('gdbm_compat')
1304 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1305 if dbm_setup_debug: print("building dbm using gdbm")
1306 dbmext = Extension(
1307 '_dbm', ['_dbmmodule.c'],
1308 define_macros=[
1309 ('HAVE_GDBM_NDBM_H', None),
1310 ],
1311 libraries = gdbm_libs)
1312 break
1313 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1314 if dbm_setup_debug: print("building dbm using gdbm")
1315 dbmext = Extension(
1316 '_dbm', ['_dbmmodule.c'],
1317 define_macros=[
1318 ('HAVE_GDBM_DASH_NDBM_H', None),
1319 ],
1320 libraries = gdbm_libs)
1321 break
1322 elif cand == "bdb":
1323 if dblibs:
1324 if dbm_setup_debug: print("building dbm using bdb")
1325 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1326 library_dirs=dblib_dir,
1327 runtime_library_dirs=dblib_dir,
1328 include_dirs=db_incs,
1329 define_macros=[
1330 ('HAVE_BERKDB_H', None),
1331 ('DB_DBM_HSEARCH', None),
1332 ],
1333 libraries=dblibs)
1334 break
1335 if dbmext is not None:
1336 self.add(dbmext)
1337 else:
1338 self.missing.append('_dbm')
1339
1340 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1341 if ('gdbm' in dbm_order and
1342 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1343 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1344 libraries=['gdbm']))
1345 else:
1346 self.missing.append('_gdbm')
1347
1348 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001349 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001350 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001351
1352 # We hunt for #define SQLITE_VERSION "n.n.n"
Charles Pigottad0daf52019-04-26 16:38:12 +01001353 # We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001354 sqlite_incdir = sqlite_libdir = None
1355 sqlite_inc_paths = [ '/usr/include',
1356 '/usr/include/sqlite',
1357 '/usr/include/sqlite3',
1358 '/usr/local/include',
1359 '/usr/local/include/sqlite',
1360 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001361 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001362 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001363 sqlite_inc_paths = []
gescheitb9a03762019-07-13 06:15:49 +03001364 MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001365 MIN_SQLITE_VERSION = ".".join([str(x)
1366 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001367
1368 # Scan the default include directories before the SQLite specific
1369 # ones. This allows one to override the copy of sqlite on OSX,
1370 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001371 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001372 sysroot = macosx_sdk_root()
1373
Victor Stinner625dbf22019-03-01 15:59:39 +01001374 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001375 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001376 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001377 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001378
Ned Deily9b635832012-08-05 15:13:33 -07001379 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001380 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001381 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001382 with open(f) as file:
1383 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001384 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001385 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001386 if m:
1387 sqlite_version = m.group(1)
1388 sqlite_version_tuple = tuple([int(x)
1389 for x in sqlite_version.split(".")])
1390 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1391 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001392 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001393 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001394 sqlite_incdir = d
1395 break
1396 else:
1397 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001398 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001399 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001400 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001401 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001402
1403 if sqlite_incdir:
1404 sqlite_dirs_to_check = [
1405 os.path.join(sqlite_incdir, '..', 'lib64'),
1406 os.path.join(sqlite_incdir, '..', 'lib'),
1407 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1408 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1409 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001410 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001411 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001412 if sqlite_libfile:
1413 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001414
1415 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001416 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001417 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001418 '_sqlite/cursor.c',
1419 '_sqlite/microprotocols.c',
1420 '_sqlite/module.c',
1421 '_sqlite/prepare_protocol.c',
1422 '_sqlite/row.c',
1423 '_sqlite/statement.c',
1424 '_sqlite/util.c', ]
1425
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001426 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001427 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001428 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1429 else:
1430 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1431
Benjamin Peterson076ed002010-10-31 17:11:02 +00001432 # Enable support for loadable extensions in the sqlite3 module
1433 # if --enable-loadable-sqlite-extensions configure option is used.
1434 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1435 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001436
Victor Stinner4cbea512019-02-28 17:48:38 +01001437 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001438 # In every directory on the search path search for a dynamic
1439 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001440 # for dynamic libraries on the entire path.
1441 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001442 # before the dynamic library in /usr/lib.
1443 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1444 else:
1445 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001446
Brett Cannonc5011fe2011-06-06 20:09:10 -07001447 include_dirs = ["Modules/_sqlite"]
1448 # Only include the directory where sqlite was found if it does
1449 # not already exist in set include directories, otherwise you
1450 # can end up with a bad search path order.
1451 if sqlite_incdir not in self.compiler.include_dirs:
1452 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001453 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001454 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001455 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001456 self.add(Extension('_sqlite3', sqlite_srcs,
1457 define_macros=sqlite_defines,
1458 include_dirs=include_dirs,
1459 library_dirs=sqlite_libdir,
1460 extra_link_args=sqlite_extra_link_args,
1461 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001462 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001463 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001464
Victor Stinner5ec33a12019-03-01 16:43:28 +01001465 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001466 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001467 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001468 if not VXWORKS:
1469 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001470 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001471 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001472 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001473 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001474 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001475
Victor Stinner5ec33a12019-03-01 16:43:28 +01001476 # Platform-specific libraries
1477 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1478 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001479 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001480 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001481
Victor Stinner5ec33a12019-03-01 16:43:28 +01001482 if MACOS:
1483 self.add(Extension('_scproxy', ['_scproxy.c'],
1484 extra_link_args=[
1485 '-framework', 'SystemConfiguration',
1486 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001487
Victor Stinner5ec33a12019-03-01 16:43:28 +01001488 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001489 # Andrew Kuchling's zlib module. Note that some versions of zlib
1490 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1491 # http://www.cert.org/advisories/CA-2002-07.html
1492 #
1493 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1494 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1495 # now, we still accept 1.1.3, because we think it's difficult to
1496 # exploit this in Python, and we'd rather make it RedHat's problem
1497 # than our problem <wink>.
1498 #
1499 # You can upgrade zlib to version 1.1.4 yourself by going to
1500 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001501 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001502 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001503 if zlib_inc is not None:
1504 zlib_h = zlib_inc[0] + '/zlib.h'
1505 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001506 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001507 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001508 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001509 with open(zlib_h) as fp:
1510 while 1:
1511 line = fp.readline()
1512 if not line:
1513 break
1514 if line.startswith('#define ZLIB_VERSION'):
1515 version = line.split()[2]
1516 break
Guido van Rossume6970912001-04-15 15:16:12 +00001517 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001518 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001519 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001520 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1521 else:
1522 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001523 self.add(Extension('zlib', ['zlibmodule.c'],
1524 libraries=['z'],
1525 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001526 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001527 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001528 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001529 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001530 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001531 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001532 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001533
Christian Heimes1dc54002008-03-24 02:19:29 +00001534 # Helper module for various ascii-encoders. Uses zlib for an optimized
1535 # crc32 if we have it. Otherwise binascii uses its own.
1536 if have_zlib:
1537 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1538 libraries = ['z']
1539 extra_link_args = zlib_extra_link_args
1540 else:
1541 extra_compile_args = []
1542 libraries = []
1543 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001544 self.add(Extension('binascii', ['binascii.c'],
1545 extra_compile_args=extra_compile_args,
1546 libraries=libraries,
1547 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001548
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001549 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001550 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001551 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001552 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1553 else:
1554 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001555 self.add(Extension('_bz2', ['_bz2module.c'],
1556 libraries=['bz2'],
1557 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001558 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001559 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001560
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001561 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001562 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001563 self.add(Extension('_lzma', ['_lzmamodule.c'],
1564 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001565 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001566 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001567
Victor Stinner5ec33a12019-03-01 16:43:28 +01001568 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001569 # Interface to the Expat XML parser
1570 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001571 # Expat was written by James Clark and is now maintained by a group of
1572 # developers on SourceForge; see www.libexpat.org for more information.
1573 # The pyexpat module was written by Paul Prescod after a prototype by
1574 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1575 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001576 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001577 #
1578 # More information on Expat can be found at www.libexpat.org.
1579 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001580 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1581 expat_inc = []
1582 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001583 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001584 expat_lib = ['expat']
1585 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001586 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001587 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001588 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001589 define_macros = [
1590 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001591 # bpo-30947: Python uses best available entropy sources to
1592 # call XML_SetHashSalt(), expat entropy sources are not needed
1593 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001594 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001595 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001596 expat_lib = []
1597 expat_sources = ['expat/xmlparse.c',
1598 'expat/xmlrole.c',
1599 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001600 expat_depends = ['expat/ascii.h',
1601 'expat/asciitab.h',
1602 'expat/expat.h',
1603 'expat/expat_config.h',
1604 'expat/expat_external.h',
1605 'expat/internal.h',
1606 'expat/latin1tab.h',
1607 'expat/utf8tab.h',
1608 'expat/xmlrole.h',
1609 'expat/xmltok.h',
1610 'expat/xmltok_impl.h'
1611 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001612
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001613 cc = sysconfig.get_config_var('CC').split()[0]
1614 ret = os.system(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001615 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001616 if ret >> 8 == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001617 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001618
Victor Stinner8058bda2019-03-01 15:31:45 +01001619 self.add(Extension('pyexpat',
1620 define_macros=define_macros,
1621 extra_compile_args=extra_compile_args,
1622 include_dirs=expat_inc,
1623 libraries=expat_lib,
1624 sources=['pyexpat.c'] + expat_sources,
1625 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001626
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001627 # Fredrik Lundh's cElementTree module. Note that this also
1628 # uses expat (via the CAPI hook in pyexpat).
1629
Victor Stinner625dbf22019-03-01 15:59:39 +01001630 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001631 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001632 self.add(Extension('_elementtree',
1633 define_macros=define_macros,
1634 include_dirs=expat_inc,
1635 libraries=expat_lib,
1636 sources=['_elementtree.c'],
1637 depends=['pyexpat.c', *expat_sources,
1638 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001639 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001640 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001641
Victor Stinner5ec33a12019-03-01 16:43:28 +01001642 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001643 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001644 self.add(Extension('_multibytecodec',
1645 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001646 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001647 self.add(Extension('_codecs_%s' % loc,
1648 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001649
Victor Stinner5ec33a12019-03-01 16:43:28 +01001650 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001651 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001652 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001653 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1654 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001655
1656 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001657 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001658 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1659 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001660 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001661 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1662 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 17:19:04 +01001663 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-01 22:52:23 -06001664 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001665 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1666 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001667 libs.append('rt')
Victor Stinner8058bda2019-03-01 15:31:45 +01001668 self.add(Extension('_posixshmem', posixshmem_srcs,
1669 define_macros={},
1670 libraries=libs,
1671 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001672
Victor Stinner8058bda2019-03-01 15:31:45 +01001673 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001674 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001675
Victor Stinner5ec33a12019-03-01 16:43:28 +01001676 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001677 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001678 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001679 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001680 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001681 uuid_libs = ['uuid']
1682 else:
1683 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001684 self.add(Extension('_uuid', ['_uuidmodule.c'],
1685 libraries=uuid_libs,
1686 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001687 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001688 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001689
Victor Stinner5ec33a12019-03-01 16:43:28 +01001690 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001691 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001692 self.init_inc_lib_dirs()
1693
1694 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001695 if TEST_EXTENSIONS:
1696 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001697 self.detect_readline_curses()
1698 self.detect_crypt()
1699 self.detect_socket()
1700 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001701 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001702 self.detect_dbm_gdbm()
1703 self.detect_sqlite()
1704 self.detect_platform_specific_exts()
1705 self.detect_nis()
1706 self.detect_compress_exts()
1707 self.detect_expat_elementtree()
1708 self.detect_multibytecodecs()
1709 self.detect_decimal()
1710 self.detect_ctypes()
1711 self.detect_multiprocessing()
1712 if not self.detect_tkinter():
1713 self.missing.append('_tkinter')
1714 self.detect_uuid()
1715
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001716## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001717## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001718
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001719 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001720 self.add(Extension('xxlimited', ['xxlimited.c'],
1721 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001722
Ned Deilyd819b932013-09-06 01:07:05 -07001723 def detect_tkinter_explicitly(self):
1724 # Build _tkinter using explicit locations for Tcl/Tk.
1725 #
1726 # This is enabled when both arguments are given to ./configure:
1727 #
1728 # --with-tcltk-includes="-I/path/to/tclincludes \
1729 # -I/path/to/tkincludes"
1730 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1731 # -L/path/to/tklibs -ltkm.n"
1732 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001733 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001734 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1735 #
1736 # This can be useful for building and testing tkinter with multiple
1737 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1738 # build of Tcl so you need to specify both arguments and use care when
1739 # overriding.
1740
1741 # The _TCLTK variables are created in the Makefile sharedmods target.
1742 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1743 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1744 if not (tcltk_includes and tcltk_libs):
1745 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001746 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001747
1748 extra_compile_args = tcltk_includes.split()
1749 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001750 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1751 define_macros=[('WITH_APPINIT', 1)],
1752 extra_compile_args = extra_compile_args,
1753 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001754 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001755
Victor Stinner625dbf22019-03-01 15:59:39 +01001756 def detect_tkinter_darwin(self):
Jack Jansen0b06be72002-06-21 14:48:38 +00001757 # The _tkinter module, using frameworks. Since frameworks are quite
1758 # different the UNIX search logic is not sharable.
1759 from os.path import join, exists
1760 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001761 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:48 +00001762 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:38 +00001763 join(os.getenv('HOME'), '/Library/Frameworks')
1764 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001765
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001766 sysroot = macosx_sdk_root()
1767
Skip Montanaro0174ddd2005-12-30 05:01:26 +00001768 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:38 +00001769 # bundles.
1770 # XXX distutils should support -F!
1771 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001772 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001773
1774
Jack Jansen0b06be72002-06-21 14:48:38 +00001775 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001776 if is_macosx_sdk_path(F):
1777 if not exists(join(sysroot, F[1:], fw + '.framework')):
1778 break
1779 else:
1780 if not exists(join(F, fw + '.framework')):
1781 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001782 else:
1783 # ok, F is now directory with both frameworks. Continure
1784 # building
1785 break
1786 else:
1787 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1788 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001789 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001790
Jack Jansen0b06be72002-06-21 14:48:38 +00001791 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1792 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:43 +00001793 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:38 +00001794 #
1795 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001796 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001797 for fw in ('Tcl', 'Tk')
1798 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:38 +00001799 ]
1800
Tim Peters2c60f7a2003-01-29 03:49:43 +00001801 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:38 +00001802 # complicated search, this is a hard-coded path. It could bail out
1803 # if X11 libs are not found...
1804 include_dirs.append('/usr/X11R6/include')
1805 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1806
Georg Brandlfcaf9102008-07-16 02:17:56 +00001807 # All existing framework builds of Tcl/Tk don't support 64-bit
1808 # architectures.
1809 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001810 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001811
Ronald Oussorend097efe2009-09-15 19:07:58 +00001812 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1813 if not os.path.exists(self.build_temp):
1814 os.makedirs(self.build_temp)
1815
1816 # Note: cannot use os.popen or subprocess here, that
1817 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001818 if is_macosx_sdk_path(F):
1819 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1820 else:
1821 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001822
Brett Cannon9f5db072010-10-29 20:19:27 +00001823 with open(tmpfile) as fp:
1824 detected_archs = []
1825 for ln in fp:
1826 a = ln.split()[-1]
1827 if a in archs:
1828 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001829 os.unlink(tmpfile)
1830
1831 for a in detected_archs:
1832 frameworks.append('-arch')
1833 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001834
Victor Stinnercfe172d2019-03-01 18:21:49 +01001835 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1836 define_macros=[('WITH_APPINIT', 1)],
1837 include_dirs=include_dirs,
1838 libraries=[],
1839 extra_compile_args=frameworks[2:],
1840 extra_link_args=frameworks))
Victor Stinner4cbea512019-02-28 17:48:38 +01001841 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001842
Victor Stinner625dbf22019-03-01 15:59:39 +01001843 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001844 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001845
Ned Deilyd819b932013-09-06 01:07:05 -07001846 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1847 # configured or passed into the make target. If so, use these values
1848 # to build tkinter and bypass the searches for Tcl and TK in standard
1849 # locations.
1850 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 16:43:28 +01001851 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001852
Jack Jansen0b06be72002-06-21 14:48:38 +00001853 # Rather than complicate the code below, detecting and building
1854 # AquaTk is a separate method. Only one Tkinter will be built on
1855 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01001856 if (MACOS and self.detect_tkinter_darwin()):
1857 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001858
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001859 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001860 # The versions with dots are used on Unix, and the versions without
1861 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001862 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00001863 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1864 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01001865 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001866 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01001867 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001868 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00001869 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001870 # Exit the loop when we've found the Tcl/Tk libraries
1871 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001872
Fredrik Lundhade711a2001-01-24 08:00:28 +00001873 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001874 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001875 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001876 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001877 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01001878 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001879 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1880 # but the include subdirs are named like .../include/tcl8.3.
1881 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1882 tcl_include_sub = []
1883 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001884 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001885 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1886 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1887 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01001888 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
1889 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001890
Martin v. Löwise86a59a2003-05-03 08:45:51 +00001891 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001892 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001893 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01001894 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00001895
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001896 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001897
Victor Stinnercfe172d2019-03-01 18:21:49 +01001898 include_dirs = []
1899 libs = []
1900 defs = []
1901 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001902 for dir in tcl_includes + tk_includes:
1903 if dir not in include_dirs:
1904 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001905
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001906 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01001907 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001908 include_dirs.append('/usr/openwin/include')
1909 added_lib_dirs.append('/usr/openwin/lib')
1910 elif os.path.exists('/usr/X11R6/include'):
1911 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00001912 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001913 added_lib_dirs.append('/usr/X11R6/lib')
1914 elif os.path.exists('/usr/X11R5/include'):
1915 include_dirs.append('/usr/X11R5/include')
1916 added_lib_dirs.append('/usr/X11R5/lib')
1917 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001918 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001919 include_dirs.append('/usr/X11/include')
1920 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001921
Jason Tishler9181c942003-02-05 15:16:17 +00001922 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01001923 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00001924 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1925 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001926 return False
Jason Tishler9181c942003-02-05 15:16:17 +00001927
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001928 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01001929 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001930 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001931 defs.append( ('WITH_BLT', 1) )
1932 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01001933 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001934 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00001935 defs.append( ('WITH_BLT', 1) )
1936 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001937
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001938 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00001939 libs.append('tk'+ version)
1940 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001941
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001942 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01001943 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001944 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001945
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001946 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001947 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001948 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001949 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001950 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001951 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001952 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001953
Victor Stinnercfe172d2019-03-01 18:21:49 +01001954 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1955 define_macros=[('WITH_APPINIT', 1)] + defs,
1956 include_dirs=include_dirs,
1957 libraries=libs,
1958 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01001959 return True
1960
Christian Heimes78644762008-03-04 23:39:23 +00001961 def configure_ctypes_darwin(self, ext):
1962 # Darwin (OS X) uses preconfigured files, in
1963 # the Modules/_ctypes/libffi_osx directory.
Victor Stinner625dbf22019-03-01 15:59:39 +01001964 ffi_srcdir = os.path.abspath(os.path.join(self.srcdir, 'Modules',
Christian Heimes78644762008-03-04 23:39:23 +00001965 '_ctypes', 'libffi_osx'))
1966 sources = [os.path.join(ffi_srcdir, p)
1967 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:56 +00001968 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:23 +00001969 'x86/x86-darwin.S',
1970 'x86/x86-ffi_darwin.c',
1971 'x86/x86-ffi64.c',
1972 'powerpc/ppc-darwin.S',
1973 'powerpc/ppc-darwin_closure.S',
1974 'powerpc/ppc-ffi_darwin.c',
1975 'powerpc/ppc64-darwin_closure.S',
1976 ]]
1977
1978 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:05 +00001979 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:23 +00001980
1981 include_dirs = [os.path.join(ffi_srcdir, 'include'),
1982 os.path.join(ffi_srcdir, 'powerpc')]
1983 ext.include_dirs.extend(include_dirs)
1984 ext.sources.extend(sources)
1985 return True
1986
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001987 def configure_ctypes(self, ext):
1988 if not self.use_system_libffi:
Victor Stinner4cbea512019-02-28 17:48:38 +01001989 if MACOS:
Christian Heimes78644762008-03-04 23:39:23 +00001990 return self.configure_ctypes_darwin(ext)
Zachary Waref40d4dd2016-09-17 01:25:24 -05001991 print('INFO: Could not locate ffi libs and/or headers')
1992 return False
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001993 return True
1994
Victor Stinner625dbf22019-03-01 15:59:39 +01001995 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001996 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001997 self.use_system_libffi = False
1998 include_dirs = []
1999 extra_compile_args = []
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002000 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002001 sources = ['_ctypes/_ctypes.c',
2002 '_ctypes/callbacks.c',
2003 '_ctypes/callproc.c',
2004 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002005 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002006 depends = ['_ctypes/ctypes.h']
2007
Victor Stinner4cbea512019-02-28 17:48:38 +01002008 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002009 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:58 +00002010 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:23 +00002011 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002012 include_dirs.append('_ctypes/darwin')
Victor Stinner5ec33a12019-03-01 16:43:28 +01002013 # XXX Is this still needed?
2014 # extra_link_args.extend(['-read_only_relocs', 'warning'])
Thomas Hellercf567c12006-03-08 19:51:58 +00002015
Victor Stinner4cbea512019-02-28 17:48:38 +01002016 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002017 # XXX This shouldn't be necessary; it appears that some
2018 # of the assembler code is non-PIC (i.e. it has relocations
2019 # when it shouldn't. The proper fix would be to rewrite
2020 # the assembler code to be PIC.
2021 # This only works with GCC; the Sun compiler likely refuses
2022 # this option. If you want to compile ctypes with the Sun
2023 # compiler, please research a proper solution, instead of
2024 # finding some -z option for the Sun compiler.
2025 extra_link_args.append('-mimpure-text')
2026
Victor Stinner4cbea512019-02-28 17:48:38 +01002027 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002028 extra_link_args.append('-fPIC')
2029
Thomas Hellercf567c12006-03-08 19:51:58 +00002030 ext = Extension('_ctypes',
2031 include_dirs=include_dirs,
2032 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002033 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002034 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002035 sources=sources,
2036 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002037 self.add(ext)
2038 if TEST_EXTENSIONS:
2039 # function my_sqrt() needs libm for sqrt()
2040 self.add(Extension('_ctypes_test',
2041 sources=['_ctypes/_ctypes_test.c'],
2042 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002043
Victor Stinner625dbf22019-03-01 15:59:39 +01002044 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002045 if MACOS:
Zachary Ware935043d2016-09-09 17:01:21 -07002046 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
2047 return
Christian Heimes78644762008-03-04 23:39:23 +00002048 # OS X 10.5 comes with libffi.dylib; the include files are
2049 # in /usr/include/ffi
Victor Stinner96d81582019-03-01 13:53:46 +01002050 ffi_inc_dirs.append('/usr/include/ffi')
Christian Heimes78644762008-03-04 23:39:23 +00002051
Benjamin Petersond78735d2010-01-01 16:04:23 +00002052 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:45 +00002053 if not ffi_inc or ffi_inc[0] == '':
Victor Stinner96d81582019-03-01 13:53:46 +01002054 ffi_inc = find_file('ffi.h', [], ffi_inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002055 if ffi_inc is not None:
2056 ffi_h = ffi_inc[0] + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002057 if not os.path.exists(ffi_h):
2058 ffi_inc = None
2059 print('Header file {} does not exist'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002060 ffi_lib = None
2061 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002062 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002063 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002064 ffi_lib = lib_name
2065 break
2066
2067 if ffi_inc and ffi_lib:
2068 ext.include_dirs.extend(ffi_inc)
2069 ext.libraries.append(ffi_lib)
2070 self.use_system_libffi = True
2071
Christian Heimes5bb96922018-02-25 10:22:14 +01002072 if sysconfig.get_config_var('HAVE_LIBDL'):
2073 # for dlopen, see bpo-32647
2074 ext.libraries.append('dl')
2075
Victor Stinner5ec33a12019-03-01 16:43:28 +01002076 def detect_decimal(self):
2077 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002078 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002079 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002080 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2081 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002082 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002083 sources = ['_decimal/_decimal.c']
2084 depends = ['_decimal/docstrings.h']
2085 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002086 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002087 'Modules',
2088 '_decimal',
2089 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002090 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002091 sources = [
2092 '_decimal/_decimal.c',
2093 '_decimal/libmpdec/basearith.c',
2094 '_decimal/libmpdec/constants.c',
2095 '_decimal/libmpdec/context.c',
2096 '_decimal/libmpdec/convolute.c',
2097 '_decimal/libmpdec/crt.c',
2098 '_decimal/libmpdec/difradix2.c',
2099 '_decimal/libmpdec/fnt.c',
2100 '_decimal/libmpdec/fourstep.c',
2101 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002102 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002103 '_decimal/libmpdec/mpdecimal.c',
2104 '_decimal/libmpdec/numbertheory.c',
2105 '_decimal/libmpdec/sixstep.c',
2106 '_decimal/libmpdec/transpose.c',
2107 ]
2108 depends = [
2109 '_decimal/docstrings.h',
2110 '_decimal/libmpdec/basearith.h',
2111 '_decimal/libmpdec/bits.h',
2112 '_decimal/libmpdec/constants.h',
2113 '_decimal/libmpdec/convolute.h',
2114 '_decimal/libmpdec/crt.h',
2115 '_decimal/libmpdec/difradix2.h',
2116 '_decimal/libmpdec/fnt.h',
2117 '_decimal/libmpdec/fourstep.h',
2118 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002119 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002120 '_decimal/libmpdec/mpdecimal.h',
2121 '_decimal/libmpdec/numbertheory.h',
2122 '_decimal/libmpdec/sixstep.h',
2123 '_decimal/libmpdec/transpose.h',
2124 '_decimal/libmpdec/typearith.h',
2125 '_decimal/libmpdec/umodarith.h',
2126 ]
2127
Stefan Krah1919b7e2012-03-21 18:25:23 +01002128 config = {
2129 'x64': [('CONFIG_64','1'), ('ASM','1')],
2130 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2131 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2132 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2133 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2134 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2135 ('LEGACY_COMPILER','1')],
2136 'universal': [('UNIVERSAL','1')]
2137 }
2138
Stefan Krah1919b7e2012-03-21 18:25:23 +01002139 cc = sysconfig.get_config_var('CC')
2140 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2141 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2142
2143 if machine:
2144 # Override automatic configuration to facilitate testing.
2145 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002146 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002147 # Universal here means: build with the same options Python
2148 # was built with.
2149 define_macros = config['universal']
2150 elif sizeof_size_t == 8:
2151 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2152 define_macros = config['x64']
2153 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2154 define_macros = config['uint128']
2155 else:
2156 define_macros = config['ansi64']
2157 elif sizeof_size_t == 4:
2158 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2159 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002160 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002161 # solaris: problems with register allocation.
2162 # icc >= 11.0 works as well.
2163 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002164 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002165 else:
2166 define_macros = config['ansi32']
2167 else:
2168 raise DistutilsError("_decimal: unsupported architecture")
2169
2170 # Workarounds for toolchain bugs:
2171 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2172 # Some versions of gcc miscompile inline asm:
2173 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2174 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2175 extra_compile_args.append('-fno-ipa-pure-const')
2176 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2177 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2178 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2179 undef_macros.append('_FORTIFY_SOURCE')
2180
Stefan Krah1919b7e2012-03-21 18:25:23 +01002181 # Uncomment for extra functionality:
2182 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002183 self.add(Extension('_decimal',
2184 include_dirs=include_dirs,
2185 libraries=libraries,
2186 define_macros=define_macros,
2187 undef_macros=undef_macros,
2188 extra_compile_args=extra_compile_args,
2189 sources=sources,
2190 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002191
Victor Stinner5ec33a12019-03-01 16:43:28 +01002192 def detect_openssl_hashlib(self):
2193 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002194 config_vars = sysconfig.get_config_vars()
2195
2196 def split_var(name, sep):
2197 # poor man's shlex, the re module is not available yet.
2198 value = config_vars.get(name)
2199 if not value:
2200 return ()
2201 # This trick works because ax_check_openssl uses --libs-only-L,
2202 # --libs-only-l, and --cflags-only-I.
2203 value = ' ' + value
2204 sep = ' ' + sep
2205 return [v.strip() for v in value.split(sep) if v.strip()]
2206
2207 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2208 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2209 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2210 if not openssl_libs:
2211 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002212 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002213 return None, None
2214
2215 # Find OpenSSL includes
2216 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002217 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002218 )
2219 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002220 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002221 return None, None
2222
2223 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2224 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002225 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002226 ['/usr/kerberos/include']
2227 )
2228 if krb5_h:
2229 ssl_incs.extend(krb5_h)
2230
Christian Heimes61d478c2018-01-27 15:51:38 +01002231 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 11:44:05 +02002232 self.add(Extension(
2233 '_ssl', ['_ssl.c'],
2234 include_dirs=openssl_includes,
2235 library_dirs=openssl_libdirs,
2236 libraries=openssl_libs,
2237 depends=['socketmodule.h', '_ssl/debughelpers.c'])
2238 )
Christian Heimes61d478c2018-01-27 15:51:38 +01002239 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002240 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002241
Victor Stinner8058bda2019-03-01 15:31:45 +01002242 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2243 depends=['hashlib.h'],
2244 include_dirs=openssl_includes,
2245 library_dirs=openssl_libdirs,
2246 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002247
xdegaye2ee077f2019-04-09 17:20:08 +02002248 def detect_hash_builtins(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002249 # We always compile these even when OpenSSL is available (issue #14693).
2250 # It's harmless and the object code is tiny (40-50 KiB per module,
2251 # only loaded when actually used).
2252 self.add(Extension('_sha256', ['sha256module.c'],
2253 depends=['hashlib.h']))
2254 self.add(Extension('_sha512', ['sha512module.c'],
2255 depends=['hashlib.h']))
2256 self.add(Extension('_md5', ['md5module.c'],
2257 depends=['hashlib.h']))
2258 self.add(Extension('_sha1', ['sha1module.c'],
2259 depends=['hashlib.h']))
2260
2261 blake2_deps = glob(os.path.join(self.srcdir,
2262 'Modules/_blake2/impl/*'))
2263 blake2_deps.append('hashlib.h')
2264
2265 self.add(Extension('_blake2',
2266 ['_blake2/blake2module.c',
2267 '_blake2/blake2b_impl.c',
2268 '_blake2/blake2s_impl.c'],
2269 depends=blake2_deps))
2270
2271 sha3_deps = glob(os.path.join(self.srcdir,
2272 'Modules/_sha3/kcp/*'))
2273 sha3_deps.append('hashlib.h')
2274 self.add(Extension('_sha3',
2275 ['_sha3/sha3module.c'],
2276 depends=sha3_deps))
2277
2278 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002279 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002280 self.missing.append('nis')
2281 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002282
2283 libs = []
2284 library_dirs = []
2285 includes_dirs = []
2286
2287 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2288 # moved headers and libraries to libtirpc and libnsl. The headers
2289 # are in tircp and nsl sub directories.
2290 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002291 'rpcsvc/yp_prot.h', self.inc_dirs,
2292 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002293 )
2294 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002295 'rpc/rpc.h', self.inc_dirs,
2296 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002297 )
2298 if rpcsvc_inc is None or rpc_inc is None:
2299 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002300 self.missing.append('nis')
2301 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002302 includes_dirs.extend(rpcsvc_inc)
2303 includes_dirs.extend(rpc_inc)
2304
Victor Stinner625dbf22019-03-01 15:59:39 +01002305 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002306 libs.append('nsl')
2307 else:
2308 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002309 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002310 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2311 if libnsl is not None:
2312 library_dirs.append(os.path.dirname(libnsl))
2313 libs.append('nsl')
2314
Victor Stinner625dbf22019-03-01 15:59:39 +01002315 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002316 libs.append('tirpc')
2317
Victor Stinner8058bda2019-03-01 15:31:45 +01002318 self.add(Extension('nis', ['nismodule.c'],
2319 libraries=libs,
2320 library_dirs=library_dirs,
2321 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002322
Christian Heimesff5be6e2018-01-20 13:19:21 +01002323
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002324class PyBuildInstall(install):
2325 # Suppress the warning about installation into the lib_dynload
2326 # directory, which is not in sys.path when running Python during
2327 # installation:
2328 def initialize_options (self):
2329 install.initialize_options(self)
2330 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002331
Éric Araujoe6792c12011-06-09 14:07:02 +02002332 # Customize subcommands to not install an egg-info file for Python
2333 sub_commands = [('install_lib', install.has_lib),
2334 ('install_headers', install.has_headers),
2335 ('install_scripts', install.has_scripts),
2336 ('install_data', install.has_data)]
2337
2338
Michael W. Hudson529a5052002-12-17 16:47:17 +00002339class PyBuildInstallLib(install_lib):
2340 # Do exactly what install_lib does but make sure correct access modes get
2341 # set on installed directories and files. All installed files with get
2342 # mode 644 unless they are a shared library in which case they will get
2343 # mode 755. All installed directories will get mode 755.
2344
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002345 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2346 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002347
2348 def install(self):
2349 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002350 self.set_file_modes(outfiles, 0o644, 0o755)
2351 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002352 return outfiles
2353
2354 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002355 if not files: return
2356
2357 for filename in files:
2358 if os.path.islink(filename): continue
2359 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002360 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002361 log.info("changing mode of %s to %o", filename, mode)
2362 if not self.dry_run: os.chmod(filename, mode)
2363
2364 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002365 for dirpath, dirnames, fnames in os.walk(dirname):
2366 if os.path.islink(dirpath):
2367 continue
2368 log.info("changing mode of %s to %o", dirpath, mode)
2369 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002370
Victor Stinnerc991f242019-03-01 17:19:04 +01002371
Georg Brandlff52f762010-12-28 09:51:43 +00002372class PyBuildScripts(build_scripts):
2373 def copy_scripts(self):
2374 outfiles, updated_files = build_scripts.copy_scripts(self)
2375 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2376 minoronly = '.{0[1]}'.format(sys.version_info)
2377 newoutfiles = []
2378 newupdated_files = []
2379 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002380 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002381 newfilename = filename + fullversion
2382 else:
2383 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002384 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002385 os.rename(filename, newfilename)
2386 newoutfiles.append(newfilename)
2387 if filename in updated_files:
2388 newupdated_files.append(newfilename)
2389 return newoutfiles, newupdated_files
2390
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002391
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002392def main():
Victor Stinnerc991f242019-03-01 17:19:04 +01002393 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2394 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2395
2396 class DummyProcess:
2397 """Hack for parallel build"""
2398 ProcessPoolExecutor = None
2399
2400 sys.modules['concurrent.futures.process'] = DummyProcess
2401
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002402 # turn off warnings when deprecated modules are imported
2403 import warnings
2404 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002405 setup(# PyPI Metadata (PEP 301)
2406 name = "Python",
2407 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002408 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002409 maintainer = "Guido van Rossum and the Python community",
2410 maintainer_email = "python-dev@python.org",
2411 description = "A high-level object-oriented programming language",
2412 long_description = SUMMARY.strip(),
2413 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002414 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002415 platforms = ["Many"],
2416
2417 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002418 cmdclass = {'build_ext': PyBuildExt,
2419 'build_scripts': PyBuildScripts,
2420 'install': PyBuildInstall,
2421 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002422 # The struct module is defined here, because build_ext won't be
2423 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002424 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002425
Georg Brandlff52f762010-12-28 09:51:43 +00002426 # If you change the scripts installed here, you also need to
2427 # check the PyBuildScripts command above, and change the links
2428 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002429 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002430 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002431 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002432
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002433# --install-platlib
2434if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002435 main()