summaryrefslogtreecommitdiff
path: root/pipermail/pycrypto/attachments/20110925/006d4129/attachment-0001.patch
diff options
context:
space:
mode:
Diffstat (limited to 'pipermail/pycrypto/attachments/20110925/006d4129/attachment-0001.patch')
-rw-r--r--pipermail/pycrypto/attachments/20110925/006d4129/attachment-0001.patch90
1 files changed, 90 insertions, 0 deletions
diff --git a/pipermail/pycrypto/attachments/20110925/006d4129/attachment-0001.patch b/pipermail/pycrypto/attachments/20110925/006d4129/attachment-0001.patch
new file mode 100644
index 0000000..28da98d
--- /dev/null
+++ b/pipermail/pycrypto/attachments/20110925/006d4129/attachment-0001.patch
@@ -0,0 +1,90 @@
+diff --git a/setup.py b/setup.py
+index 64733d2..271c5ec 100644
+--- a/setup.py
++++ b/setup.py
+@@ -39,6 +39,9 @@ __revision__ = "$Id$"
+ from distutils import core
+ from distutils.core import Extension, Command
+ from distutils.command.build_ext import build_ext
++from distutils.errors import CompileError, LinkError
++import distutils
++import tempfile
+ import os, sys
+ import struct
+
+@@ -69,42 +72,29 @@ EXCLUDE_PY = [
+ ('Crypto.Hash', 'RIPEMD160'), # Included for your amusement, but the C version is much faster.
+ ]
+
+-# Functions for finding libraries and files, copied from Python's setup.py.
+-
+-def find_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.
+- """
+-
+- # Check the standard locations
+- for dir in std_dirs:
+- f = os.path.join(dir, filename)
+- if os.path.exists(f): return []
+-
+- # Check the additional directories
+- for dir in paths:
+- f = os.path.join(dir, filename)
+- if os.path.exists(f):
+- return [dir]
+-
+- # Not found anywhere
+- return None
+-
+-def find_library_file(compiler, libname, std_dirs, paths):
+- filename = compiler.library_filename(libname, lib_type='shared')
+- result = find_file(filename, std_dirs, paths)
+- if result is not None: return result
+-
+- filename = compiler.library_filename(libname, lib_type='static')
+- result = find_file(filename, std_dirs, paths)
+- return result
++def libgmp_exists():
++ fname = tempfile.mktemp(".c")
++ f = open(fname, 'w')
++ f.write("""
++ #include <gmp.h>
++
++ int main(void)
++ {
++ mpz_init((void*)0);
++ return 0;
++ }
++ """)
++ f.close()
++
++ try:
++ compiler = distutils.ccompiler.new_compiler()
++ objects = compiler.compile([fname])
++ compiler.link_executable(objects, "a.out", libraries=('gmp',) )
++ except (CompileError, LinkError, TypeError):
++ os.remove(fname)
++ return False
++ os.remove(fname)
++ return True
+
+ def endianness_macro():
+ s = struct.pack("@I", 0x33221100)
+@@ -157,8 +147,7 @@ class PCTBuildExt (build_ext):
+ self.compiler.include_dirs.insert(0, "src/inc-msvc/")
+
+ # Detect libgmp and don't build _fastmath if it is missing.
+- lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
+- if not (self.compiler.find_library_file(lib_dirs, 'gmp')):
++ if not libgmp_exists():
+ print >>sys.stderr, "warning: GMP library not found; Not building Crypto.PublicKey._fastmath."
+ self.__remove_extensions(["Crypto.PublicKey._fastmath"])
+ \ No newline at end of file