From a14a861b441776e77b6a5e3d505fa51ce632f9ed Mon Sep 17 00:00:00 2001
From: Paul Kehrer <paul.l.kehrer@gmail.com>
Date: Thu, 31 Dec 2015 20:18:38 -0600
Subject: don't add the NXCOMPAT and DYNAMICBASE flags if the compiler isn't
 msvc

---
 src/_cffi_src/utils.py | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

(limited to 'src/_cffi_src/utils.py')

diff --git a/src/_cffi_src/utils.py b/src/_cffi_src/utils.py
index 0b00353e..bdce2f3b 100644
--- a/src/_cffi_src/utils.py
+++ b/src/_cffi_src/utils.py
@@ -5,6 +5,8 @@
 from __future__ import absolute_import, division, print_function
 
 import sys
+from distutils.ccompiler import new_compiler
+from distutils.dist import Distribution
 
 from cffi import FFI
 
@@ -79,10 +81,23 @@ def build_ffi(module_name, cdef_source, verify_source, libraries=[],
     return ffi
 
 
-def extra_link_args(platform):
-    if platform != "win32":
-        return []
+def extra_link_args(compiler_type):
+    if compiler_type == 'msvc':
+        # Enable NX and ASLR for Windows builds on MSVC. These are enabled by
+        # default on Python 3.3+ but not on 2.x.
+        return ['/NXCOMPAT', '/DYNAMICBASE']
     else:
-        # Enable NX and ASLR for Windows builds. These are enabled by default
-        # on Python 3.3+ but not on 2.x.
-        return ["/NXCOMPAT", "/DYNAMICBASE"]
+        return []
+
+
+def compiler_type():
+    """
+    Gets the compiler type from distutils. On Windows with MSVC it will be
+    "msvc". On OS X and linux it is "unix".
+    """
+    dist = Distribution()
+    dist.parse_config_files()
+    cmd = dist.get_command_obj('build')
+    cmd.ensure_finalized()
+    compiler = new_compiler(compiler=cmd.compiler)
+    return compiler.compiler_type
-- 
cgit v1.2.3