summaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2006-03-08 19:51:58 (GMT)
committerThomas Heller <theller@ctypes.org>2006-03-08 19:51:58 (GMT)
commitcf567c1b9c347e5a5e5833fecb7d10ecc675a83b (patch)
treec0f1b666317a4fe7c94859e4583716b81b82920f /setup.py
parentd4c9320412177895f598a93d73a0e654db27c351 (diff)
downloadcpython-cf567c1b9c347e5a5e5833fecb7d10ecc675a83b.zip
cpython-cf567c1b9c347e5a5e5833fecb7d10ecc675a83b.tar.gz
cpython-cf567c1b9c347e5a5e5833fecb7d10ecc675a83b.tar.bz2
Changes to build the _ctypes extension module.
Based on a patch from Hye-Shik Chang.
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/setup.py b/setup.py
index de7c13c..09b79fd 100644
--- a/setup.py
+++ b/setup.py
@@ -888,6 +888,9 @@ class PyBuildExt(build_ext):
if (dl_inc is not None) and (platform not in ['atheos', 'darwin']):
exts.append( Extension('dl', ['dlmodule.c']) )
+ # Thomas Heller's _ctypes module
+ self.detect_ctypes()
+
# Platform-specific libraries
if platform == 'linux2':
# Linux-specific modules
@@ -1180,6 +1183,61 @@ class PyBuildExt(build_ext):
# *** Uncomment these for TOGL extension only:
# -lGL -lGLU -lXext -lXmu \
+ def detect_ctypes(self):
+ (srcdir,) = sysconfig.get_config_vars('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')
+
+ if self.force or not os.path.exists(ffi_configfile):
+ from distutils.dir_util import mkpath
+ mkpath(ffi_builddir)
+ config_args = []
+
+ # 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)
+ if res or not os.path.exists(ffi_configfile):
+ print "Failed to configure _ctypes module"
+ return
+
+ fficonfig = {}
+ execfile(ffi_configfile, globals(), fficonfig)
+ ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
+
+ # 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, ffi_srcdir]
+ extra_compile_args = fficonfig['ffi_cflags'].split()
+ sources = ['_ctypes/_ctypes.c',
+ '_ctypes/callbacks.c',
+ '_ctypes/callproc.c',
+ '_ctypes/stgdict.c',
+ '_ctypes/cfield.c',
+ '_ctypes/malloc_closure.c'] + fficonfig['ffi_sources']
+ depends = ['_ctypes/ctypes.h']
+
+ if sys.platform == 'darwin':
+ sources.append('_ctypes/darwin/dlfcn_simple.c')
+ include_dirs.append('_ctypes/darwin')
+# XXX Is this still needed?
+## extra_link_args.extend(['-read_only_relocs', 'warning'])
+
+ ext = Extension('_ctypes',
+ include_dirs=include_dirs,
+ extra_compile_args=extra_compile_args,
+ sources=sources,
+ depends=depends)
+ ext_test = Extension('_ctypes_test',
+ sources=['_ctypes/_ctypes_test.c'])
+ self.extensions.extend([ext, ext_test])
+
class PyBuildInstall(install):
# Suppress the warning about installation into the lib_dynload
# directory, which is not in sys.path when running Python during