blob: 7432970a106919a0985740d307acede391c766f6 [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
Serhiy Storchakaecfecc22020-07-02 10:05:16 +030011from glob import glob, escape
Miss Islington (bot)0aab3522020-11-21 22:35:36 -080012import _osx_support
Michael W. Hudson529a5052002-12-17 16:47:17 +000013
Victor Stinner1ec63b62020-03-04 14:50:19 +010014
15try:
16 import subprocess
17 del subprocess
18 SUBPROCESS_BOOTSTRAP = False
19except ImportError:
Victor Stinner1ec63b62020-03-04 14:50:19 +010020 # Bootstrap Python: distutils.spawn uses subprocess to build C extensions,
21 # subprocess requires C extensions built by setup.py like _posixsubprocess.
22 #
Victor Stinneraddaaaa2020-03-09 23:45:59 +010023 # Use _bootsubprocess which only uses the os module.
Victor Stinner1ec63b62020-03-04 14:50:19 +010024 #
25 # It is dropped from sys.modules as soon as all C extension modules
26 # are built.
Victor Stinneraddaaaa2020-03-09 23:45:59 +010027 import _bootsubprocess
28 sys.modules['subprocess'] = _bootsubprocess
29 del _bootsubprocess
30 SUBPROCESS_BOOTSTRAP = True
Victor Stinner1ec63b62020-03-04 14:50:19 +010031
32
Michael W. Hudson529a5052002-12-17 16:47:17 +000033from distutils import log
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000034from distutils.command.build_ext import build_ext
Victor Stinner625dbf22019-03-01 15:59:39 +010035from distutils.command.build_scripts import build_scripts
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000036from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:17 +000037from distutils.command.install_lib import install_lib
Victor Stinner625dbf22019-03-01 15:59:39 +010038from distutils.core import Extension, setup
39from distutils.errors import CCompilerError, DistutilsError
Stefan Krah095b2732010-06-08 13:41:44 +000040from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000041
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020042
Victor Stinnercfe172d2019-03-01 18:21:49 +010043# Compile extensions used to test Python?
44TEST_EXTENSIONS = True
45
46# This global variable is used to hold the list of modules to be disabled.
47DISABLED_MODULE_LIST = []
48
49
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020050def get_platform():
Victor Stinnerc991f242019-03-01 17:19:04 +010051 # Cross compiling
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020052 if "_PYTHON_HOST_PLATFORM" in os.environ:
53 return os.environ["_PYTHON_HOST_PLATFORM"]
Victor Stinnerc991f242019-03-01 17:19:04 +010054
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020055 # Get value of sys.platform
56 if sys.platform.startswith('osf1'):
57 return 'osf1'
58 return sys.platform
Victor Stinnerc991f242019-03-01 17:19:04 +010059
60
61CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
Victor Stinner4cbea512019-02-28 17:48:38 +010062HOST_PLATFORM = get_platform()
63MS_WINDOWS = (HOST_PLATFORM == 'win32')
64CYGWIN = (HOST_PLATFORM == 'cygwin')
65MACOS = (HOST_PLATFORM == 'darwin')
Michael Felt08970cb2019-06-21 15:58:00 +020066AIX = (HOST_PLATFORM.startswith('aix'))
Victor Stinner4cbea512019-02-28 17:48:38 +010067VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080068
Victor Stinnerc991f242019-03-01 17:19:04 +010069
70SUMMARY = """
71Python is an interpreted, interactive, object-oriented programming
72language. It is often compared to Tcl, Perl, Scheme or Java.
73
74Python combines remarkable power with very clear syntax. It has
75modules, classes, exceptions, very high level dynamic data types, and
76dynamic typing. There are interfaces to many system calls and
77libraries, as well as to various windowing systems (X11, Motif, Tk,
78Mac, MFC). New built-in modules are easily written in C or C++. Python
79is also usable as an extension language for applications that need a
80programmable interface.
81
82The Python implementation is portable: it runs on many brands of UNIX,
83on Windows, DOS, Mac, Amiga... If your favorite system isn't
84listed here, it may still be supported, if there's a C compiler for
85it. Ask around on comp.lang.python -- or just try compiling Python
86yourself.
87"""
88
89CLASSIFIERS = """
90Development Status :: 6 - Mature
91License :: OSI Approved :: Python Software Foundation License
92Natural Language :: English
93Programming Language :: C
94Programming Language :: Python
95Topic :: Software Development
96"""
97
98
Victor Stinner6b982c22020-04-01 01:10:07 +020099def run_command(cmd):
100 status = os.system(cmd)
Victor Stinner65a796e2020-04-01 18:49:29 +0200101 return os.waitstatus_to_exitcode(status)
Victor Stinner6b982c22020-04-01 01:10:07 +0200102
103
Victor Stinnerc991f242019-03-01 17:19:04 +0100104# Set common compiler and linker flags derived from the Makefile,
105# reserved for building the interpreter and the stdlib modules.
106# See bpo-21121 and bpo-35257
107def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
108 flags = sysconfig.get_config_var(compiler_flags)
109 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
110 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
111
112
Michael W. Hudson39230b32002-01-16 15:26:48 +0000113def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000114 """Add the directory 'dir' to the list 'dirlist' (after any relative
115 directories) if:
116
Michael W. Hudson39230b32002-01-16 15:26:48 +0000117 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000118 2) 'dir' actually exists, and is a directory.
119 """
120 if dir is None or not os.path.isdir(dir) or dir in dirlist:
121 return
122 for i, path in enumerate(dirlist):
123 if not os.path.isabs(path):
124 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +0000125 return
126 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +0000127
Victor Stinnerc991f242019-03-01 17:19:04 +0100128
xdegaye77f51392017-11-25 17:25:30 +0100129def sysroot_paths(make_vars, subdirs):
130 """Get the paths of sysroot sub-directories.
131
132 * make_vars: a sequence of names of variables of the Makefile where
133 sysroot may be set.
134 * subdirs: a sequence of names of subdirectories used as the location for
135 headers or libraries.
136 """
137
138 dirs = []
139 for var_name in make_vars:
140 var = sysconfig.get_config_var(var_name)
141 if var is not None:
142 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
143 if m is not None:
144 sysroot = m.group(1).strip('"')
145 for subdir in subdirs:
146 if os.path.isabs(subdir):
147 subdir = subdir[1:]
148 path = os.path.join(sysroot, subdir)
149 if os.path.isdir(path):
150 dirs.append(path)
151 break
152 return dirs
153
Ned Deily1731d6d2020-05-18 04:32:38 -0400154
Ned Deily0288dd62019-06-03 06:34:48 -0400155MACOS_SDK_ROOT = None
Ned Deily1731d6d2020-05-18 04:32:38 -0400156MACOS_SDK_SPECIFIED = None
Victor Stinnerc991f242019-03-01 17:19:04 +0100157
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000158def macosx_sdk_root():
Ned Deily0288dd62019-06-03 06:34:48 -0400159 """Return the directory of the current macOS SDK.
160
161 If no SDK was explicitly configured, call the compiler to find which
162 include files paths are being searched by default. Use '/' if the
163 compiler is searching /usr/include (meaning system header files are
164 installed) or use the root of an SDK if that is being searched.
165 (The SDK may be supplied via Xcode or via the Command Line Tools).
166 The SDK paths used by Apple-supplied tool chains depend on the
167 setting of various variables; see the xcrun man page for more info.
Ned Deily1731d6d2020-05-18 04:32:38 -0400168 Also sets MACOS_SDK_SPECIFIED for use by macosx_sdk_specified().
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000169 """
Ned Deily1731d6d2020-05-18 04:32:38 -0400170 global MACOS_SDK_ROOT, MACOS_SDK_SPECIFIED
Ned Deily0288dd62019-06-03 06:34:48 -0400171
172 # If already called, return cached result.
173 if MACOS_SDK_ROOT:
174 return MACOS_SDK_ROOT
175
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000176 cflags = sysconfig.get_config_var('CFLAGS')
Joshua Rootb3107002020-04-22 17:44:10 +1000177 m = re.search(r'-isysroot\s*(\S+)', cflags)
Ned Deily0288dd62019-06-03 06:34:48 -0400178 if m is not None:
179 MACOS_SDK_ROOT = m.group(1)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000180 else:
Miss Islington (bot)0aab3522020-11-21 22:35:36 -0800181 MACOS_SDK_ROOT = _osx_support._default_sysroot(
182 sysconfig.get_config_var('CC'))
183 MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/'
Ned Deily0288dd62019-06-03 06:34:48 -0400184
185 return MACOS_SDK_ROOT
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000186
Victor Stinnerc991f242019-03-01 17:19:04 +0100187
Ned Deily1731d6d2020-05-18 04:32:38 -0400188def macosx_sdk_specified():
189 """Returns true if an SDK was explicitly configured.
190
191 True if an SDK was selected at configure time, either by specifying
192 --enable-universalsdk=(something other than no or /) or by adding a
193 -isysroot option to CFLAGS. In some cases, like when making
194 decisions about macOS Tk framework paths, we need to be able to
195 know whether the user explicitly asked to build with an SDK versus
196 the implicit use of an SDK when header files are no longer
197 installed on a running system by the Command Line Tools.
198 """
199 global MACOS_SDK_SPECIFIED
200
201 # If already called, return cached result.
202 if MACOS_SDK_SPECIFIED:
203 return MACOS_SDK_SPECIFIED
204
205 # Find the sdk root and set MACOS_SDK_SPECIFIED
206 macosx_sdk_root()
207 return MACOS_SDK_SPECIFIED
208
209
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000210def is_macosx_sdk_path(path):
211 """
212 Returns True if 'path' can be located in an OSX SDK
213 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700214 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
215 or path.startswith('/System/')
216 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000217
Victor Stinnerc991f242019-03-01 17:19:04 +0100218
Ronald Oussorene8b1c032020-11-22 11:18:40 +0100219def grep_headers_for(function, headers):
220 for header in headers:
221 with open(header, 'r', errors='surrogateescape') as f:
222 if function in f.read():
223 return True
224 return False
225
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000226def find_file(filename, std_dirs, paths):
227 """Searches for the directory where a given file is located,
228 and returns a possibly-empty list of additional directories, or None
229 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000230
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000231 'filename' is the name of a file, such as readline.h or libcrypto.a.
232 'std_dirs' is the list of standard system directories; if the
233 file is found in one of them, no additional directives are needed.
234 'paths' is a list of additional locations to check; if the file is
235 found in one of them, the resulting list will contain the directory.
236 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100237 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000238 # Honor the MacOSX SDK setting when one was specified.
239 # An SDK is a directory with the same structure as a real
240 # system, but with only header files and libraries.
241 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000242
243 # Check the standard locations
244 for dir in std_dirs:
245 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000246
Victor Stinner4cbea512019-02-28 17:48:38 +0100247 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000248 f = os.path.join(sysroot, dir[1:], filename)
249
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000250 if os.path.exists(f): return []
251
252 # Check the additional directories
253 for dir in paths:
254 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000255
Victor Stinner4cbea512019-02-28 17:48:38 +0100256 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000257 f = os.path.join(sysroot, dir[1:], filename)
258
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000259 if os.path.exists(f):
260 return [dir]
261
262 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000263 return None
264
Victor Stinnerc991f242019-03-01 17:19:04 +0100265
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000266def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000267 result = compiler.find_library_file(std_dirs + paths, libname)
268 if result is None:
269 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000270
Victor Stinner4cbea512019-02-28 17:48:38 +0100271 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000272 sysroot = macosx_sdk_root()
273
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000274 # Check whether the found file is in one of the standard directories
275 dirname = os.path.dirname(result)
276 for p in std_dirs:
277 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000278 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000279
Victor Stinner4cbea512019-02-28 17:48:38 +0100280 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100281 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
282 # libraries with .tbd extensions rather than the normal .dylib
283 # shared libraries installed in /. The Apple compiler tool
284 # chain handles this transparently but it can cause problems
285 # for programs that are being built with an SDK and searching
286 # for specific libraries. Distutils find_library_file() now
287 # knows to also search for and return .tbd files. But callers
288 # of find_library_file need to keep in mind that the base filename
289 # of the returned SDK library file might have a different extension
290 # from that of the library file installed on the running system,
291 # for example:
292 # /Applications/Xcode.app/Contents/Developer/Platforms/
293 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
294 # usr/lib/libedit.tbd
295 # vs
296 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000297 if os.path.join(sysroot, p[1:]) == dirname:
298 return [ ]
299
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000300 if p == dirname:
301 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000302
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000303 # Otherwise, it must have been in one of the additional directories,
304 # so we have to figure out which one.
305 for p in paths:
306 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000307 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000308
Victor Stinner4cbea512019-02-28 17:48:38 +0100309 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000310 if os.path.join(sysroot, p[1:]) == dirname:
311 return [ p ]
312
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000313 if p == dirname:
314 return [p]
315 else:
316 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000317
Paul Ganssle62972d92020-05-16 04:20:06 -0400318def validate_tzpath():
319 base_tzpath = sysconfig.get_config_var('TZPATH')
320 if not base_tzpath:
321 return
322
323 tzpaths = base_tzpath.split(os.pathsep)
324 bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
325 if bad_paths:
326 raise ValueError('TZPATH must contain only absolute paths, '
327 + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
328 + f'{bad_paths!r}')
Victor Stinnerc991f242019-03-01 17:19:04 +0100329
Jack Jansen144ebcc2001-08-05 22:31:19 +0000330def find_module_file(module, dirlist):
331 """Find a module in a set of possible folders. If it is not found
332 return the unadorned filename"""
333 list = find_file(module, [], dirlist)
334 if not list:
335 return module
336 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100337 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000338 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000339
Victor Stinnerc991f242019-03-01 17:19:04 +0100340
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000341class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000342
Guido van Rossumd8faa362007-04-27 19:54:29 +0000343 def __init__(self, dist):
344 build_ext.__init__(self, dist)
Victor Stinner625dbf22019-03-01 15:59:39 +0100345 self.srcdir = None
346 self.lib_dirs = None
347 self.inc_dirs = None
Victor Stinner5ec33a12019-03-01 16:43:28 +0100348 self.config_h_vars = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000349 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400350 self.failed_on_import = []
Victor Stinner8058bda2019-03-01 15:31:45 +0100351 self.missing = []
Christian Heimes9b60e552020-05-15 23:54:53 +0200352 self.disabled_configure = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200353 if '-j' in os.environ.get('MAKEFLAGS', ''):
354 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000355
Victor Stinner8058bda2019-03-01 15:31:45 +0100356 def add(self, ext):
357 self.extensions.append(ext)
358
Victor Stinner00c77ae2020-03-04 18:44:49 +0100359 def set_srcdir(self):
Victor Stinner625dbf22019-03-01 15:59:39 +0100360 self.srcdir = sysconfig.get_config_var('srcdir')
361 if not self.srcdir:
362 # Maybe running on Windows but not using CYGWIN?
363 raise ValueError("No source directory; cannot proceed.")
364 self.srcdir = os.path.abspath(self.srcdir)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000365
Victor Stinner00c77ae2020-03-04 18:44:49 +0100366 def remove_disabled(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000367 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000368 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100369 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000370 # move ctypes to the end, it depends on other modules
371 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
372 if "_ctypes" in ext_map:
373 ctypes = extensions.pop(ext_map["_ctypes"])
374 extensions.append(ctypes)
375 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000376
Victor Stinner00c77ae2020-03-04 18:44:49 +0100377 def update_sources_depends(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000378 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000379 # with Modules/.
Victor Stinner625dbf22019-03-01 15:59:39 +0100380 moddirlist = [os.path.join(self.srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000381
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000382 # Fix up the paths for scripts, too
Victor Stinner625dbf22019-03-01 15:59:39 +0100383 self.distribution.scripts = [os.path.join(self.srcdir, filename)
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000384 for filename in self.distribution.scripts]
385
Christian Heimesaf98da12008-01-27 15:18:18 +0000386 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000387 headers = [sysconfig.get_config_h_filename()]
Serhiy Storchakaecfecc22020-07-02 10:05:16 +0300388 headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000389
Xavier de Gaye84968b72016-10-29 16:57:20 +0200390 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000391 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000392 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000393 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000394 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000395 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000396 else:
397 ext.depends = []
398 # re-compile extensions if a header file has been changed
399 ext.depends.extend(headers)
400
Victor Stinner00c77ae2020-03-04 18:44:49 +0100401 def remove_configured_extensions(self):
402 # The sysconfig variables built by makesetup that list the already
403 # built modules and the disabled modules as configured by the Setup
404 # files.
405 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
406 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
407
408 mods_built = []
409 mods_disabled = []
410 for ext in self.extensions:
xdegayec0364fc2017-05-27 18:25:03 +0200411 # If a module has already been built or has been disabled in the
412 # Setup files, don't build it here.
413 if ext.name in sysconf_built:
414 mods_built.append(ext)
415 if ext.name in sysconf_dis:
416 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000417
xdegayec0364fc2017-05-27 18:25:03 +0200418 mods_configured = mods_built + mods_disabled
419 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200420 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200421 mods_configured]
422 # Remove the shared libraries built by a previous build.
423 for ext in mods_configured:
424 fullpath = self.get_ext_fullpath(ext.name)
425 if os.path.exists(fullpath):
426 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000427
Victor Stinner00c77ae2020-03-04 18:44:49 +0100428 return (mods_built, mods_disabled)
429
430 def set_compiler_executables(self):
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000431 # When you run "make CC=altcc" or something similar, you really want
432 # those environment variables passed into the setup.py phase. Here's
433 # a small set of useful ones.
434 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000435 args = {}
436 # unfortunately, distutils doesn't let us provide separate C and C++
437 # compilers
438 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000439 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
440 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000441 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000442
Victor Stinner00c77ae2020-03-04 18:44:49 +0100443 def build_extensions(self):
444 self.set_srcdir()
445
446 # Detect which modules should be compiled
447 self.detect_modules()
448
449 self.remove_disabled()
450
451 self.update_sources_depends()
452 mods_built, mods_disabled = self.remove_configured_extensions()
453 self.set_compiler_executables()
454
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000455 build_ext.build_extensions(self)
456
Victor Stinner1ec63b62020-03-04 14:50:19 +0100457 if SUBPROCESS_BOOTSTRAP:
458 # Drop our custom subprocess module:
459 # use the newly built subprocess module
460 del sys.modules['subprocess']
461
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200462 for ext in self.extensions:
463 self.check_extension_import(ext)
464
Victor Stinner00c77ae2020-03-04 18:44:49 +0100465 self.summary(mods_built, mods_disabled)
466
467 def summary(self, mods_built, mods_disabled):
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300468 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400469 if self.failed or self.failed_on_import:
470 all_failed = self.failed + self.failed_on_import
471 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000472
473 def print_three_column(lst):
474 lst.sort(key=str.lower)
475 # guarantee zip() doesn't drop anything
476 while len(lst) % 3:
477 lst.append("")
478 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
479 print("%-*s %-*s %-*s" % (longest, e, longest, f,
480 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000481
Victor Stinner8058bda2019-03-01 15:31:45 +0100482 if self.missing:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000483 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400484 print("Python build finished successfully!")
485 print("The necessary bits to build these optional modules were not "
486 "found:")
Victor Stinner8058bda2019-03-01 15:31:45 +0100487 print_three_column(self.missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000488 print("To find the necessary bits, look in setup.py in"
489 " detect_modules() for the module's name.")
490 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000491
xdegayec0364fc2017-05-27 18:25:03 +0200492 if mods_built:
493 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200494 print("The following modules found by detect_modules() in"
495 " setup.py, have been")
496 print("built by the Makefile instead, as configured by the"
497 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200498 print_three_column([ext.name for ext in mods_built])
499 print()
500
501 if mods_disabled:
502 print()
503 print("The following modules found by detect_modules() in"
504 " setup.py have not")
505 print("been built, they are *disabled* in the Setup files:")
506 print_three_column([ext.name for ext in mods_disabled])
507 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200508
Christian Heimes9b60e552020-05-15 23:54:53 +0200509 if self.disabled_configure:
510 print()
511 print("The following modules found by detect_modules() in"
512 " setup.py have not")
513 print("been built, they are *disabled* by configure:")
514 print_three_column(self.disabled_configure)
515 print()
516
Guido van Rossumd8faa362007-04-27 19:54:29 +0000517 if self.failed:
518 failed = self.failed[:]
519 print()
520 print("Failed to build these modules:")
521 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000522 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000523
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400524 if self.failed_on_import:
525 failed = self.failed_on_import[:]
526 print()
527 print("Following modules built successfully"
528 " but were removed because they could not be imported:")
529 print_three_column(failed)
530 print()
531
Christian Heimes61d478c2018-01-27 15:51:38 +0100532 if any('_ssl' in l
Victor Stinner8058bda2019-03-01 15:31:45 +0100533 for l in (self.missing, self.failed, self.failed_on_import)):
Christian Heimes61d478c2018-01-27 15:51:38 +0100534 print()
535 print("Could not build the ssl module!")
536 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
537 "libssl with X509_VERIFY_PARAM_set1_host().")
538 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
539 "APIs, https://github.com/libressl-portable/portable/issues/381")
540 print()
541
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000542 def build_extension(self, ext):
543
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000544 if ext.name == '_ctypes':
545 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500546 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000547 return
548
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000549 try:
550 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000551 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000552 self.announce('WARNING: building of extension "%s" failed: %s' %
Victor Stinner625dbf22019-03-01 15:59:39 +0100553 (ext.name, why))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000554 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000555 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200556
557 def check_extension_import(self, ext):
558 # Don't try to import an extension that has failed to compile
559 if ext.name in self.failed:
560 self.announce(
561 'WARNING: skipping import check for failed build "%s"' %
562 ext.name, level=1)
563 return
564
Jack Jansenf49c6f92001-11-01 14:44:15 +0000565 # Workaround for Mac OS X: The Carbon-based modules cannot be
566 # reliably imported into a command-line Python
567 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000568 self.announce(
569 'WARNING: skipping import check for Carbon-based "%s"' %
570 ext.name)
571 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000572
Victor Stinner4cbea512019-02-28 17:48:38 +0100573 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000574 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000575 # Don't bother doing an import check when an extension was
576 # build with an explicit '-arch' flag on OSX. That's currently
577 # only used to build 32-bit only extensions in a 4-way
578 # universal build and loading 32-bit code into a 64-bit
579 # process will fail.
580 self.announce(
581 'WARNING: skipping import check for "%s"' %
582 ext.name)
583 return
584
Jason Tishler24cf7762002-05-22 16:46:15 +0000585 # Workaround for Cygwin: Cygwin currently has fork issues when many
586 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100587 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000588 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
589 % ext.name)
590 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000591 ext_filename = os.path.join(
592 self.build_lib,
593 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000594
595 # If the build directory didn't exist when setup.py was
596 # started, sys.path_importer_cache has a negative result
597 # cached. Clear that cache before trying to import.
598 sys.path_importer_cache.clear()
599
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200600 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100601 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200602 return
603
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400604 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700605 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
606 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000607 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400608 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000609 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400610 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000611 self.announce('*** WARNING: renaming "%s" since importing it'
612 ' failed: %s' % (ext.name, why), level=3)
613 assert not self.inplace
614 basename, tail = os.path.splitext(ext_filename)
615 newname = basename + "_failed" + tail
616 if os.path.exists(newname):
617 os.remove(newname)
618 os.rename(ext_filename, newname)
619
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000620 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000621 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000622 self.announce('*** WARNING: importing extension "%s" '
623 'failed with %s: %s' % (ext.name, exc_type, why),
624 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000625 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000626
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400627 def add_multiarch_paths(self):
628 # Debian/Ubuntu multiarch support.
629 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200630 cc = sysconfig.get_config_var('CC')
631 tmpfile = os.path.join(self.build_temp, 'multiarch')
632 if not os.path.exists(self.build_temp):
633 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200634 ret = run_command(
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200635 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
636 multiarch_path_component = ''
637 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200638 if ret == 0:
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200639 with open(tmpfile) as fp:
640 multiarch_path_component = fp.readline().strip()
641 finally:
642 os.unlink(tmpfile)
643
644 if multiarch_path_component != '':
645 add_dir_to_list(self.compiler.library_dirs,
646 '/usr/lib/' + multiarch_path_component)
647 add_dir_to_list(self.compiler.include_dirs,
648 '/usr/include/' + multiarch_path_component)
649 return
650
Barry Warsaw88e19452011-04-07 10:40:36 -0400651 if not find_executable('dpkg-architecture'):
652 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200653 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100654 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200655 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400656 tmpfile = os.path.join(self.build_temp, 'multiarch')
657 if not os.path.exists(self.build_temp):
658 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200659 ret = run_command(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200660 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
661 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400662 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200663 if ret == 0:
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400664 with open(tmpfile) as fp:
665 multiarch_path_component = fp.readline().strip()
666 add_dir_to_list(self.compiler.library_dirs,
667 '/usr/lib/' + multiarch_path_component)
668 add_dir_to_list(self.compiler.include_dirs,
669 '/usr/include/' + multiarch_path_component)
670 finally:
671 os.unlink(tmpfile)
672
pxinwr32f5fdd2019-02-27 19:09:28 +0800673 def add_cross_compiling_paths(self):
674 cc = sysconfig.get_config_var('CC')
675 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200676 if not os.path.exists(self.build_temp):
677 os.makedirs(self.build_temp)
Victor Stinner6b982c22020-04-01 01:10:07 +0200678 ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200679 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800680 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200681 in_incdirs = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200682 try:
Victor Stinner6b982c22020-04-01 01:10:07 +0200683 if ret == 0:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200684 with open(tmpfile) as fp:
685 for line in fp.readlines():
686 if line.startswith("gcc version"):
687 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800688 elif line.startswith("clang version"):
689 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200690 elif line.startswith("#include <...>"):
691 in_incdirs = True
692 elif line.startswith("End of search list"):
693 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800694 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200695 for d in line.strip().split("=")[1].split(":"):
696 d = os.path.normpath(d)
697 if '/gcc/' not in d:
698 add_dir_to_list(self.compiler.library_dirs,
699 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800700 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 +0200701 add_dir_to_list(self.compiler.include_dirs,
702 line.strip())
703 finally:
704 os.unlink(tmpfile)
705
Victor Stinnercfe172d2019-03-01 18:21:49 +0100706 def add_ldflags_cppflags(self):
Brett Cannon516592f2004-12-07 00:42:59 +0000707 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000708 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000709 # We must get the values from the Makefile and not the environment
710 # directly since an inconsistently reproducible issue comes up where
711 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000712 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000713 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000714 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
715 ('LDFLAGS', '-L', self.compiler.library_dirs),
716 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000717 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000718 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800719 parser = argparse.ArgumentParser()
720 parser.add_argument(arg_name, dest="dirs", action="append")
721 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000722 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000723 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000724 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000725
Victor Stinnercfe172d2019-03-01 18:21:49 +0100726 def configure_compiler(self):
727 # Ensure that /usr/local is always used, but the local build
728 # directories (i.e. '.' and 'Include') must be first. See issue
729 # 10520.
730 if not CROSS_COMPILING:
731 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
732 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
733 # only change this for cross builds for 3.3, issues on Mageia
734 if CROSS_COMPILING:
735 self.add_cross_compiling_paths()
736 self.add_multiarch_paths()
737 self.add_ldflags_cppflags()
738
Victor Stinner5ec33a12019-03-01 16:43:28 +0100739 def init_inc_lib_dirs(self):
Victor Stinner4cbea512019-02-28 17:48:38 +0100740 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100741 os.path.normpath(sys.base_prefix) != '/usr' and
742 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000743 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
744 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
745 # building a framework with different architectures than
746 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000747 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000748 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000749 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000750 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000751
xdegaye77f51392017-11-25 17:25:30 +0100752 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
753 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000754 # lib_dirs and inc_dirs are used to search for files;
755 # if a file is found in one of those directories, it can
756 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100757 if not CROSS_COMPILING:
Victor Stinner625dbf22019-03-01 15:59:39 +0100758 self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
759 self.inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100760 else:
xdegaye77f51392017-11-25 17:25:30 +0100761 # Add the sysroot paths. 'sysroot' is a compiler option used to
762 # set the logical path of the standard system headers and
763 # libraries.
Victor Stinner625dbf22019-03-01 15:59:39 +0100764 self.lib_dirs = (self.compiler.library_dirs +
765 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
766 self.inc_dirs = (self.compiler.include_dirs +
767 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
768 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000769
Brett Cannon4454a1f2005-04-15 20:32:39 +0000770 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000771 with open(config_h) as file:
Victor Stinner5ec33a12019-03-01 16:43:28 +0100772 self.config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000773
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000774 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100775 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Victor Stinner625dbf22019-03-01 15:59:39 +0100776 self.lib_dirs += ['/usr/ccs/lib']
Skip Montanaro22e00c42003-05-06 20:43:34 +0000777
Charles-François Natali5739e102012-04-12 19:07:25 +0200778 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100779 if HOST_PLATFORM == 'hp-ux11':
Victor Stinner625dbf22019-03-01 15:59:39 +0100780 self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
Charles-François Natali5739e102012-04-12 19:07:25 +0200781
Victor Stinner4cbea512019-02-28 17:48:38 +0100782 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000783 # This should work on any unixy platform ;-)
784 # If the user has bothered specifying additional -I and -L flags
785 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000786 #
787 # NOTE: using shlex.split would technically be more correct, but
788 # also gives a bootstrap problem. Let's hope nobody uses
789 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000790 cflags, ldflags = sysconfig.get_config_vars(
791 'CFLAGS', 'LDFLAGS')
792 for item in cflags.split():
793 if item.startswith('-I'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100794 self.inc_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000795
796 for item in ldflags.split():
797 if item.startswith('-L'):
Victor Stinner625dbf22019-03-01 15:59:39 +0100798 self.lib_dirs.append(item[2:])
Thomas Wouters477c8d52006-05-27 19:21:47 +0000799
Victor Stinner5ec33a12019-03-01 16:43:28 +0100800 def detect_simple_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000801 #
802 # The following modules are all pretty straightforward, and compile
803 # on pretty much any POSIXish platform.
804 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000805
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000806 # array objects
Victor Stinner8058bda2019-03-01 15:31:45 +0100807 self.add(Extension('array', ['arraymodule.c']))
Martin Panterc9deece2016-02-03 05:19:44 +0000808
Yury Selivanovf23746a2018-01-22 19:11:18 -0500809 # Context Variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100810 self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
Yury Selivanovf23746a2018-01-22 19:11:18 -0500811
Martin Panterc9deece2016-02-03 05:19:44 +0000812 shared_math = 'Modules/_math.o'
Victor Stinnercfe172d2019-03-01 18:21:49 +0100813
814 # math library functions, e.g. sin()
815 self.add(Extension('math', ['mathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100816 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100817 extra_objects=[shared_math],
818 depends=['_math.h', shared_math],
819 libraries=['m']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100820
821 # complex math library functions
822 self.add(Extension('cmath', ['cmathmodule.c'],
Victor Stinnere9e7d282020-02-12 22:54:42 +0100823 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
Victor Stinner8058bda2019-03-01 15:31:45 +0100824 extra_objects=[shared_math],
825 depends=['_math.h', shared_math],
826 libraries=['m']))
Victor Stinnere0be4232011-10-25 13:06:09 +0200827
828 # time libraries: librt may be needed for clock_gettime()
829 time_libs = []
830 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
831 if lib:
832 time_libs.append(lib)
833
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000834 # time operations and variables
Victor Stinner8058bda2019-03-01 15:31:45 +0100835 self.add(Extension('time', ['timemodule.c'],
836 libraries=time_libs))
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800837 # libm is needed by delta_new() that uses round() and by accum() that
838 # uses modf().
Victor Stinner8058bda2019-03-01 15:31:45 +0100839 self.add(Extension('_datetime', ['_datetimemodule.c'],
840 libraries=['m']))
Paul Ganssle62972d92020-05-16 04:20:06 -0400841 # zoneinfo module
842 self.add(Extension('_zoneinfo', ['_zoneinfo.c'])),
Christian Heimesfe337bf2008-03-23 21:54:12 +0000843 # random number generator implemented in C
Victor Stinner9f5fe792020-04-17 19:05:35 +0200844 self.add(Extension("_random", ["_randommodule.c"],
845 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Raymond Hettinger0c410272004-01-05 10:13:35 +0000846 # bisect
Victor Stinner8058bda2019-03-01 15:31:45 +0100847 self.add(Extension("_bisect", ["_bisectmodule.c"]))
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000848 # heapq
Victor Stinner8058bda2019-03-01 15:31:45 +0100849 self.add(Extension("_heapq", ["_heapqmodule.c"]))
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000850 # C-optimized pickle replacement
Victor Stinner5c75f372019-04-17 23:02:26 +0200851 self.add(Extension("_pickle", ["_pickle.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200852 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Collin Winter670e6922007-03-21 02:57:17 +0000853 # atexit
Victor Stinner8058bda2019-03-01 15:31:45 +0100854 self.add(Extension("atexit", ["atexitmodule.c"]))
Christian Heimes90540002008-05-08 14:29:10 +0000855 # _json speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100856 self.add(Extension("_json", ["_json.c"],
Victor Stinner57491342019-04-23 12:26:33 +0200857 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinnercfe172d2019-03-01 18:21:49 +0100858
Fred Drake0e474a82007-10-11 18:01:43 +0000859 # profiler (_lsprof is for cProfile.py)
Victor Stinner8058bda2019-03-01 15:31:45 +0100860 self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000861 # static Unicode character database
Victor Stinner8058bda2019-03-01 15:31:45 +0100862 self.add(Extension('unicodedata', ['unicodedata.c'],
863 depends=['unicodedata_db.h', 'unicodename_db.h']))
Larry Hastings3a907972013-11-23 14:49:22 -0800864 # _opcode module
Victor Stinner8058bda2019-03-01 15:31:45 +0100865 self.add(Extension('_opcode', ['_opcode.c']))
INADA Naoki9f2ce252016-10-15 15:39:19 +0900866 # asyncio speedups
Chris Jerdonekda742ba2020-05-17 22:47:31 -0700867 self.add(Extension("_asyncio", ["_asynciomodule.c"],
868 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000869 # _abc speedups
Victor Stinner8058bda2019-03-01 15:31:45 +0100870 self.add(Extension("_abc", ["_abc.c"]))
Antoine Pitrou94e16962018-01-16 00:27:16 +0100871 # _queue module
Victor Stinner8058bda2019-03-01 15:31:45 +0100872 self.add(Extension("_queue", ["_queuemodule.c"]))
Dong-hee Na0a18ee42019-08-24 07:20:30 +0900873 # _statistics module
874 self.add(Extension("_statistics", ["_statisticsmodule.c"]))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000875
876 # Modules with some UNIX dependencies -- on by default:
877 # (If you have a really backward UNIX, select and socket may not be
878 # supported...)
879
880 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000881 libs = []
Victor Stinner5ec33a12019-03-01 16:43:28 +0100882 if (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
Antoine Pitroua3000072010-09-07 14:52:42 +0000883 # May be necessary on AIX for flock function
884 libs = ['bsd']
Victor Stinner8058bda2019-03-01 15:31:45 +0100885 self.add(Extension('fcntl', ['fcntlmodule.c'],
886 libraries=libs))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000887 # pwd(3)
Victor Stinner8058bda2019-03-01 15:31:45 +0100888 self.add(Extension('pwd', ['pwdmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000889 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800890 if not VXWORKS:
Victor Stinner8058bda2019-03-01 15:31:45 +0100891 self.add(Extension('grp', ['grpmodule.c']))
Ronald Oussoren94f25282010-05-05 19:11:21 +0000892 # spwd, shadow passwords
Victor Stinner5ec33a12019-03-01 16:43:28 +0100893 if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
894 self.config_h_vars.get('HAVE_GETSPENT', False)):
Victor Stinner8058bda2019-03-01 15:31:45 +0100895 self.add(Extension('spwd', ['spwdmodule.c']))
Michael Felt08970cb2019-06-21 15:58:00 +0200896 # AIX has shadow passwords, but access is not via getspent(), etc.
897 # module support is not expected so it not 'missing'
898 elif not AIX:
Victor Stinner8058bda2019-03-01 15:31:45 +0100899 self.missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000900
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000901 # select(2); not on ancient System V
Victor Stinner8058bda2019-03-01 15:31:45 +0100902 self.add(Extension('select', ['selectmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000903
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000904 # Fred Drake's interface to the Python parser
Victor Stinner8058bda2019-03-01 15:31:45 +0100905 self.add(Extension('parser', ['parsermodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000906
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000907 # Memory-mapped files (also works on Win32).
Victor Stinner8058bda2019-03-01 15:31:45 +0100908 self.add(Extension('mmap', ['mmapmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000909
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000910 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000911 # syslog daemon interface
Victor Stinner8058bda2019-03-01 15:31:45 +0100912 self.add(Extension('syslog', ['syslogmodule.c']))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000913
Eric Snow7f8bfc92018-01-29 18:23:44 -0700914 # Python interface to subinterpreter C-API.
Eric Snowc11183c2019-03-15 16:35:46 -0600915 self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
Eric Snow7f8bfc92018-01-29 18:23:44 -0700916
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000917 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000918 # Here ends the simple stuff. From here on, modules need certain
919 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000920 #
921
922 # Multimedia modules
923 # These don't work for 64-bit platforms!!!
924 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200925 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000926 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000927 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000928 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200929 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800930 # audioop needs libm for floor() in multiple functions.
Victor Stinner8058bda2019-03-01 15:31:45 +0100931 self.add(Extension('audioop', ['audioop.c'],
932 libraries=['m']))
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000933
Victor Stinner5ec33a12019-03-01 16:43:28 +0100934 # CSV files
935 self.add(Extension('_csv', ['_csv.c']))
936
937 # POSIX subprocess module helper.
938 self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
939
Victor Stinnercfe172d2019-03-01 18:21:49 +0100940 def detect_test_extensions(self):
941 # Python C API test module
942 self.add(Extension('_testcapi', ['_testcapimodule.c'],
943 depends=['testcapi_long.h']))
944
Victor Stinner23bace22019-04-18 11:37:26 +0200945 # Python Internal C API test module
946 self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
Victor Stinner57491342019-04-23 12:26:33 +0200947 extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
Victor Stinner23bace22019-04-18 11:37:26 +0200948
Victor Stinnercfe172d2019-03-01 18:21:49 +0100949 # Python PEP-3118 (buffer protocol) test module
950 self.add(Extension('_testbuffer', ['_testbuffer.c']))
951
952 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
953 self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
954
955 # Test multi-phase extension module init (PEP 489)
956 self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
957
958 # Fuzz tests.
959 self.add(Extension('_xxtestfuzz',
960 ['_xxtestfuzz/_xxtestfuzz.c',
961 '_xxtestfuzz/fuzzer.c']))
962
Victor Stinner5ec33a12019-03-01 16:43:28 +0100963 def detect_readline_curses(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000964 # readline
Victor Stinner625dbf22019-03-01 15:59:39 +0100965 do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000966 readline_termcap_library = ""
967 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200968 # Cannot use os.popen here in py3k.
969 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
970 if not os.path.exists(self.build_temp):
971 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000972 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200973 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100974 if CROSS_COMPILING:
Victor Stinner6b982c22020-04-01 01:10:07 +0200975 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
doko@ubuntu.com58844492012-06-30 18:25:32 +0200976 % (sysconfig.get_config_var('READELF'),
977 do_readline, tmpfile))
978 elif find_executable('ldd'):
Victor Stinner6b982c22020-04-01 01:10:07 +0200979 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
doko@ubuntu.com58844492012-06-30 18:25:32 +0200980 else:
Victor Stinner6b982c22020-04-01 01:10:07 +0200981 ret = 1
982 if ret == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +0000983 with open(tmpfile) as fp:
984 for ln in fp:
985 if 'curses' in ln:
986 readline_termcap_library = re.sub(
987 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
988 ).rstrip()
989 break
990 # termcap interface split out from ncurses
991 if 'tinfo' in ln:
992 readline_termcap_library = 'tinfo'
993 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200994 if os.path.exists(tmpfile):
995 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +0000996 # Issue 7384: If readline is already linked against curses,
997 # use the same library for the readline and curses modules.
998 if 'curses' in readline_termcap_library:
999 curses_library = readline_termcap_library
Victor Stinner625dbf22019-03-01 15:59:39 +01001000 elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +00001001 curses_library = 'ncursesw'
Michael Felt08970cb2019-06-21 15:58:00 +02001002 # Issue 36210: OSS provided ncurses does not link on AIX
1003 # Use IBM supplied 'curses' for successful build of _curses
1004 elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
1005 curses_library = 'curses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001006 elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001007 curses_library = 'ncurses'
Victor Stinner625dbf22019-03-01 15:59:39 +01001008 elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001009 curses_library = 'curses'
1010
Victor Stinner4cbea512019-02-28 17:48:38 +01001011 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001012 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +00001013 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -07001014 if (dep_target and
1015 (tuple(int(n) for n in dep_target.split('.')[0:2])
1016 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +00001017 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001018 if os_release < 9:
1019 # MacOSX 10.4 has a broken readline. Don't try to build
1020 # the readline module unless the user has installed a fixed
1021 # readline package
Victor Stinner625dbf22019-03-01 15:59:39 +01001022 if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
Ronald Oussoren2efd9242009-09-20 14:53:22 +00001023 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +00001024 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +01001025 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001026 # In every directory on the search path search for a dynamic
1027 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +00001028 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +00001029 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001030 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +00001031 readline_extra_link_args = ('-Wl,-search_paths_first',)
1032 else:
1033 readline_extra_link_args = ()
1034
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001035 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +00001036 if readline_termcap_library:
1037 pass # Issue 7384: Already linked against curses or tinfo.
1038 elif curses_library:
1039 readline_libs.append(curses_library)
Victor Stinner625dbf22019-03-01 15:59:39 +01001040 elif self.compiler.find_library_file(self.lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001041 ['/usr/lib/termcap'],
1042 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +00001043 readline_libs.append('termcap')
Victor Stinner8058bda2019-03-01 15:31:45 +01001044 self.add(Extension('readline', ['readline.c'],
1045 library_dirs=['/usr/lib/termcap'],
1046 extra_link_args=readline_extra_link_args,
1047 libraries=readline_libs))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001048 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001049 self.missing.append('readline')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001050
Victor Stinner5ec33a12019-03-01 16:43:28 +01001051 # Curses support, requiring the System V version of curses, often
1052 # provided by the ncurses library.
1053 curses_defines = []
1054 curses_includes = []
1055 panel_library = 'panel'
1056 if curses_library == 'ncursesw':
1057 curses_defines.append(('HAVE_NCURSESW', '1'))
1058 if not CROSS_COMPILING:
1059 curses_includes.append('/usr/include/ncursesw')
1060 # Bug 1464056: If _curses.so links with ncursesw,
1061 # _curses_panel.so must link with panelw.
1062 panel_library = 'panelw'
1063 if MACOS:
1064 # On OS X, there is no separate /usr/lib/libncursesw nor
1065 # libpanelw. If we are here, we found a locally-supplied
1066 # version of libncursesw. There should also be a
1067 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1068 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1069 # ncurses wide char support
1070 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
1071 elif MACOS and curses_library == 'ncurses':
1072 # Building with the system-suppied combined libncurses/libpanel
1073 curses_defines.append(('HAVE_NCURSESW', '1'))
1074 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Tim Peters2c60f7a2003-01-29 03:49:43 +00001075
Victor Stinnercfe172d2019-03-01 18:21:49 +01001076 curses_enabled = True
Victor Stinner5ec33a12019-03-01 16:43:28 +01001077 if curses_library.startswith('ncurses'):
1078 curses_libs = [curses_library]
1079 self.add(Extension('_curses', ['_cursesmodule.c'],
1080 include_dirs=curses_includes,
1081 define_macros=curses_defines,
1082 libraries=curses_libs))
1083 elif curses_library == 'curses' and not MACOS:
1084 # OSX has an old Berkeley curses, not good enough for
1085 # the _curses module.
1086 if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
1087 curses_libs = ['curses', 'terminfo']
1088 elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
1089 curses_libs = ['curses', 'termcap']
1090 else:
1091 curses_libs = ['curses']
1092
1093 self.add(Extension('_curses', ['_cursesmodule.c'],
1094 define_macros=curses_defines,
1095 libraries=curses_libs))
1096 else:
Victor Stinnercfe172d2019-03-01 18:21:49 +01001097 curses_enabled = False
Victor Stinner5ec33a12019-03-01 16:43:28 +01001098 self.missing.append('_curses')
1099
1100 # If the curses module is enabled, check for the panel module
Michael Felt08970cb2019-06-21 15:58:00 +02001101 # _curses_panel needs some form of ncurses
1102 skip_curses_panel = True if AIX else False
1103 if (curses_enabled and not skip_curses_panel and
1104 self.compiler.find_library_file(self.lib_dirs, panel_library)):
Victor Stinner5ec33a12019-03-01 16:43:28 +01001105 self.add(Extension('_curses_panel', ['_curses_panel.c'],
Michael Felt08970cb2019-06-21 15:58:00 +02001106 include_dirs=curses_includes,
1107 define_macros=curses_defines,
1108 libraries=[panel_library, *curses_libs]))
1109 elif not skip_curses_panel:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001110 self.missing.append('_curses_panel')
1111
1112 def detect_crypt(self):
1113 # crypt module.
pxinwr236d0b72019-04-15 17:02:20 +08001114 if VXWORKS:
1115 # bpo-31904: crypt() function is not provided by VxWorks.
1116 # DES_crypt() OpenSSL provides is too weak to implement
1117 # the encryption.
1118 return
1119
Victor Stinner625dbf22019-03-01 15:59:39 +01001120 if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +00001121 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +00001122 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +00001123 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +08001124
pxinwr236d0b72019-04-15 17:02:20 +08001125 self.add(Extension('_crypt', ['_cryptmodule.c'],
Victor Stinner8058bda2019-03-01 15:31:45 +01001126 libraries=libs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001127
Victor Stinner5ec33a12019-03-01 16:43:28 +01001128 def detect_socket(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001129 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +08001130 if not VXWORKS:
Erlend Egeberg Aasland9a45bfe2020-05-17 08:32:46 +02001131 kwargs = {'depends': ['socketmodule.h']}
1132 if MACOS:
1133 # Issue #35569: Expose RFC 3542 socket options.
1134 kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542']
1135
1136 self.add(Extension('_socket', ['socketmodule.c'], **kwargs))
Victor Stinner625dbf22019-03-01 15:59:39 +01001137 elif self.compiler.find_library_file(self.lib_dirs, 'net'):
pxinwr32f5fdd2019-02-27 19:09:28 +08001138 libs = ['net']
Victor Stinner8058bda2019-03-01 15:31:45 +01001139 self.add(Extension('_socket', ['socketmodule.c'],
1140 depends=['socketmodule.h'],
1141 libraries=libs))
pxinwr32f5fdd2019-02-27 19:09:28 +08001142
Victor Stinner5ec33a12019-03-01 16:43:28 +01001143 def detect_dbm_gdbm(self):
Georg Brandl489cb4f2009-07-11 10:08:49 +00001144 # Modules that provide persistent dictionary-like semantics. You will
1145 # probably want to arrange for at least one of them to be available on
1146 # your machine, though none are defined by default because of library
1147 # dependencies. The Python module dbm/__init__.py provides an
1148 # implementation independent wrapper for these; dbm/dumb.py provides
1149 # similar functionality (but slower of course) implemented in Python.
1150
1151 # Sleepycat^WOracle Berkeley DB interface.
1152 # http://www.oracle.com/database/berkeley-db/db/index.html
1153 #
1154 # This requires the Sleepycat^WOracle DB code. The supported versions
1155 # are set below. Visit the URL above to download
1156 # a release. Most open source OSes come with one or more
1157 # versions of BerkeleyDB already installed.
1158
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +02001159 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001160 min_db_ver = (3, 3)
1161 db_setup_debug = False # verbose debug prints from this script?
1162
1163 def allow_db_ver(db_ver):
1164 """Returns a boolean if the given BerkeleyDB version is acceptable.
1165
1166 Args:
1167 db_ver: A tuple of the version to verify.
1168 """
1169 if not (min_db_ver <= db_ver <= max_db_ver):
1170 return False
1171 return True
1172
1173 def gen_db_minor_ver_nums(major):
1174 if major == 4:
1175 for x in range(max_db_ver[1]+1):
1176 if allow_db_ver((4, x)):
1177 yield x
1178 elif major == 3:
1179 for x in (3,):
1180 if allow_db_ver((3, x)):
1181 yield x
1182 else:
1183 raise ValueError("unknown major BerkeleyDB version", major)
1184
1185 # construct a list of paths to look for the header file in on
1186 # top of the normal inc_dirs.
1187 db_inc_paths = [
1188 '/usr/include/db4',
1189 '/usr/local/include/db4',
1190 '/opt/sfw/include/db4',
1191 '/usr/include/db3',
1192 '/usr/local/include/db3',
1193 '/opt/sfw/include/db3',
1194 # Fink defaults (http://fink.sourceforge.net/)
1195 '/sw/include/db4',
1196 '/sw/include/db3',
1197 ]
1198 # 4.x minor number specific paths
1199 for x in gen_db_minor_ver_nums(4):
1200 db_inc_paths.append('/usr/include/db4%d' % x)
1201 db_inc_paths.append('/usr/include/db4.%d' % x)
1202 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1203 db_inc_paths.append('/usr/local/include/db4%d' % x)
1204 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1205 db_inc_paths.append('/opt/db-4.%d/include' % x)
1206 # MacPorts default (http://www.macports.org/)
1207 db_inc_paths.append('/opt/local/include/db4%d' % x)
1208 # 3.x minor number specific paths
1209 for x in gen_db_minor_ver_nums(3):
1210 db_inc_paths.append('/usr/include/db3%d' % x)
1211 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1212 db_inc_paths.append('/usr/local/include/db3%d' % x)
1213 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1214 db_inc_paths.append('/opt/db-3.%d/include' % x)
1215
Victor Stinner4cbea512019-02-28 17:48:38 +01001216 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001217 db_inc_paths = []
1218
Georg Brandl489cb4f2009-07-11 10:08:49 +00001219 # Add some common subdirectories for Sleepycat DB to the list,
1220 # based on the standard include directories. This way DB3/4 gets
1221 # picked up when it is installed in a non-standard prefix and
1222 # the user has added that prefix into inc_dirs.
1223 std_variants = []
Victor Stinner625dbf22019-03-01 15:59:39 +01001224 for dn in self.inc_dirs:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001225 std_variants.append(os.path.join(dn, 'db3'))
1226 std_variants.append(os.path.join(dn, 'db4'))
1227 for x in gen_db_minor_ver_nums(4):
1228 std_variants.append(os.path.join(dn, "db4%d"%x))
1229 std_variants.append(os.path.join(dn, "db4.%d"%x))
1230 for x in gen_db_minor_ver_nums(3):
1231 std_variants.append(os.path.join(dn, "db3%d"%x))
1232 std_variants.append(os.path.join(dn, "db3.%d"%x))
1233
1234 db_inc_paths = std_variants + db_inc_paths
1235 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1236
1237 db_ver_inc_map = {}
1238
Victor Stinner4cbea512019-02-28 17:48:38 +01001239 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001240 sysroot = macosx_sdk_root()
1241
Georg Brandl489cb4f2009-07-11 10:08:49 +00001242 class db_found(Exception): pass
1243 try:
1244 # See whether there is a Sleepycat header in the standard
1245 # search path.
Victor Stinner625dbf22019-03-01 15:59:39 +01001246 for d in self.inc_dirs + db_inc_paths:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001247 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001248 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001249 f = os.path.join(sysroot, d[1:], "db.h")
1250
Georg Brandl489cb4f2009-07-11 10:08:49 +00001251 if db_setup_debug: print("db: looking for db.h in", f)
1252 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001253 with open(f, 'rb') as file:
1254 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001255 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001256 if m:
1257 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001258 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001259 db_minor = int(m.group(1))
1260 db_ver = (db_major, db_minor)
1261
1262 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1263 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001264 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001265 db_patch = int(m.group(1))
1266 if db_patch < 21:
1267 print("db.h:", db_ver, "patch", db_patch,
1268 "being ignored (4.6.x must be >= 4.6.21)")
1269 continue
1270
1271 if ( (db_ver not in db_ver_inc_map) and
1272 allow_db_ver(db_ver) ):
1273 # save the include directory with the db.h version
1274 # (first occurrence only)
1275 db_ver_inc_map[db_ver] = d
1276 if db_setup_debug:
1277 print("db.h: found", db_ver, "in", d)
1278 else:
1279 # we already found a header for this library version
1280 if db_setup_debug: print("db.h: ignoring", d)
1281 else:
1282 # ignore this header, it didn't contain a version number
1283 if db_setup_debug:
1284 print("db.h: no version number version in", d)
1285
1286 db_found_vers = list(db_ver_inc_map.keys())
1287 db_found_vers.sort()
1288
1289 while db_found_vers:
1290 db_ver = db_found_vers.pop()
1291 db_incdir = db_ver_inc_map[db_ver]
1292
1293 # check lib directories parallel to the location of the header
1294 db_dirs_to_check = [
1295 db_incdir.replace("include", 'lib64'),
1296 db_incdir.replace("include", 'lib'),
1297 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001298
Victor Stinner4cbea512019-02-28 17:48:38 +01001299 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001300 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1301
1302 else:
1303 # Same as other branch, but takes OSX SDK into account
1304 tmp = []
1305 for dn in db_dirs_to_check:
1306 if is_macosx_sdk_path(dn):
1307 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1308 tmp.append(dn)
1309 else:
1310 if os.path.isdir(dn):
1311 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001312 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001313
1314 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001315
Ezio Melotti42da6632011-03-15 05:18:48 +02001316 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001317 # XXX should we -ever- look for a dbX name? Do any
1318 # systems really not name their library by version and
1319 # symlink to more general names?
1320 for dblib in (('db-%d.%d' % db_ver),
1321 ('db%d%d' % db_ver),
1322 ('db%d' % db_ver[0])):
1323 dblib_file = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001324 db_dirs_to_check + self.lib_dirs, dblib )
Georg Brandl489cb4f2009-07-11 10:08:49 +00001325 if dblib_file:
1326 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1327 raise db_found
1328 else:
1329 if db_setup_debug: print("db lib: ", dblib, "not found")
1330
1331 except db_found:
1332 if db_setup_debug:
1333 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1334 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001335 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001336 # Only add the found library and include directories if they aren't
1337 # already being searched. This avoids an explicit runtime library
1338 # dependency.
Victor Stinner625dbf22019-03-01 15:59:39 +01001339 if db_incdir in self.inc_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001340 db_incs = None
1341 else:
1342 db_incs = [db_incdir]
Victor Stinner625dbf22019-03-01 15:59:39 +01001343 if dblib_dir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001344 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001345 else:
1346 if db_setup_debug: print("db: no appropriate library found")
1347 db_incs = None
1348 dblibs = []
1349 dblib_dir = None
1350
Victor Stinner5ec33a12019-03-01 16:43:28 +01001351 dbm_setup_debug = False # verbose debug prints from this script?
1352 dbm_order = ['gdbm']
1353 # The standard Unix dbm module:
1354 if not CYGWIN:
1355 config_args = [arg.strip("'")
1356 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
1357 dbm_args = [arg for arg in config_args
1358 if arg.startswith('--with-dbmliborder=')]
1359 if dbm_args:
1360 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
1361 else:
1362 dbm_order = "ndbm:gdbm:bdb".split(":")
1363 dbmext = None
1364 for cand in dbm_order:
1365 if cand == "ndbm":
1366 if find_file("ndbm.h", self.inc_dirs, []) is not None:
1367 # Some systems have -lndbm, others have -lgdbm_compat,
1368 # others don't have either
1369 if self.compiler.find_library_file(self.lib_dirs,
1370 'ndbm'):
1371 ndbm_libs = ['ndbm']
1372 elif self.compiler.find_library_file(self.lib_dirs,
1373 'gdbm_compat'):
1374 ndbm_libs = ['gdbm_compat']
1375 else:
1376 ndbm_libs = []
1377 if dbm_setup_debug: print("building dbm using ndbm")
1378 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1379 define_macros=[
1380 ('HAVE_NDBM_H',None),
1381 ],
1382 libraries=ndbm_libs)
1383 break
1384
1385 elif cand == "gdbm":
1386 if self.compiler.find_library_file(self.lib_dirs, 'gdbm'):
1387 gdbm_libs = ['gdbm']
1388 if self.compiler.find_library_file(self.lib_dirs,
1389 'gdbm_compat'):
1390 gdbm_libs.append('gdbm_compat')
1391 if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
1392 if dbm_setup_debug: print("building dbm using gdbm")
1393 dbmext = Extension(
1394 '_dbm', ['_dbmmodule.c'],
1395 define_macros=[
1396 ('HAVE_GDBM_NDBM_H', None),
1397 ],
1398 libraries = gdbm_libs)
1399 break
1400 if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
1401 if dbm_setup_debug: print("building dbm using gdbm")
1402 dbmext = Extension(
1403 '_dbm', ['_dbmmodule.c'],
1404 define_macros=[
1405 ('HAVE_GDBM_DASH_NDBM_H', None),
1406 ],
1407 libraries = gdbm_libs)
1408 break
1409 elif cand == "bdb":
1410 if dblibs:
1411 if dbm_setup_debug: print("building dbm using bdb")
1412 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1413 library_dirs=dblib_dir,
1414 runtime_library_dirs=dblib_dir,
1415 include_dirs=db_incs,
1416 define_macros=[
1417 ('HAVE_BERKDB_H', None),
1418 ('DB_DBM_HSEARCH', None),
1419 ],
1420 libraries=dblibs)
1421 break
1422 if dbmext is not None:
1423 self.add(dbmext)
1424 else:
1425 self.missing.append('_dbm')
1426
1427 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
1428 if ('gdbm' in dbm_order and
1429 self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
1430 self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1431 libraries=['gdbm']))
1432 else:
1433 self.missing.append('_gdbm')
1434
1435 def detect_sqlite(self):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001436 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001437 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001438
1439 # We hunt for #define SQLITE_VERSION "n.n.n"
Charles Pigottad0daf52019-04-26 16:38:12 +01001440 # We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001441 sqlite_incdir = sqlite_libdir = None
1442 sqlite_inc_paths = [ '/usr/include',
1443 '/usr/include/sqlite',
1444 '/usr/include/sqlite3',
1445 '/usr/local/include',
1446 '/usr/local/include/sqlite',
1447 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001448 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001449 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001450 sqlite_inc_paths = []
gescheitb9a03762019-07-13 06:15:49 +03001451 MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001452 MIN_SQLITE_VERSION = ".".join([str(x)
1453 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001454
1455 # Scan the default include directories before the SQLite specific
1456 # ones. This allows one to override the copy of sqlite on OSX,
1457 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001458 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001459 sysroot = macosx_sdk_root()
1460
Victor Stinner625dbf22019-03-01 15:59:39 +01001461 for d_ in self.inc_dirs + sqlite_inc_paths:
Ned Deily9b635832012-08-05 15:13:33 -07001462 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001463 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001464 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001465
Ned Deily9b635832012-08-05 15:13:33 -07001466 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001467 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001468 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001469 with open(f) as file:
1470 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001471 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001472 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001473 if m:
1474 sqlite_version = m.group(1)
1475 sqlite_version_tuple = tuple([int(x)
1476 for x in sqlite_version.split(".")])
1477 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1478 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001479 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001480 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001481 sqlite_incdir = d
1482 break
1483 else:
1484 if sqlite_setup_debug:
Charles Pigottad0daf52019-04-26 16:38:12 +01001485 print("%s: version %s is too old, need >= %s"%(d,
Guido van Rossum452bf512007-02-09 05:32:43 +00001486 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001487 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001488 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001489
1490 if sqlite_incdir:
1491 sqlite_dirs_to_check = [
1492 os.path.join(sqlite_incdir, '..', 'lib64'),
1493 os.path.join(sqlite_incdir, '..', 'lib'),
1494 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1495 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1496 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001497 sqlite_libfile = self.compiler.find_library_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01001498 sqlite_dirs_to_check + self.lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001499 if sqlite_libfile:
1500 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001501
1502 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001503 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001504 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001505 '_sqlite/cursor.c',
1506 '_sqlite/microprotocols.c',
1507 '_sqlite/module.c',
1508 '_sqlite/prepare_protocol.c',
1509 '_sqlite/row.c',
1510 '_sqlite/statement.c',
1511 '_sqlite/util.c', ]
1512
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001513 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001514 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001515 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1516 else:
1517 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1518
Benjamin Peterson076ed002010-10-31 17:11:02 +00001519 # Enable support for loadable extensions in the sqlite3 module
1520 # if --enable-loadable-sqlite-extensions configure option is used.
1521 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1522 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001523
Victor Stinner4cbea512019-02-28 17:48:38 +01001524 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001525 # In every directory on the search path search for a dynamic
1526 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001527 # for dynamic libraries on the entire path.
1528 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001529 # before the dynamic library in /usr/lib.
1530 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1531 else:
1532 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001533
Brett Cannonc5011fe2011-06-06 20:09:10 -07001534 include_dirs = ["Modules/_sqlite"]
1535 # Only include the directory where sqlite was found if it does
1536 # not already exist in set include directories, otherwise you
1537 # can end up with a bad search path order.
1538 if sqlite_incdir not in self.compiler.include_dirs:
1539 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001540 # avoid a runtime library path for a system library dir
Victor Stinner625dbf22019-03-01 15:59:39 +01001541 if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001542 sqlite_libdir = None
Victor Stinner8058bda2019-03-01 15:31:45 +01001543 self.add(Extension('_sqlite3', sqlite_srcs,
1544 define_macros=sqlite_defines,
1545 include_dirs=include_dirs,
1546 library_dirs=sqlite_libdir,
1547 extra_link_args=sqlite_extra_link_args,
1548 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001549 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001550 self.missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001551
Victor Stinner5ec33a12019-03-01 16:43:28 +01001552 def detect_platform_specific_exts(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001553 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001554 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001555 if not VXWORKS:
1556 # Steen Lumholt's termios module
Victor Stinner8058bda2019-03-01 15:31:45 +01001557 self.add(Extension('termios', ['termios.c']))
pxinwr32f5fdd2019-02-27 19:09:28 +08001558 # Jeremy Hylton's rlimit interface
Victor Stinner8058bda2019-03-01 15:31:45 +01001559 self.add(Extension('resource', ['resource.c']))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001560 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001561 self.missing.extend(['resource', 'termios'])
Christian Heimes29a7df72018-01-26 23:28:46 +01001562
Victor Stinner5ec33a12019-03-01 16:43:28 +01001563 # Platform-specific libraries
1564 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
1565 self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
Michael Felt08970cb2019-06-21 15:58:00 +02001566 elif not AIX:
Victor Stinner5ec33a12019-03-01 16:43:28 +01001567 self.missing.append('ossaudiodev')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001568
Victor Stinner5ec33a12019-03-01 16:43:28 +01001569 if MACOS:
Ned Deily951ab582020-05-18 11:31:21 -04001570 self.add(Extension('_scproxy', ['_scproxy.c'],
Victor Stinner5ec33a12019-03-01 16:43:28 +01001571 extra_link_args=[
1572 '-framework', 'SystemConfiguration',
Ned Deily951ab582020-05-18 11:31:21 -04001573 '-framework', 'CoreFoundation']))
Fredrik Lundhade711a2001-01-24 08:00:28 +00001574
Victor Stinner5ec33a12019-03-01 16:43:28 +01001575 def detect_compress_exts(self):
Barry Warsaw259b1e12002-08-13 20:09:26 +00001576 # Andrew Kuchling's zlib module. Note that some versions of zlib
1577 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1578 # http://www.cert.org/advisories/CA-2002-07.html
1579 #
1580 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1581 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1582 # now, we still accept 1.1.3, because we think it's difficult to
1583 # exploit this in Python, and we'd rather make it RedHat's problem
1584 # than our problem <wink>.
1585 #
1586 # You can upgrade zlib to version 1.1.4 yourself by going to
1587 # http://www.gzip.org/zlib/
Victor Stinner625dbf22019-03-01 15:59:39 +01001588 zlib_inc = find_file('zlib.h', [], self.inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001589 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001590 if zlib_inc is not None:
1591 zlib_h = zlib_inc[0] + '/zlib.h'
1592 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001593 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001594 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001595 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001596 with open(zlib_h) as fp:
1597 while 1:
1598 line = fp.readline()
1599 if not line:
1600 break
1601 if line.startswith('#define ZLIB_VERSION'):
1602 version = line.split()[2]
1603 break
Guido van Rossume6970912001-04-15 15:16:12 +00001604 if version >= version_req:
Victor Stinner625dbf22019-03-01 15:59:39 +01001605 if (self.compiler.find_library_file(self.lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001606 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001607 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1608 else:
1609 zlib_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001610 self.add(Extension('zlib', ['zlibmodule.c'],
1611 libraries=['z'],
1612 extra_link_args=zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001613 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001614 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001615 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001616 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001617 self.missing.append('zlib')
Guido van Rossumd8faa362007-04-27 19:54:29 +00001618 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001619 self.missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001620
Christian Heimes1dc54002008-03-24 02:19:29 +00001621 # Helper module for various ascii-encoders. Uses zlib for an optimized
1622 # crc32 if we have it. Otherwise binascii uses its own.
1623 if have_zlib:
1624 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1625 libraries = ['z']
1626 extra_link_args = zlib_extra_link_args
1627 else:
1628 extra_compile_args = []
1629 libraries = []
1630 extra_link_args = []
Victor Stinner8058bda2019-03-01 15:31:45 +01001631 self.add(Extension('binascii', ['binascii.c'],
1632 extra_compile_args=extra_compile_args,
1633 libraries=libraries,
1634 extra_link_args=extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001635
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001636 # Gustavo Niemeyer's bz2 module.
Victor Stinner625dbf22019-03-01 15:59:39 +01001637 if (self.compiler.find_library_file(self.lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001638 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001639 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1640 else:
1641 bz2_extra_link_args = ()
Victor Stinner8058bda2019-03-01 15:31:45 +01001642 self.add(Extension('_bz2', ['_bz2module.c'],
1643 libraries=['bz2'],
1644 extra_link_args=bz2_extra_link_args))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001645 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001646 self.missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001647
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001648 # LZMA compression support.
Victor Stinner625dbf22019-03-01 15:59:39 +01001649 if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001650 self.add(Extension('_lzma', ['_lzmamodule.c'],
1651 libraries=['lzma']))
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001652 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001653 self.missing.append('_lzma')
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001654
Victor Stinner5ec33a12019-03-01 16:43:28 +01001655 def detect_expat_elementtree(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001656 # Interface to the Expat XML parser
1657 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001658 # Expat was written by James Clark and is now maintained by a group of
1659 # developers on SourceForge; see www.libexpat.org for more information.
1660 # The pyexpat module was written by Paul Prescod after a prototype by
1661 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1662 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001663 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001664 #
1665 # More information on Expat can be found at www.libexpat.org.
1666 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001667 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1668 expat_inc = []
1669 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001670 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001671 expat_lib = ['expat']
1672 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001673 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001674 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01001675 expat_inc = [os.path.join(self.srcdir, 'Modules', 'expat')]
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001676 define_macros = [
1677 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001678 # bpo-30947: Python uses best available entropy sources to
1679 # call XML_SetHashSalt(), expat entropy sources are not needed
1680 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001681 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001682 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001683 expat_lib = []
1684 expat_sources = ['expat/xmlparse.c',
1685 'expat/xmlrole.c',
1686 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001687 expat_depends = ['expat/ascii.h',
1688 'expat/asciitab.h',
1689 'expat/expat.h',
1690 'expat/expat_config.h',
1691 'expat/expat_external.h',
1692 'expat/internal.h',
1693 'expat/latin1tab.h',
1694 'expat/utf8tab.h',
1695 'expat/xmlrole.h',
1696 'expat/xmltok.h',
1697 'expat/xmltok_impl.h'
1698 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001699
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001700 cc = sysconfig.get_config_var('CC').split()[0]
Victor Stinner6b982c22020-04-01 01:10:07 +02001701 ret = run_command(
Benjamin Peterson95da3102019-06-29 16:00:22 -07001702 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Victor Stinner6b982c22020-04-01 01:10:07 +02001703 if ret == 0:
Benjamin Peterson95da3102019-06-29 16:00:22 -07001704 extra_compile_args.append('-Wno-unreachable-code')
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001705
Victor Stinner8058bda2019-03-01 15:31:45 +01001706 self.add(Extension('pyexpat',
1707 define_macros=define_macros,
1708 extra_compile_args=extra_compile_args,
1709 include_dirs=expat_inc,
1710 libraries=expat_lib,
1711 sources=['pyexpat.c'] + expat_sources,
1712 depends=expat_depends))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001713
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001714 # Fredrik Lundh's cElementTree module. Note that this also
1715 # uses expat (via the CAPI hook in pyexpat).
1716
Victor Stinner625dbf22019-03-01 15:59:39 +01001717 if os.path.isfile(os.path.join(self.srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001718 define_macros.append(('USE_PYEXPAT_CAPI', None))
Victor Stinner8058bda2019-03-01 15:31:45 +01001719 self.add(Extension('_elementtree',
1720 define_macros=define_macros,
1721 include_dirs=expat_inc,
1722 libraries=expat_lib,
1723 sources=['_elementtree.c'],
1724 depends=['pyexpat.c', *expat_sources,
1725 *expat_depends]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001726 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001727 self.missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001728
Victor Stinner5ec33a12019-03-01 16:43:28 +01001729 def detect_multibytecodecs(self):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001730 # Hye-Shik Chang's CJKCodecs modules.
Victor Stinner8058bda2019-03-01 15:31:45 +01001731 self.add(Extension('_multibytecodec',
1732 ['cjkcodecs/multibytecodec.c']))
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001733 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Victor Stinner8058bda2019-03-01 15:31:45 +01001734 self.add(Extension('_codecs_%s' % loc,
1735 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001736
Victor Stinner5ec33a12019-03-01 16:43:28 +01001737 def detect_multiprocessing(self):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001738 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001739 if MS_WINDOWS:
Victor Stinnerc991f242019-03-01 17:19:04 +01001740 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
1741 '_multiprocessing/semaphore.c']
Benjamin Petersone711caf2008-06-11 16:44:04 +00001742
1743 else:
Victor Stinnerc991f242019-03-01 17:19:04 +01001744 multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
Mark Dickinsona614f042009-11-28 12:48:43 +00001745 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1746 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001747 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001748 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1749 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Victor Stinnerc991f242019-03-01 17:19:04 +01001750 posixshmem_srcs = ['_multiprocessing/posixshmem.c']
Davin Pottse5ef45b2019-02-01 22:52:23 -06001751 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001752 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1753 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001754 libs.append('rt')
Victor Stinner8058bda2019-03-01 15:31:45 +01001755 self.add(Extension('_posixshmem', posixshmem_srcs,
1756 define_macros={},
1757 libraries=libs,
1758 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001759
Victor Stinner8058bda2019-03-01 15:31:45 +01001760 self.add(Extension('_multiprocessing', multiprocessing_srcs,
Victor Stinner8058bda2019-03-01 15:31:45 +01001761 include_dirs=["Modules/_multiprocessing"]))
Guido van Rossuma9e20242007-03-08 00:43:48 +00001762
Victor Stinner5ec33a12019-03-01 16:43:28 +01001763 def detect_uuid(self):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001764 # Build the _uuid module if possible
Victor Stinner625dbf22019-03-01 15:59:39 +01001765 uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001766 if uuid_incs is not None:
Victor Stinner625dbf22019-03-01 15:59:39 +01001767 if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
Antoine Pitroua106aec2017-09-28 23:03:06 +02001768 uuid_libs = ['uuid']
1769 else:
1770 uuid_libs = []
Victor Stinnercfe172d2019-03-01 18:21:49 +01001771 self.add(Extension('_uuid', ['_uuidmodule.c'],
1772 libraries=uuid_libs,
1773 include_dirs=uuid_incs))
Antoine Pitroua106aec2017-09-28 23:03:06 +02001774 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01001775 self.missing.append('_uuid')
Antoine Pitroua106aec2017-09-28 23:03:06 +02001776
Victor Stinner5ec33a12019-03-01 16:43:28 +01001777 def detect_modules(self):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001778 self.configure_compiler()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001779 self.init_inc_lib_dirs()
1780
1781 self.detect_simple_extensions()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001782 if TEST_EXTENSIONS:
1783 self.detect_test_extensions()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001784 self.detect_readline_curses()
1785 self.detect_crypt()
1786 self.detect_socket()
1787 self.detect_openssl_hashlib()
xdegaye2ee077f2019-04-09 17:20:08 +02001788 self.detect_hash_builtins()
Victor Stinner5ec33a12019-03-01 16:43:28 +01001789 self.detect_dbm_gdbm()
1790 self.detect_sqlite()
1791 self.detect_platform_specific_exts()
1792 self.detect_nis()
1793 self.detect_compress_exts()
1794 self.detect_expat_elementtree()
1795 self.detect_multibytecodecs()
1796 self.detect_decimal()
1797 self.detect_ctypes()
1798 self.detect_multiprocessing()
1799 if not self.detect_tkinter():
1800 self.missing.append('_tkinter')
1801 self.detect_uuid()
1802
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001803## # Uncomment these lines if you want to play with xxmodule.c
Victor Stinnercfe172d2019-03-01 18:21:49 +01001804## self.add(Extension('xx', ['xxmodule.c']))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001805
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001806 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Victor Stinnercfe172d2019-03-01 18:21:49 +01001807 self.add(Extension('xxlimited', ['xxlimited.c'],
1808 define_macros=[('Py_LIMITED_API', '0x03050000')]))
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001809
Ned Deilyd819b932013-09-06 01:07:05 -07001810 def detect_tkinter_explicitly(self):
1811 # Build _tkinter using explicit locations for Tcl/Tk.
1812 #
1813 # This is enabled when both arguments are given to ./configure:
1814 #
1815 # --with-tcltk-includes="-I/path/to/tclincludes \
1816 # -I/path/to/tkincludes"
1817 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1818 # -L/path/to/tklibs -ltkm.n"
1819 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001820 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001821 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1822 #
1823 # This can be useful for building and testing tkinter with multiple
1824 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1825 # build of Tcl so you need to specify both arguments and use care when
1826 # overriding.
1827
1828 # The _TCLTK variables are created in the Makefile sharedmods target.
1829 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1830 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1831 if not (tcltk_includes and tcltk_libs):
1832 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001833 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001834
1835 extra_compile_args = tcltk_includes.split()
1836 extra_link_args = tcltk_libs.split()
Victor Stinnercfe172d2019-03-01 18:21:49 +01001837 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1838 define_macros=[('WITH_APPINIT', 1)],
1839 extra_compile_args = extra_compile_args,
1840 extra_link_args = extra_link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001841 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001842
Victor Stinner625dbf22019-03-01 15:59:39 +01001843 def detect_tkinter_darwin(self):
Ned Deily1731d6d2020-05-18 04:32:38 -04001844 # Build default _tkinter on macOS using Tcl and Tk frameworks.
1845 #
1846 # The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
1847 # built and installed as macOS framework bundles. However,
1848 # for several reasons, we cannot take full advantage of the
1849 # Apple-supplied compiler chain's -framework options here.
1850 # Instead, we need to find and pass to the compiler the
1851 # absolute paths of the Tcl and Tk headers files we want to use
1852 # and the absolute path to the directory containing the Tcl
1853 # and Tk frameworks for linking.
1854 #
1855 # We want to handle here two common use cases on macOS:
1856 # 1. Build and link with system-wide third-party or user-built
1857 # Tcl and Tk frameworks installed in /Library/Frameworks.
1858 # 2. Build and link using a user-specified macOS SDK so that the
1859 # built Python can be exported to other systems. In this case,
1860 # search only the SDK's /Library/Frameworks (normally empty)
1861 # and /System/Library/Frameworks.
1862 #
1863 # Any other use case should be able to be handled explicitly by
1864 # using the options described above in detect_tkinter_explicitly().
1865 # In particular it would be good to handle here the case where
1866 # you want to build and link with a framework build of Tcl and Tk
1867 # that is not in /Library/Frameworks, say, in your private
1868 # $HOME/Library/Frameworks directory or elsewhere. It turns
Miss Skeleton (bot)f3a6b7f2020-10-04 14:51:38 -07001869 # out to be difficult to make that work automatically here
Ned Deily1731d6d2020-05-18 04:32:38 -04001870 # without bringing into play more tools and magic. That case
Miss Skeleton (bot)f3a6b7f2020-10-04 14:51:38 -07001871 # can be handled using a recipe with the right arguments
Ned Deily1731d6d2020-05-18 04:32:38 -04001872 # to detect_tkinter_explicitly().
1873 #
1874 # Note also that the fallback case here is to try to use the
1875 # Apple-supplied Tcl and Tk frameworks in /System/Library but
1876 # be forewarned that they are deprecated by Apple and typically
1877 # out-of-date and buggy; their use should be avoided if at
1878 # all possible by installing a newer version of Tcl and Tk in
Miss Skeleton (bot)f3a6b7f2020-10-04 14:51:38 -07001879 # /Library/Frameworks before building Python without
Ned Deily1731d6d2020-05-18 04:32:38 -04001880 # an explicit SDK or by configuring build arguments explicitly.
1881
Jack Jansen0b06be72002-06-21 14:48:38 +00001882 from os.path import join, exists
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001883
Ned Deily1731d6d2020-05-18 04:32:38 -04001884 sysroot = macosx_sdk_root() # path to the SDK or '/'
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001885
Ned Deily1731d6d2020-05-18 04:32:38 -04001886 if macosx_sdk_specified():
1887 # Use case #2: an SDK other than '/' was specified.
1888 # Only search there.
1889 framework_dirs = [
1890 join(sysroot, 'Library', 'Frameworks'),
1891 join(sysroot, 'System', 'Library', 'Frameworks'),
1892 ]
1893 else:
1894 # Use case #1: no explicit SDK selected.
1895 # Search the local system-wide /Library/Frameworks,
Miss Skeleton (bot)f3a6b7f2020-10-04 14:51:38 -07001896 # not the one in the default SDK, otherwise fall back to
Ned Deily1731d6d2020-05-18 04:32:38 -04001897 # /System/Library/Frameworks whose header files may be in
1898 # the default SDK or, on older systems, actually installed.
1899 framework_dirs = [
1900 join('/', 'Library', 'Frameworks'),
1901 join(sysroot, 'System', 'Library', 'Frameworks'),
1902 ]
1903
1904 # Find the directory that contains the Tcl.framework and
1905 # Tk.framework bundles.
Jack Jansen0b06be72002-06-21 14:48:38 +00001906 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001907 # both Tcl.framework and Tk.framework should be present
Jack Jansen0b06be72002-06-21 14:48:38 +00001908 for fw in 'Tcl', 'Tk':
Ned Deily1731d6d2020-05-18 04:32:38 -04001909 if not exists(join(F, fw + '.framework')):
1910 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001911 else:
Miss Skeleton (bot)f3a6b7f2020-10-04 14:51:38 -07001912 # ok, F is now directory with both frameworks. Continue
Jack Jansen0b06be72002-06-21 14:48:38 +00001913 # building
1914 break
1915 else:
1916 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1917 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001918 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001919
Jack Jansen0b06be72002-06-21 14:48:38 +00001920 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001921 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001922 for fw in ('Tcl', 'Tk')
Ned Deily1731d6d2020-05-18 04:32:38 -04001923 for H in ('Headers',)
Jack Jansen0b06be72002-06-21 14:48:38 +00001924 ]
1925
Ned Deily1731d6d2020-05-18 04:32:38 -04001926 # Add the base framework directory as well
1927 compile_args = ['-F', F]
Jack Jansen0b06be72002-06-21 14:48:38 +00001928
Ned Deily1731d6d2020-05-18 04:32:38 -04001929 # Do not build tkinter for archs that this Tk was not built with.
Georg Brandlfcaf9102008-07-16 02:17:56 +00001930 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001931 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001932
Ronald Oussorend097efe2009-09-15 19:07:58 +00001933 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1934 if not os.path.exists(self.build_temp):
1935 os.makedirs(self.build_temp)
1936
Ned Deily1731d6d2020-05-18 04:32:38 -04001937 run_command(
1938 "file {}/Tk.framework/Tk | grep 'for architecture' > {}".format(F, tmpfile)
1939 )
Brett Cannon9f5db072010-10-29 20:19:27 +00001940 with open(tmpfile) as fp:
1941 detected_archs = []
1942 for ln in fp:
1943 a = ln.split()[-1]
1944 if a in archs:
1945 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001946 os.unlink(tmpfile)
1947
Ned Deily1731d6d2020-05-18 04:32:38 -04001948 arch_args = []
Ronald Oussorend097efe2009-09-15 19:07:58 +00001949 for a in detected_archs:
Ned Deily1731d6d2020-05-18 04:32:38 -04001950 arch_args.append('-arch')
1951 arch_args.append(a)
1952
1953 compile_args += arch_args
1954 link_args = [','.join(['-Wl', '-F', F, '-framework', 'Tcl', '-framework', 'Tk']), *arch_args]
1955
1956 # The X11/xlib.h file bundled in the Tk sources can cause function
1957 # prototype warnings from the compiler. Since we cannot easily fix
1958 # that, suppress the warnings here instead.
1959 if '-Wstrict-prototypes' in cflags.split():
1960 compile_args.append('-Wno-strict-prototypes')
Georg Brandlfcaf9102008-07-16 02:17:56 +00001961
Victor Stinnercfe172d2019-03-01 18:21:49 +01001962 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1963 define_macros=[('WITH_APPINIT', 1)],
1964 include_dirs=include_dirs,
1965 libraries=[],
Ned Deily1731d6d2020-05-18 04:32:38 -04001966 extra_compile_args=compile_args,
1967 extra_link_args=link_args))
Victor Stinner4cbea512019-02-28 17:48:38 +01001968 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001969
Victor Stinner625dbf22019-03-01 15:59:39 +01001970 def detect_tkinter(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001971 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001972
Ned Deilyd819b932013-09-06 01:07:05 -07001973 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1974 # configured or passed into the make target. If so, use these values
1975 # to build tkinter and bypass the searches for Tcl and TK in standard
1976 # locations.
1977 if self.detect_tkinter_explicitly():
Victor Stinner5ec33a12019-03-01 16:43:28 +01001978 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001979
Jack Jansen0b06be72002-06-21 14:48:38 +00001980 # Rather than complicate the code below, detecting and building
1981 # AquaTk is a separate method. Only one Tkinter will be built on
1982 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner5ec33a12019-03-01 16:43:28 +01001983 if (MACOS and self.detect_tkinter_darwin()):
1984 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001985
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001986 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001987 # The versions with dots are used on Unix, and the versions without
1988 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001989 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00001990 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1991 '8.2', '82', '8.1', '81', '8.0', '80']:
Victor Stinner625dbf22019-03-01 15:59:39 +01001992 tklib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001993 'tk' + version)
Victor Stinner625dbf22019-03-01 15:59:39 +01001994 tcllib = self.compiler.find_library_file(self.lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001995 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00001996 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001997 # Exit the loop when we've found the Tcl/Tk libraries
1998 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001999
Fredrik Lundhade711a2001-01-24 08:00:28 +00002000 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002001 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002002 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002003 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002004 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01002005 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002006 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
2007 # but the include subdirs are named like .../include/tcl8.3.
2008 dotversion = dotversion[:-1] + '.' + dotversion[-1]
2009 tcl_include_sub = []
2010 tk_include_sub = []
Victor Stinner625dbf22019-03-01 15:59:39 +01002011 for dir in self.inc_dirs:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002012 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
2013 tk_include_sub += [dir + os.sep + "tk" + dotversion]
2014 tk_include_sub += tcl_include_sub
Victor Stinner625dbf22019-03-01 15:59:39 +01002015 tcl_includes = find_file('tcl.h', self.inc_dirs, tcl_include_sub)
2016 tk_includes = find_file('tk.h', self.inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002017
Martin v. Löwise86a59a2003-05-03 08:45:51 +00002018 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002019 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00002020 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Victor Stinner5ec33a12019-03-01 16:43:28 +01002021 return False
Fredrik Lundhade711a2001-01-24 08:00:28 +00002022
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002023 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002024
Victor Stinnercfe172d2019-03-01 18:21:49 +01002025 include_dirs = []
2026 libs = []
2027 defs = []
2028 added_lib_dirs = []
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002029 for dir in tcl_includes + tk_includes:
2030 if dir not in include_dirs:
2031 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002032
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002033 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01002034 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002035 include_dirs.append('/usr/openwin/include')
2036 added_lib_dirs.append('/usr/openwin/lib')
2037 elif os.path.exists('/usr/X11R6/include'):
2038 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00002039 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002040 added_lib_dirs.append('/usr/X11R6/lib')
2041 elif os.path.exists('/usr/X11R5/include'):
2042 include_dirs.append('/usr/X11R5/include')
2043 added_lib_dirs.append('/usr/X11R5/lib')
2044 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002045 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002046 include_dirs.append('/usr/X11/include')
2047 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002048
Jason Tishler9181c942003-02-05 15:16:17 +00002049 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01002050 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00002051 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
2052 if x11_inc is None:
Victor Stinner5ec33a12019-03-01 16:43:28 +01002053 return False
Jason Tishler9181c942003-02-05 15:16:17 +00002054
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002055 # Check for BLT extension
Victor Stinner625dbf22019-03-01 15:59:39 +01002056 if self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002057 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002058 defs.append( ('WITH_BLT', 1) )
2059 libs.append('BLT8.0')
Victor Stinner625dbf22019-03-01 15:59:39 +01002060 elif self.compiler.find_library_file(self.lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00002061 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00002062 defs.append( ('WITH_BLT', 1) )
2063 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002064
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002065 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00002066 libs.append('tk'+ version)
2067 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00002068
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002069 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01002070 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00002071 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002072
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00002073 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002074 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002075 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002076 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002077 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002078 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00002079 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002080
Victor Stinnercfe172d2019-03-01 18:21:49 +01002081 self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2082 define_macros=[('WITH_APPINIT', 1)] + defs,
2083 include_dirs=include_dirs,
2084 libraries=libs,
2085 library_dirs=added_lib_dirs))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002086 return True
2087
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002088 def configure_ctypes(self, ext):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002089 return True
2090
Victor Stinner625dbf22019-03-01 15:59:39 +01002091 def detect_ctypes(self):
Victor Stinner5ec33a12019-03-01 16:43:28 +01002092 # Thomas Heller's _ctypes module
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002093
2094 if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
2095 self.use_system_libffi = True
2096 else:
2097 self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
2098
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002099 include_dirs = []
Victor Stinner1ae035b2020-04-17 17:47:20 +02002100 extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002101 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00002102 sources = ['_ctypes/_ctypes.c',
2103 '_ctypes/callbacks.c',
2104 '_ctypes/callproc.c',
2105 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00002106 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00002107 depends = ['_ctypes/ctypes.h']
2108
Victor Stinner4cbea512019-02-28 17:48:38 +01002109 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00002110 sources.append('_ctypes/malloc_closure.c')
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002111 extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
Christian Heimes78644762008-03-04 23:39:23 +00002112 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00002113 include_dirs.append('_ctypes/darwin')
Thomas Hellercf567c12006-03-08 19:51:58 +00002114
Victor Stinner4cbea512019-02-28 17:48:38 +01002115 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002116 # XXX This shouldn't be necessary; it appears that some
2117 # of the assembler code is non-PIC (i.e. it has relocations
2118 # when it shouldn't. The proper fix would be to rewrite
2119 # the assembler code to be PIC.
2120 # This only works with GCC; the Sun compiler likely refuses
2121 # this option. If you want to compile ctypes with the Sun
2122 # compiler, please research a proper solution, instead of
2123 # finding some -z option for the Sun compiler.
2124 extra_link_args.append('-mimpure-text')
2125
Victor Stinner4cbea512019-02-28 17:48:38 +01002126 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00002127 extra_link_args.append('-fPIC')
2128
Thomas Hellercf567c12006-03-08 19:51:58 +00002129 ext = Extension('_ctypes',
2130 include_dirs=include_dirs,
2131 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00002132 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002133 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00002134 sources=sources,
2135 depends=depends)
Victor Stinnercfe172d2019-03-01 18:21:49 +01002136 self.add(ext)
2137 if TEST_EXTENSIONS:
2138 # function my_sqrt() needs libm for sqrt()
2139 self.add(Extension('_ctypes_test',
2140 sources=['_ctypes/_ctypes_test.c'],
2141 libraries=['m']))
Thomas Hellercf567c12006-03-08 19:51:58 +00002142
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002143 ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
2144 ffi_lib = None
2145
Victor Stinner625dbf22019-03-01 15:59:39 +01002146 ffi_inc_dirs = self.inc_dirs.copy()
Victor Stinner4cbea512019-02-28 17:48:38 +01002147 if MACOS:
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002148 ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
Christian Heimes78644762008-03-04 23:39:23 +00002149
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002150 if not ffi_inc:
2151 if os.path.exists(ffi_in_sdk):
2152 ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
2153 ffi_inc = ffi_in_sdk
2154 ffi_lib = 'ffi'
2155 else:
2156 # OS X 10.5 comes with libffi.dylib; the include files are
2157 # in /usr/include/ffi
2158 ffi_inc_dirs.append('/usr/include/ffi')
2159
2160 if not ffi_inc:
2161 found = find_file('ffi.h', [], ffi_inc_dirs)
2162 if found:
2163 ffi_inc = found[0]
2164 if ffi_inc:
2165 ffi_h = ffi_inc + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002166 if not os.path.exists(ffi_h):
2167 ffi_inc = None
2168 print('Header file {} does not exist'.format(ffi_h))
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002169 if ffi_lib is None and ffi_inc:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002170 for lib_name in ('ffi', 'ffi_pic'):
Victor Stinner625dbf22019-03-01 15:59:39 +01002171 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002172 ffi_lib = lib_name
2173 break
2174
2175 if ffi_inc and ffi_lib:
Ronald Oussorene8b1c032020-11-22 11:18:40 +01002176 ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
2177 if grep_headers_for('ffi_prep_cif_var', ffi_headers):
2178 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
2179 if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
2180 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
2181 if grep_headers_for('ffi_closure_alloc', ffi_headers):
2182 ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
2183
2184 ext.include_dirs.append(ffi_inc)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002185 ext.libraries.append(ffi_lib)
2186 self.use_system_libffi = True
2187
Christian Heimes5bb96922018-02-25 10:22:14 +01002188 if sysconfig.get_config_var('HAVE_LIBDL'):
2189 # for dlopen, see bpo-32647
2190 ext.libraries.append('dl')
2191
Victor Stinner5ec33a12019-03-01 16:43:28 +01002192 def detect_decimal(self):
2193 # Stefan Krah's _decimal module
Stefan Krah60187b52012-03-23 19:06:27 +01002194 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002195 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002196 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2197 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002198 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002199 sources = ['_decimal/_decimal.c']
2200 depends = ['_decimal/docstrings.h']
2201 else:
Victor Stinner625dbf22019-03-01 15:59:39 +01002202 include_dirs = [os.path.abspath(os.path.join(self.srcdir,
Ned Deily458a6fb2012-04-01 02:30:46 -07002203 'Modules',
2204 '_decimal',
2205 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002206 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002207 sources = [
2208 '_decimal/_decimal.c',
2209 '_decimal/libmpdec/basearith.c',
2210 '_decimal/libmpdec/constants.c',
2211 '_decimal/libmpdec/context.c',
2212 '_decimal/libmpdec/convolute.c',
2213 '_decimal/libmpdec/crt.c',
2214 '_decimal/libmpdec/difradix2.c',
2215 '_decimal/libmpdec/fnt.c',
2216 '_decimal/libmpdec/fourstep.c',
2217 '_decimal/libmpdec/io.c',
Stefan Krahf117d872019-07-10 18:27:38 +02002218 '_decimal/libmpdec/mpalloc.c',
Stefan Krah60187b52012-03-23 19:06:27 +01002219 '_decimal/libmpdec/mpdecimal.c',
2220 '_decimal/libmpdec/numbertheory.c',
2221 '_decimal/libmpdec/sixstep.c',
2222 '_decimal/libmpdec/transpose.c',
2223 ]
2224 depends = [
2225 '_decimal/docstrings.h',
2226 '_decimal/libmpdec/basearith.h',
2227 '_decimal/libmpdec/bits.h',
2228 '_decimal/libmpdec/constants.h',
2229 '_decimal/libmpdec/convolute.h',
2230 '_decimal/libmpdec/crt.h',
2231 '_decimal/libmpdec/difradix2.h',
2232 '_decimal/libmpdec/fnt.h',
2233 '_decimal/libmpdec/fourstep.h',
2234 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002235 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002236 '_decimal/libmpdec/mpdecimal.h',
2237 '_decimal/libmpdec/numbertheory.h',
2238 '_decimal/libmpdec/sixstep.h',
2239 '_decimal/libmpdec/transpose.h',
2240 '_decimal/libmpdec/typearith.h',
2241 '_decimal/libmpdec/umodarith.h',
2242 ]
2243
Stefan Krah1919b7e2012-03-21 18:25:23 +01002244 config = {
2245 'x64': [('CONFIG_64','1'), ('ASM','1')],
2246 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2247 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2248 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2249 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2250 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2251 ('LEGACY_COMPILER','1')],
2252 'universal': [('UNIVERSAL','1')]
2253 }
2254
Stefan Krah1919b7e2012-03-21 18:25:23 +01002255 cc = sysconfig.get_config_var('CC')
2256 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2257 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2258
2259 if machine:
2260 # Override automatic configuration to facilitate testing.
2261 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002262 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002263 # Universal here means: build with the same options Python
2264 # was built with.
2265 define_macros = config['universal']
2266 elif sizeof_size_t == 8:
2267 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2268 define_macros = config['x64']
2269 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2270 define_macros = config['uint128']
2271 else:
2272 define_macros = config['ansi64']
2273 elif sizeof_size_t == 4:
2274 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2275 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002276 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002277 # solaris: problems with register allocation.
2278 # icc >= 11.0 works as well.
2279 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002280 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002281 else:
2282 define_macros = config['ansi32']
2283 else:
2284 raise DistutilsError("_decimal: unsupported architecture")
2285
2286 # Workarounds for toolchain bugs:
2287 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2288 # Some versions of gcc miscompile inline asm:
2289 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2290 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2291 extra_compile_args.append('-fno-ipa-pure-const')
2292 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2293 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2294 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2295 undef_macros.append('_FORTIFY_SOURCE')
2296
Stefan Krah1919b7e2012-03-21 18:25:23 +01002297 # Uncomment for extra functionality:
2298 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
Victor Stinner8058bda2019-03-01 15:31:45 +01002299 self.add(Extension('_decimal',
2300 include_dirs=include_dirs,
2301 libraries=libraries,
2302 define_macros=define_macros,
2303 undef_macros=undef_macros,
2304 extra_compile_args=extra_compile_args,
2305 sources=sources,
2306 depends=depends))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002307
Victor Stinner5ec33a12019-03-01 16:43:28 +01002308 def detect_openssl_hashlib(self):
2309 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +01002310 config_vars = sysconfig.get_config_vars()
2311
2312 def split_var(name, sep):
2313 # poor man's shlex, the re module is not available yet.
2314 value = config_vars.get(name)
2315 if not value:
2316 return ()
2317 # This trick works because ax_check_openssl uses --libs-only-L,
2318 # --libs-only-l, and --cflags-only-I.
2319 value = ' ' + value
2320 sep = ' ' + sep
2321 return [v.strip() for v in value.split(sep) if v.strip()]
2322
2323 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2324 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2325 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2326 if not openssl_libs:
2327 # libssl and libcrypto not found
Christian Heimes8abc3f42019-04-09 18:40:12 +02002328 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002329 return None, None
2330
2331 # Find OpenSSL includes
2332 ssl_incs = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002333 'openssl/ssl.h', self.inc_dirs, openssl_includes
Christian Heimesff5be6e2018-01-20 13:19:21 +01002334 )
2335 if ssl_incs is None:
Christian Heimes8abc3f42019-04-09 18:40:12 +02002336 self.missing.extend(['_ssl', '_hashlib'])
Christian Heimesff5be6e2018-01-20 13:19:21 +01002337 return None, None
2338
2339 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2340 krb5_h = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002341 'krb5.h', self.inc_dirs,
Christian Heimesff5be6e2018-01-20 13:19:21 +01002342 ['/usr/kerberos/include']
2343 )
2344 if krb5_h:
2345 ssl_incs.extend(krb5_h)
2346
Christian Heimes61d478c2018-01-27 15:51:38 +01002347 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
Christian Heimesc7f70692019-05-31 11:44:05 +02002348 self.add(Extension(
2349 '_ssl', ['_ssl.c'],
2350 include_dirs=openssl_includes,
2351 library_dirs=openssl_libdirs,
2352 libraries=openssl_libs,
2353 depends=['socketmodule.h', '_ssl/debughelpers.c'])
2354 )
Christian Heimes61d478c2018-01-27 15:51:38 +01002355 else:
Victor Stinner8058bda2019-03-01 15:31:45 +01002356 self.missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +01002357
Victor Stinner8058bda2019-03-01 15:31:45 +01002358 self.add(Extension('_hashlib', ['_hashopenssl.c'],
2359 depends=['hashlib.h'],
2360 include_dirs=openssl_includes,
2361 library_dirs=openssl_libdirs,
2362 libraries=openssl_libs))
Christian Heimesff5be6e2018-01-20 13:19:21 +01002363
xdegaye2ee077f2019-04-09 17:20:08 +02002364 def detect_hash_builtins(self):
Christian Heimes9b60e552020-05-15 23:54:53 +02002365 # By default we always compile these even when OpenSSL is available
2366 # (issue #14693). It's harmless and the object code is tiny
2367 # (40-50 KiB per module, only loaded when actually used). Modules can
2368 # be disabled via the --with-builtin-hashlib-hashes configure flag.
2369 supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
Victor Stinner5ec33a12019-03-01 16:43:28 +01002370
Christian Heimes9b60e552020-05-15 23:54:53 +02002371 configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
2372 configured = configured.strip('"').lower()
2373 configured = {
2374 m.strip() for m in configured.split(",")
2375 }
Victor Stinner5ec33a12019-03-01 16:43:28 +01002376
Christian Heimes9b60e552020-05-15 23:54:53 +02002377 self.disabled_configure.extend(
2378 sorted(supported.difference(configured))
2379 )
Victor Stinner5ec33a12019-03-01 16:43:28 +01002380
Christian Heimes9b60e552020-05-15 23:54:53 +02002381 if "sha256" in configured:
2382 self.add(Extension(
2383 '_sha256', ['sha256module.c'],
2384 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2385 depends=['hashlib.h']
2386 ))
2387
2388 if "sha512" in configured:
2389 self.add(Extension(
2390 '_sha512', ['sha512module.c'],
2391 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
2392 depends=['hashlib.h']
2393 ))
2394
2395 if "md5" in configured:
2396 self.add(Extension(
2397 '_md5', ['md5module.c'],
2398 depends=['hashlib.h']
2399 ))
2400
2401 if "sha1" in configured:
2402 self.add(Extension(
2403 '_sha1', ['sha1module.c'],
2404 depends=['hashlib.h']
2405 ))
2406
2407 if "blake2" in configured:
2408 blake2_deps = glob(
Serhiy Storchakaecfecc22020-07-02 10:05:16 +03002409 os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002410 )
2411 blake2_deps.append('hashlib.h')
2412 self.add(Extension(
2413 '_blake2',
2414 [
2415 '_blake2/blake2module.c',
2416 '_blake2/blake2b_impl.c',
2417 '_blake2/blake2s_impl.c'
2418 ],
2419 depends=blake2_deps
2420 ))
2421
2422 if "sha3" in configured:
2423 sha3_deps = glob(
Serhiy Storchakaecfecc22020-07-02 10:05:16 +03002424 os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
Christian Heimes9b60e552020-05-15 23:54:53 +02002425 )
2426 sha3_deps.append('hashlib.h')
2427 self.add(Extension(
2428 '_sha3',
2429 ['_sha3/sha3module.c'],
2430 depends=sha3_deps
2431 ))
Victor Stinner5ec33a12019-03-01 16:43:28 +01002432
2433 def detect_nis(self):
Victor Stinner4cbea512019-02-28 17:48:38 +01002434 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Victor Stinner8058bda2019-03-01 15:31:45 +01002435 self.missing.append('nis')
2436 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002437
2438 libs = []
2439 library_dirs = []
2440 includes_dirs = []
2441
2442 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2443 # moved headers and libraries to libtirpc and libnsl. The headers
2444 # are in tircp and nsl sub directories.
2445 rpcsvc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002446 'rpcsvc/yp_prot.h', self.inc_dirs,
2447 [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002448 )
2449 rpc_inc = find_file(
Victor Stinner625dbf22019-03-01 15:59:39 +01002450 'rpc/rpc.h', self.inc_dirs,
2451 [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002452 )
2453 if rpcsvc_inc is None or rpc_inc is None:
2454 # not found
Victor Stinner8058bda2019-03-01 15:31:45 +01002455 self.missing.append('nis')
2456 return
Christian Heimes29a7df72018-01-26 23:28:46 +01002457 includes_dirs.extend(rpcsvc_inc)
2458 includes_dirs.extend(rpc_inc)
2459
Victor Stinner625dbf22019-03-01 15:59:39 +01002460 if self.compiler.find_library_file(self.lib_dirs, 'nsl'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002461 libs.append('nsl')
2462 else:
2463 # libnsl-devel: check for libnsl in nsl/ subdirectory
Victor Stinner625dbf22019-03-01 15:59:39 +01002464 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in self.lib_dirs]
Christian Heimes29a7df72018-01-26 23:28:46 +01002465 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2466 if libnsl is not None:
2467 library_dirs.append(os.path.dirname(libnsl))
2468 libs.append('nsl')
2469
Victor Stinner625dbf22019-03-01 15:59:39 +01002470 if self.compiler.find_library_file(self.lib_dirs, 'tirpc'):
Christian Heimes29a7df72018-01-26 23:28:46 +01002471 libs.append('tirpc')
2472
Victor Stinner8058bda2019-03-01 15:31:45 +01002473 self.add(Extension('nis', ['nismodule.c'],
2474 libraries=libs,
2475 library_dirs=library_dirs,
2476 include_dirs=includes_dirs))
Christian Heimes29a7df72018-01-26 23:28:46 +01002477
Christian Heimesff5be6e2018-01-20 13:19:21 +01002478
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002479class PyBuildInstall(install):
2480 # Suppress the warning about installation into the lib_dynload
2481 # directory, which is not in sys.path when running Python during
2482 # installation:
2483 def initialize_options (self):
2484 install.initialize_options(self)
2485 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002486
Éric Araujoe6792c12011-06-09 14:07:02 +02002487 # Customize subcommands to not install an egg-info file for Python
2488 sub_commands = [('install_lib', install.has_lib),
2489 ('install_headers', install.has_headers),
2490 ('install_scripts', install.has_scripts),
2491 ('install_data', install.has_data)]
2492
2493
Michael W. Hudson529a5052002-12-17 16:47:17 +00002494class PyBuildInstallLib(install_lib):
2495 # Do exactly what install_lib does but make sure correct access modes get
2496 # set on installed directories and files. All installed files with get
2497 # mode 644 unless they are a shared library in which case they will get
2498 # mode 755. All installed directories will get mode 755.
2499
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002500 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2501 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002502
2503 def install(self):
2504 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002505 self.set_file_modes(outfiles, 0o644, 0o755)
2506 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002507 return outfiles
2508
2509 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002510 if not files: return
2511
2512 for filename in files:
2513 if os.path.islink(filename): continue
2514 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002515 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002516 log.info("changing mode of %s to %o", filename, mode)
2517 if not self.dry_run: os.chmod(filename, mode)
2518
2519 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002520 for dirpath, dirnames, fnames in os.walk(dirname):
2521 if os.path.islink(dirpath):
2522 continue
2523 log.info("changing mode of %s to %o", dirpath, mode)
2524 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002525
Victor Stinnerc991f242019-03-01 17:19:04 +01002526
Georg Brandlff52f762010-12-28 09:51:43 +00002527class PyBuildScripts(build_scripts):
2528 def copy_scripts(self):
2529 outfiles, updated_files = build_scripts.copy_scripts(self)
2530 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2531 minoronly = '.{0[1]}'.format(sys.version_info)
2532 newoutfiles = []
2533 newupdated_files = []
2534 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002535 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002536 newfilename = filename + fullversion
2537 else:
2538 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002539 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002540 os.rename(filename, newfilename)
2541 newoutfiles.append(newfilename)
2542 if filename in updated_files:
2543 newupdated_files.append(newfilename)
2544 return newoutfiles, newupdated_files
2545
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002546
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002547def main():
Victor Stinnerc991f242019-03-01 17:19:04 +01002548 set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
2549 set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
2550
2551 class DummyProcess:
2552 """Hack for parallel build"""
2553 ProcessPoolExecutor = None
2554
2555 sys.modules['concurrent.futures.process'] = DummyProcess
Paul Ganssle62972d92020-05-16 04:20:06 -04002556 validate_tzpath()
Victor Stinnerc991f242019-03-01 17:19:04 +01002557
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002558 # turn off warnings when deprecated modules are imported
2559 import warnings
2560 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002561 setup(# PyPI Metadata (PEP 301)
2562 name = "Python",
2563 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002564 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002565 maintainer = "Guido van Rossum and the Python community",
2566 maintainer_email = "python-dev@python.org",
2567 description = "A high-level object-oriented programming language",
2568 long_description = SUMMARY.strip(),
2569 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002570 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002571 platforms = ["Many"],
2572
2573 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002574 cmdclass = {'build_ext': PyBuildExt,
2575 'build_scripts': PyBuildScripts,
2576 'install': PyBuildInstall,
2577 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002578 # The struct module is defined here, because build_ext won't be
2579 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002580 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002581
Georg Brandlff52f762010-12-28 09:51:43 +00002582 # If you change the scripts installed here, you also need to
2583 # check the PyBuildScripts command above, and change the links
2584 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002585 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002586 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002587 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002588
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002589# --install-platlib
2590if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002591 main()