diff options
author | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2011-10-10 19:14:30 -0400 |
---|---|---|
committer | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2011-10-10 19:15:50 -0400 |
commit | 323ce9ef951378dc96ce14c9e514e9aa19ab39d9 (patch) | |
tree | 5986ee1d95f37cdb4605b5b4899667747ae40dfc /setup.py | |
parent | 32114297da2450af00c4612596bc15da4f6256f2 (diff) | |
download | pycrypto-323ce9ef951378dc96ce14c9e514e9aa19ab39d9.tar.gz |
Fix libgmp/libmpir autodetection
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 62 |
1 files changed, 46 insertions, 16 deletions
@@ -37,11 +37,12 @@ __revision__ = "$Id$" from distutils import core +from distutils.ccompiler import new_compiler from distutils.core import Extension, Command from distutils.command.build import build from distutils.command.build_ext import build_ext -import os, sys +import os, sys, re import struct if sys.version[0:1] == '1': @@ -190,26 +191,32 @@ class PCTBuildExt (build_ext): build_ext.build_extensions(self) def detect_modules (self): - # Add special include directory for MSVC (because MSVC is special) + # Read the config.h file (usually generated by autoconf) if self.compiler.compiler_type == 'msvc': + # Add special include directory for MSVC (because MSVC is special) self.compiler.include_dirs.insert(0, "src/inc-msvc/") + ac = self.__read_autoconf("src/inc-msvc/config.h") + else: + ac = self.__read_autoconf("src/config.h") # Detect libgmp or libmpir and don't build _fastmath if both are missing. - lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib', '/usr/local/lib'] - if not (self.compiler.find_library_file(lib_dirs, 'gmp') or - self.compiler.find_library_file(lib_dirs, 'mpir')): - PrintErr ("warning: GMP or MPIR library not found; Not building "+ - "Crypto.PublicKey._fastmath.") - self.__remove_extensions(["Crypto.PublicKey._fastmath"]) - # Change library to libmpir if libgmp is missing - elif not (self.compiler.find_library_file(lib_dirs, 'gmp')): + if ac.get("HAVE_LIBGMP"): + # Default; no changes needed + pass + elif ac.get("HAVE_LIBMPIR"): + # Change library to libmpir if libgmp is missing self.__change_extension_lib(["Crypto.PublicKey._fastmath"], ['mpir']) - # And if this is Windows, we need to add a linker option + # And if this is MSVC, we need to add a linker option # to make a static libmpir link well into a dynamic _fastmath - if sys.platform == 'win32': + if self.compiler.compiler_type == 'msvc': self.__add_extension_link_option(["Crypto.PublicKey._fastmath"], ["/NODEFAULTLIB:LIBCMT"]) + else: + # No MP library; use _slowmath. + PrintErr ("warning: GMP or MPIR library not found; Not building "+ + "Crypto.PublicKey._fastmath.") + self.__remove_extensions(["Crypto.PublicKey._fastmath"]) def __add_extension_link_option(self, names, options): """Add linker options for the specified extension(s)""" @@ -257,9 +264,33 @@ class PCTBuildExt (build_ext): if compiler is not None: compiler.append(option) + def __read_autoconf(self, filename): + rx_define = re.compile(r"""^#define (\S+) (?:(\d+)|(".*"))$""") + + result = {} + f = open(filename, "r") + try: + config_lines = f.read().replace("\r\n", "\n").split("\n") + for line in config_lines: + m = rx_define.search(line) + if not m: continue + sym = m.group(1) + n = m.group(2) + s = m.group(3) + if n: + result[sym] = int(n) + elif s: + result[sym] = eval(s) # XXX - hack to unescape C-style string + else: + continue + finally: + f.close() + return result + class PCTBuild(build): def has_configure(self): - return sys.platform != 'win32' + compiler = new_compiler(compiler=self.compiler) + return compiler.compiler_type != 'msvc' sub_commands = [ ('build_configure', has_configure) ] + build.sub_commands @@ -276,10 +307,9 @@ class PCTBuildConfigure(Command): if not os.path.exists("config.status"): if os.system("chmod 0755 configure") != 0: raise RuntimeError("chmod error") + cmd = "sh configure" # we use "sh" here so that it'll work on mingw32 with standard python.org binaries if self.verbose < 1: - cmd = "./configure -q" - else: - cmd = "./configure" + cmd += " -q" if os.system(cmd) != 0: raise RuntimeError("autoconf error") |