blob: 2fef0ad468a49d8f71a289a653747c4068ff7e16 [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
2#
Fredrik Lundhade711a2001-01-24 08:00:28 +00003
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +08004import sys, os, importlib.machinery, re, argparse
Christian Heimesaf98da12008-01-27 15:18:18 +00005from glob import glob
Eric Snow335e14d2014-01-04 15:09:28 -07006import importlib._bootstrap
7import importlib.util
Tarek Ziadéedacea32010-01-29 11:41:03 +00008import sysconfig
Michael W. Hudson529a5052002-12-17 16:47:17 +00009
10from distutils import log
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +000011from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000012from distutils.core import Extension, setup
13from distutils.command.build_ext import build_ext
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000014from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:17 +000015from distutils.command.install_lib import install_lib
Georg Brandlff52f762010-12-28 09:51:43 +000016from distutils.command.build_scripts import build_scripts
Stefan Krah095b2732010-06-08 13:41:44 +000017from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000018
Victor Stinner4cbea512019-02-28 17:48:38 +010019CROSS_COMPILING = "_PYTHON_HOST_PLATFORM" in os.environ
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020020
stratakiscf10a752018-12-19 18:19:01 +010021# Set common compiler and linker flags derived from the Makefile,
22# reserved for building the interpreter and the stdlib modules.
23# See bpo-21121 and bpo-35257
24def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
25 flags = sysconfig.get_config_var(compiler_flags)
26 py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
27 sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
28
29set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
30set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
Benjamin Petersonacb8c522014-08-09 20:01:49 -070031
Antoine Pitrou2c0a9162014-09-26 23:31:59 +020032class Dummy:
33 """Hack for parallel build"""
34 ProcessPoolExecutor = None
35sys.modules['concurrent.futures.process'] = Dummy
36
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020037def get_platform():
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020038 # cross build
39 if "_PYTHON_HOST_PLATFORM" in os.environ:
40 return os.environ["_PYTHON_HOST_PLATFORM"]
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020041 # Get value of sys.platform
42 if sys.platform.startswith('osf1'):
43 return 'osf1'
44 return sys.platform
Victor Stinner4cbea512019-02-28 17:48:38 +010045HOST_PLATFORM = get_platform()
46MS_WINDOWS = (HOST_PLATFORM == 'win32')
47CYGWIN = (HOST_PLATFORM == 'cygwin')
48MACOS = (HOST_PLATFORM == 'darwin')
doko@ubuntu.com93df16b2012-06-30 14:32:08 +020049
Victor Stinner4cbea512019-02-28 17:48:38 +010050VXWORKS = ('vxworks' in HOST_PLATFORM)
pxinwr32f5fdd2019-02-27 19:09:28 +080051
Gregory P. Smithb04ded42010-01-03 00:38:10 +000052# Were we compiled --with-pydebug or with #define Py_DEBUG?
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +020053COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
Gregory P. Smithb04ded42010-01-03 00:38:10 +000054
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000055# This global variable is used to hold the list of modules to be disabled.
Victor Stinner4cbea512019-02-28 17:48:38 +010056DISABLED_MODULE_LIST = []
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000057
Michael W. Hudson39230b32002-01-16 15:26:48 +000058def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:00 +000059 """Add the directory 'dir' to the list 'dirlist' (after any relative
60 directories) if:
61
Michael W. Hudson39230b32002-01-16 15:26:48 +000062 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:00 +000063 2) 'dir' actually exists, and is a directory.
64 """
65 if dir is None or not os.path.isdir(dir) or dir in dirlist:
66 return
67 for i, path in enumerate(dirlist):
68 if not os.path.isabs(path):
69 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:03 +000070 return
71 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:48 +000072
xdegaye77f51392017-11-25 17:25:30 +010073def sysroot_paths(make_vars, subdirs):
74 """Get the paths of sysroot sub-directories.
75
76 * make_vars: a sequence of names of variables of the Makefile where
77 sysroot may be set.
78 * subdirs: a sequence of names of subdirectories used as the location for
79 headers or libraries.
80 """
81
82 dirs = []
83 for var_name in make_vars:
84 var = sysconfig.get_config_var(var_name)
85 if var is not None:
86 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
87 if m is not None:
88 sysroot = m.group(1).strip('"')
89 for subdir in subdirs:
90 if os.path.isabs(subdir):
91 subdir = subdir[1:]
92 path = os.path.join(sysroot, subdir)
93 if os.path.isdir(path):
94 dirs.append(path)
95 break
96 return dirs
97
Ronald Oussoren2c12ab12010-06-03 14:42:25 +000098def macosx_sdk_root():
99 """
100 Return the directory of the current OSX SDK,
101 or '/' if no SDK was specified.
102 """
103 cflags = sysconfig.get_config_var('CFLAGS')
104 m = re.search(r'-isysroot\s+(\S+)', cflags)
105 if m is None:
106 sysroot = '/'
107 else:
108 sysroot = m.group(1)
109 return sysroot
110
111def is_macosx_sdk_path(path):
112 """
113 Returns True if 'path' can be located in an OSX SDK
114 """
Ned Deily2910a7b2012-07-30 02:35:58 -0700115 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
116 or path.startswith('/System/')
117 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000118
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000119def find_file(filename, std_dirs, paths):
120 """Searches for the directory where a given file is located,
121 and returns a possibly-empty list of additional directories, or None
122 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000123
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000124 'filename' is the name of a file, such as readline.h or libcrypto.a.
125 'std_dirs' is the list of standard system directories; if the
126 file is found in one of them, no additional directives are needed.
127 'paths' is a list of additional locations to check; if the file is
128 found in one of them, the resulting list will contain the directory.
129 """
Victor Stinner4cbea512019-02-28 17:48:38 +0100130 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000131 # Honor the MacOSX SDK setting when one was specified.
132 # An SDK is a directory with the same structure as a real
133 # system, but with only header files and libraries.
134 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000135
136 # Check the standard locations
137 for dir in std_dirs:
138 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000139
Victor Stinner4cbea512019-02-28 17:48:38 +0100140 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000141 f = os.path.join(sysroot, dir[1:], filename)
142
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000143 if os.path.exists(f): return []
144
145 # Check the additional directories
146 for dir in paths:
147 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000148
Victor Stinner4cbea512019-02-28 17:48:38 +0100149 if MACOS and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000150 f = os.path.join(sysroot, dir[1:], filename)
151
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000152 if os.path.exists(f):
153 return [dir]
154
155 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000156 return None
157
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000158def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000159 result = compiler.find_library_file(std_dirs + paths, libname)
160 if result is None:
161 return None
Fredrik Lundhade711a2001-01-24 08:00:28 +0000162
Victor Stinner4cbea512019-02-28 17:48:38 +0100163 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000164 sysroot = macosx_sdk_root()
165
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000166 # Check whether the found file is in one of the standard directories
167 dirname = os.path.dirname(result)
168 for p in std_dirs:
169 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000170 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000171
Victor Stinner4cbea512019-02-28 17:48:38 +0100172 if MACOS and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-25 00:56:38 +1100173 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
174 # libraries with .tbd extensions rather than the normal .dylib
175 # shared libraries installed in /. The Apple compiler tool
176 # chain handles this transparently but it can cause problems
177 # for programs that are being built with an SDK and searching
178 # for specific libraries. Distutils find_library_file() now
179 # knows to also search for and return .tbd files. But callers
180 # of find_library_file need to keep in mind that the base filename
181 # of the returned SDK library file might have a different extension
182 # from that of the library file installed on the running system,
183 # for example:
184 # /Applications/Xcode.app/Contents/Developer/Platforms/
185 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
186 # usr/lib/libedit.tbd
187 # vs
188 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000189 if os.path.join(sysroot, p[1:]) == dirname:
190 return [ ]
191
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000192 if p == dirname:
193 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000194
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000195 # Otherwise, it must have been in one of the additional directories,
196 # so we have to figure out which one.
197 for p in paths:
198 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57 +0000199 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000200
Victor Stinner4cbea512019-02-28 17:48:38 +0100201 if MACOS and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000202 if os.path.join(sysroot, p[1:]) == dirname:
203 return [ p ]
204
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46 +0000205 if p == dirname:
206 return [p]
207 else:
208 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43 +0000209
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000210def module_enabled(extlist, modname):
211 """Returns whether the module 'modname' is present in the list
212 of extensions 'extlist'."""
213 extlist = [ext for ext in extlist if ext.name == modname]
214 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000215
Jack Jansen144ebcc2001-08-05 22:31:19 +0000216def find_module_file(module, dirlist):
217 """Find a module in a set of possible folders. If it is not found
218 return the unadorned filename"""
219 list = find_file(module, [], dirlist)
220 if not list:
221 return module
222 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 08:22:29 +0100223 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19 +0000224 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000225
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000226class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000227
Guido van Rossumd8faa362007-04-27 19:54:29 +0000228 def __init__(self, dist):
229 build_ext.__init__(self, dist)
230 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400231 self.failed_on_import = []
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200232 if '-j' in os.environ.get('MAKEFLAGS', ''):
233 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29 +0000234
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000235 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000236
237 # Detect which modules should be compiled
doko@ubuntu.comd5537d02013-03-21 13:21:49 -0700238 missing = self.detect_modules()
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000239
240 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22 +0000241 extensions = [ext for ext in self.extensions
Victor Stinner4cbea512019-02-28 17:48:38 +0100242 if ext.name not in DISABLED_MODULE_LIST]
Christian Heimes679db4a2008-01-18 09:56:22 +0000243 # move ctypes to the end, it depends on other modules
244 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
245 if "_ctypes" in ext_map:
246 ctypes = extensions.pop(ext_map["_ctypes"])
247 extensions.append(ctypes)
248 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28 +0000249
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000250 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000251 # with Modules/.
252 srcdir = sysconfig.get_config_var('srcdir')
Guido van Rossume0fea6c2002-10-14 20:48:09 +0000253 if not srcdir:
254 # Maybe running on Windows but not using CYGWIN?
255 raise ValueError("No source directory; cannot proceed.")
Neil Schemenauer4d491a52009-02-06 00:27:50 +0000256 srcdir = os.path.abspath(srcdir)
Neil Schemenauer014bf282009-02-05 16:35:45 +0000257 moddirlist = [os.path.join(srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41 +0000258
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000259 # Fix up the paths for scripts, too
260 self.distribution.scripts = [os.path.join(srcdir, filename)
261 for filename in self.distribution.scripts]
262
Christian Heimesaf98da12008-01-27 15:18:18 +0000263 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45 +0000264 headers = [sysconfig.get_config_h_filename()]
Stefan Kraheb977da2012-02-29 14:10:53 +0100265 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18 +0000266
xdegayec0364fc2017-05-27 18:25:03 +0200267 # The sysconfig variables built by makesetup that list the already
268 # built modules and the disabled modules as configured by the Setup
269 # files.
270 sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
271 sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200272
xdegayec0364fc2017-05-27 18:25:03 +0200273 mods_built = []
274 mods_disabled = []
Xavier de Gaye84968b72016-10-29 16:57:20 +0200275 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000276 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000277 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000278 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45 +0000279 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11 +0000280 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18 +0000281 else:
282 ext.depends = []
283 # re-compile extensions if a header file has been changed
284 ext.depends.extend(headers)
285
xdegayec0364fc2017-05-27 18:25:03 +0200286 # If a module has already been built or has been disabled in the
287 # Setup files, don't build it here.
288 if ext.name in sysconf_built:
289 mods_built.append(ext)
290 if ext.name in sysconf_dis:
291 mods_disabled.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000292
xdegayec0364fc2017-05-27 18:25:03 +0200293 mods_configured = mods_built + mods_disabled
294 if mods_configured:
Xavier de Gaye84968b72016-10-29 16:57:20 +0200295 self.extensions = [x for x in self.extensions if x not in
xdegayec0364fc2017-05-27 18:25:03 +0200296 mods_configured]
297 # Remove the shared libraries built by a previous build.
298 for ext in mods_configured:
299 fullpath = self.get_ext_fullpath(ext.name)
300 if os.path.exists(fullpath):
301 os.unlink(fullpath)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000302
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000303 # When you run "make CC=altcc" or something similar, you really want
304 # those environment variables passed into the setup.py phase. Here's
305 # a small set of useful ones.
306 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000307 args = {}
308 # unfortunately, distutils doesn't let us provide separate C and C++
309 # compilers
310 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03 +0000311 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
312 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05 +0000313 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000314
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000315 build_ext.build_extensions(self)
316
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200317 for ext in self.extensions:
318 self.check_extension_import(ext)
319
Berker Peksag1d82a9c2014-10-01 05:11:13 +0300320 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400321 if self.failed or self.failed_on_import:
322 all_failed = self.failed + self.failed_on_import
323 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000324
325 def print_three_column(lst):
326 lst.sort(key=str.lower)
327 # guarantee zip() doesn't drop anything
328 while len(lst) % 3:
329 lst.append("")
330 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
331 print("%-*s %-*s %-*s" % (longest, e, longest, f,
332 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000333
334 if missing:
335 print()
Brett Cannonae95b4f2013-07-12 11:30:32 -0400336 print("Python build finished successfully!")
337 print("The necessary bits to build these optional modules were not "
338 "found:")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000339 print_three_column(missing)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000340 print("To find the necessary bits, look in setup.py in"
341 " detect_modules() for the module's name.")
342 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000343
xdegayec0364fc2017-05-27 18:25:03 +0200344 if mods_built:
345 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200346 print("The following modules found by detect_modules() in"
347 " setup.py, have been")
348 print("built by the Makefile instead, as configured by the"
349 " Setup files:")
xdegayec0364fc2017-05-27 18:25:03 +0200350 print_three_column([ext.name for ext in mods_built])
351 print()
352
353 if mods_disabled:
354 print()
355 print("The following modules found by detect_modules() in"
356 " setup.py have not")
357 print("been built, they are *disabled* in the Setup files:")
358 print_three_column([ext.name for ext in mods_disabled])
359 print()
Xavier de Gaye84968b72016-10-29 16:57:20 +0200360
Guido van Rossumd8faa362007-04-27 19:54:29 +0000361 if self.failed:
362 failed = self.failed[:]
363 print()
364 print("Failed to build these modules:")
365 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000366 print()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000367
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400368 if self.failed_on_import:
369 failed = self.failed_on_import[:]
370 print()
371 print("Following modules built successfully"
372 " but were removed because they could not be imported:")
373 print_three_column(failed)
374 print()
375
Christian Heimes61d478c2018-01-27 15:51:38 +0100376 if any('_ssl' in l
377 for l in (missing, self.failed, self.failed_on_import)):
378 print()
379 print("Could not build the ssl module!")
380 print("Python requires an OpenSSL 1.0.2 or 1.1 compatible "
381 "libssl with X509_VERIFY_PARAM_set1_host().")
382 print("LibreSSL 2.6.4 and earlier do not provide the necessary "
383 "APIs, https://github.com/libressl-portable/portable/issues/381")
384 print()
385
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000386 def build_extension(self, ext):
387
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000388 if ext.name == '_ctypes':
389 if not self.configure_ctypes(ext):
Zachary Waref40d4dd2016-09-17 01:25:24 -0500390 self.failed.append(ext.name)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000391 return
392
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000393 try:
394 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56 +0000395 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000396 self.announce('WARNING: building of extension "%s" failed: %s' %
397 (ext.name, sys.exc_info()[1]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000398 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000399 return
Antoine Pitrou2c0a9162014-09-26 23:31:59 +0200400
401 def check_extension_import(self, ext):
402 # Don't try to import an extension that has failed to compile
403 if ext.name in self.failed:
404 self.announce(
405 'WARNING: skipping import check for failed build "%s"' %
406 ext.name, level=1)
407 return
408
Jack Jansenf49c6f92001-11-01 14:44:15 +0000409 # Workaround for Mac OS X: The Carbon-based modules cannot be
410 # reliably imported into a command-line Python
411 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000412 self.announce(
413 'WARNING: skipping import check for Carbon-based "%s"' %
414 ext.name)
415 return
Georg Brandlfcaf9102008-07-16 02:17:56 +0000416
Victor Stinner4cbea512019-02-28 17:48:38 +0100417 if MACOS and (
Benjamin Petersonfc576352008-07-16 02:39:02 +0000418 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56 +0000419 # Don't bother doing an import check when an extension was
420 # build with an explicit '-arch' flag on OSX. That's currently
421 # only used to build 32-bit only extensions in a 4-way
422 # universal build and loading 32-bit code into a 64-bit
423 # process will fail.
424 self.announce(
425 'WARNING: skipping import check for "%s"' %
426 ext.name)
427 return
428
Jason Tishler24cf7762002-05-22 16:46:15 +0000429 # Workaround for Cygwin: Cygwin currently has fork issues when many
430 # modules have been imported
Victor Stinner4cbea512019-02-28 17:48:38 +0100431 if CYGWIN:
Jason Tishler24cf7762002-05-22 16:46:15 +0000432 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
433 % ext.name)
434 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000435 ext_filename = os.path.join(
436 self.build_lib,
437 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53 +0000438
439 # If the build directory didn't exist when setup.py was
440 # started, sys.path_importer_cache has a negative result
441 # cached. Clear that cache before trying to import.
442 sys.path_importer_cache.clear()
443
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200444 # Don't try to load extensions for cross builds
Victor Stinner4cbea512019-02-28 17:48:38 +0100445 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200446 return
447
Brett Cannonca5ff3a2013-06-15 17:52:59 -0400448 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 15:09:28 -0700449 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
450 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000451 try:
Brett Cannon2a17bde2014-05-30 14:55:29 -0400452 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56 +0000453 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 11:06:16 -0400454 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000455 self.announce('*** WARNING: renaming "%s" since importing it'
456 ' failed: %s' % (ext.name, why), level=3)
457 assert not self.inplace
458 basename, tail = os.path.splitext(ext_filename)
459 newname = basename + "_failed" + tail
460 if os.path.exists(newname):
461 os.remove(newname)
462 os.rename(ext_filename, newname)
463
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000464 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39 +0000465 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42 +0000466 self.announce('*** WARNING: importing extension "%s" '
467 'failed with %s: %s' % (ext.name, exc_type, why),
468 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000469 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54 +0000470
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400471 def add_multiarch_paths(self):
472 # Debian/Ubuntu multiarch support.
473 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 12:15:55 +0200474 cc = sysconfig.get_config_var('CC')
475 tmpfile = os.path.join(self.build_temp, 'multiarch')
476 if not os.path.exists(self.build_temp):
477 os.makedirs(self.build_temp)
478 ret = os.system(
479 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
480 multiarch_path_component = ''
481 try:
482 if ret >> 8 == 0:
483 with open(tmpfile) as fp:
484 multiarch_path_component = fp.readline().strip()
485 finally:
486 os.unlink(tmpfile)
487
488 if multiarch_path_component != '':
489 add_dir_to_list(self.compiler.library_dirs,
490 '/usr/lib/' + multiarch_path_component)
491 add_dir_to_list(self.compiler.include_dirs,
492 '/usr/include/' + multiarch_path_component)
493 return
494
Barry Warsaw88e19452011-04-07 10:40:36 -0400495 if not find_executable('dpkg-architecture'):
496 return
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200497 opt = ''
Victor Stinner4cbea512019-02-28 17:48:38 +0100498 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200499 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400500 tmpfile = os.path.join(self.build_temp, 'multiarch')
501 if not os.path.exists(self.build_temp):
502 os.makedirs(self.build_temp)
503 ret = os.system(
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200504 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
505 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400506 try:
507 if ret >> 8 == 0:
508 with open(tmpfile) as fp:
509 multiarch_path_component = fp.readline().strip()
510 add_dir_to_list(self.compiler.library_dirs,
511 '/usr/lib/' + multiarch_path_component)
512 add_dir_to_list(self.compiler.include_dirs,
513 '/usr/include/' + multiarch_path_component)
514 finally:
515 os.unlink(tmpfile)
516
pxinwr32f5fdd2019-02-27 19:09:28 +0800517 def add_cross_compiling_paths(self):
518 cc = sysconfig.get_config_var('CC')
519 tmpfile = os.path.join(self.build_temp, 'ccpaths')
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200520 if not os.path.exists(self.build_temp):
521 os.makedirs(self.build_temp)
pxinwr32f5fdd2019-02-27 19:09:28 +0800522 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200523 is_gcc = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800524 is_clang = False
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200525 in_incdirs = False
526 inc_dirs = []
527 lib_dirs = []
528 try:
529 if ret >> 8 == 0:
530 with open(tmpfile) as fp:
531 for line in fp.readlines():
532 if line.startswith("gcc version"):
533 is_gcc = True
pxinwr32f5fdd2019-02-27 19:09:28 +0800534 elif line.startswith("clang version"):
535 is_clang = True
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200536 elif line.startswith("#include <...>"):
537 in_incdirs = True
538 elif line.startswith("End of search list"):
539 in_incdirs = False
pxinwr32f5fdd2019-02-27 19:09:28 +0800540 elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200541 for d in line.strip().split("=")[1].split(":"):
542 d = os.path.normpath(d)
543 if '/gcc/' not in d:
544 add_dir_to_list(self.compiler.library_dirs,
545 d)
pxinwr32f5fdd2019-02-27 19:09:28 +0800546 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 +0200547 add_dir_to_list(self.compiler.include_dirs,
548 line.strip())
549 finally:
550 os.unlink(tmpfile)
551
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000552 def detect_modules(self):
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000553 # Ensure that /usr/local is always used, but the local build
554 # directories (i.e. '.' and 'Include') must be first. See issue
555 # 10520.
Victor Stinner4cbea512019-02-28 17:48:38 +0100556 if not CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +0200557 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
558 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
doko@ubuntu.comcc5addd2012-07-01 00:23:51 +0200559 # only change this for cross builds for 3.3, issues on Mageia
Victor Stinner4cbea512019-02-28 17:48:38 +0100560 if CROSS_COMPILING:
pxinwr32f5fdd2019-02-27 19:09:28 +0800561 self.add_cross_compiling_paths()
Barry Warsaw5ca305a2011-04-06 15:18:12 -0400562 self.add_multiarch_paths()
Michael W. Hudson39230b32002-01-16 15:26:48 +0000563
Brett Cannon516592f2004-12-07 00:42:59 +0000564 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21 +0000565 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09 +0000566 # We must get the values from the Makefile and not the environment
567 # directly since an inconsistently reproducible issue comes up where
568 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21 +0000569 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59 +0000570 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05 +0000571 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
572 ('LDFLAGS', '-L', self.compiler.library_dirs),
573 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09 +0000574 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59 +0000575 if env_val:
Chih-Hsuan Yen09b2bec2018-07-11 16:48:43 +0800576 parser = argparse.ArgumentParser()
577 parser.add_argument(arg_name, dest="dirs", action="append")
578 options, _ = parser.parse_known_args(env_val.split())
Brett Cannon44837712005-01-02 21:54:07 +0000579 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08 +0000580 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07 +0000581 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49 +0000582
Victor Stinner4cbea512019-02-28 17:48:38 +0100583 if (not CROSS_COMPILING and
Xavier de Gaye1351c312016-12-14 11:14:33 +0100584 os.path.normpath(sys.base_prefix) != '/usr' and
585 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12 +0000586 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
587 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
588 # building a framework with different architectures than
589 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05 +0000590 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000591 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05 +0000592 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000593 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000594
xdegaye77f51392017-11-25 17:25:30 +0100595 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
596 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000597 # lib_dirs and inc_dirs are used to search for files;
598 # if a file is found in one of those directories, it can
599 # be assumed that no additional -I,-L directives are needed.
Victor Stinner4cbea512019-02-28 17:48:38 +0100600 if not CROSS_COMPILING:
xdegaye77f51392017-11-25 17:25:30 +0100601 lib_dirs = self.compiler.library_dirs + system_lib_dirs
602 inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 12:41:00 +0100603 else:
xdegaye77f51392017-11-25 17:25:30 +0100604 # Add the sysroot paths. 'sysroot' is a compiler option used to
605 # set the logical path of the standard system headers and
606 # libraries.
607 lib_dirs = (self.compiler.library_dirs +
608 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
609 inc_dirs = (self.compiler.include_dirs +
610 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
611 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000612 exts = []
Guido van Rossumd8faa362007-04-27 19:54:29 +0000613 missing = []
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000614
Brett Cannon4454a1f2005-04-15 20:32:39 +0000615 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27 +0000616 with open(config_h) as file:
617 config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39 +0000618
Neil Schemenauer014bf282009-02-05 16:35:45 +0000619 srcdir = sysconfig.get_config_var('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41 +0000620
Andrew M. Kuchling7883dc82003-10-24 18:26:26 +0000621 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
Victor Stinner4cbea512019-02-28 17:48:38 +0100622 if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
Skip Montanaro22e00c42003-05-06 20:43:34 +0000623 lib_dirs += ['/usr/ccs/lib']
624
Charles-François Natali5739e102012-04-12 19:07:25 +0200625 # HP-UX11iv3 keeps files in lib/hpux folders.
Victor Stinner4cbea512019-02-28 17:48:38 +0100626 if HOST_PLATFORM == 'hp-ux11':
Charles-François Natali5739e102012-04-12 19:07:25 +0200627 lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
628
Victor Stinner4cbea512019-02-28 17:48:38 +0100629 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000630 # This should work on any unixy platform ;-)
631 # If the user has bothered specifying additional -I and -L flags
632 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00 +0000633 #
634 # NOTE: using shlex.split would technically be more correct, but
635 # also gives a bootstrap problem. Let's hope nobody uses
636 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000637 cflags, ldflags = sysconfig.get_config_vars(
638 'CFLAGS', 'LDFLAGS')
639 for item in cflags.split():
640 if item.startswith('-I'):
641 inc_dirs.append(item[2:])
642
643 for item in ldflags.split():
644 if item.startswith('-L'):
645 lib_dirs.append(item[2:])
646
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000647 #
648 # The following modules are all pretty straightforward, and compile
649 # on pretty much any POSIXish platform.
650 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000651
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000652 # array objects
653 exts.append( Extension('array', ['arraymodule.c']) )
Martin Panterc9deece2016-02-03 05:19:44 +0000654
Yury Selivanovf23746a2018-01-22 19:11:18 -0500655 # Context Variables
656 exts.append( Extension('_contextvars', ['_contextvarsmodule.c']) )
657
Martin Panterc9deece2016-02-03 05:19:44 +0000658 shared_math = 'Modules/_math.o'
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000659 # complex math library functions
Martin Panterc9deece2016-02-03 05:19:44 +0000660 exts.append( Extension('cmath', ['cmathmodule.c'],
661 extra_objects=[shared_math],
662 depends=['_math.h', shared_math],
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800663 libraries=['m']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000664 # math library functions, e.g. sin()
Martin Panterc9deece2016-02-03 05:19:44 +0000665 exts.append( Extension('math', ['mathmodule.c'],
666 extra_objects=[shared_math],
667 depends=['_math.h', shared_math],
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800668 libraries=['m']) )
Victor Stinnere0be4232011-10-25 13:06:09 +0200669
670 # time libraries: librt may be needed for clock_gettime()
671 time_libs = []
672 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
673 if lib:
674 time_libs.append(lib)
675
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000676 # time operations and variables
Victor Stinner5d272cc2012-03-13 13:35:55 +0100677 exts.append( Extension('time', ['timemodule.c'],
Victor Stinnere0be4232011-10-25 13:06:09 +0200678 libraries=time_libs) )
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800679 # libm is needed by delta_new() that uses round() and by accum() that
680 # uses modf().
Victor Stinnerdef80722016-04-19 15:58:11 +0200681 exts.append( Extension('_datetime', ['_datetimemodule.c'],
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800682 libraries=['m']) )
Christian Heimesfe337bf2008-03-23 21:54:12 +0000683 # random number generator implemented in C
684 exts.append( Extension("_random", ["_randommodule.c"]) )
Raymond Hettinger0c410272004-01-05 10:13:35 +0000685 # bisect
686 exts.append( Extension("_bisect", ["_bisectmodule.c"]) )
Raymond Hettingerb3af1812003-11-08 10:24:38 +0000687 # heapq
Raymond Hettingerc46cb2a2004-04-19 19:06:21 +0000688 exts.append( Extension("_heapq", ["_heapqmodule.c"]) )
Alexandre Vassalottica2d6102008-06-12 18:26:05 +0000689 # C-optimized pickle replacement
690 exts.append( Extension("_pickle", ["_pickle.c"]) )
Collin Winter670e6922007-03-21 02:57:17 +0000691 # atexit
692 exts.append( Extension("atexit", ["atexitmodule.c"]) )
Christian Heimes90540002008-05-08 14:29:10 +0000693 # _json speedups
Victor Stinner130893d2018-11-09 13:03:37 +0100694 exts.append( Extension("_json", ["_json.c"],
695 # pycore_accu.h requires Py_BUILD_CORE_BUILTIN
696 extra_compile_args=['-DPy_BUILD_CORE_BUILTIN']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000697 # Python C API test module
Mark Dickinsona06f44b2009-02-10 16:18:22 +0000698 exts.append( Extension('_testcapi', ['_testcapimodule.c'],
699 depends=['testcapi_long.h']) )
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100700 # Python PEP-3118 (buffer protocol) test module
701 exts.append( Extension('_testbuffer', ['_testbuffer.c']) )
Andrew Svetlov6b2cbeb2012-12-14 17:04:59 +0200702 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
703 exts.append( Extension('_testimportmultiple', ['_testimportmultiple.c']) )
Nick Coghland5cacbb2015-05-23 22:24:10 +1000704 # Test multi-phase extension module init (PEP 489)
705 exts.append( Extension('_testmultiphase', ['_testmultiphase.c']) )
Fred Drake0e474a82007-10-11 18:01:43 +0000706 # profiler (_lsprof is for cProfile.py)
Armin Rigoa871ef22006-02-08 12:53:56 +0000707 exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000708 # static Unicode character database
Benjamin Peterson67752312016-09-14 23:53:47 -0700709 exts.append( Extension('unicodedata', ['unicodedata.c'],
710 depends=['unicodedata_db.h', 'unicodename_db.h']) )
Larry Hastings3a907972013-11-23 14:49:22 -0800711 # _opcode module
712 exts.append( Extension('_opcode', ['_opcode.c']) )
INADA Naoki9f2ce252016-10-15 15:39:19 +0900713 # asyncio speedups
714 exts.append( Extension("_asyncio", ["_asynciomodule.c"]) )
Ivan Levkivskyi03e3c342018-02-18 12:41:58 +0000715 # _abc speedups
716 exts.append( Extension("_abc", ["_abc.c"]) )
Antoine Pitrou94e16962018-01-16 00:27:16 +0100717 # _queue module
718 exts.append( Extension("_queue", ["_queuemodule.c"]) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000719
720 # Modules with some UNIX dependencies -- on by default:
721 # (If you have a really backward UNIX, select and socket may not be
722 # supported...)
723
724 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42 +0000725 libs = []
726 if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
727 # May be necessary on AIX for flock function
728 libs = ['bsd']
729 exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) )
Ronald Oussoren94f25282010-05-05 19:11:21 +0000730 # pwd(3)
731 exts.append( Extension('pwd', ['pwdmodule.c']) )
732 # grp(3)
pxinwr32f5fdd2019-02-27 19:09:28 +0800733 if not VXWORKS:
734 exts.append( Extension('grp', ['grpmodule.c']) )
Ronald Oussoren94f25282010-05-05 19:11:21 +0000735 # spwd, shadow passwords
736 if (config_h_vars.get('HAVE_GETSPNAM', False) or
737 config_h_vars.get('HAVE_GETSPENT', False)):
738 exts.append( Extension('spwd', ['spwdmodule.c']) )
Guido van Rossumd8faa362007-04-27 19:54:29 +0000739 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +0000740 missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29 +0000741
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000742 # select(2); not on ancient System V
743 exts.append( Extension('select', ['selectmodule.c']) )
744
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000745 # Fred Drake's interface to the Python parser
746 exts.append( Extension('parser', ['parsermodule.c']) )
747
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000748 # Memory-mapped files (also works on Win32).
Ronald Oussoren94f25282010-05-05 19:11:21 +0000749 exts.append( Extension('mmap', ['mmapmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000750
Andrew M. Kuchling57269d02004-08-31 13:37:25 +0000751 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21 +0000752 # syslog daemon interface
753 exts.append( Extension('syslog', ['syslogmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000754
Devin Jeanpierrec5bace22017-09-06 11:15:35 -0700755 # Fuzz tests.
756 exts.append( Extension(
757 '_xxtestfuzz',
758 ['_xxtestfuzz/_xxtestfuzz.c', '_xxtestfuzz/fuzzer.c'])
759 )
760
Eric Snow7f8bfc92018-01-29 18:23:44 -0700761 # Python interface to subinterpreter C-API.
762 exts.append(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c'],
763 define_macros=[('Py_BUILD_CORE', '')]))
764
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000765 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000766 # Here ends the simple stuff. From here on, modules need certain
767 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000768 #
769
770 # Multimedia modules
771 # These don't work for 64-bit platforms!!!
772 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 15:58:11 +0200773 #
Neal Norwitz5e4a3b82004-07-19 16:55:07 +0000774 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10 +0000775 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000776 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 15:58:11 +0200777 #
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800778 # audioop needs libm for floor() in multiple functions.
Victor Stinnerdef80722016-04-19 15:58:11 +0200779 exts.append( Extension('audioop', ['audioop.c'],
Benjamin Peterson8acaa312017-11-12 20:53:39 -0800780 libraries=['m']) )
Martin v. Löwis8fbefe22004-07-19 16:42:20 +0000781
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000782 # readline
Tarek Ziadé36797272010-07-22 12:50:05 +0000783 do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44 +0000784 readline_termcap_library = ""
785 curses_library = ""
doko@ubuntu.com58844492012-06-30 18:25:32 +0200786 # Cannot use os.popen here in py3k.
787 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
788 if not os.path.exists(self.build_temp):
789 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44 +0000790 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 18:25:32 +0200791 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100792 if CROSS_COMPILING:
doko@ubuntu.com58844492012-06-30 18:25:32 +0200793 ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
794 % (sysconfig.get_config_var('READELF'),
795 do_readline, tmpfile))
796 elif find_executable('ldd'):
797 ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
798 else:
799 ret = 256
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200800 if ret >> 8 == 0:
Brett Cannon9f5db072010-10-29 20:19:27 +0000801 with open(tmpfile) as fp:
802 for ln in fp:
803 if 'curses' in ln:
804 readline_termcap_library = re.sub(
805 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
806 ).rstrip()
807 break
808 # termcap interface split out from ncurses
809 if 'tinfo' in ln:
810 readline_termcap_library = 'tinfo'
811 break
doko@ubuntu.com4c990712012-06-30 23:28:09 +0200812 if os.path.exists(tmpfile):
813 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44 +0000814 # Issue 7384: If readline is already linked against curses,
815 # use the same library for the readline and curses modules.
816 if 'curses' in readline_termcap_library:
817 curses_library = readline_termcap_library
Tarek Ziadé36797272010-07-22 12:50:05 +0000818 elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44 +0000819 curses_library = 'ncursesw'
Tarek Ziadé36797272010-07-22 12:50:05 +0000820 elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000821 curses_library = 'ncurses'
Tarek Ziadé36797272010-07-22 12:50:05 +0000822 elif self.compiler.find_library_file(lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44 +0000823 curses_library = 'curses'
824
Victor Stinner4cbea512019-02-28 17:48:38 +0100825 if MACOS:
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000826 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59 +0000827 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 13:36:14 -0700828 if (dep_target and
829 (tuple(int(n) for n in dep_target.split('.')[0:2])
830 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59 +0000831 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22 +0000832 if os_release < 9:
833 # MacOSX 10.4 has a broken readline. Don't try to build
834 # the readline module unless the user has installed a fixed
835 # readline package
836 if find_file('readline/rlconf.h', inc_dirs, []) is None:
837 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23 +0000838 if do_readline:
Victor Stinner4cbea512019-02-28 17:48:38 +0100839 if MACOS and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000840 # In every directory on the search path search for a dynamic
841 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19 +0000842 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09 +0000843 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25 +0000844 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000845 readline_extra_link_args = ('-Wl,-search_paths_first',)
846 else:
847 readline_extra_link_args = ()
848
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000849 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44 +0000850 if readline_termcap_library:
851 pass # Issue 7384: Already linked against curses or tinfo.
852 elif curses_library:
853 readline_libs.append(curses_library)
Tarek Ziadé36797272010-07-22 12:50:05 +0000854 elif self.compiler.find_library_file(lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17 +0000855 ['/usr/lib/termcap'],
856 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000857 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000858 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000859 library_dirs=['/usr/lib/termcap'],
Thomas Wouters477c8d52006-05-27 19:21:47 +0000860 extra_link_args=readline_extra_link_args,
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000861 libraries=readline_libs) )
Guido van Rossumd8faa362007-04-27 19:54:29 +0000862 else:
863 missing.append('readline')
864
Ronald Oussoren94f25282010-05-05 19:11:21 +0000865 # crypt module.
Tim Peters2c60f7a2003-01-29 03:49:43 +0000866
Tarek Ziadé36797272010-07-22 12:50:05 +0000867 if self.compiler.find_library_file(lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21 +0000868 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29 +0000869 else:
Ronald Oussoren94f25282010-05-05 19:11:21 +0000870 libs = []
pxinwr32f5fdd2019-02-27 19:09:28 +0800871
872 if not VXWORKS:
873 exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) )
874 elif self.compiler.find_library_file(lib_dirs, 'OPENSSL'):
875 libs = ['OPENSSL']
876 exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000877
Skip Montanaroba9e9782003-03-20 23:34:22 +0000878 # CSV files
879 exts.append( Extension('_csv', ['_csv.c']) )
880
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000881 # POSIX subprocess module helper.
882 exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) )
883
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000884 # socket(2)
pxinwr32f5fdd2019-02-27 19:09:28 +0800885 if not VXWORKS:
886 exts.append( Extension('_socket', ['socketmodule.c'],
887 depends = ['socketmodule.h']) )
888 elif self.compiler.find_library_file(lib_dirs, 'net'):
889 libs = ['net']
890 exts.append( Extension('_socket', ['socketmodule.c'],
891 depends = ['socketmodule.h'], libraries=libs) )
892
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000893 # Detect SSL support for the socket module (via _ssl)
Christian Heimesff5be6e2018-01-20 13:19:21 +0100894 ssl_ext, hashlib_ext = self._detect_openssl(inc_dirs, lib_dirs)
895 if ssl_ext is not None:
896 exts.append(ssl_ext)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000897 else:
898 missing.append('_ssl')
Christian Heimesff5be6e2018-01-20 13:19:21 +0100899 if hashlib_ext is not None:
900 exts.append(hashlib_ext)
901 else:
902 missing.append('_hashlib')
Gregory P. Smithf21a5f72005-08-21 18:45:59 +0000903
Antoine Pitrou019ff192012-05-16 16:41:26 +0200904 # We always compile these even when OpenSSL is available (issue #14693).
Victor Stinner8c663fd2017-11-08 14:44:44 -0800905 # It's harmless and the object code is tiny (40-50 KiB per module,
Antoine Pitrou019ff192012-05-16 16:41:26 +0200906 # only loaded when actually used).
907 exts.append( Extension('_sha256', ['sha256module.c'],
908 depends=['hashlib.h']) )
909 exts.append( Extension('_sha512', ['sha512module.c'],
910 depends=['hashlib.h']) )
911 exts.append( Extension('_md5', ['md5module.c'],
912 depends=['hashlib.h']) )
913 exts.append( Extension('_sha1', ['sha1module.c'],
914 depends=['hashlib.h']) )
Gregory P. Smith2f21eb32007-09-09 06:44:34 +0000915
Christian Heimes3c397e42016-09-06 22:35:14 +0200916 blake2_deps = glob(os.path.join(os.getcwd(), srcdir,
917 'Modules/_blake2/impl/*'))
Christian Heimes121b9482016-09-06 22:03:25 +0200918 blake2_deps.append('hashlib.h')
919
Christian Heimes121b9482016-09-06 22:03:25 +0200920 exts.append( Extension('_blake2',
921 ['_blake2/blake2module.c',
922 '_blake2/blake2b_impl.c',
923 '_blake2/blake2s_impl.c'],
Christian Heimes121b9482016-09-06 22:03:25 +0200924 depends=blake2_deps) )
925
Christian Heimes6fe2a752016-09-07 11:58:24 +0200926 sha3_deps = glob(os.path.join(os.getcwd(), srcdir,
927 'Modules/_sha3/kcp/*'))
928 sha3_deps.append('hashlib.h')
929 exts.append( Extension('_sha3',
930 ['_sha3/sha3module.c'],
931 depends=sha3_deps))
932
Georg Brandl489cb4f2009-07-11 10:08:49 +0000933 # Modules that provide persistent dictionary-like semantics. You will
934 # probably want to arrange for at least one of them to be available on
935 # your machine, though none are defined by default because of library
936 # dependencies. The Python module dbm/__init__.py provides an
937 # implementation independent wrapper for these; dbm/dumb.py provides
938 # similar functionality (but slower of course) implemented in Python.
939
940 # Sleepycat^WOracle Berkeley DB interface.
941 # http://www.oracle.com/database/berkeley-db/db/index.html
942 #
943 # This requires the Sleepycat^WOracle DB code. The supported versions
944 # are set below. Visit the URL above to download
945 # a release. Most open source OSes come with one or more
946 # versions of BerkeleyDB already installed.
947
doko@ubuntu.com15bac0f2012-07-01 10:35:54 +0200948 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49 +0000949 min_db_ver = (3, 3)
950 db_setup_debug = False # verbose debug prints from this script?
951
952 def allow_db_ver(db_ver):
953 """Returns a boolean if the given BerkeleyDB version is acceptable.
954
955 Args:
956 db_ver: A tuple of the version to verify.
957 """
958 if not (min_db_ver <= db_ver <= max_db_ver):
959 return False
960 return True
961
962 def gen_db_minor_ver_nums(major):
963 if major == 4:
964 for x in range(max_db_ver[1]+1):
965 if allow_db_ver((4, x)):
966 yield x
967 elif major == 3:
968 for x in (3,):
969 if allow_db_ver((3, x)):
970 yield x
971 else:
972 raise ValueError("unknown major BerkeleyDB version", major)
973
974 # construct a list of paths to look for the header file in on
975 # top of the normal inc_dirs.
976 db_inc_paths = [
977 '/usr/include/db4',
978 '/usr/local/include/db4',
979 '/opt/sfw/include/db4',
980 '/usr/include/db3',
981 '/usr/local/include/db3',
982 '/opt/sfw/include/db3',
983 # Fink defaults (http://fink.sourceforge.net/)
984 '/sw/include/db4',
985 '/sw/include/db3',
986 ]
987 # 4.x minor number specific paths
988 for x in gen_db_minor_ver_nums(4):
989 db_inc_paths.append('/usr/include/db4%d' % x)
990 db_inc_paths.append('/usr/include/db4.%d' % x)
991 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
992 db_inc_paths.append('/usr/local/include/db4%d' % x)
993 db_inc_paths.append('/pkg/db-4.%d/include' % x)
994 db_inc_paths.append('/opt/db-4.%d/include' % x)
995 # MacPorts default (http://www.macports.org/)
996 db_inc_paths.append('/opt/local/include/db4%d' % x)
997 # 3.x minor number specific paths
998 for x in gen_db_minor_ver_nums(3):
999 db_inc_paths.append('/usr/include/db3%d' % x)
1000 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1001 db_inc_paths.append('/usr/local/include/db3%d' % x)
1002 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1003 db_inc_paths.append('/opt/db-3.%d/include' % x)
1004
Victor Stinner4cbea512019-02-28 17:48:38 +01001005 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001006 db_inc_paths = []
1007
Georg Brandl489cb4f2009-07-11 10:08:49 +00001008 # Add some common subdirectories for Sleepycat DB to the list,
1009 # based on the standard include directories. This way DB3/4 gets
1010 # picked up when it is installed in a non-standard prefix and
1011 # the user has added that prefix into inc_dirs.
1012 std_variants = []
1013 for dn in inc_dirs:
1014 std_variants.append(os.path.join(dn, 'db3'))
1015 std_variants.append(os.path.join(dn, 'db4'))
1016 for x in gen_db_minor_ver_nums(4):
1017 std_variants.append(os.path.join(dn, "db4%d"%x))
1018 std_variants.append(os.path.join(dn, "db4.%d"%x))
1019 for x in gen_db_minor_ver_nums(3):
1020 std_variants.append(os.path.join(dn, "db3%d"%x))
1021 std_variants.append(os.path.join(dn, "db3.%d"%x))
1022
1023 db_inc_paths = std_variants + db_inc_paths
1024 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1025
1026 db_ver_inc_map = {}
1027
Victor Stinner4cbea512019-02-28 17:48:38 +01001028 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001029 sysroot = macosx_sdk_root()
1030
Georg Brandl489cb4f2009-07-11 10:08:49 +00001031 class db_found(Exception): pass
1032 try:
1033 # See whether there is a Sleepycat header in the standard
1034 # search path.
1035 for d in inc_dirs + db_inc_paths:
1036 f = os.path.join(d, "db.h")
Victor Stinner4cbea512019-02-28 17:48:38 +01001037 if MACOS and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001038 f = os.path.join(sysroot, d[1:], "db.h")
1039
Georg Brandl489cb4f2009-07-11 10:08:49 +00001040 if db_setup_debug: print("db: looking for db.h in", f)
1041 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:27 +00001042 with open(f, 'rb') as file:
1043 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:03 +00001044 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001045 if m:
1046 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:03 +00001047 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001048 db_minor = int(m.group(1))
1049 db_ver = (db_major, db_minor)
1050
1051 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1052 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:03 +00001053 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001054 db_patch = int(m.group(1))
1055 if db_patch < 21:
1056 print("db.h:", db_ver, "patch", db_patch,
1057 "being ignored (4.6.x must be >= 4.6.21)")
1058 continue
1059
1060 if ( (db_ver not in db_ver_inc_map) and
1061 allow_db_ver(db_ver) ):
1062 # save the include directory with the db.h version
1063 # (first occurrence only)
1064 db_ver_inc_map[db_ver] = d
1065 if db_setup_debug:
1066 print("db.h: found", db_ver, "in", d)
1067 else:
1068 # we already found a header for this library version
1069 if db_setup_debug: print("db.h: ignoring", d)
1070 else:
1071 # ignore this header, it didn't contain a version number
1072 if db_setup_debug:
1073 print("db.h: no version number version in", d)
1074
1075 db_found_vers = list(db_ver_inc_map.keys())
1076 db_found_vers.sort()
1077
1078 while db_found_vers:
1079 db_ver = db_found_vers.pop()
1080 db_incdir = db_ver_inc_map[db_ver]
1081
1082 # check lib directories parallel to the location of the header
1083 db_dirs_to_check = [
1084 db_incdir.replace("include", 'lib64'),
1085 db_incdir.replace("include", 'lib'),
1086 ]
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001087
Victor Stinner4cbea512019-02-28 17:48:38 +01001088 if not MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001089 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1090
1091 else:
1092 # Same as other branch, but takes OSX SDK into account
1093 tmp = []
1094 for dn in db_dirs_to_check:
1095 if is_macosx_sdk_path(dn):
1096 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1097 tmp.append(dn)
1098 else:
1099 if os.path.isdir(dn):
1100 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:46 +00001101 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001102
1103 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:49 +00001104
Ezio Melotti42da6632011-03-15 05:18:48 +02001105 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:49 +00001106 # XXX should we -ever- look for a dbX name? Do any
1107 # systems really not name their library by version and
1108 # symlink to more general names?
1109 for dblib in (('db-%d.%d' % db_ver),
1110 ('db%d%d' % db_ver),
1111 ('db%d' % db_ver[0])):
1112 dblib_file = self.compiler.find_library_file(
1113 db_dirs_to_check + lib_dirs, dblib )
1114 if dblib_file:
1115 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1116 raise db_found
1117 else:
1118 if db_setup_debug: print("db lib: ", dblib, "not found")
1119
1120 except db_found:
1121 if db_setup_debug:
1122 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1123 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:49 +00001124 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001125 # Only add the found library and include directories if they aren't
1126 # already being searched. This avoids an explicit runtime library
1127 # dependency.
1128 if db_incdir in inc_dirs:
1129 db_incs = None
1130 else:
1131 db_incs = [db_incdir]
1132 if dblib_dir[0] in lib_dirs:
1133 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:49 +00001134 else:
1135 if db_setup_debug: print("db: no appropriate library found")
1136 db_incs = None
1137 dblibs = []
1138 dblib_dir = None
1139
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001140 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:30 +00001141 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001142
1143 # We hunt for #define SQLITE_VERSION "n.n.n"
1144 # We need to find >= sqlite version 3.0.8
1145 sqlite_incdir = sqlite_libdir = None
1146 sqlite_inc_paths = [ '/usr/include',
1147 '/usr/include/sqlite',
1148 '/usr/include/sqlite3',
1149 '/usr/local/include',
1150 '/usr/local/include/sqlite',
1151 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001152 ]
Victor Stinner4cbea512019-02-28 17:48:38 +01001153 if CROSS_COMPILING:
doko@ubuntu.com1abe1c52012-06-30 20:42:45 +02001154 sqlite_inc_paths = []
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001155 MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
1156 MIN_SQLITE_VERSION = ".".join([str(x)
1157 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:47 +00001158
1159 # Scan the default include directories before the SQLite specific
1160 # ones. This allows one to override the copy of sqlite on OSX,
1161 # where /usr/include contains an old version of sqlite.
Victor Stinner4cbea512019-02-28 17:48:38 +01001162 if MACOS:
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001163 sysroot = macosx_sdk_root()
1164
Ned Deily9b635832012-08-05 15:13:33 -07001165 for d_ in inc_dirs + sqlite_inc_paths:
1166 d = d_
Victor Stinner4cbea512019-02-28 17:48:38 +01001167 if MACOS and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 15:13:33 -07001168 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001169
Ned Deily9b635832012-08-05 15:13:33 -07001170 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001171 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:43 +00001172 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:27 +00001173 with open(f) as file:
1174 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001175 m = re.search(
Petri Lehtinened909bc2013-02-23 17:05:28 +01001176 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001177 if m:
1178 sqlite_version = m.group(1)
1179 sqlite_version_tuple = tuple([int(x)
1180 for x in sqlite_version.split(".")])
1181 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1182 # we win!
Thomas Wouters89f507f2006-12-13 04:49:30 +00001183 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001184 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001185 sqlite_incdir = d
1186 break
1187 else:
1188 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001189 print("%s: version %d is too old, need >= %s"%(d,
1190 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001191 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:43 +00001192 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001193
1194 if sqlite_incdir:
1195 sqlite_dirs_to_check = [
1196 os.path.join(sqlite_incdir, '..', 'lib64'),
1197 os.path.join(sqlite_incdir, '..', 'lib'),
1198 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1199 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1200 ]
Tarek Ziadé36797272010-07-22 12:50:05 +00001201 sqlite_libfile = self.compiler.find_library_file(
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001202 sqlite_dirs_to_check + lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:57 +00001203 if sqlite_libfile:
1204 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001205
1206 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001207 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001208 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001209 '_sqlite/cursor.c',
1210 '_sqlite/microprotocols.c',
1211 '_sqlite/module.c',
1212 '_sqlite/prepare_protocol.c',
1213 '_sqlite/row.c',
1214 '_sqlite/statement.c',
1215 '_sqlite/util.c', ]
1216
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001217 sqlite_defines = []
Victor Stinner4cbea512019-02-28 17:48:38 +01001218 if not MS_WINDOWS:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001219 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1220 else:
1221 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1222
Benjamin Peterson076ed002010-10-31 17:11:02 +00001223 # Enable support for loadable extensions in the sqlite3 module
1224 # if --enable-loadable-sqlite-extensions configure option is used.
1225 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1226 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:47 +00001227
Victor Stinner4cbea512019-02-28 17:48:38 +01001228 if MACOS:
Thomas Wouters477c8d52006-05-27 19:21:47 +00001229 # In every directory on the search path search for a dynamic
1230 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 11:05:33 +02001231 # for dynamic libraries on the entire path.
1232 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:47 +00001233 # before the dynamic library in /usr/lib.
1234 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1235 else:
1236 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001237
Brett Cannonc5011fe2011-06-06 20:09:10 -07001238 include_dirs = ["Modules/_sqlite"]
1239 # Only include the directory where sqlite was found if it does
1240 # not already exist in set include directories, otherwise you
1241 # can end up with a bad search path order.
1242 if sqlite_incdir not in self.compiler.include_dirs:
1243 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001244 # avoid a runtime library path for a system library dir
1245 if sqlite_libdir and sqlite_libdir[0] in lib_dirs:
1246 sqlite_libdir = None
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001247 exts.append(Extension('_sqlite3', sqlite_srcs,
1248 define_macros=sqlite_defines,
Brett Cannonc5011fe2011-06-06 20:09:10 -07001249 include_dirs=include_dirs,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001250 library_dirs=sqlite_libdir,
Thomas Wouters477c8d52006-05-27 19:21:47 +00001251 extra_link_args=sqlite_extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001252 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001253 else:
1254 missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:34 +00001255
Ross Lagerwall0b63b562012-04-15 08:19:35 +02001256 dbm_setup_debug = False # verbose debug prints from this script?
Benjamin Petersond78735d2010-01-01 16:04:23 +00001257 dbm_order = ['gdbm']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001258 # The standard Unix dbm module:
Victor Stinner4cbea512019-02-28 17:48:38 +01001259 if not CYGWIN:
Matthias Klose55708cc2009-04-30 08:06:49 +00001260 config_args = [arg.strip("'")
1261 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
Benjamin Petersond78735d2010-01-01 16:04:23 +00001262 dbm_args = [arg for arg in config_args
Matthias Klose55708cc2009-04-30 08:06:49 +00001263 if arg.startswith('--with-dbmliborder=')]
1264 if dbm_args:
Benjamin Petersond78735d2010-01-01 16:04:23 +00001265 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
Matthias Klose55708cc2009-04-30 08:06:49 +00001266 else:
Georg Brandl489cb4f2009-07-11 10:08:49 +00001267 dbm_order = "ndbm:gdbm:bdb".split(":")
Matthias Klose55708cc2009-04-30 08:06:49 +00001268 dbmext = None
1269 for cand in dbm_order:
1270 if cand == "ndbm":
1271 if find_file("ndbm.h", inc_dirs, []) is not None:
Nick Coghlan50f147a2012-06-17 18:27:11 +10001272 # Some systems have -lndbm, others have -lgdbm_compat,
1273 # others don't have either
Tarek Ziadé36797272010-07-22 12:50:05 +00001274 if self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001275 'ndbm'):
Matthias Klose55708cc2009-04-30 08:06:49 +00001276 ndbm_libs = ['ndbm']
Nick Coghlan50f147a2012-06-17 18:27:11 +10001277 elif self.compiler.find_library_file(lib_dirs,
1278 'gdbm_compat'):
1279 ndbm_libs = ['gdbm_compat']
Matthias Klose55708cc2009-04-30 08:06:49 +00001280 else:
1281 ndbm_libs = []
Ross Lagerwall0b63b562012-04-15 08:19:35 +02001282 if dbm_setup_debug: print("building dbm using ndbm")
Matthias Klose55708cc2009-04-30 08:06:49 +00001283 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1284 define_macros=[
1285 ('HAVE_NDBM_H',None),
1286 ],
1287 libraries=ndbm_libs)
1288 break
1289
1290 elif cand == "gdbm":
Tarek Ziadé36797272010-07-22 12:50:05 +00001291 if self.compiler.find_library_file(lib_dirs, 'gdbm'):
Matthias Klose55708cc2009-04-30 08:06:49 +00001292 gdbm_libs = ['gdbm']
Tarek Ziadé36797272010-07-22 12:50:05 +00001293 if self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001294 'gdbm_compat'):
Matthias Klose55708cc2009-04-30 08:06:49 +00001295 gdbm_libs.append('gdbm_compat')
1296 if find_file("gdbm/ndbm.h", inc_dirs, []) is not None:
Ross Lagerwall0b63b562012-04-15 08:19:35 +02001297 if dbm_setup_debug: print("building dbm using gdbm")
Matthias Klose55708cc2009-04-30 08:06:49 +00001298 dbmext = Extension(
1299 '_dbm', ['_dbmmodule.c'],
1300 define_macros=[
1301 ('HAVE_GDBM_NDBM_H', None),
1302 ],
1303 libraries = gdbm_libs)
1304 break
1305 if find_file("gdbm-ndbm.h", inc_dirs, []) is not None:
Ross Lagerwall0b63b562012-04-15 08:19:35 +02001306 if dbm_setup_debug: print("building dbm using gdbm")
Matthias Klose55708cc2009-04-30 08:06:49 +00001307 dbmext = Extension(
1308 '_dbm', ['_dbmmodule.c'],
1309 define_macros=[
1310 ('HAVE_GDBM_DASH_NDBM_H', None),
1311 ],
1312 libraries = gdbm_libs)
1313 break
Georg Brandl489cb4f2009-07-11 10:08:49 +00001314 elif cand == "bdb":
doko@ubuntu.coma3818a32014-04-17 17:52:48 +02001315 if dblibs:
Ross Lagerwall0b63b562012-04-15 08:19:35 +02001316 if dbm_setup_debug: print("building dbm using bdb")
Georg Brandl489cb4f2009-07-11 10:08:49 +00001317 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1318 library_dirs=dblib_dir,
1319 runtime_library_dirs=dblib_dir,
1320 include_dirs=db_incs,
1321 define_macros=[
1322 ('HAVE_BERKDB_H', None),
1323 ('DB_DBM_HSEARCH', None),
1324 ],
1325 libraries=dblibs)
Matthias Klose55708cc2009-04-30 08:06:49 +00001326 break
1327 if dbmext is not None:
1328 exts.append(dbmext)
Guido van Rossumd8faa362007-04-27 19:54:29 +00001329 else:
Georg Brandl0a7ac7d2008-05-26 10:29:35 +00001330 missing.append('_dbm')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001331
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001332 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
Benjamin Petersond78735d2010-01-01 16:04:23 +00001333 if ('gdbm' in dbm_order and
Tarek Ziadé36797272010-07-22 12:50:05 +00001334 self.compiler.find_library_file(lib_dirs, 'gdbm')):
Georg Brandl0a7ac7d2008-05-26 10:29:35 +00001335 exts.append( Extension('_gdbm', ['_gdbmmodule.c'],
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001336 libraries = ['gdbm'] ) )
Guido van Rossumd8faa362007-04-27 19:54:29 +00001337 else:
Georg Brandl0a7ac7d2008-05-26 10:29:35 +00001338 missing.append('_gdbm')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001339
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001340 # Unix-only modules
Victor Stinner4cbea512019-02-28 17:48:38 +01001341 if not MS_WINDOWS:
pxinwr32f5fdd2019-02-27 19:09:28 +08001342 if not VXWORKS:
1343 # Steen Lumholt's termios module
1344 exts.append( Extension('termios', ['termios.c']) )
1345 # Jeremy Hylton's rlimit interface
Antoine Pitrou6103ab12009-10-24 20:11:21 +00001346 exts.append( Extension('resource', ['resource.c']) )
Guido van Rossumd8faa362007-04-27 19:54:29 +00001347 else:
Christian Heimes29a7df72018-01-26 23:28:46 +01001348 missing.extend(['resource', 'termios'])
1349
1350 nis = self._detect_nis(inc_dirs, lib_dirs)
1351 if nis is not None:
1352 exts.append(nis)
1353 else:
1354 missing.append('nis')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001355
Skip Montanaro72092942004-02-07 12:50:19 +00001356 # Curses support, requiring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +00001357 # provided by the ncurses library.
Victor Stinneraa35b002011-11-29 00:08:12 +01001358 curses_defines = []
Victor Stinner756c6ec2011-11-27 00:19:53 +01001359 curses_includes = []
Victor Stinneraa35b002011-11-29 00:08:12 +01001360 panel_library = 'panel'
1361 if curses_library == 'ncursesw':
1362 curses_defines.append(('HAVE_NCURSESW', '1'))
Victor Stinner4cbea512019-02-28 17:48:38 +01001363 if not CROSS_COMPILING:
Xavier de Gayee13c3202016-12-13 16:04:14 +01001364 curses_includes.append('/usr/include/ncursesw')
Victor Stinneraa35b002011-11-29 00:08:12 +01001365 # Bug 1464056: If _curses.so links with ncursesw,
1366 # _curses_panel.so must link with panelw.
1367 panel_library = 'panelw'
Victor Stinner4cbea512019-02-28 17:48:38 +01001368 if MACOS:
Ned Deily69192232012-06-20 23:47:14 -07001369 # On OS X, there is no separate /usr/lib/libncursesw nor
1370 # libpanelw. If we are here, we found a locally-supplied
Mike53f7a7c2017-12-14 14:04:53 +03001371 # version of libncursesw. There should also be a
Ned Deily69192232012-06-20 23:47:14 -07001372 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1373 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1374 # ncurses wide char support
1375 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Victor Stinner4cbea512019-02-28 17:48:38 +01001376 elif MACOS and curses_library == 'ncurses':
Ned Deily69192232012-06-20 23:47:14 -07001377 # Building with the system-suppied combined libncurses/libpanel
1378 curses_defines.append(('HAVE_NCURSESW', '1'))
1379 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Victor Stinneraa35b002011-11-29 00:08:12 +01001380
Stefan Krah095b2732010-06-08 13:41:44 +00001381 if curses_library.startswith('ncurses'):
Stefan Krah095b2732010-06-08 13:41:44 +00001382 curses_libs = [curses_library]
Martin v. Löwisa55e55e2006-02-11 15:55:14 +00001383 exts.append( Extension('_curses', ['_cursesmodule.c'],
Victor Stinner756c6ec2011-11-27 00:19:53 +01001384 include_dirs=curses_includes,
Nadeem Vawda9e2e9902011-07-31 15:01:11 +02001385 define_macros=curses_defines,
Martin v. Löwisa55e55e2006-02-11 15:55:14 +00001386 libraries = curses_libs) )
Victor Stinner4cbea512019-02-28 17:48:38 +01001387 elif curses_library == 'curses' and not MACOS:
Michael W. Hudson5b109102002-01-23 15:04:41 +00001388 # OSX has an old Berkeley curses, not good enough for
1389 # the _curses module.
Tarek Ziadé36797272010-07-22 12:50:05 +00001390 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001391 curses_libs = ['curses', 'terminfo']
Tarek Ziadé36797272010-07-22 12:50:05 +00001392 elif (self.compiler.find_library_file(lib_dirs, 'termcap')):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001393 curses_libs = ['curses', 'termcap']
Neal Norwitz0b27ff92003-03-31 15:53:49 +00001394 else:
1395 curses_libs = ['curses']
Fredrik Lundhade711a2001-01-24 08:00:28 +00001396
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001397 exts.append( Extension('_curses', ['_cursesmodule.c'],
Nadeem Vawda9e2e9902011-07-31 15:01:11 +02001398 define_macros=curses_defines,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001399 libraries = curses_libs) )
Guido van Rossumd8faa362007-04-27 19:54:29 +00001400 else:
1401 missing.append('_curses')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001402
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001403 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:16 +00001404 if (module_enabled(exts, '_curses') and
Tarek Ziadé36797272010-07-22 12:50:05 +00001405 self.compiler.find_library_file(lib_dirs, panel_library)):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001406 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
Victor Stinner756c6ec2011-11-27 00:19:53 +01001407 include_dirs=curses_includes,
Ned Deily69192232012-06-20 23:47:14 -07001408 define_macros=curses_defines,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001409 libraries = [panel_library] + curses_libs) )
Guido van Rossumd8faa362007-04-27 19:54:29 +00001410 else:
1411 missing.append('_curses_panel')
Fredrik Lundhade711a2001-01-24 08:00:28 +00001412
Barry Warsaw259b1e12002-08-13 20:09:26 +00001413 # Andrew Kuchling's zlib module. Note that some versions of zlib
1414 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1415 # http://www.cert.org/advisories/CA-2002-07.html
1416 #
1417 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1418 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1419 # now, we still accept 1.1.3, because we think it's difficult to
1420 # exploit this in Python, and we'd rather make it RedHat's problem
1421 # than our problem <wink>.
1422 #
1423 # You can upgrade zlib to version 1.1.4 yourself by going to
1424 # http://www.gzip.org/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +00001425 zlib_inc = find_file('zlib.h', [], inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:29 +00001426 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:12 +00001427 if zlib_inc is not None:
1428 zlib_h = zlib_inc[0] + '/zlib.h'
1429 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +00001430 version_req = '"1.1.3"'
Victor Stinner4cbea512019-02-28 17:48:38 +01001431 if MACOS and is_macosx_sdk_path(zlib_h):
Ned Deily507c5912013-10-18 21:32:00 -07001432 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:27 +00001433 with open(zlib_h) as fp:
1434 while 1:
1435 line = fp.readline()
1436 if not line:
1437 break
1438 if line.startswith('#define ZLIB_VERSION'):
1439 version = line.split()[2]
1440 break
Guido van Rossume6970912001-04-15 15:16:12 +00001441 if version >= version_req:
Tarek Ziadé36797272010-07-22 12:50:05 +00001442 if (self.compiler.find_library_file(lib_dirs, 'z')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001443 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001444 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1445 else:
1446 zlib_extra_link_args = ()
Guido van Rossume6970912001-04-15 15:16:12 +00001447 exts.append( Extension('zlib', ['zlibmodule.c'],
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001448 libraries = ['z'],
1449 extra_link_args = zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:29 +00001450 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:29 +00001451 else:
1452 missing.append('zlib')
1453 else:
1454 missing.append('zlib')
1455 else:
1456 missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001457
Christian Heimes1dc54002008-03-24 02:19:29 +00001458 # Helper module for various ascii-encoders. Uses zlib for an optimized
1459 # crc32 if we have it. Otherwise binascii uses its own.
1460 if have_zlib:
1461 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1462 libraries = ['z']
1463 extra_link_args = zlib_extra_link_args
1464 else:
1465 extra_compile_args = []
1466 libraries = []
1467 extra_link_args = []
1468 exts.append( Extension('binascii', ['binascii.c'],
1469 extra_compile_args = extra_compile_args,
1470 libraries = libraries,
1471 extra_link_args = extra_link_args) )
1472
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001473 # Gustavo Niemeyer's bz2 module.
Tarek Ziadé36797272010-07-22 12:50:05 +00001474 if (self.compiler.find_library_file(lib_dirs, 'bz2')):
Victor Stinner4cbea512019-02-28 17:48:38 +01001475 if MACOS:
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001476 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1477 else:
1478 bz2_extra_link_args = ()
Antoine Pitrou37dc5f82011-04-03 17:05:46 +02001479 exts.append( Extension('_bz2', ['_bz2module.c'],
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001480 libraries = ['bz2'],
1481 extra_link_args = bz2_extra_link_args) )
Guido van Rossumd8faa362007-04-27 19:54:29 +00001482 else:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +02001483 missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +00001484
Nadeem Vawda3ff069e2011-11-30 00:25:06 +02001485 # LZMA compression support.
1486 if self.compiler.find_library_file(lib_dirs, 'lzma'):
1487 exts.append( Extension('_lzma', ['_lzmamodule.c'],
1488 libraries = ['lzma']) )
1489 else:
1490 missing.append('_lzma')
1491
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001492 # Interface to the Expat XML parser
1493 #
Benjamin Petersona28e7022010-01-09 18:53:06 +00001494 # Expat was written by James Clark and is now maintained by a group of
1495 # developers on SourceForge; see www.libexpat.org for more information.
1496 # The pyexpat module was written by Paul Prescod after a prototype by
1497 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1498 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:19 +00001499 # configure option.
Fred Drakefc8341d2002-06-17 17:55:30 +00001500 #
1501 # More information on Expat can be found at www.libexpat.org.
1502 #
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001503 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1504 expat_inc = []
1505 define_macros = []
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001506 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001507 expat_lib = ['expat']
1508 expat_sources = []
Christian Heimesd489c7a2013-02-09 17:02:06 +01001509 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001510 else:
1511 expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')]
1512 define_macros = [
1513 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner93d0cb52017-08-18 23:43:54 +02001514 # bpo-30947: Python uses best available entropy sources to
1515 # call XML_SetHashSalt(), expat entropy sources are not needed
1516 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001517 ]
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001518 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001519 expat_lib = []
1520 expat_sources = ['expat/xmlparse.c',
1521 'expat/xmlrole.c',
1522 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 17:02:06 +01001523 expat_depends = ['expat/ascii.h',
1524 'expat/asciitab.h',
1525 'expat/expat.h',
1526 'expat/expat_config.h',
1527 'expat/expat_external.h',
1528 'expat/internal.h',
1529 'expat/latin1tab.h',
1530 'expat/utf8tab.h',
1531 'expat/xmlrole.h',
1532 'expat/xmltok.h',
1533 'expat/xmltok_impl.h'
1534 ]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001535
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001536 cc = sysconfig.get_config_var('CC').split()[0]
1537 ret = os.system(
1538 '"%s" -Werror -Wimplicit-fallthrough -E -xc /dev/null >/dev/null 2>&1' % cc)
1539 if ret >> 8 == 0:
1540 extra_compile_args.append('-Wno-implicit-fallthrough')
1541
Fred Drake2d59a492003-10-21 15:41:15 +00001542 exts.append(Extension('pyexpat',
1543 define_macros = define_macros,
Stefan Krah9e1e6f52017-08-25 14:07:50 +02001544 extra_compile_args = extra_compile_args,
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001545 include_dirs = expat_inc,
1546 libraries = expat_lib,
Christian Heimesd489c7a2013-02-09 17:02:06 +01001547 sources = ['pyexpat.c'] + expat_sources,
1548 depends = expat_depends,
Fred Drake2d59a492003-10-21 15:41:15 +00001549 ))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001550
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001551 # Fredrik Lundh's cElementTree module. Note that this also
1552 # uses expat (via the CAPI hook in pyexpat).
1553
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001554 if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001555 define_macros.append(('USE_PYEXPAT_CAPI', None))
1556 exts.append(Extension('_elementtree',
1557 define_macros = define_macros,
Benjamin Petersonb2d90462009-12-31 03:23:10 +00001558 include_dirs = expat_inc,
1559 libraries = expat_lib,
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001560 sources = ['_elementtree.c'],
Christian Heimesd489c7a2013-02-09 17:02:06 +01001561 depends = ['pyexpat.c'] + expat_sources +
1562 expat_depends,
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001563 ))
Guido van Rossumd8faa362007-04-27 19:54:29 +00001564 else:
1565 missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:16 +00001566
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001567 # Hye-Shik Chang's CJKCodecs modules.
Walter Dörwalde9eaab42007-05-22 16:02:13 +00001568 exts.append(Extension('_multibytecodec',
1569 ['cjkcodecs/multibytecodec.c']))
1570 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
1571 exts.append(Extension('_codecs_%s' % loc,
1572 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001573
Stefan Krah1919b7e2012-03-21 18:25:23 +01001574 # Stefan Krah's _decimal module
1575 exts.append(self._decimal_ext())
1576
Thomas Hellercf567c12006-03-08 19:51:58 +00001577 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001578 self.detect_ctypes(inc_dirs, lib_dirs)
Thomas Hellercf567c12006-03-08 19:51:58 +00001579
Benjamin Petersone711caf2008-06-11 16:44:04 +00001580 # Richard Oudkerk's multiprocessing module
Victor Stinner4cbea512019-02-28 17:48:38 +01001581 if MS_WINDOWS:
Benjamin Petersone711caf2008-06-11 16:44:04 +00001582 macros = dict()
1583 libraries = ['ws2_32']
1584
Victor Stinner4cbea512019-02-28 17:48:38 +01001585 elif MACOS: # Mac OSX
Benjamin Peterson965ce872009-04-05 21:24:58 +00001586 macros = dict()
Benjamin Petersone711caf2008-06-11 16:44:04 +00001587 libraries = []
1588
Victor Stinner4cbea512019-02-28 17:48:38 +01001589 elif CYGWIN:
Benjamin Peterson965ce872009-04-05 21:24:58 +00001590 macros = dict()
Benjamin Petersone711caf2008-06-11 16:44:04 +00001591 libraries = []
Benjamin Peterson41181742008-07-02 20:22:54 +00001592
Victor Stinner4cbea512019-02-28 17:48:38 +01001593 elif HOST_PLATFORM.startswith('openbsd'):
Benjamin Peterson965ce872009-04-05 21:24:58 +00001594 macros = dict()
Benjamin Petersone5384b02008-10-04 22:00:42 +00001595 libraries = []
1596
Victor Stinner4cbea512019-02-28 17:48:38 +01001597 elif HOST_PLATFORM.startswith('netbsd'):
Benjamin Peterson965ce872009-04-05 21:24:58 +00001598 macros = dict()
Jesse Noller32d68c22009-03-31 18:48:42 +00001599 libraries = []
1600
Benjamin Petersone711caf2008-06-11 16:44:04 +00001601 else: # Linux and other unices
Benjamin Peterson965ce872009-04-05 21:24:58 +00001602 macros = dict()
Benjamin Petersone711caf2008-06-11 16:44:04 +00001603 libraries = ['rt']
1604
Victor Stinner4cbea512019-02-28 17:48:38 +01001605 if MS_WINDOWS:
Benjamin Petersone711caf2008-06-11 16:44:04 +00001606 multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
1607 '_multiprocessing/semaphore.c',
Benjamin Petersone711caf2008-06-11 16:44:04 +00001608 ]
1609
1610 else:
1611 multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
Benjamin Petersone711caf2008-06-11 16:44:04 +00001612 ]
Mark Dickinsona614f042009-11-28 12:48:43 +00001613 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1614 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:04 +00001615 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Neil Schemenauer5741c452019-02-08 10:48:46 -08001616 if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1617 sysconfig.get_config_var('HAVE_SHM_UNLINK')):
Davin Pottse5ef45b2019-02-01 22:52:23 -06001618 posixshmem_srcs = [ '_multiprocessing/posixshmem.c',
1619 ]
1620 libs = []
Neil Schemenauer5741c452019-02-08 10:48:46 -08001621 if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1622 # need to link with librt to get shm_open()
Davin Pottse5ef45b2019-02-01 22:52:23 -06001623 libs.append('rt')
1624 exts.append( Extension('_posixshmem', posixshmem_srcs,
1625 define_macros={},
1626 libraries=libs,
1627 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001628
Antoine Pitroua6a4dc82017-09-07 18:56:24 +02001629 exts.append ( Extension('_multiprocessing', multiprocessing_srcs,
1630 define_macros=list(macros.items()),
1631 include_dirs=["Modules/_multiprocessing"]))
Benjamin Petersone711caf2008-06-11 16:44:04 +00001632 # End multiprocessing
Guido van Rossuma9e20242007-03-08 00:43:48 +00001633
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001634 # Platform-specific libraries
Victor Stinner4cbea512019-02-28 17:48:38 +01001635 if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
Guido van Rossum0c016a92003-02-13 16:12:21 +00001636 exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
Guido van Rossumd8faa362007-04-27 19:54:29 +00001637 else:
1638 missing.append('ossaudiodev')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001639
Victor Stinner4cbea512019-02-28 17:48:38 +01001640 if MACOS:
Benjamin Petersonebacd262008-05-29 21:09:51 +00001641 exts.append(
Ronald Oussoren84151202010-04-18 20:46:11 +00001642 Extension('_scproxy', ['_scproxy.c'],
1643 extra_link_args=[
1644 '-framework', 'SystemConfiguration',
1645 '-framework', 'CoreFoundation',
1646 ]))
Benjamin Petersonebacd262008-05-29 21:09:51 +00001647
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001648 self.extensions.extend(exts)
1649
1650 # Call the method for detecting whether _tkinter can be compiled
1651 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001652
Guido van Rossumd8faa362007-04-27 19:54:29 +00001653 if '_tkinter' not in [e.name for e in self.extensions]:
1654 missing.append('_tkinter')
1655
Antoine Pitroua106aec2017-09-28 23:03:06 +02001656 # Build the _uuid module if possible
1657 uuid_incs = find_file("uuid.h", inc_dirs, ["/usr/include/uuid"])
Nick Coghlan53efbf32017-11-26 13:04:46 +10001658 if uuid_incs is not None:
Antoine Pitroua106aec2017-09-28 23:03:06 +02001659 if self.compiler.find_library_file(lib_dirs, 'uuid'):
1660 uuid_libs = ['uuid']
1661 else:
1662 uuid_libs = []
Antoine Pitroua106aec2017-09-28 23:03:06 +02001663 self.extensions.append(Extension('_uuid', ['_uuidmodule.c'],
1664 libraries=uuid_libs,
1665 include_dirs=uuid_incs))
1666 else:
1667 missing.append('_uuid')
1668
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001669## # Uncomment these lines if you want to play with xxmodule.c
1670## ext = Extension('xx', ['xxmodule.c'])
1671## self.extensions.append(ext)
1672
Xavier de Gaye13f1c332016-12-10 16:45:53 +01001673 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001674 ext = Extension('xxlimited', ['xxlimited.c'],
Benjamin Peterson24ac8772015-06-03 00:04:46 -05001675 define_macros=[('Py_LIMITED_API', '0x03050000')])
Ned Deilycd3d8fb2013-08-01 23:51:27 -07001676 self.extensions.append(ext)
1677
Guido van Rossumd8faa362007-04-27 19:54:29 +00001678 return missing
1679
Ned Deilyd819b932013-09-06 01:07:05 -07001680 def detect_tkinter_explicitly(self):
1681 # Build _tkinter using explicit locations for Tcl/Tk.
1682 #
1683 # This is enabled when both arguments are given to ./configure:
1684 #
1685 # --with-tcltk-includes="-I/path/to/tclincludes \
1686 # -I/path/to/tkincludes"
1687 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1688 # -L/path/to/tklibs -ltkm.n"
1689 #
Martin Pantere26da7c2016-06-02 10:07:09 +00001690 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 01:07:05 -07001691 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1692 #
1693 # This can be useful for building and testing tkinter with multiple
1694 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1695 # build of Tcl so you need to specify both arguments and use care when
1696 # overriding.
1697
1698 # The _TCLTK variables are created in the Makefile sharedmods target.
1699 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1700 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1701 if not (tcltk_includes and tcltk_libs):
1702 # Resume default configuration search.
Victor Stinner4cbea512019-02-28 17:48:38 +01001703 return False
Ned Deilyd819b932013-09-06 01:07:05 -07001704
1705 extra_compile_args = tcltk_includes.split()
1706 extra_link_args = tcltk_libs.split()
1707 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1708 define_macros=[('WITH_APPINIT', 1)],
1709 extra_compile_args = extra_compile_args,
1710 extra_link_args = extra_link_args,
1711 )
1712 self.extensions.append(ext)
Victor Stinner4cbea512019-02-28 17:48:38 +01001713 return True
Ned Deilyd819b932013-09-06 01:07:05 -07001714
Jack Jansen0b06be72002-06-21 14:48:38 +00001715 def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
1716 # The _tkinter module, using frameworks. Since frameworks are quite
1717 # different the UNIX search logic is not sharable.
1718 from os.path import join, exists
1719 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001720 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:48 +00001721 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:38 +00001722 join(os.getenv('HOME'), '/Library/Frameworks')
1723 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001724
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001725 sysroot = macosx_sdk_root()
1726
Skip Montanaro0174ddd2005-12-30 05:01:26 +00001727 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:38 +00001728 # bundles.
1729 # XXX distutils should support -F!
1730 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:43 +00001731 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001732
1733
Jack Jansen0b06be72002-06-21 14:48:38 +00001734 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001735 if is_macosx_sdk_path(F):
1736 if not exists(join(sysroot, F[1:], fw + '.framework')):
1737 break
1738 else:
1739 if not exists(join(F, fw + '.framework')):
1740 break
Jack Jansen0b06be72002-06-21 14:48:38 +00001741 else:
1742 # ok, F is now directory with both frameworks. Continure
1743 # building
1744 break
1745 else:
1746 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1747 # will now resume.
Victor Stinner4cbea512019-02-28 17:48:38 +01001748 return False
Tim Peters2c60f7a2003-01-29 03:49:43 +00001749
Jack Jansen0b06be72002-06-21 14:48:38 +00001750 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1751 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:43 +00001752 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:38 +00001753 #
1754 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:43 +00001755 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:43 +00001756 for fw in ('Tcl', 'Tk')
1757 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:38 +00001758 ]
1759
Tim Peters2c60f7a2003-01-29 03:49:43 +00001760 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:38 +00001761 # complicated search, this is a hard-coded path. It could bail out
1762 # if X11 libs are not found...
1763 include_dirs.append('/usr/X11R6/include')
1764 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1765
Georg Brandlfcaf9102008-07-16 02:17:56 +00001766 # All existing framework builds of Tcl/Tk don't support 64-bit
1767 # architectures.
1768 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 13:59:53 -04001769 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001770
Ronald Oussorend097efe2009-09-15 19:07:58 +00001771 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1772 if not os.path.exists(self.build_temp):
1773 os.makedirs(self.build_temp)
1774
1775 # Note: cannot use os.popen or subprocess here, that
1776 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001777 if is_macosx_sdk_path(F):
1778 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1779 else:
1780 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:25 +00001781
Brett Cannon9f5db072010-10-29 20:19:27 +00001782 with open(tmpfile) as fp:
1783 detected_archs = []
1784 for ln in fp:
1785 a = ln.split()[-1]
1786 if a in archs:
1787 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:58 +00001788 os.unlink(tmpfile)
1789
1790 for a in detected_archs:
1791 frameworks.append('-arch')
1792 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:56 +00001793
Jack Jansen0b06be72002-06-21 14:48:38 +00001794 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1795 define_macros=[('WITH_APPINIT', 1)],
1796 include_dirs = include_dirs,
1797 libraries = [],
Georg Brandlfcaf9102008-07-16 02:17:56 +00001798 extra_compile_args = frameworks[2:],
Jack Jansen0b06be72002-06-21 14:48:38 +00001799 extra_link_args = frameworks,
1800 )
1801 self.extensions.append(ext)
Victor Stinner4cbea512019-02-28 17:48:38 +01001802 return True
Jack Jansen0b06be72002-06-21 14:48:38 +00001803
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001804 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001805 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +00001806
Ned Deilyd819b932013-09-06 01:07:05 -07001807 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1808 # configured or passed into the make target. If so, use these values
1809 # to build tkinter and bypass the searches for Tcl and TK in standard
1810 # locations.
1811 if self.detect_tkinter_explicitly():
1812 return
1813
Jack Jansen0b06be72002-06-21 14:48:38 +00001814 # Rather than complicate the code below, detecting and building
1815 # AquaTk is a separate method. Only one Tkinter will be built on
1816 # Darwin - either AquaTk, if it is found, or X11 based Tk.
Victor Stinner4cbea512019-02-28 17:48:38 +01001817 if (MACOS and
Skip Montanaro0174ddd2005-12-30 05:01:26 +00001818 self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
Tim Peters2c60f7a2003-01-29 03:49:43 +00001819 return
Jack Jansen0b06be72002-06-21 14:48:38 +00001820
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001821 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001822 # The versions with dots are used on Unix, and the versions without
1823 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001824 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:14 +00001825 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1826 '8.2', '82', '8.1', '81', '8.0', '80']:
Tarek Ziadé36797272010-07-22 12:50:05 +00001827 tklib = self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001828 'tk' + version)
Tarek Ziadé36797272010-07-22 12:50:05 +00001829 tcllib = self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001830 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:41 +00001831 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001832 # Exit the loop when we've found the Tcl/Tk libraries
1833 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001834
Fredrik Lundhade711a2001-01-24 08:00:28 +00001835 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001836 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001837 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001838 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001839 dotversion = version
Victor Stinner4cbea512019-02-28 17:48:38 +01001840 if '.' not in dotversion and "bsd" in HOST_PLATFORM.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001841 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1842 # but the include subdirs are named like .../include/tcl8.3.
1843 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1844 tcl_include_sub = []
1845 tk_include_sub = []
1846 for dir in inc_dirs:
1847 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1848 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1849 tk_include_sub += tcl_include_sub
1850 tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub)
1851 tk_includes = find_file('tk.h', inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001852
Martin v. Löwise86a59a2003-05-03 08:45:51 +00001853 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001854 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:35 +00001855 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001856 return
Fredrik Lundhade711a2001-01-24 08:00:28 +00001857
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001858 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001859
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001860 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
1861 for dir in tcl_includes + tk_includes:
1862 if dir not in include_dirs:
1863 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001864
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001865 # Check for various platform-specific directories
Victor Stinner4cbea512019-02-28 17:48:38 +01001866 if HOST_PLATFORM == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001867 include_dirs.append('/usr/openwin/include')
1868 added_lib_dirs.append('/usr/openwin/lib')
1869 elif os.path.exists('/usr/X11R6/include'):
1870 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:35 +00001871 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001872 added_lib_dirs.append('/usr/X11R6/lib')
1873 elif os.path.exists('/usr/X11R5/include'):
1874 include_dirs.append('/usr/X11R5/include')
1875 added_lib_dirs.append('/usr/X11R5/lib')
1876 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001877 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001878 include_dirs.append('/usr/X11/include')
1879 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001880
Jason Tishler9181c942003-02-05 15:16:17 +00001881 # If Cygwin, then verify that X is installed before proceeding
Victor Stinner4cbea512019-02-28 17:48:38 +01001882 if CYGWIN:
Jason Tishler9181c942003-02-05 15:16:17 +00001883 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1884 if x11_inc is None:
1885 return
1886
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001887 # Check for BLT extension
Tarek Ziadé36797272010-07-22 12:50:05 +00001888 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001889 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001890 defs.append( ('WITH_BLT', 1) )
1891 libs.append('BLT8.0')
Tarek Ziadé36797272010-07-22 12:50:05 +00001892 elif self.compiler.find_library_file(lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:17 +00001893 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:38 +00001894 defs.append( ('WITH_BLT', 1) )
1895 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001896
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001897 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:46 +00001898 libs.append('tk'+ version)
1899 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001900
Victor Stinner4cbea512019-02-28 17:48:38 +01001901 if HOST_PLATFORM in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001902 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001903
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001904 # Finally, link with the X11 libraries (not appropriate on cygwin)
Victor Stinner4cbea512019-02-28 17:48:38 +01001905 if not CYGWIN:
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +00001906 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001907
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001908 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1909 define_macros=[('WITH_APPINIT', 1)] + defs,
1910 include_dirs = include_dirs,
1911 libraries = libs,
1912 library_dirs = added_lib_dirs,
1913 )
1914 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +00001915
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +00001916 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001917 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001918 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001919 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001920 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001921 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +00001922 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001923
Christian Heimes78644762008-03-04 23:39:23 +00001924 def configure_ctypes_darwin(self, ext):
1925 # Darwin (OS X) uses preconfigured files, in
1926 # the Modules/_ctypes/libffi_osx directory.
Neil Schemenauer014bf282009-02-05 16:35:45 +00001927 srcdir = sysconfig.get_config_var('srcdir')
Christian Heimes78644762008-03-04 23:39:23 +00001928 ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
1929 '_ctypes', 'libffi_osx'))
1930 sources = [os.path.join(ffi_srcdir, p)
1931 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:56 +00001932 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:23 +00001933 'x86/x86-darwin.S',
1934 'x86/x86-ffi_darwin.c',
1935 'x86/x86-ffi64.c',
1936 'powerpc/ppc-darwin.S',
1937 'powerpc/ppc-darwin_closure.S',
1938 'powerpc/ppc-ffi_darwin.c',
1939 'powerpc/ppc64-darwin_closure.S',
1940 ]]
1941
1942 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:05 +00001943 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:23 +00001944
1945 include_dirs = [os.path.join(ffi_srcdir, 'include'),
1946 os.path.join(ffi_srcdir, 'powerpc')]
1947 ext.include_dirs.extend(include_dirs)
1948 ext.sources.extend(sources)
1949 return True
1950
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001951 def configure_ctypes(self, ext):
1952 if not self.use_system_libffi:
Victor Stinner4cbea512019-02-28 17:48:38 +01001953 if MACOS:
Christian Heimes78644762008-03-04 23:39:23 +00001954 return self.configure_ctypes_darwin(ext)
Zachary Waref40d4dd2016-09-17 01:25:24 -05001955 print('INFO: Could not locate ffi libs and/or headers')
1956 return False
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001957 return True
1958
1959 def detect_ctypes(self, inc_dirs, lib_dirs):
1960 self.use_system_libffi = False
1961 include_dirs = []
1962 extra_compile_args = []
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001963 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:58 +00001964 sources = ['_ctypes/_ctypes.c',
1965 '_ctypes/callbacks.c',
1966 '_ctypes/callproc.c',
1967 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:53 +00001968 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:58 +00001969 depends = ['_ctypes/ctypes.h']
1970
Victor Stinner4cbea512019-02-28 17:48:38 +01001971 if MACOS:
Ronald Oussoren2decf222010-09-05 18:25:59 +00001972 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:58 +00001973 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:23 +00001974 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:58 +00001975 include_dirs.append('_ctypes/darwin')
1976# XXX Is this still needed?
1977## extra_link_args.extend(['-read_only_relocs', 'warning'])
1978
Victor Stinner4cbea512019-02-28 17:48:38 +01001979 elif HOST_PLATFORM == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001980 # XXX This shouldn't be necessary; it appears that some
1981 # of the assembler code is non-PIC (i.e. it has relocations
1982 # when it shouldn't. The proper fix would be to rewrite
1983 # the assembler code to be PIC.
1984 # This only works with GCC; the Sun compiler likely refuses
1985 # this option. If you want to compile ctypes with the Sun
1986 # compiler, please research a proper solution, instead of
1987 # finding some -z option for the Sun compiler.
1988 extra_link_args.append('-mimpure-text')
1989
Victor Stinner4cbea512019-02-28 17:48:38 +01001990 elif HOST_PLATFORM.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:46 +00001991 extra_link_args.append('-fPIC')
1992
Thomas Hellercf567c12006-03-08 19:51:58 +00001993 ext = Extension('_ctypes',
1994 include_dirs=include_dirs,
1995 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001996 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001997 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:58 +00001998 sources=sources,
1999 depends=depends)
Benjamin Peterson8acaa312017-11-12 20:53:39 -08002000 # function my_sqrt() needs libm for sqrt()
Thomas Hellercf567c12006-03-08 19:51:58 +00002001 ext_test = Extension('_ctypes_test',
Victor Stinnerdef80722016-04-19 15:58:11 +02002002 sources=['_ctypes/_ctypes_test.c'],
Benjamin Peterson8acaa312017-11-12 20:53:39 -08002003 libraries=['m'])
Thomas Hellercf567c12006-03-08 19:51:58 +00002004 self.extensions.extend([ext, ext_test])
2005
Victor Stinner4cbea512019-02-28 17:48:38 +01002006 if MACOS:
Zachary Ware935043d2016-09-09 17:01:21 -07002007 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
2008 return
Christian Heimes78644762008-03-04 23:39:23 +00002009 # OS X 10.5 comes with libffi.dylib; the include files are
2010 # in /usr/include/ffi
2011 inc_dirs.append('/usr/include/ffi')
2012
Benjamin Petersond78735d2010-01-01 16:04:23 +00002013 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:45 +00002014 if not ffi_inc or ffi_inc[0] == '':
Benjamin Petersond78735d2010-01-01 16:04:23 +00002015 ffi_inc = find_file('ffi.h', [], inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002016 if ffi_inc is not None:
2017 ffi_h = ffi_inc[0] + '/ffi.h'
Shlomi Fish6d51b872017-09-06 23:19:19 +03002018 if not os.path.exists(ffi_h):
2019 ffi_inc = None
2020 print('Header file {} does not exist'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002021 ffi_lib = None
2022 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-05 01:38:29 +02002023 for lib_name in ('ffi', 'ffi_pic'):
Tarek Ziadé36797272010-07-22 12:50:05 +00002024 if (self.compiler.find_library_file(lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002025 ffi_lib = lib_name
2026 break
2027
2028 if ffi_inc and ffi_lib:
2029 ext.include_dirs.extend(ffi_inc)
2030 ext.libraries.append(ffi_lib)
2031 self.use_system_libffi = True
2032
Christian Heimes5bb96922018-02-25 10:22:14 +01002033 if sysconfig.get_config_var('HAVE_LIBDL'):
2034 # for dlopen, see bpo-32647
2035 ext.libraries.append('dl')
2036
Stefan Krah1919b7e2012-03-21 18:25:23 +01002037 def _decimal_ext(self):
Stefan Krah60187b52012-03-23 19:06:27 +01002038 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 14:21:22 +02002039 undef_macros = []
Stefan Krah60187b52012-03-23 19:06:27 +01002040 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2041 include_dirs = []
Stefan Krah45059eb2013-11-24 19:44:57 +01002042 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 19:06:27 +01002043 sources = ['_decimal/_decimal.c']
2044 depends = ['_decimal/docstrings.h']
2045 else:
Ned Deily458a6fb2012-04-01 02:30:46 -07002046 srcdir = sysconfig.get_config_var('srcdir')
2047 include_dirs = [os.path.abspath(os.path.join(srcdir,
2048 'Modules',
2049 '_decimal',
2050 'libmpdec'))]
Stefan Krahbd4ed772017-12-06 18:24:17 +01002051 libraries = ['m']
Stefan Krah60187b52012-03-23 19:06:27 +01002052 sources = [
2053 '_decimal/_decimal.c',
2054 '_decimal/libmpdec/basearith.c',
2055 '_decimal/libmpdec/constants.c',
2056 '_decimal/libmpdec/context.c',
2057 '_decimal/libmpdec/convolute.c',
2058 '_decimal/libmpdec/crt.c',
2059 '_decimal/libmpdec/difradix2.c',
2060 '_decimal/libmpdec/fnt.c',
2061 '_decimal/libmpdec/fourstep.c',
2062 '_decimal/libmpdec/io.c',
2063 '_decimal/libmpdec/memory.c',
2064 '_decimal/libmpdec/mpdecimal.c',
2065 '_decimal/libmpdec/numbertheory.c',
2066 '_decimal/libmpdec/sixstep.c',
2067 '_decimal/libmpdec/transpose.c',
2068 ]
2069 depends = [
2070 '_decimal/docstrings.h',
2071 '_decimal/libmpdec/basearith.h',
2072 '_decimal/libmpdec/bits.h',
2073 '_decimal/libmpdec/constants.h',
2074 '_decimal/libmpdec/convolute.h',
2075 '_decimal/libmpdec/crt.h',
2076 '_decimal/libmpdec/difradix2.h',
2077 '_decimal/libmpdec/fnt.h',
2078 '_decimal/libmpdec/fourstep.h',
2079 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 16:34:41 +02002080 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 19:06:27 +01002081 '_decimal/libmpdec/mpdecimal.h',
2082 '_decimal/libmpdec/numbertheory.h',
2083 '_decimal/libmpdec/sixstep.h',
2084 '_decimal/libmpdec/transpose.h',
2085 '_decimal/libmpdec/typearith.h',
2086 '_decimal/libmpdec/umodarith.h',
2087 ]
2088
Stefan Krah1919b7e2012-03-21 18:25:23 +01002089 config = {
2090 'x64': [('CONFIG_64','1'), ('ASM','1')],
2091 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2092 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2093 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2094 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2095 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2096 ('LEGACY_COMPILER','1')],
2097 'universal': [('UNIVERSAL','1')]
2098 }
2099
Stefan Krah1919b7e2012-03-21 18:25:23 +01002100 cc = sysconfig.get_config_var('CC')
2101 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2102 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2103
2104 if machine:
2105 # Override automatic configuration to facilitate testing.
2106 define_macros = config[machine]
Victor Stinner4cbea512019-02-28 17:48:38 +01002107 elif MACOS:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002108 # Universal here means: build with the same options Python
2109 # was built with.
2110 define_macros = config['universal']
2111 elif sizeof_size_t == 8:
2112 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2113 define_macros = config['x64']
2114 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2115 define_macros = config['uint128']
2116 else:
2117 define_macros = config['ansi64']
2118 elif sizeof_size_t == 4:
2119 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2120 if ppro and ('gcc' in cc or 'clang' in cc) and \
Victor Stinner4cbea512019-02-28 17:48:38 +01002121 not 'sunos' in HOST_PLATFORM:
Stefan Krah1919b7e2012-03-21 18:25:23 +01002122 # solaris: problems with register allocation.
2123 # icc >= 11.0 works as well.
2124 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 21:12:53 +02002125 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 18:25:23 +01002126 else:
2127 define_macros = config['ansi32']
2128 else:
2129 raise DistutilsError("_decimal: unsupported architecture")
2130
2131 # Workarounds for toolchain bugs:
2132 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2133 # Some versions of gcc miscompile inline asm:
2134 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2135 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2136 extra_compile_args.append('-fno-ipa-pure-const')
2137 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2138 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2139 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2140 undef_macros.append('_FORTIFY_SOURCE')
2141
Stefan Krah1919b7e2012-03-21 18:25:23 +01002142 # Uncomment for extra functionality:
2143 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
2144 ext = Extension (
2145 '_decimal',
2146 include_dirs=include_dirs,
Stefan Krahbd4ed772017-12-06 18:24:17 +01002147 libraries=libraries,
Stefan Krah1919b7e2012-03-21 18:25:23 +01002148 define_macros=define_macros,
2149 undef_macros=undef_macros,
2150 extra_compile_args=extra_compile_args,
2151 sources=sources,
2152 depends=depends
2153 )
2154 return ext
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002155
Christian Heimesff5be6e2018-01-20 13:19:21 +01002156 def _detect_openssl(self, inc_dirs, lib_dirs):
2157 config_vars = sysconfig.get_config_vars()
2158
2159 def split_var(name, sep):
2160 # poor man's shlex, the re module is not available yet.
2161 value = config_vars.get(name)
2162 if not value:
2163 return ()
2164 # This trick works because ax_check_openssl uses --libs-only-L,
2165 # --libs-only-l, and --cflags-only-I.
2166 value = ' ' + value
2167 sep = ' ' + sep
2168 return [v.strip() for v in value.split(sep) if v.strip()]
2169
2170 openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
2171 openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
2172 openssl_libs = split_var('OPENSSL_LIBS', '-l')
2173 if not openssl_libs:
2174 # libssl and libcrypto not found
2175 return None, None
2176
2177 # Find OpenSSL includes
2178 ssl_incs = find_file(
2179 'openssl/ssl.h', inc_dirs, openssl_includes
2180 )
2181 if ssl_incs is None:
2182 return None, None
2183
2184 # OpenSSL 1.0.2 uses Kerberos for KRB5 ciphers
2185 krb5_h = find_file(
2186 'krb5.h', inc_dirs,
2187 ['/usr/kerberos/include']
2188 )
2189 if krb5_h:
2190 ssl_incs.extend(krb5_h)
2191
Christian Heimes61d478c2018-01-27 15:51:38 +01002192 if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
2193 ssl_ext = Extension(
2194 '_ssl', ['_ssl.c'],
2195 include_dirs=openssl_includes,
2196 library_dirs=openssl_libdirs,
2197 libraries=openssl_libs,
2198 depends=['socketmodule.h']
2199 )
2200 else:
2201 ssl_ext = None
Christian Heimesff5be6e2018-01-20 13:19:21 +01002202
2203 hashlib_ext = Extension(
2204 '_hashlib', ['_hashopenssl.c'],
2205 depends=['hashlib.h'],
2206 include_dirs=openssl_includes,
2207 library_dirs=openssl_libdirs,
2208 libraries=openssl_libs,
2209 )
2210
2211 return ssl_ext, hashlib_ext
2212
Christian Heimes29a7df72018-01-26 23:28:46 +01002213 def _detect_nis(self, inc_dirs, lib_dirs):
Victor Stinner4cbea512019-02-28 17:48:38 +01002214 if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
Christian Heimes29a7df72018-01-26 23:28:46 +01002215 return None
2216
2217 libs = []
2218 library_dirs = []
2219 includes_dirs = []
2220
2221 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2222 # moved headers and libraries to libtirpc and libnsl. The headers
2223 # are in tircp and nsl sub directories.
2224 rpcsvc_inc = find_file(
2225 'rpcsvc/yp_prot.h', inc_dirs,
2226 [os.path.join(inc_dir, 'nsl') for inc_dir in inc_dirs]
2227 )
2228 rpc_inc = find_file(
2229 'rpc/rpc.h', inc_dirs,
2230 [os.path.join(inc_dir, 'tirpc') for inc_dir in inc_dirs]
2231 )
2232 if rpcsvc_inc is None or rpc_inc is None:
2233 # not found
2234 return None
2235 includes_dirs.extend(rpcsvc_inc)
2236 includes_dirs.extend(rpc_inc)
2237
2238 if self.compiler.find_library_file(lib_dirs, 'nsl'):
2239 libs.append('nsl')
2240 else:
2241 # libnsl-devel: check for libnsl in nsl/ subdirectory
2242 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in lib_dirs]
2243 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2244 if libnsl is not None:
2245 library_dirs.append(os.path.dirname(libnsl))
2246 libs.append('nsl')
2247
2248 if self.compiler.find_library_file(lib_dirs, 'tirpc'):
2249 libs.append('tirpc')
2250
2251 return Extension(
2252 'nis', ['nismodule.c'],
2253 libraries=libs,
2254 library_dirs=library_dirs,
2255 include_dirs=includes_dirs
2256 )
2257
Christian Heimesff5be6e2018-01-20 13:19:21 +01002258
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +00002259class PyBuildInstall(install):
2260 # Suppress the warning about installation into the lib_dynload
2261 # directory, which is not in sys.path when running Python during
2262 # installation:
2263 def initialize_options (self):
2264 install.initialize_options(self)
2265 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +00002266
Éric Araujoe6792c12011-06-09 14:07:02 +02002267 # Customize subcommands to not install an egg-info file for Python
2268 sub_commands = [('install_lib', install.has_lib),
2269 ('install_headers', install.has_headers),
2270 ('install_scripts', install.has_scripts),
2271 ('install_data', install.has_data)]
2272
2273
Michael W. Hudson529a5052002-12-17 16:47:17 +00002274class PyBuildInstallLib(install_lib):
2275 # Do exactly what install_lib does but make sure correct access modes get
2276 # set on installed directories and files. All installed files with get
2277 # mode 644 unless they are a shared library in which case they will get
2278 # mode 755. All installed directories will get mode 755.
2279
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002280 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2281 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:17 +00002282
2283 def install(self):
2284 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:49 +00002285 self.set_file_modes(outfiles, 0o644, 0o755)
2286 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002287 return outfiles
2288
2289 def set_file_modes(self, files, defaultMode, sharedLibMode):
Michael W. Hudson529a5052002-12-17 16:47:17 +00002290 if not files: return
2291
2292 for filename in files:
2293 if os.path.islink(filename): continue
2294 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 13:21:49 -07002295 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:17 +00002296 log.info("changing mode of %s to %o", filename, mode)
2297 if not self.dry_run: os.chmod(filename, mode)
2298
2299 def set_dir_modes(self, dirname, mode):
Amaury Forgeot d'Arc321e5332009-07-02 23:08:45 +00002300 for dirpath, dirnames, fnames in os.walk(dirname):
2301 if os.path.islink(dirpath):
2302 continue
2303 log.info("changing mode of %s to %o", dirpath, mode)
2304 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:17 +00002305
Georg Brandlff52f762010-12-28 09:51:43 +00002306class PyBuildScripts(build_scripts):
2307 def copy_scripts(self):
2308 outfiles, updated_files = build_scripts.copy_scripts(self)
2309 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2310 minoronly = '.{0[1]}'.format(sys.version_info)
2311 newoutfiles = []
2312 newupdated_files = []
2313 for filename in outfiles:
Brett Cannona8c34242018-04-20 14:15:40 -07002314 if filename.endswith('2to3'):
Georg Brandlff52f762010-12-28 09:51:43 +00002315 newfilename = filename + fullversion
2316 else:
2317 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 08:22:29 +01002318 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:43 +00002319 os.rename(filename, newfilename)
2320 newoutfiles.append(newfilename)
2321 if filename in updated_files:
2322 newupdated_files.append(newfilename)
2323 return newoutfiles, newupdated_files
2324
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002325SUMMARY = """
2326Python is an interpreted, interactive, object-oriented programming
2327language. It is often compared to Tcl, Perl, Scheme or Java.
2328
2329Python combines remarkable power with very clear syntax. It has
2330modules, classes, exceptions, very high level dynamic data types, and
2331dynamic typing. There are interfaces to many system calls and
2332libraries, as well as to various windowing systems (X11, Motif, Tk,
2333Mac, MFC). New built-in modules are easily written in C or C++. Python
2334is also usable as an extension language for applications that need a
2335programmable interface.
2336
2337The Python implementation is portable: it runs on many brands of UNIX,
Jesus Ceaf1af7052012-10-05 02:48:46 +02002338on Windows, DOS, Mac, Amiga... If your favorite system isn't
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002339listed here, it may still be supported, if there's a C compiler for
2340it. Ask around on comp.lang.python -- or just try compiling Python
2341yourself.
2342"""
2343
2344CLASSIFIERS = """
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002345Development Status :: 6 - Mature
2346License :: OSI Approved :: Python Software Foundation License
2347Natural Language :: English
2348Programming Language :: C
2349Programming Language :: Python
2350Topic :: Software Development
2351"""
2352
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002353def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +00002354 # turn off warnings when deprecated modules are imported
2355 import warnings
2356 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002357 setup(# PyPI Metadata (PEP 301)
2358 name = "Python",
2359 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 13:10:36 +02002360 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002361 maintainer = "Guido van Rossum and the Python community",
2362 maintainer_email = "python-dev@python.org",
2363 description = "A high-level object-oriented programming language",
2364 long_description = SUMMARY.strip(),
2365 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:58 +00002366 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:04 +00002367 platforms = ["Many"],
2368
2369 # Build info
Georg Brandlff52f762010-12-28 09:51:43 +00002370 cmdclass = {'build_ext': PyBuildExt,
2371 'build_scripts': PyBuildScripts,
2372 'install': PyBuildInstall,
2373 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002374 # The struct module is defined here, because build_ext won't be
2375 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:47 +00002376 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +00002377
Georg Brandlff52f762010-12-28 09:51:43 +00002378 # If you change the scripts installed here, you also need to
2379 # check the PyBuildScripts command above, and change the links
2380 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:14 +00002381 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Brett Cannona8c34242018-04-20 14:15:40 -07002382 "Tools/scripts/2to3"]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002383 )
Fredrik Lundhade711a2001-01-24 08:00:28 +00002384
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002385# --install-platlib
2386if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00002387 main()