blob: f764223d0627ce07b35a002a49f2f293e5e173ba [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
Andrew M. Kuchling66012fe2001-01-26 21:56:584__version__ = "$Revision$"
5
Brett Cannon84667c02004-12-07 03:25:186import sys, os, imp, re, optparse
Christian Heimes8608d912008-01-25 15:52:117from glob import glob
Gregory P. Smith0902cac2008-05-27 08:40:098from platform import machine as platform_machine
Tarek Ziadé5633a802010-01-23 09:23:159import sysconfig
Michael W. Hudson529a5052002-12-17 16:47:1710
11from distutils import log
Andrew M. Kuchling8d7f0862001-02-23 16:32:3212from distutils import text_file
Marc-André Lemburg7c6fcda2001-01-26 18:03:2413from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:2314from distutils.core import Extension, setup
15from distutils.command.build_ext import build_ext
Andrew M. Kuchlingf52d27e2001-05-21 20:29:2716from distutils.command.install import install
Michael W. Hudson529a5052002-12-17 16:47:1717from distutils.command.install_lib import install_lib
Stefan Krah4d32c9c2010-06-04 09:49:2018from distutils.spawn import find_executable
Andrew M. Kuchling00e0f212001-01-17 15:23:2319
doko@python.orgd65e2ba2013-01-31 22:52:0320cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
21
22def get_platform():
23 # cross build
24 if "_PYTHON_HOST_PLATFORM" in os.environ:
25 return os.environ["_PYTHON_HOST_PLATFORM"]
26 # Get value of sys.platform
27 if sys.platform.startswith('osf1'):
28 return 'osf1'
29 return sys.platform
30host_platform = get_platform()
31
Gregory P. Smithc2fa18c2010-01-02 22:25:2932# Were we compiled --with-pydebug or with #define Py_DEBUG?
doko@python.orgd65e2ba2013-01-31 22:52:0333COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
Gregory P. Smithc2fa18c2010-01-02 22:25:2934
Andrew M. Kuchling00e0f212001-01-17 15:23:2335# This global variable is used to hold the list of modules to be disabled.
36disabled_module_list = []
37
Michael W. Hudson39230b32002-01-16 15:26:4838def add_dir_to_list(dirlist, dir):
39 """Add the directory 'dir' to the list 'dirlist' (at the front) if
40 1) 'dir' is not already in 'dirlist'
41 2) 'dir' actually exists, and is a directory."""
Ned Deilyda7f6db2019-07-01 23:15:0942 if dir is not None and dir not in dirlist:
43 if host_platform == 'darwin' and is_macosx_sdk_path(dir):
44 # If in a macOS SDK path, check relative to the SDK root
45 dir_exists = os.path.isdir(
46 os.path.join(macosx_sdk_root(), dir[1:]))
47 else:
48 dir_exists = os.path.isdir(dir)
49 if dir_exists:
50 dirlist.insert(0, dir)
Michael W. Hudson39230b32002-01-16 15:26:4851
Ned Deilyc421c662019-06-20 05:59:5452MACOS_SDK_ROOT = None
53
Ronald Oussoren593e4ca2010-06-03 09:47:2154def macosx_sdk_root():
Ned Deilyc421c662019-06-20 05:59:5455 """Return the directory of the current macOS SDK.
56
57 If no SDK was explicitly configured, call the compiler to find which
58 include files paths are being searched by default. Use '/' if the
59 compiler is searching /usr/include (meaning system header files are
60 installed) or use the root of an SDK if that is being searched.
61 (The SDK may be supplied via Xcode or via the Command Line Tools).
62 The SDK paths used by Apple-supplied tool chains depend on the
63 setting of various variables; see the xcrun man page for more info.
Ronald Oussoren593e4ca2010-06-03 09:47:2164 """
Ned Deilyc421c662019-06-20 05:59:5465 global MACOS_SDK_ROOT
66
67 # If already called, return cached result.
68 if MACOS_SDK_ROOT:
69 return MACOS_SDK_ROOT
70
Ronald Oussoren593e4ca2010-06-03 09:47:2171 cflags = sysconfig.get_config_var('CFLAGS')
72 m = re.search(r'-isysroot\s+(\S+)', cflags)
Ned Deilyc421c662019-06-20 05:59:5473 if m is not None:
74 MACOS_SDK_ROOT = m.group(1)
Ronald Oussoren593e4ca2010-06-03 09:47:2175 else:
Ned Deilyc421c662019-06-20 05:59:5476 MACOS_SDK_ROOT = '/'
77 cc = sysconfig.get_config_var('CC')
78 tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid()
79 try:
80 os.unlink(tmpfile)
81 except:
82 pass
83 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
84 in_incdirs = False
85 try:
86 if ret >> 8 == 0:
87 with open(tmpfile) as fp:
88 for line in fp.readlines():
89 if line.startswith("#include <...>"):
90 in_incdirs = True
91 elif line.startswith("End of search list"):
92 in_incdirs = False
93 elif in_incdirs:
94 line = line.strip()
95 if line == '/usr/include':
96 MACOS_SDK_ROOT = '/'
97 elif line.endswith(".sdk/usr/include"):
98 MACOS_SDK_ROOT = line[:-12]
99 finally:
100 os.unlink(tmpfile)
101
102 return MACOS_SDK_ROOT
Ronald Oussoren593e4ca2010-06-03 09:47:21103
104def is_macosx_sdk_path(path):
105 """
106 Returns True if 'path' can be located in an OSX SDK
107 """
Ned Deilyd8ec4642012-07-30 11:07:49108 return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
109 or path.startswith('/System/')
110 or path.startswith('/Library/') )
Ronald Oussoren593e4ca2010-06-03 09:47:21111
Andrew M. Kuchlingfbe73762001-01-18 18:44:20112def find_file(filename, std_dirs, paths):
113 """Searches for the directory where a given file is located,
114 and returns a possibly-empty list of additional directories, or None
115 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28116
Andrew M. Kuchlingfbe73762001-01-18 18:44:20117 'filename' is the name of a file, such as readline.h or libcrypto.a.
118 'std_dirs' is the list of standard system directories; if the
119 file is found in one of them, no additional directives are needed.
120 'paths' is a list of additional locations to check; if the file is
121 found in one of them, the resulting list will contain the directory.
122 """
doko@python.orgd65e2ba2013-01-31 22:52:03123 if host_platform == 'darwin':
Ronald Oussoren593e4ca2010-06-03 09:47:21124 # Honor the MacOSX SDK setting when one was specified.
125 # An SDK is a directory with the same structure as a real
126 # system, but with only header files and libraries.
127 sysroot = macosx_sdk_root()
Andrew M. Kuchlingfbe73762001-01-18 18:44:20128
129 # Check the standard locations
130 for dir in std_dirs:
131 f = os.path.join(dir, filename)
Ronald Oussoren593e4ca2010-06-03 09:47:21132
doko@python.orgd65e2ba2013-01-31 22:52:03133 if host_platform == 'darwin' and is_macosx_sdk_path(dir):
Ronald Oussoren593e4ca2010-06-03 09:47:21134 f = os.path.join(sysroot, dir[1:], filename)
135
Andrew M. Kuchlingfbe73762001-01-18 18:44:20136 if os.path.exists(f): return []
137
138 # Check the additional directories
139 for dir in paths:
140 f = os.path.join(dir, filename)
Ronald Oussoren593e4ca2010-06-03 09:47:21141
doko@python.orgd65e2ba2013-01-31 22:52:03142 if host_platform == 'darwin' and is_macosx_sdk_path(dir):
Ronald Oussoren593e4ca2010-06-03 09:47:21143 f = os.path.join(sysroot, dir[1:], filename)
144
Andrew M. Kuchlingfbe73762001-01-18 18:44:20145 if os.path.exists(f):
146 return [dir]
147
148 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23149 return None
150
Andrew M. Kuchlingfbe73762001-01-18 18:44:20151def find_library_file(compiler, libname, std_dirs, paths):
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46152 result = compiler.find_library_file(std_dirs + paths, libname)
153 if result is None:
154 return None
Fredrik Lundhade711a2001-01-24 08:00:28155
doko@python.orgd65e2ba2013-01-31 22:52:03156 if host_platform == 'darwin':
Ronald Oussoren593e4ca2010-06-03 09:47:21157 sysroot = macosx_sdk_root()
158
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46159 # Check whether the found file is in one of the standard directories
160 dirname = os.path.dirname(result)
161 for p in std_dirs:
162 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57163 p = p.rstrip(os.sep)
Ronald Oussoren593e4ca2010-06-03 09:47:21164
doko@python.orgd65e2ba2013-01-31 22:52:03165 if host_platform == 'darwin' and is_macosx_sdk_path(p):
Ned Deily83abccb2016-02-24 13:55:24166 # Note that, as of Xcode 7, Apple SDKs may contain textual stub
167 # libraries with .tbd extensions rather than the normal .dylib
168 # shared libraries installed in /. The Apple compiler tool
169 # chain handles this transparently but it can cause problems
170 # for programs that are being built with an SDK and searching
171 # for specific libraries. Distutils find_library_file() now
172 # knows to also search for and return .tbd files. But callers
173 # of find_library_file need to keep in mind that the base filename
174 # of the returned SDK library file might have a different extension
175 # from that of the library file installed on the running system,
176 # for example:
177 # /Applications/Xcode.app/Contents/Developer/Platforms/
178 # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
179 # usr/lib/libedit.tbd
180 # vs
181 # /usr/lib/libedit.dylib
Ronald Oussoren593e4ca2010-06-03 09:47:21182 if os.path.join(sysroot, p[1:]) == dirname:
183 return [ ]
184
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46185 if p == dirname:
186 return [ ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20187
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46188 # Otherwise, it must have been in one of the additional directories,
189 # so we have to figure out which one.
190 for p in paths:
191 # Ensure path doesn't end with path separator
Skip Montanaro9f5178a2003-05-06 20:59:57192 p = p.rstrip(os.sep)
Ronald Oussoren593e4ca2010-06-03 09:47:21193
doko@python.orgd65e2ba2013-01-31 22:52:03194 if host_platform == 'darwin' and is_macosx_sdk_path(p):
Ronald Oussoren593e4ca2010-06-03 09:47:21195 if os.path.join(sysroot, p[1:]) == dirname:
196 return [ p ]
197
Andrew M. Kuchlinga246d9f2002-11-27 13:43:46198 if p == dirname:
199 return [p]
200 else:
201 assert False, "Internal error: Path not found in std_dirs or paths"
Tim Peters2c60f7a2003-01-29 03:49:43202
Andrew M. Kuchling00e0f212001-01-17 15:23:23203def module_enabled(extlist, modname):
204 """Returns whether the module 'modname' is present in the list
205 of extensions 'extlist'."""
206 extlist = [ext for ext in extlist if ext.name == modname]
207 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28208
Jack Jansen144ebcc2001-08-05 22:31:19209def find_module_file(module, dirlist):
210 """Find a module in a set of possible folders. If it is not found
211 return the unadorned filename"""
212 list = find_file(module, [], dirlist)
213 if not list:
214 return module
215 if len(list) > 1:
Guido van Rossum12471d62003-02-20 02:11:43216 log.info("WARNING: multiple copies of %s found"%module)
Jack Jansen144ebcc2001-08-05 22:31:19217 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41218
Andrew M. Kuchling00e0f212001-01-17 15:23:23219class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28220
Skip Montanarod1287322007-03-06 15:41:38221 def __init__(self, dist):
222 build_ext.__init__(self, dist)
223 self.failed = []
224
Andrew M. Kuchling00e0f212001-01-17 15:23:23225 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23226
227 # Detect which modules should be compiled
Skip Montanarod1287322007-03-06 15:41:38228 missing = self.detect_modules()
Andrew M. Kuchling00e0f212001-01-17 15:23:23229
230 # Remove modules that are present on the disabled list
Christian Heimesb222bbc2008-01-18 09:51:43231 extensions = [ext for ext in self.extensions
232 if ext.name not in disabled_module_list]
233 # move ctypes to the end, it depends on other modules
234 ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
235 if "_ctypes" in ext_map:
236 ctypes = extensions.pop(ext_map["_ctypes"])
237 extensions.append(ctypes)
238 self.extensions = extensions
Fredrik Lundhade711a2001-01-24 08:00:28239
Andrew M. Kuchling00e0f212001-01-17 15:23:23240 # Fix up the autodetected modules, prefixing all the source files
241 # with Modules/ and adding Python's include directory to the path.
242 (srcdir,) = sysconfig.get_config_vars('srcdir')
Guido van Rossume0fea6c2002-10-14 20:48:09243 if not srcdir:
244 # Maybe running on Windows but not using CYGWIN?
245 raise ValueError("No source directory; cannot proceed.")
Neil Schemenauer0189ddc2009-02-06 00:21:55246 srcdir = os.path.abspath(srcdir)
Neil Schemenauerc59c5f32009-02-05 16:32:29247 moddirlist = [os.path.join(srcdir, 'Modules')]
Michael W. Hudson5b109102002-01-23 15:04:41248
Jack Jansen144ebcc2001-08-05 22:31:19249 # Platform-dependent module source and include directories
Neil Schemenauer38870cb2009-02-05 22:14:04250 incdirlist = []
doko@python.orgd65e2ba2013-01-31 22:52:03251
252 if host_platform == 'darwin' and ("--disable-toolbox-glue" not in
Brett Cannoncc8a4f62004-08-26 01:44:07253 sysconfig.get_config_var("CONFIG_ARGS")):
Jack Jansen144ebcc2001-08-05 22:31:19254 # Mac OS X also includes some mac-specific modules
Neil Schemenauerc59c5f32009-02-05 16:32:29255 macmoddir = os.path.join(srcdir, 'Mac/Modules')
Jack Jansen144ebcc2001-08-05 22:31:19256 moddirlist.append(macmoddir)
Neil Schemenauer38870cb2009-02-05 22:14:04257 incdirlist.append(os.path.join(srcdir, 'Mac/Include'))
Andrew M. Kuchling00e0f212001-01-17 15:23:23258
Andrew M. Kuchling3da989c2001-02-28 22:49:26259 # Fix up the paths for scripts, too
260 self.distribution.scripts = [os.path.join(srcdir, filename)
261 for filename in self.distribution.scripts]
262
Christian Heimes8608d912008-01-25 15:52:11263 # Python header files
Neil Schemenauerc59c5f32009-02-05 16:32:29264 headers = [sysconfig.get_config_h_filename()]
Stefan Krah4666ebd2012-02-29 13:17:18265 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20266 for ext in self.extensions[:]:
Jack Jansen144ebcc2001-08-05 22:31:19267 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23268 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11269 if ext.depends is not None:
Neil Schemenauerc59c5f32009-02-05 16:32:29270 ext.depends = [find_module_file(filename, moddirlist)
Jeremy Hylton340043e2002-06-13 17:38:11271 for filename in ext.depends]
Christian Heimes8608d912008-01-25 15:52:11272 else:
273 ext.depends = []
274 # re-compile extensions if a header file has been changed
275 ext.depends.extend(headers)
276
Neil Schemenauer38870cb2009-02-05 22:14:04277 # platform specific include directories
278 ext.include_dirs.extend(incdirlist)
279
Andrew M. Kuchlinge7c87322001-01-19 16:58:21280 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20281 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21282 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20283 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34284
Ronald Oussoren9545a232010-05-05 19:09:31285 # Parse Modules/Setup and Modules/Setup.local to figure out which
286 # modules are turned on in the file.
287 remove_modules = []
288 for filename in ('Modules/Setup', 'Modules/Setup.local'):
289 input = text_file.TextFile(filename, join_lines=1)
290 while 1:
291 line = input.readline()
292 if not line: break
293 line = line.split()
294 remove_modules.append(line[0])
295 input.close()
Tim Peters1b27f862005-12-30 18:42:42296
Ronald Oussoren9545a232010-05-05 19:09:31297 for ext in self.extensions[:]:
298 if ext.name in remove_modules:
299 self.extensions.remove(ext)
Michael W. Hudson5b109102002-01-23 15:04:41300
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34301 # When you run "make CC=altcc" or something similar, you really want
302 # those environment variables passed into the setup.py phase. Here's
303 # a small set of useful ones.
304 compiler = os.environ.get('CC')
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34305 args = {}
306 # unfortunately, distutils doesn't let us provide separate C and C++
307 # compilers
308 if compiler is not None:
Martin v. Löwisd7c795e2005-04-25 07:14:03309 (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
310 args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
Tarek Ziadé35a3f572010-03-05 00:29:38311 self.compiler.set_executables(**args)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34312
Andrew M. Kuchling00e0f212001-01-17 15:23:23313 build_ext.build_extensions(self)
314
Berker Peksag1b4b7af2014-09-27 19:55:10315 longest = 0
316 if self.extensions:
317 longest = max([len(e.name) for e in self.extensions])
Skip Montanarod1287322007-03-06 15:41:38318 if self.failed:
319 longest = max(longest, max([len(name) for name in self.failed]))
320
321 def print_three_column(lst):
Georg Brandle95cf1c2007-03-06 17:49:14322 lst.sort(key=str.lower)
Skip Montanarod1287322007-03-06 15:41:38323 # guarantee zip() doesn't drop anything
324 while len(lst) % 3:
325 lst.append("")
326 for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
327 print "%-*s %-*s %-*s" % (longest, e, longest, f,
328 longest, g)
Skip Montanarod1287322007-03-06 15:41:38329
330 if missing:
331 print
Georg Brandl40f982f2008-12-28 11:58:49332 print ("Python build finished, but the necessary bits to build "
333 "these modules were not found:")
Skip Montanarod1287322007-03-06 15:41:38334 print_three_column(missing)
Jeffrey Yasskin87997562007-08-22 23:14:27335 print ("To find the necessary bits, look in setup.py in"
336 " detect_modules() for the module's name.")
337 print
Skip Montanarod1287322007-03-06 15:41:38338
339 if self.failed:
340 failed = self.failed[:]
341 print
342 print "Failed to build these modules:"
343 print_three_column(failed)
Jeffrey Yasskin87997562007-08-22 23:14:27344 print
Skip Montanarod1287322007-03-06 15:41:38345
Marc-André Lemburg7c6fcda2001-01-26 18:03:24346 def build_extension(self, ext):
347
Thomas Hellereba43c12006-04-07 19:04:09348 if ext.name == '_ctypes':
Thomas Heller795246c2006-04-07 19:27:56349 if not self.configure_ctypes(ext):
350 return
Thomas Hellereba43c12006-04-07 19:04:09351
Marc-André Lemburg7c6fcda2001-01-26 18:03:24352 try:
353 build_ext.build_extension(self, ext)
354 except (CCompilerError, DistutilsError), why:
355 self.announce('WARNING: building of extension "%s" failed: %s' %
356 (ext.name, sys.exc_info()[1]))
Skip Montanarod1287322007-03-06 15:41:38357 self.failed.append(ext.name)
Andrew M. Kuchling62686692001-05-21 20:48:09358 return
Jack Jansenf49c6f92001-11-01 14:44:15359 # Workaround for Mac OS X: The Carbon-based modules cannot be
360 # reliably imported into a command-line Python
361 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41362 self.announce(
363 'WARNING: skipping import check for Carbon-based "%s"' %
364 ext.name)
365 return
Ronald Oussoren5640ce22008-06-05 12:58:24366
doko@python.orgd65e2ba2013-01-31 22:52:03367 if host_platform == 'darwin' and (
Ronald Oussoren5640ce22008-06-05 12:58:24368 sys.maxint > 2**32 and '-arch' in ext.extra_link_args):
369 # Don't bother doing an import check when an extension was
370 # build with an explicit '-arch' flag on OSX. That's currently
371 # only used to build 32-bit only extensions in a 4-way
372 # universal build and loading 32-bit code into a 64-bit
373 # process will fail.
374 self.announce(
375 'WARNING: skipping import check for "%s"' %
376 ext.name)
377 return
378
Jason Tishler24cf7762002-05-22 16:46:15379 # Workaround for Cygwin: Cygwin currently has fork issues when many
380 # modules have been imported
doko@python.orgd65e2ba2013-01-31 22:52:03381 if host_platform == 'cygwin':
Jason Tishler24cf7762002-05-22 16:46:15382 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
383 % ext.name)
384 return
Michael W. Hudsonaf142892002-01-23 15:07:46385 ext_filename = os.path.join(
386 self.build_lib,
387 self.get_ext_filename(self.get_ext_fullname(ext.name)))
doko@python.orgd65e2ba2013-01-31 22:52:03388
389 # Don't try to load extensions for cross builds
390 if cross_compiling:
391 return
392
Andrew M. Kuchling62686692001-05-21 20:48:09393 try:
Michael W. Hudsonaf142892002-01-23 15:07:46394 imp.load_dynamic(ext.name, ext_filename)
Neal Norwitz6e2d1c72003-02-28 17:39:42395 except ImportError, why:
Skip Montanarod1287322007-03-06 15:41:38396 self.failed.append(ext.name)
Neal Norwitz6e2d1c72003-02-28 17:39:42397 self.announce('*** WARNING: renaming "%s" since importing it'
398 ' failed: %s' % (ext.name, why), level=3)
399 assert not self.inplace
400 basename, tail = os.path.splitext(ext_filename)
401 newname = basename + "_failed" + tail
402 if os.path.exists(newname):
403 os.remove(newname)
404 os.rename(ext_filename, newname)
405
406 # XXX -- This relies on a Vile HACK in
407 # distutils.command.build_ext.build_extension(). The
408 # _built_objects attribute is stored there strictly for
409 # use here.
410 # If there is a failure, _built_objects may not be there,
411 # so catch the AttributeError and move on.
412 try:
413 for filename in self._built_objects:
414 os.remove(filename)
415 except AttributeError:
416 self.announce('unable to remove files (ignored)')
Neal Norwitz3f5fcc82003-02-28 17:21:39417 except:
Neal Norwitz3f5fcc82003-02-28 17:21:39418 exc_type, why, tb = sys.exc_info()
Neal Norwitz6e2d1c72003-02-28 17:39:42419 self.announce('*** WARNING: importing extension "%s" '
420 'failed with %s: %s' % (ext.name, exc_type, why),
421 level=3)
Skip Montanarod1287322007-03-06 15:41:38422 self.failed.append(ext.name)
Fred Drake9028d0a2001-12-06 22:59:54423
Barry Warsawffc9caf2011-04-07 15:28:11424 def add_multiarch_paths(self):
425 # Debian/Ubuntu multiarch support.
426 # https://wiki.ubuntu.com/MultiarchSpec
doko@ubuntu.com3d2fc152012-09-21 11:51:40427 cc = sysconfig.get_config_var('CC')
428 tmpfile = os.path.join(self.build_temp, 'multiarch')
429 if not os.path.exists(self.build_temp):
430 os.makedirs(self.build_temp)
431 ret = os.system(
432 '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
433 multiarch_path_component = ''
434 try:
435 if ret >> 8 == 0:
436 with open(tmpfile) as fp:
437 multiarch_path_component = fp.readline().strip()
438 finally:
439 os.unlink(tmpfile)
440
441 if multiarch_path_component != '':
442 add_dir_to_list(self.compiler.library_dirs,
443 '/usr/lib/' + multiarch_path_component)
444 add_dir_to_list(self.compiler.include_dirs,
445 '/usr/include/' + multiarch_path_component)
446 return
447
Barry Warsawffc9caf2011-04-07 15:28:11448 if not find_executable('dpkg-architecture'):
449 return
doko@python.orgd65e2ba2013-01-31 22:52:03450 opt = ''
451 if cross_compiling:
452 opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
Barry Warsawffc9caf2011-04-07 15:28:11453 tmpfile = os.path.join(self.build_temp, 'multiarch')
454 if not os.path.exists(self.build_temp):
455 os.makedirs(self.build_temp)
456 ret = os.system(
doko@python.orgd65e2ba2013-01-31 22:52:03457 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
458 (opt, tmpfile))
Barry Warsawffc9caf2011-04-07 15:28:11459 try:
460 if ret >> 8 == 0:
461 with open(tmpfile) as fp:
462 multiarch_path_component = fp.readline().strip()
463 add_dir_to_list(self.compiler.library_dirs,
464 '/usr/lib/' + multiarch_path_component)
465 add_dir_to_list(self.compiler.include_dirs,
466 '/usr/include/' + multiarch_path_component)
467 finally:
468 os.unlink(tmpfile)
469
doko@python.orgd65e2ba2013-01-31 22:52:03470 def add_gcc_paths(self):
471 gcc = sysconfig.get_config_var('CC')
472 tmpfile = os.path.join(self.build_temp, 'gccpaths')
473 if not os.path.exists(self.build_temp):
474 os.makedirs(self.build_temp)
475 ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
476 is_gcc = False
477 in_incdirs = False
478 inc_dirs = []
479 lib_dirs = []
480 try:
481 if ret >> 8 == 0:
482 with open(tmpfile) as fp:
483 for line in fp.readlines():
484 if line.startswith("gcc version"):
485 is_gcc = True
486 elif line.startswith("#include <...>"):
487 in_incdirs = True
488 elif line.startswith("End of search list"):
489 in_incdirs = False
490 elif is_gcc and line.startswith("LIBRARY_PATH"):
491 for d in line.strip().split("=")[1].split(":"):
492 d = os.path.normpath(d)
493 if '/gcc/' not in d:
494 add_dir_to_list(self.compiler.library_dirs,
495 d)
496 elif is_gcc and in_incdirs and '/gcc/' not in line:
497 add_dir_to_list(self.compiler.include_dirs,
498 line.strip())
499 finally:
500 os.unlink(tmpfile)
501
Andrew M. Kuchling00e0f212001-01-17 15:23:23502 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28503 # Ensure that /usr/local is always used
Ned Deily61667092013-05-16 01:00:45504 if not cross_compiling:
505 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
506 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
507 if cross_compiling:
508 self.add_gcc_paths()
Barry Warsawffc9caf2011-04-07 15:28:11509 self.add_multiarch_paths()
Michael W. Hudson39230b32002-01-16 15:26:48510
Brett Cannon516592f2004-12-07 00:42:59511 # Add paths specified in the environment variables LDFLAGS and
Brett Cannon4810eb92004-12-31 08:11:21512 # CPPFLAGS for header and library files.
Brett Cannon5399c6d2004-12-18 20:48:09513 # We must get the values from the Makefile and not the environment
514 # directly since an inconsistently reproducible issue comes up where
515 # the environment variable is not set even though the value were passed
Brett Cannon4810eb92004-12-31 08:11:21516 # into configure and stored in the Makefile (issue found on OS X 10.3).
Brett Cannon516592f2004-12-07 00:42:59517 for env_var, arg_name, dir_list in (
Tarek Ziadé35a3f572010-03-05 00:29:38518 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
519 ('LDFLAGS', '-L', self.compiler.library_dirs),
520 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
Brett Cannon5399c6d2004-12-18 20:48:09521 env_val = sysconfig.get_config_var(env_var)
Brett Cannon516592f2004-12-07 00:42:59522 if env_val:
Brett Cannon4810eb92004-12-31 08:11:21523 # To prevent optparse from raising an exception about any
Skip Montanaroa46ed912008-10-07 02:02:00524 # options in env_val that it doesn't know about we strip out
Brett Cannon4810eb92004-12-31 08:11:21525 # all double dashes and any dashes followed by a character
526 # that is not for the option we are dealing with.
527 #
528 # Please note that order of the regex is important! We must
529 # strip out double-dashes first so that we don't end up with
530 # substituting "--Long" to "-Long" and thus lead to "ong" being
531 # used for a library directory.
Georg Brandl915c87d2007-08-24 11:47:37532 env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
533 ' ', env_val)
Brett Cannon84667c02004-12-07 03:25:18534 parser = optparse.OptionParser()
Brett Cannon4810eb92004-12-31 08:11:21535 # Make sure that allowing args interspersed with options is
536 # allowed
537 parser.allow_interspersed_args = True
538 parser.error = lambda msg: None
Brett Cannon84667c02004-12-07 03:25:18539 parser.add_option(arg_name, dest="dirs", action="append")
540 options = parser.parse_args(env_val.split())[0]
Brett Cannon44837712005-01-02 21:54:07541 if options.dirs:
Brett Cannon861e3962008-02-03 02:08:45542 for directory in reversed(options.dirs):
Brett Cannon44837712005-01-02 21:54:07543 add_dir_to_list(dir_list, directory)
Skip Montanarodecc6a42003-01-01 20:07:49544
Ronald Oussoren24215252010-10-20 13:11:46545 if os.path.normpath(sys.prefix) != '/usr' \
546 and not sysconfig.get_config_var('PYTHONFRAMEWORK'):
547 # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
548 # (PYTHONFRAMEWORK is set) to avoid # linking problems when
549 # building a framework with different architectures than
550 # the one that is currently installed (issue #7473)
Tarek Ziadé35a3f572010-03-05 00:29:38551 add_dir_to_list(self.compiler.library_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50552 sysconfig.get_config_var("LIBDIR"))
Tarek Ziadé35a3f572010-03-05 00:29:38553 add_dir_to_list(self.compiler.include_dirs,
Michael W. Hudson90b8e4d2002-08-02 13:55:50554 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20555
Martin v. Löwis339d0f72001-08-17 18:39:25556 try:
557 have_unicode = unicode
558 except NameError:
559 have_unicode = 0
560
Andrew M. Kuchlingfbe73762001-01-18 18:44:20561 # lib_dirs and inc_dirs are used to search for files;
562 # if a file is found in one of those directories, it can
563 # be assumed that no additional -I,-L directives are needed.
doko@python.orgd65e2ba2013-01-31 22:52:03564 inc_dirs = self.compiler.include_dirs[:]
565 lib_dirs = self.compiler.library_dirs[:]
566 if not cross_compiling:
567 for d in (
568 '/usr/include',
569 ):
570 add_dir_to_list(inc_dirs, d)
571 for d in (
572 '/lib64', '/usr/lib64',
573 '/lib', '/usr/lib',
574 ):
575 add_dir_to_list(lib_dirs, d)
Andrew M. Kuchling00e0f212001-01-17 15:23:23576 exts = []
Skip Montanarod1287322007-03-06 15:41:38577 missing = []
Andrew M. Kuchling00e0f212001-01-17 15:23:23578
Brett Cannon4454a1f2005-04-15 20:32:39579 config_h = sysconfig.get_config_h_filename()
580 config_h_vars = sysconfig.parse_config_h(open(config_h))
581
Neil Schemenauerc59c5f32009-02-05 16:32:29582 srcdir = sysconfig.get_config_var('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41583
Martin v. Löwisf90ae202002-06-11 06:22:31584 # Check for AtheOS which has libraries in non-standard locations
doko@python.orgd65e2ba2013-01-31 22:52:03585 if host_platform == 'atheos':
Martin v. Löwisf90ae202002-06-11 06:22:31586 lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
587 lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
588 inc_dirs += ['/system/include', '/atheos/autolnk/include']
589 inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
590
Andrew M. Kuchling7883dc82003-10-24 18:26:26591 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
doko@python.orgd65e2ba2013-01-31 22:52:03592 if host_platform in ['osf1', 'unixware7', 'openunix8']:
Skip Montanaro22e00c42003-05-06 20:43:34593 lib_dirs += ['/usr/ccs/lib']
594
Charles-François Natali0d3db3a2012-04-12 17:11:54595 # HP-UX11iv3 keeps files in lib/hpux folders.
doko@python.orgd65e2ba2013-01-31 22:52:03596 if host_platform == 'hp-ux11':
Charles-François Natali0d3db3a2012-04-12 17:11:54597 lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
598
doko@python.orgd65e2ba2013-01-31 22:52:03599 if host_platform == 'darwin':
Ronald Oussoren39be38c2006-05-26 11:38:39600 # This should work on any unixy platform ;-)
601 # If the user has bothered specifying additional -I and -L flags
602 # in OPT and LDFLAGS we might as well use them here.
603 # NOTE: using shlex.split would technically be more correct, but
604 # also gives a bootstrap problem. Let's hope nobody uses directories
605 # with whitespace in the name to store libraries.
606 cflags, ldflags = sysconfig.get_config_vars(
607 'CFLAGS', 'LDFLAGS')
608 for item in cflags.split():
609 if item.startswith('-I'):
610 inc_dirs.append(item[2:])
611
612 for item in ldflags.split():
613 if item.startswith('-L'):
614 lib_dirs.append(item[2:])
615
Fredrik Lundhade711a2001-01-24 08:00:28616 # Check for MacOS X, which doesn't need libm.a at all
617 math_libs = ['m']
doko@python.orgd65e2ba2013-01-31 22:52:03618 if host_platform in ['darwin', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28619 math_libs = []
Michael W. Hudson5b109102002-01-23 15:04:41620
Andrew M. Kuchling00e0f212001-01-17 15:23:23621 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
622
623 #
624 # The following modules are all pretty straightforward, and compile
625 # on pretty much any POSIXish platform.
626 #
Fredrik Lundhade711a2001-01-24 08:00:28627
Andrew M. Kuchling00e0f212001-01-17 15:23:23628 # Some modules that are normally always on:
Georg Brandlfa8fa0c2010-08-21 13:05:38629 #exts.append( Extension('_weakref', ['_weakref.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23630
631 # array objects
632 exts.append( Extension('array', ['arraymodule.c']) )
Martin Panter83e9b572016-02-03 05:19:44633
634 shared_math = 'Modules/_math.o'
Andrew M. Kuchling00e0f212001-01-17 15:23:23635 # complex math library functions
Martin Panter83e9b572016-02-03 05:19:44636 exts.append( Extension('cmath', ['cmathmodule.c'],
637 extra_objects=[shared_math],
638 depends=['_math.h', shared_math],
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11639 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23640 # math library functions, e.g. sin()
Martin Panter83e9b572016-02-03 05:19:44641 exts.append( Extension('math', ['mathmodule.c'],
642 extra_objects=[shared_math],
643 depends=['_math.h', shared_math],
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11644 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23645 # fast string operations implemented in C
646 exts.append( Extension('strop', ['stropmodule.c']) )
647 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11648 exts.append( Extension('time', ['timemodule.c'],
649 libraries=math_libs) )
Brett Cannon057e7202004-06-24 01:38:47650 exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
Guido van Rossuma29d5082002-12-16 20:31:57651 libraries=math_libs) )
Neal Norwitz0d2192b2008-03-23 06:13:25652 # fast iterator tools implemented in C
653 exts.append( Extension("itertools", ["itertoolsmodule.c"]) )
Eric Smitha73fbe72008-02-23 03:09:44654 # code that will be builtins in the future, but conflict with the
655 # current builtins
656 exts.append( Extension('future_builtins', ['future_builtins.c']) )
Raymond Hettinger40f62172002-12-29 23:03:38657 # random number generator implemented in C
Tim Peters2c60f7a2003-01-29 03:49:43658 exts.append( Extension("_random", ["_randommodule.c"]) )
Raymond Hettinger756b3f32004-01-29 06:37:52659 # high-performance collections
Raymond Hettingereb979882007-02-28 18:37:52660 exts.append( Extension("_collections", ["_collectionsmodule.c"]) )
Raymond Hettinger0c410272004-01-05 10:13:35661 # bisect
662 exts.append( Extension("_bisect", ["_bisectmodule.c"]) )
Raymond Hettingerb3af1812003-11-08 10:24:38663 # heapq
Raymond Hettingerc46cb2a2004-04-19 19:06:21664 exts.append( Extension("_heapq", ["_heapqmodule.c"]) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23665 # operator.add() and similar goodies
666 exts.append( Extension('operator', ['operator.c']) )
Antoine Pitrou19690592009-06-12 20:14:08667 # Python 3.1 _io library
668 exts.append( Extension("_io",
669 ["_io/bufferedio.c", "_io/bytesio.c", "_io/fileio.c",
670 "_io/iobase.c", "_io/_iomodule.c", "_io/stringio.c", "_io/textio.c"],
671 depends=["_io/_iomodule.h"], include_dirs=["Modules/_io"]))
Nick Coghlanc649ec52006-05-29 12:43:05672 # _functools
673 exts.append( Extension("_functools", ["_functoolsmodule.c"]) )
Brett Cannon4b964f92008-05-05 20:21:38674 # _json speedups
675 exts.append( Extension("_json", ["_json.c"]) )
Marc-André Lemburg261b8e22001-02-02 12:12:44676 # Python C API test module
Mark Dickinsond155bbf2009-02-10 16:17:16677 exts.append( Extension('_testcapi', ['_testcapimodule.c'],
678 depends=['testcapi_long.h']) )
Armin Rigoa871ef22006-02-08 12:53:56679 # profilers (_lsprof is for cProfile.py)
680 exts.append( Extension('_hotshot', ['_hotshot.c']) )
681 exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23682 # static Unicode character database
Martin v. Löwis339d0f72001-08-17 18:39:25683 if have_unicode:
684 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Skip Montanarod1287322007-03-06 15:41:38685 else:
686 missing.append('unicodedata')
Andrew M. Kuchling00e0f212001-01-17 15:23:23687 # access to ISO C locale support
Martin v. Löwis19d17342003-06-14 21:03:05688 data = open('pyconfig.h').read()
689 m = re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*", data)
690 if m is not None:
Jason Tishlerd28216b2002-08-14 11:13:52691 locale_libs = ['intl']
692 else:
693 locale_libs = []
doko@python.orgd65e2ba2013-01-31 22:52:03694 if host_platform == 'darwin':
Jack Jansen84b74472004-07-15 19:56:25695 locale_extra_link_args = ['-framework', 'CoreFoundation']
696 else:
697 locale_extra_link_args = []
Tim Peterse6ddc8b2004-07-18 05:56:09698
Jack Jansen84b74472004-07-15 19:56:25699
Jason Tishlerd28216b2002-08-14 11:13:52700 exts.append( Extension('_locale', ['_localemodule.c'],
Jack Jansen84b74472004-07-15 19:56:25701 libraries=locale_libs,
702 extra_link_args=locale_extra_link_args) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23703
704 # Modules with some UNIX dependencies -- on by default:
705 # (If you have a really backward UNIX, select and socket may not be
706 # supported...)
707
708 # fcntl(2) and ioctl(2)
Antoine Pitrou85729812010-09-07 14:55:24709 libs = []
710 if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
711 # May be necessary on AIX for flock function
712 libs = ['bsd']
713 exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) )
Ronald Oussoren9545a232010-05-05 19:09:31714 # pwd(3)
715 exts.append( Extension('pwd', ['pwdmodule.c']) )
716 # grp(3)
717 exts.append( Extension('grp', ['grpmodule.c']) )
718 # spwd, shadow passwords
719 if (config_h_vars.get('HAVE_GETSPNAM', False) or
720 config_h_vars.get('HAVE_GETSPENT', False)):
721 exts.append( Extension('spwd', ['spwdmodule.c']) )
Skip Montanarod1287322007-03-06 15:41:38722 else:
Ronald Oussoren9545a232010-05-05 19:09:31723 missing.append('spwd')
Skip Montanarod1287322007-03-06 15:41:38724
Andrew M. Kuchling00e0f212001-01-17 15:23:23725 # select(2); not on ancient System V
726 exts.append( Extension('select', ['selectmodule.c']) )
727
Andrew M. Kuchling00e0f212001-01-17 15:23:23728 # Fred Drake's interface to the Python parser
729 exts.append( Extension('parser', ['parsermodule.c']) )
730
Guido van Rossum2e1c09c2002-04-04 17:52:50731 # cStringIO and cPickle
Andrew M. Kuchling00e0f212001-01-17 15:23:23732 exts.append( Extension('cStringIO', ['cStringIO.c']) )
733 exts.append( Extension('cPickle', ['cPickle.c']) )
734
735 # Memory-mapped files (also works on Win32).
doko@python.orgd65e2ba2013-01-31 22:52:03736 if host_platform not in ['atheos']:
Martin v. Löwisf90ae202002-06-11 06:22:31737 exts.append( Extension('mmap', ['mmapmodule.c']) )
Skip Montanarod1287322007-03-06 15:41:38738 else:
739 missing.append('mmap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23740
Andrew M. Kuchling57269d02004-08-31 13:37:25741 # Lance Ellinghaus's syslog module
Ronald Oussoren9545a232010-05-05 19:09:31742 # syslog daemon interface
743 exts.append( Extension('syslog', ['syslogmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23744
745 # George Neville-Neil's timing module:
Neal Norwitz6143c542006-03-03 00:48:46746 # Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html
747 # http://mail.python.org/pipermail/python-dev/2006-January/060023.html
748 #exts.append( Extension('timing', ['timingmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23749
750 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34751 # Here ends the simple stuff. From here on, modules need certain
752 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23753 #
754
755 # Multimedia modules
756 # These don't work for 64-bit platforms!!!
757 # These represent audio samples or images as strings:
758
Neal Norwitz5e4a3b82004-07-19 16:55:07759 # Operations on audio samples
Tim Petersf9cbf212004-07-23 02:50:10760 # According to #993173, this one should actually work fine on
Martin v. Löwis8fbefe22004-07-19 16:42:20761 # 64-bit platforms.
762 exts.append( Extension('audioop', ['audioop.c']) )
763
Fredrik Lundhade711a2001-01-24 08:00:28764 # Disabled on 64-bit platforms
Benjamin Peterson6e3c3c32015-01-21 05:47:54765 if sys.maxsize != 9223372036854775807L:
Andrew M. Kuchling00e0f212001-01-17 15:23:23766 # Operations on images
767 exts.append( Extension('imageop', ['imageop.c']) )
Skip Montanarod1287322007-03-06 15:41:38768 else:
Brett Cannondc48b742007-05-20 07:09:50769 missing.extend(['imageop'])
Andrew M. Kuchling00e0f212001-01-17 15:23:23770
771 # readline
Tarek Ziadé35a3f572010-03-05 00:29:38772 do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
Stefan Krah449aa862010-06-03 12:39:50773 readline_termcap_library = ""
774 curses_library = ""
775 # Determine if readline is already linked against curses or tinfo.
Stefan Krah4d32c9c2010-06-04 09:49:20776 if do_readline and find_executable('ldd'):
Stefan Krah449aa862010-06-03 12:39:50777 fp = os.popen("ldd %s" % do_readline)
Stefan Krah2e26e232010-07-17 12:21:08778 ldd_output = fp.readlines()
779 ret = fp.close()
780 if ret is None or ret >> 8 == 0:
781 for ln in ldd_output:
782 if 'curses' in ln:
783 readline_termcap_library = re.sub(
784 r'.*lib(n?cursesw?)\.so.*', r'\1', ln
785 ).rstrip()
786 break
787 if 'tinfo' in ln: # termcap interface split out from ncurses
788 readline_termcap_library = 'tinfo'
789 break
Stefan Krah449aa862010-06-03 12:39:50790 # Issue 7384: If readline is already linked against curses,
791 # use the same library for the readline and curses modules.
792 if 'curses' in readline_termcap_library:
793 curses_library = readline_termcap_library
Stefan Krah23152ea2010-06-03 14:25:16794 elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
Stefan Krah449aa862010-06-03 12:39:50795 curses_library = 'ncursesw'
Stefan Krah23152ea2010-06-03 14:25:16796 elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
Stefan Krah449aa862010-06-03 12:39:50797 curses_library = 'ncurses'
Stefan Krah23152ea2010-06-03 14:25:16798 elif self.compiler.find_library_file(lib_dirs, 'curses'):
Stefan Krah449aa862010-06-03 12:39:50799 curses_library = 'curses'
800
doko@python.orgd65e2ba2013-01-31 22:52:03801 if host_platform == 'darwin':
Ronald Oussoren9f20d9d2009-09-20 14:18:15802 os_release = int(os.uname()[2].split('.')[0])
Ronald Oussoren05b0d1d2010-03-08 07:06:47803 dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Ned Deily1f70b872014-06-25 20:33:57804 if (dep_target and
805 (tuple(int(n) for n in dep_target.split('.')[0:2])
806 < (10, 5) ) ):
Ronald Oussoren05b0d1d2010-03-08 07:06:47807 os_release = 8
Ronald Oussoren9f20d9d2009-09-20 14:18:15808 if os_release < 9:
809 # MacOSX 10.4 has a broken readline. Don't try to build
810 # the readline module unless the user has installed a fixed
811 # readline package
812 if find_file('readline/rlconf.h', inc_dirs, []) is None:
813 do_readline = False
Jack Jansen81ae2352006-02-23 15:02:23814 if do_readline:
doko@python.orgd65e2ba2013-01-31 22:52:03815 if host_platform == 'darwin' and os_release < 9:
Ronald Oussoren39be38c2006-05-26 11:38:39816 # In every directory on the search path search for a dynamic
817 # library and then a static library, instead of first looking
Fred Drake9c771ba2007-09-04 19:43:19818 # for dynamic libraries on the entire path.
Martin Panter8d496ad2016-06-02 10:35:44819 # This way a statically linked custom readline gets picked up
Ronald Oussoren593e4ca2010-06-03 09:47:21820 # before the (possibly broken) dynamic library in /usr/lib.
Ronald Oussoren39be38c2006-05-26 11:38:39821 readline_extra_link_args = ('-Wl,-search_paths_first',)
822 else:
823 readline_extra_link_args = ()
824
Marc-André Lemburg2efc3232001-01-26 18:23:02825 readline_libs = ['readline']
Stefan Krah449aa862010-06-03 12:39:50826 if readline_termcap_library:
827 pass # Issue 7384: Already linked against curses or tinfo.
828 elif curses_library:
829 readline_libs.append(curses_library)
Tarek Ziadé35a3f572010-03-05 00:29:38830 elif self.compiler.find_library_file(lib_dirs +
Tarek Ziadée670e5a2009-07-06 12:50:46831 ['/usr/lib/termcap'],
832 'termcap'):
Marc-André Lemburg2efc3232001-01-26 18:23:02833 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23834 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24835 library_dirs=['/usr/lib/termcap'],
Ronald Oussoren39be38c2006-05-26 11:38:39836 extra_link_args=readline_extra_link_args,
Marc-André Lemburg2efc3232001-01-26 18:23:02837 libraries=readline_libs) )
Skip Montanarod1287322007-03-06 15:41:38838 else:
839 missing.append('readline')
840
Ronald Oussoren9545a232010-05-05 19:09:31841 # crypt module.
Tim Peters2c60f7a2003-01-29 03:49:43842
Ronald Oussoren9545a232010-05-05 19:09:31843 if self.compiler.find_library_file(lib_dirs, 'crypt'):
844 libs = ['crypt']
Skip Montanarod1287322007-03-06 15:41:38845 else:
Ronald Oussoren9545a232010-05-05 19:09:31846 libs = []
847 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23848
Skip Montanaroba9e9782003-03-20 23:34:22849 # CSV files
850 exts.append( Extension('_csv', ['_csv.c']) )
851
Andrew M. Kuchling00e0f212001-01-17 15:23:23852 # socket(2)
Kristján Valur Jónsson868f0aa2013-03-19 20:53:56853 exts.append( Extension('_socket', ['socketmodule.c', 'timemodule.c'],
854 depends=['socketmodule.h'],
855 libraries=math_libs) )
Marc-André Lemburga5d2b4c2002-02-16 18:23:30856 # Detect SSL support for the socket module (via _ssl)
Gregory P. Smithade97332005-08-23 21:19:40857 search_for_ssl_incs_in = [
858 '/usr/local/ssl/include',
Andrew M. Kuchlinge7c87322001-01-19 16:58:21859 '/usr/contrib/ssl/include/'
860 ]
Gregory P. Smithade97332005-08-23 21:19:40861 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
862 search_for_ssl_incs_in
Andrew M. Kuchlingfbe73762001-01-18 18:44:20863 )
Martin v. Löwisa950f7f2003-05-09 09:05:19864 if ssl_incs is not None:
865 krb5_h = find_file('krb5.h', inc_dirs,
866 ['/usr/kerberos/include'])
867 if krb5_h:
868 ssl_incs += krb5_h
Tarek Ziadé35a3f572010-03-05 00:29:38869 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21870 ['/usr/local/ssl/lib',
871 '/usr/contrib/ssl/lib/'
872 ] )
Fredrik Lundhade711a2001-01-24 08:00:28873
Andrew M. Kuchlingfbe73762001-01-18 18:44:20874 if (ssl_incs is not None and
875 ssl_libs is not None):
Marc-André Lemburga5d2b4c2002-02-16 18:23:30876 exts.append( Extension('_ssl', ['_ssl.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20877 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28878 library_dirs = ssl_libs,
Guido van Rossum47d3a7a2002-06-13 14:41:32879 libraries = ['ssl', 'crypto'],
Jeremy Hylton340043e2002-06-13 17:38:11880 depends = ['socketmodule.h']), )
Skip Montanarod1287322007-03-06 15:41:38881 else:
882 missing.append('_ssl')
Andrew M. Kuchling00e0f212001-01-17 15:23:23883
Gregory P. Smithade97332005-08-23 21:19:40884 # find out which version of OpenSSL we have
885 openssl_ver = 0
886 openssl_ver_re = re.compile(
887 '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
Gregory P. Smithade97332005-08-23 21:19:40888
Ronald Oussoren593e4ca2010-06-03 09:47:21889 # look for the openssl version header on the compiler search path.
890 opensslv_h = find_file('openssl/opensslv.h', [],
891 inc_dirs + search_for_ssl_incs_in)
892 if opensslv_h:
893 name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
doko@python.orgd65e2ba2013-01-31 22:52:03894 if host_platform == 'darwin' and is_macosx_sdk_path(name):
Ronald Oussoren593e4ca2010-06-03 09:47:21895 name = os.path.join(macosx_sdk_root(), name[1:])
896 try:
897 incfile = open(name, 'r')
898 for line in incfile:
899 m = openssl_ver_re.match(line)
900 if m:
901 openssl_ver = eval(m.group(1))
902 except IOError, msg:
903 print "IOError while reading opensshv.h:", msg
904 pass
Gregory P. Smithade97332005-08-23 21:19:40905
Gregory P. Smithc2fa18c2010-01-02 22:25:29906 min_openssl_ver = 0x00907000
Gregory P. Smithffd5d882010-01-03 00:43:02907 have_any_openssl = ssl_incs is not None and ssl_libs is not None
908 have_usable_openssl = (have_any_openssl and
Gregory P. Smithc2fa18c2010-01-02 22:25:29909 openssl_ver >= min_openssl_ver)
Gregory P. Smithade97332005-08-23 21:19:40910
Gregory P. Smithffd5d882010-01-03 00:43:02911 if have_any_openssl:
912 if have_usable_openssl:
913 # The _hashlib module wraps optimized implementations
914 # of hash functions from the OpenSSL library.
915 exts.append( Extension('_hashlib', ['_hashopenssl.c'],
916 include_dirs = ssl_incs,
917 library_dirs = ssl_libs,
918 libraries = ['ssl', 'crypto']) )
919 else:
920 print ("warning: openssl 0x%08x is too old for _hashlib" %
921 openssl_ver)
922 missing.append('_hashlib')
Gregory P. Smithc2fa18c2010-01-02 22:25:29923 if COMPILED_WITH_PYDEBUG or not have_usable_openssl:
Gregory P. Smithf21a5f72005-08-21 18:45:59924 # The _sha module implements the SHA1 hash algorithm.
925 exts.append( Extension('_sha', ['shamodule.c']) )
926 # The _md5 module implements the RSA Data Security, Inc. MD5
927 # Message-Digest Algorithm, described in RFC 1321. The
Matthias Klose8e39ec72006-04-03 16:27:50928 # necessary files md5.c and md5.h are included here.
Gregory P. Smithd792392d2006-06-05 23:38:06929 exts.append( Extension('_md5',
930 sources = ['md5module.c', 'md5.c'],
931 depends = ['md5.h']) )
Gregory P. Smithf21a5f72005-08-21 18:45:59932
Gregory P. Smithc2fa18c2010-01-02 22:25:29933 min_sha2_openssl_ver = 0x00908000
934 if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver:
Gregory P. Smithade97332005-08-23 21:19:40935 # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
936 exts.append( Extension('_sha256', ['sha256module.c']) )
937 exts.append( Extension('_sha512', ['sha512module.c']) )
Gregory P. Smithf21a5f72005-08-21 18:45:59938
Andrew M. Kuchling00e0f212001-01-17 15:23:23939 # Modules that provide persistent dictionary-like semantics. You will
940 # probably want to arrange for at least one of them to be available on
941 # your machine, though none are defined by default because of library
942 # dependencies. The Python module anydbm.py provides an
943 # implementation independent wrapper for these; dumbdbm.py provides
944 # similar functionality (but slower of course) implemented in Python.
945
Gregory P. Smith1475cd82007-10-06 07:51:59946 # Sleepycat^WOracle Berkeley DB interface.
947 # http://www.oracle.com/database/berkeley-db/db/index.html
Skip Montanaro57454e52002-06-14 20:30:31948 #
Gregory P. Smith4eb60e52007-08-26 00:26:00949 # This requires the Sleepycat^WOracle DB code. The supported versions
Gregory P. Smithe7f4d842007-10-09 18:26:02950 # are set below. Visit the URL above to download
Gregory P. Smith3adc4aa2006-04-13 19:19:01951 # a release. Most open source OSes come with one or more
952 # versions of BerkeleyDB already installed.
Skip Montanaro57454e52002-06-14 20:30:31953
doko@ubuntu.com4950a3b2013-03-19 21:46:29954 max_db_ver = (5, 3)
955 min_db_ver = (4, 3)
Gregory P. Smithe76c8c02004-12-13 12:01:24956 db_setup_debug = False # verbose debug prints from this script?
Skip Montanaro57454e52002-06-14 20:30:31957
Gregory P. Smith0902cac2008-05-27 08:40:09958 def allow_db_ver(db_ver):
959 """Returns a boolean if the given BerkeleyDB version is acceptable.
960
961 Args:
962 db_ver: A tuple of the version to verify.
963 """
964 if not (min_db_ver <= db_ver <= max_db_ver):
965 return False
966 # Use this function to filter out known bad configurations.
967 if (4, 6) == db_ver[:2]:
968 # BerkeleyDB 4.6.x is not stable on many architectures.
969 arch = platform_machine()
970 if arch not in ('i386', 'i486', 'i586', 'i686',
971 'x86_64', 'ia64'):
972 return False
973 return True
974
975 def gen_db_minor_ver_nums(major):
doko@ubuntu.com4950a3b2013-03-19 21:46:29976 if major == 5:
977 for x in range(max_db_ver[1]+1):
978 if allow_db_ver((5, x)):
979 yield x
980 elif major == 4:
Benjamin Petersonef2436f2013-10-26 17:55:25981 for x in range(9):
Gregory P. Smith0902cac2008-05-27 08:40:09982 if allow_db_ver((4, x)):
983 yield x
984 elif major == 3:
985 for x in (3,):
986 if allow_db_ver((3, x)):
987 yield x
988 else:
989 raise ValueError("unknown major BerkeleyDB version", major)
990
Gregory P. Smithe76c8c02004-12-13 12:01:24991 # construct a list of paths to look for the header file in on
992 # top of the normal inc_dirs.
993 db_inc_paths = [
994 '/usr/include/db4',
995 '/usr/local/include/db4',
996 '/opt/sfw/include/db4',
Gregory P. Smithe76c8c02004-12-13 12:01:24997 '/usr/include/db3',
998 '/usr/local/include/db3',
999 '/opt/sfw/include/db3',
Skip Montanaro00c5a012007-03-04 20:52:281000 # Fink defaults (http://fink.sourceforge.net/)
1001 '/sw/include/db4',
Gregory P. Smithe76c8c02004-12-13 12:01:241002 '/sw/include/db3',
1003 ]
1004 # 4.x minor number specific paths
Gregory P. Smith0902cac2008-05-27 08:40:091005 for x in gen_db_minor_ver_nums(4):
Gregory P. Smithe76c8c02004-12-13 12:01:241006 db_inc_paths.append('/usr/include/db4%d' % x)
Neal Norwitz8f401712005-10-20 05:28:291007 db_inc_paths.append('/usr/include/db4.%d' % x)
Gregory P. Smithe76c8c02004-12-13 12:01:241008 db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
1009 db_inc_paths.append('/usr/local/include/db4%d' % x)
1010 db_inc_paths.append('/pkg/db-4.%d/include' % x)
Gregory P. Smith29602d22006-01-24 09:46:481011 db_inc_paths.append('/opt/db-4.%d/include' % x)
Skip Montanaro00c5a012007-03-04 20:52:281012 # MacPorts default (http://www.macports.org/)
1013 db_inc_paths.append('/opt/local/include/db4%d' % x)
Gregory P. Smithe76c8c02004-12-13 12:01:241014 # 3.x minor number specific paths
Gregory P. Smith0902cac2008-05-27 08:40:091015 for x in gen_db_minor_ver_nums(3):
Gregory P. Smithe76c8c02004-12-13 12:01:241016 db_inc_paths.append('/usr/include/db3%d' % x)
1017 db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
1018 db_inc_paths.append('/usr/local/include/db3%d' % x)
1019 db_inc_paths.append('/pkg/db-3.%d/include' % x)
Gregory P. Smith29602d22006-01-24 09:46:481020 db_inc_paths.append('/opt/db-3.%d/include' % x)
Tim Peters2c60f7a2003-01-29 03:49:431021
doko@python.orgd65e2ba2013-01-31 22:52:031022 if cross_compiling:
1023 db_inc_paths = []
1024
Ronald Oussoren9b8b6192006-06-27 12:53:521025 # Add some common subdirectories for Sleepycat DB to the list,
1026 # based on the standard include directories. This way DB3/4 gets
1027 # picked up when it is installed in a non-standard prefix and
1028 # the user has added that prefix into inc_dirs.
1029 std_variants = []
1030 for dn in inc_dirs:
1031 std_variants.append(os.path.join(dn, 'db3'))
1032 std_variants.append(os.path.join(dn, 'db4'))
Gregory P. Smith0902cac2008-05-27 08:40:091033 for x in gen_db_minor_ver_nums(4):
Ronald Oussoren9b8b6192006-06-27 12:53:521034 std_variants.append(os.path.join(dn, "db4%d"%x))
1035 std_variants.append(os.path.join(dn, "db4.%d"%x))
Gregory P. Smith0902cac2008-05-27 08:40:091036 for x in gen_db_minor_ver_nums(3):
Ronald Oussoren9b8b6192006-06-27 12:53:521037 std_variants.append(os.path.join(dn, "db3%d"%x))
1038 std_variants.append(os.path.join(dn, "db3.%d"%x))
1039
Tim Peters38ff36c2006-06-30 06:18:391040 db_inc_paths = std_variants + db_inc_paths
Skip Montanaro00c5a012007-03-04 20:52:281041 db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
Ronald Oussoren9b8b6192006-06-27 12:53:521042
Gregory P. Smithe76c8c02004-12-13 12:01:241043 db_ver_inc_map = {}
1044
doko@python.orgd65e2ba2013-01-31 22:52:031045 if host_platform == 'darwin':
Ronald Oussoren593e4ca2010-06-03 09:47:211046 sysroot = macosx_sdk_root()
1047
Gregory P. Smithe76c8c02004-12-13 12:01:241048 class db_found(Exception): pass
Skip Montanaro57454e52002-06-14 20:30:311049 try:
Martin v. Löwis05d4d562002-12-06 10:25:021050 # See whether there is a Sleepycat header in the standard
1051 # search path.
Gregory P. Smithe76c8c02004-12-13 12:01:241052 for d in inc_dirs + db_inc_paths:
Martin v. Löwis05d4d562002-12-06 10:25:021053 f = os.path.join(d, "db.h")
Ronald Oussoren593e4ca2010-06-03 09:47:211054
doko@python.orgd65e2ba2013-01-31 22:52:031055 if host_platform == 'darwin' and is_macosx_sdk_path(d):
Ronald Oussoren593e4ca2010-06-03 09:47:211056 f = os.path.join(sysroot, d[1:], "db.h")
1057
Gregory P. Smithe76c8c02004-12-13 12:01:241058 if db_setup_debug: print "db: looking for db.h in", f
Martin v. Löwis05d4d562002-12-06 10:25:021059 if os.path.exists(f):
1060 f = open(f).read()
Gregory P. Smithe76c8c02004-12-13 12:01:241061 m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f)
Martin v. Löwis05d4d562002-12-06 10:25:021062 if m:
Gregory P. Smithe76c8c02004-12-13 12:01:241063 db_major = int(m.group(1))
1064 m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f)
1065 db_minor = int(m.group(1))
1066 db_ver = (db_major, db_minor)
1067
Gregory P. Smith1475cd82007-10-06 07:51:591068 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
1069 if db_ver == (4, 6):
1070 m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f)
1071 db_patch = int(m.group(1))
1072 if db_patch < 21:
1073 print "db.h:", db_ver, "patch", db_patch,
1074 print "being ignored (4.6.x must be >= 4.6.21)"
1075 continue
1076
Antoine Pitrou8c510e72010-01-13 11:47:491077 if ( (db_ver not in db_ver_inc_map) and
Gregory P. Smith0902cac2008-05-27 08:40:091078 allow_db_ver(db_ver) ):
Gregory P. Smithe76c8c02004-12-13 12:01:241079 # save the include directory with the db.h version
Skip Montanaro00c5a012007-03-04 20:52:281080 # (first occurrence only)
Gregory P. Smithe76c8c02004-12-13 12:01:241081 db_ver_inc_map[db_ver] = d
Andrew M. Kuchling738446f42006-10-27 18:13:461082 if db_setup_debug:
1083 print "db.h: found", db_ver, "in", d
Gregory P. Smithe76c8c02004-12-13 12:01:241084 else:
1085 # we already found a header for this library version
1086 if db_setup_debug: print "db.h: ignoring", d
1087 else:
1088 # ignore this header, it didn't contain a version number
Skip Montanaro00c5a012007-03-04 20:52:281089 if db_setup_debug:
1090 print "db.h: no version number version in", d
Gregory P. Smithe76c8c02004-12-13 12:01:241091
1092 db_found_vers = db_ver_inc_map.keys()
1093 db_found_vers.sort()
1094
1095 while db_found_vers:
1096 db_ver = db_found_vers.pop()
1097 db_incdir = db_ver_inc_map[db_ver]
1098
1099 # check lib directories parallel to the location of the header
1100 db_dirs_to_check = [
Skip Montanaro00c5a012007-03-04 20:52:281101 db_incdir.replace("include", 'lib64'),
1102 db_incdir.replace("include", 'lib'),
Gregory P. Smithe76c8c02004-12-13 12:01:241103 ]
Ronald Oussoren593e4ca2010-06-03 09:47:211104
doko@python.orgd65e2ba2013-01-31 22:52:031105 if host_platform != 'darwin':
Ronald Oussoren593e4ca2010-06-03 09:47:211106 db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check)
1107
1108 else:
1109 # Same as other branch, but takes OSX SDK into account
1110 tmp = []
1111 for dn in db_dirs_to_check:
1112 if is_macosx_sdk_path(dn):
1113 if os.path.isdir(os.path.join(sysroot, dn[1:])):
1114 tmp.append(dn)
1115 else:
1116 if os.path.isdir(dn):
1117 tmp.append(dn)
Ronald Oussorencd172132010-06-27 12:36:161118 db_dirs_to_check = tmp
Gregory P. Smithe76c8c02004-12-13 12:01:241119
Ezio Melotti24b07bc2011-03-15 16:55:011120 # Look for a version specific db-X.Y before an ambiguous dbX
Gregory P. Smithe76c8c02004-12-13 12:01:241121 # XXX should we -ever- look for a dbX name? Do any
1122 # systems really not name their library by version and
1123 # symlink to more general names?
Andrew MacIntyre953f98d2005-03-09 22:21:081124 for dblib in (('db-%d.%d' % db_ver),
1125 ('db%d%d' % db_ver),
1126 ('db%d' % db_ver[0])):
Tarek Ziadé35a3f572010-03-05 00:29:381127 dblib_file = self.compiler.find_library_file(
Gregory P. Smithe76c8c02004-12-13 12:01:241128 db_dirs_to_check + lib_dirs, dblib )
1129 if dblib_file:
1130 dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
1131 raise db_found
1132 else:
1133 if db_setup_debug: print "db lib: ", dblib, "not found"
1134
1135 except db_found:
Brett Cannonef3dab22008-05-29 21:23:331136 if db_setup_debug:
1137 print "bsddb using BerkeleyDB lib:", db_ver, dblib
1138 print "bsddb lib dir:", dblib_dir, " inc dir:", db_incdir
Gregory P. Smithe76c8c02004-12-13 12:01:241139 db_incs = [db_incdir]
Jack Jansend1b20452002-07-08 21:39:361140 dblibs = [dblib]
Gregory P. Smithe76c8c02004-12-13 12:01:241141 # We add the runtime_library_dirs argument because the
1142 # BerkeleyDB lib we're linking against often isn't in the
1143 # system dynamic library search path. This is usually
1144 # correct and most trouble free, but may cause problems in
1145 # some unusual system configurations (e.g. the directory
1146 # is on an NFS server that goes away).
Martin v. Löwis6aa4a1f2002-11-19 08:09:521147 exts.append(Extension('_bsddb', ['_bsddb.c'],
Gregory P. Smith39250532007-10-09 06:02:211148 depends = ['bsddb.h'],
Martin v. Löwis05d4d562002-12-06 10:25:021149 library_dirs=dblib_dir,
1150 runtime_library_dirs=dblib_dir,
Martin v. Löwis6aa4a1f2002-11-19 08:09:521151 include_dirs=db_incs,
1152 libraries=dblibs))
Skip Montanaro57454e52002-06-14 20:30:311153 else:
Gregory P. Smithe76c8c02004-12-13 12:01:241154 if db_setup_debug: print "db: no appropriate library found"
Skip Montanaro57454e52002-06-14 20:30:311155 db_incs = None
1156 dblibs = []
1157 dblib_dir = None
Skip Montanarod1287322007-03-06 15:41:381158 missing.append('_bsddb')
Skip Montanaro57454e52002-06-14 20:30:311159
Anthony Baxterc51ee692006-04-01 00:57:311160 # The sqlite interface
Andrew M. Kuchling738446f42006-10-27 18:13:461161 sqlite_setup_debug = False # verbose debug prints from this script?
Anthony Baxterc51ee692006-04-01 00:57:311162
Anthony Baxter3dc6bb32006-04-03 02:20:491163 # We hunt for #define SQLITE_VERSION "n.n.n"
1164 # We need to find >= sqlite version 3.0.8
Anthony Baxterc51ee692006-04-01 00:57:311165 sqlite_incdir = sqlite_libdir = None
Anthony Baxter3dc6bb32006-04-03 02:20:491166 sqlite_inc_paths = [ '/usr/include',
Anthony Baxterc51ee692006-04-01 00:57:311167 '/usr/include/sqlite',
1168 '/usr/include/sqlite3',
1169 '/usr/local/include',
1170 '/usr/local/include/sqlite',
1171 '/usr/local/include/sqlite3',
1172 ]
doko@python.orgd65e2ba2013-01-31 22:52:031173 if cross_compiling:
1174 sqlite_inc_paths = []
Anthony Baxter3dc6bb32006-04-03 02:20:491175 MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
1176 MIN_SQLITE_VERSION = ".".join([str(x)
1177 for x in MIN_SQLITE_VERSION_NUMBER])
Ronald Oussoren39be38c2006-05-26 11:38:391178
1179 # Scan the default include directories before the SQLite specific
1180 # ones. This allows one to override the copy of sqlite on OSX,
1181 # where /usr/include contains an old version of sqlite.
doko@python.orgd65e2ba2013-01-31 22:52:031182 if host_platform == 'darwin':
Ronald Oussoren593e4ca2010-06-03 09:47:211183 sysroot = macosx_sdk_root()
1184
Ned Deily67028042012-08-05 21:42:451185 for d_ in inc_dirs + sqlite_inc_paths:
1186 d = d_
doko@python.orgd65e2ba2013-01-31 22:52:031187 if host_platform == 'darwin' and is_macosx_sdk_path(d):
Ned Deily67028042012-08-05 21:42:451188 d = os.path.join(sysroot, d[1:])
Ronald Oussoren593e4ca2010-06-03 09:47:211189
Ned Deily67028042012-08-05 21:42:451190 f = os.path.join(d, "sqlite3.h")
Anthony Baxterc51ee692006-04-01 00:57:311191 if os.path.exists(f):
Anthony Baxter07f5b352006-04-01 08:36:271192 if sqlite_setup_debug: print "sqlite: found %s"%f
Anthony Baxter3dc6bb32006-04-03 02:20:491193 incf = open(f).read()
1194 m = re.search(
Petri Lehtinenc23178b2013-02-23 16:05:281195 r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
Anthony Baxterc51ee692006-04-01 00:57:311196 if m:
Anthony Baxter3dc6bb32006-04-03 02:20:491197 sqlite_version = m.group(1)
1198 sqlite_version_tuple = tuple([int(x)
1199 for x in sqlite_version.split(".")])
1200 if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
Anthony Baxterc51ee692006-04-01 00:57:311201 # we win!
Andrew M. Kuchling738446f42006-10-27 18:13:461202 if sqlite_setup_debug:
1203 print "%s/sqlite3.h: version %s"%(d, sqlite_version)
Anthony Baxterc51ee692006-04-01 00:57:311204 sqlite_incdir = d
1205 break
1206 else:
Anthony Baxter3dc6bb32006-04-03 02:20:491207 if sqlite_setup_debug:
Anthony Baxterc51ee692006-04-01 00:57:311208 print "%s: version %d is too old, need >= %s"%(d,
1209 sqlite_version, MIN_SQLITE_VERSION)
Anthony Baxter3dc6bb32006-04-03 02:20:491210 elif sqlite_setup_debug:
1211 print "sqlite: %s had no SQLITE_VERSION"%(f,)
1212
Anthony Baxterc51ee692006-04-01 00:57:311213 if sqlite_incdir:
1214 sqlite_dirs_to_check = [
1215 os.path.join(sqlite_incdir, '..', 'lib64'),
1216 os.path.join(sqlite_incdir, '..', 'lib'),
1217 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
1218 os.path.join(sqlite_incdir, '..', '..', 'lib'),
1219 ]
Tarek Ziadé35a3f572010-03-05 00:29:381220 sqlite_libfile = self.compiler.find_library_file(
Anthony Baxterc51ee692006-04-01 00:57:311221 sqlite_dirs_to_check + lib_dirs, 'sqlite3')
Hirokazu Yamamoto1ae415c2008-10-03 17:34:491222 if sqlite_libfile:
1223 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
Anthony Baxterc51ee692006-04-01 00:57:311224
1225 if sqlite_incdir and sqlite_libdir:
Gerhard Häring3e99c0a2006-04-23 15:24:261226 sqlite_srcs = ['_sqlite/cache.c',
Anthony Baxterc51ee692006-04-01 00:57:311227 '_sqlite/connection.c',
Anthony Baxterc51ee692006-04-01 00:57:311228 '_sqlite/cursor.c',
1229 '_sqlite/microprotocols.c',
1230 '_sqlite/module.c',
1231 '_sqlite/prepare_protocol.c',
1232 '_sqlite/row.c',
1233 '_sqlite/statement.c',
1234 '_sqlite/util.c', ]
1235
Anthony Baxterc51ee692006-04-01 00:57:311236 sqlite_defines = []
doko@python.orgd65e2ba2013-01-31 22:52:031237 if host_platform != "win32":
Anthony Baxter8e7b4902006-04-05 18:25:331238 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
Anthony Baxterc51ee692006-04-01 00:57:311239 else:
Anthony Baxter8e7b4902006-04-05 18:25:331240 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
1241
Gerhard Häring3bbb6722010-03-05 09:12:371242 # Comment this out if you want the sqlite3 module to be able to load extensions.
1243 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
Ronald Oussoren39be38c2006-05-26 11:38:391244
doko@python.orgd65e2ba2013-01-31 22:52:031245 if host_platform == 'darwin':
Ronald Oussoren39be38c2006-05-26 11:38:391246 # In every directory on the search path search for a dynamic
1247 # library and then a static library, instead of first looking
Ezio Melottic2077b02011-03-16 10:34:311248 # for dynamic libraries on the entire path.
1249 # This way a statically linked custom sqlite gets picked up
Ronald Oussoren39be38c2006-05-26 11:38:391250 # before the dynamic library in /usr/lib.
1251 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
1252 else:
1253 sqlite_extra_link_args = ()
1254
Anthony Baxterc51ee692006-04-01 00:57:311255 exts.append(Extension('_sqlite3', sqlite_srcs,
1256 define_macros=sqlite_defines,
Anthony Baxter3dc6bb32006-04-03 02:20:491257 include_dirs=["Modules/_sqlite",
Anthony Baxterc51ee692006-04-01 00:57:311258 sqlite_incdir],
1259 library_dirs=sqlite_libdir,
Ronald Oussoren39be38c2006-05-26 11:38:391260 extra_link_args=sqlite_extra_link_args,
Anthony Baxterc51ee692006-04-01 00:57:311261 libraries=["sqlite3",]))
Skip Montanarod1287322007-03-06 15:41:381262 else:
1263 missing.append('_sqlite3')
Skip Montanaro22e00c42003-05-06 20:43:341264
1265 # Look for Berkeley db 1.85. Note that it is built as a different
1266 # module name so it can be included even when later versions are
1267 # available. A very restrictive search is performed to avoid
1268 # accidentally building this module with a later version of the
1269 # underlying db library. May BSD-ish Unixes incorporate db 1.85
1270 # symbols into libc and place the include file in /usr/include.
Gregory P. Smith4eb60e52007-08-26 00:26:001271 #
1272 # If the better bsddb library can be built (db_incs is defined)
1273 # we do not build this one. Otherwise this build will pick up
1274 # the more recent berkeleydb's db.h file first in the include path
1275 # when attempting to compile and it will fail.
Skip Montanaro22e00c42003-05-06 20:43:341276 f = "/usr/include/db.h"
Ronald Oussoren593e4ca2010-06-03 09:47:211277
doko@python.orgd65e2ba2013-01-31 22:52:031278 if host_platform == 'darwin':
Ronald Oussoren593e4ca2010-06-03 09:47:211279 if is_macosx_sdk_path(f):
1280 sysroot = macosx_sdk_root()
1281 f = os.path.join(sysroot, f[1:])
1282
Gregory P. Smith4eb60e52007-08-26 00:26:001283 if os.path.exists(f) and not db_incs:
Skip Montanaro22e00c42003-05-06 20:43:341284 data = open(f).read()
1285 m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data)
1286 if m is not None:
1287 # bingo - old version used hash file format version 2
1288 ### XXX this should be fixed to not be platform-dependent
1289 ### but I don't have direct access to an osf1 platform and
1290 ### seemed to be muffing the search somehow
doko@python.orgd65e2ba2013-01-31 22:52:031291 libraries = host_platform == "osf1" and ['db'] or None
Skip Montanaro22e00c42003-05-06 20:43:341292 if libraries is not None:
1293 exts.append(Extension('bsddb185', ['bsddbmodule.c'],
1294 libraries=libraries))
1295 else:
1296 exts.append(Extension('bsddb185', ['bsddbmodule.c']))
Skip Montanarod1287322007-03-06 15:41:381297 else:
1298 missing.append('bsddb185')
1299 else:
1300 missing.append('bsddb185')
Skip Montanaro22e00c42003-05-06 20:43:341301
Benjamin Petersonedfe72f2010-01-01 15:21:131302 dbm_order = ['gdbm']
Andrew M. Kuchling00e0f212001-01-17 15:23:231303 # The standard Unix dbm module:
doko@python.orgd65e2ba2013-01-31 22:52:031304 if host_platform not in ['cygwin']:
Matthias Klose51c614e2009-04-29 19:52:491305 config_args = [arg.strip("'")
1306 for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
Benjamin Petersonedfe72f2010-01-01 15:21:131307 dbm_args = [arg for arg in config_args
Matthias Klose10cbe482009-04-29 17:18:191308 if arg.startswith('--with-dbmliborder=')]
1309 if dbm_args:
Benjamin Petersonedfe72f2010-01-01 15:21:131310 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
Matthias Klose10cbe482009-04-29 17:18:191311 else:
Matthias Klose51c614e2009-04-29 19:52:491312 dbm_order = "ndbm:gdbm:bdb".split(":")
Matthias Klose10cbe482009-04-29 17:18:191313 dbmext = None
1314 for cand in dbm_order:
1315 if cand == "ndbm":
1316 if find_file("ndbm.h", inc_dirs, []) is not None:
Nick Coghlan970fcef2012-06-17 08:35:391317 # Some systems have -lndbm, others have -lgdbm_compat,
1318 # others don't have either
Tarek Ziadé35a3f572010-03-05 00:29:381319 if self.compiler.find_library_file(lib_dirs,
Tarek Ziadée670e5a2009-07-06 12:50:461320 'ndbm'):
Matthias Klose10cbe482009-04-29 17:18:191321 ndbm_libs = ['ndbm']
Nick Coghlan970fcef2012-06-17 08:35:391322 elif self.compiler.find_library_file(lib_dirs,
1323 'gdbm_compat'):
1324 ndbm_libs = ['gdbm_compat']
Matthias Klose10cbe482009-04-29 17:18:191325 else:
1326 ndbm_libs = []
1327 print "building dbm using ndbm"
1328 dbmext = Extension('dbm', ['dbmmodule.c'],
1329 define_macros=[
1330 ('HAVE_NDBM_H',None),
1331 ],
1332 libraries=ndbm_libs)
1333 break
1334
1335 elif cand == "gdbm":
Tarek Ziadé35a3f572010-03-05 00:29:381336 if self.compiler.find_library_file(lib_dirs, 'gdbm'):
Matthias Klose10cbe482009-04-29 17:18:191337 gdbm_libs = ['gdbm']
Tarek Ziadé35a3f572010-03-05 00:29:381338 if self.compiler.find_library_file(lib_dirs,
Tarek Ziadée670e5a2009-07-06 12:50:461339 'gdbm_compat'):
Matthias Klose10cbe482009-04-29 17:18:191340 gdbm_libs.append('gdbm_compat')
1341 if find_file("gdbm/ndbm.h", inc_dirs, []) is not None:
1342 print "building dbm using gdbm"
1343 dbmext = Extension(
1344 'dbm', ['dbmmodule.c'],
1345 define_macros=[
1346 ('HAVE_GDBM_NDBM_H', None),
1347 ],
1348 libraries = gdbm_libs)
1349 break
1350 if find_file("gdbm-ndbm.h", inc_dirs, []) is not None:
1351 print "building dbm using gdbm"
1352 dbmext = Extension(
1353 'dbm', ['dbmmodule.c'],
1354 define_macros=[
1355 ('HAVE_GDBM_DASH_NDBM_H', None),
1356 ],
1357 libraries = gdbm_libs)
1358 break
1359 elif cand == "bdb":
1360 if db_incs is not None:
1361 print "building dbm using bdb"
1362 dbmext = Extension('dbm', ['dbmmodule.c'],
1363 library_dirs=dblib_dir,
1364 runtime_library_dirs=dblib_dir,
1365 include_dirs=db_incs,
1366 define_macros=[
1367 ('HAVE_BERKDB_H', None),
1368 ('DB_DBM_HSEARCH', None),
1369 ],
1370 libraries=dblibs)
1371 break
1372 if dbmext is not None:
1373 exts.append(dbmext)
Skip Montanarod1287322007-03-06 15:41:381374 else:
1375 missing.append('dbm')
Fredrik Lundhade711a2001-01-24 08:00:281376
Andrew M. Kuchling00e0f212001-01-17 15:23:231377 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
Benjamin Petersonedfe72f2010-01-01 15:21:131378 if ('gdbm' in dbm_order and
Tarek Ziadé35a3f572010-03-05 00:29:381379 self.compiler.find_library_file(lib_dirs, 'gdbm')):
Andrew M. Kuchling00e0f212001-01-17 15:23:231380 exts.append( Extension('gdbm', ['gdbmmodule.c'],
1381 libraries = ['gdbm'] ) )
Skip Montanarod1287322007-03-06 15:41:381382 else:
1383 missing.append('gdbm')
Andrew M. Kuchling00e0f212001-01-17 15:23:231384
Andrew M. Kuchling00e0f212001-01-17 15:23:231385 # Unix-only modules
doko@python.orgd65e2ba2013-01-31 22:52:031386 if host_platform not in ['win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:231387 # Steen Lumholt's termios module
1388 exts.append( Extension('termios', ['termios.c']) )
1389 # Jeremy Hylton's rlimit interface
doko@python.orgd65e2ba2013-01-31 22:52:031390 if host_platform not in ['atheos']:
Martin v. Löwisf90ae202002-06-11 06:22:311391 exts.append( Extension('resource', ['resource.c']) )
Skip Montanarod1287322007-03-06 15:41:381392 else:
1393 missing.append('resource')
Andrew M. Kuchling00e0f212001-01-17 15:23:231394
Christian Heimes38487a02018-01-27 08:39:391395 nis = self._detect_nis(inc_dirs, lib_dirs)
1396 if nis is not None:
1397 exts.append(nis)
Skip Montanarod1287322007-03-06 15:41:381398 else:
1399 missing.append('nis')
Andrew M. Kuchling00e0f212001-01-17 15:23:231400
Skip Montanaro72092942004-02-07 12:50:191401 # Curses support, requiring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:281402 # provided by the ncurses library.
Andrew M. Kuchling86070422006-08-06 22:07:041403 panel_library = 'panel'
doko@ubuntu.comf27ec3e2014-04-17 18:11:191404 curses_incs = None
Stefan Krah449aa862010-06-03 12:39:501405 if curses_library.startswith('ncurses'):
1406 if curses_library == 'ncursesw':
1407 # Bug 1464056: If _curses.so links with ncursesw,
1408 # _curses_panel.so must link with panelw.
1409 panel_library = 'panelw'
1410 curses_libs = [curses_library]
doko@ubuntu.comf27ec3e2014-04-17 18:11:191411 curses_incs = find_file('curses.h', inc_dirs,
1412 [os.path.join(d, 'ncursesw') for d in inc_dirs])
Martin v. Löwisa55e55e2006-02-11 15:55:141413 exts.append( Extension('_curses', ['_cursesmodule.c'],
doko@ubuntu.comf27ec3e2014-04-17 18:11:191414 include_dirs = curses_incs,
Martin v. Löwisa55e55e2006-02-11 15:55:141415 libraries = curses_libs) )
doko@python.orgd65e2ba2013-01-31 22:52:031416 elif curses_library == 'curses' and host_platform != 'darwin':
Michael W. Hudson5b109102002-01-23 15:04:411417 # OSX has an old Berkeley curses, not good enough for
1418 # the _curses module.
Tarek Ziadé35a3f572010-03-05 00:29:381419 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
Andrew M. Kuchling00e0f212001-01-17 15:23:231420 curses_libs = ['curses', 'terminfo']
Tarek Ziadé35a3f572010-03-05 00:29:381421 elif (self.compiler.find_library_file(lib_dirs, 'termcap')):
Andrew M. Kuchling00e0f212001-01-17 15:23:231422 curses_libs = ['curses', 'termcap']
Neal Norwitz0b27ff92003-03-31 15:53:491423 else:
1424 curses_libs = ['curses']
Fredrik Lundhade711a2001-01-24 08:00:281425
Andrew M. Kuchling00e0f212001-01-17 15:23:231426 exts.append( Extension('_curses', ['_cursesmodule.c'],
1427 libraries = curses_libs) )
Skip Montanarod1287322007-03-06 15:41:381428 else:
1429 missing.append('_curses')
Fredrik Lundhade711a2001-01-24 08:00:281430
Andrew M. Kuchling00e0f212001-01-17 15:23:231431 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:161432 if (module_enabled(exts, '_curses') and
Tarek Ziadé35a3f572010-03-05 00:29:381433 self.compiler.find_library_file(lib_dirs, panel_library)):
Andrew M. Kuchling00e0f212001-01-17 15:23:231434 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
doko@ubuntu.comf27ec3e2014-04-17 18:11:191435 include_dirs = curses_incs,
Andrew M. Kuchling86070422006-08-06 22:07:041436 libraries = [panel_library] + curses_libs) )
Skip Montanarod1287322007-03-06 15:41:381437 else:
1438 missing.append('_curses_panel')
Fredrik Lundhade711a2001-01-24 08:00:281439
Barry Warsaw259b1e12002-08-13 20:09:261440 # Andrew Kuchling's zlib module. Note that some versions of zlib
1441 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1442 # http://www.cert.org/advisories/CA-2002-07.html
1443 #
1444 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1445 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1446 # now, we still accept 1.1.3, because we think it's difficult to
1447 # exploit this in Python, and we'd rather make it RedHat's problem
1448 # than our problem <wink>.
1449 #
1450 # You can upgrade zlib to version 1.1.4 yourself by going to
1451 # http://www.gzip.org/zlib/
Guido van Rossume6970912001-04-15 15:16:121452 zlib_inc = find_file('zlib.h', [], inc_dirs)
Gregory P. Smith440ca772008-03-24 00:08:011453 have_zlib = False
Guido van Rossume6970912001-04-15 15:16:121454 if zlib_inc is not None:
1455 zlib_h = zlib_inc[0] + '/zlib.h'
1456 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:261457 version_req = '"1.1.3"'
Ned Deily6ea3c9b2013-10-19 04:33:571458 if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
1459 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
Guido van Rossume6970912001-04-15 15:16:121460 fp = open(zlib_h)
1461 while 1:
1462 line = fp.readline()
1463 if not line:
1464 break
Guido van Rossum8cdc03d2002-08-06 17:28:301465 if line.startswith('#define ZLIB_VERSION'):
Guido van Rossume6970912001-04-15 15:16:121466 version = line.split()[2]
1467 break
1468 if version >= version_req:
Tarek Ziadé35a3f572010-03-05 00:29:381469 if (self.compiler.find_library_file(lib_dirs, 'z')):
doko@python.orgd65e2ba2013-01-31 22:52:031470 if host_platform == "darwin":
Ronald Oussoren9b8b6192006-06-27 12:53:521471 zlib_extra_link_args = ('-Wl,-search_paths_first',)
1472 else:
1473 zlib_extra_link_args = ()
Guido van Rossume6970912001-04-15 15:16:121474 exts.append( Extension('zlib', ['zlibmodule.c'],
Ronald Oussoren9b8b6192006-06-27 12:53:521475 libraries = ['z'],
1476 extra_link_args = zlib_extra_link_args))
Gregory P. Smith440ca772008-03-24 00:08:011477 have_zlib = True
Skip Montanarod1287322007-03-06 15:41:381478 else:
1479 missing.append('zlib')
1480 else:
1481 missing.append('zlib')
1482 else:
1483 missing.append('zlib')
Andrew M. Kuchling00e0f212001-01-17 15:23:231484
Gregory P. Smith440ca772008-03-24 00:08:011485 # Helper module for various ascii-encoders. Uses zlib for an optimized
1486 # crc32 if we have it. Otherwise binascii uses its own.
1487 if have_zlib:
1488 extra_compile_args = ['-DUSE_ZLIB_CRC32']
1489 libraries = ['z']
1490 extra_link_args = zlib_extra_link_args
1491 else:
1492 extra_compile_args = []
1493 libraries = []
1494 extra_link_args = []
1495 exts.append( Extension('binascii', ['binascii.c'],
1496 extra_compile_args = extra_compile_args,
1497 libraries = libraries,
1498 extra_link_args = extra_link_args) )
1499
Gustavo Niemeyerf8ca8362002-11-05 16:50:051500 # Gustavo Niemeyer's bz2 module.
Tarek Ziadé35a3f572010-03-05 00:29:381501 if (self.compiler.find_library_file(lib_dirs, 'bz2')):
doko@python.orgd65e2ba2013-01-31 22:52:031502 if host_platform == "darwin":
Ronald Oussoren9b8b6192006-06-27 12:53:521503 bz2_extra_link_args = ('-Wl,-search_paths_first',)
1504 else:
1505 bz2_extra_link_args = ()
Gustavo Niemeyerf8ca8362002-11-05 16:50:051506 exts.append( Extension('bz2', ['bz2module.c'],
Ronald Oussoren9b8b6192006-06-27 12:53:521507 libraries = ['bz2'],
1508 extra_link_args = bz2_extra_link_args) )
Skip Montanarod1287322007-03-06 15:41:381509 else:
1510 missing.append('bz2')
Gustavo Niemeyerf8ca8362002-11-05 16:50:051511
Andrew M. Kuchling00e0f212001-01-17 15:23:231512 # Interface to the Expat XML parser
1513 #
Benjamin Peterson2fd2e862009-12-31 16:28:241514 # Expat was written by James Clark and is now maintained by a group of
1515 # developers on SourceForge; see www.libexpat.org for more information.
1516 # The pyexpat module was written by Paul Prescod after a prototype by
1517 # Jack Jansen. The Expat source is included in Modules/expat/. Usage
1518 # of a system shared libexpat.so is possible with --with-system-expat
Benjamin Peterson206e10c2010-10-31 16:40:211519 # configure option.
Fred Drakefc8341d2002-06-17 17:55:301520 #
1521 # More information on Expat can be found at www.libexpat.org.
1522 #
Benjamin Peterson2c196742009-12-31 03:17:181523 if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
1524 expat_inc = []
1525 define_macros = []
1526 expat_lib = ['expat']
1527 expat_sources = []
Christian Heimes56656b02013-02-09 16:02:061528 expat_depends = []
Benjamin Peterson2c196742009-12-31 03:17:181529 else:
1530 expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')]
1531 define_macros = [
1532 ('HAVE_EXPAT_CONFIG_H', '1'),
Victor Stinnerec4ab092017-08-18 23:06:451533 # bpo-30947: Python uses best available entropy sources to
1534 # call XML_SetHashSalt(), expat entropy sources are not needed
1535 ('XML_POOR_ENTROPY', '1'),
Benjamin Peterson2c196742009-12-31 03:17:181536 ]
1537 expat_lib = []
1538 expat_sources = ['expat/xmlparse.c',
1539 'expat/xmlrole.c',
1540 'expat/xmltok.c']
Christian Heimes56656b02013-02-09 16:02:061541 expat_depends = ['expat/ascii.h',
1542 'expat/asciitab.h',
1543 'expat/expat.h',
1544 'expat/expat_config.h',
1545 'expat/expat_external.h',
1546 'expat/internal.h',
1547 'expat/latin1tab.h',
1548 'expat/utf8tab.h',
1549 'expat/xmlrole.h',
1550 'expat/xmltok.h',
1551 'expat/xmltok_impl.h'
1552 ]
Ronald Oussoren988117f2006-04-29 11:31:351553
Fred Drake2d59a492003-10-21 15:41:151554 exts.append(Extension('pyexpat',
1555 define_macros = define_macros,
Benjamin Peterson2c196742009-12-31 03:17:181556 include_dirs = expat_inc,
1557 libraries = expat_lib,
Christian Heimes56656b02013-02-09 16:02:061558 sources = ['pyexpat.c'] + expat_sources,
1559 depends = expat_depends,
Fred Drake2d59a492003-10-21 15:41:151560 ))
Andrew M. Kuchling00e0f212001-01-17 15:23:231561
Fredrik Lundh4c86ec62005-12-14 18:46:161562 # Fredrik Lundh's cElementTree module. Note that this also
1563 # uses expat (via the CAPI hook in pyexpat).
1564
Hye-Shik Chang6c403592006-03-27 08:43:111565 if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')):
Fredrik Lundh4c86ec62005-12-14 18:46:161566 define_macros.append(('USE_PYEXPAT_CAPI', None))
1567 exts.append(Extension('_elementtree',
1568 define_macros = define_macros,
Benjamin Peterson2c196742009-12-31 03:17:181569 include_dirs = expat_inc,
1570 libraries = expat_lib,
Fredrik Lundh4c86ec62005-12-14 18:46:161571 sources = ['_elementtree.c'],
Christian Heimes56656b02013-02-09 16:02:061572 depends = ['pyexpat.c'] + expat_sources +
1573 expat_depends,
Fredrik Lundh4c86ec62005-12-14 18:46:161574 ))
Skip Montanarod1287322007-03-06 15:41:381575 else:
1576 missing.append('_elementtree')
Fredrik Lundh4c86ec62005-12-14 18:46:161577
Hye-Shik Chang3e2a3062004-01-17 14:29:291578 # Hye-Shik Chang's CJKCodecs modules.
Martin v. Löwise2713be2005-03-08 15:03:081579 if have_unicode:
1580 exts.append(Extension('_multibytecodec',
1581 ['cjkcodecs/multibytecodec.c']))
1582 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
Skip Montanarod1287322007-03-06 15:41:381583 exts.append(Extension('_codecs_%s' % loc,
Martin v. Löwise2713be2005-03-08 15:03:081584 ['cjkcodecs/_codecs_%s.c' % loc]))
Skip Montanarod1287322007-03-06 15:41:381585 else:
1586 missing.append('_multibytecodec')
1587 for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
1588 missing.append('_codecs_%s' % loc)
Hye-Shik Chang3e2a3062004-01-17 14:29:291589
Michael W. Hudson5b109102002-01-23 15:04:411590 # Dynamic loading module
Guido van Rossum770acd32002-09-12 14:41:201591 if sys.maxint == 0x7fffffff:
1592 # This requires sizeof(int) == sizeof(long) == sizeof(char*)
1593 dl_inc = find_file('dlfcn.h', [], inc_dirs)
doko@python.orgd65e2ba2013-01-31 22:52:031594 if (dl_inc is not None) and (host_platform not in ['atheos']):
Guido van Rossum770acd32002-09-12 14:41:201595 exts.append( Extension('dl', ['dlmodule.c']) )
Skip Montanarod1287322007-03-06 15:41:381596 else:
1597 missing.append('dl')
1598 else:
1599 missing.append('dl')
Michael W. Hudson5b109102002-01-23 15:04:411600
Thomas Hellercf567c12006-03-08 19:51:581601 # Thomas Heller's _ctypes module
Martin v. Löwis9176fc12006-04-11 11:12:431602 self.detect_ctypes(inc_dirs, lib_dirs)
Thomas Hellercf567c12006-03-08 19:51:581603
Benjamin Peterson190d56e2008-06-11 02:40:251604 # Richard Oudkerk's multiprocessing module
doko@python.orgd65e2ba2013-01-31 22:52:031605 if host_platform == 'win32': # Windows
Benjamin Peterson190d56e2008-06-11 02:40:251606 macros = dict()
1607 libraries = ['ws2_32']
1608
doko@python.orgd65e2ba2013-01-31 22:52:031609 elif host_platform == 'darwin': # Mac OSX
Jesse Noller355b1262009-04-02 00:03:281610 macros = dict()
Benjamin Peterson190d56e2008-06-11 02:40:251611 libraries = []
1612
doko@python.orgd65e2ba2013-01-31 22:52:031613 elif host_platform == 'cygwin': # Cygwin
Jesse Noller355b1262009-04-02 00:03:281614 macros = dict()
Benjamin Peterson190d56e2008-06-11 02:40:251615 libraries = []
Hye-Shik Chang99c48a82008-06-28 01:04:311616
doko@python.orgd65e2ba2013-01-31 22:52:031617 elif host_platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
Hye-Shik Chang99c48a82008-06-28 01:04:311618 # FreeBSD's P1003.1b semaphore support is very experimental
1619 # and has many known problems. (as of June 2008)
Jesse Noller355b1262009-04-02 00:03:281620 macros = dict()
Hye-Shik Chang99c48a82008-06-28 01:04:311621 libraries = []
1622
doko@python.orgd65e2ba2013-01-31 22:52:031623 elif host_platform.startswith('openbsd'):
Jesse Noller355b1262009-04-02 00:03:281624 macros = dict()
Jesse Noller37040cd2008-09-30 00:15:451625 libraries = []
1626
doko@python.orgd65e2ba2013-01-31 22:52:031627 elif host_platform.startswith('netbsd'):
Jesse Noller355b1262009-04-02 00:03:281628 macros = dict()
Jesse Noller40a61642009-03-31 18:12:351629 libraries = []
1630
Benjamin Peterson190d56e2008-06-11 02:40:251631 else: # Linux and other unices
Jesse Noller355b1262009-04-02 00:03:281632 macros = dict()
Benjamin Peterson190d56e2008-06-11 02:40:251633 libraries = ['rt']
1634
doko@python.orgd65e2ba2013-01-31 22:52:031635 if host_platform == 'win32':
Benjamin Peterson190d56e2008-06-11 02:40:251636 multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
1637 '_multiprocessing/semaphore.c',
1638 '_multiprocessing/pipe_connection.c',
1639 '_multiprocessing/socket_connection.c',
1640 '_multiprocessing/win32_functions.c'
1641 ]
1642
1643 else:
1644 multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
1645 '_multiprocessing/socket_connection.c'
1646 ]
Mark Dickinsonc4920e82009-11-20 19:30:221647 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
Mark Dickinson5afa6d42009-11-28 10:44:201648 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
Benjamin Peterson190d56e2008-06-11 02:40:251649 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
1650
Jesse Nollerf6da8d12009-01-23 14:04:411651 if sysconfig.get_config_var('WITH_THREAD'):
1652 exts.append ( Extension('_multiprocessing', multiprocessing_srcs,
1653 define_macros=macros.items(),
1654 include_dirs=["Modules/_multiprocessing"]))
1655 else:
1656 missing.append('_multiprocessing')
1657
Benjamin Peterson190d56e2008-06-11 02:40:251658 # End multiprocessing
1659
1660
Andrew M. Kuchling00e0f212001-01-17 15:23:231661 # Platform-specific libraries
doko@python.orgd65e2ba2013-01-31 22:52:031662 if host_platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:231663 # Linux-specific modules
1664 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
Skip Montanarod1287322007-03-06 15:41:381665 else:
1666 missing.append('linuxaudiodev')
Greg Ward0a6355e2003-01-08 01:37:411667
doko@python.orgd65e2ba2013-01-31 22:52:031668 if (host_platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
Matthias Klose8a96d202010-04-21 22:18:521669 'freebsd7', 'freebsd8')
doko@python.orgd65e2ba2013-01-31 22:52:031670 or host_platform.startswith("gnukfreebsd")):
Guido van Rossum0c016a92003-02-13 16:12:211671 exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
Skip Montanarod1287322007-03-06 15:41:381672 else:
1673 missing.append('ossaudiodev')
Andrew M. Kuchling00e0f212001-01-17 15:23:231674
doko@python.orgd65e2ba2013-01-31 22:52:031675 if host_platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:281676 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:231677 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Skip Montanarod1287322007-03-06 15:41:381678 else:
1679 missing.append('sunaudiodev')
Michael W. Hudson5b109102002-01-23 15:04:411680
doko@python.orgd65e2ba2013-01-31 22:52:031681 if host_platform == 'darwin':
Ronald Oussorena5b642c2009-10-08 08:04:151682 # _scproxy
1683 exts.append(Extension("_scproxy", [os.path.join(srcdir, "Mac/Modules/_scproxy.c")],
1684 extra_link_args= [
1685 '-framework', 'SystemConfiguration',
1686 '-framework', 'CoreFoundation'
1687 ]))
1688
1689
doko@python.orgd65e2ba2013-01-31 22:52:031690 if host_platform == 'darwin' and ("--disable-toolbox-glue" not in
Ronald Oussoren090f8152006-03-30 20:18:331691 sysconfig.get_config_var("CONFIG_ARGS")):
1692
Ronald Oussoren05b0d1d2010-03-08 07:06:471693 if int(os.uname()[2].split('.')[0]) >= 8:
Ronald Oussoren090f8152006-03-30 20:18:331694 # We're on Mac OS X 10.4 or later, the compiler should
1695 # support '-Wno-deprecated-declarations'. This will
Martin Panter99496762016-08-20 08:00:531696 # suppress deprecation warnings for the Carbon extensions,
Ronald Oussoren090f8152006-03-30 20:18:331697 # these extensions wrap the Carbon APIs and even those
1698 # parts that are deprecated.
1699 carbon_extra_compile_args = ['-Wno-deprecated-declarations']
1700 else:
1701 carbon_extra_compile_args = []
1702
Just van Rossum05ced6a2002-11-24 23:15:571703 # Mac OS X specific modules.
Neal Norwitz3e1ec3a2006-04-03 04:52:051704 def macSrcExists(name1, name2=''):
1705 if not name1:
1706 return None
1707 names = (name1,)
1708 if name2:
1709 names = (name1, name2)
1710 path = os.path.join(srcdir, 'Mac', 'Modules', *names)
1711 return os.path.exists(path)
1712
1713 def addMacExtension(name, kwds, extra_srcs=[]):
1714 dirname = ''
1715 if name[0] == '_':
1716 dirname = name[1:].lower()
1717 cname = name + '.c'
1718 cmodulename = name + 'module.c'
1719 # Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c
1720 if macSrcExists(cname):
1721 srcs = [cname]
1722 elif macSrcExists(cmodulename):
1723 srcs = [cmodulename]
1724 elif macSrcExists(dirname, cname):
1725 # XXX(nnorwitz): If all the names ended with module, we
1726 # wouldn't need this condition. ibcarbon is the only one.
1727 srcs = [os.path.join(dirname, cname)]
1728 elif macSrcExists(dirname, cmodulename):
1729 srcs = [os.path.join(dirname, cmodulename)]
1730 else:
1731 raise RuntimeError("%s not found" % name)
1732
1733 # Here's the whole point: add the extension with sources
1734 exts.append(Extension(name, srcs + extra_srcs, **kwds))
1735
1736 # Core Foundation
1737 core_kwds = {'extra_compile_args': carbon_extra_compile_args,
1738 'extra_link_args': ['-framework', 'CoreFoundation'],
1739 }
1740 addMacExtension('_CF', core_kwds, ['cf/pycfbridge.c'])
1741 addMacExtension('autoGIL', core_kwds)
1742
Ronald Oussoren51f06332009-09-20 10:31:221743
1744
Neal Norwitz3e1ec3a2006-04-03 04:52:051745 # Carbon
1746 carbon_kwds = {'extra_compile_args': carbon_extra_compile_args,
1747 'extra_link_args': ['-framework', 'Carbon'],
1748 }
Anthony Baxtera2a26b92006-04-05 17:30:381749 CARBON_EXTS = ['ColorPicker', 'gestalt', 'MacOS', 'Nav',
1750 'OSATerminology', 'icglue',
Neal Norwitz3e1ec3a2006-04-03 04:52:051751 # All these are in subdirs
Anthony Baxtera2a26b92006-04-05 17:30:381752 '_AE', '_AH', '_App', '_CarbonEvt', '_Cm', '_Ctl',
Neal Norwitz3e1ec3a2006-04-03 04:52:051753 '_Dlg', '_Drag', '_Evt', '_File', '_Folder', '_Fm',
Anthony Baxtera2a26b92006-04-05 17:30:381754 '_Help', '_Icn', '_IBCarbon', '_List',
1755 '_Menu', '_Mlte', '_OSA', '_Res', '_Qd', '_Qdoffs',
Ronald Oussoren5640ce22008-06-05 12:58:241756 '_Scrap', '_Snd', '_TE',
Anthony Baxtera2a26b92006-04-05 17:30:381757 ]
Neal Norwitz3e1ec3a2006-04-03 04:52:051758 for name in CARBON_EXTS:
1759 addMacExtension(name, carbon_kwds)
1760
Ronald Oussoren5640ce22008-06-05 12:58:241761 # Workaround for a bug in the version of gcc shipped with Xcode 3.
1762 # The _Win extension should build just like the other Carbon extensions, but
1763 # this actually results in a hard crash of the linker.
1764 #
1765 if '-arch ppc64' in cflags and '-arch ppc' in cflags:
1766 win_kwds = {'extra_compile_args': carbon_extra_compile_args + ['-arch', 'i386', '-arch', 'ppc'],
1767 'extra_link_args': ['-framework', 'Carbon', '-arch', 'i386', '-arch', 'ppc'],
1768 }
1769 addMacExtension('_Win', win_kwds)
1770 else:
1771 addMacExtension('_Win', carbon_kwds)
1772
1773
Neal Norwitz3e1ec3a2006-04-03 04:52:051774 # Application Services & QuickTime
1775 app_kwds = {'extra_compile_args': carbon_extra_compile_args,
1776 'extra_link_args': ['-framework','ApplicationServices'],
1777 }
1778 addMacExtension('_Launch', app_kwds)
1779 addMacExtension('_CG', app_kwds)
1780
Just van Rossum05ced6a2002-11-24 23:15:571781 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
Ronald Oussoren090f8152006-03-30 20:18:331782 extra_compile_args=carbon_extra_compile_args,
1783 extra_link_args=['-framework', 'QuickTime',
Just van Rossum05ced6a2002-11-24 23:15:571784 '-framework', 'Carbon']) )
Neal Norwitz3e1ec3a2006-04-03 04:52:051785
Michael W. Hudson5b109102002-01-23 15:04:411786
Andrew M. Kuchlingfbe73762001-01-18 18:44:201787 self.extensions.extend(exts)
1788
1789 # Call the method for detecting whether _tkinter can be compiled
1790 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:281791
Skip Montanarod1287322007-03-06 15:41:381792 if '_tkinter' not in [e.name for e in self.extensions]:
1793 missing.append('_tkinter')
1794
Georg Brandl28523642013-10-13 21:38:441795## # Uncomment these lines if you want to play with xxmodule.c
1796## ext = Extension('xx', ['xxmodule.c'])
1797## self.extensions.append(ext)
1798
Skip Montanarod1287322007-03-06 15:41:381799 return missing
1800
Ned Deilya2a9f572013-10-25 07:30:101801 def detect_tkinter_explicitly(self):
1802 # Build _tkinter using explicit locations for Tcl/Tk.
1803 #
1804 # This is enabled when both arguments are given to ./configure:
1805 #
1806 # --with-tcltk-includes="-I/path/to/tclincludes \
1807 # -I/path/to/tkincludes"
1808 # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
1809 # -L/path/to/tklibs -ltkm.n"
1810 #
Martin Panter8d496ad2016-06-02 10:35:441811 # These values can also be specified or overridden via make:
Ned Deilya2a9f572013-10-25 07:30:101812 # make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1813 #
1814 # This can be useful for building and testing tkinter with multiple
1815 # versions of Tcl/Tk. Note that a build of Tk depends on a particular
1816 # build of Tcl so you need to specify both arguments and use care when
1817 # overriding.
1818
1819 # The _TCLTK variables are created in the Makefile sharedmods target.
1820 tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
1821 tcltk_libs = os.environ.get('_TCLTK_LIBS')
1822 if not (tcltk_includes and tcltk_libs):
1823 # Resume default configuration search.
1824 return 0
1825
1826 extra_compile_args = tcltk_includes.split()
1827 extra_link_args = tcltk_libs.split()
1828 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1829 define_macros=[('WITH_APPINIT', 1)],
1830 extra_compile_args = extra_compile_args,
1831 extra_link_args = extra_link_args,
1832 )
1833 self.extensions.append(ext)
1834 return 1
1835
Jack Jansen0b06be72002-06-21 14:48:381836 def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
1837 # The _tkinter module, using frameworks. Since frameworks are quite
1838 # different the UNIX search logic is not sharable.
1839 from os.path import join, exists
1840 framework_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:431841 '/Library/Frameworks',
Ronald Oussorencea1ddb2009-03-04 21:30:121842 '/System/Library/Frameworks/',
Jack Jansen0b06be72002-06-21 14:48:381843 join(os.getenv('HOME'), '/Library/Frameworks')
1844 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:201845
Ronald Oussoren593e4ca2010-06-03 09:47:211846 sysroot = macosx_sdk_root()
1847
Skip Montanaro0174ddd2005-12-30 05:01:261848 # Find the directory that contains the Tcl.framework and Tk.framework
Jack Jansen0b06be72002-06-21 14:48:381849 # bundles.
1850 # XXX distutils should support -F!
1851 for F in framework_dirs:
Tim Peters2c60f7a2003-01-29 03:49:431852 # both Tcl.framework and Tk.framework should be present
Ronald Oussoren593e4ca2010-06-03 09:47:211853
1854
Jack Jansen0b06be72002-06-21 14:48:381855 for fw in 'Tcl', 'Tk':
Ronald Oussoren593e4ca2010-06-03 09:47:211856 if is_macosx_sdk_path(F):
1857 if not exists(join(sysroot, F[1:], fw + '.framework')):
1858 break
1859 else:
1860 if not exists(join(F, fw + '.framework')):
1861 break
Jack Jansen0b06be72002-06-21 14:48:381862 else:
1863 # ok, F is now directory with both frameworks. Continure
1864 # building
1865 break
1866 else:
1867 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1868 # will now resume.
1869 return 0
Tim Peters2c60f7a2003-01-29 03:49:431870
Jack Jansen0b06be72002-06-21 14:48:381871 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1872 # frameworks. In later release we should hopefully be able to pass
Tim Peters2c60f7a2003-01-29 03:49:431873 # the -F option to gcc, which specifies a framework lookup path.
Jack Jansen0b06be72002-06-21 14:48:381874 #
1875 include_dirs = [
Tim Peters2c60f7a2003-01-29 03:49:431876 join(F, fw + '.framework', H)
Jack Jansen0b06be72002-06-21 14:48:381877 for fw in 'Tcl', 'Tk'
1878 for H in 'Headers', 'Versions/Current/PrivateHeaders'
1879 ]
1880
Tim Peters2c60f7a2003-01-29 03:49:431881 # For 8.4a2, the X11 headers are not included. Rather than include a
Jack Jansen0b06be72002-06-21 14:48:381882 # complicated search, this is a hard-coded path. It could bail out
1883 # if X11 libs are not found...
1884 include_dirs.append('/usr/X11R6/include')
1885 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
1886
Ronald Oussoren5640ce22008-06-05 12:58:241887 # All existing framework builds of Tcl/Tk don't support 64-bit
1888 # architectures.
1889 cflags = sysconfig.get_config_vars('CFLAGS')[0]
1890 archs = re.findall('-arch\s+(\w+)', cflags)
Ronald Oussoren593e4ca2010-06-03 09:47:211891
1892 if is_macosx_sdk_path(F):
1893 fp = os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(os.path.join(sysroot, F[1:]),))
1894 else:
1895 fp = os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(F,))
1896
Ronald Oussoren91a11a42009-09-15 18:33:331897 detected_archs = []
1898 for ln in fp:
1899 a = ln.split()[-1]
1900 if a in archs:
1901 detected_archs.append(ln.split()[-1])
1902 fp.close()
Ronald Oussoren5640ce22008-06-05 12:58:241903
Ronald Oussoren91a11a42009-09-15 18:33:331904 for a in detected_archs:
1905 frameworks.append('-arch')
1906 frameworks.append(a)
Ronald Oussoren5640ce22008-06-05 12:58:241907
Jack Jansen0b06be72002-06-21 14:48:381908 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1909 define_macros=[('WITH_APPINIT', 1)],
1910 include_dirs = include_dirs,
1911 libraries = [],
Ronald Oussoren5640ce22008-06-05 12:58:241912 extra_compile_args = frameworks[2:],
Jack Jansen0b06be72002-06-21 14:48:381913 extra_link_args = frameworks,
1914 )
1915 self.extensions.append(ext)
1916 return 1
1917
Andrew M. Kuchlingfbe73762001-01-18 18:44:201918 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:231919 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:411920
Ned Deilya2a9f572013-10-25 07:30:101921 # Check whether --with-tcltk-includes and --with-tcltk-libs were
1922 # configured or passed into the make target. If so, use these values
1923 # to build tkinter and bypass the searches for Tcl and TK in standard
1924 # locations.
1925 if self.detect_tkinter_explicitly():
1926 return
1927
Jack Jansen0b06be72002-06-21 14:48:381928 # Rather than complicate the code below, detecting and building
1929 # AquaTk is a separate method. Only one Tkinter will be built on
1930 # Darwin - either AquaTk, if it is found, or X11 based Tk.
doko@python.orgd65e2ba2013-01-31 22:52:031931 if (host_platform == 'darwin' and
Skip Montanaro0174ddd2005-12-30 05:01:261932 self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
Tim Peters2c60f7a2003-01-29 03:49:431933 return
Jack Jansen0b06be72002-06-21 14:48:381934
Andrew M. Kuchlingfbe73762001-01-18 18:44:201935 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:011936 # The versions with dots are used on Unix, and the versions without
1937 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:201938 tcllib = tklib = tcl_includes = tk_includes = None
Guilherme Polofb118352009-08-16 14:34:261939 for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
1940 '8.2', '82', '8.1', '81', '8.0', '80']:
Tarek Ziadé35a3f572010-03-05 00:29:381941 tklib = self.compiler.find_library_file(lib_dirs,
Tarek Ziadée670e5a2009-07-06 12:50:461942 'tk' + version)
Tarek Ziadé35a3f572010-03-05 00:29:381943 tcllib = self.compiler.find_library_file(lib_dirs,
Tarek Ziadée670e5a2009-07-06 12:50:461944 'tcl' + version)
Michael W. Hudson5b109102002-01-23 15:04:411945 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:231946 # Exit the loop when we've found the Tcl/Tk libraries
1947 break
Andrew M. Kuchling00e0f212001-01-17 15:23:231948
Fredrik Lundhade711a2001-01-24 08:00:281949 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:201950 if tklib and tcllib:
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351951 # Check for the include files on Debian and {Free,Open}BSD, where
Andrew M. Kuchlingfbe73762001-01-18 18:44:201952 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351953 dotversion = version
doko@python.orgd65e2ba2013-01-31 22:52:031954 if '.' not in dotversion and "bsd" in host_platform.lower():
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351955 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1956 # but the include subdirs are named like .../include/tcl8.3.
1957 dotversion = dotversion[:-1] + '.' + dotversion[-1]
1958 tcl_include_sub = []
1959 tk_include_sub = []
1960 for dir in inc_dirs:
1961 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
1962 tk_include_sub += [dir + os.sep + "tk" + dotversion]
1963 tk_include_sub += tcl_include_sub
1964 tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub)
1965 tk_includes = find_file('tk.h', inc_dirs, tk_include_sub)
Andrew M. Kuchling00e0f212001-01-17 15:23:231966
Martin v. Löwise86a59a2003-05-03 08:45:511967 if (tcllib is None or tklib is None or
Andrew M. Kuchlingfbe73762001-01-18 18:44:201968 tcl_includes is None or tk_includes is None):
Andrew M. Kuchling3c0aa7e2004-03-21 18:57:351969 self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
Andrew M. Kuchlingfbe73762001-01-18 18:44:201970 return
Fredrik Lundhade711a2001-01-24 08:00:281971
Andrew M. Kuchlingfbe73762001-01-18 18:44:201972 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:231973
Andrew M. Kuchlingfbe73762001-01-18 18:44:201974 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
1975 for dir in tcl_includes + tk_includes:
1976 if dir not in include_dirs:
1977 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:281978
Andrew M. Kuchlingfbe73762001-01-18 18:44:201979 # Check for various platform-specific directories
doko@python.orgd65e2ba2013-01-31 22:52:031980 if host_platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:201981 include_dirs.append('/usr/openwin/include')
1982 added_lib_dirs.append('/usr/openwin/lib')
1983 elif os.path.exists('/usr/X11R6/include'):
1984 include_dirs.append('/usr/X11R6/include')
Martin v. Löwisfba73692004-11-13 11:13:351985 added_lib_dirs.append('/usr/X11R6/lib64')
Andrew M. Kuchlingfbe73762001-01-18 18:44:201986 added_lib_dirs.append('/usr/X11R6/lib')
1987 elif os.path.exists('/usr/X11R5/include'):
1988 include_dirs.append('/usr/X11R5/include')
1989 added_lib_dirs.append('/usr/X11R5/lib')
1990 else:
Fredrik Lundhade711a2001-01-24 08:00:281991 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:201992 include_dirs.append('/usr/X11/include')
1993 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:231994
Jason Tishler9181c942003-02-05 15:16:171995 # If Cygwin, then verify that X is installed before proceeding
doko@python.orgd65e2ba2013-01-31 22:52:031996 if host_platform == 'cygwin':
Jason Tishler9181c942003-02-05 15:16:171997 x11_inc = find_file('X11/Xlib.h', [], include_dirs)
1998 if x11_inc is None:
1999 return
2000
Andrew M. Kuchlingfbe73762001-01-18 18:44:202001 # Check for BLT extension
Tarek Ziadé35a3f572010-03-05 00:29:382002 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
Tarek Ziadée670e5a2009-07-06 12:50:462003 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:202004 defs.append( ('WITH_BLT', 1) )
2005 libs.append('BLT8.0')
Tarek Ziadé35a3f572010-03-05 00:29:382006 elif self.compiler.find_library_file(lib_dirs + added_lib_dirs,
Tarek Ziadée670e5a2009-07-06 12:50:462007 'BLT'):
Martin v. Löwis427a2902002-12-12 20:23:382008 defs.append( ('WITH_BLT', 1) )
2009 libs.append('BLT')
Andrew M. Kuchling00e0f212001-01-17 15:23:232010
Andrew M. Kuchlingfbe73762001-01-18 18:44:202011 # Add the Tcl/Tk libraries
Jason Tishlercccac1a2003-02-05 15:06:462012 libs.append('tk'+ version)
2013 libs.append('tcl'+ version)
Fredrik Lundhade711a2001-01-24 08:00:282014
doko@python.orgd65e2ba2013-01-31 22:52:032015 if host_platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:202016 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:232017
Martin v. Löwis3db5b8c2001-07-24 06:54:012018 # Finally, link with the X11 libraries (not appropriate on cygwin)
doko@python.orgd65e2ba2013-01-31 22:52:032019 if host_platform != "cygwin":
Martin v. Löwis3db5b8c2001-07-24 06:54:012020 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:232021
Andrew M. Kuchlingfbe73762001-01-18 18:44:202022 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
2023 define_macros=[('WITH_APPINIT', 1)] + defs,
2024 include_dirs = include_dirs,
2025 libraries = libs,
2026 library_dirs = added_lib_dirs,
2027 )
2028 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:282029
Andrew M. Kuchlingfbe73762001-01-18 18:44:202030 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:232031 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:282032 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:232033 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:282034 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:232035 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:282036 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:232037
Thomas Heller8bdf81d2008-03-04 20:09:112038 def configure_ctypes_darwin(self, ext):
2039 # Darwin (OS X) uses preconfigured files, in
2040 # the Modules/_ctypes/libffi_osx directory.
Neil Schemenauerc59c5f32009-02-05 16:32:292041 srcdir = sysconfig.get_config_var('srcdir')
Thomas Heller8bdf81d2008-03-04 20:09:112042 ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
2043 '_ctypes', 'libffi_osx'))
2044 sources = [os.path.join(ffi_srcdir, p)
2045 for p in ['ffi.c',
Ronald Oussoren5640ce22008-06-05 12:58:242046 'x86/darwin64.S',
Thomas Heller8bdf81d2008-03-04 20:09:112047 'x86/x86-darwin.S',
2048 'x86/x86-ffi_darwin.c',
2049 'x86/x86-ffi64.c',
2050 'powerpc/ppc-darwin.S',
2051 'powerpc/ppc-darwin_closure.S',
2052 'powerpc/ppc-ffi_darwin.c',
2053 'powerpc/ppc64-darwin_closure.S',
2054 ]]
2055
2056 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé35a3f572010-03-05 00:29:382057 self.compiler.src_extensions.append('.S')
Thomas Heller8bdf81d2008-03-04 20:09:112058
2059 include_dirs = [os.path.join(ffi_srcdir, 'include'),
2060 os.path.join(ffi_srcdir, 'powerpc')]
2061 ext.include_dirs.extend(include_dirs)
2062 ext.sources.extend(sources)
2063 return True
2064
Thomas Hellereba43c12006-04-07 19:04:092065 def configure_ctypes(self, ext):
Martin v. Löwis9176fc12006-04-11 11:12:432066 if not self.use_system_libffi:
doko@python.orgd65e2ba2013-01-31 22:52:032067 if host_platform == 'darwin':
Thomas Heller8bdf81d2008-03-04 20:09:112068 return self.configure_ctypes_darwin(ext)
2069
Neil Schemenauerc59c5f32009-02-05 16:32:292070 srcdir = sysconfig.get_config_var('srcdir')
Martin v. Löwis9176fc12006-04-11 11:12:432071 ffi_builddir = os.path.join(self.build_temp, 'libffi')
2072 ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
2073 '_ctypes', 'libffi'))
2074 ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
Thomas Hellercf567c12006-03-08 19:51:582075
Thomas Heller5e218b42006-04-27 15:50:422076 from distutils.dep_util import newer_group
2077
2078 config_sources = [os.path.join(ffi_srcdir, fname)
Martin v. Löwisf1a4aa32007-02-14 11:30:562079 for fname in os.listdir(ffi_srcdir)
2080 if os.path.isfile(os.path.join(ffi_srcdir, fname))]
Thomas Heller5e218b42006-04-27 15:50:422081 if self.force or newer_group(config_sources,
2082 ffi_configfile):
Martin v. Löwis9176fc12006-04-11 11:12:432083 from distutils.dir_util import mkpath
2084 mkpath(ffi_builddir)
doko@python.orgd65e2ba2013-01-31 22:52:032085 config_args = [arg for arg in sysconfig.get_config_var("CONFIG_ARGS").split()
2086 if (('--host=' in arg) or ('--build=' in arg))]
Christian Heimes6fd32482012-09-06 16:02:492087 if not self.verbose:
2088 config_args.append("-q")
Thomas Hellercf567c12006-03-08 19:51:582089
Martin v. Löwis9176fc12006-04-11 11:12:432090 # Pass empty CFLAGS because we'll just append the resulting
2091 # CFLAGS to Python's; -g or -O2 is to be avoided.
2092 cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
2093 % (ffi_builddir, ffi_srcdir, " ".join(config_args))
Thomas Hellercf567c12006-03-08 19:51:582094
Martin v. Löwis9176fc12006-04-11 11:12:432095 res = os.system(cmd)
2096 if res or not os.path.exists(ffi_configfile):
2097 print "Failed to configure _ctypes module"
2098 return False
Thomas Hellercf567c12006-03-08 19:51:582099
Martin v. Löwis9176fc12006-04-11 11:12:432100 fficonfig = {}
Antoine Pitrou1379b842010-01-13 11:57:422101 with open(ffi_configfile) as f:
2102 exec f in fficonfig
Thomas Hellercf567c12006-03-08 19:51:582103
Martin v. Löwis9176fc12006-04-11 11:12:432104 # Add .S (preprocessed assembly) to C compiler source extensions.
Tarek Ziadé35a3f572010-03-05 00:29:382105 self.compiler.src_extensions.append('.S')
Thomas Hellercf567c12006-03-08 19:51:582106
Martin v. Löwis9176fc12006-04-11 11:12:432107 include_dirs = [os.path.join(ffi_builddir, 'include'),
Antoine Pitrou8c510e72010-01-13 11:47:492108 ffi_builddir,
2109 os.path.join(ffi_srcdir, 'src')]
Martin v. Löwis9176fc12006-04-11 11:12:432110 extra_compile_args = fficonfig['ffi_cflags'].split()
Thomas Hellereba43c12006-04-07 19:04:092111
Antoine Pitrou8c510e72010-01-13 11:47:492112 ext.sources.extend(os.path.join(ffi_srcdir, f) for f in
2113 fficonfig['ffi_sources'])
Martin v. Löwis9176fc12006-04-11 11:12:432114 ext.include_dirs.extend(include_dirs)
2115 ext.extra_compile_args.extend(extra_compile_args)
Thomas Heller795246c2006-04-07 19:27:562116 return True
Thomas Hellereba43c12006-04-07 19:04:092117
Martin v. Löwis9176fc12006-04-11 11:12:432118 def detect_ctypes(self, inc_dirs, lib_dirs):
2119 self.use_system_libffi = False
Thomas Hellereba43c12006-04-07 19:04:092120 include_dirs = []
2121 extra_compile_args = []
Thomas Heller17984892006-08-04 18:57:342122 extra_link_args = []
Thomas Hellercf567c12006-03-08 19:51:582123 sources = ['_ctypes/_ctypes.c',
2124 '_ctypes/callbacks.c',
2125 '_ctypes/callproc.c',
2126 '_ctypes/stgdict.c',
Thomas Heller001d3a12010-08-08 17:56:412127 '_ctypes/cfield.c']
Thomas Hellercf567c12006-03-08 19:51:582128 depends = ['_ctypes/ctypes.h']
2129
doko@python.orgd65e2ba2013-01-31 22:52:032130 if host_platform == 'darwin':
Ronald Oussoren30a171f2010-09-16 11:35:072131 sources.append('_ctypes/malloc_closure.c')
Thomas Hellercf567c12006-03-08 19:51:582132 sources.append('_ctypes/darwin/dlfcn_simple.c')
Thomas Heller8bdf81d2008-03-04 20:09:112133 extra_compile_args.append('-DMACOSX')
Thomas Hellercf567c12006-03-08 19:51:582134 include_dirs.append('_ctypes/darwin')
2135# XXX Is this still needed?
2136## extra_link_args.extend(['-read_only_relocs', 'warning'])
2137
doko@python.orgd65e2ba2013-01-31 22:52:032138 elif host_platform == 'sunos5':
Martin v. Löwis73f12a32006-08-09 23:42:182139 # XXX This shouldn't be necessary; it appears that some
2140 # of the assembler code is non-PIC (i.e. it has relocations
2141 # when it shouldn't. The proper fix would be to rewrite
2142 # the assembler code to be PIC.
2143 # This only works with GCC; the Sun compiler likely refuses
2144 # this option. If you want to compile ctypes with the Sun
2145 # compiler, please research a proper solution, instead of
2146 # finding some -z option for the Sun compiler.
Thomas Heller17984892006-08-04 18:57:342147 extra_link_args.append('-mimpure-text')
2148
doko@python.orgd65e2ba2013-01-31 22:52:032149 elif host_platform.startswith('hp-ux'):
Thomas Heller03b75dd2008-05-20 19:53:472150 extra_link_args.append('-fPIC')
2151
Thomas Hellercf567c12006-03-08 19:51:582152 ext = Extension('_ctypes',
2153 include_dirs=include_dirs,
2154 extra_compile_args=extra_compile_args,
Thomas Heller17984892006-08-04 18:57:342155 extra_link_args=extra_link_args,
Martin v. Löwis9176fc12006-04-11 11:12:432156 libraries=[],
Thomas Hellercf567c12006-03-08 19:51:582157 sources=sources,
2158 depends=depends)
2159 ext_test = Extension('_ctypes_test',
2160 sources=['_ctypes/_ctypes_test.c'])
2161 self.extensions.extend([ext, ext_test])
2162
Martin v. Löwis9176fc12006-04-11 11:12:432163 if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
2164 return
2165
doko@python.orgd65e2ba2013-01-31 22:52:032166 if host_platform == 'darwin':
Thomas Heller8bdf81d2008-03-04 20:09:112167 # OS X 10.5 comes with libffi.dylib; the include files are
2168 # in /usr/include/ffi
2169 inc_dirs.append('/usr/include/ffi')
2170
Benjamin Peterson1c335e62010-01-01 15:16:292171 ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
Matthias Kloseca6d9e92010-04-21 21:45:302172 if not ffi_inc or ffi_inc[0] == '':
Benjamin Peterson1c335e62010-01-01 15:16:292173 ffi_inc = find_file('ffi.h', [], inc_dirs)
Martin v. Löwis9176fc12006-04-11 11:12:432174 if ffi_inc is not None:
2175 ffi_h = ffi_inc[0] + '/ffi.h'
Christian Heimes37471dc2016-09-18 12:40:152176 with open(ffi_h) as f:
2177 for line in f:
2178 line = line.strip()
2179 if line.startswith(('#define LIBFFI_H',
2180 '#define ffi_wrapper_h')):
2181 break
2182 else:
Martin v. Löwis9176fc12006-04-11 11:12:432183 ffi_inc = None
Christian Heimes37471dc2016-09-18 12:40:152184 print('Header file {} does not define LIBFFI_H or '
2185 'ffi_wrapper_h'.format(ffi_h))
Martin v. Löwis9176fc12006-04-11 11:12:432186 ffi_lib = None
2187 if ffi_inc is not None:
2188 for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):
Tarek Ziadé35a3f572010-03-05 00:29:382189 if (self.compiler.find_library_file(lib_dirs, lib_name)):
Martin v. Löwis9176fc12006-04-11 11:12:432190 ffi_lib = lib_name
2191 break
2192
2193 if ffi_inc and ffi_lib:
2194 ext.include_dirs.extend(ffi_inc)
2195 ext.libraries.append(ffi_lib)
2196 self.use_system_libffi = True
2197
Christian Heimes4bb9b9a2018-02-25 11:31:172198 if sysconfig.get_config_var('HAVE_LIBDL'):
2199 # for dlopen, see bpo-32647
2200 ext.libraries.append('dl')
2201
Christian Heimes38487a02018-01-27 08:39:392202 def _detect_nis(self, inc_dirs, lib_dirs):
2203 if host_platform in {'win32', 'cygwin', 'qnx6'}:
2204 return None
2205
2206 libs = []
2207 library_dirs = []
2208 includes_dirs = []
2209
2210 # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
2211 # moved headers and libraries to libtirpc and libnsl. The headers
2212 # are in tircp and nsl sub directories.
2213 rpcsvc_inc = find_file(
2214 'rpcsvc/yp_prot.h', inc_dirs,
2215 [os.path.join(inc_dir, 'nsl') for inc_dir in inc_dirs]
2216 )
2217 rpc_inc = find_file(
2218 'rpc/rpc.h', inc_dirs,
2219 [os.path.join(inc_dir, 'tirpc') for inc_dir in inc_dirs]
2220 )
2221 if rpcsvc_inc is None or rpc_inc is None:
2222 # not found
2223 return None
2224 includes_dirs.extend(rpcsvc_inc)
2225 includes_dirs.extend(rpc_inc)
2226
2227 if self.compiler.find_library_file(lib_dirs, 'nsl'):
2228 libs.append('nsl')
2229 else:
2230 # libnsl-devel: check for libnsl in nsl/ subdirectory
2231 nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in lib_dirs]
2232 libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
2233 if libnsl is not None:
2234 library_dirs.append(os.path.dirname(libnsl))
2235 libs.append('nsl')
2236
2237 if self.compiler.find_library_file(lib_dirs, 'tirpc'):
2238 libs.append('tirpc')
2239
2240 return Extension(
2241 'nis', ['nismodule.c'],
2242 libraries=libs,
2243 library_dirs=library_dirs,
2244 include_dirs=includes_dirs
2245 )
2246
Martin v. Löwis9176fc12006-04-11 11:12:432247
Andrew M. Kuchlingf52d27e2001-05-21 20:29:272248class PyBuildInstall(install):
2249 # Suppress the warning about installation into the lib_dynload
2250 # directory, which is not in sys.path when running Python during
2251 # installation:
2252 def initialize_options (self):
2253 install.initialize_options(self)
2254 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:412255
Michael W. Hudson529a5052002-12-17 16:47:172256class PyBuildInstallLib(install_lib):
2257 # Do exactly what install_lib does but make sure correct access modes get
2258 # set on installed directories and files. All installed files with get
2259 # mode 644 unless they are a shared library in which case they will get
2260 # mode 755. All installed directories will get mode 755.
2261
2262 so_ext = sysconfig.get_config_var("SO")
2263
2264 def install(self):
2265 outfiles = install_lib.install(self)
2266 self.set_file_modes(outfiles, 0644, 0755)
2267 self.set_dir_modes(self.install_dir, 0755)
2268 return outfiles
2269
2270 def set_file_modes(self, files, defaultMode, sharedLibMode):
2271 if not self.is_chmod_supported(): return
2272 if not files: return
2273
2274 for filename in files:
2275 if os.path.islink(filename): continue
2276 mode = defaultMode
2277 if filename.endswith(self.so_ext): mode = sharedLibMode
2278 log.info("changing mode of %s to %o", filename, mode)
2279 if not self.dry_run: os.chmod(filename, mode)
2280
2281 def set_dir_modes(self, dirname, mode):
2282 if not self.is_chmod_supported(): return
2283 os.path.walk(dirname, self.set_dir_modes_visitor, mode)
2284
2285 def set_dir_modes_visitor(self, mode, dirname, names):
2286 if os.path.islink(dirname): return
2287 log.info("changing mode of %s to %o", dirname, mode)
2288 if not self.dry_run: os.chmod(dirname, mode)
2289
2290 def is_chmod_supported(self):
2291 return hasattr(os, 'chmod')
2292
Guido van Rossum14ee89c2003-02-20 02:52:042293SUMMARY = """
2294Python is an interpreted, interactive, object-oriented programming
2295language. It is often compared to Tcl, Perl, Scheme or Java.
2296
2297Python combines remarkable power with very clear syntax. It has
2298modules, classes, exceptions, very high level dynamic data types, and
2299dynamic typing. There are interfaces to many system calls and
2300libraries, as well as to various windowing systems (X11, Motif, Tk,
2301Mac, MFC). New built-in modules are easily written in C or C++. Python
2302is also usable as an extension language for applications that need a
2303programmable interface.
2304
2305The Python implementation is portable: it runs on many brands of UNIX,
2306on Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't
2307listed here, it may still be supported, if there's a C compiler for
2308it. Ask around on comp.lang.python -- or just try compiling Python
2309yourself.
2310"""
2311
2312CLASSIFIERS = """
Guido van Rossum14ee89c2003-02-20 02:52:042313Development Status :: 6 - Mature
2314License :: OSI Approved :: Python Software Foundation License
2315Natural Language :: English
2316Programming Language :: C
2317Programming Language :: Python
2318Topic :: Software Development
2319"""
2320
Andrew M. Kuchling00e0f212001-01-17 15:23:232321def main():
Andrew M. Kuchling62686692001-05-21 20:48:092322 # turn off warnings when deprecated modules are imported
2323 import warnings
2324 warnings.filterwarnings("ignore",category=DeprecationWarning)
Guido van Rossum14ee89c2003-02-20 02:52:042325 setup(# PyPI Metadata (PEP 301)
2326 name = "Python",
2327 version = sys.version.split()[0],
2328 url = "http://www.python.org/%s" % sys.version[:3],
2329 maintainer = "Guido van Rossum and the Python community",
2330 maintainer_email = "python-dev@python.org",
2331 description = "A high-level object-oriented programming language",
2332 long_description = SUMMARY.strip(),
2333 license = "PSF license",
2334 classifiers = filter(None, CLASSIFIERS.split("\n")),
2335 platforms = ["Many"],
2336
2337 # Build info
Michael W. Hudson529a5052002-12-17 16:47:172338 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall,
2339 'install_lib':PyBuildInstallLib},
Andrew M. Kuchling00e0f212001-01-17 15:23:232340 # The struct module is defined here, because build_ext won't be
2341 # called unless there's at least one extension module defined.
Bob Ippolito7ccc95a2006-05-23 19:11:342342 ext_modules=[Extension('_struct', ['_struct.c'])],
Andrew M. Kuchlingaece4272001-02-28 20:56:492343
2344 # Scripts to install
Skip Montanaro852f7992004-06-26 22:29:422345 scripts = ['Tools/scripts/pydoc', 'Tools/scripts/idle',
Martin v. Löwiscdbc9772008-03-24 12:57:532346 'Tools/scripts/2to3',
Skip Montanaro852f7992004-06-26 22:29:422347 'Lib/smtpd.py']
Andrew M. Kuchling00e0f212001-01-17 15:23:232348 )
Fredrik Lundhade711a2001-01-24 08:00:282349
Andrew M. Kuchling00e0f212001-01-17 15:23:232350# --install-platlib
2351if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:232352 main()