blob: e2c18982532b8448b200f80dd6322795e24ecb3e [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:581# Autodetecting setup.py script for building the Python extensions
2#
Fredrik Lundhade711a2001-01-24 08:00:283
Brett Cannonca5ff3a2013-06-15 21:52:594import sys, os, importlib.machinery, re, optparse
Christian Heimesaf98da12008-01-27 15:18:185from glob import glob
Eric Snow335e14d2014-01-04 22:09:286import importlib._bootstrap
7import importlib.util
Tarek Ziadéedacea32010-01-29 11:41:038import sysconfig
Michael W. Hudson529a5052002-12-17 16:47:179
10from distutils import log
Marc-André Lemburg7c6fcda2001-01-26 18:03:2411from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:2312from distutils.core import Extension, setup
13from distutils.command.build_ext import build_ext
Andrew M. Kuchlingf52d27e2001-05-21 20:29:2714from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:1715from distutils.command.install_lib import install_lib
Georg Brandlff52f762010-12-28 09:51:4316from distutils.command.build_scripts import build_scripts
Stefan Krah095b2732010-06-08 13:41:4417from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:2318
doko@ubuntu.com1abe1c52012-06-30 18:42:4519cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
20
Victor Stinnera21bedf2018-12-20 20:31:2221# 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-10 03:01:4931
Antoine Pitrou2c0a9162014-09-26 21:31:5932class Dummy:
33 """Hack for parallel build"""
34 ProcessPoolExecutor = None
35sys.modules['concurrent.futures.process'] = Dummy
36
doko@ubuntu.com93df16b2012-06-30 12:32:0837def get_platform():
doko@ubuntu.com1abe1c52012-06-30 18:42:4538 # cross build
39 if "_PYTHON_HOST_PLATFORM" in os.environ:
40 return os.environ["_PYTHON_HOST_PLATFORM"]
doko@ubuntu.com93df16b2012-06-30 12:32:0841 # Get value of sys.platform
42 if sys.platform.startswith('osf1'):
43 return 'osf1'
44 return sys.platform
45host_platform = get_platform()
46
Gregory P. Smithb04ded42010-01-03 00:38:1047# Were we compiled --with-pydebug or with #define Py_DEBUG?
doko@ubuntu.com1abe1c52012-06-30 18:42:4548COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
Gregory P. Smithb04ded42010-01-03 00:38:1049
Andrew M. Kuchling00e0f212001-01-17 15:23:2350# This global variable is used to hold the list of modules to be disabled.
51disabled_module_list = []
52
Michael W. Hudson39230b32002-01-16 15:26:4853def add_dir_to_list(dirlist, dir):
Barry Warsaw807bd0a2010-11-24 20:30:0054 """Add the directory 'dir' to the list 'dirlist' (after any relative
55 directories) if:
56
Michael W. Hudson39230b32002-01-16 15:26:4857 1) 'dir' is not already in 'dirlist'
Barry Warsaw807bd0a2010-11-24 20:30:0058 2) 'dir' actually exists, and is a directory.
59 """
60 if dir is None or not os.path.isdir(dir) or dir in dirlist:
61 return
62 for i, path in enumerate(dirlist):
63 if not os.path.isabs(path):
64 dirlist.insert(i + 1, dir)
Barry Warsaw34520cd2010-11-27 20:03:0365 return
66 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:4867
Miss Islington (bot)04af8ac2017-11-25 16:52:2068def sysroot_paths(make_vars, subdirs):
69 """Get the paths of sysroot sub-directories.
70
71 * make_vars: a sequence of names of variables of the Makefile where
72 sysroot may be set.
73 * subdirs: a sequence of names of subdirectories used as the location for
74 headers or libraries.
75 """
76
77 dirs = []
78 for var_name in make_vars:
79 var = sysconfig.get_config_var(var_name)
80 if var is not None:
81 m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
82 if m is not None:
83 sysroot = m.group(1).strip('"')
84 for subdir in subdirs:
85 if os.path.isabs(subdir):
86 subdir = subdir[1:]
87 path = os.path.join(sysroot, subdir)
88 if os.path.isdir(path):
89 dirs.append(path)
90 break
91 return dirs
92
Ronald Oussoren2c12ab12010-06-03 14:42:2593def macosx_sdk_root():
94 """
95 Return the directory of the current OSX SDK,
96 or '/' if no SDK was specified.
97 """
98 cflags = sysconfig.get_config_var('CFLAGS')
99 m = re.search(r'-isysroot\s+(\S+)', cflags)
100 if m is None:
101 sysroot = '/'
102 else:
103 sysroot = m.group(1)
104 return sysroot
105
106def is_macosx_sdk_path(path):
107 """
108 Returns True if 'path' can be located in an OSX SDK
109 """
Ned Deily2910a7b2012-07-30 09:35:58110 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
111 or path.startswith('/System/')
112 or path.startswith('/Library/') )
Ronald Oussoren2c12ab12010-06-03 14:42:25113
Andrew M. Kuchlingfbe73762001-01-18 18:44:20114def find_file(filename, std_dirs, paths):
115 """Searches for the directory where a given file is located,
116 and returns a possibly-empty list of additional directories, or None
117 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28118
Andrew M. Kuchlingfbe73762001-01-18 18:44:20119 'filename' is the name of a file, such as readline.h or libcrypto.a.
120 'std_dirs' is the list of standard system directories; if the
121 file is found in one of them, no additional directives are needed.
122 'paths' is a list of additional locations to check; if the file is
123 found in one of them, the resulting list will contain the directory.
124 """
doko@ubuntu.com93df16b2012-06-30 12:32:08125 if host_platform == 'darwin':
Ronald Oussoren2c12ab12010-06-03 14:42:25126 # Honor the MacOSX SDK setting when one was specified.
127 # An SDK is a directory with the same structure as a real
128 # system, but with only header files and libraries.
129 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20130
131 # Check the standard locations
132 for dir in std_dirs:
133 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25134
doko@ubuntu.com93df16b2012-06-30 12:32:08135 if host_platform == 'darwin' and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25136 f = os.path.join(sysroot, dir[1:], filename)
137
Andrew M. Kuchlingfbe73762001-01-18 18:44:20138 if os.path.exists(f): return []
139
140 # Check the additional directories
141 for dir in paths:
142 f = os.path.join(dir, filename)
Ronald Oussoren2c12ab12010-06-03 14:42:25143
doko@ubuntu.com93df16b2012-06-30 12:32:08144 if host_platform == 'darwin' and is_macosx_sdk_path(dir):
Ronald Oussoren2c12ab12010-06-03 14:42:25145 f = os.path.join(sysroot, dir[1:], filename)
146
Andrew M. Kuchlingfbe73762001-01-18 18:44:20147 if os.path.exists(f):
148 return [dir]
149
150 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23151 return None
152
Andrew M. Kuchlingfbe73762001-01-18 18:44:20153def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46154 result = compiler.find_library_file(std_dirs + paths, libname)
155 if result is None:
156 return None
Fredrik Lundhade711a2001-01-24 08:00:28157
doko@ubuntu.com93df16b2012-06-30 12:32:08158 if host_platform == 'darwin':
Ronald Oussoren2c12ab12010-06-03 14:42:25159 sysroot = macosx_sdk_root()
160
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46161 # Check whether the found file is in one of the standard directories
162 dirname = os.path.dirname(result)
163 for p in std_dirs:
164 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57165 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25166
doko@ubuntu.com93df16b2012-06-30 12:32:08167 if host_platform == 'darwin' and is_macosx_sdk_path(p):
Ned Deily020250f2016-02-24 13:56:38168 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
169 # libraries with .tbd extensions rather than the normal .dylib
170 # shared libraries installed in /. The Apple compiler tool
171 # chain handles this transparently but it can cause problems
172 # for programs that are being built with an SDK and searching
173 # for specific libraries. Distutils find_library_file() now
174 # knows to also search for and return .tbd files. But callers
175 # of find_library_file need to keep in mind that the base filename
176 # of the returned SDK library file might have a different extension
177 # from that of the library file installed on the running system,
178 # for example:
179 # /Applications/Xcode.app/Contents/Developer/Platforms/
180 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
181 # usr/lib/libedit.tbd
182 # vs
183 # /usr/lib/libedit.dylib
Ronald Oussoren2c12ab12010-06-03 14:42:25184 if os.path.join(sysroot, p[1:]) == dirname:
185 return [ ]
186
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46187 if p == dirname:
188 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20189
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46190 # Otherwise, it must have been in one of the additional directories,
191 # so we have to figure out which one.
192 for p in paths:
193 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57194 p = p.rstrip(os.sep)
Ronald Oussoren2c12ab12010-06-03 14:42:25195
doko@ubuntu.com93df16b2012-06-30 12:32:08196 if host_platform == 'darwin' and is_macosx_sdk_path(p):
Ronald Oussoren2c12ab12010-06-03 14:42:25197 if os.path.join(sysroot, p[1:]) == dirname:
198 return [ p ]
199
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46200 if p == dirname:
201 return [p]
202 else:
203 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43204
Andrew M. Kuchling00e0f212001-01-17 15:23:23205def module_enabled(extlist, modname):
206 """Returns whether the module 'modname' is present in the list
207 of extensions 'extlist'."""
208 extlist = [ext for ext in extlist if ext.name == modname]
209 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28210
Jack Jansen144ebcc2001-08-05 22:31:19211def find_module_file(module, dirlist):
212 """Find a module in a set of possible folders. If it is not found
213 return the unadorned filename"""
214 list = find_file(module, [], dirlist)
215 if not list:
216 return module
217 if len(list) > 1:
Vinay Sajipdd917f82016-08-31 07:22:29218 log.info("WARNING: multiple copies of %s found", module)
Jack Jansen144ebcc2001-08-05 22:31:19219 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41220
Andrew M. Kuchling00e0f212001-01-17 15:23:23221class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28222
Guido van Rossumd8faa362007-04-27 19:54:29223 def __init__(self, dist):
224 build_ext.__init__(self, dist)
225 self.failed = []
Benjamin Peterson5c2ac8c2014-04-30 15:06:16226 self.failed_on_import = []
Antoine Pitrou2c0a9162014-09-26 21:31:59227 if '-j' in os.environ.get('MAKEFLAGS', ''):
228 self.parallel = True
Guido van Rossumd8faa362007-04-27 19:54:29229
Andrew M. Kuchling00e0f212001-01-17 15:23:23230 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23231
232 # Detect which modules should be compiled
doko@ubuntu.comd5537d02013-03-21 20:21:49233 missing = self.detect_modules()
Andrew M. Kuchling00e0f212001-01-17 15:23:23234
235 # Remove modules that are present on the disabled list
Christian Heimes679db4a2008-01-18 09:56:22236 extensions = [ext for ext in self.extensions
237 if ext.name not in disabled_module_list]
238 # move ctypes to the end, it depends on other modules
239 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
240 if "_ctypes" in ext_map:
241 ctypes = extensions.pop(ext_map["_ctypes"])
242 extensions.append(ctypes)
243 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28244
Andrew M. Kuchling00e0f212001-01-17 15:23:23245 # Fix up the autodetected modules, prefixing all the source files
Neil Schemenauer014bf282009-02-05 16:35:45246 # with Modules/.
247 srcdir = sysconfig.get_config_var('srcdir')
Guido van Rossume0fea6c2002-10-14 20:48:09248 if not srcdir:
249 # Maybe running on Windows but not using CYGWIN?
250 raise ValueError("No source directory; cannot proceed.")
Neil Schemenauer4d491a52009-02-06 00:27:50251 srcdir = os.path.abspath(srcdir)
Neil Schemenauer014bf282009-02-05 16:35:45252 moddirlist = [os.path.join(srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41253
Andrew M. Kuchling3da989c2001-02-28 22:49:26254 # Fix up the paths for scripts, too
255 self.distribution.scripts = [os.path.join(srcdir, filename)
256 for filename in self.distribution.scripts]
257
Christian Heimesaf98da12008-01-27 15:18:18258 # Python header files
Neil Schemenauer014bf282009-02-05 16:35:45259 headers = [sysconfig.get_config_h_filename()]
Stefan Kraheb977da2012-02-29 13:10:53260 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Christian Heimesaf98da12008-01-27 15:18:18261
Xavier de Gaye84968b72016-10-29 14:57:20262 # The sysconfig variable built by makesetup, listing the already
263 # built modules as configured by the Setup files.
264 modnames = sysconfig.get_config_var('MODNAMES').split()
265
266 removed_modules = []
267 for ext in self.extensions:
Jack Jansen144ebcc2001-08-05 22:31:19268 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23269 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11270 if ext.depends is not None:
Neil Schemenauer014bf282009-02-05 16:35:45271 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11272 for filename in ext.depends]
Christian Heimesaf98da12008-01-27 15:18:18273 else:
274 ext.depends = []
275 # re-compile extensions if a header file has been changed
276 ext.depends.extend(headers)
277
Xavier de Gaye84968b72016-10-29 14:57:20278 # If a module has already been built by the Makefile,
279 # don't build it here.
280 if ext.name in modnames:
281 removed_modules.append(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34282
Xavier de Gaye84968b72016-10-29 14:57:20283 if removed_modules:
284 self.extensions = [x for x in self.extensions if x not in
285 removed_modules]
Michael W. Hudson5b109102002-01-23 15:04:41286
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34287 # When you run "make CC=altcc" or something similar, you really want
288 # those environment variables passed into the setup.py phase. Here's
289 # a small set of useful ones.
290 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34291 args = {}
292 # unfortunately, distutils doesn't let us provide separate C and C++
293 # compilers
294 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03295 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
296 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé36797272010-07-22 12:50:05297 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34298
Andrew M. Kuchling00e0f212001-01-17 15:23:23299 build_ext.build_extensions(self)
300
Antoine Pitrou2c0a9162014-09-26 21:31:59301 for ext in self.extensions:
302 self.check_extension_import(ext)
303
Berker Peksag1d82a9c2014-10-01 02:11:13304 longest = max([len(e.name) for e in self.extensions], default=0)
Benjamin Peterson5c2ac8c2014-04-30 15:06:16305 if self.failed or self.failed_on_import:
306 all_failed = self.failed + self.failed_on_import
307 longest = max(longest, max([len(name) for name in all_failed]))
Guido van Rossumd8faa362007-04-27 19:54:29308
309 def print_three_column(lst):
310 lst.sort(key=str.lower)
311 # guarantee zip() doesn't drop anything
312 while len(lst) % 3:
313 lst.append("")
314 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
315 print("%-*s %-*s %-*s" % (longest, e, longest, f,
316 longest, g))
Guido van Rossumd8faa362007-04-27 19:54:29317
318 if missing:
319 print()
Brett Cannonae95b4f2013-07-12 15:30:32320 print("Python build finished successfully!")
321 print("The necessary bits to build these optional modules were not "
322 "found:")
Guido van Rossumd8faa362007-04-27 19:54:29323 print_three_column(missing)
Guido van Rossum04110fb2007-08-24 16:32:05324 print("To find the necessary bits, look in setup.py in"
325 " detect_modules() for the module's name.")
326 print()
Guido van Rossumd8faa362007-04-27 19:54:29327
Xavier de Gaye84968b72016-10-29 14:57:20328 if removed_modules:
329 print("The following modules found by detect_modules() in"
330 " setup.py, have been")
331 print("built by the Makefile instead, as configured by the"
332 " Setup files:")
333 print_three_column([ext.name for ext in removed_modules])
334
Guido van Rossumd8faa362007-04-27 19:54:29335 if self.failed:
336 failed = self.failed[:]
337 print()
338 print("Failed to build these modules:")
339 print_three_column(failed)
Guido van Rossum04110fb2007-08-24 16:32:05340 print()
Guido van Rossumd8faa362007-04-27 19:54:29341
Benjamin Peterson5c2ac8c2014-04-30 15:06:16342 if self.failed_on_import:
343 failed = self.failed_on_import[:]
344 print()
345 print("Following modules built successfully"
346 " but were removed because they could not be imported:")
347 print_three_column(failed)
348 print()
349
Marc-André Lemburg7c6fcda2001-01-26 18:03:24350 def build_extension(self, ext):
351
Thomas Wouters49fd7fa2006-04-21 10:40:58352 if ext.name == '_ctypes':
353 if not self.configure_ctypes(ext):
354 return
355
Marc-André Lemburg7c6fcda2001-01-26 18:03:24356 try:
357 build_ext.build_extension(self, ext)
Guido van Rossumb940e112007-01-10 16:19:56358 except (CCompilerError, DistutilsError) as why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24359 self.announce('WARNING: building of extension "%s" failed: %s' %
360 (ext.name, sys.exc_info()[1]))
Guido van Rossumd8faa362007-04-27 19:54:29361 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09362 return
Antoine Pitrou2c0a9162014-09-26 21:31:59363
364 def check_extension_import(self, ext):
365 # Don't try to import an extension that has failed to compile
366 if ext.name in self.failed:
367 self.announce(
368 'WARNING: skipping import check for failed build "%s"' %
369 ext.name, level=1)
370 return
371
Jack Jansenf49c6f92001-11-01 14:44:15372 # Workaround for Mac OS X: The Carbon-based modules cannot be
373 # reliably imported into a command-line Python
374 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41375 self.announce(
376 'WARNING: skipping import check for Carbon-based "%s"' %
377 ext.name)
378 return
Georg Brandlfcaf9102008-07-16 02:17:56379
doko@ubuntu.com93df16b2012-06-30 12:32:08380 if host_platform == 'darwin' and (
Benjamin Petersonfc576352008-07-16 02:39:02381 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
Georg Brandlfcaf9102008-07-16 02:17:56382 # Don't bother doing an import check when an extension was
383 # build with an explicit '-arch' flag on OSX. That's currently
384 # only used to build 32-bit only extensions in a 4-way
385 # universal build and loading 32-bit code into a 64-bit
386 # process will fail.
387 self.announce(
388 'WARNING: skipping import check for "%s"' %
389 ext.name)
390 return
391
Jason Tishler24cf7762002-05-22 16:46:15392 # Workaround for Cygwin: Cygwin currently has fork issues when many
393 # modules have been imported
doko@ubuntu.com93df16b2012-06-30 12:32:08394 if host_platform == 'cygwin':
Jason Tishler24cf7762002-05-22 16:46:15395 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
396 % ext.name)
397 return
Michael W. Hudsonaf142892002-01-23 15:07:46398 ext_filename = os.path.join(
399 self.build_lib,
400 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Guido van Rossumc3fee692008-07-17 16:23:53401
402 # If the build directory didn't exist when setup.py was
403 # started, sys.path_importer_cache has a negative result
404 # cached. Clear that cache before trying to import.
405 sys.path_importer_cache.clear()
406
doko@ubuntu.com1abe1c52012-06-30 18:42:45407 # Don't try to load extensions for cross builds
408 if cross_compiling:
409 return
410
Brett Cannonca5ff3a2013-06-15 21:52:59411 loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
Eric Snow335e14d2014-01-04 22:09:28412 spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
413 loader=loader)
Andrew M. Kuchling62686692001-05-21 20:48:09414 try:
Brett Cannon2a17bde2014-05-30 18:55:29415 importlib._bootstrap._load(spec)
Guido van Rossumb940e112007-01-10 16:19:56416 except ImportError as why:
Benjamin Peterson5c2ac8c2014-04-30 15:06:16417 self.failed_on_import.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42418 self.announce('*** WARNING: renaming "%s" since importing it'
419 ' failed: %s' % (ext.name, why), level=3)
420 assert not self.inplace
421 basename, tail = os.path.splitext(ext_filename)
422 newname = basename + "_failed" + tail
423 if os.path.exists(newname):
424 os.remove(newname)
425 os.rename(ext_filename, newname)
426
Neal Norwitz3f5fcc82003-02-28 17:21:39427 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39428 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42429 self.announce('*** WARNING: importing extension "%s" '
430 'failed with %s: %s' % (ext.name, exc_type, why),
431 level=3)
Guido van Rossumd8faa362007-04-27 19:54:29432 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54433
Barry Warsaw5ca305a2011-04-06 19:18:12434 def add_multiarch_paths(self):
435 # Debian/Ubuntu multiarch support.
436 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3277b352012-08-08 10:15:55437 cc = sysconfig.get_config_var('CC')
438 tmpfile = os.path.join(self.build_temp, 'multiarch')
439 if not os.path.exists(self.build_temp):
440 os.makedirs(self.build_temp)
441 ret = os.system(
442 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
443 multiarch_path_component = ''
444 try:
445 if ret >> 8 == 0:
446 with open(tmpfile) as fp:
447 multiarch_path_component = fp.readline().strip()
448 finally:
449 os.unlink(tmpfile)
450
451 if multiarch_path_component != '':
452 add_dir_to_list(self.compiler.library_dirs,
453 '/usr/lib/' + multiarch_path_component)
454 add_dir_to_list(self.compiler.include_dirs,
455 '/usr/include/' + multiarch_path_component)
456 return
457
Barry Warsaw88e19452011-04-07 14:40:36458 if not find_executable('dpkg-architecture'):
459 return
doko@ubuntu.com1abe1c52012-06-30 18:42:45460 opt = ''
461 if cross_compiling:
462 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsaw5ca305a2011-04-06 19:18:12463 tmpfile = os.path.join(self.build_temp, 'multiarch')
464 if not os.path.exists(self.build_temp):
465 os.makedirs(self.build_temp)
466 ret = os.system(
doko@ubuntu.com1abe1c52012-06-30 18:42:45467 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
468 (opt, tmpfile))
Barry Warsaw5ca305a2011-04-06 19:18:12469 try:
470 if ret >> 8 == 0:
471 with open(tmpfile) as fp:
472 multiarch_path_component = fp.readline().strip()
473 add_dir_to_list(self.compiler.library_dirs,
474 '/usr/lib/' + multiarch_path_component)
475 add_dir_to_list(self.compiler.include_dirs,
476 '/usr/include/' + multiarch_path_component)
477 finally:
478 os.unlink(tmpfile)
479
doko@ubuntu.com1abe1c52012-06-30 18:42:45480 def add_gcc_paths(self):
481 gcc = sysconfig.get_config_var('CC')
482 tmpfile = os.path.join(self.build_temp, 'gccpaths')
483 if not os.path.exists(self.build_temp):
484 os.makedirs(self.build_temp)
485 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
486 is_gcc = False
487 in_incdirs = False
488 inc_dirs = []
489 lib_dirs = []
490 try:
491 if ret >> 8 == 0:
492 with open(tmpfile) as fp:
493 for line in fp.readlines():
494 if line.startswith("gcc version"):
495 is_gcc = True
496 elif line.startswith("#include <...>"):
497 in_incdirs = True
498 elif line.startswith("End of search list"):
499 in_incdirs = False
500 elif is_gcc and line.startswith("LIBRARY_PATH"):
501 for d in line.strip().split("=")[1].split(":"):
502 d = os.path.normpath(d)
503 if '/gcc/' not in d:
504 add_dir_to_list(self.compiler.library_dirs,
505 d)
506 elif is_gcc and in_incdirs and '/gcc/' not in line:
507 add_dir_to_list(self.compiler.include_dirs,
508 line.strip())
509 finally:
510 os.unlink(tmpfile)
511
Victor Stinnerdef80722016-04-19 13:58:11512 def detect_math_libs(self):
513 # Check for MacOS X, which doesn't need libm.a at all
514 if host_platform == 'darwin':
515 return []
516 else:
517 return ['m']
518
Andrew M. Kuchling00e0f212001-01-17 15:23:23519 def detect_modules(self):
Barry Warsaw807bd0a2010-11-24 20:30:00520 # Ensure that /usr/local is always used, but the local build
521 # directories (i.e. '.' and 'Include') must be first. See issue
522 # 10520.
doko@ubuntu.com1abe1c52012-06-30 18:42:45523 if not cross_compiling:
524 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
525 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
doko@ubuntu.comcc5addd2012-06-30 22:23:51526 # only change this for cross builds for 3.3, issues on Mageia
527 if cross_compiling:
528 self.add_gcc_paths()
Barry Warsaw5ca305a2011-04-06 19:18:12529 self.add_multiarch_paths()
Michael W. Hudson39230b32002-01-16 15:26:48530
Brett Cannon516592f2004-12-07 00:42:59531 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21532 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09533 # We must get the values from the Makefile and not the environment
534 # directly since an inconsistently reproducible issue comes up where
535 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21536 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59537 for env_var, arg_name, dir_list in (
Tarek Ziadé36797272010-07-22 12:50:05538 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
539 ('LDFLAGS', '-L', self.compiler.library_dirs),
540 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09541 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59542 if env_val:
Brett Cannon4810eb92004-12-31 08:11:21543 # To prevent optparse from raising an exception about any
Skip Montanaroa5c2a512008-10-07 02:51:48544 # options in env_val that it doesn't know about we strip out
Brett Cannon4810eb92004-12-31 08:11:21545 # all double dashes and any dashes followed by a character
546 # that is not for the option we are dealing with.
547 #
548 # Please note that order of the regex is important! We must
549 # strip out double-dashes first so that we don't end up with
550 # substituting "--Long" to "-Long" and thus lead to "ong" being
551 # used for a library directory.
Guido van Rossum04110fb2007-08-24 16:32:05552 env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
553 ' ', env_val)
Brett Cannon84667c02004-12-07 03:25:18554 parser = optparse.OptionParser()
Brett Cannon4810eb92004-12-31 08:11:21555 # Make sure that allowing args interspersed with options is
556 # allowed
557 parser.allow_interspersed_args = True
558 parser.error = lambda msg: None
Brett Cannon84667c02004-12-07 03:25:18559 parser.add_option(arg_name, dest="dirs", action="append")
560 options = parser.parse_args(env_val.split())[0]
Brett Cannon44837712005-01-02 21:54:07561 if options.dirs:
Christian Heimes292d3512008-02-03 16:51:08562 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07563 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49564
Xavier de Gaye1351c312016-12-14 10:14:33565 if (not cross_compiling and
566 os.path.normpath(sys.base_prefix) != '/usr' and
567 not sysconfig.get_config_var('PYTHONFRAMEWORK')):
Ronald Oussorenf3500e12010-10-20 13:10:12568 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
569 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
570 # building a framework with different architectures than
571 # the one that is currently installed (issue #7473)
Tarek Ziadé36797272010-07-22 12:50:05572 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50573 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé36797272010-07-22 12:50:05574 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50575 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20576
Miss Islington (bot)04af8ac2017-11-25 16:52:20577 system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
578 system_include_dirs = ['/usr/include']
Andrew M. Kuchlingfbe73762001-01-18 18:44:20579 # lib_dirs and inc_dirs are used to search for files;
580 # if a file is found in one of those directories, it can
581 # be assumed that no additional -I,-L directives are needed.
doko@ubuntu.com1abe1c52012-06-30 18:42:45582 if not cross_compiling:
Miss Islington (bot)04af8ac2017-11-25 16:52:20583 lib_dirs = self.compiler.library_dirs + system_lib_dirs
584 inc_dirs = self.compiler.include_dirs + system_include_dirs
Christian Heimesf19529c2012-12-12 11:41:00585 else:
Miss Islington (bot)04af8ac2017-11-25 16:52:20586 # Add the sysroot paths. 'sysroot' is a compiler option used to
587 # set the logical path of the standard system headers and
588 # libraries.
589 lib_dirs = (self.compiler.library_dirs +
590 sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
591 inc_dirs = (self.compiler.include_dirs +
592 sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
593 system_include_dirs))
Andrew M. Kuchling00e0f212001-01-17 15:23:23594 exts = []
Guido van Rossumd8faa362007-04-27 19:54:29595 missing = []
Andrew M. Kuchling00e0f212001-01-17 15:23:23596
Brett Cannon4454a1f2005-04-15 20:32:39597 config_h = sysconfig.get_config_h_filename()
Brett Cannon9f5db072010-10-29 20:19:27598 with open(config_h) as file:
599 config_h_vars = sysconfig.parse_config_h(file)
Brett Cannon4454a1f2005-04-15 20:32:39600
Neil Schemenauer014bf282009-02-05 16:35:45601 srcdir = sysconfig.get_config_var('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41602
Andrew M. Kuchling7883dc82003-10-24 18:26:26603 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
doko@ubuntu.com93df16b2012-06-30 12:32:08604 if host_platform in ['osf1', 'unixware7', 'openunix8']:
Skip Montanaro22e00c42003-05-06 20:43:34605 lib_dirs += ['/usr/ccs/lib']
606
Charles-François Natali5739e102012-04-12 17:07:25607 # HP-UX11iv3 keeps files in lib/hpux folders.
doko@ubuntu.com93df16b2012-06-30 12:32:08608 if host_platform == 'hp-ux11':
Charles-François Natali5739e102012-04-12 17:07:25609 lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
610
doko@ubuntu.com93df16b2012-06-30 12:32:08611 if host_platform == 'darwin':
Thomas Wouters477c8d52006-05-27 19:21:47612 # This should work on any unixy platform ;-)
613 # If the user has bothered specifying additional -I and -L flags
614 # in OPT and LDFLAGS we might as well use them here.
Barry Warsaw807bd0a2010-11-24 20:30:00615 #
616 # NOTE: using shlex.split would technically be more correct, but
617 # also gives a bootstrap problem. Let's hope nobody uses
618 # directories with whitespace in the name to store libraries.
Thomas Wouters477c8d52006-05-27 19:21:47619 cflags, ldflags = sysconfig.get_config_vars(
620 'CFLAGS', 'LDFLAGS')
621 for item in cflags.split():
622 if item.startswith('-I'):
623 inc_dirs.append(item[2:])
624
625 for item in ldflags.split():
626 if item.startswith('-L'):
627 lib_dirs.append(item[2:])
628
Victor Stinnerdef80722016-04-19 13:58:11629 math_libs = self.detect_math_libs()
Michael W. Hudson5b109102002-01-23 15:04:41630
Andrew M. Kuchling00e0f212001-01-17 15:23:23631 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
632
633 #
634 # The following modules are all pretty straightforward, and compile
635 # on pretty much any POSIXish platform.
636 #
Fredrik Lundhade711a2001-01-24 08:00:28637
Andrew M. Kuchling00e0f212001-01-17 15:23:23638 # array objects
639 exts.append( Extension('array', ['arraymodule.c']) )
Martin Panterc9deece2016-02-03 05:19:44640
641 shared_math = 'Modules/_math.o'
Andrew M. Kuchling00e0f212001-01-17 15:23:23642 # complex math library functions
Martin Panterc9deece2016-02-03 05:19:44643 exts.append( Extension('cmath', ['cmathmodule.c'],
644 extra_objects=[shared_math],
645 depends=['_math.h', shared_math],
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11646 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23647 # math library functions, e.g. sin()
Martin Panterc9deece2016-02-03 05:19:44648 exts.append( Extension('math', ['mathmodule.c'],
649 extra_objects=[shared_math],
650 depends=['_math.h', shared_math],
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11651 libraries=math_libs) )
Victor Stinnere0be4232011-10-25 11:06:09652
653 # time libraries: librt may be needed for clock_gettime()
654 time_libs = []
655 lib = sysconfig.get_config_var('TIMEMODULE_LIB')
656 if lib:
657 time_libs.append(lib)
658
Andrew M. Kuchling00e0f212001-01-17 15:23:23659 # time operations and variables
Victor Stinner5d272cc2012-03-13 12:35:55660 exts.append( Extension('time', ['timemodule.c'],
Victor Stinnere0be4232011-10-25 11:06:09661 libraries=time_libs) )
Victor Stinnerdef80722016-04-19 13:58:11662 # math_libs is needed by delta_new() that uses round() and by accum()
663 # that uses modf().
664 exts.append( Extension('_datetime', ['_datetimemodule.c'],
665 libraries=math_libs) )
Christian Heimesfe337bf2008-03-23 21:54:12666 # random number generator implemented in C
667 exts.append( Extension("_random", ["_randommodule.c"]) )
Raymond Hettinger0c410272004-01-05 10:13:35668 # bisect
669 exts.append( Extension("_bisect", ["_bisectmodule.c"]) )
Raymond Hettingerb3af1812003-11-08 10:24:38670 # heapq
Raymond Hettingerc46cb2a2004-04-19 19:06:21671 exts.append( Extension("_heapq", ["_heapqmodule.c"]) )
Alexandre Vassalottica2d6102008-06-12 18:26:05672 # C-optimized pickle replacement
673 exts.append( Extension("_pickle", ["_pickle.c"]) )
Collin Winter670e6922007-03-21 02:57:17674 # atexit
675 exts.append( Extension("atexit", ["atexitmodule.c"]) )
Christian Heimes90540002008-05-08 14:29:10676 # _json speedups
677 exts.append( Extension("_json", ["_json.c"]) )
Marc-André Lemburg261b8e22001-02-02 12:12:44678 # Python C API test module
Mark Dickinsona06f44b2009-02-10 16:18:22679 exts.append( Extension('_testcapi', ['_testcapimodule.c'],
680 depends=['testcapi_long.h']) )
Stefan Krah9a2d99e2012-02-25 11:24:21681 # Python PEP-3118 (buffer protocol) test module
682 exts.append( Extension('_testbuffer', ['_testbuffer.c']) )
Andrew Svetlov6b2cbeb2012-12-14 15:04:59683 # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
684 exts.append( Extension('_testimportmultiple', ['_testimportmultiple.c']) )
Nick Coghland5cacbb2015-05-23 12:24:10685 # Test multi-phase extension module init (PEP 489)
686 exts.append( Extension('_testmultiphase', ['_testmultiphase.c']) )
Fred Drake0e474a82007-10-11 18:01:43687 # profiler (_lsprof is for cProfile.py)
Armin Rigoa871ef22006-02-08 12:53:56688 exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23689 # static Unicode character database
Benjamin Peterson67752312016-09-15 06:53:47690 exts.append( Extension('unicodedata', ['unicodedata.c'],
691 depends=['unicodedata_db.h', 'unicodename_db.h']) )
Larry Hastings3a907972013-11-23 22:49:22692 # _opcode module
693 exts.append( Extension('_opcode', ['_opcode.c']) )
INADA Naoki9f2ce252016-10-15 06:39:19694 # asyncio speedups
695 exts.append( Extension("_asyncio", ["_asynciomodule.c"]) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23696
697 # Modules with some UNIX dependencies -- on by default:
698 # (If you have a really backward UNIX, select and socket may not be
699 # supported...)
700
701 # fcntl(2) and ioctl(2)
Antoine Pitroua3000072010-09-07 14:52:42702 libs = []
703 if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
704 # May be necessary on AIX for flock function
705 libs = ['bsd']
706 exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) )
Ronald Oussoren94f25282010-05-05 19:11:21707 # pwd(3)
708 exts.append( Extension('pwd', ['pwdmodule.c']) )
709 # grp(3)
710 exts.append( Extension('grp', ['grpmodule.c']) )
711 # spwd, shadow passwords
712 if (config_h_vars.get('HAVE_GETSPNAM', False) or
713 config_h_vars.get('HAVE_GETSPENT', False)):
714 exts.append( Extension('spwd', ['spwdmodule.c']) )
Guido van Rossumd8faa362007-04-27 19:54:29715 else:
Ronald Oussoren94f25282010-05-05 19:11:21716 missing.append('spwd')
Guido van Rossumd8faa362007-04-27 19:54:29717
Andrew M. Kuchling00e0f212001-01-17 15:23:23718 # select(2); not on ancient System V
719 exts.append( Extension('select', ['selectmodule.c']) )
720
Andrew M. Kuchling00e0f212001-01-17 15:23:23721 # Fred Drake's interface to the Python parser
722 exts.append( Extension('parser', ['parsermodule.c']) )
723
Andrew M. Kuchling00e0f212001-01-17 15:23:23724 # Memory-mapped files (also works on Win32).
Ronald Oussoren94f25282010-05-05 19:11:21725 exts.append( Extension('mmap', ['mmapmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23726
Andrew M. Kuchling57269d02004-08-31 13:37:25727 # Lance Ellinghaus's syslog module
Ronald Oussoren94f25282010-05-05 19:11:21728 # syslog daemon interface
729 exts.append( Extension('syslog', ['syslogmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23730
Andrew M. Kuchling00e0f212001-01-17 15:23:23731 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34732 # Here ends the simple stuff. From here on, modules need certain
733 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23734 #
735
736 # Multimedia modules
737 # These don't work for 64-bit platforms!!!
738 # These represent audio samples or images as strings:
Victor Stinnerdef80722016-04-19 13:58:11739 #
Neal Norwitz5e4a3b82004-07-19 16:55:07740 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10741 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20742 # 64-bit platforms.
Victor Stinnerdef80722016-04-19 13:58:11743 #
744 # audioop needs math_libs for floor() in multiple functions.
745 exts.append( Extension('audioop', ['audioop.c'],
746 libraries=math_libs) )
Martin v. Löwis8fbefe22004-07-19 16:42:20747
Andrew M. Kuchling00e0f212001-01-17 15:23:23748 # readline
Tarek Ziadé36797272010-07-22 12:50:05749 do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
Stefan Krah095b2732010-06-08 13:41:44750 readline_termcap_library = ""
751 curses_library = ""
doko@ubuntu.com58844492012-06-30 16:25:32752 # Cannot use os.popen here in py3k.
753 tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
754 if not os.path.exists(self.build_temp):
755 os.makedirs(self.build_temp)
Stefan Krah095b2732010-06-08 13:41:44756 # Determine if readline is already linked against curses or tinfo.
doko@ubuntu.com58844492012-06-30 16:25:32757 if do_readline:
758 if cross_compiling:
759 ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
760 % (sysconfig.get_config_var('READELF'),
761 do_readline, tmpfile))
762 elif find_executable('ldd'):
763 ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
764 else:
765 ret = 256
doko@ubuntu.com4c990712012-06-30 21:28:09766 if ret >> 8 == 0:
Brett Cannon9f5db072010-10-29 20:19:27767 with open(tmpfile) as fp:
768 for ln in fp:
769 if 'curses' in ln:
770 readline_termcap_library = re.sub(
771 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
772 ).rstrip()
773 break
774 # termcap interface split out from ncurses
775 if 'tinfo' in ln:
776 readline_termcap_library = 'tinfo'
777 break
doko@ubuntu.com4c990712012-06-30 21:28:09778 if os.path.exists(tmpfile):
779 os.unlink(tmpfile)
Stefan Krah095b2732010-06-08 13:41:44780 # Issue 7384: If readline is already linked against curses,
781 # use the same library for the readline and curses modules.
782 if 'curses' in readline_termcap_library:
783 curses_library = readline_termcap_library
Tarek Ziadé36797272010-07-22 12:50:05784 elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
Stefan Krah095b2732010-06-08 13:41:44785 curses_library = 'ncursesw'
Tarek Ziadé36797272010-07-22 12:50:05786 elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
Stefan Krah095b2732010-06-08 13:41:44787 curses_library = 'ncurses'
Tarek Ziadé36797272010-07-22 12:50:05788 elif self.compiler.find_library_file(lib_dirs, 'curses'):
Stefan Krah095b2732010-06-08 13:41:44789 curses_library = 'curses'
790
doko@ubuntu.com93df16b2012-06-30 12:32:08791 if host_platform == 'darwin':
Ronald Oussoren2efd9242009-09-20 14:53:22792 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren961683a2010-03-08 07:09:59793 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily04cdfa12014-06-25 20:36:14794 if (dep_target and
795 (tuple(int(n) for n in dep_target.split('.')[0:2])
796 < (10, 5) ) ):
Ronald Oussoren961683a2010-03-08 07:09:59797 os_release = 8
Ronald Oussoren2efd9242009-09-20 14:53:22798 if os_release < 9:
799 # MacOSX 10.4 has a broken readline. Don't try to build
800 # the readline module unless the user has installed a fixed
801 # readline package
802 if find_file('readline/rlconf.h', inc_dirs, []) is None:
803 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23804 if do_readline:
doko@ubuntu.com93df16b2012-06-30 12:32:08805 if host_platform == 'darwin' and os_release < 9:
Thomas Wouters477c8d52006-05-27 19:21:47806 # In every directory on the search path search for a dynamic
807 # library and then a static library, instead of first looking
Fred Drake0af17612007-09-04 19:43:19808 # for dynamic libraries on the entire path.
Martin Pantere26da7c2016-06-02 10:07:09809 # This way a statically linked custom readline gets picked up
Ronald Oussoren2c12ab12010-06-03 14:42:25810 # before the (possibly broken) dynamic library in /usr/lib.
Thomas Wouters477c8d52006-05-27 19:21:47811 readline_extra_link_args = ('-Wl,-search_paths_first',)
812 else:
813 readline_extra_link_args = ()
814
Marc-André Lemburg2efc3232001-01-26 18:23:02815 readline_libs = ['readline']
Stefan Krah095b2732010-06-08 13:41:44816 if readline_termcap_library:
817 pass # Issue 7384: Already linked against curses or tinfo.
818 elif curses_library:
819 readline_libs.append(curses_library)
Tarek Ziadé36797272010-07-22 12:50:05820 elif self.compiler.find_library_file(lib_dirs +
Tarek Ziadédd07ebb2009-07-06 13:52:17821 ['/usr/lib/termcap'],
822 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02823 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23824 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24825 library_dirs=['/usr/lib/termcap'],
Thomas Wouters477c8d52006-05-27 19:21:47826 extra_link_args=readline_extra_link_args,
Marc-André Lemburg2efc3232001-01-26 18:23:02827 libraries=readline_libs) )
Guido van Rossumd8faa362007-04-27 19:54:29828 else:
829 missing.append('readline')
830
Ronald Oussoren94f25282010-05-05 19:11:21831 # crypt module.
Tim Peters2c60f7a2003-01-29 03:49:43832
Tarek Ziadé36797272010-07-22 12:50:05833 if self.compiler.find_library_file(lib_dirs, 'crypt'):
Ronald Oussoren94f25282010-05-05 19:11:21834 libs = ['crypt']
Guido van Rossumd8faa362007-04-27 19:54:29835 else:
Ronald Oussoren94f25282010-05-05 19:11:21836 libs = []
Sean Reifscheidere2dfefb2011-02-22 10:55:44837 exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23838
Skip Montanaroba9e9782003-03-20 23:34:22839 # CSV files
840 exts.append( Extension('_csv', ['_csv.c']) )
841
Gregory P. Smithfb94c5f2010-03-14 06:49:55842 # POSIX subprocess module helper.
843 exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) )
844
Andrew M. Kuchling00e0f212001-01-17 15:23:23845 # socket(2)
Guido van Rossum47d3a7a2002-06-13 14:41:32846 exts.append( Extension('_socket', ['socketmodule.c'],
Jeremy Hylton340043e2002-06-13 17:38:11847 depends = ['socketmodule.h']) )
Marc-André Lemburga5d2b4c2002-02-16 18:23:30848 # Detect SSL support for the socket module (via _ssl)
Gregory P. Smithade97332005-08-23 21:19:40849 search_for_ssl_incs_in = [
850 '/usr/local/ssl/include',
Andrew M. Kuchlinge7c87322001-01-19 16:58:21851 '/usr/contrib/ssl/include/'
852 ]
Gregory P. Smithade97332005-08-23 21:19:40853 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
854 search_for_ssl_incs_in
Andrew M. Kuchlingfbe73762001-01-18 18:44:20855 )
Martin v. Löwisa950f7f2003-05-09 09:05:19856 if ssl_incs is not None:
857 krb5_h = find_file('krb5.h', inc_dirs,
858 ['/usr/kerberos/include'])
859 if krb5_h:
860 ssl_incs += krb5_h
Tarek Ziadé36797272010-07-22 12:50:05861 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21862 ['/usr/local/ssl/lib',
863 '/usr/contrib/ssl/lib/'
864 ] )
Fredrik Lundhade711a2001-01-24 08:00:28865
Andrew M. Kuchlingfbe73762001-01-18 18:44:20866 if (ssl_incs is not None and
867 ssl_libs is not None):
Marc-André Lemburga5d2b4c2002-02-16 18:23:30868 exts.append( Extension('_ssl', ['_ssl.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20869 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28870 library_dirs = ssl_libs,
Guido van Rossum47d3a7a2002-06-13 14:41:32871 libraries = ['ssl', 'crypto'],
Jeremy Hylton340043e2002-06-13 17:38:11872 depends = ['socketmodule.h']), )
Guido van Rossumd8faa362007-04-27 19:54:29873 else:
874 missing.append('_ssl')
Andrew M. Kuchling00e0f212001-01-17 15:23:23875
Gregory P. Smithade97332005-08-23 21:19:40876 # find out which version of OpenSSL we have
877 openssl_ver = 0
878 openssl_ver_re = re.compile(
R David Murray44b548d2016-09-08 17:59:53879 r'^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
Gregory P. Smithade97332005-08-23 21:19:40880
Ronald Oussoren2c12ab12010-06-03 14:42:25881 # look for the openssl version header on the compiler search path.
882 opensslv_h = find_file('openssl/opensslv.h', [],
883 inc_dirs + search_for_ssl_incs_in)
884 if opensslv_h:
885 name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
doko@ubuntu.com93df16b2012-06-30 12:32:08886 if host_platform == 'darwin' and is_macosx_sdk_path(name):
Ronald Oussoren2c12ab12010-06-03 14:42:25887 name = os.path.join(macosx_sdk_root(), name[1:])
888 try:
Brett Cannon9f5db072010-10-29 20:19:27889 with open(name, 'r') as incfile:
890 for line in incfile:
891 m = openssl_ver_re.match(line)
892 if m:
Antoine Pitrou2463e5f2013-03-28 21:24:43893 openssl_ver = int(m.group(1), 16)
894 break
Ronald Oussoren2c12ab12010-06-03 14:42:25895 except IOError as msg:
896 print("IOError while reading opensshv.h:", msg)
Gregory P. Smithade97332005-08-23 21:19:40897
Guido van Rossumeb1cf4e2007-08-17 17:14:17898 #print('openssl_ver = 0x%08x' % openssl_ver)
Gregory P. Smithb04ded42010-01-03 00:38:10899 min_openssl_ver = 0x00907000
900 have_any_openssl = ssl_incs is not None and ssl_libs is not None
901 have_usable_openssl = (have_any_openssl and
902 openssl_ver >= min_openssl_ver)
Gregory P. Smithade97332005-08-23 21:19:40903
Gregory P. Smithb04ded42010-01-03 00:38:10904 if have_any_openssl:
905 if have_usable_openssl:
Guido van Rossumeb1cf4e2007-08-17 17:14:17906 # The _hashlib module wraps optimized implementations
907 # of hash functions from the OpenSSL library.
908 exts.append( Extension('_hashlib', ['_hashopenssl.c'],
Gregory P. Smith5af7fba2010-01-03 14:51:13909 depends = ['hashlib.h'],
Guido van Rossumeb1cf4e2007-08-17 17:14:17910 include_dirs = ssl_incs,
911 library_dirs = ssl_libs,
912 libraries = ['ssl', 'crypto']) )
913 else:
914 print("warning: openssl 0x%08x is too old for _hashlib" %
915 openssl_ver)
916 missing.append('_hashlib')
Gregory P. Smithf21a5f72005-08-21 18:45:59917
Antoine Pitrou019ff192012-05-16 14:41:26918 # We always compile these even when OpenSSL is available (issue #14693).
919 # It's harmless and the object code is tiny (40-50 KB per module,
920 # only loaded when actually used).
921 exts.append( Extension('_sha256', ['sha256module.c'],
922 depends=['hashlib.h']) )
923 exts.append( Extension('_sha512', ['sha512module.c'],
924 depends=['hashlib.h']) )
925 exts.append( Extension('_md5', ['md5module.c'],
926 depends=['hashlib.h']) )
927 exts.append( Extension('_sha1', ['sha1module.c'],
928 depends=['hashlib.h']) )
Gregory P. Smith2f21eb32007-09-09 06:44:34929
Christian Heimes3c397e42016-09-06 20:35:14930 blake2_deps = glob(os.path.join(os.getcwd(), srcdir,
931 'Modules/_blake2/impl/*'))
Christian Heimes121b9482016-09-06 20:03:25932 blake2_deps.append('hashlib.h')
933
934 blake2_macros = []
Neil Schemenauer9cead062017-06-16 02:12:46935 if (not cross_compiling and
936 os.uname().machine == "x86_64" and
937 sys.maxsize > 2**32):
938 # Every x86_64 machine has at least SSE2. Check for sys.maxsize
939 # in case that kernel is 64-bit but userspace is 32-bit.
Christian Heimes121b9482016-09-06 20:03:25940 blake2_macros.append(('BLAKE2_USE_SSE', '1'))
941
942 exts.append( Extension('_blake2',
943 ['_blake2/blake2module.c',
944 '_blake2/blake2b_impl.c',
945 '_blake2/blake2s_impl.c'],
946 define_macros=blake2_macros,
947 depends=blake2_deps) )
948
Christian Heimes6fe2a752016-09-07 09:58:24949 sha3_deps = glob(os.path.join(os.getcwd(), srcdir,
950 'Modules/_sha3/kcp/*'))
951 sha3_deps.append('hashlib.h')
952 exts.append( Extension('_sha3',
953 ['_sha3/sha3module.c'],
954 depends=sha3_deps))
955
Georg Brandl489cb4f2009-07-11 10:08:49956 # Modules that provide persistent dictionary-like semantics. You will
957 # probably want to arrange for at least one of them to be available on
958 # your machine, though none are defined by default because of library
959 # dependencies. The Python module dbm/__init__.py provides an
960 # implementation independent wrapper for these; dbm/dumb.py provides
961 # similar functionality (but slower of course) implemented in Python.
962
963 # Sleepycat^WOracle Berkeley DB interface.
964 # http://www.oracle.com/database/berkeley-db/db/index.html
965 #
966 # This requires the Sleepycat^WOracle DB code. The supported versions
967 # are set below. Visit the URL above to download
968 # a release. Most open source OSes come with one or more
969 # versions of BerkeleyDB already installed.
970
doko@ubuntu.com15bac0f2012-07-01 08:35:54971 max_db_ver = (5, 3)
Georg Brandl489cb4f2009-07-11 10:08:49972 min_db_ver = (3, 3)
973 db_setup_debug = False # verbose debug prints from this script?
974
975 def allow_db_ver(db_ver):
976 """Returns a boolean if the given BerkeleyDB version is acceptable.
977
978 Args:
979 db_ver: A tuple of the version to verify.
980 """
981 if not (min_db_ver <= db_ver <= max_db_ver):
982 return False
983 return True
984
985 def gen_db_minor_ver_nums(major):
986 if major == 4:
987 for x in range(max_db_ver[1]+1):
988 if allow_db_ver((4, x)):
989 yield x
990 elif major == 3:
991 for x in (3,):
992 if allow_db_ver((3, x)):
993 yield x
994 else:
995 raise ValueError("unknown major BerkeleyDB version", major)
996
997 # construct a list of paths to look for the header file in on
998 # top of the normal inc_dirs.
999 db_inc_paths = [
1000 '/usr/include/db4',
1001 '/usr/local/include/db4',
1002 '/opt/sfw/include/db4',
1003 '/usr/include/db3',
1004 '/usr/local/include/db3',
1005 '/opt/sfw/include/db3',
1006 # Fink defaults (http://fink.sourceforge.net/)
1007 '/sw/include/db4',
1008 '/sw/include/db3',
1009 ]
1010 # 4.x minor number specific paths
1011 for x in gen_db_minor_ver_nums(4):
1012 db_inc_paths.append('/usr/include/db4%d' % x)
1013 db_inc_paths.append('/usr/include/db4.%d' % x)
1014 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1015 db_inc_paths.append('/usr/local/include/db4%d' % x)
1016 db_inc_paths.append('/pkg/db-4.%d/include' % x)
1017 db_inc_paths.append('/opt/db-4.%d/include' % x)
1018 # MacPorts default (http://www.macports.org/)
1019 db_inc_paths.append('/opt/local/include/db4%d' % x)
1020 # 3.x minor number specific paths
1021 for x in gen_db_minor_ver_nums(3):
1022 db_inc_paths.append('/usr/include/db3%d' % x)
1023 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1024 db_inc_paths.append('/usr/local/include/db3%d' % x)
1025 db_inc_paths.append('/pkg/db-3.%d/include' % x)
1026 db_inc_paths.append('/opt/db-3.%d/include' % x)
1027
doko@ubuntu.com1abe1c52012-06-30 18:42:451028 if cross_compiling:
1029 db_inc_paths = []
1030
Georg Brandl489cb4f2009-07-11 10:08:491031 # Add some common subdirectories for Sleepycat DB to the list,
1032 # based on the standard include directories. This way DB3/4 gets
1033 # picked up when it is installed in a non-standard prefix and
1034 # the user has added that prefix into inc_dirs.
1035 std_variants = []
1036 for dn in inc_dirs:
1037 std_variants.append(os.path.join(dn, 'db3'))
1038 std_variants.append(os.path.join(dn, 'db4'))
1039 for x in gen_db_minor_ver_nums(4):
1040 std_variants.append(os.path.join(dn, "db4%d"%x))
1041 std_variants.append(os.path.join(dn, "db4.%d"%x))
1042 for x in gen_db_minor_ver_nums(3):
1043 std_variants.append(os.path.join(dn, "db3%d"%x))
1044 std_variants.append(os.path.join(dn, "db3.%d"%x))
1045
1046 db_inc_paths = std_variants + db_inc_paths
1047 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
1048
1049 db_ver_inc_map = {}
1050
doko@ubuntu.com93df16b2012-06-30 12:32:081051 if host_platform == 'darwin':
Ronald Oussoren2c12ab12010-06-03 14:42:251052 sysroot = macosx_sdk_root()
1053
Georg Brandl489cb4f2009-07-11 10:08:491054 class db_found(Exception): pass
1055 try:
1056 # See whether there is a Sleepycat header in the standard
1057 # search path.
1058 for d in inc_dirs + db_inc_paths:
1059 f = os.path.join(d, "db.h")
doko@ubuntu.com93df16b2012-06-30 12:32:081060 if host_platform == 'darwin' and is_macosx_sdk_path(d):
Ronald Oussoren2c12ab12010-06-03 14:42:251061 f = os.path.join(sysroot, d[1:], "db.h")
1062
Georg Brandl489cb4f2009-07-11 10:08:491063 if db_setup_debug: print("db: looking for db.h in", f)
1064 if os.path.exists(f):
Brett Cannon9f5db072010-10-29 20:19:271065 with open(f, 'rb') as file:
1066 f = file.read()
Benjamin Peterson019f3612009-08-12 18:18:031067 m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:491068 if m:
1069 db_major = int(m.group(1))
Benjamin Peterson019f3612009-08-12 18:18:031070 m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:491071 db_minor = int(m.group(1))
1072 db_ver = (db_major, db_minor)
1073
1074 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1075 if db_ver == (4, 6):
Benjamin Peterson019f3612009-08-12 18:18:031076 m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f)
Georg Brandl489cb4f2009-07-11 10:08:491077 db_patch = int(m.group(1))
1078 if db_patch < 21:
1079 print("db.h:", db_ver, "patch", db_patch,
1080 "being ignored (4.6.x must be >= 4.6.21)")
1081 continue
1082
1083 if ( (db_ver not in db_ver_inc_map) and
1084 allow_db_ver(db_ver) ):
1085 # save the include directory with the db.h version
1086 # (first occurrence only)
1087 db_ver_inc_map[db_ver] = d
1088 if db_setup_debug:
1089 print("db.h: found", db_ver, "in", d)
1090 else:
1091 # we already found a header for this library version
1092 if db_setup_debug: print("db.h: ignoring", d)
1093 else:
1094 # ignore this header, it didn't contain a version number
1095 if db_setup_debug:
1096 print("db.h: no version number version in", d)
1097
1098 db_found_vers = list(db_ver_inc_map.keys())
1099 db_found_vers.sort()
1100
1101 while db_found_vers:
1102 db_ver = db_found_vers.pop()
1103 db_incdir = db_ver_inc_map[db_ver]
1104
1105 # check lib directories parallel to the location of the header
1106 db_dirs_to_check = [
1107 db_incdir.replace("include", 'lib64'),
1108 db_incdir.replace("include", 'lib'),
1109 ]
Ronald Oussoren2c12ab12010-06-03 14:42:251110
doko@ubuntu.com93df16b2012-06-30 12:32:081111 if host_platform != 'darwin':
Ronald Oussoren2c12ab12010-06-03 14:42:251112 db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
1113
1114 else:
1115 # Same as other branch, but takes OSX SDK into account
1116 tmp = []
1117 for dn in db_dirs_to_check:
1118 if is_macosx_sdk_path(dn):
1119 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1120 tmp.append(dn)
1121 else:
1122 if os.path.isdir(dn):
1123 tmp.append(dn)
Ronald Oussorendc969e52010-06-27 12:37:461124 db_dirs_to_check = tmp
Ronald Oussoren2c12ab12010-06-03 14:42:251125
1126 db_dirs_to_check = tmp
Georg Brandl489cb4f2009-07-11 10:08:491127
Ezio Melotti42da6632011-03-15 03:18:481128 # Look for a version specific db-X.Y before an ambiguous dbX
Georg Brandl489cb4f2009-07-11 10:08:491129 # XXX should we -ever- look for a dbX name? Do any
1130 # systems really not name their library by version and
1131 # symlink to more general names?
1132 for dblib in (('db-%d.%d' % db_ver),
1133 ('db%d%d' % db_ver),
1134 ('db%d' % db_ver[0])):
1135 dblib_file = self.compiler.find_library_file(
1136 db_dirs_to_check + lib_dirs, dblib )
1137 if dblib_file:
1138 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1139 raise db_found
1140 else:
1141 if db_setup_debug: print("db lib: ", dblib, "not found")
1142
1143 except db_found:
1144 if db_setup_debug:
1145 print("bsddb using BerkeleyDB lib:", db_ver, dblib)
1146 print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir)
Georg Brandl489cb4f2009-07-11 10:08:491147 dblibs = [dblib]
doko@ubuntu.coma3818a32014-04-17 15:52:481148 # Only add the found library and include directories if they aren't
1149 # already being searched. This avoids an explicit runtime library
1150 # dependency.
1151 if db_incdir in inc_dirs:
1152 db_incs = None
1153 else:
1154 db_incs = [db_incdir]
1155 if dblib_dir[0] in lib_dirs:
1156 dblib_dir = None
Georg Brandl489cb4f2009-07-11 10:08:491157 else:
1158 if db_setup_debug: print("db: no appropriate library found")
1159 db_incs = None
1160 dblibs = []
1161 dblib_dir = None
1162
Thomas Wouters49fd7fa2006-04-21 10:40:581163 # The sqlite interface
Thomas Wouters89f507f2006-12-13 04:49:301164 sqlite_setup_debug = False # verbose debug prints from this script?
Thomas Wouters49fd7fa2006-04-21 10:40:581165
1166 # We hunt for #define SQLITE_VERSION "n.n.n"
1167 # We need to find >= sqlite version 3.0.8
1168 sqlite_incdir = sqlite_libdir = None
1169 sqlite_inc_paths = [ '/usr/include',
1170 '/usr/include/sqlite',
1171 '/usr/include/sqlite3',
1172 '/usr/local/include',
1173 '/usr/local/include/sqlite',
1174 '/usr/local/include/sqlite3',
doko@ubuntu.com1abe1c52012-06-30 18:42:451175 ]
1176 if cross_compiling:
1177 sqlite_inc_paths = []
Thomas Wouters49fd7fa2006-04-21 10:40:581178 MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
1179 MIN_SQLITE_VERSION = ".".join([str(x)
1180 for x in MIN_SQLITE_VERSION_NUMBER])
Thomas Wouters477c8d52006-05-27 19:21:471181
1182 # Scan the default include directories before the SQLite specific
1183 # ones. This allows one to override the copy of sqlite on OSX,
1184 # where /usr/include contains an old version of sqlite.
doko@ubuntu.com93df16b2012-06-30 12:32:081185 if host_platform == 'darwin':
Ronald Oussoren2c12ab12010-06-03 14:42:251186 sysroot = macosx_sdk_root()
1187
Ned Deily9b635832012-08-05 22:13:331188 for d_ in inc_dirs + sqlite_inc_paths:
1189 d = d_
doko@ubuntu.com93df16b2012-06-30 12:32:081190 if host_platform == 'darwin' and is_macosx_sdk_path(d):
Ned Deily9b635832012-08-05 22:13:331191 d = os.path.join(sysroot, d[1:])
Ronald Oussoren2c12ab12010-06-03 14:42:251192
Ned Deily9b635832012-08-05 22:13:331193 f = os.path.join(d, "sqlite3.h")
Thomas Wouters49fd7fa2006-04-21 10:40:581194 if os.path.exists(f):
Guido van Rossum452bf512007-02-09 05:32:431195 if sqlite_setup_debug: print("sqlite: found %s"%f)
Brett Cannon9f5db072010-10-29 20:19:271196 with open(f) as file:
1197 incf = file.read()
Thomas Wouters49fd7fa2006-04-21 10:40:581198 m = re.search(
Petri Lehtinened909bc2013-02-23 16:05:281199 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Thomas Wouters49fd7fa2006-04-21 10:40:581200 if m:
1201 sqlite_version = m.group(1)
1202 sqlite_version_tuple = tuple([int(x)
1203 for x in sqlite_version.split(".")])
1204 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
1205 # we win!
Thomas Wouters89f507f2006-12-13 04:49:301206 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:431207 print("%s/sqlite3.h: version %s"%(d, sqlite_version))
Thomas Wouters49fd7fa2006-04-21 10:40:581208 sqlite_incdir = d
1209 break
1210 else:
1211 if sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:431212 print("%s: version %d is too old, need >= %s"%(d,
1213 sqlite_version, MIN_SQLITE_VERSION))
Thomas Wouters49fd7fa2006-04-21 10:40:581214 elif sqlite_setup_debug:
Guido van Rossum452bf512007-02-09 05:32:431215 print("sqlite: %s had no SQLITE_VERSION"%(f,))
Thomas Wouters49fd7fa2006-04-21 10:40:581216
1217 if sqlite_incdir:
1218 sqlite_dirs_to_check = [
1219 os.path.join(sqlite_incdir, '..', 'lib64'),
1220 os.path.join(sqlite_incdir, '..', 'lib'),
1221 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1222 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1223 ]
Tarek Ziadé36797272010-07-22 12:50:051224 sqlite_libfile = self.compiler.find_library_file(
Thomas Wouters49fd7fa2006-04-21 10:40:581225 sqlite_dirs_to_check + lib_dirs, 'sqlite3')
Benjamin Petersonf10a79a2008-10-11 00:49:571226 if sqlite_libfile:
1227 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Thomas Wouters49fd7fa2006-04-21 10:40:581228
1229 if sqlite_incdir and sqlite_libdir:
Thomas Wouters477c8d52006-05-27 19:21:471230 sqlite_srcs = ['_sqlite/cache.c',
Thomas Wouters49fd7fa2006-04-21 10:40:581231 '_sqlite/connection.c',
Thomas Wouters49fd7fa2006-04-21 10:40:581232 '_sqlite/cursor.c',
1233 '_sqlite/microprotocols.c',
1234 '_sqlite/module.c',
1235 '_sqlite/prepare_protocol.c',
1236 '_sqlite/row.c',
1237 '_sqlite/statement.c',
1238 '_sqlite/util.c', ]
1239
Thomas Wouters49fd7fa2006-04-21 10:40:581240 sqlite_defines = []
doko@ubuntu.com93df16b2012-06-30 12:32:081241 if host_platform != "win32":
Thomas Wouters49fd7fa2006-04-21 10:40:581242 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
1243 else:
1244 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1245
Benjamin Peterson076ed002010-10-31 17:11:021246 # Enable support for loadable extensions in the sqlite3 module
1247 # if --enable-loadable-sqlite-extensions configure option is used.
1248 if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
1249 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Thomas Wouters477c8d52006-05-27 19:21:471250
doko@ubuntu.com93df16b2012-06-30 12:32:081251 if host_platform == 'darwin':
Thomas Wouters477c8d52006-05-27 19:21:471252 # In every directory on the search path search for a dynamic
1253 # library and then a static library, instead of first looking
Ezio Melotti13925002011-03-16 09:05:331254 # for dynamic libraries on the entire path.
1255 # This way a statically linked custom sqlite gets picked up
Thomas Wouters477c8d52006-05-27 19:21:471256 # before the dynamic library in /usr/lib.
1257 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1258 else:
1259 sqlite_extra_link_args = ()
Thomas Wouters49fd7fa2006-04-21 10:40:581260
Brett Cannonc5011fe2011-06-07 03:09:101261 include_dirs = ["Modules/_sqlite"]
1262 # Only include the directory where sqlite was found if it does
1263 # not already exist in set include directories, otherwise you
1264 # can end up with a bad search path order.
1265 if sqlite_incdir not in self.compiler.include_dirs:
1266 include_dirs.append(sqlite_incdir)
doko@ubuntu.coma3818a32014-04-17 15:52:481267 # avoid a runtime library path for a system library dir
1268 if sqlite_libdir and sqlite_libdir[0] in lib_dirs:
1269 sqlite_libdir = None
Thomas Wouters49fd7fa2006-04-21 10:40:581270 exts.append(Extension('_sqlite3', sqlite_srcs,
1271 define_macros=sqlite_defines,
Brett Cannonc5011fe2011-06-07 03:09:101272 include_dirs=include_dirs,
Thomas Wouters49fd7fa2006-04-21 10:40:581273 library_dirs=sqlite_libdir,
Thomas Wouters477c8d52006-05-27 19:21:471274 extra_link_args=sqlite_extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:581275 libraries=["sqlite3",]))
Guido van Rossumd8faa362007-04-27 19:54:291276 else:
1277 missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:341278
Ross Lagerwall0b63b562012-04-15 06:19:351279 dbm_setup_debug = False # verbose debug prints from this script?
Benjamin Petersond78735d2010-01-01 16:04:231280 dbm_order = ['gdbm']
Andrew M. Kuchling00e0f212001-01-17 15:23:231281 # The standard Unix dbm module:
doko@ubuntu.com93df16b2012-06-30 12:32:081282 if host_platform not in ['cygwin']:
Matthias Klose55708cc2009-04-30 08:06:491283 config_args = [arg.strip("'")
1284 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
Benjamin Petersond78735d2010-01-01 16:04:231285 dbm_args = [arg for arg in config_args
Matthias Klose55708cc2009-04-30 08:06:491286 if arg.startswith('--with-dbmliborder=')]
1287 if dbm_args:
Benjamin Petersond78735d2010-01-01 16:04:231288 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
Matthias Klose55708cc2009-04-30 08:06:491289 else:
Georg Brandl489cb4f2009-07-11 10:08:491290 dbm_order = "ndbm:gdbm:bdb".split(":")
Matthias Klose55708cc2009-04-30 08:06:491291 dbmext = None
1292 for cand in dbm_order:
1293 if cand == "ndbm":
1294 if find_file("ndbm.h", inc_dirs, []) is not None:
Nick Coghlan50f147a2012-06-17 08:27:111295 # Some systems have -lndbm, others have -lgdbm_compat,
1296 # others don't have either
Tarek Ziadé36797272010-07-22 12:50:051297 if self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171298 'ndbm'):
Matthias Klose55708cc2009-04-30 08:06:491299 ndbm_libs = ['ndbm']
Nick Coghlan50f147a2012-06-17 08:27:111300 elif self.compiler.find_library_file(lib_dirs,
1301 'gdbm_compat'):
1302 ndbm_libs = ['gdbm_compat']
Matthias Klose55708cc2009-04-30 08:06:491303 else:
1304 ndbm_libs = []
Ross Lagerwall0b63b562012-04-15 06:19:351305 if dbm_setup_debug: print("building dbm using ndbm")
Matthias Klose55708cc2009-04-30 08:06:491306 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1307 define_macros=[
1308 ('HAVE_NDBM_H',None),
1309 ],
1310 libraries=ndbm_libs)
1311 break
1312
1313 elif cand == "gdbm":
Tarek Ziadé36797272010-07-22 12:50:051314 if self.compiler.find_library_file(lib_dirs, 'gdbm'):
Matthias Klose55708cc2009-04-30 08:06:491315 gdbm_libs = ['gdbm']
Tarek Ziadé36797272010-07-22 12:50:051316 if self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171317 'gdbm_compat'):
Matthias Klose55708cc2009-04-30 08:06:491318 gdbm_libs.append('gdbm_compat')
1319 if find_file("gdbm/ndbm.h", inc_dirs, []) is not None:
Ross Lagerwall0b63b562012-04-15 06:19:351320 if dbm_setup_debug: print("building dbm using gdbm")
Matthias Klose55708cc2009-04-30 08:06:491321 dbmext = Extension(
1322 '_dbm', ['_dbmmodule.c'],
1323 define_macros=[
1324 ('HAVE_GDBM_NDBM_H', None),
1325 ],
1326 libraries = gdbm_libs)
1327 break
1328 if find_file("gdbm-ndbm.h", inc_dirs, []) is not None:
Ross Lagerwall0b63b562012-04-15 06:19:351329 if dbm_setup_debug: print("building dbm using gdbm")
Matthias Klose55708cc2009-04-30 08:06:491330 dbmext = Extension(
1331 '_dbm', ['_dbmmodule.c'],
1332 define_macros=[
1333 ('HAVE_GDBM_DASH_NDBM_H', None),
1334 ],
1335 libraries = gdbm_libs)
1336 break
Georg Brandl489cb4f2009-07-11 10:08:491337 elif cand == "bdb":
doko@ubuntu.coma3818a32014-04-17 15:52:481338 if dblibs:
Ross Lagerwall0b63b562012-04-15 06:19:351339 if dbm_setup_debug: print("building dbm using bdb")
Georg Brandl489cb4f2009-07-11 10:08:491340 dbmext = Extension('_dbm', ['_dbmmodule.c'],
1341 library_dirs=dblib_dir,
1342 runtime_library_dirs=dblib_dir,
1343 include_dirs=db_incs,
1344 define_macros=[
1345 ('HAVE_BERKDB_H', None),
1346 ('DB_DBM_HSEARCH', None),
1347 ],
1348 libraries=dblibs)
Matthias Klose55708cc2009-04-30 08:06:491349 break
1350 if dbmext is not None:
1351 exts.append(dbmext)
Guido van Rossumd8faa362007-04-27 19:54:291352 else:
Georg Brandl0a7ac7d2008-05-26 10:29:351353 missing.append('_dbm')
Fredrik Lundhade711a2001-01-24 08:00:281354
Andrew M. Kuchling00e0f212001-01-17 15:23:231355 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
Benjamin Petersond78735d2010-01-01 16:04:231356 if ('gdbm' in dbm_order and
Tarek Ziadé36797272010-07-22 12:50:051357 self.compiler.find_library_file(lib_dirs, 'gdbm')):
Georg Brandl0a7ac7d2008-05-26 10:29:351358 exts.append( Extension('_gdbm', ['_gdbmmodule.c'],
Andrew M. Kuchling00e0f212001-01-17 15:23:231359 libraries = ['gdbm'] ) )
Guido van Rossumd8faa362007-04-27 19:54:291360 else:
Georg Brandl0a7ac7d2008-05-26 10:29:351361 missing.append('_gdbm')
Andrew M. Kuchling00e0f212001-01-17 15:23:231362
Andrew M. Kuchling00e0f212001-01-17 15:23:231363 # Unix-only modules
doko@ubuntu.com93df16b2012-06-30 12:32:081364 if host_platform != 'win32':
Andrew M. Kuchling00e0f212001-01-17 15:23:231365 # Steen Lumholt's termios module
1366 exts.append( Extension('termios', ['termios.c']) )
1367 # Jeremy Hylton's rlimit interface
Antoine Pitrou6103ab12009-10-24 20:11:211368 exts.append( Extension('resource', ['resource.c']) )
Guido van Rossumd8faa362007-04-27 19:54:291369 else:
Christian Heimes12ae4072018-01-27 08:39:161370 missing.extend(['resource', 'termios'])
1371
1372 nis = self._detect_nis(inc_dirs, lib_dirs)
1373 if nis is not None:
1374 exts.append(nis)
1375 else:
1376 missing.append('nis')
Andrew M. Kuchling00e0f212001-01-17 15:23:231377
Skip Montanaro72092942004-02-07 12:50:191378 # Curses support, requiring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:281379 # provided by the ncurses library.
Victor Stinneraa35b002011-11-28 23:08:121380 curses_defines = []
Victor Stinner756c6ec2011-11-26 23:19:531381 curses_includes = []
Victor Stinneraa35b002011-11-28 23:08:121382 panel_library = 'panel'
1383 if curses_library == 'ncursesw':
1384 curses_defines.append(('HAVE_NCURSESW', '1'))
Xavier de Gayee13c3202016-12-13 15:04:141385 if not cross_compiling:
1386 curses_includes.append('/usr/include/ncursesw')
Victor Stinneraa35b002011-11-28 23:08:121387 # Bug 1464056: If _curses.so links with ncursesw,
1388 # _curses_panel.so must link with panelw.
1389 panel_library = 'panelw'
doko@ubuntu.com93df16b2012-06-30 12:32:081390 if host_platform == 'darwin':
Ned Deily69192232012-06-21 06:47:141391 # On OS X, there is no separate /usr/lib/libncursesw nor
1392 # libpanelw. If we are here, we found a locally-supplied
Andrew Svetlov28453fe2017-12-14 14:19:511393 # version of libncursesw. There should also be a
Ned Deily69192232012-06-21 06:47:141394 # libpanelw. _XOPEN_SOURCE defines are usually excluded
1395 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
1396 # ncurses wide char support
1397 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
doko@ubuntu.com93df16b2012-06-30 12:32:081398 elif host_platform == 'darwin' and curses_library == 'ncurses':
Ned Deily69192232012-06-21 06:47:141399 # Building with the system-suppied combined libncurses/libpanel
1400 curses_defines.append(('HAVE_NCURSESW', '1'))
1401 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
Victor Stinneraa35b002011-11-28 23:08:121402
Stefan Krah095b2732010-06-08 13:41:441403 if curses_library.startswith('ncurses'):
Stefan Krah095b2732010-06-08 13:41:441404 curses_libs = [curses_library]
Martin v. Löwisa55e55e2006-02-11 15:55:141405 exts.append( Extension('_curses', ['_cursesmodule.c'],
Victor Stinner756c6ec2011-11-26 23:19:531406 include_dirs=curses_includes,
Nadeem Vawda9e2e9902011-07-31 13:01:111407 define_macros=curses_defines,
Martin v. Löwisa55e55e2006-02-11 15:55:141408 libraries = curses_libs) )
doko@ubuntu.com93df16b2012-06-30 12:32:081409 elif curses_library == 'curses' and host_platform != 'darwin':
Michael W. Hudson5b109102002-01-23 15:04:411410 # OSX has an old Berkeley curses, not good enough for
1411 # the _curses module.
Tarek Ziadé36797272010-07-22 12:50:051412 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
Andrew M. Kuchling00e0f212001-01-17 15:23:231413 curses_libs = ['curses', 'terminfo']
Tarek Ziadé36797272010-07-22 12:50:051414 elif (self.compiler.find_library_file(lib_dirs, 'termcap')):
Andrew M. Kuchling00e0f212001-01-17 15:23:231415 curses_libs = ['curses', 'termcap']
Neal Norwitz0b27ff92003-03-31 15:53:491416 else:
1417 curses_libs = ['curses']
Fredrik Lundhade711a2001-01-24 08:00:281418
Andrew M. Kuchling00e0f212001-01-17 15:23:231419 exts.append( Extension('_curses', ['_cursesmodule.c'],
Nadeem Vawda9e2e9902011-07-31 13:01:111420 define_macros=curses_defines,
Andrew M. Kuchling00e0f212001-01-17 15:23:231421 libraries = curses_libs) )
Guido van Rossumd8faa362007-04-27 19:54:291422 else:
1423 missing.append('_curses')
Fredrik Lundhade711a2001-01-24 08:00:281424
Andrew M. Kuchling00e0f212001-01-17 15:23:231425 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:161426 if (module_enabled(exts, '_curses') and
Tarek Ziadé36797272010-07-22 12:50:051427 self.compiler.find_library_file(lib_dirs, panel_library)):
Andrew M. Kuchling00e0f212001-01-17 15:23:231428 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
Victor Stinner756c6ec2011-11-26 23:19:531429 include_dirs=curses_includes,
Ned Deily69192232012-06-21 06:47:141430 define_macros=curses_defines,
Thomas Wouters0e3f5912006-08-11 14:57:121431 libraries = [panel_library] + curses_libs) )
Guido van Rossumd8faa362007-04-27 19:54:291432 else:
1433 missing.append('_curses_panel')
Fredrik Lundhade711a2001-01-24 08:00:281434
Barry Warsaw259b1e12002-08-13 20:09:261435 # Andrew Kuchling's zlib module. Note that some versions of zlib
1436 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1437 # http://www.cert.org/advisories/CA-2002-07.html
1438 #
1439 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1440 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1441 # now, we still accept 1.1.3, because we think it's difficult to
1442 # exploit this in Python, and we'd rather make it RedHat's problem
1443 # than our problem <wink>.
1444 #
1445 # You can upgrade zlib to version 1.1.4 yourself by going to
1446 # http://www.gzip.org/zlib/
Guido van Rossume6970912001-04-15 15:16:121447 zlib_inc = find_file('zlib.h', [], inc_dirs)
Christian Heimes1dc54002008-03-24 02:19:291448 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:121449 if zlib_inc is not None:
1450 zlib_h = zlib_inc[0] + '/zlib.h'
1451 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:261452 version_req = '"1.1.3"'
Ned Deily507c5912013-10-19 04:32:001453 if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
1454 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Brett Cannon9f5db072010-10-29 20:19:271455 with open(zlib_h) as fp:
1456 while 1:
1457 line = fp.readline()
1458 if not line:
1459 break
1460 if line.startswith('#define ZLIB_VERSION'):
1461 version = line.split()[2]
1462 break
Guido van Rossume6970912001-04-15 15:16:121463 if version >= version_req:
Tarek Ziadé36797272010-07-22 12:50:051464 if (self.compiler.find_library_file(lib_dirs, 'z')):
doko@ubuntu.com93df16b2012-06-30 12:32:081465 if host_platform == "darwin":
Thomas Wouters0e3f5912006-08-11 14:57:121466 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1467 else:
1468 zlib_extra_link_args = ()
Guido van Rossume6970912001-04-15 15:16:121469 exts.append( Extension('zlib', ['zlibmodule.c'],
Thomas Wouters0e3f5912006-08-11 14:57:121470 libraries = ['z'],
1471 extra_link_args = zlib_extra_link_args))
Christian Heimes1dc54002008-03-24 02:19:291472 have_zlib = True
Guido van Rossumd8faa362007-04-27 19:54:291473 else:
1474 missing.append('zlib')
1475 else:
1476 missing.append('zlib')
1477 else:
1478 missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:231479
Christian Heimes1dc54002008-03-24 02:19:291480 # Helper module for various ascii-encoders. Uses zlib for an optimized
1481 # crc32 if we have it. Otherwise binascii uses its own.
1482 if have_zlib:
1483 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1484 libraries = ['z']
1485 extra_link_args = zlib_extra_link_args
1486 else:
1487 extra_compile_args = []
1488 libraries = []
1489 extra_link_args = []
1490 exts.append( Extension('binascii', ['binascii.c'],
1491 extra_compile_args = extra_compile_args,
1492 libraries = libraries,
1493 extra_link_args = extra_link_args) )
1494
Gustavo Niemeyerf8ca8362002-11-05 16:50:051495 # Gustavo Niemeyer's bz2 module.
Tarek Ziadé36797272010-07-22 12:50:051496 if (self.compiler.find_library_file(lib_dirs, 'bz2')):
doko@ubuntu.com93df16b2012-06-30 12:32:081497 if host_platform == "darwin":
Thomas Wouters0e3f5912006-08-11 14:57:121498 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1499 else:
1500 bz2_extra_link_args = ()
Antoine Pitrou37dc5f82011-04-03 15:05:461501 exts.append( Extension('_bz2', ['_bz2module.c'],
Thomas Wouters0e3f5912006-08-11 14:57:121502 libraries = ['bz2'],
1503 extra_link_args = bz2_extra_link_args) )
Guido van Rossumd8faa362007-04-27 19:54:291504 else:
Antoine Pitrou37dc5f82011-04-03 15:05:461505 missing.append('_bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:051506
Nadeem Vawda3ff069e2011-11-29 22:25:061507 # LZMA compression support.
1508 if self.compiler.find_library_file(lib_dirs, 'lzma'):
1509 exts.append( Extension('_lzma', ['_lzmamodule.c'],
1510 libraries = ['lzma']) )
1511 else:
1512 missing.append('_lzma')
1513
Andrew M. Kuchling00e0f212001-01-17 15:23:231514 # Interface to the Expat XML parser
1515 #
Benjamin Petersona28e7022010-01-09 18:53:061516 # Expat was written by James Clark and is now maintained by a group of
1517 # developers on SourceForge; see www.libexpat.org for more information.
1518 # The pyexpat module was written by Paul Prescod after a prototype by
1519 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1520 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Petersonc73206c2010-10-31 16:38:191521 # configure option.
Fred Drakefc8341d2002-06-17 17:55:301522 #
1523 # More information on Expat can be found at www.libexpat.org.
1524 #
Benjamin Petersonb2d90462009-12-31 03:23:101525 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1526 expat_inc = []
1527 define_macros = []
Victor Stinnerdedcbee2017-11-29 23:00:351528 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:101529 expat_lib = ['expat']
1530 expat_sources = []
Christian Heimesd489c7a2013-02-09 16:02:061531 expat_depends = []
Benjamin Petersonb2d90462009-12-31 03:23:101532 else:
1533 expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')]
1534 define_macros = [
1535 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinner83e37e12017-08-18 23:06:271536 # bpo-30947: Python uses best available entropy sources to
1537 # call XML_SetHashSalt(), expat entropy sources are not needed
1538 ('XML_POOR_ENTROPY', '1'),
Benjamin Petersonb2d90462009-12-31 03:23:101539 ]
Victor Stinnerdedcbee2017-11-29 23:00:351540 extra_compile_args = []
Benjamin Petersonb2d90462009-12-31 03:23:101541 expat_lib = []
1542 expat_sources = ['expat/xmlparse.c',
1543 'expat/xmlrole.c',
1544 'expat/xmltok.c']
Christian Heimesd489c7a2013-02-09 16:02:061545 expat_depends = ['expat/ascii.h',
1546 'expat/asciitab.h',
1547 'expat/expat.h',
1548 'expat/expat_config.h',
1549 'expat/expat_external.h',
1550 'expat/internal.h',
1551 'expat/latin1tab.h',
1552 'expat/utf8tab.h',
1553 'expat/xmlrole.h',
1554 'expat/xmltok.h',
1555 'expat/xmltok_impl.h'
1556 ]
Thomas Wouters477c8d52006-05-27 19:21:471557
Victor Stinnerdedcbee2017-11-29 23:00:351558 cc = sysconfig.get_config_var('CC').split()[0]
1559 ret = os.system(
Miss Islington (bot)a1093e42019-06-30 00:36:291560 '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
Victor Stinnerdedcbee2017-11-29 23:00:351561 if ret >> 8 == 0:
Miss Islington (bot)a1093e42019-06-30 00:36:291562 extra_compile_args.append('-Wno-unreachable-code')
Victor Stinnerdedcbee2017-11-29 23:00:351563
Fred Drake2d59a492003-10-21 15:41:151564 exts.append(Extension('pyexpat',
1565 define_macros = define_macros,
Victor Stinnerdedcbee2017-11-29 23:00:351566 extra_compile_args = extra_compile_args,
Benjamin Petersonb2d90462009-12-31 03:23:101567 include_dirs = expat_inc,
1568 libraries = expat_lib,
Christian Heimesd489c7a2013-02-09 16:02:061569 sources = ['pyexpat.c'] + expat_sources,
1570 depends = expat_depends,
Fred Drake2d59a492003-10-21 15:41:151571 ))
Andrew M. Kuchling00e0f212001-01-17 15:23:231572
Fredrik Lundh4c86ec62005-12-14 18:46:161573 # Fredrik Lundh's cElementTree module. Note that this also
1574 # uses expat (via the CAPI hook in pyexpat).
1575
Thomas Wouters49fd7fa2006-04-21 10:40:581576 if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:161577 define_macros.append(('USE_PYEXPAT_CAPI', None))
1578 exts.append(Extension('_elementtree',
1579 define_macros = define_macros,
Benjamin Petersonb2d90462009-12-31 03:23:101580 include_dirs = expat_inc,
1581 libraries = expat_lib,
Fredrik Lundh4c86ec62005-12-14 18:46:161582 sources = ['_elementtree.c'],
Christian Heimesd489c7a2013-02-09 16:02:061583 depends = ['pyexpat.c'] + expat_sources +
1584 expat_depends,
Fredrik Lundh4c86ec62005-12-14 18:46:161585 ))
Guido van Rossumd8faa362007-04-27 19:54:291586 else:
1587 missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:161588
Hye-Shik Chang3e2a3062004-01-17 14:29:291589 # Hye-Shik Chang's CJKCodecs modules.
Walter Dörwalde9eaab42007-05-22 16:02:131590 exts.append(Extension('_multibytecodec',
1591 ['cjkcodecs/multibytecodec.c']))
1592 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
1593 exts.append(Extension('_codecs_%s' % loc,
1594 ['cjkcodecs/_codecs_%s.c' % loc]))
Hye-Shik Chang3e2a3062004-01-17 14:29:291595
Stefan Krah1919b7e2012-03-21 17:25:231596 # Stefan Krah's _decimal module
1597 exts.append(self._decimal_ext())
1598
Thomas Hellercf567c12006-03-08 19:51:581599 # Thomas Heller's _ctypes module
Thomas Wouters49fd7fa2006-04-21 10:40:581600 self.detect_ctypes(inc_dirs, lib_dirs)
Thomas Hellercf567c12006-03-08 19:51:581601
Benjamin Petersone711caf2008-06-11 16:44:041602 # Richard Oudkerk's multiprocessing module
doko@ubuntu.com93df16b2012-06-30 12:32:081603 if host_platform == 'win32': # Windows
Benjamin Petersone711caf2008-06-11 16:44:041604 macros = dict()
1605 libraries = ['ws2_32']
1606
doko@ubuntu.com93df16b2012-06-30 12:32:081607 elif host_platform == 'darwin': # Mac OSX
Benjamin Peterson965ce872009-04-05 21:24:581608 macros = dict()
Benjamin Petersone711caf2008-06-11 16:44:041609 libraries = []
1610
doko@ubuntu.com93df16b2012-06-30 12:32:081611 elif host_platform == 'cygwin': # Cygwin
Benjamin Peterson965ce872009-04-05 21:24:581612 macros = dict()
Benjamin Petersone711caf2008-06-11 16:44:041613 libraries = []
Benjamin Peterson41181742008-07-02 20:22:541614
doko@ubuntu.com93df16b2012-06-30 12:32:081615 elif host_platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
Benjamin Peterson41181742008-07-02 20:22:541616 # FreeBSD's P1003.1b semaphore support is very experimental
1617 # and has many known problems. (as of June 2008)
Benjamin Peterson965ce872009-04-05 21:24:581618 macros = dict()
Benjamin Peterson41181742008-07-02 20:22:541619 libraries = []
1620
doko@ubuntu.com93df16b2012-06-30 12:32:081621 elif host_platform.startswith('openbsd'):
Benjamin Peterson965ce872009-04-05 21:24:581622 macros = dict()
Benjamin Petersone5384b02008-10-04 22:00:421623 libraries = []
1624
doko@ubuntu.com93df16b2012-06-30 12:32:081625 elif host_platform.startswith('netbsd'):
Benjamin Peterson965ce872009-04-05 21:24:581626 macros = dict()
Jesse Noller32d68c22009-03-31 18:48:421627 libraries = []
1628
Benjamin Petersone711caf2008-06-11 16:44:041629 else: # Linux and other unices
Benjamin Peterson965ce872009-04-05 21:24:581630 macros = dict()
Benjamin Petersone711caf2008-06-11 16:44:041631 libraries = ['rt']
1632
doko@ubuntu.com93df16b2012-06-30 12:32:081633 if host_platform == 'win32':
Benjamin Petersone711caf2008-06-11 16:44:041634 multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
1635 '_multiprocessing/semaphore.c',
Benjamin Petersone711caf2008-06-11 16:44:041636 ]
1637
1638 else:
1639 multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
Benjamin Petersone711caf2008-06-11 16:44:041640 ]
Mark Dickinsona614f042009-11-28 12:48:431641 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1642 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Petersone711caf2008-06-11 16:44:041643 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
1644
Jesse Noller6fd47e22009-01-23 14:09:081645 if sysconfig.get_config_var('WITH_THREAD'):
1646 exts.append ( Extension('_multiprocessing', multiprocessing_srcs,
1647 define_macros=list(macros.items()),
1648 include_dirs=["Modules/_multiprocessing"]))
1649 else:
1650 missing.append('_multiprocessing')
Benjamin Petersone711caf2008-06-11 16:44:041651 # End multiprocessing
Guido van Rossuma9e20242007-03-08 00:43:481652
Andrew M. Kuchling00e0f212001-01-17 15:23:231653 # Platform-specific libraries
doko@ubuntu.com93df16b2012-06-30 12:32:081654 if host_platform.startswith(('linux', 'freebsd', 'gnukfreebsd')):
Guido van Rossum0c016a92003-02-13 16:12:211655 exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
Guido van Rossumd8faa362007-04-27 19:54:291656 else:
1657 missing.append('ossaudiodev')
Andrew M. Kuchling00e0f212001-01-17 15:23:231658
doko@ubuntu.com93df16b2012-06-30 12:32:081659 if host_platform == 'darwin':
Benjamin Petersonebacd262008-05-29 21:09:511660 exts.append(
Ronald Oussoren84151202010-04-18 20:46:111661 Extension('_scproxy', ['_scproxy.c'],
1662 extra_link_args=[
1663 '-framework', 'SystemConfiguration',
1664 '-framework', 'CoreFoundation',
1665 ]))
Benjamin Petersonebacd262008-05-29 21:09:511666
Andrew M. Kuchlingfbe73762001-01-18 18:44:201667 self.extensions.extend(exts)
1668
1669 # Call the method for detecting whether _tkinter can be compiled
1670 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:281671
Guido van Rossumd8faa362007-04-27 19:54:291672 if '_tkinter' not in [e.name for e in self.extensions]:
1673 missing.append('_tkinter')
1674
Ned Deilycd3d8fb2013-08-02 06:51:271675## # Uncomment these lines if you want to play with xxmodule.c
1676## ext = Extension('xx', ['xxmodule.c'])
1677## self.extensions.append(ext)
1678
Xavier de Gaye13f1c332016-12-10 15:45:531679 if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
Ned Deilycd3d8fb2013-08-02 06:51:271680 ext = Extension('xxlimited', ['xxlimited.c'],
Benjamin Peterson24ac8772015-06-03 05:04:461681 define_macros=[('Py_LIMITED_API', '0x03050000')])
Ned Deilycd3d8fb2013-08-02 06:51:271682 self.extensions.append(ext)
1683
Guido van Rossumd8faa362007-04-27 19:54:291684 return missing
1685
Ned Deilyd819b932013-09-06 08:07:051686 def detect_tkinter_explicitly(self):
1687 # Build _tkinter using explicit locations for Tcl/Tk.
1688 #
1689 # This is enabled when both arguments are given to ./configure:
1690 #
1691 # --with-tcltk-includes="-I/path/to/tclincludes \
1692 # -I/path/to/tkincludes"
1693 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1694 # -L/path/to/tklibs -ltkm.n"
1695 #
Martin Pantere26da7c2016-06-02 10:07:091696 # These values can also be specified or overridden via make:
Ned Deilyd819b932013-09-06 08:07:051697 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1698 #
1699 # This can be useful for building and testing tkinter with multiple
1700 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1701 # build of Tcl so you need to specify both arguments and use care when
1702 # overriding.
1703
1704 # The _TCLTK variables are created in the Makefile sharedmods target.
1705 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1706 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1707 if not (tcltk_includes and tcltk_libs):
1708 # Resume default configuration search.
1709 return 0
1710
1711 extra_compile_args = tcltk_includes.split()
1712 extra_link_args = tcltk_libs.split()
1713 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1714 define_macros=[('WITH_APPINIT', 1)],
1715 extra_compile_args = extra_compile_args,
1716 extra_link_args = extra_link_args,
1717 )
1718 self.extensions.append(ext)
1719 return 1
1720
Jack Jansen0b06be72002-06-21 14:48:381721 def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
1722 # The _tkinter module, using frameworks. Since frameworks are quite
1723 # different the UNIX search logic is not sharable.
1724 from os.path import join, exists
1725 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:431726 '/Library/Frameworks',
Ronald Oussoren5f734f12009-03-04 21:32:481727 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:381728 join(os.getenv('HOME'), '/Library/Frameworks')
1729 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:201730
Ronald Oussoren2c12ab12010-06-03 14:42:251731 sysroot = macosx_sdk_root()
1732
Skip Montanaro0174ddd2005-12-30 05:01:261733 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:381734 # bundles.
1735 # XXX distutils should support -F!
1736 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:431737 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren2c12ab12010-06-03 14:42:251738
1739
Jack Jansen0b06be72002-06-21 14:48:381740 for fw in 'Tcl', 'Tk':
Ronald Oussoren2c12ab12010-06-03 14:42:251741 if is_macosx_sdk_path(F):
1742 if not exists(join(sysroot, F[1:], fw + '.framework')):
1743 break
1744 else:
1745 if not exists(join(F, fw + '.framework')):
1746 break
Jack Jansen0b06be72002-06-21 14:48:381747 else:
1748 # ok, F is now directory with both frameworks. Continure
1749 # building
1750 break
1751 else:
1752 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1753 # will now resume.
1754 return 0
Tim Peters2c60f7a2003-01-29 03:49:431755
Jack Jansen0b06be72002-06-21 14:48:381756 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1757 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:431758 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:381759 #
1760 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:431761 join(F, fw + '.framework', H)
Nick Coghlan650f0d02007-04-15 12:05:431762 for fw in ('Tcl', 'Tk')
1763 for H in ('Headers', 'Versions/Current/PrivateHeaders')
Jack Jansen0b06be72002-06-21 14:48:381764 ]
1765
Tim Peters2c60f7a2003-01-29 03:49:431766 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:381767 # complicated search, this is a hard-coded path. It could bail out
1768 # if X11 libs are not found...
1769 include_dirs.append('/usr/X11R6/include')
1770 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1771
Georg Brandlfcaf9102008-07-16 02:17:561772 # All existing framework builds of Tcl/Tk don't support 64-bit
1773 # architectures.
1774 cflags = sysconfig.get_config_vars('CFLAGS')[0]
R David Murray44b548d2016-09-08 17:59:531775 archs = re.findall(r'-arch\s+(\w+)', cflags)
Georg Brandlfcaf9102008-07-16 02:17:561776
Ronald Oussorend097efe2009-09-15 19:07:581777 tmpfile = os.path.join(self.build_temp, 'tk.arch')
1778 if not os.path.exists(self.build_temp):
1779 os.makedirs(self.build_temp)
1780
1781 # Note: cannot use os.popen or subprocess here, that
1782 # requires extensions that are not available here.
Ronald Oussoren2c12ab12010-06-03 14:42:251783 if is_macosx_sdk_path(F):
1784 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1785 else:
1786 os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
Ronald Oussoren2c12ab12010-06-03 14:42:251787
Brett Cannon9f5db072010-10-29 20:19:271788 with open(tmpfile) as fp:
1789 detected_archs = []
1790 for ln in fp:
1791 a = ln.split()[-1]
1792 if a in archs:
1793 detected_archs.append(ln.split()[-1])
Ronald Oussorend097efe2009-09-15 19:07:581794 os.unlink(tmpfile)
1795
1796 for a in detected_archs:
1797 frameworks.append('-arch')
1798 frameworks.append(a)
Georg Brandlfcaf9102008-07-16 02:17:561799
Jack Jansen0b06be72002-06-21 14:48:381800 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1801 define_macros=[('WITH_APPINIT', 1)],
1802 include_dirs = include_dirs,
1803 libraries = [],
Georg Brandlfcaf9102008-07-16 02:17:561804 extra_compile_args = frameworks[2:],
Jack Jansen0b06be72002-06-21 14:48:381805 extra_link_args = frameworks,
1806 )
1807 self.extensions.append(ext)
1808 return 1
1809
Andrew M. Kuchlingfbe73762001-01-18 18:44:201810 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:231811 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:411812
Ned Deilyd819b932013-09-06 08:07:051813 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1814 # configured or passed into the make target. If so, use these values
1815 # to build tkinter and bypass the searches for Tcl and TK in standard
1816 # locations.
1817 if self.detect_tkinter_explicitly():
1818 return
1819
Jack Jansen0b06be72002-06-21 14:48:381820 # Rather than complicate the code below, detecting and building
1821 # AquaTk is a separate method. Only one Tkinter will be built on
1822 # Darwin - either AquaTk, if it is found, or X11 based Tk.
doko@ubuntu.com93df16b2012-06-30 12:32:081823 if (host_platform == 'darwin' and
Skip Montanaro0174ddd2005-12-30 05:01:261824 self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
Tim Peters2c60f7a2003-01-29 03:49:431825 return
Jack Jansen0b06be72002-06-21 14:48:381826
Andrew M. Kuchlingfbe73762001-01-18 18:44:201827 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:011828 # The versions with dots are used on Unix, and the versions without
1829 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:201830 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polo5d377bd2009-08-16 14:44:141831 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1832 '8.2', '82', '8.1', '81', '8.0', '80']:
Tarek Ziadé36797272010-07-22 12:50:051833 tklib = self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171834 'tk' + version)
Tarek Ziadé36797272010-07-22 12:50:051835 tcllib = self.compiler.find_library_file(lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171836 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:411837 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:231838 # Exit the loop when we've found the Tcl/Tk libraries
1839 break
Andrew M. Kuchling00e0f212001-01-17 15:23:231840
Fredrik Lundhade711a2001-01-24 08:00:281841 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:201842 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351843 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:201844 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351845 dotversion = version
doko@ubuntu.com93df16b2012-06-30 12:32:081846 if '.' not in dotversion and "bsd" in host_platform.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351847 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1848 # but the include subdirs are named like .../include/tcl8.3.
1849 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1850 tcl_include_sub = []
1851 tk_include_sub = []
1852 for dir in inc_dirs:
1853 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1854 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1855 tk_include_sub += tcl_include_sub
1856 tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub)
1857 tk_includes = find_file('tk.h', inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:231858
Martin v. Löwise86a59a2003-05-03 08:45:511859 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:201860 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351861 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Andrew M. Kuchlingfbe73762001-01-18 18:44:201862 return
Fredrik Lundhade711a2001-01-24 08:00:281863
Andrew M. Kuchlingfbe73762001-01-18 18:44:201864 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:231865
Andrew M. Kuchlingfbe73762001-01-18 18:44:201866 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
1867 for dir in tcl_includes + tk_includes:
1868 if dir not in include_dirs:
1869 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:281870
Andrew M. Kuchlingfbe73762001-01-18 18:44:201871 # Check for various platform-specific directories
doko@ubuntu.com93df16b2012-06-30 12:32:081872 if host_platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:201873 include_dirs.append('/usr/openwin/include')
1874 added_lib_dirs.append('/usr/openwin/lib')
1875 elif os.path.exists('/usr/X11R6/include'):
1876 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:351877 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:201878 added_lib_dirs.append('/usr/X11R6/lib')
1879 elif os.path.exists('/usr/X11R5/include'):
1880 include_dirs.append('/usr/X11R5/include')
1881 added_lib_dirs.append('/usr/X11R5/lib')
1882 else:
Fredrik Lundhade711a2001-01-24 08:00:281883 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:201884 include_dirs.append('/usr/X11/include')
1885 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:231886
Jason Tishler9181c942003-02-05 15:16:171887 # If Cygwin, then verify that X is installed before proceeding
doko@ubuntu.com93df16b2012-06-30 12:32:081888 if host_platform == 'cygwin':
Jason Tishler9181c942003-02-05 15:16:171889 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1890 if x11_inc is None:
1891 return
1892
Andrew M. Kuchlingfbe73762001-01-18 18:44:201893 # Check for BLT extension
Tarek Ziadé36797272010-07-22 12:50:051894 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171895 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:201896 defs.append( ('WITH_BLT', 1) )
1897 libs.append('BLT8.0')
Tarek Ziadé36797272010-07-22 12:50:051898 elif self.compiler.find_library_file(lib_dirs + added_lib_dirs,
Tarek Ziadédd07ebb2009-07-06 13:52:171899 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:381900 defs.append( ('WITH_BLT', 1) )
1901 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:231902
Andrew M. Kuchlingfbe73762001-01-18 18:44:201903 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:461904 libs.append('tk'+ version)
1905 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:281906
doko@ubuntu.com93df16b2012-06-30 12:32:081907 if host_platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:201908 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:231909
Martin v. Löwis3db5b8c2001-07-24 06:54:011910 # Finally, link with the X11 libraries (not appropriate on cygwin)
doko@ubuntu.com93df16b2012-06-30 12:32:081911 if host_platform != "cygwin":
Martin v. Löwis3db5b8c2001-07-24 06:54:011912 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:231913
Andrew M. Kuchlingfbe73762001-01-18 18:44:201914 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1915 define_macros=[('WITH_APPINIT', 1)] + defs,
1916 include_dirs = include_dirs,
1917 libraries = libs,
1918 library_dirs = added_lib_dirs,
1919 )
1920 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:281921
Andrew M. Kuchlingfbe73762001-01-18 18:44:201922 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:231923 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:281924 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:231925 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:281926 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:231927 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:281928 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:231929
Christian Heimes78644762008-03-04 23:39:231930 def configure_ctypes_darwin(self, ext):
1931 # Darwin (OS X) uses preconfigured files, in
1932 # the Modules/_ctypes/libffi_osx directory.
Neil Schemenauer014bf282009-02-05 16:35:451933 srcdir = sysconfig.get_config_var('srcdir')
Christian Heimes78644762008-03-04 23:39:231934 ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
1935 '_ctypes', 'libffi_osx'))
1936 sources = [os.path.join(ffi_srcdir, p)
1937 for p in ['ffi.c',
Georg Brandlfcaf9102008-07-16 02:17:561938 'x86/darwin64.S',
Christian Heimes78644762008-03-04 23:39:231939 'x86/x86-darwin.S',
1940 'x86/x86-ffi_darwin.c',
1941 'x86/x86-ffi64.c',
1942 'powerpc/ppc-darwin.S',
1943 'powerpc/ppc-darwin_closure.S',
1944 'powerpc/ppc-ffi_darwin.c',
1945 'powerpc/ppc64-darwin_closure.S',
1946 ]]
1947
1948 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:051949 self.compiler.src_extensions.append('.S')
Christian Heimes78644762008-03-04 23:39:231950
1951 include_dirs = [os.path.join(ffi_srcdir, 'include'),
1952 os.path.join(ffi_srcdir, 'powerpc')]
1953 ext.include_dirs.extend(include_dirs)
1954 ext.sources.extend(sources)
1955 return True
1956
Thomas Wouters49fd7fa2006-04-21 10:40:581957 def configure_ctypes(self, ext):
1958 if not self.use_system_libffi:
doko@ubuntu.com93df16b2012-06-30 12:32:081959 if host_platform == 'darwin':
Christian Heimes78644762008-03-04 23:39:231960 return self.configure_ctypes_darwin(ext)
1961
Zachary Ware935043d2016-09-10 00:01:211962 print('warning: building with the bundled copy of libffi is'
1963 ' deprecated on this platform. It will not be'
1964 ' distributed with Python 3.7')
Neil Schemenauer014bf282009-02-05 16:35:451965 srcdir = sysconfig.get_config_var('srcdir')
Thomas Wouters49fd7fa2006-04-21 10:40:581966 ffi_builddir = os.path.join(self.build_temp, 'libffi')
1967 ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
1968 '_ctypes', 'libffi'))
1969 ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
Thomas Hellercf567c12006-03-08 19:51:581970
Thomas Wouters477c8d52006-05-27 19:21:471971 from distutils.dep_util import newer_group
1972
1973 config_sources = [os.path.join(ffi_srcdir, fname)
Thomas Wouterscf297e42007-02-23 15:07:441974 for fname in os.listdir(ffi_srcdir)
1975 if os.path.isfile(os.path.join(ffi_srcdir, fname))]
Thomas Wouters477c8d52006-05-27 19:21:471976 if self.force or newer_group(config_sources,
1977 ffi_configfile):
Thomas Wouters49fd7fa2006-04-21 10:40:581978 from distutils.dir_util import mkpath
1979 mkpath(ffi_builddir)
doko@ubuntu.com1abe1c52012-06-30 18:42:451980 config_args = [arg for arg in sysconfig.get_config_var("CONFIG_ARGS").split()
1981 if (('--host=' in arg) or ('--build=' in arg))]
Christian Heimes7dd06e12012-09-06 16:02:491982 if not self.verbose:
1983 config_args.append("-q")
Thomas Hellercf567c12006-03-08 19:51:581984
Thomas Wouters49fd7fa2006-04-21 10:40:581985 # Pass empty CFLAGS because we'll just append the resulting
1986 # CFLAGS to Python's; -g or -O2 is to be avoided.
1987 cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
1988 % (ffi_builddir, ffi_srcdir, " ".join(config_args))
Thomas Hellercf567c12006-03-08 19:51:581989
Thomas Wouters49fd7fa2006-04-21 10:40:581990 res = os.system(cmd)
1991 if res or not os.path.exists(ffi_configfile):
Guido van Rossum452bf512007-02-09 05:32:431992 print("Failed to configure _ctypes module")
Thomas Wouters49fd7fa2006-04-21 10:40:581993 return False
Thomas Hellercf567c12006-03-08 19:51:581994
Thomas Wouters49fd7fa2006-04-21 10:40:581995 fficonfig = {}
Antoine Pitrou72f4d642010-01-13 12:04:201996 with open(ffi_configfile) as f:
1997 exec(f.read(), globals(), fficonfig)
Thomas Hellercf567c12006-03-08 19:51:581998
Thomas Wouters49fd7fa2006-04-21 10:40:581999 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé36797272010-07-22 12:50:052000 self.compiler.src_extensions.append('.S')
Thomas Hellercf567c12006-03-08 19:51:582001
Thomas Wouters49fd7fa2006-04-21 10:40:582002 include_dirs = [os.path.join(ffi_builddir, 'include'),
Antoine Pitrou72f4d642010-01-13 12:04:202003 ffi_builddir,
2004 os.path.join(ffi_srcdir, 'src')]
Thomas Wouters49fd7fa2006-04-21 10:40:582005 extra_compile_args = fficonfig['ffi_cflags'].split()
2006
Antoine Pitrou72f4d642010-01-13 12:04:202007 ext.sources.extend(os.path.join(ffi_srcdir, f) for f in
2008 fficonfig['ffi_sources'])
Thomas Wouters49fd7fa2006-04-21 10:40:582009 ext.include_dirs.extend(include_dirs)
2010 ext.extra_compile_args.extend(extra_compile_args)
2011 return True
2012
2013 def detect_ctypes(self, inc_dirs, lib_dirs):
2014 self.use_system_libffi = False
2015 include_dirs = []
2016 extra_compile_args = []
Thomas Wouters0e3f5912006-08-11 14:57:122017 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:582018 sources = ['_ctypes/_ctypes.c',
2019 '_ctypes/callbacks.c',
2020 '_ctypes/callproc.c',
2021 '_ctypes/stgdict.c',
Thomas Heller864cc672010-08-08 17:58:532022 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:582023 depends = ['_ctypes/ctypes.h']
Victor Stinnerdef80722016-04-19 13:58:112024 math_libs = self.detect_math_libs()
Thomas Hellercf567c12006-03-08 19:51:582025
doko@ubuntu.com93df16b2012-06-30 12:32:082026 if host_platform == 'darwin':
Ronald Oussoren2decf222010-09-05 18:25:592027 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:582028 sources.append('_ctypes/darwin/dlfcn_simple.c')
Christian Heimes78644762008-03-04 23:39:232029 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:582030 include_dirs.append('_ctypes/darwin')
2031# XXX Is this still needed?
2032## extra_link_args.extend(['-read_only_relocs', 'warning'])
2033
doko@ubuntu.com93df16b2012-06-30 12:32:082034 elif host_platform == 'sunos5':
Thomas Wouters0e3f5912006-08-11 14:57:122035 # XXX This shouldn't be necessary; it appears that some
2036 # of the assembler code is non-PIC (i.e. it has relocations
2037 # when it shouldn't. The proper fix would be to rewrite
2038 # the assembler code to be PIC.
2039 # This only works with GCC; the Sun compiler likely refuses
2040 # this option. If you want to compile ctypes with the Sun
2041 # compiler, please research a proper solution, instead of
2042 # finding some -z option for the Sun compiler.
2043 extra_link_args.append('-mimpure-text')
2044
doko@ubuntu.com93df16b2012-06-30 12:32:082045 elif host_platform.startswith('hp-ux'):
Thomas Heller3eaaeb42008-05-23 17:26:462046 extra_link_args.append('-fPIC')
2047
Thomas Hellercf567c12006-03-08 19:51:582048 ext = Extension('_ctypes',
2049 include_dirs=include_dirs,
2050 extra_compile_args=extra_compile_args,
Thomas Wouters0e3f5912006-08-11 14:57:122051 extra_link_args=extra_link_args,
Thomas Wouters49fd7fa2006-04-21 10:40:582052 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:582053 sources=sources,
2054 depends=depends)
Victor Stinnerdef80722016-04-19 13:58:112055 # function my_sqrt() needs math library for sqrt()
Thomas Hellercf567c12006-03-08 19:51:582056 ext_test = Extension('_ctypes_test',
Victor Stinnerdef80722016-04-19 13:58:112057 sources=['_ctypes/_ctypes_test.c'],
2058 libraries=math_libs)
Thomas Hellercf567c12006-03-08 19:51:582059 self.extensions.extend([ext, ext_test])
2060
doko@ubuntu.com93df16b2012-06-30 12:32:082061 if host_platform == 'darwin':
Zachary Ware935043d2016-09-10 00:01:212062 if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
2063 return
Christian Heimes78644762008-03-04 23:39:232064 # OS X 10.5 comes with libffi.dylib; the include files are
2065 # in /usr/include/ffi
2066 inc_dirs.append('/usr/include/ffi')
Zachary Ware935043d2016-09-10 00:01:212067 elif '--without-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
2068 return
Christian Heimes78644762008-03-04 23:39:232069
Benjamin Petersond78735d2010-01-01 16:04:232070 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Klose5a204fe2010-04-21 21:47:452071 if not ffi_inc or ffi_inc[0] == '':
Benjamin Petersond78735d2010-01-01 16:04:232072 ffi_inc = find_file('ffi.h', [], inc_dirs)
Thomas Wouters49fd7fa2006-04-21 10:40:582073 if ffi_inc is not None:
2074 ffi_h = ffi_inc[0] + '/ffi.h'
Christian Heimes96b2dd52016-09-18 12:33:302075 with open(ffi_h) as f:
2076 for line in f:
2077 line = line.strip()
2078 if line.startswith(('#define LIBFFI_H',
2079 '#define ffi_wrapper_h')):
Brett Cannon9f5db072010-10-29 20:19:272080 break
Christian Heimes96b2dd52016-09-18 12:33:302081 else:
2082 ffi_inc = None
2083 print('Header file {} does not define LIBFFI_H or '
2084 'ffi_wrapper_h'.format(ffi_h))
Thomas Wouters49fd7fa2006-04-21 10:40:582085 ffi_lib = None
2086 if ffi_inc is not None:
doko@ubuntu.comae683652016-06-04 23:38:292087 for lib_name in ('ffi', 'ffi_pic'):
Tarek Ziadé36797272010-07-22 12:50:052088 if (self.compiler.find_library_file(lib_dirs, lib_name)):
Thomas Wouters49fd7fa2006-04-21 10:40:582089 ffi_lib = lib_name
2090 break
2091
2092 if ffi_inc and ffi_lib:
2093 ext.include_dirs.extend(ffi_inc)
2094 ext.libraries.append(ffi_lib)
2095 self.use_system_libffi = True
2096
Miss Islington (bot)192bff42018-02-25 12:07:362097 if sysconfig.get_config_var('HAVE_LIBDL'):
2098 # for dlopen, see bpo-32647
2099 ext.libraries.append('dl')
2100
Stefan Krah1919b7e2012-03-21 17:25:232101 def _decimal_ext(self):
Stefan Krah60187b52012-03-23 18:06:272102 extra_compile_args = []
Stefan Kraha10e2fb2012-09-01 12:21:222103 undef_macros = []
Stefan Krah60187b52012-03-23 18:06:272104 if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
2105 include_dirs = []
Stefan Krah45059eb2013-11-24 18:44:572106 libraries = [':libmpdec.so.2']
Stefan Krah60187b52012-03-23 18:06:272107 sources = ['_decimal/_decimal.c']
2108 depends = ['_decimal/docstrings.h']
2109 else:
Ned Deily458a6fb2012-04-01 09:30:462110 srcdir = sysconfig.get_config_var('srcdir')
2111 include_dirs = [os.path.abspath(os.path.join(srcdir,
2112 'Modules',
2113 '_decimal',
2114 'libmpdec'))]
Stefan Krah75c0d4f2017-02-04 13:58:502115 libraries = self.detect_math_libs()
Stefan Krah60187b52012-03-23 18:06:272116 sources = [
2117 '_decimal/_decimal.c',
2118 '_decimal/libmpdec/basearith.c',
2119 '_decimal/libmpdec/constants.c',
2120 '_decimal/libmpdec/context.c',
2121 '_decimal/libmpdec/convolute.c',
2122 '_decimal/libmpdec/crt.c',
2123 '_decimal/libmpdec/difradix2.c',
2124 '_decimal/libmpdec/fnt.c',
2125 '_decimal/libmpdec/fourstep.c',
2126 '_decimal/libmpdec/io.c',
2127 '_decimal/libmpdec/memory.c',
2128 '_decimal/libmpdec/mpdecimal.c',
2129 '_decimal/libmpdec/numbertheory.c',
2130 '_decimal/libmpdec/sixstep.c',
2131 '_decimal/libmpdec/transpose.c',
2132 ]
2133 depends = [
2134 '_decimal/docstrings.h',
2135 '_decimal/libmpdec/basearith.h',
2136 '_decimal/libmpdec/bits.h',
2137 '_decimal/libmpdec/constants.h',
2138 '_decimal/libmpdec/convolute.h',
2139 '_decimal/libmpdec/crt.h',
2140 '_decimal/libmpdec/difradix2.h',
2141 '_decimal/libmpdec/fnt.h',
2142 '_decimal/libmpdec/fourstep.h',
2143 '_decimal/libmpdec/io.h',
Stefan Krah8d013a82016-04-26 14:34:412144 '_decimal/libmpdec/mpalloc.h',
Stefan Krah60187b52012-03-23 18:06:272145 '_decimal/libmpdec/mpdecimal.h',
2146 '_decimal/libmpdec/numbertheory.h',
2147 '_decimal/libmpdec/sixstep.h',
2148 '_decimal/libmpdec/transpose.h',
2149 '_decimal/libmpdec/typearith.h',
2150 '_decimal/libmpdec/umodarith.h',
2151 ]
2152
Stefan Krah1919b7e2012-03-21 17:25:232153 config = {
2154 'x64': [('CONFIG_64','1'), ('ASM','1')],
2155 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
2156 'ansi64': [('CONFIG_64','1'), ('ANSI','1')],
2157 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
2158 'ansi32': [('CONFIG_32','1'), ('ANSI','1')],
2159 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
2160 ('LEGACY_COMPILER','1')],
2161 'universal': [('UNIVERSAL','1')]
2162 }
2163
Stefan Krah1919b7e2012-03-21 17:25:232164 cc = sysconfig.get_config_var('CC')
2165 sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
2166 machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
2167
2168 if machine:
2169 # Override automatic configuration to facilitate testing.
2170 define_macros = config[machine]
doko@ubuntu.com93df16b2012-06-30 12:32:082171 elif host_platform == 'darwin':
Stefan Krah1919b7e2012-03-21 17:25:232172 # Universal here means: build with the same options Python
2173 # was built with.
2174 define_macros = config['universal']
2175 elif sizeof_size_t == 8:
2176 if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
2177 define_macros = config['x64']
2178 elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
2179 define_macros = config['uint128']
2180 else:
2181 define_macros = config['ansi64']
2182 elif sizeof_size_t == 4:
2183 ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
2184 if ppro and ('gcc' in cc or 'clang' in cc) and \
doko@ubuntu.com93df16b2012-06-30 12:32:082185 not 'sunos' in host_platform:
Stefan Krah1919b7e2012-03-21 17:25:232186 # solaris: problems with register allocation.
2187 # icc >= 11.0 works as well.
2188 define_macros = config['ppro']
Stefan Krahce23dbc2012-09-30 19:12:532189 extra_compile_args.append('-Wno-unknown-pragmas')
Stefan Krah1919b7e2012-03-21 17:25:232190 else:
2191 define_macros = config['ansi32']
2192 else:
2193 raise DistutilsError("_decimal: unsupported architecture")
2194
2195 # Workarounds for toolchain bugs:
2196 if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
2197 # Some versions of gcc miscompile inline asm:
2198 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
2199 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
2200 extra_compile_args.append('-fno-ipa-pure-const')
2201 if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
2202 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
2203 # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2204 undef_macros.append('_FORTIFY_SOURCE')
2205
2206 # Faster version without thread local contexts:
2207 if not sysconfig.get_config_var('WITH_THREAD'):
2208 define_macros.append(('WITHOUT_THREADS', 1))
2209
2210 # Uncomment for extra functionality:
2211 #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
2212 ext = Extension (
2213 '_decimal',
2214 include_dirs=include_dirs,
Stefan Krah60187b52012-03-23 18:06:272215 libraries=libraries,
Stefan Krah1919b7e2012-03-21 17:25:232216 define_macros=define_macros,
2217 undef_macros=undef_macros,
2218 extra_compile_args=extra_compile_args,
2219 sources=sources,
2220 depends=depends
2221 )
2222 return ext
Thomas Wouters49fd7fa2006-04-21 10:40:582223
Christian Heimes12ae4072018-01-27 08:39:162224 def _detect_nis(self, inc_dirs, lib_dirs):
2225 if host_platform in {'win32', 'cygwin', 'qnx6'}:
2226 return None
2227
2228 libs = []
2229 library_dirs = []
2230 includes_dirs = []
2231
2232 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2233 # moved headers and libraries to libtirpc and libnsl. The headers
2234 # are in tircp and nsl sub directories.
2235 rpcsvc_inc = find_file(
2236 'rpcsvc/yp_prot.h', inc_dirs,
2237 [os.path.join(inc_dir, 'nsl') for inc_dir in inc_dirs]
2238 )
2239 rpc_inc = find_file(
2240 'rpc/rpc.h', inc_dirs,
2241 [os.path.join(inc_dir, 'tirpc') for inc_dir in inc_dirs]
2242 )
2243 if rpcsvc_inc is None or rpc_inc is None:
2244 # not found
2245 return None
2246 includes_dirs.extend(rpcsvc_inc)
2247 includes_dirs.extend(rpc_inc)
2248
2249 if self.compiler.find_library_file(lib_dirs, 'nsl'):
2250 libs.append('nsl')
2251 else:
2252 # libnsl-devel: check for libnsl in nsl/ subdirectory
2253 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in lib_dirs]
2254 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2255 if libnsl is not None:
2256 library_dirs.append(os.path.dirname(libnsl))
2257 libs.append('nsl')
2258
2259 if self.compiler.find_library_file(lib_dirs, 'tirpc'):
2260 libs.append('tirpc')
2261
2262 return Extension(
2263 'nis', ['nismodule.c'],
2264 libraries=libs,
2265 library_dirs=library_dirs,
2266 include_dirs=includes_dirs
2267 )
2268
2269
Andrew M. Kuchlingf52d27e2001-05-21 20:29:272270class PyBuildInstall(install):
2271 # Suppress the warning about installation into the lib_dynload
2272 # directory, which is not in sys.path when running Python during
2273 # installation:
2274 def initialize_options (self):
2275 install.initialize_options(self)
2276 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:412277
Éric Araujoe6792c12011-06-09 12:07:022278 # Customize subcommands to not install an egg-info file for Python
2279 sub_commands = [('install_lib', install.has_lib),
2280 ('install_headers', install.has_headers),
2281 ('install_scripts', install.has_scripts),
2282 ('install_data', install.has_data)]
2283
2284
Michael W. Hudson529a5052002-12-17 16:47:172285class PyBuildInstallLib(install_lib):
2286 # Do exactly what install_lib does but make sure correct access modes get
2287 # set on installed directories and files. All installed files with get
2288 # mode 644 unless they are a shared library in which case they will get
2289 # mode 755. All installed directories will get mode 755.
2290
doko@ubuntu.comd5537d02013-03-21 20:21:492291 # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
2292 shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
Michael W. Hudson529a5052002-12-17 16:47:172293
2294 def install(self):
2295 outfiles = install_lib.install(self)
Guido van Rossumcd16bf62007-06-13 18:07:492296 self.set_file_modes(outfiles, 0o644, 0o755)
2297 self.set_dir_modes(self.install_dir, 0o755)
Michael W. Hudson529a5052002-12-17 16:47:172298 return outfiles
2299
2300 def set_file_modes(self, files, defaultMode, sharedLibMode):
2301 if not self.is_chmod_supported(): return
2302 if not files: return
2303
2304 for filename in files:
2305 if os.path.islink(filename): continue
2306 mode = defaultMode
doko@ubuntu.comd5537d02013-03-21 20:21:492307 if filename.endswith(self.shlib_suffix): mode = sharedLibMode
Michael W. Hudson529a5052002-12-17 16:47:172308 log.info("changing mode of %s to %o", filename, mode)
2309 if not self.dry_run: os.chmod(filename, mode)
2310
2311 def set_dir_modes(self, dirname, mode):
2312 if not self.is_chmod_supported(): return
Amaury Forgeot d'Arc321e5332009-07-02 23:08:452313 for dirpath, dirnames, fnames in os.walk(dirname):
2314 if os.path.islink(dirpath):
2315 continue
2316 log.info("changing mode of %s to %o", dirpath, mode)
2317 if not self.dry_run: os.chmod(dirpath, mode)
Michael W. Hudson529a5052002-12-17 16:47:172318
2319 def is_chmod_supported(self):
2320 return hasattr(os, 'chmod')
2321
Georg Brandlff52f762010-12-28 09:51:432322class PyBuildScripts(build_scripts):
2323 def copy_scripts(self):
2324 outfiles, updated_files = build_scripts.copy_scripts(self)
2325 fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
2326 minoronly = '.{0[1]}'.format(sys.version_info)
2327 newoutfiles = []
2328 newupdated_files = []
2329 for filename in outfiles:
Vinay Sajip7ded1f02012-05-26 02:45:292330 if filename.endswith(('2to3', 'pyvenv')):
Georg Brandlff52f762010-12-28 09:51:432331 newfilename = filename + fullversion
2332 else:
2333 newfilename = filename + minoronly
Vinay Sajipdd917f82016-08-31 07:22:292334 log.info('renaming %s to %s', filename, newfilename)
Georg Brandlff52f762010-12-28 09:51:432335 os.rename(filename, newfilename)
2336 newoutfiles.append(newfilename)
2337 if filename in updated_files:
2338 newupdated_files.append(newfilename)
2339 return newoutfiles, newupdated_files
2340
Guido van Rossum14ee89c2003-02-20 02:52:042341SUMMARY = """
2342Python is an interpreted, interactive, object-oriented programming
2343language. It is often compared to Tcl, Perl, Scheme or Java.
2344
2345Python combines remarkable power with very clear syntax. It has
2346modules, classes, exceptions, very high level dynamic data types, and
2347dynamic typing. There are interfaces to many system calls and
2348libraries, as well as to various windowing systems (X11, Motif, Tk,
2349Mac, MFC). New built-in modules are easily written in C or C++. Python
2350is also usable as an extension language for applications that need a
2351programmable interface.
2352
2353The Python implementation is portable: it runs on many brands of UNIX,
Jesus Ceaf1af7052012-10-05 00:48:462354on Windows, DOS, Mac, Amiga... If your favorite system isn't
Guido van Rossum14ee89c2003-02-20 02:52:042355listed here, it may still be supported, if there's a C compiler for
2356it. Ask around on comp.lang.python -- or just try compiling Python
2357yourself.
2358"""
2359
2360CLASSIFIERS = """
Guido van Rossum14ee89c2003-02-20 02:52:042361Development Status :: 6 - Mature
2362License :: OSI Approved :: Python Software Foundation License
2363Natural Language :: English
2364Programming Language :: C
2365Programming Language :: Python
2366Topic :: Software Development
2367"""
2368
Andrew M. Kuchling00e0f212001-01-17 15:23:232369def main():
Andrew M. Kuchling62686692001-05-21 20:48:092370 # turn off warnings when deprecated modules are imported
2371 import warnings
2372 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:042373 setup(# PyPI Metadata (PEP 301)
2374 name = "Python",
2375 version = sys.version.split()[0],
Serhiy Storchaka885bdc42016-02-11 11:10:362376 url = "http://www.python.org/%d.%d" % sys.version_info[:2],
Guido van Rossum14ee89c2003-02-20 02:52:042377 maintainer = "Guido van Rossum and the Python community",
2378 maintainer_email = "python-dev@python.org",
2379 description = "A high-level object-oriented programming language",
2380 long_description = SUMMARY.strip(),
2381 license = "PSF license",
Guido van Rossumc1f779c2007-07-03 08:25:582382 classifiers = [x for x in CLASSIFIERS.split("\n") if x],
Guido van Rossum14ee89c2003-02-20 02:52:042383 platforms = ["Many"],
2384
2385 # Build info
Georg Brandlff52f762010-12-28 09:51:432386 cmdclass = {'build_ext': PyBuildExt,
2387 'build_scripts': PyBuildScripts,
2388 'install': PyBuildInstall,
2389 'install_lib': PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:232390 # The struct module is defined here, because build_ext won't be
2391 # called unless there's at least one extension module defined.
Thomas Wouters477c8d52006-05-27 19:21:472392 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:492393
Georg Brandlff52f762010-12-28 09:51:432394 # If you change the scripts installed here, you also need to
2395 # check the PyBuildScripts command above, and change the links
2396 # created by the bininstall target in Makefile.pre.in
Benjamin Petersondfea1922009-05-23 17:13:142397 scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
Éric Araujo859aad62012-06-24 04:07:412398 "Tools/scripts/2to3", "Tools/scripts/pyvenv"]
Andrew M. Kuchling00e0f212001-01-17 15:23:232399 )
Fredrik Lundhade711a2001-01-24 08:00:282400
Andrew M. Kuchling00e0f212001-01-17 15:23:232401# --install-platlib
2402if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:232403 main()