summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-02-02 20:48:04 -0800
committerDwayne Litzenberger <dlitz@dlitz.net>2013-02-16 13:09:42 -0800
commit95918a1a86bc1e4c5045801b4bdb83359e033c6a (patch)
treec594383bae412a70e930c6f37040fb8d34572de2 /setup.py
parent6e3d2bdcc0e2a97f56f69c77b8acd1fbd80eaa45 (diff)
downloadpycrypto-95918a1a86bc1e4c5045801b4bdb83359e033c6a.tar.gz
Use autoconf to generate compiler options
Hopefully this means we'll break on fewer platforms. Also, remove some of the extra optimization flags (e.g. -O3 -fomit-frame-pointer), which don't really do much.
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py74
1 files changed, 42 insertions, 32 deletions
diff --git a/setup.py b/setup.py
index 7ef7928..13ff5e2 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,43 +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")
-
- # More compiler warnings
- self.__add_compiler_option("-Wextra")
- self.__add_compiler_option("-Wno-missing-field-initializers")
- self.__add_compiler_option("-Wno-unused-parameter")
-
- # ... 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)
@@ -252,10 +232,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)
@@ -384,7 +394,7 @@ kw = {'name':"pycrypto",
'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"]),