1 # Autodetecting setup.py script for building the Python extensions
4 __version__
= "$Revision$"
6 import sys
, os
, imp
, re
, optparse
9 from distutils
import log
10 from distutils
import sysconfig
11 from distutils
import text_file
12 from distutils
.errors
import *
13 from distutils
.core
import Extension
, setup
14 from distutils
.command
.build_ext
import build_ext
15 from distutils
.command
.install
import install
16 from distutils
.command
.install_lib
import install_lib
18 # This global variable is used to hold the list of modules to be disabled.
19 disabled_module_list
= []
21 def add_dir_to_list(dirlist
, dir):
22 """Add the directory 'dir' to the list 'dirlist' (at the front) if
23 1) 'dir' is not already in 'dirlist'
24 2) 'dir' actually exists, and is a directory."""
25 if dir is not None and os
.path
.isdir(dir) and dir not in dirlist
:
26 dirlist
.insert(0, dir)
28 def find_file(filename
, std_dirs
, paths
):
29 """Searches for the directory where a given file is located,
30 and returns a possibly-empty list of additional directories, or None
31 if the file couldn't be found at all.
33 'filename' is the name of a file, such as readline.h or libcrypto.a.
34 'std_dirs' is the list of standard system directories; if the
35 file is found in one of them, no additional directives are needed.
36 'paths' is a list of additional locations to check; if the file is
37 found in one of them, the resulting list will contain the directory.
40 # Check the standard locations
42 f
= os
.path
.join(dir, filename
)
43 if os
.path
.exists(f
): return []
45 # Check the additional directories
47 f
= os
.path
.join(dir, filename
)
54 def find_library_file(compiler
, libname
, std_dirs
, paths
):
55 result
= compiler
.find_library_file(std_dirs
+ paths
, libname
)
59 # Check whether the found file is in one of the standard directories
60 dirname
= os
.path
.dirname(result
)
62 # Ensure path doesn't end with path separator
67 # Otherwise, it must have been in one of the additional directories,
68 # so we have to figure out which one.
70 # Ensure path doesn't end with path separator
75 assert False, "Internal error: Path not found in std_dirs or paths"
77 def module_enabled(extlist
, modname
):
78 """Returns whether the module 'modname' is present in the list
79 of extensions 'extlist'."""
80 extlist
= [ext
for ext
in extlist
if ext
.name
== modname
]
83 def find_module_file(module
, dirlist
):
84 """Find a module in a set of possible folders. If it is not found
85 return the unadorned filename"""
86 list = find_file(module
, [], dirlist
)
90 log
.info("WARNING: multiple copies of %s found"%module
)
91 return os
.path
.join(list[0], module
)
93 class PyBuildExt(build_ext
):
95 def __init__(self
, dist
):
96 build_ext
.__init
__(self
, dist
)
99 def build_extensions(self
):
101 # Detect which modules should be compiled
102 missing
= self
.detect_modules()
104 # Remove modules that are present on the disabled list
105 extensions
= [ext
for ext
in self
.extensions
106 if ext
.name
not in disabled_module_list
]
107 # move ctypes to the end, it depends on other modules
108 ext_map
= dict((ext
.name
, i
) for i
, ext
in enumerate(extensions
))
109 if "_ctypes" in ext_map
:
110 ctypes
= extensions
.pop(ext_map
["_ctypes"])
111 extensions
.append(ctypes
)
112 self
.extensions
= extensions
114 # Fix up the autodetected modules, prefixing all the source files
115 # with Modules/ and adding Python's include directory to the path.
116 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
118 # Maybe running on Windows but not using CYGWIN?
119 raise ValueError("No source directory; cannot proceed.")
121 # Figure out the location of the source code for extension modules
122 # (This logic is copied in distutils.test.test_sysconfig,
123 # so building in a separate directory does not break test_distutils.)
124 moddir
= os
.path
.join(os
.getcwd(), srcdir
, 'Modules')
125 moddir
= os
.path
.normpath(moddir
)
126 srcdir
, tail
= os
.path
.split(moddir
)
127 srcdir
= os
.path
.normpath(srcdir
)
128 moddir
= os
.path
.normpath(moddir
)
130 moddirlist
= [moddir
]
131 incdirlist
= ['./Include']
133 # Platform-dependent module source and include directories
134 platform
= self
.get_platform()
136 alldirlist
= moddirlist
+ incdirlist
138 # Fix up the paths for scripts, too
139 self
.distribution
.scripts
= [os
.path
.join(srcdir
, filename
)
140 for filename
in self
.distribution
.scripts
]
142 # Python header files
143 headers
= glob("Include/*.h") + ["pyconfig.h"]
145 for ext
in self
.extensions
[:]:
146 ext
.sources
= [ find_module_file(filename
, moddirlist
)
147 for filename
in ext
.sources
]
148 if ext
.depends
is not None:
149 ext
.depends
= [find_module_file(filename
, alldirlist
)
150 for filename
in ext
.depends
]
153 # re-compile extensions if a header file has been changed
154 ext
.depends
.extend(headers
)
156 ext
.include_dirs
.append( '.' ) # to get config.h
157 for incdir
in incdirlist
:
158 ext
.include_dirs
.append( os
.path
.join(srcdir
, incdir
) )
160 # If a module has already been built statically,
161 # don't build it here
162 if ext
.name
in sys
.builtin_module_names
:
163 self
.extensions
.remove(ext
)
165 if platform
!= 'mac':
166 # Parse Modules/Setup and Modules/Setup.local to figure out which
167 # modules are turned on in the file.
169 for filename
in ('Modules/Setup', 'Modules/Setup.local'):
170 input = text_file
.TextFile(filename
, join_lines
=1)
172 line
= input.readline()
175 remove_modules
.append(line
[0])
178 for ext
in self
.extensions
[:]:
179 if ext
.name
in remove_modules
:
180 self
.extensions
.remove(ext
)
182 # When you run "make CC=altcc" or something similar, you really want
183 # those environment variables passed into the setup.py phase. Here's
184 # a small set of useful ones.
185 compiler
= os
.environ
.get('CC')
187 # unfortunately, distutils doesn't let us provide separate C and C++
189 if compiler
is not None:
190 (ccshared
,cflags
) = sysconfig
.get_config_vars('CCSHARED','CFLAGS')
191 args
['compiler_so'] = compiler
+ ' ' + ccshared
+ ' ' + cflags
192 self
.compiler
.set_executables(**args
)
194 build_ext
.build_extensions(self
)
196 longest
= max([len(e
.name
) for e
in self
.extensions
])
198 longest
= max(longest
, max([len(name
) for name
in self
.failed
]))
200 def print_three_column(lst
):
201 lst
.sort(key
=str.lower
)
202 # guarantee zip() doesn't drop anything
205 for e
, f
, g
in zip(lst
[::3], lst
[1::3], lst
[2::3]):
206 print("%-*s %-*s %-*s" % (longest
, e
, longest
, f
,
211 print("Failed to find the necessary bits to build these modules:")
212 print_three_column(missing
)
213 print("To find the necessary bits, look in setup.py in"
214 " detect_modules() for the module's name.")
218 failed
= self
.failed
[:]
220 print("Failed to build these modules:")
221 print_three_column(failed
)
224 def build_extension(self
, ext
):
226 if ext
.name
== '_ctypes':
227 if not self
.configure_ctypes(ext
):
231 build_ext
.build_extension(self
, ext
)
232 except (CCompilerError
, DistutilsError
) as why
:
233 self
.announce('WARNING: building of extension "%s" failed: %s' %
234 (ext
.name
, sys
.exc_info()[1]))
235 self
.failed
.append(ext
.name
)
237 # Workaround for Mac OS X: The Carbon-based modules cannot be
238 # reliably imported into a command-line Python
239 if 'Carbon' in ext
.extra_link_args
:
241 'WARNING: skipping import check for Carbon-based "%s"' %
245 if self
.get_platform() == 'darwin' and (
246 sys
.maxsize
> 2**32 and '-arch' in ext
.extra_link_args
):
247 # Don't bother doing an import check when an extension was
248 # build with an explicit '-arch' flag on OSX. That's currently
249 # only used to build 32-bit only extensions in a 4-way
250 # universal build and loading 32-bit code into a 64-bit
253 'WARNING: skipping import check for "%s"' %
257 # Workaround for Cygwin: Cygwin currently has fork issues when many
258 # modules have been imported
259 if self
.get_platform() == 'cygwin':
260 self
.announce('WARNING: skipping import check for Cygwin-based "%s"'
263 ext_filename
= os
.path
.join(
265 self
.get_ext_filename(self
.get_ext_fullname(ext
.name
)))
267 # If the build directory didn't exist when setup.py was
268 # started, sys.path_importer_cache has a negative result
269 # cached. Clear that cache before trying to import.
270 sys
.path_importer_cache
.clear()
273 imp
.load_dynamic(ext
.name
, ext_filename
)
274 except ImportError as why
:
275 self
.failed
.append(ext
.name
)
276 self
.announce('*** WARNING: renaming "%s" since importing it'
277 ' failed: %s' % (ext
.name
, why
), level
=3)
278 assert not self
.inplace
279 basename
, tail
= os
.path
.splitext(ext_filename
)
280 newname
= basename
+ "_failed" + tail
281 if os
.path
.exists(newname
):
283 os
.rename(ext_filename
, newname
)
285 # XXX -- This relies on a Vile HACK in
286 # distutils.command.build_ext.build_extension(). The
287 # _built_objects attribute is stored there strictly for
289 # If there is a failure, _built_objects may not be there,
290 # so catch the AttributeError and move on.
292 for filename
in self
._built
_objects
:
294 except AttributeError:
295 self
.announce('unable to remove files (ignored)')
297 exc_type
, why
, tb
= sys
.exc_info()
298 self
.announce('*** WARNING: importing extension "%s" '
299 'failed with %s: %s' % (ext
.name
, exc_type
, why
),
301 self
.failed
.append(ext
.name
)
303 def get_platform(self
):
304 # Get value of sys.platform
305 for platform
in ['cygwin', 'darwin', 'atheos', 'osf1']:
306 if sys
.platform
.startswith(platform
):
310 def detect_modules(self
):
311 # Ensure that /usr/local is always used
312 add_dir_to_list(self
.compiler
.library_dirs
, '/usr/local/lib')
313 add_dir_to_list(self
.compiler
.include_dirs
, '/usr/local/include')
315 # Add paths specified in the environment variables LDFLAGS and
316 # CPPFLAGS for header and library files.
317 # We must get the values from the Makefile and not the environment
318 # directly since an inconsistently reproducible issue comes up where
319 # the environment variable is not set even though the value were passed
320 # into configure and stored in the Makefile (issue found on OS X 10.3).
321 for env_var
, arg_name
, dir_list
in (
322 ('LDFLAGS', '-L', self
.compiler
.library_dirs
),
323 ('CPPFLAGS', '-I', self
.compiler
.include_dirs
)):
324 env_val
= sysconfig
.get_config_var(env_var
)
326 # To prevent optparse from raising an exception about any
327 # options in env_val that is doesn't know about we strip out
328 # all double dashes and any dashes followed by a character
329 # that is not for the option we are dealing with.
331 # Please note that order of the regex is important! We must
332 # strip out double-dashes first so that we don't end up with
333 # substituting "--Long" to "-Long" and thus lead to "ong" being
334 # used for a library directory.
335 env_val
= re
.sub(r
'(^|\s+)-(-|(?!%s))' % arg_name
[1],
337 parser
= optparse
.OptionParser()
338 # Make sure that allowing args interspersed with options is
340 parser
.allow_interspersed_args
= True
341 parser
.error
= lambda msg
: None
342 parser
.add_option(arg_name
, dest
="dirs", action
="append")
343 options
= parser
.parse_args(env_val
.split())[0]
345 for directory
in reversed(options
.dirs
):
346 add_dir_to_list(dir_list
, directory
)
348 if os
.path
.normpath(sys
.prefix
) != '/usr':
349 add_dir_to_list(self
.compiler
.library_dirs
,
350 sysconfig
.get_config_var("LIBDIR"))
351 add_dir_to_list(self
.compiler
.include_dirs
,
352 sysconfig
.get_config_var("INCLUDEDIR"))
354 # lib_dirs and inc_dirs are used to search for files;
355 # if a file is found in one of those directories, it can
356 # be assumed that no additional -I,-L directives are needed.
357 lib_dirs
= self
.compiler
.library_dirs
+ [
358 '/lib64', '/usr/lib64',
361 inc_dirs
= self
.compiler
.include_dirs
+ ['/usr/include']
365 config_h
= sysconfig
.get_config_h_filename()
366 config_h_vars
= sysconfig
.parse_config_h(open(config_h
))
368 platform
= self
.get_platform()
369 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
371 # Check for AtheOS which has libraries in non-standard locations
372 if platform
== 'atheos':
373 lib_dirs
+= ['/system/libs', '/atheos/autolnk/lib']
374 lib_dirs
+= os
.getenv('LIBRARY_PATH', '').split(os
.pathsep
)
375 inc_dirs
+= ['/system/include', '/atheos/autolnk/include']
376 inc_dirs
+= os
.getenv('C_INCLUDE_PATH', '').split(os
.pathsep
)
378 # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
379 if platform
in ['osf1', 'unixware7', 'openunix8']:
380 lib_dirs
+= ['/usr/ccs/lib']
382 if platform
== 'darwin':
383 # This should work on any unixy platform ;-)
384 # If the user has bothered specifying additional -I and -L flags
385 # in OPT and LDFLAGS we might as well use them here.
386 # NOTE: using shlex.split would technically be more correct, but
387 # also gives a bootstrap problem. Let's hope nobody uses directories
388 # with whitespace in the name to store libraries.
389 cflags
, ldflags
= sysconfig
.get_config_vars(
391 for item
in cflags
.split():
392 if item
.startswith('-I'):
393 inc_dirs
.append(item
[2:])
395 for item
in ldflags
.split():
396 if item
.startswith('-L'):
397 lib_dirs
.append(item
[2:])
399 # Check for MacOS X, which doesn't need libm.a at all
401 if platform
in ['darwin', 'mac']:
404 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
407 # The following modules are all pretty straightforward, and compile
408 # on pretty much any POSIXish platform.
411 # Some modules that are normally always on:
412 exts
.append( Extension('_weakref', ['_weakref.c']) )
415 exts
.append( Extension('array', ['arraymodule.c']) )
416 # complex math library functions
417 exts
.append( Extension('cmath', ['cmathmodule.c'],
418 libraries
=math_libs
) )
420 # math library functions, e.g. sin()
421 exts
.append( Extension('math', ['mathmodule.c'],
422 libraries
=math_libs
) )
423 # time operations and variables
424 exts
.append( Extension('time', ['timemodule.c'],
425 libraries
=math_libs
) )
426 exts
.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
427 libraries
=math_libs
) )
428 # fast iterator tools implemented in C
429 exts
.append( Extension("itertools", ["itertoolsmodule.c"]) )
430 # random number generator implemented in C
431 exts
.append( Extension("_random", ["_randommodule.c"]) )
432 # high-performance collections
433 exts
.append( Extension("_collections", ["_collectionsmodule.c"]) )
435 exts
.append( Extension("_bisect", ["_bisectmodule.c"]) )
437 exts
.append( Extension("_heapq", ["_heapqmodule.c"]) )
438 # operator.add() and similar goodies
439 exts
.append( Extension('operator', ['operator.c']) )
441 exts
.append( Extension("_functools", ["_functoolsmodule.c"]) )
442 # Memory-based IO accelerator modules
443 exts
.append( Extension("_bytesio", ["_bytesio.c"]) )
444 exts
.append( Extension("_stringio", ["_stringio.c"]) )
445 # C-optimized pickle replacement
446 exts
.append( Extension("_pickle", ["_pickle.c"]) )
448 exts
.append( Extension("atexit", ["atexitmodule.c"]) )
450 exts
.append( Extension("_json", ["_json.c"]) )
451 # Python C API test module
452 exts
.append( Extension('_testcapi', ['_testcapimodule.c']) )
453 # profiler (_lsprof is for cProfile.py)
454 exts
.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
455 # static Unicode character database
456 exts
.append( Extension('unicodedata', ['unicodedata.c']) )
457 # access to ISO C locale support
458 data
= open('pyconfig.h').read()
459 m
= re
.search(r
"#s*define\s+WITH_LIBINTL\s+1\s*", data
)
461 locale_libs
= ['intl']
464 if platform
== 'darwin':
465 locale_extra_link_args
= ['-framework', 'CoreFoundation']
467 locale_extra_link_args
= []
470 exts
.append( Extension('_locale', ['_localemodule.c'],
471 libraries
=locale_libs
,
472 extra_link_args
=locale_extra_link_args
) )
474 # Modules with some UNIX dependencies -- on by default:
475 # (If you have a really backward UNIX, select and socket may not be
478 # fcntl(2) and ioctl(2)
479 exts
.append( Extension('fcntl', ['fcntlmodule.c']) )
480 if platform
not in ['mac']:
482 exts
.append( Extension('pwd', ['pwdmodule.c']) )
484 exts
.append( Extension('grp', ['grpmodule.c']) )
485 # spwd, shadow passwords
486 if (config_h_vars
.get('HAVE_GETSPNAM', False) or
487 config_h_vars
.get('HAVE_GETSPENT', False)):
488 exts
.append( Extension('spwd', ['spwdmodule.c']) )
490 missing
.append('spwd')
492 missing
.extend(['pwd', 'grp', 'spwd'])
494 # select(2); not on ancient System V
495 exts
.append( Extension('select', ['selectmodule.c']) )
497 # Fred Drake's interface to the Python parser
498 exts
.append( Extension('parser', ['parsermodule.c']) )
500 # Memory-mapped files (also works on Win32).
501 if platform
not in ['atheos', 'mac']:
502 exts
.append( Extension('mmap', ['mmapmodule.c']) )
504 missing
.append('mmap')
506 # Lance Ellinghaus's syslog module
507 if platform
not in ['mac']:
508 # syslog daemon interface
509 exts
.append( Extension('syslog', ['syslogmodule.c']) )
511 missing
.append('syslog')
514 # Here ends the simple stuff. From here on, modules need certain
515 # libraries, are platform-specific, or present other surprises.
519 # These don't work for 64-bit platforms!!!
520 # These represent audio samples or images as strings:
522 # Operations on audio samples
523 # According to #993173, this one should actually work fine on
525 exts
.append( Extension('audioop', ['audioop.c']) )
528 do_readline
= self
.compiler
.find_library_file(lib_dirs
, 'readline')
529 if platform
== 'darwin': # and os.uname()[2] < '9.':
530 # MacOSX 10.4 has a broken readline. Don't try to build
531 # the readline module unless the user has installed a fixed
533 # FIXME: The readline emulation on 10.5 is better, but the
534 # readline module doesn't compile out of the box.
535 if find_file('readline/rlconf.h', inc_dirs
, []) is None:
538 if sys
.platform
== 'darwin':
539 # In every directory on the search path search for a dynamic
540 # library and then a static library, instead of first looking
541 # for dynamic libraries on the entire path.
542 # This way a staticly linked custom readline gets picked up
543 # before the (broken) dynamic library in /usr/lib.
544 readline_extra_link_args
= ('-Wl,-search_paths_first',)
546 readline_extra_link_args
= ()
548 readline_libs
= ['readline']
549 if self
.compiler
.find_library_file(lib_dirs
,
551 readline_libs
.append('ncursesw')
552 elif self
.compiler
.find_library_file(lib_dirs
,
554 readline_libs
.append('ncurses')
555 elif self
.compiler
.find_library_file(lib_dirs
, 'curses'):
556 readline_libs
.append('curses')
557 elif self
.compiler
.find_library_file(lib_dirs
+
558 ['/usr/lib/termcap'],
560 readline_libs
.append('termcap')
561 exts
.append( Extension('readline', ['readline.c'],
562 library_dirs
=['/usr/lib/termcap'],
563 extra_link_args
=readline_extra_link_args
,
564 libraries
=readline_libs
) )
566 missing
.append('readline')
568 if platform
not in ['mac']:
571 if self
.compiler
.find_library_file(lib_dirs
, 'crypt'):
575 exts
.append( Extension('crypt', ['cryptmodule.c'], libraries
=libs
) )
577 missing
.append('crypt')
580 exts
.append( Extension('_csv', ['_csv.c']) )
583 exts
.append( Extension('_socket', ['socketmodule.c'],
584 depends
= ['socketmodule.h']) )
585 # Detect SSL support for the socket module (via _ssl)
586 search_for_ssl_incs_in
= [
587 '/usr/local/ssl/include',
588 '/usr/contrib/ssl/include/'
590 ssl_incs
= find_file('openssl/ssl.h', inc_dirs
,
591 search_for_ssl_incs_in
593 if ssl_incs
is not None:
594 krb5_h
= find_file('krb5.h', inc_dirs
,
595 ['/usr/kerberos/include'])
598 ssl_libs
= find_library_file(self
.compiler
, 'ssl',lib_dirs
,
599 ['/usr/local/ssl/lib',
600 '/usr/contrib/ssl/lib/'
603 if (ssl_incs
is not None and
604 ssl_libs
is not None):
605 exts
.append( Extension('_ssl', ['_ssl.c'],
606 include_dirs
= ssl_incs
,
607 library_dirs
= ssl_libs
,
608 libraries
= ['ssl', 'crypto'],
609 depends
= ['socketmodule.h']), )
611 missing
.append('_ssl')
613 # find out which version of OpenSSL we have
615 openssl_ver_re
= re
.compile(
616 '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
617 for ssl_inc_dir
in inc_dirs
+ search_for_ssl_incs_in
:
618 name
= os
.path
.join(ssl_inc_dir
, 'openssl', 'opensslv.h')
619 if os
.path
.isfile(name
):
621 incfile
= open(name
, 'r')
623 m
= openssl_ver_re
.match(line
)
625 openssl_ver
= eval(m
.group(1))
630 # first version found is what we'll use (as the compiler should)
634 #print('openssl_ver = 0x%08x' % openssl_ver)
636 if ssl_incs
is not None and ssl_libs
is not None:
637 if openssl_ver
>= 0x00907000:
638 # The _hashlib module wraps optimized implementations
639 # of hash functions from the OpenSSL library.
640 exts
.append( Extension('_hashlib', ['_hashopenssl.c'],
641 include_dirs
= ssl_incs
,
642 library_dirs
= ssl_libs
,
643 libraries
= ['ssl', 'crypto']) )
645 print("warning: openssl 0x%08x is too old for _hashlib" %
647 missing
.append('_hashlib')
649 missing
.append('_hashlib')
651 if openssl_ver
< 0x00908000:
652 # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
653 exts
.append( Extension('_sha256', ['sha256module.c']) )
654 exts
.append( Extension('_sha512', ['sha512module.c']) )
656 if openssl_ver
< 0x00907000:
657 # no openssl at all, use our own md5 and sha1
658 exts
.append( Extension('_md5', ['md5module.c']) )
659 exts
.append( Extension('_sha1', ['sha1module.c']) )
661 # Modules that provide persistent dictionary-like semantics. You will
662 # probably want to arrange for at least one of them to be available on
663 # your machine, though none are defined by default because of library
664 # dependencies. The Python module dbm/__init__.py provides an
665 # implementation independent wrapper for these; dbm/dumb.py provides
666 # similar functionality (but slower of course) implemented in Python.
668 # Sleepycat^WOracle Berkeley DB interface.
669 # http://www.oracle.com/database/berkeley-db/db/index.html
671 # This requires the Sleepycat^WOracle DB code. The supported versions
672 # are set below. Visit the URL above to download
673 # a release. Most open source OSes come with one or more
674 # versions of BerkeleyDB already installed.
676 max_db_ver
= (4, 5) # XXX(gregory.p.smith): 4.6 "works" but seems to
677 # have issues on many platforms. I've temporarily
678 # disabled 4.6 to see what the odd platform
680 max_db_ver
= (4, 7) # XXX(matthias.klose): test with 4.7 on some buildds
682 db_setup_debug
= False # verbose debug prints from this script?
684 # construct a list of paths to look for the header file in on
685 # top of the normal inc_dirs.
688 '/usr/local/include/db4',
689 '/opt/sfw/include/db4',
691 '/usr/local/include/db3',
692 '/opt/sfw/include/db3',
693 # Fink defaults (http://fink.sourceforge.net/)
697 # 4.x minor number specific paths
698 for x
in range(max_db_ver
[1]+1):
699 db_inc_paths
.append('/usr/include/db4%d' % x
)
700 db_inc_paths
.append('/usr/include/db4.%d' % x
)
701 db_inc_paths
.append('/usr/local/BerkeleyDB.4.%d/include' % x
)
702 db_inc_paths
.append('/usr/local/include/db4%d' % x
)
703 db_inc_paths
.append('/pkg/db-4.%d/include' % x
)
704 db_inc_paths
.append('/opt/db-4.%d/include' % x
)
705 # MacPorts default (http://www.macports.org/)
706 db_inc_paths
.append('/opt/local/include/db4%d' % x
)
707 # 3.x minor number specific paths
709 db_inc_paths
.append('/usr/include/db3%d' % x
)
710 db_inc_paths
.append('/usr/local/BerkeleyDB.3.%d/include' % x
)
711 db_inc_paths
.append('/usr/local/include/db3%d' % x
)
712 db_inc_paths
.append('/pkg/db-3.%d/include' % x
)
713 db_inc_paths
.append('/opt/db-3.%d/include' % x
)
715 # Add some common subdirectories for Sleepycat DB to the list,
716 # based on the standard include directories. This way DB3/4 gets
717 # picked up when it is installed in a non-standard prefix and
718 # the user has added that prefix into inc_dirs.
721 std_variants
.append(os
.path
.join(dn
, 'db3'))
722 std_variants
.append(os
.path
.join(dn
, 'db4'))
723 for x
in range(max_db_ver
[1]+1):
724 std_variants
.append(os
.path
.join(dn
, "db4%d"%x))
725 std_variants
.append(os
.path
.join(dn
, "db4.%d"%x))
727 std_variants
.append(os
.path
.join(dn
, "db3%d"%x))
728 std_variants
.append(os
.path
.join(dn
, "db3.%d"%x))
730 db_inc_paths
= std_variants
+ db_inc_paths
731 db_inc_paths
= [p
for p
in db_inc_paths
if os
.path
.exists(p
)]
735 class db_found(Exception): pass
737 # See whether there is a Sleepycat header in the standard
739 for d
in inc_dirs
+ db_inc_paths
:
740 f
= os
.path
.join(d
, "db.h")
741 if db_setup_debug
: print("db: looking for db.h in", f
)
742 if os
.path
.exists(f
):
744 m
= re
.search(r
"#define\WDB_VERSION_MAJOR\W(\d+)", f
)
746 db_major
= int(m
.group(1))
747 m
= re
.search(r
"#define\WDB_VERSION_MINOR\W(\d+)", f
)
748 db_minor
= int(m
.group(1))
749 db_ver
= (db_major
, db_minor
)
751 # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
753 m
= re
.search(r
"#define\WDB_VERSION_PATCH\W(\d+)", f
)
754 db_patch
= int(m
.group(1))
756 print("db.h:", db_ver
, "patch", db_patch
,
757 "being ignored (4.6.x must be >= 4.6.21)")
760 if ( (db_ver
not in db_ver_inc_map
) and
761 (db_ver
<= max_db_ver
and db_ver
>= min_db_ver
) ):
762 # save the include directory with the db.h version
763 # (first occurrence only)
764 db_ver_inc_map
[db_ver
] = d
766 print("db.h: found", db_ver
, "in", d
)
768 # we already found a header for this library version
769 if db_setup_debug
: print("db.h: ignoring", d
)
771 # ignore this header, it didn't contain a version number
773 print("db.h: no version number version in", d
)
775 db_found_vers
= sorted(db_ver_inc_map
.keys())
778 db_ver
= db_found_vers
.pop()
779 db_incdir
= db_ver_inc_map
[db_ver
]
781 # check lib directories parallel to the location of the header
783 db_incdir
.replace("include", 'lib64'),
784 db_incdir
.replace("include", 'lib'),
786 db_dirs_to_check
= [x
for x
in db_dirs_to_check
if os
.path
.isdir(x
)]
788 # Look for a version specific db-X.Y before an ambiguoius dbX
789 # XXX should we -ever- look for a dbX name? Do any
790 # systems really not name their library by version and
791 # symlink to more general names?
792 for dblib
in (('db-%d.%d' % db_ver
),
794 ('db%d' % db_ver
[0])):
795 dblib_file
= self
.compiler
.find_library_file(
796 db_dirs_to_check
+ lib_dirs
, dblib
)
798 dblib_dir
= [ os
.path
.abspath(os
.path
.dirname(dblib_file
)) ]
801 if db_setup_debug
: print("db lib: ", dblib
, "not found")
805 print("db lib: using", db_ver
, dblib
)
806 print("db: lib dir", dblib_dir
, "inc dir", db_incdir
)
807 db_incs
= [db_incdir
]
809 # We add the runtime_library_dirs argument because the
810 # BerkeleyDB lib we're linking against often isn't in the
811 # system dynamic library search path. This is usually
812 # correct and most trouble free, but may cause problems in
813 # some unusual system configurations (e.g. the directory
814 # is on an NFS server that goes away).
815 exts
.append(Extension('_bsddb', ['_bsddb.c'],
816 depends
= ['bsddb.h'],
817 library_dirs
=dblib_dir
,
818 runtime_library_dirs
=dblib_dir
,
819 include_dirs
=db_incs
,
822 if db_setup_debug
: print("db: no appropriate library found")
826 missing
.append('_bsddb')
828 # The sqlite interface
829 sqlite_setup_debug
= False # verbose debug prints from this script?
831 # We hunt for #define SQLITE_VERSION "n.n.n"
832 # We need to find >= sqlite version 3.0.8
833 sqlite_incdir
= sqlite_libdir
= None
834 sqlite_inc_paths
= [ '/usr/include',
835 '/usr/include/sqlite',
836 '/usr/include/sqlite3',
837 '/usr/local/include',
838 '/usr/local/include/sqlite',
839 '/usr/local/include/sqlite3',
841 MIN_SQLITE_VERSION_NUMBER
= (3, 0, 8)
842 MIN_SQLITE_VERSION
= ".".join([str(x
)
843 for x
in MIN_SQLITE_VERSION_NUMBER
])
845 # Scan the default include directories before the SQLite specific
846 # ones. This allows one to override the copy of sqlite on OSX,
847 # where /usr/include contains an old version of sqlite.
848 for d
in inc_dirs
+ sqlite_inc_paths
:
849 f
= os
.path
.join(d
, "sqlite3.h")
850 if os
.path
.exists(f
):
851 if sqlite_setup_debug
: print("sqlite: found %s"%f)
852 incf
= open(f
).read()
854 r
'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf
)
856 sqlite_version
= m
.group(1)
857 sqlite_version_tuple
= tuple([int(x
)
858 for x
in sqlite_version
.split(".")])
859 if sqlite_version_tuple
>= MIN_SQLITE_VERSION_NUMBER
:
861 if sqlite_setup_debug
:
862 print("%s/sqlite3.h: version %s"%(d
, sqlite_version
))
866 if sqlite_setup_debug
:
867 print("%s: version %d is too old, need >= %s"%(d
,
868 sqlite_version
, MIN_SQLITE_VERSION
))
869 elif sqlite_setup_debug
:
870 print("sqlite: %s had no SQLITE_VERSION"%(f
,))
873 sqlite_dirs_to_check
= [
874 os
.path
.join(sqlite_incdir
, '..', 'lib64'),
875 os
.path
.join(sqlite_incdir
, '..', 'lib'),
876 os
.path
.join(sqlite_incdir
, '..', '..', 'lib64'),
877 os
.path
.join(sqlite_incdir
, '..', '..', 'lib'),
879 sqlite_libfile
= self
.compiler
.find_library_file(
880 sqlite_dirs_to_check
+ lib_dirs
, 'sqlite3')
881 sqlite_libdir
= [os
.path
.abspath(os
.path
.dirname(sqlite_libfile
))]
883 if sqlite_incdir
and sqlite_libdir
:
884 sqlite_srcs
= ['_sqlite/cache.c',
885 '_sqlite/connection.c',
887 '_sqlite/microprotocols.c',
889 '_sqlite/prepare_protocol.c',
891 '_sqlite/statement.c',
895 if sys
.platform
!= "win32":
896 sqlite_defines
.append(('MODULE_NAME', '"sqlite3"'))
898 sqlite_defines
.append(('MODULE_NAME', '\\"sqlite3\\"'))
901 if sys
.platform
== 'darwin':
902 # In every directory on the search path search for a dynamic
903 # library and then a static library, instead of first looking
904 # for dynamic libraries on the entiry path.
905 # This way a staticly linked custom sqlite gets picked up
906 # before the dynamic library in /usr/lib.
907 sqlite_extra_link_args
= ('-Wl,-search_paths_first',)
909 sqlite_extra_link_args
= ()
911 exts
.append(Extension('_sqlite3', sqlite_srcs
,
912 define_macros
=sqlite_defines
,
913 include_dirs
=["Modules/_sqlite",
915 library_dirs
=sqlite_libdir
,
916 runtime_library_dirs
=sqlite_libdir
,
917 extra_link_args
=sqlite_extra_link_args
,
918 libraries
=["sqlite3",]))
920 missing
.append('_sqlite3')
922 # The standard Unix dbm module:
923 if platform
not in ['cygwin']:
924 if find_file("ndbm.h", inc_dirs
, []) is not None:
925 # Some systems have -lndbm, others don't
926 if self
.compiler
.find_library_file(lib_dirs
, 'ndbm'):
930 exts
.append( Extension('_dbm', ['_dbmmodule.c'],
931 define_macros
=[('HAVE_NDBM_H',None)],
932 libraries
= ndbm_libs
) )
933 elif (self
.compiler
.find_library_file(lib_dirs
, 'gdbm')
934 and find_file("gdbm/ndbm.h", inc_dirs
, []) is not None):
935 exts
.append( Extension('_dbm', ['_dbmmodule.c'],
936 define_macros
=[('HAVE_GDBM_NDBM_H',None)],
937 libraries
= ['gdbm'] ) )
938 elif db_incs
is not None:
939 exts
.append( Extension('_dbm', ['_dbmmodule.c'],
940 library_dirs
=dblib_dir
,
941 runtime_library_dirs
=dblib_dir
,
942 include_dirs
=db_incs
,
943 define_macros
=[('HAVE_BERKDB_H',None),
944 ('DB_DBM_HSEARCH',None)],
947 missing
.append('_dbm')
949 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
950 if (self
.compiler
.find_library_file(lib_dirs
, 'gdbm')):
951 exts
.append( Extension('_gdbm', ['_gdbmmodule.c'],
952 libraries
= ['gdbm'] ) )
954 missing
.append('_gdbm')
957 if platform
not in ['mac', 'win32']:
958 # Steen Lumholt's termios module
959 exts
.append( Extension('termios', ['termios.c']) )
960 # Jeremy Hylton's rlimit interface
961 if platform
not in ['atheos']:
962 exts
.append( Extension('resource', ['resource.c']) )
964 missing
.append('resource')
966 # Sun yellow pages. Some systems have the functions in libc.
967 if platform
not in ['cygwin', 'atheos', 'qnx6']:
968 if (self
.compiler
.find_library_file(lib_dirs
, 'nsl')):
972 exts
.append( Extension('nis', ['nismodule.c'],
975 missing
.append('nis')
977 missing
.extend(['nis', 'resource', 'termios'])
979 # Curses support, requiring the System V version of curses, often
980 # provided by the ncurses library.
981 panel_library
= 'panel'
982 if (self
.compiler
.find_library_file(lib_dirs
, 'ncursesw')):
983 curses_libs
= ['ncursesw']
984 # Bug 1464056: If _curses.so links with ncursesw,
985 # _curses_panel.so must link with panelw.
986 panel_library
= 'panelw'
987 exts
.append( Extension('_curses', ['_cursesmodule.c'],
988 libraries
= curses_libs
) )
989 elif (self
.compiler
.find_library_file(lib_dirs
, 'ncurses')):
990 curses_libs
= ['ncurses']
991 exts
.append( Extension('_curses', ['_cursesmodule.c'],
992 libraries
= curses_libs
) )
993 elif (self
.compiler
.find_library_file(lib_dirs
, 'curses')
994 and platform
!= 'darwin'):
995 # OSX has an old Berkeley curses, not good enough for
996 # the _curses module.
997 if (self
.compiler
.find_library_file(lib_dirs
, 'terminfo')):
998 curses_libs
= ['curses', 'terminfo']
999 elif (self
.compiler
.find_library_file(lib_dirs
, 'termcap')):
1000 curses_libs
= ['curses', 'termcap']
1002 curses_libs
= ['curses']
1004 exts
.append( Extension('_curses', ['_cursesmodule.c'],
1005 libraries
= curses_libs
) )
1007 missing
.append('_curses')
1009 # If the curses module is enabled, check for the panel module
1010 if (module_enabled(exts
, '_curses') and
1011 self
.compiler
.find_library_file(lib_dirs
, panel_library
)):
1012 exts
.append( Extension('_curses_panel', ['_curses_panel.c'],
1013 libraries
= [panel_library
] + curses_libs
) )
1015 missing
.append('_curses_panel')
1017 # Andrew Kuchling's zlib module. Note that some versions of zlib
1018 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1019 # http://www.cert.org/advisories/CA-2002-07.html
1021 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1022 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1023 # now, we still accept 1.1.3, because we think it's difficult to
1024 # exploit this in Python, and we'd rather make it RedHat's problem
1025 # than our problem <wink>.
1027 # You can upgrade zlib to version 1.1.4 yourself by going to
1028 # http://www.gzip.org/zlib/
1029 zlib_inc
= find_file('zlib.h', [], inc_dirs
)
1031 if zlib_inc
is not None:
1032 zlib_h
= zlib_inc
[0] + '/zlib.h'
1034 version_req
= '"1.1.3"'
1037 line
= fp
.readline()
1040 if line
.startswith('#define ZLIB_VERSION'):
1041 version
= line
.split()[2]
1043 if version
>= version_req
:
1044 if (self
.compiler
.find_library_file(lib_dirs
, 'z')):
1045 if sys
.platform
== "darwin":
1046 zlib_extra_link_args
= ('-Wl,-search_paths_first',)
1048 zlib_extra_link_args
= ()
1049 exts
.append( Extension('zlib', ['zlibmodule.c'],
1051 extra_link_args
= zlib_extra_link_args
))
1054 missing
.append('zlib')
1056 missing
.append('zlib')
1058 missing
.append('zlib')
1060 # Helper module for various ascii-encoders. Uses zlib for an optimized
1061 # crc32 if we have it. Otherwise binascii uses its own.
1063 extra_compile_args
= ['-DUSE_ZLIB_CRC32']
1065 extra_link_args
= zlib_extra_link_args
1067 extra_compile_args
= []
1069 extra_link_args
= []
1070 exts
.append( Extension('binascii', ['binascii.c'],
1071 extra_compile_args
= extra_compile_args
,
1072 libraries
= libraries
,
1073 extra_link_args
= extra_link_args
) )
1075 # Gustavo Niemeyer's bz2 module.
1076 if (self
.compiler
.find_library_file(lib_dirs
, 'bz2')):
1077 if sys
.platform
== "darwin":
1078 bz2_extra_link_args
= ('-Wl,-search_paths_first',)
1080 bz2_extra_link_args
= ()
1081 exts
.append( Extension('bz2', ['bz2module.c'],
1082 libraries
= ['bz2'],
1083 extra_link_args
= bz2_extra_link_args
) )
1085 missing
.append('bz2')
1087 # Interface to the Expat XML parser
1089 # Expat was written by James Clark and is now maintained by a
1090 # group of developers on SourceForge; see www.libexpat.org for
1091 # more information. The pyexpat module was written by Paul
1092 # Prescod after a prototype by Jack Jansen. The Expat source
1093 # is included in Modules/expat/. Usage of a system
1094 # shared libexpat.so/expat.dll is not advised.
1096 # More information on Expat can be found at www.libexpat.org.
1098 expatinc
= os
.path
.join(os
.getcwd(), srcdir
, 'Modules', 'expat')
1100 ('HAVE_EXPAT_CONFIG_H', '1'),
1103 exts
.append(Extension('pyexpat',
1104 define_macros
= define_macros
,
1105 include_dirs
= [expatinc
],
1106 sources
= ['pyexpat.c',
1113 # Fredrik Lundh's cElementTree module. Note that this also
1114 # uses expat (via the CAPI hook in pyexpat).
1116 if os
.path
.isfile(os
.path
.join(srcdir
, 'Modules', '_elementtree.c')):
1117 define_macros
.append(('USE_PYEXPAT_CAPI', None))
1118 exts
.append(Extension('_elementtree',
1119 define_macros
= define_macros
,
1120 include_dirs
= [expatinc
],
1121 sources
= ['_elementtree.c'],
1124 missing
.append('_elementtree')
1126 # Hye-Shik Chang's CJKCodecs modules.
1127 exts
.append(Extension('_multibytecodec',
1128 ['cjkcodecs/multibytecodec.c']))
1129 for loc
in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
1130 exts
.append(Extension('_codecs_%s' % loc
,
1131 ['cjkcodecs/_codecs_%s.c' % loc
]))
1133 # Thomas Heller's _ctypes module
1134 self
.detect_ctypes(inc_dirs
, lib_dirs
)
1136 # _fileio -- supposedly cross platform
1137 exts
.append(Extension('_fileio', ['_fileio.c']))
1138 # Richard Oudkerk's multiprocessing module
1139 if platform
== 'win32': # Windows
1141 libraries
= ['ws2_32']
1143 elif platform
== 'darwin': # Mac OSX
1146 HAVE_SEM_TIMEDWAIT
=0,
1148 HAVE_BROKEN_SEM_GETVALUE
=1
1152 elif platform
== 'cygwin': # Cygwin
1155 HAVE_SEM_TIMEDWAIT
=1,
1157 HAVE_BROKEN_SEM_UNLINK
=1
1161 elif platform
in ('freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
1162 # FreeBSD's P1003.1b semaphore support is very experimental
1163 # and has many known problems. (as of June 2008)
1164 macros
= dict( # FreeBSD
1166 HAVE_SEM_TIMEDWAIT
=0,
1171 else: # Linux and other unices
1174 HAVE_SEM_TIMEDWAIT
=1,
1179 if platform
== 'win32':
1180 multiprocessing_srcs
= [ '_multiprocessing/multiprocessing.c',
1181 '_multiprocessing/semaphore.c',
1182 '_multiprocessing/pipe_connection.c',
1183 '_multiprocessing/socket_connection.c',
1184 '_multiprocessing/win32_functions.c'
1188 multiprocessing_srcs
= [ '_multiprocessing/multiprocessing.c',
1189 '_multiprocessing/socket_connection.c'
1192 if macros
.get('HAVE_SEM_OPEN', False):
1193 multiprocessing_srcs
.append('_multiprocessing/semaphore.c')
1195 exts
.append ( Extension('_multiprocessing', multiprocessing_srcs
,
1196 define_macros
=list(macros
.items()),
1197 include_dirs
=["Modules/_multiprocessing"]))
1198 # End multiprocessing
1200 # Platform-specific libraries
1201 if platform
in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
1202 'freebsd7', 'freebsd8'):
1203 exts
.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
1205 missing
.append('ossaudiodev')
1207 if sys
.platform
== 'darwin':
1209 Extension('_gestalt', ['_gestalt.c'],
1210 extra_link_args
=['-framework', 'Carbon'])
1213 self
.extensions
.extend(exts
)
1215 # Call the method for detecting whether _tkinter can be compiled
1216 self
.detect_tkinter(inc_dirs
, lib_dirs
)
1218 if '_tkinter' not in [e
.name
for e
in self
.extensions
]:
1219 missing
.append('_tkinter')
1223 def detect_tkinter_darwin(self
, inc_dirs
, lib_dirs
):
1224 # The _tkinter module, using frameworks. Since frameworks are quite
1225 # different the UNIX search logic is not sharable.
1226 from os
.path
import join
, exists
1228 '/System/Library/Frameworks/',
1229 '/Library/Frameworks',
1230 join(os
.getenv('HOME'), '/Library/Frameworks')
1233 # Find the directory that contains the Tcl.framework and Tk.framework
1235 # XXX distutils should support -F!
1236 for F
in framework_dirs
:
1237 # both Tcl.framework and Tk.framework should be present
1238 for fw
in 'Tcl', 'Tk':
1239 if not exists(join(F
, fw
+ '.framework')):
1242 # ok, F is now directory with both frameworks. Continure
1246 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
1250 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
1251 # frameworks. In later release we should hopefully be able to pass
1252 # the -F option to gcc, which specifies a framework lookup path.
1255 join(F
, fw
+ '.framework', H
)
1256 for fw
in ('Tcl', 'Tk')
1257 for H
in ('Headers', 'Versions/Current/PrivateHeaders')
1260 # For 8.4a2, the X11 headers are not included. Rather than include a
1261 # complicated search, this is a hard-coded path. It could bail out
1262 # if X11 libs are not found...
1263 include_dirs
.append('/usr/X11R6/include')
1264 frameworks
= ['-framework', 'Tcl', '-framework', 'Tk']
1266 # All existing framework builds of Tcl/Tk don't support 64-bit
1268 cflags
= sysconfig
.get_config_vars('CFLAGS')[0]
1269 archs
= re
.findall('-arch\s+(\w+)', cflags
)
1270 if 'x86_64' in archs
or 'ppc64' in archs
:
1272 archs
.remove('x86_64')
1276 archs
.remove('ppc64')
1281 frameworks
.append('-arch')
1282 frameworks
.append(a
)
1284 ext
= Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1285 define_macros
=[('WITH_APPINIT', 1)],
1286 include_dirs
= include_dirs
,
1288 extra_compile_args
= frameworks
[2:],
1289 extra_link_args
= frameworks
,
1291 self
.extensions
.append(ext
)
1295 def detect_tkinter(self
, inc_dirs
, lib_dirs
):
1296 # The _tkinter module.
1298 # Rather than complicate the code below, detecting and building
1299 # AquaTk is a separate method. Only one Tkinter will be built on
1300 # Darwin - either AquaTk, if it is found, or X11 based Tk.
1301 platform
= self
.get_platform()
1302 if (platform
== 'darwin' and
1303 self
.detect_tkinter_darwin(inc_dirs
, lib_dirs
)):
1306 # Assume we haven't found any of the libraries or include files
1307 # The versions with dots are used on Unix, and the versions without
1308 # dots on Windows, for detection by cygwin.
1309 tcllib
= tklib
= tcl_includes
= tk_includes
= None
1310 for version
in ['8.5', '85', '8.4', '84', '8.3', '83', '8.2',
1311 '82', '8.1', '81', '8.0', '80']:
1312 tklib
= self
.compiler
.find_library_file(lib_dirs
, 'tk' + version
)
1313 tcllib
= self
.compiler
.find_library_file(lib_dirs
, 'tcl' + version
)
1314 if tklib
and tcllib
:
1315 # Exit the loop when we've found the Tcl/Tk libraries
1318 # Now check for the header files
1319 if tklib
and tcllib
:
1320 # Check for the include files on Debian and {Free,Open}BSD, where
1321 # they're put in /usr/include/{tcl,tk}X.Y
1322 dotversion
= version
1323 if '.' not in dotversion
and "bsd" in sys
.platform
.lower():
1324 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
1325 # but the include subdirs are named like .../include/tcl8.3.
1326 dotversion
= dotversion
[:-1] + '.' + dotversion
[-1]
1327 tcl_include_sub
= []
1329 for dir in inc_dirs
:
1330 tcl_include_sub
+= [dir + os
.sep
+ "tcl" + dotversion
]
1331 tk_include_sub
+= [dir + os
.sep
+ "tk" + dotversion
]
1332 tk_include_sub
+= tcl_include_sub
1333 tcl_includes
= find_file('tcl.h', inc_dirs
, tcl_include_sub
)
1334 tk_includes
= find_file('tk.h', inc_dirs
, tk_include_sub
)
1336 if (tcllib
is None or tklib
is None or
1337 tcl_includes
is None or tk_includes
is None):
1338 self
.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
1341 # OK... everything seems to be present for Tcl/Tk.
1343 include_dirs
= [] ; libs
= [] ; defs
= [] ; added_lib_dirs
= []
1344 for dir in tcl_includes
+ tk_includes
:
1345 if dir not in include_dirs
:
1346 include_dirs
.append(dir)
1348 # Check for various platform-specific directories
1349 if platform
== 'sunos5':
1350 include_dirs
.append('/usr/openwin/include')
1351 added_lib_dirs
.append('/usr/openwin/lib')
1352 elif os
.path
.exists('/usr/X11R6/include'):
1353 include_dirs
.append('/usr/X11R6/include')
1354 added_lib_dirs
.append('/usr/X11R6/lib64')
1355 added_lib_dirs
.append('/usr/X11R6/lib')
1356 elif os
.path
.exists('/usr/X11R5/include'):
1357 include_dirs
.append('/usr/X11R5/include')
1358 added_lib_dirs
.append('/usr/X11R5/lib')
1360 # Assume default location for X11
1361 include_dirs
.append('/usr/X11/include')
1362 added_lib_dirs
.append('/usr/X11/lib')
1364 # If Cygwin, then verify that X is installed before proceeding
1365 if platform
== 'cygwin':
1366 x11_inc
= find_file('X11/Xlib.h', [], include_dirs
)
1370 # Check for BLT extension
1371 if self
.compiler
.find_library_file(lib_dirs
+ added_lib_dirs
,
1373 defs
.append( ('WITH_BLT', 1) )
1374 libs
.append('BLT8.0')
1375 elif self
.compiler
.find_library_file(lib_dirs
+ added_lib_dirs
,
1377 defs
.append( ('WITH_BLT', 1) )
1380 # Add the Tcl/Tk libraries
1381 libs
.append('tk'+ version
)
1382 libs
.append('tcl'+ version
)
1384 if platform
in ['aix3', 'aix4']:
1387 # Finally, link with the X11 libraries (not appropriate on cygwin)
1388 if platform
!= "cygwin":
1391 ext
= Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
1392 define_macros
=[('WITH_APPINIT', 1)] + defs
,
1393 include_dirs
= include_dirs
,
1395 library_dirs
= added_lib_dirs
,
1397 self
.extensions
.append(ext
)
1399 ## # Uncomment these lines if you want to play with xxmodule.c
1400 ## ext = Extension('xx', ['xxmodule.c'])
1401 ## self.extensions.append(ext)
1403 # XXX handle these, but how to detect?
1404 # *** Uncomment and edit for PIL (TkImaging) extension only:
1405 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
1406 # *** Uncomment and edit for TOGL extension only:
1407 # -DWITH_TOGL togl.c \
1408 # *** Uncomment these for TOGL extension only:
1409 # -lGL -lGLU -lXext -lXmu \
1411 def configure_ctypes_darwin(self
, ext
):
1412 # Darwin (OS X) uses preconfigured files, in
1413 # the Modules/_ctypes/libffi_osx directory.
1414 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
1415 ffi_srcdir
= os
.path
.abspath(os
.path
.join(srcdir
, 'Modules',
1416 '_ctypes', 'libffi_osx'))
1417 sources
= [os
.path
.join(ffi_srcdir
, p
)
1421 'x86/x86-ffi_darwin.c',
1423 'powerpc/ppc-darwin.S',
1424 'powerpc/ppc-darwin_closure.S',
1425 'powerpc/ppc-ffi_darwin.c',
1426 'powerpc/ppc64-darwin_closure.S',
1429 # Add .S (preprocessed assembly) to C compiler source extensions.
1430 self
.compiler
.src_extensions
.append('.S')
1432 include_dirs
= [os
.path
.join(ffi_srcdir
, 'include'),
1433 os
.path
.join(ffi_srcdir
, 'powerpc')]
1434 ext
.include_dirs
.extend(include_dirs
)
1435 ext
.sources
.extend(sources
)
1438 def configure_ctypes(self
, ext
):
1439 if not self
.use_system_libffi
:
1440 if sys
.platform
== 'darwin':
1441 return self
.configure_ctypes_darwin(ext
)
1443 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
1444 ffi_builddir
= os
.path
.join(self
.build_temp
, 'libffi')
1445 ffi_srcdir
= os
.path
.abspath(os
.path
.join(srcdir
, 'Modules',
1446 '_ctypes', 'libffi'))
1447 ffi_configfile
= os
.path
.join(ffi_builddir
, 'fficonfig.py')
1449 from distutils
.dep_util
import newer_group
1451 config_sources
= [os
.path
.join(ffi_srcdir
, fname
)
1452 for fname
in os
.listdir(ffi_srcdir
)
1453 if os
.path
.isfile(os
.path
.join(ffi_srcdir
, fname
))]
1454 if self
.force
or newer_group(config_sources
,
1456 from distutils
.dir_util
import mkpath
1457 mkpath(ffi_builddir
)
1460 # Pass empty CFLAGS because we'll just append the resulting
1461 # CFLAGS to Python's; -g or -O2 is to be avoided.
1462 cmd
= "cd %s && env CFLAGS='' '%s/configure' %s" \
1463 % (ffi_builddir
, ffi_srcdir
, " ".join(config_args
))
1465 res
= os
.system(cmd
)
1466 if res
or not os
.path
.exists(ffi_configfile
):
1467 print("Failed to configure _ctypes module")
1471 fp
= open(ffi_configfile
)
1476 exec(script
, globals(), fficonfig
)
1477 ffi_srcdir
= os
.path
.join(fficonfig
['ffi_srcdir'], 'src')
1479 # Add .S (preprocessed assembly) to C compiler source extensions.
1480 self
.compiler
.src_extensions
.append('.S')
1482 include_dirs
= [os
.path
.join(ffi_builddir
, 'include'),
1483 ffi_builddir
, ffi_srcdir
]
1484 extra_compile_args
= fficonfig
['ffi_cflags'].split()
1486 ext
.sources
.extend(fficonfig
['ffi_sources'])
1487 ext
.include_dirs
.extend(include_dirs
)
1488 ext
.extra_compile_args
.extend(extra_compile_args
)
1491 def detect_ctypes(self
, inc_dirs
, lib_dirs
):
1492 self
.use_system_libffi
= False
1494 extra_compile_args
= []
1495 extra_link_args
= []
1496 sources
= ['_ctypes/_ctypes.c',
1497 '_ctypes/callbacks.c',
1498 '_ctypes/callproc.c',
1499 '_ctypes/stgdict.c',
1501 '_ctypes/malloc_closure.c']
1502 depends
= ['_ctypes/ctypes.h']
1504 if sys
.platform
== 'darwin':
1505 sources
.append('_ctypes/darwin/dlfcn_simple.c')
1506 extra_compile_args
.append('-DMACOSX')
1507 include_dirs
.append('_ctypes/darwin')
1508 # XXX Is this still needed?
1509 ## extra_link_args.extend(['-read_only_relocs', 'warning'])
1511 elif sys
.platform
== 'sunos5':
1512 # XXX This shouldn't be necessary; it appears that some
1513 # of the assembler code is non-PIC (i.e. it has relocations
1514 # when it shouldn't. The proper fix would be to rewrite
1515 # the assembler code to be PIC.
1516 # This only works with GCC; the Sun compiler likely refuses
1517 # this option. If you want to compile ctypes with the Sun
1518 # compiler, please research a proper solution, instead of
1519 # finding some -z option for the Sun compiler.
1520 extra_link_args
.append('-mimpure-text')
1522 elif sys
.platform
.startswith('hp-ux'):
1523 extra_link_args
.append('-fPIC')
1525 ext
= Extension('_ctypes',
1526 include_dirs
=include_dirs
,
1527 extra_compile_args
=extra_compile_args
,
1528 extra_link_args
=extra_link_args
,
1532 ext_test
= Extension('_ctypes_test',
1533 sources
=['_ctypes/_ctypes_test.c'])
1534 self
.extensions
.extend([ext
, ext_test
])
1536 if not '--with-system-ffi' in sysconfig
.get_config_var("CONFIG_ARGS"):
1539 if sys
.platform
== 'darwin':
1540 # OS X 10.5 comes with libffi.dylib; the include files are
1541 # in /usr/include/ffi
1542 inc_dirs
.append('/usr/include/ffi')
1544 ffi_inc
= find_file('ffi.h', [], inc_dirs
)
1545 if ffi_inc
is not None:
1546 ffi_h
= ffi_inc
[0] + '/ffi.h'
1549 line
= fp
.readline()
1553 if line
.startswith('#define LIBFFI_H'):
1556 if ffi_inc
is not None:
1557 for lib_name
in ('ffi_convenience', 'ffi_pic', 'ffi'):
1558 if (self
.compiler
.find_library_file(lib_dirs
, lib_name
)):
1562 if ffi_inc
and ffi_lib
:
1563 ext
.include_dirs
.extend(ffi_inc
)
1564 ext
.libraries
.append(ffi_lib
)
1565 self
.use_system_libffi
= True
1568 class PyBuildInstall(install
):
1569 # Suppress the warning about installation into the lib_dynload
1570 # directory, which is not in sys.path when running Python during
1572 def initialize_options (self
):
1573 install
.initialize_options(self
)
1576 class PyBuildInstallLib(install_lib
):
1577 # Do exactly what install_lib does but make sure correct access modes get
1578 # set on installed directories and files. All installed files with get
1579 # mode 644 unless they are a shared library in which case they will get
1580 # mode 755. All installed directories will get mode 755.
1582 so_ext
= sysconfig
.get_config_var("SO")
1585 outfiles
= install_lib
.install(self
)
1586 self
.set_file_modes(outfiles
, 0o644, 0o755)
1587 self
.set_dir_modes(self
.install_dir
, 0o755)
1590 def set_file_modes(self
, files
, defaultMode
, sharedLibMode
):
1591 if not self
.is_chmod_supported(): return
1592 if not files
: return
1594 for filename
in files
:
1595 if os
.path
.islink(filename
): continue
1597 if filename
.endswith(self
.so_ext
): mode
= sharedLibMode
1598 log
.info("changing mode of %s to %o", filename
, mode
)
1599 if not self
.dry_run
: os
.chmod(filename
, mode
)
1601 def set_dir_modes(self
, dirname
, mode
):
1602 if not self
.is_chmod_supported(): return
1603 os
.walk(dirname
, self
.set_dir_modes_visitor
, mode
)
1605 def set_dir_modes_visitor(self
, mode
, dirname
, names
):
1606 if os
.path
.islink(dirname
): return
1607 log
.info("changing mode of %s to %o", dirname
, mode
)
1608 if not self
.dry_run
: os
.chmod(dirname
, mode
)
1610 def is_chmod_supported(self
):
1611 return hasattr(os
, 'chmod')
1614 Python is an interpreted, interactive, object-oriented programming
1615 language. It is often compared to Tcl, Perl, Scheme or Java.
1617 Python combines remarkable power with very clear syntax. It has
1618 modules, classes, exceptions, very high level dynamic data types, and
1619 dynamic typing. There are interfaces to many system calls and
1620 libraries, as well as to various windowing systems (X11, Motif, Tk,
1621 Mac, MFC). New built-in modules are easily written in C or C++. Python
1622 is also usable as an extension language for applications that need a
1623 programmable interface.
1625 The Python implementation is portable: it runs on many brands of UNIX,
1626 on Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't
1627 listed here, it may still be supported, if there's a C compiler for
1628 it. Ask around on comp.lang.python -- or just try compiling Python
1633 Development Status :: 3 - Alpha
1634 Development Status :: 6 - Mature
1635 License :: OSI Approved :: Python Software Foundation License
1636 Natural Language :: English
1637 Programming Language :: C
1638 Programming Language :: Python
1639 Topic :: Software Development
1643 # turn off warnings when deprecated modules are imported
1645 warnings
.filterwarnings("ignore",category
=DeprecationWarning)
1646 setup(# PyPI Metadata (PEP 301)
1648 version
= sys
.version
.split()[0],
1649 url
= "http://www.python.org/%s" % sys
.version
[:3],
1650 maintainer
= "Guido van Rossum and the Python community",
1651 maintainer_email
= "python-dev@python.org",
1652 description
= "A high-level object-oriented programming language",
1653 long_description
= SUMMARY
.strip(),
1654 license
= "PSF license",
1655 classifiers
= [x
for x
in CLASSIFIERS
.split("\n") if x
],
1656 platforms
= ["Many"],
1659 cmdclass
= {'build_ext':PyBuildExt
, 'install':PyBuildInstall
,
1660 'install_lib':PyBuildInstallLib
},
1661 # The struct module is defined here, because build_ext won't be
1662 # called unless there's at least one extension module defined.
1663 ext_modules
=[Extension('_struct', ['_struct.c'])],
1665 # Scripts to install
1666 scripts
= ['Tools/scripts/pydoc', 'Tools/scripts/idle',
1667 'Tools/scripts/2to3',
1672 if __name__
== '__main__':