summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py121
1 files changed, 84 insertions, 37 deletions
diff --git a/setup.py b/setup.py
index 2dca4fb..ba0cc0d 100644
--- a/setup.py
+++ b/setup.py
@@ -41,6 +41,7 @@ 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 distutils.sysconfig
import os, sys, re
import struct
@@ -114,38 +115,22 @@ class PCTBuildExt (build_ext):
# Tweak compiler options
if self.compiler.compiler_type in ('unix', 'cygwin', 'mingw32'):
- # Tell GCC to compile using the C99 standard.
- self.__add_compiler_option("-std=c99")
-
- # ... but don't tell that to the aCC compiler on HP-UX
- if self.compiler.compiler_so[0] == 'cc' and sys.platform.startswith('hp-ux'):
- self.__remove_compiler_option("-std=c99")
-
# Make assert() statements always work
self.__remove_compiler_option("-DNDEBUG")
- # Choose our own optimization options
- for opt in ["-O", "-O0", "-O1", "-O2", "-O3", "-Os"]:
- self.__remove_compiler_option(opt)
- if self.debug:
- # Basic optimization is still needed when debugging to compile
- # the libtomcrypt code.
- self.__add_compiler_option("-O")
- else:
- # Speed up execution by tweaking compiler options. This
- # especially helps the DES modules.
- self.__add_compiler_option("-O3")
- self.__add_compiler_option("-fomit-frame-pointer")
- # Don't include debug symbols unless debugging
- self.__remove_compiler_option("-g")
- # Don't include profiling information (incompatible with
- # -fomit-frame-pointer)
- self.__remove_compiler_option("-pg")
- if USE_GCOV:
+ if USE_GCOV: # TODO - move this to configure.ac
self.__add_compiler_option("-fprofile-arcs")
self.__add_compiler_option("-ftest-coverage")
self.compiler.libraries += ['gcov']
+ # Python 2.1 and 2.2 don't respect the LDFLAGS environment variable. Hack it.
+ if sys.version_info < (2, 3, 'final', 0):
+ if os.environ.get('LDFLAGS'): # Set from ./buildenv (ultimately provided by autoconf)
+ for opt in os.environ['LDFLAGS'].split(" "):
+ opt = opt.strip()
+ if not opt: continue
+ self.compiler.linker_so.append(opt)
+
# Call the superclass's build_extensions method
build_ext.build_extensions(self)
@@ -177,6 +162,21 @@ class PCTBuildExt (build_ext):
"Crypto.PublicKey._fastmath.")
self.__remove_extensions(["Crypto.PublicKey._fastmath"])
+ # Detect if we have AES-NI instrincs available
+ if not ac.get("HAVE_WMMINTRIN_H"):
+ # AES-NI instrincs not available
+ self.__remove_extensions(["Crypto.Cipher._AESNI"])
+ elif ac.get("HAVE_MAES"):
+ # -maes has to be passed to the compiler to use the AES-NI instrincs
+ self.__add_extension_compile_option(["Crypto.Cipher._AESNI"],
+ ["-maes"])
+
+ def __add_extension_compile_option(self, names, options):
+ """Add compiler options for the specified extension(s)"""
+ for extension in self.extensions:
+ if extension.name in names:
+ extension.extra_compile_args = options
+
def __add_extension_link_option(self, names, options):
"""Add linker options for the specified extension(s)"""
i = 0
@@ -247,10 +247,40 @@ class PCTBuildExt (build_ext):
return result
def run(self):
+ # Run the commands that this one depends on (i.e. build_configure)
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
- build_ext.run(self)
+ class unmodified: pass # sentinel value
+ orig_cc = unmodified
+ try:
+ # Set environment variables generated by the configure script
+ if os.path.exists("buildenv"):
+ try:
+ f = open("buildenv", "r")
+ for line in f.readlines():
+ if line.startswith("#") or not line.strip():
+ continue
+ k, v = line.split("=", 1)
+ k, v = k.strip(), v.strip()
+ os.environ[k] = v
+ finally:
+ f.close()
+
+ # Python 2.1 and 2.2 don't respect the CC environment variable by default. Monkey-patch it.
+ if sys.version_info < (2, 3, 'final', 0) and os.environ.get('CC'):
+ distutils.sysconfig.get_config_vars() # populates distutils.sysconfig._config_vars
+ orig_cc = distutils.sysconfig._config_vars['CC']
+ distutils.sysconfig._config_vars['CC'] = os.environ['CC']
+
+ # Build the extension modules
+ build_ext.run(self)
+
+ finally:
+ if orig_cc is not unmodified:
+ # Undo monkey-patch
+ distutils.sysconfig._config_vars['CC'] = orig_cc
+
def has_configure(self):
compiler = new_compiler(compiler=self.compiler)
@@ -269,8 +299,11 @@ class PCTBuildConfigure(Command):
def run(self):
if not os.path.exists("config.status"):
- if os.system("chmod 0755 configure") != 0:
- raise RuntimeError("chmod error")
+ if hasattr(os, "chmod"):
+ import stat
+ os.chmod("configure", stat.S_IRUSR | stat.S_IWUSR |
+ stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP |
+ stat.S_IROTH | stat.S_IXOTH)
cmd = "sh configure" # we use "sh" here so that it'll work on mingw32 with standard python.org binaries
if self.verbose < 1:
cmd += " -q"
@@ -313,6 +346,10 @@ class TestCommand(Command):
self.config = {'slow_tests': not self.skip_slow_tests}
def run(self):
+ # Run sub commands
+ for cmd_name in self.get_sub_commands():
+ self.run_command(cmd_name)
+
# Run SelfTest
self.announce("running self-tests")
old_path = sys.path[:]
@@ -341,6 +378,8 @@ class TestCommand(Command):
# Run slower self-tests
self.announce("running extended self-tests")
+ sub_commands = [ ('build', None) ]
+
kw = {'name':"pycrypto",
'version':"2.6.1", # See also: lib/Crypto/__init__.py
'description':"Cryptographic modules for Python.",
@@ -363,37 +402,39 @@ kw = {'name':"pycrypto",
"Crypto.SelfTest.Random.OSRNG",
"Crypto.SelfTest.Util",
"Crypto.SelfTest.Signature",
+ "Crypto.SelfTest.IO",
"Crypto.Protocol",
"Crypto.PublicKey",
- "Crypto.Signature"],
+ "Crypto.Signature",
+ "Crypto.IO"],
'package_dir' : { "Crypto": "lib/Crypto" },
'ext_modules': plat_ext + [
# _fastmath (uses GNU mp library)
Extension("Crypto.PublicKey._fastmath",
- include_dirs=['src/','/usr/include/'],
+ include_dirs=['src/'],
libraries=['gmp'],
sources=["src/_fastmath.c"]),
# Hash functions
- Extension("Crypto.Hash._MD2",
+ Extension("Crypto.Hash.MD2",
include_dirs=['src/'],
sources=["src/MD2.c"]),
- Extension("Crypto.Hash._MD4",
+ Extension("Crypto.Hash.MD4",
include_dirs=['src/'],
sources=["src/MD4.c"]),
- Extension("Crypto.Hash._SHA256",
+ Extension("Crypto.Hash.SHA256",
include_dirs=['src/'],
sources=["src/SHA256.c"]),
- Extension("Crypto.Hash._SHA224",
+ Extension("Crypto.Hash.SHA224",
include_dirs=['src/'],
sources=["src/SHA224.c"]),
- Extension("Crypto.Hash._SHA384",
+ Extension("Crypto.Hash.SHA384",
include_dirs=['src/'],
sources=["src/SHA384.c"]),
- Extension("Crypto.Hash._SHA512",
+ Extension("Crypto.Hash.SHA512",
include_dirs=['src/'],
sources=["src/SHA512.c"]),
- Extension("Crypto.Hash._RIPEMD160",
+ Extension("Crypto.Hash.RIPEMD160",
include_dirs=['src/'],
sources=["src/RIPEMD160.c"],
define_macros=[endianness_macro()]),
@@ -402,6 +443,9 @@ kw = {'name':"pycrypto",
Extension("Crypto.Cipher._AES",
include_dirs=['src/'],
sources=["src/AES.c"]),
+ Extension("Crypto.Cipher._AESNI",
+ include_dirs=['src/'],
+ sources=["src/AESNI.c"]),
Extension("Crypto.Cipher._ARC2",
include_dirs=['src/'],
sources=["src/ARC2.c"]),
@@ -430,6 +474,9 @@ kw = {'name':"pycrypto",
Extension("Crypto.Util.strxor",
include_dirs=['src/'],
sources=['src/strxor.c']),
+ Extension("Crypto.Util.cpuid",
+ include_dirs=['src/'],
+ sources=['src/cpuid.c']),
# Counter modules
Extension("Crypto.Util._counter",