Movatterモバイル変換


[0]ホーム

URL:


Wayback Machine
65 captures
15 Dec 2019 - 06 Jan 2024
SepAPRJan
Previous capture09Next capture
202020222024
success
fail
COLLECTED BY
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20220409155111/https://github.com/python/cpython/blob/2.7/setup.py
Skip to content
Sign up
Sign up
Permalink
2.7
Switch branches/tags

cpython/setup.py/
Jump to
Code definitions
get_platformFunctionadd_dir_to_listFunctionmacosx_sdk_rootFunctionis_macosx_sdk_pathFunctionfind_fileFunctionfind_library_fileFunctionmodule_enabledFunctionfind_module_fileFunctionPyBuildExtClass__init__Functionbuild_extensionsFunctionprint_three_columnFunctionbuild_extensionFunctionadd_multiarch_pathsFunctionadd_gcc_pathsFunctiondetect_modulesFunctionallow_db_verFunctiongen_db_minor_ver_numsFunctiondb_foundClassmacSrcExistsFunctionaddMacExtensionFunctiondetect_tkinter_explicitlyFunctiondetect_tkinter_darwinFunctiondetect_tkinterFunctionconfigure_ctypes_darwinFunctionconfigure_ctypesFunctiondetect_ctypesFunction_detect_nisFunctionPyBuildInstallClassinitialize_optionsFunctionPyBuildInstallLibClassinstallFunctionset_file_modesFunctionset_dir_modesFunctionset_dir_modes_visitorFunctionis_chmod_supportedFunctionmainFunction
Code navigation index up-to-date

Go to file
  • Go to file
  • Copy path
  • Copy permalink
 
 
Cannot retrieve contributors at this time
2352 lines (2071 sloc) 100 KB
# Autodetecting setup.py script for building the Python extensions
#
__version__="$Revision$"
importsys,os,imp,re,optparse
fromglobimportglob
fromplatformimportmachineasplatform_machine
importsysconfig
fromdistutilsimportlog
fromdistutilsimporttext_file
fromdistutils.errorsimport*
fromdistutils.coreimportExtension,setup
fromdistutils.command.build_extimportbuild_ext
fromdistutils.command.installimportinstall
fromdistutils.command.install_libimportinstall_lib
fromdistutils.spawnimportfind_executable
cross_compiling="_PYTHON_HOST_PLATFORM"inos.environ
defget_platform():
# cross build
if"_PYTHON_HOST_PLATFORM"inos.environ:
returnos.environ["_PYTHON_HOST_PLATFORM"]
# Get value of sys.platform
ifsys.platform.startswith('osf1'):
return'osf1'
returnsys.platform
host_platform=get_platform()
# Were we compiled --with-pydebug or with #define Py_DEBUG?
COMPILED_WITH_PYDEBUG= ('--with-pydebug'insysconfig.get_config_var("CONFIG_ARGS"))
# This global variable is used to hold the list of modules to be disabled.
disabled_module_list= []
defadd_dir_to_list(dirlist,dir):
"""Add the directory 'dir' to the list 'dirlist' (at the front) if
1) 'dir' is not already in 'dirlist'
2) 'dir' actually exists, and is a directory."""
ifdirisnotNoneanddirnotindirlist:
ifhost_platform=='darwin'andis_macosx_sdk_path(dir):
# If in a macOS SDK path, check relative to the SDK root
dir_exists=os.path.isdir(
os.path.join(macosx_sdk_root(),dir[1:]))
else:
dir_exists=os.path.isdir(dir)
ifdir_exists:
dirlist.insert(0,dir)
MACOS_SDK_ROOT=None
defmacosx_sdk_root():
"""Return the directory of the current macOS SDK.
If no SDK was explicitly configured, call the compiler to find which
include files paths are being searched by default. Use '/' if the
compiler is searching /usr/include (meaning system header files are
installed) or use the root of an SDK if that is being searched.
(The SDK may be supplied via Xcode or via the Command Line Tools).
The SDK paths used by Apple-supplied tool chains depend on the
setting of various variables; see the xcrun man page for more info.
"""
globalMACOS_SDK_ROOT
# If already called, return cached result.
ifMACOS_SDK_ROOT:
returnMACOS_SDK_ROOT
cflags=sysconfig.get_config_var('CFLAGS')
m=re.search(r'-isysroot\s+(\S+)',cflags)
ifmisnotNone:
MACOS_SDK_ROOT=m.group(1)
else:
MACOS_SDK_ROOT='/'
cc=sysconfig.get_config_var('CC')
tmpfile='/tmp/setup_sdk_root.%d'%os.getpid()
try:
os.unlink(tmpfile)
except:
pass
ret=os.system('%s -E -v - </dev/null 2>%s 1>/dev/null'% (cc,tmpfile))
in_incdirs=False
try:
ifret>>8==0:
withopen(tmpfile)asfp:
forlineinfp.readlines():
ifline.startswith("#include <...>"):
in_incdirs=True
elifline.startswith("End of search list"):
in_incdirs=False
elifin_incdirs:
line=line.strip()
ifline=='/usr/include':
MACOS_SDK_ROOT='/'
elifline.endswith(".sdk/usr/include"):
MACOS_SDK_ROOT=line[:-12]
finally:
os.unlink(tmpfile)
returnMACOS_SDK_ROOT
defis_macosx_sdk_path(path):
"""
Returns True if 'path' can be located in an OSX SDK
"""
return ( (path.startswith('/usr/')andnotpath.startswith('/usr/local'))
orpath.startswith('/System/')
orpath.startswith('/Library/') )
deffind_file(filename,std_dirs,paths):
"""Searches for the directory where a given file is located,
and returns a possibly-empty list of additional directories, or None
if the file couldn't be found at all.
'filename' is the name of a file, such as readline.h or libcrypto.a.
'std_dirs' is the list of standard system directories; if the
file is found in one of them, no additional directives are needed.
'paths' is a list of additional locations to check; if the file is
found in one of them, the resulting list will contain the directory.
"""
ifhost_platform=='darwin':
# Honor the MacOSX SDK setting when one was specified.
# An SDK is a directory with the same structure as a real
# system, but with only header files and libraries.
sysroot=macosx_sdk_root()
# Check the standard locations
fordirinstd_dirs:
f=os.path.join(dir,filename)
ifhost_platform=='darwin'andis_macosx_sdk_path(dir):
f=os.path.join(sysroot,dir[1:],filename)
ifos.path.exists(f):return []
# Check the additional directories
fordirinpaths:
f=os.path.join(dir,filename)
ifhost_platform=='darwin'andis_macosx_sdk_path(dir):
f=os.path.join(sysroot,dir[1:],filename)
ifos.path.exists(f):
return [dir]
# Not found anywhere
returnNone
deffind_library_file(compiler,libname,std_dirs,paths):
result=compiler.find_library_file(std_dirs+paths,libname)
ifresultisNone:
returnNone
ifhost_platform=='darwin':
sysroot=macosx_sdk_root()
# Check whether the found file is in one of the standard directories
dirname=os.path.dirname(result)
forpinstd_dirs:
# Ensure path doesn't end with path separator
p=p.rstrip(os.sep)
ifhost_platform=='darwin'andis_macosx_sdk_path(p):
# Note that, as of Xcode 7, Apple SDKs may contain textual stub
# libraries with .tbd extensions rather than the normal .dylib
# shared libraries installed in /. The Apple compiler tool
# chain handles this transparently but it can cause problems
# for programs that are being built with an SDK and searching
# for specific libraries. Distutils find_library_file() now
# knows to also search for and return .tbd files. But callers
# of find_library_file need to keep in mind that the base filename
# of the returned SDK library file might have a different extension
# from that of the library file installed on the running system,
# for example:
# /Applications/Xcode.app/Contents/Developer/Platforms/
# MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
# usr/lib/libedit.tbd
# vs
# /usr/lib/libedit.dylib
ifos.path.join(sysroot,p[1:])==dirname:
return [ ]
ifp==dirname:
return [ ]
# Otherwise, it must have been in one of the additional directories,
# so we have to figure out which one.
forpinpaths:
# Ensure path doesn't end with path separator
p=p.rstrip(os.sep)
ifhost_platform=='darwin'andis_macosx_sdk_path(p):
ifos.path.join(sysroot,p[1:])==dirname:
return [p ]
ifp==dirname:
return [p]
else:
assertFalse,"Internal error: Path not found in std_dirs or paths"
defmodule_enabled(extlist,modname):
"""Returns whether the module 'modname' is present in the list
of extensions 'extlist'."""
extlist= [extforextinextlistifext.name==modname]
returnlen(extlist)
deffind_module_file(module,dirlist):
"""Find a module in a set of possible folders. If it is not found
return the unadorned filename"""
list=find_file(module, [],dirlist)
ifnotlist:
returnmodule
iflen(list)>1:
log.info("WARNING: multiple copies of %s found"%module)
returnos.path.join(list[0],module)
classPyBuildExt(build_ext):
def__init__(self,dist):
build_ext.__init__(self,dist)
self.failed= []
defbuild_extensions(self):
# Detect which modules should be compiled
missing=self.detect_modules()
# Remove modules that are present on the disabled list
extensions= [extforextinself.extensions
ifext.namenotindisabled_module_list]
# move ctypes to the end, it depends on other modules
ext_map=dict((ext.name,i)fori,extinenumerate(extensions))
if"_ctypes"inext_map:
ctypes=extensions.pop(ext_map["_ctypes"])
extensions.append(ctypes)
self.extensions=extensions
# Fix up the autodetected modules, prefixing all the source files
# with Modules/ and adding Python's include directory to the path.
(srcdir,)=sysconfig.get_config_vars('srcdir')
ifnotsrcdir:
# Maybe running on Windows but not using CYGWIN?
raiseValueError("No source directory; cannot proceed.")
srcdir=os.path.abspath(srcdir)
moddirlist= [os.path.join(srcdir,'Modules')]
# Platform-dependent module source and include directories
incdirlist= []
ifhost_platform=='darwin'and ("--disable-toolbox-glue"notin
sysconfig.get_config_var("CONFIG_ARGS")):
# Mac OS X also includes some mac-specific modules
macmoddir=os.path.join(srcdir,'Mac/Modules')
moddirlist.append(macmoddir)
incdirlist.append(os.path.join(srcdir,'Mac/Include'))
# Fix up the paths for scripts, too
self.distribution.scripts= [os.path.join(srcdir,filename)
forfilenameinself.distribution.scripts]
# Python header files
headers= [sysconfig.get_config_h_filename()]
headers+=glob(os.path.join(sysconfig.get_path('include'),"*.h"))
forextinself.extensions[:]:
ext.sources= [find_module_file(filename,moddirlist)
forfilenameinext.sources ]
ifext.dependsisnotNone:
ext.depends= [find_module_file(filename,moddirlist)
forfilenameinext.depends]
else:
ext.depends= []
# re-compile extensions if a header file has been changed
ext.depends.extend(headers)
# platform specific include directories
ext.include_dirs.extend(incdirlist)
# If a module has already been built statically,
# don't build it here
ifext.nameinsys.builtin_module_names:
self.extensions.remove(ext)
# Parse Modules/Setup and Modules/Setup.local to figure out which
# modules are turned on in the file.
remove_modules= []
forfilenamein ('Modules/Setup','Modules/Setup.local'):
input=text_file.TextFile(filename,join_lines=1)
while1:
line=input.readline()
ifnotline:break
line=line.split()
remove_modules.append(line[0])
input.close()
forextinself.extensions[:]:
ifext.nameinremove_modules:
self.extensions.remove(ext)
# When you run "make CC=altcc" or something similar, you really want
# those environment variables passed into the setup.py phase. Here's
# a small set of useful ones.
compiler=os.environ.get('CC')
args= {}
# unfortunately, distutils doesn't let us provide separate C and C++
# compilers
ifcompilerisnotNone:
(ccshared,cflags)=sysconfig.get_config_vars('CCSHARED','CFLAGS')
args['compiler_so']=compiler+' '+ccshared+' '+cflags
self.compiler.set_executables(**args)
build_ext.build_extensions(self)
longest=0
ifself.extensions:
longest=max([len(e.name)foreinself.extensions])
ifself.failed:
longest=max(longest,max([len(name)fornameinself.failed]))
defprint_three_column(lst):
lst.sort(key=str.lower)
# guarantee zip() doesn't drop anything
whilelen(lst)%3:
lst.append("")
fore,f,ginzip(lst[::3],lst[1::3],lst[2::3]):
print"%-*s %-*s %-*s"% (longest,e,longest,f,
longest,g)
ifmissing:
print
print ("Python build finished, but the necessary bits to build "
"these modules were not found:")
print_three_column(missing)
print ("To find the necessary bits, look in setup.py in"
" detect_modules() for the module's name.")
print
ifself.failed:
failed=self.failed[:]
print
print"Failed to build these modules:"
print_three_column(failed)
print
defbuild_extension(self,ext):
ifext.name=='_ctypes':
ifnotself.configure_ctypes(ext):
return
try:
build_ext.build_extension(self,ext)
except (CCompilerError,DistutilsError),why:
self.announce('WARNING: building of extension "%s" failed: %s'%
(ext.name,sys.exc_info()[1]))
self.failed.append(ext.name)
return
# Workaround for Mac OS X: The Carbon-based modules cannot be
# reliably imported into a command-line Python
if'Carbon'inext.extra_link_args:
self.announce(
'WARNING: skipping import check for Carbon-based "%s"'%
ext.name)
return
ifhost_platform=='darwin'and (
sys.maxint>2**32and'-arch'inext.extra_link_args):
# Don't bother doing an import check when an extension was
# build with an explicit '-arch' flag on OSX. That's currently
# only used to build 32-bit only extensions in a 4-way
# universal build and loading 32-bit code into a 64-bit
# process will fail.
self.announce(
'WARNING: skipping import check for "%s"'%
ext.name)
return
# Workaround for Cygwin: Cygwin currently has fork issues when many
# modules have been imported
ifhost_platform=='cygwin':
self.announce('WARNING: skipping import check for Cygwin-based "%s"'
%ext.name)
return
ext_filename=os.path.join(
self.build_lib,
self.get_ext_filename(self.get_ext_fullname(ext.name)))
# Don't try to load extensions for cross builds
ifcross_compiling:
return
try:
imp.load_dynamic(ext.name,ext_filename)
exceptImportError,why:
self.failed.append(ext.name)
self.announce('*** WARNING: renaming "%s" since importing it'
' failed: %s'% (ext.name,why),level=3)
assertnotself.inplace
basename,tail=os.path.splitext(ext_filename)
newname=basename+"_failed"+tail
ifos.path.exists(newname):
os.remove(newname)
os.rename(ext_filename,newname)
# XXX -- This relies on a Vile HACK in
# distutils.command.build_ext.build_extension(). The
# _built_objects attribute is stored there strictly for
# use here.
# If there is a failure, _built_objects may not be there,
# so catch the AttributeError and move on.
try:
forfilenameinself._built_objects:
os.remove(filename)
exceptAttributeError:
self.announce('unable to remove files (ignored)')
except:
exc_type,why,tb=sys.exc_info()
self.announce('*** WARNING: importing extension "%s" '
'failed with %s: %s'% (ext.name,exc_type,why),
level=3)
self.failed.append(ext.name)
defadd_multiarch_paths(self):
# Debian/Ubuntu multiarch support.
# https://wiki.ubuntu.com/MultiarchSpec
cc=sysconfig.get_config_var('CC')
tmpfile=os.path.join(self.build_temp,'multiarch')
ifnotos.path.exists(self.build_temp):
os.makedirs(self.build_temp)
ret=os.system(
'%s -print-multiarch > %s 2> /dev/null'% (cc,tmpfile))
multiarch_path_component=''
try:
ifret>>8==0:
withopen(tmpfile)asfp:
multiarch_path_component=fp.readline().strip()
finally:
os.unlink(tmpfile)
ifmultiarch_path_component!='':
add_dir_to_list(self.compiler.library_dirs,
'/usr/lib/'+multiarch_path_component)
add_dir_to_list(self.compiler.include_dirs,
'/usr/include/'+multiarch_path_component)
return
ifnotfind_executable('dpkg-architecture'):
return
opt=''
ifcross_compiling:
opt='-t'+sysconfig.get_config_var('HOST_GNU_TYPE')
tmpfile=os.path.join(self.build_temp,'multiarch')
ifnotos.path.exists(self.build_temp):
os.makedirs(self.build_temp)
ret=os.system(
'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null'%
(opt,tmpfile))
try:
ifret>>8==0:
withopen(tmpfile)asfp:
multiarch_path_component=fp.readline().strip()
add_dir_to_list(self.compiler.library_dirs,
'/usr/lib/'+multiarch_path_component)
add_dir_to_list(self.compiler.include_dirs,
'/usr/include/'+multiarch_path_component)
finally:
os.unlink(tmpfile)
defadd_gcc_paths(self):
gcc=sysconfig.get_config_var('CC')
tmpfile=os.path.join(self.build_temp,'gccpaths')
ifnotos.path.exists(self.build_temp):
os.makedirs(self.build_temp)
ret=os.system('%s -E -v - </dev/null 2>%s 1>/dev/null'% (gcc,tmpfile))
is_gcc=False
in_incdirs=False
inc_dirs= []
lib_dirs= []
try:
ifret>>8==0:
withopen(tmpfile)asfp:
forlineinfp.readlines():
ifline.startswith("gcc version"):
is_gcc=True
elifline.startswith("#include <...>"):
in_incdirs=True
elifline.startswith("End of search list"):
in_incdirs=False
elifis_gccandline.startswith("LIBRARY_PATH"):
fordinline.strip().split("=")[1].split(":"):
d=os.path.normpath(d)
if'/gcc/'notind:
add_dir_to_list(self.compiler.library_dirs,
d)
elifis_gccandin_incdirsand'/gcc/'notinline:
add_dir_to_list(self.compiler.include_dirs,
line.strip())
finally:
os.unlink(tmpfile)
defdetect_modules(self):
# Ensure that /usr/local is always used
ifnotcross_compiling:
add_dir_to_list(self.compiler.library_dirs,'/usr/local/lib')
add_dir_to_list(self.compiler.include_dirs,'/usr/local/include')
ifcross_compiling:
self.add_gcc_paths()
self.add_multiarch_paths()
# Add paths specified in the environment variables LDFLAGS and
# CPPFLAGS for header and library files.
# We must get the values from the Makefile and not the environment
# directly since an inconsistently reproducible issue comes up where
# the environment variable is not set even though the value were passed
# into configure and stored in the Makefile (issue found on OS X 10.3).
forenv_var,arg_name,dir_listin (
('LDFLAGS','-R',self.compiler.runtime_library_dirs),
('LDFLAGS','-L',self.compiler.library_dirs),
('CPPFLAGS','-I',self.compiler.include_dirs)):
env_val=sysconfig.get_config_var(env_var)
ifenv_val:
# To prevent optparse from raising an exception about any
# options in env_val that it doesn't know about we strip out
# all double dashes and any dashes followed by a character
# that is not for the option we are dealing with.
#
# Please note that order of the regex is important! We must
# strip out double-dashes first so that we don't end up with
# substituting "--Long" to "-Long" and thus lead to "ong" being
# used for a library directory.
env_val=re.sub(r'(^|\s+)-(-|(?!%s))'%arg_name[1],
' ',env_val)
parser=optparse.OptionParser()
# Make sure that allowing args interspersed with options is
# allowed
parser.allow_interspersed_args=True
parser.error=lambdamsg:None
parser.add_option(arg_name,dest="dirs",action="append")
options=parser.parse_args(env_val.split())[0]
ifoptions.dirs:
fordirectoryinreversed(options.dirs):
add_dir_to_list(dir_list,directory)
ifos.path.normpath(sys.prefix)!='/usr' \
andnotsysconfig.get_config_var('PYTHONFRAMEWORK'):
# OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
# (PYTHONFRAMEWORK is set) to avoid # linking problems when
# building a framework with different architectures than
# the one that is currently installed (issue #7473)
add_dir_to_list(self.compiler.library_dirs,
sysconfig.get_config_var("LIBDIR"))
add_dir_to_list(self.compiler.include_dirs,
sysconfig.get_config_var("INCLUDEDIR"))
try:
have_unicode=unicode
exceptNameError:
have_unicode=0
# lib_dirs and inc_dirs are used to search for files;
# if a file is found in one of those directories, it can
# be assumed that no additional -I,-L directives are needed.
inc_dirs=self.compiler.include_dirs[:]
lib_dirs=self.compiler.library_dirs[:]
ifnotcross_compiling:
fordin (
'/usr/include',
):
add_dir_to_list(inc_dirs,d)
fordin (
'/lib64','/usr/lib64',
'/lib','/usr/lib',
):
add_dir_to_list(lib_dirs,d)
exts= []
missing= []
config_h=sysconfig.get_config_h_filename()
config_h_vars=sysconfig.parse_config_h(open(config_h))
srcdir=sysconfig.get_config_var('srcdir')
# Check for AtheOS which has libraries in non-standard locations
ifhost_platform=='atheos':
lib_dirs+= ['/system/libs','/atheos/autolnk/lib']
lib_dirs+=os.getenv('LIBRARY_PATH','').split(os.pathsep)
inc_dirs+= ['/system/include','/atheos/autolnk/include']
inc_dirs+=os.getenv('C_INCLUDE_PATH','').split(os.pathsep)
# OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
ifhost_platformin ['osf1','unixware7','openunix8']:
lib_dirs+= ['/usr/ccs/lib']
# HP-UX11iv3 keeps files in lib/hpux folders.
ifhost_platform=='hp-ux11':
lib_dirs+= ['/usr/lib/hpux64','/usr/lib/hpux32']
ifhost_platform=='darwin':
# This should work on any unixy platform ;-)
# If the user has bothered specifying additional -I and -L flags
# in OPT and LDFLAGS we might as well use them here.
# NOTE: using shlex.split would technically be more correct, but
# also gives a bootstrap problem. Let's hope nobody uses directories
# with whitespace in the name to store libraries.
cflags,ldflags=sysconfig.get_config_vars(
'CFLAGS','LDFLAGS')
foritemincflags.split():
ifitem.startswith('-I'):
inc_dirs.append(item[2:])
foriteminldflags.split():
ifitem.startswith('-L'):
lib_dirs.append(item[2:])
# Check for MacOS X, which doesn't need libm.a at all
math_libs= ['m']
ifhost_platformin ['darwin','beos']:
math_libs= []
# XXX Omitted modules: gl, pure, dl, SGI-specific modules
#
# The following modules are all pretty straightforward, and compile
# on pretty much any POSIXish platform.
#
# Some modules that are normally always on:
#exts.append( Extension('_weakref', ['_weakref.c']) )
# array objects
exts.append(Extension('array', ['arraymodule.c']) )
shared_math='Modules/_math.o'
# complex math library functions
exts.append(Extension('cmath', ['cmathmodule.c'],
extra_objects=[shared_math],
depends=['_math.h',shared_math],
libraries=math_libs) )
# math library functions, e.g. sin()
exts.append(Extension('math', ['mathmodule.c'],
extra_objects=[shared_math],
depends=['_math.h',shared_math],
libraries=math_libs) )
# fast string operations implemented in C
exts.append(Extension('strop', ['stropmodule.c']) )
# time operations and variables
exts.append(Extension('time', ['timemodule.c'],
libraries=math_libs) )
exts.append(Extension('datetime', ['datetimemodule.c','timemodule.c'],
libraries=math_libs) )
# fast iterator tools implemented in C
exts.append(Extension("itertools", ["itertoolsmodule.c"]) )
# code that will be builtins in the future, but conflict with the
# current builtins
exts.append(Extension('future_builtins', ['future_builtins.c']) )
# random number generator implemented in C
exts.append(Extension("_random", ["_randommodule.c"]) )
# high-performance collections
exts.append(Extension("_collections", ["_collectionsmodule.c"]) )
# bisect
exts.append(Extension("_bisect", ["_bisectmodule.c"]) )
# heapq
exts.append(Extension("_heapq", ["_heapqmodule.c"]) )
# operator.add() and similar goodies
exts.append(Extension('operator', ['operator.c']) )
# Python 3.1 _io library
exts.append(Extension("_io",
["_io/bufferedio.c","_io/bytesio.c","_io/fileio.c",
"_io/iobase.c","_io/_iomodule.c","_io/stringio.c","_io/textio.c"],
depends=["_io/_iomodule.h"],include_dirs=["Modules/_io"]))
# _functools
exts.append(Extension("_functools", ["_functoolsmodule.c"]) )
# _json speedups
exts.append(Extension("_json", ["_json.c"]) )
# Python C API test module
exts.append(Extension('_testcapi', ['_testcapimodule.c'],
depends=['testcapi_long.h']) )
# profilers (_lsprof is for cProfile.py)
exts.append(Extension('_hotshot', ['_hotshot.c']) )
exts.append(Extension('_lsprof', ['_lsprof.c','rotatingtree.c']) )
# static Unicode character database
ifhave_unicode:
exts.append(Extension('unicodedata', ['unicodedata.c']) )
else:
missing.append('unicodedata')
# access to ISO C locale support
data=open('pyconfig.h').read()
m=re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*",data)
ifmisnotNone:
locale_libs= ['intl']
else:
locale_libs= []
ifhost_platform=='darwin':
locale_extra_link_args= ['-framework','CoreFoundation']
else:
locale_extra_link_args= []
exts.append(Extension('_locale', ['_localemodule.c'],
libraries=locale_libs,
extra_link_args=locale_extra_link_args) )
# Modules with some UNIX dependencies -- on by default:
# (If you have a really backward UNIX, select and socket may not be
# supported...)
# fcntl(2) and ioctl(2)
libs= []
if (config_h_vars.get('FLOCK_NEEDS_LIBBSD',False)):
# May be necessary on AIX for flock function
libs= ['bsd']
exts.append(Extension('fcntl', ['fcntlmodule.c'],libraries=libs) )
# pwd(3)
exts.append(Extension('pwd', ['pwdmodule.c']) )
# grp(3)
exts.append(Extension('grp', ['grpmodule.c']) )
# spwd, shadow passwords
if (config_h_vars.get('HAVE_GETSPNAM',False)or
config_h_vars.get('HAVE_GETSPENT',False)):
exts.append(Extension('spwd', ['spwdmodule.c']) )
else:
missing.append('spwd')
# select(2); not on ancient System V
exts.append(Extension('select', ['selectmodule.c']) )
# Fred Drake's interface to the Python parser
exts.append(Extension('parser', ['parsermodule.c']) )
# cStringIO and cPickle
exts.append(Extension('cStringIO', ['cStringIO.c']) )
exts.append(Extension('cPickle', ['cPickle.c']) )
# Memory-mapped files (also works on Win32).
ifhost_platformnotin ['atheos']:
exts.append(Extension('mmap', ['mmapmodule.c']) )
else:
missing.append('mmap')
# Lance Ellinghaus's syslog module
# syslog daemon interface
exts.append(Extension('syslog', ['syslogmodule.c']) )
# George Neville-Neil's timing module:
# Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html
# http://mail.python.org/pipermail/python-dev/2006-January/060023.html
#exts.append( Extension('timing', ['timingmodule.c']) )
#
# Here ends the simple stuff. From here on, modules need certain
# libraries, are platform-specific, or present other surprises.
#
# Multimedia modules
# These don't work for 64-bit platforms!!!
# These represent audio samples or images as strings:
# Operations on audio samples
# According to #993173, this one should actually work fine on
# 64-bit platforms.
exts.append(Extension('audioop', ['audioop.c']) )
# Disabled on 64-bit platforms
ifsys.maxsize!=9223372036854775807L:
# Operations on images
exts.append(Extension('imageop', ['imageop.c']) )
else:
missing.extend(['imageop'])
# readline
do_readline=self.compiler.find_library_file(lib_dirs,'readline')
readline_termcap_library=""
curses_library=""
# Determine if readline is already linked against curses or tinfo.
ifdo_readlineandfind_executable('ldd'):
fp=os.popen("ldd %s"%do_readline)
ldd_output=fp.readlines()
ret=fp.close()
ifretisNoneorret>>8==0:
forlninldd_output:
if'curses'inln:
readline_termcap_library=re.sub(
r'.*lib(n?cursesw?)\.so.*',r'\1',ln
).rstrip()
break
if'tinfo'inln:# termcap interface split out from ncurses
readline_termcap_library='tinfo'
break
# Issue 7384: If readline is already linked against curses,
# use the same library for the readline and curses modules.
if'curses'inreadline_termcap_library:
curses_library=readline_termcap_library
elifself.compiler.find_library_file(lib_dirs,'ncursesw'):
curses_library='ncursesw'
elifself.compiler.find_library_file(lib_dirs,'ncurses'):
curses_library='ncurses'
elifself.compiler.find_library_file(lib_dirs,'curses'):
curses_library='curses'
ifhost_platform=='darwin':
os_release=int(os.uname()[2].split('.')[0])
dep_target=sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
if (dep_targetand
(tuple(int(n)fornindep_target.split('.')[0:2])
< (10,5) ) ):
os_release=8
ifos_release<9:
# MacOSX 10.4 has a broken readline. Don't try to build
# the readline module unless the user has installed a fixed
# readline package
iffind_file('readline/rlconf.h',inc_dirs, [])isNone:
do_readline=False
ifdo_readline:
ifhost_platform=='darwin'andos_release<9:
# In every directory on the search path search for a dynamic
# library and then a static library, instead of first looking
# for dynamic libraries on the entire path.
# This way a statically linked custom readline gets picked up
# before the (possibly broken) dynamic library in /usr/lib.
readline_extra_link_args= ('-Wl,-search_paths_first',)
else:
readline_extra_link_args= ()
readline_libs= ['readline']
ifreadline_termcap_library:
pass# Issue 7384: Already linked against curses or tinfo.
elifcurses_library:
readline_libs.append(curses_library)
elifself.compiler.find_library_file(lib_dirs+
['/usr/lib/termcap'],
'termcap'):
readline_libs.append('termcap')
exts.append(Extension('readline', ['readline.c'],
library_dirs=['/usr/lib/termcap'],
extra_link_args=readline_extra_link_args,
libraries=readline_libs) )
else:
missing.append('readline')
# crypt module.
ifself.compiler.find_library_file(lib_dirs,'crypt'):
libs= ['crypt']
else:
libs= []
exts.append(Extension('crypt', ['cryptmodule.c'],libraries=libs) )
# CSV files
exts.append(Extension('_csv', ['_csv.c']) )
# socket(2)
exts.append(Extension('_socket', ['socketmodule.c','timemodule.c'],
depends=['socketmodule.h'],
libraries=math_libs) )
# Detect SSL support for the socket module (via _ssl)
search_for_ssl_incs_in= [
'/usr/local/ssl/include',
'/usr/contrib/ssl/include/'
]
ssl_incs=find_file('openssl/ssl.h',inc_dirs,
search_for_ssl_incs_in
)
ifssl_incsisnotNone:
krb5_h=find_file('krb5.h',inc_dirs,
['/usr/kerberos/include'])
ifkrb5_h:
ssl_incs+=krb5_h
ssl_libs=find_library_file(self.compiler,'ssl',lib_dirs,
['/usr/local/ssl/lib',
'/usr/contrib/ssl/lib/'
] )
if (ssl_incsisnotNoneand
ssl_libsisnotNone):
exts.append(Extension('_ssl', ['_ssl.c'],
include_dirs=ssl_incs,
library_dirs=ssl_libs,
libraries= ['ssl','crypto'],
depends= ['socketmodule.h']), )
else:
missing.append('_ssl')
# find out which version of OpenSSL we have
openssl_ver=0
openssl_ver_re=re.compile(
'^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
# look for the openssl version header on the compiler search path.
opensslv_h=find_file('openssl/opensslv.h', [],
inc_dirs+search_for_ssl_incs_in)
ifopensslv_h:
name=os.path.join(opensslv_h[0],'openssl/opensslv.h')
ifhost_platform=='darwin'andis_macosx_sdk_path(name):
name=os.path.join(macosx_sdk_root(),name[1:])
try:
incfile=open(name,'r')
forlineinincfile:
m=openssl_ver_re.match(line)
ifm:
openssl_ver=eval(m.group(1))
exceptIOError,msg:
print"IOError while reading opensshv.h:",msg
pass
min_openssl_ver=0x00907000
have_any_openssl=ssl_incsisnotNoneandssl_libsisnotNone
have_usable_openssl= (have_any_openssland
openssl_ver>=min_openssl_ver)
ifhave_any_openssl:
ifhave_usable_openssl:
# The _hashlib module wraps optimized implementations
# of hash functions from the OpenSSL library.
exts.append(Extension('_hashlib', ['_hashopenssl.c'],
include_dirs=ssl_incs,
library_dirs=ssl_libs,
libraries= ['ssl','crypto']) )
else:
print ("warning: openssl 0x%08x is too old for _hashlib"%
openssl_ver)
missing.append('_hashlib')
ifCOMPILED_WITH_PYDEBUGornothave_usable_openssl:
# The _sha module implements the SHA1 hash algorithm.
exts.append(Extension('_sha', ['shamodule.c']) )
# The _md5 module implements the RSA Data Security, Inc. MD5
# Message-Digest Algorithm, described in RFC 1321. The
# necessary files md5.c and md5.h are included here.
exts.append(Extension('_md5',
sources= ['md5module.c','md5.c'],
depends= ['md5.h']) )
min_sha2_openssl_ver=0x00908000
ifCOMPILED_WITH_PYDEBUGoropenssl_ver<min_sha2_openssl_ver:
# OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
exts.append(Extension('_sha256', ['sha256module.c']) )
exts.append(Extension('_sha512', ['sha512module.c']) )
# Modules that provide persistent dictionary-like semantics. You will
# probably want to arrange for at least one of them to be available on
# your machine, though none are defined by default because of library
# dependencies. The Python module anydbm.py provides an
# implementation independent wrapper for these; dumbdbm.py provides
# similar functionality (but slower of course) implemented in Python.
# Sleepycat^WOracle Berkeley DB interface.
# http://www.oracle.com/database/berkeley-db/db/index.html
#
# This requires the Sleepycat^WOracle DB code. The supported versions
# are set below. Visit the URL above to download
# a release. Most open source OSes come with one or more
# versions of BerkeleyDB already installed.
max_db_ver= (5,3)
min_db_ver= (4,3)
db_setup_debug=False# verbose debug prints from this script?
defallow_db_ver(db_ver):
"""Returns a boolean if the given BerkeleyDB version is acceptable.
Args:
db_ver: A tuple of the version to verify.
"""
ifnot (min_db_ver<=db_ver<=max_db_ver):
returnFalse
# Use this function to filter out known bad configurations.
if (4,6)==db_ver[:2]:
# BerkeleyDB 4.6.x is not stable on many architectures.
arch=platform_machine()
ifarchnotin ('i386','i486','i586','i686',
'x86_64','ia64'):
returnFalse
returnTrue
defgen_db_minor_ver_nums(major):
ifmajor==5:
forxinrange(max_db_ver[1]+1):
ifallow_db_ver((5,x)):
yieldx
elifmajor==4:
forxinrange(9):
ifallow_db_ver((4,x)):
yieldx
elifmajor==3:
forxin (3,):
ifallow_db_ver((3,x)):
yieldx
else:
raiseValueError("unknown major BerkeleyDB version",major)
# construct a list of paths to look for the header file in on
# top of the normal inc_dirs.
db_inc_paths= [
'/usr/include/db4',
'/usr/local/include/db4',
'/opt/sfw/include/db4',
'/usr/include/db3',
'/usr/local/include/db3',
'/opt/sfw/include/db3',
# Fink defaults (http://fink.sourceforge.net/)
'/sw/include/db4',
'/sw/include/db3',
]
# 4.x minor number specific paths
forxingen_db_minor_ver_nums(4):
db_inc_paths.append('/usr/include/db4%d'%x)
db_inc_paths.append('/usr/include/db4.%d'%x)
db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include'%x)
db_inc_paths.append('/usr/local/include/db4%d'%x)
db_inc_paths.append('/pkg/db-4.%d/include'%x)
db_inc_paths.append('/opt/db-4.%d/include'%x)
# MacPorts default (http://www.macports.org/)
db_inc_paths.append('/opt/local/include/db4%d'%x)
# 3.x minor number specific paths
forxingen_db_minor_ver_nums(3):
db_inc_paths.append('/usr/include/db3%d'%x)
db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include'%x)
db_inc_paths.append('/usr/local/include/db3%d'%x)
db_inc_paths.append('/pkg/db-3.%d/include'%x)
db_inc_paths.append('/opt/db-3.%d/include'%x)
ifcross_compiling:
db_inc_paths= []
# Add some common subdirectories for Sleepycat DB to the list,
# based on the standard include directories. This way DB3/4 gets
# picked up when it is installed in a non-standard prefix and
# the user has added that prefix into inc_dirs.
std_variants= []
fordnininc_dirs:
std_variants.append(os.path.join(dn,'db3'))
std_variants.append(os.path.join(dn,'db4'))
forxingen_db_minor_ver_nums(4):
std_variants.append(os.path.join(dn,"db4%d"%x))
std_variants.append(os.path.join(dn,"db4.%d"%x))
forxingen_db_minor_ver_nums(3):
std_variants.append(os.path.join(dn,"db3%d"%x))
std_variants.append(os.path.join(dn,"db3.%d"%x))
db_inc_paths=std_variants+db_inc_paths
db_inc_paths= [pforpindb_inc_pathsifos.path.exists(p)]
db_ver_inc_map= {}
ifhost_platform=='darwin':
sysroot=macosx_sdk_root()
classdb_found(Exception):pass
try:
# See whether there is a Sleepycat header in the standard
# search path.
fordininc_dirs+db_inc_paths:
f=os.path.join(d,"db.h")
ifhost_platform=='darwin'andis_macosx_sdk_path(d):
f=os.path.join(sysroot,d[1:],"db.h")
ifdb_setup_debug:print"db: looking for db.h in",f
ifos.path.exists(f):
f=open(f).read()
m=re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)",f)
ifm:
db_major=int(m.group(1))
m=re.search(r"#define\WDB_VERSION_MINOR\W(\d+)",f)
db_minor=int(m.group(1))
db_ver= (db_major,db_minor)
# Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
ifdb_ver== (4,6):
m=re.search(r"#define\WDB_VERSION_PATCH\W(\d+)",f)
db_patch=int(m.group(1))
ifdb_patch<21:
print"db.h:",db_ver,"patch",db_patch,
print"being ignored (4.6.x must be >= 4.6.21)"
continue
if ( (db_vernotindb_ver_inc_map)and
allow_db_ver(db_ver) ):
# save the include directory with the db.h version
# (first occurrence only)
db_ver_inc_map[db_ver]=d
ifdb_setup_debug:
print"db.h: found",db_ver,"in",d
else:
# we already found a header for this library version
ifdb_setup_debug:print"db.h: ignoring",d
else:
# ignore this header, it didn't contain a version number
ifdb_setup_debug:
print"db.h: no version number version in",d
db_found_vers=db_ver_inc_map.keys()
db_found_vers.sort()
whiledb_found_vers:
db_ver=db_found_vers.pop()
db_incdir=db_ver_inc_map[db_ver]
# check lib directories parallel to the location of the header
db_dirs_to_check= [
db_incdir.replace("include",'lib64'),
db_incdir.replace("include",'lib'),
]
ifhost_platform!='darwin':
db_dirs_to_check=filter(os.path.isdir,db_dirs_to_check)
else:
# Same as other branch, but takes OSX SDK into account
tmp= []
fordnindb_dirs_to_check:
ifis_macosx_sdk_path(dn):
ifos.path.isdir(os.path.join(sysroot,dn[1:])):
tmp.append(dn)
else:
ifos.path.isdir(dn):
tmp.append(dn)
db_dirs_to_check=tmp
# Look for a version specific db-X.Y before an ambiguous dbX
# XXX should we -ever- look for a dbX name? Do any
# systems really not name their library by version and
# symlink to more general names?
fordblibin (('db-%d.%d'%db_ver),
('db%d%d'%db_ver),
('db%d'%db_ver[0])):
dblib_file=self.compiler.find_library_file(
db_dirs_to_check+lib_dirs,dblib )
ifdblib_file:
dblib_dir= [os.path.abspath(os.path.dirname(dblib_file)) ]
raisedb_found
else:
ifdb_setup_debug:print"db lib: ",dblib,"not found"
exceptdb_found:
ifdb_setup_debug:
print"bsddb using BerkeleyDB lib:",db_ver,dblib
print"bsddb lib dir:",dblib_dir," inc dir:",db_incdir
db_incs= [db_incdir]
dblibs= [dblib]
# We add the runtime_library_dirs argument because the
# BerkeleyDB lib we're linking against often isn't in the
# system dynamic library search path. This is usually
# correct and most trouble free, but may cause problems in
# some unusual system configurations (e.g. the directory
# is on an NFS server that goes away).
exts.append(Extension('_bsddb', ['_bsddb.c'],
depends= ['bsddb.h'],
library_dirs=dblib_dir,
runtime_library_dirs=dblib_dir,
include_dirs=db_incs,
libraries=dblibs))
else:
ifdb_setup_debug:print"db: no appropriate library found"
db_incs=None
dblibs= []
dblib_dir=None
missing.append('_bsddb')
# The sqlite interface
sqlite_setup_debug=False# verbose debug prints from this script?
# We hunt for #define SQLITE_VERSION "n.n.n"
# We need to find >= sqlite version 3.0.8
sqlite_incdir=sqlite_libdir=None
sqlite_inc_paths= ['/usr/include',
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
]
ifcross_compiling:
sqlite_inc_paths= []
MIN_SQLITE_VERSION_NUMBER= (3,0,8)
MIN_SQLITE_VERSION=".".join([str(x)
forxinMIN_SQLITE_VERSION_NUMBER])
# Scan the default include directories before the SQLite specific
# ones. This allows one to override the copy of sqlite on OSX,
# where /usr/include contains an old version of sqlite.
ifhost_platform=='darwin':
sysroot=macosx_sdk_root()
ford_ininc_dirs+sqlite_inc_paths:
d=d_
ifhost_platform=='darwin'andis_macosx_sdk_path(d):
d=os.path.join(sysroot,d[1:])
f=os.path.join(d,"sqlite3.h")
ifos.path.exists(f):
ifsqlite_setup_debug:print"sqlite: found %s"%f
incf=open(f).read()
m=re.search(
r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"',incf)
ifm:
sqlite_version=m.group(1)
sqlite_version_tuple=tuple([int(x)
forxinsqlite_version.split(".")])
ifsqlite_version_tuple>=MIN_SQLITE_VERSION_NUMBER:
# we win!
ifsqlite_setup_debug:
print"%s/sqlite3.h: version %s"%(d,sqlite_version)
sqlite_incdir=d
break
else:
ifsqlite_setup_debug:
print"%s: version %d is too old, need >= %s"%(d,
sqlite_version,MIN_SQLITE_VERSION)
elifsqlite_setup_debug:
print"sqlite: %s had no SQLITE_VERSION"%(f,)
ifsqlite_incdir:
sqlite_dirs_to_check= [
os.path.join(sqlite_incdir,'..','lib64'),
os.path.join(sqlite_incdir,'..','lib'),
os.path.join(sqlite_incdir,'..','..','lib64'),
os.path.join(sqlite_incdir,'..','..','lib'),
]
sqlite_libfile=self.compiler.find_library_file(
sqlite_dirs_to_check+lib_dirs,'sqlite3')
ifsqlite_libfile:
sqlite_libdir= [os.path.abspath(os.path.dirname(sqlite_libfile))]
ifsqlite_incdirandsqlite_libdir:
sqlite_srcs= ['_sqlite/cache.c',
'_sqlite/connection.c',
'_sqlite/cursor.c',
'_sqlite/microprotocols.c',
'_sqlite/module.c',
'_sqlite/prepare_protocol.c',
'_sqlite/row.c',
'_sqlite/statement.c',
'_sqlite/util.c', ]
sqlite_defines= []
ifhost_platform!="win32":
sqlite_defines.append(('MODULE_NAME','"sqlite3"'))
else:
sqlite_defines.append(('MODULE_NAME','\\"sqlite3\\"'))
# Comment this out if you want the sqlite3 module to be able to load extensions.
sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION","1"))
ifhost_platform=='darwin':
# In every directory on the search path search for a dynamic
# library and then a static library, instead of first looking
# for dynamic libraries on the entire path.
# This way a statically linked custom sqlite gets picked up
# before the dynamic library in /usr/lib.
sqlite_extra_link_args= ('-Wl,-search_paths_first',)
else:
sqlite_extra_link_args= ()
exts.append(Extension('_sqlite3',sqlite_srcs,
define_macros=sqlite_defines,
include_dirs=["Modules/_sqlite",
sqlite_incdir],
library_dirs=sqlite_libdir,
extra_link_args=sqlite_extra_link_args,
libraries=["sqlite3",]))
else:
missing.append('_sqlite3')
# Look for Berkeley db 1.85. Note that it is built as a different
# module name so it can be included even when later versions are
# available. A very restrictive search is performed to avoid
# accidentally building this module with a later version of the
# underlying db library. May BSD-ish Unixes incorporate db 1.85
# symbols into libc and place the include file in /usr/include.
#
# If the better bsddb library can be built (db_incs is defined)
# we do not build this one. Otherwise this build will pick up
# the more recent berkeleydb's db.h file first in the include path
# when attempting to compile and it will fail.
f="/usr/include/db.h"
ifhost_platform=='darwin':
ifis_macosx_sdk_path(f):
sysroot=macosx_sdk_root()
f=os.path.join(sysroot,f[1:])
ifos.path.exists(f)andnotdb_incs:
data=open(f).read()
m=re.search(r"#s*define\s+HASHVERSION\s+2\s*",data)
ifmisnotNone:
# bingo - old version used hash file format version 2
### XXX this should be fixed to not be platform-dependent
### but I don't have direct access to an osf1 platform and
### seemed to be muffing the search somehow
libraries=host_platform=="osf1"and ['db']orNone
iflibrariesisnotNone:
exts.append(Extension('bsddb185', ['bsddbmodule.c'],
libraries=libraries))
else:
exts.append(Extension('bsddb185', ['bsddbmodule.c']))
else:
missing.append('bsddb185')
else:
missing.append('bsddb185')
dbm_order= ['gdbm']
# The standard Unix dbm module:
ifhost_platformnotin ['cygwin']:
config_args= [arg.strip("'")
forarginsysconfig.get_config_var("CONFIG_ARGS").split()]
dbm_args= [argforarginconfig_args
ifarg.startswith('--with-dbmliborder=')]
ifdbm_args:
dbm_order= [arg.split('=')[-1]forargindbm_args][-1].split(":")
else:
dbm_order="ndbm:gdbm:bdb".split(":")
dbmext=None
forcandindbm_order:
ifcand=="ndbm":
iffind_file("ndbm.h",inc_dirs, [])isnotNone:
# Some systems have -lndbm, others have -lgdbm_compat,
# others don't have either
ifself.compiler.find_library_file(lib_dirs,
'ndbm'):
ndbm_libs= ['ndbm']
elifself.compiler.find_library_file(lib_dirs,
'gdbm_compat'):
ndbm_libs= ['gdbm_compat']
else:
ndbm_libs= []
print"building dbm using ndbm"
dbmext=Extension('dbm', ['dbmmodule.c'],
define_macros=[
('HAVE_NDBM_H',None),
],
libraries=ndbm_libs)
break
elifcand=="gdbm":
ifself.compiler.find_library_file(lib_dirs,'gdbm'):
gdbm_libs= ['gdbm']
ifself.compiler.find_library_file(lib_dirs,
'gdbm_compat'):
gdbm_libs.append('gdbm_compat')
iffind_file("gdbm/ndbm.h",inc_dirs, [])isnotNone:
print"building dbm using gdbm"
dbmext=Extension(
'dbm', ['dbmmodule.c'],
define_macros=[
('HAVE_GDBM_NDBM_H',None),
],
libraries=gdbm_libs)
break
iffind_file("gdbm-ndbm.h",inc_dirs, [])isnotNone:
print"building dbm using gdbm"
dbmext=Extension(
'dbm', ['dbmmodule.c'],
define_macros=[
('HAVE_GDBM_DASH_NDBM_H',None),
],
libraries=gdbm_libs)
break
elifcand=="bdb":
ifdb_incsisnotNone:
print"building dbm using bdb"
dbmext=Extension('dbm', ['dbmmodule.c'],
library_dirs=dblib_dir,
runtime_library_dirs=dblib_dir,
include_dirs=db_incs,
define_macros=[
('HAVE_BERKDB_H',None),
('DB_DBM_HSEARCH',None),
],
libraries=dblibs)
break
ifdbmextisnotNone:
exts.append(dbmext)
else:
missing.append('dbm')
# Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
if ('gdbm'indbm_orderand
self.compiler.find_library_file(lib_dirs,'gdbm')):
exts.append(Extension('gdbm', ['gdbmmodule.c'],
libraries= ['gdbm'] ) )
else:
missing.append('gdbm')
# Unix-only modules
ifhost_platformnotin ['win32']:
# Steen Lumholt's termios module
exts.append(Extension('termios', ['termios.c']) )
# Jeremy Hylton's rlimit interface
ifhost_platformnotin ['atheos']:
exts.append(Extension('resource', ['resource.c']) )
else:
missing.append('resource')
nis=self._detect_nis(inc_dirs,lib_dirs)
ifnisisnotNone:
exts.append(nis)
else:
missing.append('nis')
# Curses support, requiring the System V version of curses, often
# provided by the ncurses library.
panel_library='panel'
curses_incs=None
ifcurses_library.startswith('ncurses'):
ifcurses_library=='ncursesw':
# Bug 1464056: If _curses.so links with ncursesw,
# _curses_panel.so must link with panelw.
panel_library='panelw'
curses_libs= [curses_library]
curses_incs=find_file('curses.h',inc_dirs,
[os.path.join(d,'ncursesw')fordininc_dirs])
exts.append(Extension('_curses', ['_cursesmodule.c'],
include_dirs=curses_incs,
libraries=curses_libs) )
elifcurses_library=='curses'andhost_platform!='darwin':
# OSX has an old Berkeley curses, not good enough for
# the _curses module.
if (self.compiler.find_library_file(lib_dirs,'terminfo')):
curses_libs= ['curses','terminfo']
elif (self.compiler.find_library_file(lib_dirs,'termcap')):
curses_libs= ['curses','termcap']
else:
curses_libs= ['curses']
exts.append(Extension('_curses', ['_cursesmodule.c'],
libraries=curses_libs) )
else:
missing.append('_curses')
# If the curses module is enabled, check for the panel module
if (module_enabled(exts,'_curses')and
self.compiler.find_library_file(lib_dirs,panel_library)):
exts.append(Extension('_curses_panel', ['_curses_panel.c'],
include_dirs=curses_incs,
libraries= [panel_library]+curses_libs) )
else:
missing.append('_curses_panel')
# Andrew Kuchling's zlib module. Note that some versions of zlib
# 1.1.3 have security problems. See CERT Advisory CA-2002-07:
# http://www.cert.org/advisories/CA-2002-07.html
#
# zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
# patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
# now, we still accept 1.1.3, because we think it's difficult to
# exploit this in Python, and we'd rather make it RedHat's problem
# than our problem <wink>.
#
# You can upgrade zlib to version 1.1.4 yourself by going to
# http://www.gzip.org/zlib/
zlib_inc=find_file('zlib.h', [],inc_dirs)
have_zlib=False
ifzlib_incisnotNone:
zlib_h=zlib_inc[0]+'/zlib.h'
version='"0.0.0"'
version_req='"1.1.3"'
ifhost_platform=='darwin'andis_macosx_sdk_path(zlib_h):
zlib_h=os.path.join(macosx_sdk_root(),zlib_h[1:])
fp=open(zlib_h)
while1:
line=fp.readline()
ifnotline:
break
ifline.startswith('#define ZLIB_VERSION'):
version=line.split()[2]
break
ifversion>=version_req:
if (self.compiler.find_library_file(lib_dirs,'z')):
ifhost_platform=="darwin":
zlib_extra_link_args= ('-Wl,-search_paths_first',)
else:
zlib_extra_link_args= ()
exts.append(Extension('zlib', ['zlibmodule.c'],
libraries= ['z'],
extra_link_args=zlib_extra_link_args))
have_zlib=True
else:
missing.append('zlib')
else:
missing.append('zlib')
else:
missing.append('zlib')
# Helper module for various ascii-encoders. Uses zlib for an optimized
# crc32 if we have it. Otherwise binascii uses its own.
ifhave_zlib:
extra_compile_args= ['-DUSE_ZLIB_CRC32']
libraries= ['z']
extra_link_args=zlib_extra_link_args
else:
extra_compile_args= []
libraries= []
extra_link_args= []
exts.append(Extension('binascii', ['binascii.c'],
extra_compile_args=extra_compile_args,
libraries=libraries,
extra_link_args=extra_link_args) )
# Gustavo Niemeyer's bz2 module.
if (self.compiler.find_library_file(lib_dirs,'bz2')):
ifhost_platform=="darwin":
bz2_extra_link_args= ('-Wl,-search_paths_first',)
else:
bz2_extra_link_args= ()
exts.append(Extension('bz2', ['bz2module.c'],
libraries= ['bz2'],
extra_link_args=bz2_extra_link_args) )
else:
missing.append('bz2')
# Interface to the Expat XML parser
#
# Expat was written by James Clark and is now maintained by a group of
# developers on SourceForge; see www.libexpat.org for more information.
# The pyexpat module was written by Paul Prescod after a prototype by
# Jack Jansen. The Expat source is included in Modules/expat/. Usage
# of a system shared libexpat.so is possible with --with-system-expat
# configure option.
#
# More information on Expat can be found at www.libexpat.org.
#
if'--with-system-expat'insysconfig.get_config_var("CONFIG_ARGS"):
expat_inc= []
define_macros= []
expat_lib= ['expat']
expat_sources= []
expat_depends= []
else:
expat_inc= [os.path.join(os.getcwd(),srcdir,'Modules','expat')]
define_macros= [
('HAVE_EXPAT_CONFIG_H','1'),
# bpo-30947: Python uses best available entropy sources to
# call XML_SetHashSalt(), expat entropy sources are not needed
('XML_POOR_ENTROPY','1'),
]
expat_lib= []
expat_sources= ['expat/xmlparse.c',
'expat/xmlrole.c',
'expat/xmltok.c']
expat_depends= ['expat/ascii.h',
'expat/asciitab.h',
'expat/expat.h',
'expat/expat_config.h',
'expat/expat_external.h',
'expat/internal.h',
'expat/latin1tab.h',
'expat/utf8tab.h',
'expat/xmlrole.h',
'expat/xmltok.h',
'expat/xmltok_impl.h'
]
exts.append(Extension('pyexpat',
define_macros=define_macros,
include_dirs=expat_inc,
libraries=expat_lib,
sources= ['pyexpat.c']+expat_sources,
depends=expat_depends,
))
# Fredrik Lundh's cElementTree module. Note that this also
# uses expat (via the CAPI hook in pyexpat).
ifos.path.isfile(os.path.join(srcdir,'Modules','_elementtree.c')):
define_macros.append(('USE_PYEXPAT_CAPI',None))
exts.append(Extension('_elementtree',
define_macros=define_macros,
include_dirs=expat_inc,
libraries=expat_lib,
sources= ['_elementtree.c'],
depends= ['pyexpat.c']+expat_sources+
expat_depends,
))
else:
missing.append('_elementtree')
# Hye-Shik Chang's CJKCodecs modules.
ifhave_unicode:
exts.append(Extension('_multibytecodec',
['cjkcodecs/multibytecodec.c']))
forlocin ('kr','jp','cn','tw','hk','iso2022'):
exts.append(Extension('_codecs_%s'%loc,
['cjkcodecs/_codecs_%s.c'%loc]))
else:
missing.append('_multibytecodec')
forlocin ('kr','jp','cn','tw','hk','iso2022'):
missing.append('_codecs_%s'%loc)
# Dynamic loading module
ifsys.maxint==0x7fffffff:
# This requires sizeof(int) == sizeof(long) == sizeof(char*)
dl_inc=find_file('dlfcn.h', [],inc_dirs)
if (dl_incisnotNone)and (host_platformnotin ['atheos']):
exts.append(Extension('dl', ['dlmodule.c']) )
else:
missing.append('dl')
else:
missing.append('dl')
# Thomas Heller's _ctypes module
self.detect_ctypes(inc_dirs,lib_dirs)
# Richard Oudkerk's multiprocessing module
ifhost_platform=='win32':# Windows
macros=dict()
libraries= ['ws2_32']
elifhost_platform=='darwin':# Mac OSX
macros=dict()
libraries= []
elifhost_platform=='cygwin':# Cygwin
macros=dict()
libraries= []
elifhost_platformin ('freebsd4','freebsd5','freebsd6','freebsd7','freebsd8'):
# FreeBSD's P1003.1b semaphore support is very experimental
# and has many known problems. (as of June 2008)
macros=dict()
libraries= []
elifhost_platform.startswith('openbsd'):
macros=dict()
libraries= []
elifhost_platform.startswith('netbsd'):
macros=dict()
libraries= []
else:# Linux and other unices
macros=dict()
libraries= ['rt']
ifhost_platform=='win32':
multiprocessing_srcs= ['_multiprocessing/multiprocessing.c',
'_multiprocessing/semaphore.c',
'_multiprocessing/pipe_connection.c',
'_multiprocessing/socket_connection.c',
'_multiprocessing/win32_functions.c'
]
else:
multiprocessing_srcs= ['_multiprocessing/multiprocessing.c',
'_multiprocessing/socket_connection.c'
]
if (sysconfig.get_config_var('HAVE_SEM_OPEN')andnot
sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
multiprocessing_srcs.append('_multiprocessing/semaphore.c')
ifsysconfig.get_config_var('WITH_THREAD'):
exts.append (Extension('_multiprocessing',multiprocessing_srcs,
define_macros=macros.items(),
include_dirs=["Modules/_multiprocessing"]))
else:
missing.append('_multiprocessing')
# End multiprocessing
# Platform-specific libraries
ifhost_platform=='linux2':
# Linux-specific modules
exts.append(Extension('linuxaudiodev', ['linuxaudiodev.c']) )
else:
missing.append('linuxaudiodev')
if (host_platformin ('linux2','freebsd4','freebsd5','freebsd6',
'freebsd7','freebsd8')
orhost_platform.startswith("gnukfreebsd")):
exts.append(Extension('ossaudiodev', ['ossaudiodev.c']) )
else:
missing.append('ossaudiodev')
ifhost_platform=='sunos5':
# SunOS specific modules
exts.append(Extension('sunaudiodev', ['sunaudiodev.c']) )
else:
missing.append('sunaudiodev')
ifhost_platform=='darwin':
# _scproxy
exts.append(Extension("_scproxy", [os.path.join(srcdir,"Mac/Modules/_scproxy.c")],
extra_link_args= [
'-framework','SystemConfiguration',
'-framework','CoreFoundation'
]))
ifhost_platform=='darwin'and ("--disable-toolbox-glue"notin
sysconfig.get_config_var("CONFIG_ARGS")):
ifint(os.uname()[2].split('.')[0])>=8:
# We're on Mac OS X 10.4 or later, the compiler should
# support '-Wno-deprecated-declarations'. This will
# suppress deprecation warnings for the Carbon extensions,
# these extensions wrap the Carbon APIs and even those
# parts that are deprecated.
carbon_extra_compile_args= ['-Wno-deprecated-declarations']
else:
carbon_extra_compile_args= []
# Mac OS X specific modules.
defmacSrcExists(name1,name2=''):
ifnotname1:
returnNone
names= (name1,)
ifname2:
names= (name1,name2)
path=os.path.join(srcdir,'Mac','Modules',*names)
returnos.path.exists(path)
defaddMacExtension(name,kwds,extra_srcs=[]):
dirname=''
ifname[0]=='_':
dirname=name[1:].lower()
cname=name+'.c'
cmodulename=name+'module.c'
# Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c
ifmacSrcExists(cname):
srcs= [cname]
elifmacSrcExists(cmodulename):
srcs= [cmodulename]
elifmacSrcExists(dirname,cname):
# XXX(nnorwitz): If all the names ended with module, we
# wouldn't need this condition. ibcarbon is the only one.
srcs= [os.path.join(dirname,cname)]
elifmacSrcExists(dirname,cmodulename):
srcs= [os.path.join(dirname,cmodulename)]
else:
raiseRuntimeError("%s not found"%name)
# Here's the whole point: add the extension with sources
exts.append(Extension(name,srcs+extra_srcs,**kwds))
# Core Foundation
core_kwds= {'extra_compile_args':carbon_extra_compile_args,
'extra_link_args': ['-framework','CoreFoundation'],
}
addMacExtension('_CF',core_kwds, ['cf/pycfbridge.c'])
addMacExtension('autoGIL',core_kwds)
# Carbon
carbon_kwds= {'extra_compile_args':carbon_extra_compile_args,
'extra_link_args': ['-framework','Carbon'],
}
CARBON_EXTS= ['ColorPicker','gestalt','MacOS','Nav',
'OSATerminology','icglue',
# All these are in subdirs
'_AE','_AH','_App','_CarbonEvt','_Cm','_Ctl',
'_Dlg','_Drag','_Evt','_File','_Folder','_Fm',
'_Help','_Icn','_IBCarbon','_List',
'_Menu','_Mlte','_OSA','_Res','_Qd','_Qdoffs',
'_Scrap','_Snd','_TE',
]
fornameinCARBON_EXTS:
addMacExtension(name,carbon_kwds)
# Workaround for a bug in the version of gcc shipped with Xcode 3.
# The _Win extension should build just like the other Carbon extensions, but
# this actually results in a hard crash of the linker.
#
if'-arch ppc64'incflagsand'-arch ppc'incflags:
win_kwds= {'extra_compile_args':carbon_extra_compile_args+ ['-arch','i386','-arch','ppc'],
'extra_link_args': ['-framework','Carbon','-arch','i386','-arch','ppc'],
}
addMacExtension('_Win',win_kwds)
else:
addMacExtension('_Win',carbon_kwds)
# Application Services & QuickTime
app_kwds= {'extra_compile_args':carbon_extra_compile_args,
'extra_link_args': ['-framework','ApplicationServices'],
}
addMacExtension('_Launch',app_kwds)
addMacExtension('_CG',app_kwds)
exts.append(Extension('_Qt', ['qt/_Qtmodule.c'],
extra_compile_args=carbon_extra_compile_args,
extra_link_args=['-framework','QuickTime',
'-framework','Carbon']) )
self.extensions.extend(exts)
# Call the method for detecting whether _tkinter can be compiled
self.detect_tkinter(inc_dirs,lib_dirs)
if'_tkinter'notin [e.nameforeinself.extensions]:
missing.append('_tkinter')
## # Uncomment these lines if you want to play with xxmodule.c
## ext = Extension('xx', ['xxmodule.c'])
## self.extensions.append(ext)
returnmissing
defdetect_tkinter_explicitly(self):
# Build _tkinter using explicit locations for Tcl/Tk.
#
# This is enabled when both arguments are given to ./configure:
#
# --with-tcltk-includes="-I/path/to/tclincludes \
# -I/path/to/tkincludes"
# --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
# -L/path/to/tklibs -ltkm.n"
#
# These values can also be specified or overridden via make:
# make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
#
# This can be useful for building and testing tkinter with multiple
# versions of Tcl/Tk. Note that a build of Tk depends on a particular
# build of Tcl so you need to specify both arguments and use care when
# overriding.
# The _TCLTK variables are created in the Makefile sharedmods target.
tcltk_includes=os.environ.get('_TCLTK_INCLUDES')
tcltk_libs=os.environ.get('_TCLTK_LIBS')
ifnot (tcltk_includesandtcltk_libs):
# Resume default configuration search.
return0
extra_compile_args=tcltk_includes.split()
extra_link_args=tcltk_libs.split()
ext=Extension('_tkinter', ['_tkinter.c','tkappinit.c'],
define_macros=[('WITH_APPINIT',1)],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
self.extensions.append(ext)
return1
defdetect_tkinter_darwin(self,inc_dirs,lib_dirs):
# The _tkinter module, using frameworks. Since frameworks are quite
# different the UNIX search logic is not sharable.
fromos.pathimportjoin,exists
framework_dirs= [
'/Library/Frameworks',
'/System/Library/Frameworks/',
join(os.getenv('HOME'),'/Library/Frameworks')
]
sysroot=macosx_sdk_root()
# Find the directory that contains the Tcl.framework and Tk.framework
# bundles.
# XXX distutils should support -F!
forFinframework_dirs:
# both Tcl.framework and Tk.framework should be present
forfwin'Tcl','Tk':
ifis_macosx_sdk_path(F):
ifnotexists(join(sysroot,F[1:],fw+'.framework')):
break
else:
ifnotexists(join(F,fw+'.framework')):
break
else:
# ok, F is now directory with both frameworks. Continure
# building
break
else:
# Tk and Tcl frameworks not found. Normal "unix" tkinter search
# will now resume.
return0
# For 8.4a2, we must add -I options that point inside the Tcl and Tk
# frameworks. In later release we should hopefully be able to pass
# the -F option to gcc, which specifies a framework lookup path.
#
include_dirs= [
join(F,fw+'.framework',H)
forfwin'Tcl','Tk'
forHin'Headers','Versions/Current/PrivateHeaders'
]
# For 8.4a2, the X11 headers are not included. Rather than include a
# complicated search, this is a hard-coded path. It could bail out
# if X11 libs are not found...
include_dirs.append('/usr/X11R6/include')
frameworks= ['-framework','Tcl','-framework','Tk']
# All existing framework builds of Tcl/Tk don't support 64-bit
# architectures.
cflags=sysconfig.get_config_vars('CFLAGS')[0]
archs=re.findall('-arch\s+(\w+)',cflags)
ifis_macosx_sdk_path(F):
fp=os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(os.path.join(sysroot,F[1:]),))
else:
fp=os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(F,))
detected_archs= []
forlninfp:
a=ln.split()[-1]
ifainarchs:
detected_archs.append(ln.split()[-1])
fp.close()
foraindetected_archs:
frameworks.append('-arch')
frameworks.append(a)
ext=Extension('_tkinter', ['_tkinter.c','tkappinit.c'],
define_macros=[('WITH_APPINIT',1)],
include_dirs=include_dirs,
libraries= [],
extra_compile_args=frameworks[2:],
extra_link_args=frameworks,
)
self.extensions.append(ext)
return1
defdetect_tkinter(self,inc_dirs,lib_dirs):
# The _tkinter module.
# Check whether --with-tcltk-includes and --with-tcltk-libs were
# configured or passed into the make target. If so, use these values
# to build tkinter and bypass the searches for Tcl and TK in standard
# locations.
ifself.detect_tkinter_explicitly():
return
# Rather than complicate the code below, detecting and building
# AquaTk is a separate method. Only one Tkinter will be built on
# Darwin - either AquaTk, if it is found, or X11 based Tk.
if (host_platform=='darwin'and
self.detect_tkinter_darwin(inc_dirs,lib_dirs)):
return
# Assume we haven't found any of the libraries or include files
# The versions with dots are used on Unix, and the versions without
# dots on Windows, for detection by cygwin.
tcllib=tklib=tcl_includes=tk_includes=None
forversionin ['8.6','86','8.5','85','8.4','84','8.3','83',
'8.2','82','8.1','81','8.0','80']:
tklib=self.compiler.find_library_file(lib_dirs,
'tk'+version)
tcllib=self.compiler.find_library_file(lib_dirs,
'tcl'+version)
iftklibandtcllib:
# Exit the loop when we've found the Tcl/Tk libraries
break
# Now check for the header files
iftklibandtcllib:
# Check for the include files on Debian and {Free,Open}BSD, where
# they're put in /usr/include/{tcl,tk}X.Y
dotversion=version
if'.'notindotversionand"bsd"inhost_platform.lower():
# OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
# but the include subdirs are named like .../include/tcl8.3.
dotversion=dotversion[:-1]+'.'+dotversion[-1]
tcl_include_sub= []
tk_include_sub= []
fordirininc_dirs:
tcl_include_sub+= [dir+os.sep+"tcl"+dotversion]
tk_include_sub+= [dir+os.sep+"tk"+dotversion]
tk_include_sub+=tcl_include_sub
tcl_includes=find_file('tcl.h',inc_dirs,tcl_include_sub)
tk_includes=find_file('tk.h',inc_dirs,tk_include_sub)
if (tcllibisNoneortklibisNoneor
tcl_includesisNoneortk_includesisNone):
self.announce("INFO: Can't locate Tcl/Tk libs and/or headers",2)
return
# OK... everything seems to be present for Tcl/Tk.
include_dirs= [] ;libs= [] ;defs= [] ;added_lib_dirs= []
fordirintcl_includes+tk_includes:
ifdirnotininclude_dirs:
include_dirs.append(dir)
# Check for various platform-specific directories
ifhost_platform=='sunos5':
include_dirs.append('/usr/openwin/include')
added_lib_dirs.append('/usr/openwin/lib')
elifos.path.exists('/usr/X11R6/include'):
include_dirs.append('/usr/X11R6/include')
added_lib_dirs.append('/usr/X11R6/lib64')
added_lib_dirs.append('/usr/X11R6/lib')
elifos.path.exists('/usr/X11R5/include'):
include_dirs.append('/usr/X11R5/include')
added_lib_dirs.append('/usr/X11R5/lib')
else:
# Assume default location for X11
include_dirs.append('/usr/X11/include')
added_lib_dirs.append('/usr/X11/lib')
# If Cygwin, then verify that X is installed before proceeding
ifhost_platform=='cygwin':
x11_inc=find_file('X11/Xlib.h', [],include_dirs)
ifx11_incisNone:
return
# Check for BLT extension
ifself.compiler.find_library_file(lib_dirs+added_lib_dirs,
'BLT8.0'):
defs.append( ('WITH_BLT',1) )
libs.append('BLT8.0')
elifself.compiler.find_library_file(lib_dirs+added_lib_dirs,
'BLT'):
defs.append( ('WITH_BLT',1) )
libs.append('BLT')
# Add the Tcl/Tk libraries
libs.append('tk'+version)
libs.append('tcl'+version)
ifhost_platformin ['aix3','aix4']:
libs.append('ld')
# Finally, link with the X11 libraries (not appropriate on cygwin)
ifhost_platform!="cygwin":
libs.append('X11')
ext=Extension('_tkinter', ['_tkinter.c','tkappinit.c'],
define_macros=[('WITH_APPINIT',1)]+defs,
include_dirs=include_dirs,
libraries=libs,
library_dirs=added_lib_dirs,
)
self.extensions.append(ext)
# XXX handle these, but how to detect?
# *** Uncomment and edit for PIL (TkImaging) extension only:
# -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
# *** Uncomment and edit for TOGL extension only:
# -DWITH_TOGL togl.c \
# *** Uncomment these for TOGL extension only:
# -lGL -lGLU -lXext -lXmu \
defconfigure_ctypes_darwin(self,ext):
# Darwin (OS X) uses preconfigured files, in
# the Modules/_ctypes/libffi_osx directory.
srcdir=sysconfig.get_config_var('srcdir')
ffi_srcdir=os.path.abspath(os.path.join(srcdir,'Modules',
'_ctypes','libffi_osx'))
sources= [os.path.join(ffi_srcdir,p)
forpin ['ffi.c',
'x86/darwin64.S',
'x86/x86-darwin.S',
'x86/x86-ffi_darwin.c',
'x86/x86-ffi64.c',
'powerpc/ppc-darwin.S',
'powerpc/ppc-darwin_closure.S',
'powerpc/ppc-ffi_darwin.c',
'powerpc/ppc64-darwin_closure.S',
]]
# Add .S (preprocessed assembly) to C compiler source extensions.
self.compiler.src_extensions.append('.S')
include_dirs= [os.path.join(ffi_srcdir,'include'),
os.path.join(ffi_srcdir,'powerpc')]
ext.include_dirs.extend(include_dirs)
ext.sources.extend(sources)
returnTrue
defconfigure_ctypes(self,ext):
ifnotself.use_system_libffi:
ifhost_platform=='darwin':
returnself.configure_ctypes_darwin(ext)
srcdir=sysconfig.get_config_var('srcdir')
ffi_builddir=os.path.join(self.build_temp,'libffi')
ffi_srcdir=os.path.abspath(os.path.join(srcdir,'Modules',
'_ctypes','libffi'))
ffi_configfile=os.path.join(ffi_builddir,'fficonfig.py')
fromdistutils.dep_utilimportnewer_group
config_sources= [os.path.join(ffi_srcdir,fname)
forfnameinos.listdir(ffi_srcdir)
ifos.path.isfile(os.path.join(ffi_srcdir,fname))]
ifself.forceornewer_group(config_sources,
ffi_configfile):
fromdistutils.dir_utilimportmkpath
mkpath(ffi_builddir)
config_args= [argforarginsysconfig.get_config_var("CONFIG_ARGS").split()
if (('--host='inarg)or ('--build='inarg))]
ifnotself.verbose:
config_args.append("-q")
# Pass empty CFLAGS because we'll just append the resulting
# CFLAGS to Python's; -g or -O2 is to be avoided.
cmd="cd %s && env CFLAGS='' '%s/configure' %s" \
% (ffi_builddir,ffi_srcdir," ".join(config_args))
res=os.system(cmd)
ifresornotos.path.exists(ffi_configfile):
print"Failed to configure _ctypes module"
returnFalse
fficonfig= {}
withopen(ffi_configfile)asf:
execfinfficonfig
# Add .S (preprocessed assembly) to C compiler source extensions.
self.compiler.src_extensions.append('.S')
include_dirs= [os.path.join(ffi_builddir,'include'),
ffi_builddir,
os.path.join(ffi_srcdir,'src')]
extra_compile_args=fficonfig['ffi_cflags'].split()
ext.sources.extend(os.path.join(ffi_srcdir,f)forfin
fficonfig['ffi_sources'])
ext.include_dirs.extend(include_dirs)
ext.extra_compile_args.extend(extra_compile_args)
returnTrue
defdetect_ctypes(self,inc_dirs,lib_dirs):
self.use_system_libffi=False
include_dirs= []
extra_compile_args= []
extra_link_args= []
sources= ['_ctypes/_ctypes.c',
'_ctypes/callbacks.c',
'_ctypes/callproc.c',
'_ctypes/stgdict.c',
'_ctypes/cfield.c']
depends= ['_ctypes/ctypes.h']
ifhost_platform=='darwin':
sources.append('_ctypes/malloc_closure.c')
sources.append('_ctypes/darwin/dlfcn_simple.c')
extra_compile_args.append('-DMACOSX')
include_dirs.append('_ctypes/darwin')
# XXX Is this still needed?
## extra_link_args.extend(['-read_only_relocs', 'warning'])
elifhost_platform=='sunos5':
# XXX This shouldn't be necessary; it appears that some
# of the assembler code is non-PIC (i.e. it has relocations
# when it shouldn't. The proper fix would be to rewrite
# the assembler code to be PIC.
# This only works with GCC; the Sun compiler likely refuses
# this option. If you want to compile ctypes with the Sun
# compiler, please research a proper solution, instead of
# finding some -z option for the Sun compiler.
extra_link_args.append('-mimpure-text')
elifhost_platform.startswith('hp-ux'):
extra_link_args.append('-fPIC')
ext=Extension('_ctypes',
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
libraries=[],
sources=sources,
depends=depends)
ext_test=Extension('_ctypes_test',
sources=['_ctypes/_ctypes_test.c'])
self.extensions.extend([ext,ext_test])
ifnot'--with-system-ffi'insysconfig.get_config_var("CONFIG_ARGS"):
return
ifhost_platform=='darwin':
# OS X 10.5 comes with libffi.dylib; the include files are
# in /usr/include/ffi
inc_dirs.append('/usr/include/ffi')
ffi_inc= [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
ifnotffi_incorffi_inc[0]=='':
ffi_inc=find_file('ffi.h', [],inc_dirs)
ifffi_incisnotNone:
ffi_h=ffi_inc[0]+'/ffi.h'
withopen(ffi_h)asf:
forlineinf:
line=line.strip()
ifline.startswith(('#define LIBFFI_H',
'#define ffi_wrapper_h')):
break
else:
ffi_inc=None
print('Header file {} does not define LIBFFI_H or '
'ffi_wrapper_h'.format(ffi_h))
ffi_lib=None
ifffi_incisnotNone:
forlib_namein ('ffi_convenience','ffi_pic','ffi'):
if (self.compiler.find_library_file(lib_dirs,lib_name)):
ffi_lib=lib_name
break
ifffi_incandffi_lib:
ext.include_dirs.extend(ffi_inc)
ext.libraries.append(ffi_lib)
self.use_system_libffi=True
ifsysconfig.get_config_var('HAVE_LIBDL'):
# for dlopen, see bpo-32647
ext.libraries.append('dl')
def_detect_nis(self,inc_dirs,lib_dirs):
ifhost_platformin {'win32','cygwin','qnx6'}:
returnNone
libs= []
library_dirs= []
includes_dirs= []
# bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
# moved headers and libraries to libtirpc and libnsl. The headers
# are in tircp and nsl sub directories.
rpcsvc_inc=find_file(
'rpcsvc/yp_prot.h',inc_dirs,
[os.path.join(inc_dir,'nsl')forinc_dirininc_dirs]
)
rpc_inc=find_file(
'rpc/rpc.h',inc_dirs,
[os.path.join(inc_dir,'tirpc')forinc_dirininc_dirs]
)
ifrpcsvc_incisNoneorrpc_incisNone:
# not found
returnNone
includes_dirs.extend(rpcsvc_inc)
includes_dirs.extend(rpc_inc)
ifself.compiler.find_library_file(lib_dirs,'nsl'):
libs.append('nsl')
else:
# libnsl-devel: check for libnsl in nsl/ subdirectory
nsl_dirs= [os.path.join(lib_dir,'nsl')forlib_dirinlib_dirs]
libnsl=self.compiler.find_library_file(nsl_dirs,'nsl')
iflibnslisnotNone:
library_dirs.append(os.path.dirname(libnsl))
libs.append('nsl')
ifself.compiler.find_library_file(lib_dirs,'tirpc'):
libs.append('tirpc')
returnExtension(
'nis', ['nismodule.c'],
libraries=libs,
library_dirs=library_dirs,
include_dirs=includes_dirs
)
classPyBuildInstall(install):
# Suppress the warning about installation into the lib_dynload
# directory, which is not in sys.path when running Python during
# installation:
definitialize_options (self):
install.initialize_options(self)
self.warn_dir=0
classPyBuildInstallLib(install_lib):
# Do exactly what install_lib does but make sure correct access modes get
# set on installed directories and files. All installed files with get
# mode 644 unless they are a shared library in which case they will get
# mode 755. All installed directories will get mode 755.
so_ext=sysconfig.get_config_var("SO")
definstall(self):
outfiles=install_lib.install(self)
self.set_file_modes(outfiles,0644,0755)
self.set_dir_modes(self.install_dir,0755)
returnoutfiles
defset_file_modes(self,files,defaultMode,sharedLibMode):
ifnotself.is_chmod_supported():return
ifnotfiles:return
forfilenameinfiles:
ifos.path.islink(filename):continue
mode=defaultMode
iffilename.endswith(self.so_ext):mode=sharedLibMode
log.info("changing mode of %s to %o",filename,mode)
ifnotself.dry_run:os.chmod(filename,mode)
defset_dir_modes(self,dirname,mode):
ifnotself.is_chmod_supported():return
os.path.walk(dirname,self.set_dir_modes_visitor,mode)
defset_dir_modes_visitor(self,mode,dirname,names):
ifos.path.islink(dirname):return
log.info("changing mode of %s to %o",dirname,mode)
ifnotself.dry_run:os.chmod(dirname,mode)
defis_chmod_supported(self):
returnhasattr(os,'chmod')
SUMMARY="""
Python is an interpreted, interactive, object-oriented programming
language. It is often compared to Tcl, Perl, Scheme or Java.
Python combines remarkable power with very clear syntax. It has
modules, classes, exceptions, very high level dynamic data types, and
dynamic typing. There are interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac, MFC). New built-in modules are easily written in C or C++. Python
is also usable as an extension language for applications that need a
programmable interface.
The Python implementation is portable: it runs on many brands of UNIX,
on Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't
listed here, it may still be supported, if there's a C compiler for
it. Ask around on comp.lang.python -- or just try compiling Python
yourself.
"""
CLASSIFIERS="""
Development Status :: 6 - Mature
License :: OSI Approved :: Python Software Foundation License
Natural Language :: English
Programming Language :: C
Programming Language :: Python
Topic :: Software Development
"""
defmain():
# turn off warnings when deprecated modules are imported
importwarnings
warnings.filterwarnings("ignore",category=DeprecationWarning)
setup(# PyPI Metadata (PEP 301)
name="Python",
version=sys.version.split()[0],
url="http://www.python.org/%s"%sys.version[:3],
maintainer="Guido van Rossum and the Python community",
maintainer_email="python-dev@python.org",
description="A high-level object-oriented programming language",
long_description=SUMMARY.strip(),
license="PSF license",
classifiers=filter(None,CLASSIFIERS.split("\n")),
platforms= ["Many"],
# Build info
cmdclass= {'build_ext':PyBuildExt,'install':PyBuildInstall,
'install_lib':PyBuildInstallLib},
# The struct module is defined here, because build_ext won't be
# called unless there's at least one extension module defined.
ext_modules=[Extension('_struct', ['_struct.c'])],
# Scripts to install
scripts= ['Tools/scripts/pydoc','Tools/scripts/idle',
'Tools/scripts/2to3',
'Lib/smtpd.py']
)
# --install-platlib
if__name__=='__main__':
main()

[8]ページ先頭

©2009-2025 Movatter.jp