summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2015-07-11 03:43:04 +0200
committerMatěj Cepl <mcepl@cepl.eu>2015-10-13 15:52:26 +0200
commit62dbd41b0b6e3d04a02a3d9d8bd533e6016e6565 (patch)
tree267667fce9a7adbf9acaef2a9dfe1c7d5e093c8e /setup.py
parent4c606090a51c54caadda8a6f0090ccb6737408f0 (diff)
downloadm2crypto-62dbd41b0b6e3d04a02a3d9d8bd533e6016e6565.tar.gz
Fix build with SWIG 3.0.5
See analysis and previous patches in https://github.com/martinpaljak/M2Crypto/issues/60 and https://github.com/swig/swig/issues/344, in particular this adds the build machinery to patch https://github.com/martinpaljak/M2Crypto/issues/60#issuecomment-75735489 Fixes #47
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py96
1 files changed, 38 insertions, 58 deletions
diff --git a/setup.py b/setup.py
index ec0ed5e..4b37d0f 100644
--- a/setup.py
+++ b/setup.py
@@ -23,6 +23,8 @@ except ImportError:
from distutils.command import build_ext
from distutils.core import Extension
+from distutils.spawn import find_executable
+from distutils.file_util import copy_file
class _M2CryptoBuildExt(build_ext.build_ext):
@@ -58,9 +60,24 @@ class _M2CryptoBuildExt(build_ext.build_ext):
self.swig_opts = ['-I%s' % i for i in self.include_dirs + \
[opensslIncludeDir]]
self.swig_opts.append('-includeall')
- #self.swig_opts.append('-D__i386__') # Uncomment for early OpenSSL 0.9.7 versions, or on Fedora Core if build fails
- #self.swig_opts.append('-DOPENSSL_NO_EC') # Try uncommenting if you can't build with EC disabled
-
+ self.swig_opts.append('-modern')
+ self.swig_opts.append('-builtin')
+
+ # These two lines are a workaround for
+ # http://bugs.python.org/issue2624 , hard-coding that we are only
+ # building a single extension with a known path; a proper patch to
+ # distutils would be in the run phase, when extension name and path are
+ # known.
+ self.swig_opts.append('-outdir')
+ self.swig_opts.append(os.path.join(self.build_lib, 'M2Crypto'))
+
+ # Fedora does hat tricks.
+ if platform.linux_distribution()[0] in ['Fedora', 'CentOS']:
+ if platform.architecture()[0] == '64bit':
+ self.swig_opts.append('-D__x86_64__')
+ elif platform.architecture()[0] == '32bit':
+ self.swig_opts.append('-D__i386__')
+
self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir),
os.path.join(os.getcwd(), 'SWIG')]
@@ -74,61 +91,24 @@ class _M2CryptoBuildExt(build_ext.build_ext):
self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)]
-
-if sys.version_info < (2,4):
-
- # This copy of swig_sources is from Python 2.2.
-
- def swig_sources (self, sources):
-
- """Walk the list of source files in 'sources', looking for SWIG
- interface (.i) files. Run SWIG on all that are found, and
- return a modified 'sources' list with SWIG source files replaced
- by the generated C (or C++) files.
- """
-
- new_sources = []
- swig_sources = []
- swig_targets = {}
-
- # XXX this drops generated C/C++ files into the source tree, which
- # is fine for developers who want to distribute the generated
- # source -- but there should be an option to put SWIG output in
- # the temp dir.
-
- if self.swig_cpp:
- target_ext = '.cpp'
- else:
- target_ext = '.c'
-
- for source in sources:
- (base, ext) = os.path.splitext(source)
- if ext == ".i": # SWIG interface file
- new_sources.append(base + target_ext)
- swig_sources.append(source)
- swig_targets[source] = new_sources[-1]
- else:
- new_sources.append(source)
-
- if not swig_sources:
- return new_sources
-
- swig = self.find_swig()
- swig_cmd = [swig, "-python", "-ISWIG"]
- if self.swig_cpp:
- swig_cmd.append("-c++")
-
- swig_cmd += self.swig_opts
-
- for source in swig_sources:
- target = swig_targets[source]
- self.announce("swigging %s to %s" % (source, target))
- self.spawn(swig_cmd + ["-o", target, source])
-
- return new_sources
-
- build_ext.build_ext.swig_sources = swig_sources
-
+ def run(self):
+ '''Overloaded build_ext implementation to allow inplace=1 to work,
+ which is needed for (python setup.py test).'''
+ # This is another workaround for http://bugs.python.org/issue2624 + the
+ # corresponding lack of support in setuptools' test command. Note that
+ # just using self.inplace in finalize_options() above does not work
+ # because swig is not rerun if the __m2crypto.so extension exists.
+ # Again, hard-coding our extension name and location.
+ build_ext.build_ext.run(self)
+ if self.inplace:
+ copy_file(os.path.join(self.build_lib, 'M2Crypto', '_m2crypto.py'),
+ os.path.join('M2Crypto', '_m2crypto.py'),
+ verbose=self.verbose, dry_run=self.dry_run)
+
+if sys.platform == 'darwin':
+ my_extra_compile_args = ["-Wno-deprecated-declarations"]
+else:
+ my_extra_compile_args = []
m2crypto = Extension(name = 'M2Crypto.__m2crypto',
sources = ['SWIG/_m2crypto.i'],