summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/command/build_ext.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/command/build_ext.py')
-rw-r--r--Lib/distutils/command/build_ext.py140
1 files changed, 55 insertions, 85 deletions
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 8f41fac..bd61bc5 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -7,14 +7,12 @@ extensions ASAP)."""
__revision__ = "$Id$"
import sys, os, re
-from warnings import warn
-
-from distutils.util import get_platform
from distutils.core import Command
from distutils.errors import *
-from distutils.ccompiler import customize_compiler
+from distutils.sysconfig import customize_compiler, get_python_version
from distutils.dep_util import newer_group
from distutils.extension import Extension
+from distutils.util import get_platform
from distutils import log
# this keeps compatibility from 2.3 to 2.5
@@ -114,39 +112,6 @@ class build_ext(Command):
"list available compilers", show_compilers),
]
- # making 'compiler' a property to deprecate
- # its usage as something else than a compiler type
- # e.g. like a compiler instance
- def __init__(self, dist):
- self._compiler = None
- Command.__init__(self, dist)
-
- def __setattr__(self, name, value):
- # need this to make sure setattr() (used in distutils)
- # doesn't kill our property
- if name == 'compiler':
- self._set_compiler(value)
- else:
- self.__dict__[name] = value
-
- def _set_compiler(self, compiler):
- if not isinstance(compiler, str) and compiler is not None:
- # we don't want to allow that anymore in the future
- warn("'compiler' specifies the compiler type in build_ext. "
- "If you want to get the compiler object itself, "
- "use 'compiler_obj'", DeprecationWarning)
- self._compiler = compiler
-
- def _get_compiler(self):
- if not isinstance(self._compiler, str) and self._compiler is not None:
- # we don't want to allow that anymore in the future
- warn("'compiler' specifies the compiler type in build_ext. "
- "If you want to get the compiler object itself, "
- "use 'compiler_obj'", DeprecationWarning)
- return self._compiler
-
- compiler = property(_get_compiler, _set_compiler)
-
def initialize_options(self):
self.extensions = None
self.build_lib = None
@@ -171,7 +136,8 @@ class build_ext(Command):
self.user = None
def finalize_options(self):
- _sysconfig = __import__('sysconfig')
+ from distutils import sysconfig
+
self.set_undefined_options('build',
('build_lib', 'build_lib'),
('build_temp', 'build_temp'),
@@ -188,8 +154,8 @@ class build_ext(Command):
# Make sure Python's include directories (for Python.h, pyconfig.h,
# etc.) are in the include search path.
- py_include = _sysconfig.get_path('include')
- plat_py_include = _sysconfig.get_path('platinclude')
+ py_include = sysconfig.get_python_inc()
+ plat_py_include = sysconfig.get_python_inc(plat_specific=1)
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
if isinstance(self.include_dirs, str):
@@ -261,13 +227,13 @@ class build_ext(Command):
if os.name == 'os2':
self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
- # for extensions under Cygwin Python's library directory must be
+ # for extensions under Cygwin and AtheOS Python's library directory must be
# appended to library_dirs
- if sys.platform[:6] == 'cygwin':
+ if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
# building third party extensions
self.library_dirs.append(os.path.join(sys.prefix, "lib",
- "python" + _sysconfig.get_python_version(),
+ "python" + get_python_version(),
"config"))
else:
# building python standard extensions
@@ -275,13 +241,13 @@ class build_ext(Command):
# for extensions under Linux or Solaris with a shared Python library,
# Python's library directory must be appended to library_dirs
- _sysconfig.get_config_var('Py_ENABLE_SHARED')
+ sysconfig.get_config_var('Py_ENABLE_SHARED')
if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
or sys.platform.startswith('sunos'))
- and _sysconfig.get_config_var('Py_ENABLE_SHARED')):
+ and sysconfig.get_config_var('Py_ENABLE_SHARED')):
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
# building third party extensions
- self.library_dirs.append(_sysconfig.get_config_var('LIBDIR'))
+ self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
else:
# building python standard extensions
self.library_dirs.append('.')
@@ -344,50 +310,38 @@ class build_ext(Command):
# Setup the CCompiler object that we'll use to do all the
# compiling and linking
-
- # used to prevent the usage of an existing compiler for the
- # compiler option when calling new_compiler()
- # this will be removed in 3.3 and 2.8
- if not isinstance(self._compiler, str):
- self._compiler = None
-
- self.compiler_obj = new_compiler(compiler=self._compiler,
- verbose=self.verbose,
- dry_run=self.dry_run,
- force=self.force)
-
- # used to keep the compiler object reachable with
- # "self.compiler". this will be removed in 3.3 and 2.8
- self._compiler = self.compiler_obj
-
- customize_compiler(self.compiler_obj)
+ self.compiler = new_compiler(compiler=self.compiler,
+ verbose=self.verbose,
+ dry_run=self.dry_run,
+ force=self.force)
+ customize_compiler(self.compiler)
# If we are cross-compiling, init the compiler now (if we are not
# cross-compiling, init would not hurt, but people may rely on
# late initialization of compiler even if they shouldn't...)
if os.name == 'nt' and self.plat_name != get_platform():
- self.compiler_obj.initialize(self.plat_name)
+ self.compiler.initialize(self.plat_name)
# And make sure that any compile/link-related options (which might
# come from the command-line or from the setup script) are set in
# that CCompiler object -- that way, they automatically apply to
# all compiling and linking done here.
if self.include_dirs is not None:
- self.compiler_obj.set_include_dirs(self.include_dirs)
+ self.compiler.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name, value) in self.define:
- self.compiler_obj.define_macro(name, value)
+ self.compiler.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
- self.compiler_obj.undefine_macro(macro)
+ self.compiler.undefine_macro(macro)
if self.libraries is not None:
- self.compiler_obj.set_libraries(self.libraries)
+ self.compiler.set_libraries(self.libraries)
if self.library_dirs is not None:
- self.compiler_obj.set_library_dirs(self.library_dirs)
+ self.compiler.set_library_dirs(self.library_dirs)
if self.rpath is not None:
- self.compiler_obj.set_runtime_library_dirs(self.rpath)
+ self.compiler.set_runtime_library_dirs(self.rpath)
if self.link_objects is not None:
- self.compiler_obj.set_link_objects(self.link_objects)
+ self.compiler.set_link_objects(self.link_objects)
# Now actually compile and link everything.
self.build_extensions()
@@ -548,13 +502,13 @@ class build_ext(Command):
for undef in ext.undef_macros:
macros.append((undef,))
- objects = self.compiler_obj.compile(sources,
- output_dir=self.build_temp,
- macros=macros,
- include_dirs=ext.include_dirs,
- debug=self.debug,
- extra_postargs=extra_args,
- depends=ext.depends)
+ objects = self.compiler.compile(sources,
+ output_dir=self.build_temp,
+ macros=macros,
+ include_dirs=ext.include_dirs,
+ debug=self.debug,
+ extra_postargs=extra_args,
+ depends=ext.depends)
# XXX -- this is a Vile HACK!
#
@@ -575,9 +529,9 @@ class build_ext(Command):
extra_args = ext.extra_link_args or []
# Detect target language, if not provided
- language = ext.language or self.compiler_obj.detect_language(sources)
+ language = ext.language or self.compiler.detect_language(sources)
- self.compiler_obj.link_shared_object(
+ self.compiler.link_shared_object(
objects, ext_path,
libraries=self.get_libraries(ext),
library_dirs=ext.library_dirs,
@@ -710,13 +664,13 @@ class build_ext(Command):
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").
"""
- _sysconfig = __import__('sysconfig')
+ from distutils.sysconfig import get_config_var
ext_path = ext_name.split('.')
# OS/2 has an 8 character module (extension) limit :-(
if os.name == "os2":
ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
# extensions in debug_mode are named 'module_d.pyd' under windows
- so_ext = _sysconfig.get_config_var('SO')
+ so_ext = get_config_var('SO')
if os.name == 'nt' and self.debug:
return os.path.join(*ext_path) + '_d' + so_ext
return os.path.join(*ext_path) + so_ext
@@ -744,7 +698,7 @@ class build_ext(Command):
# Append '_d' to the python import library on debug builds.
if sys.platform == "win32":
from distutils.msvccompiler import MSVCCompiler
- if not isinstance(self.compiler_obj, MSVCCompiler):
+ if not isinstance(self.compiler, MSVCCompiler):
template = "python%d%d"
if self.debug:
template = template + '_d'
@@ -775,12 +729,28 @@ class build_ext(Command):
# don't extend ext.libraries, it may be shared with other
# extensions, it is a reference to the original list
return ext.libraries + [pythonlib]
+ elif sys.platform[:6] == "atheos":
+ from distutils import sysconfig
+
+ template = "python%d.%d"
+ pythonlib = (template %
+ (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
+ # Get SHLIBS from Makefile
+ extra = []
+ for lib in sysconfig.get_config_var('SHLIBS').split():
+ if lib.startswith('-l'):
+ extra.append(lib[2:])
+ else:
+ extra.append(lib)
+ # don't extend ext.libraries, it may be shared with other
+ # extensions, it is a reference to the original list
+ return ext.libraries + [pythonlib, "m"] + extra
elif sys.platform == 'darwin':
# Don't use the default code below
return ext.libraries
else:
- _sysconfig = __import__('sysconfig')
- if _sysconfig.get_config_var('Py_ENABLE_SHARED'):
+ from distutils import sysconfig
+ if sysconfig.get_config_var('Py_ENABLE_SHARED'):
template = "python%d.%d"
pythonlib = (template %
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))