summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2020-08-27 13:14:12 -0600
committerGitHub <noreply@github.com>2020-08-27 13:14:12 -0600
commita7401aee4d6d465977760e9e4b16f793d60f4ee4 (patch)
treedeab92771d87bf50f53bd0bf3d741524d1e19cd3 /setup.py
parente4e0ab8e5ba9cdf17f9bd2c3c9e06e3d12030022 (diff)
parent10dcfb0da453b103192a3adeca3197ac161f29a0 (diff)
downloadnumpy-a7401aee4d6d465977760e9e4b16f793d60f4ee4.tar.gz
Merge pull request #16619 from mattip/c99-again2
BLD: check if std=c99 is really required
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/setup.py b/setup.py
index 0016deac0..1f5212676 100755
--- a/setup.py
+++ b/setup.py
@@ -189,7 +189,6 @@ def check_submodules():
for line in status.splitlines():
if line.startswith('-') or line.startswith('+'):
raise ValueError('Submodule not clean: {}'.format(line))
-
class concat_license_files():
@@ -234,20 +233,27 @@ def get_build_overrides():
"""
from numpy.distutils.command.build_clib import build_clib
from numpy.distutils.command.build_ext import build_ext
+ from distutils.version import LooseVersion
- def _is_using_gcc(obj):
- is_gcc = False
- if obj.compiler.compiler_type == 'unix':
- cc = sysconfig.get_config_var("CC")
- if not cc:
- cc = ""
- compiler_name = os.path.basename(cc)
- is_gcc = "gcc" in compiler_name
- return is_gcc
+ def _needs_gcc_c99_flag(obj):
+ if obj.compiler.compiler_type != 'unix':
+ return False
+
+ cc = obj.compiler.compiler[0]
+ if "gcc" not in cc:
+ return False
+
+ # will print something like '4.2.1\n'
+ out = subprocess.run([cc, '-dumpversion'], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, universal_newlines=True)
+ # -std=c99 is default from this version on
+ if LooseVersion(out.stdout) >= LooseVersion('5.0'):
+ return False
+ return True
class new_build_clib(build_clib):
def build_a_library(self, build_info, lib_name, libraries):
- if _is_using_gcc(self):
+ if _needs_gcc_c99_flag(self):
args = build_info.get('extra_compiler_args') or []
args.append('-std=c99')
build_info['extra_compiler_args'] = args
@@ -255,7 +261,7 @@ def get_build_overrides():
class new_build_ext(build_ext):
def build_extension(self, ext):
- if _is_using_gcc(self):
+ if _needs_gcc_c99_flag(self):
if '-std=c99' not in ext.extra_compile_args:
ext.extra_compile_args.append('-std=c99')
build_ext.build_extension(self, ext)