Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40addab

Browse files
authored
Merge pull request #15245 from charris/backport-15238
MAINT: only add --std=c99 where needed
2 parents 9d979a7 + c1f1875 commit 40addab

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

numpy/distutils/ccompiler.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,6 @@ def CCompiler_customize(self, dist, need_cxx=0):
532532
'g++' in self.compiler[0] or
533533
'clang' in self.compiler[0]):
534534
self._auto_depends = True
535-
if 'gcc' in self.compiler[0] and not need_cxx:
536-
# add std=c99 flag for gcc
537-
# TODO: does this need to be more specific?
538-
self.compiler.append('-std=c99')
539-
self.compiler_so.append('-std=c99')
540535
elif os.name == 'posix':
541536
import tempfile
542537
import shutil

numpy/distutils/tests/test_ccompiler.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

setup.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import sys
2626
import subprocess
2727
import textwrap
28+
import sysconfig
2829

2930

3031
if sys.version_info[:2] < (3, 5):
@@ -228,6 +229,40 @@ def run(self):
228229
sdist.run(self)
229230

230231

232+
def get_build_overrides():
233+
"""
234+
Custom build commands to add `-std=c99` to compilation
235+
"""
236+
from numpy.distutils.command.build_clib import build_clib
237+
from numpy.distutils.command.build_ext import build_ext
238+
239+
def _is_using_gcc(obj):
240+
is_gcc = False
241+
if obj.compiler.compiler_type == 'unix':
242+
cc = sysconfig.get_config_var("CC")
243+
if not cc:
244+
cc = ""
245+
compiler_name = os.path.basename(cc)
246+
is_gcc = "gcc" in compiler_name
247+
return is_gcc
248+
249+
class new_build_clib(build_clib):
250+
def build_a_library(self, build_info, lib_name, libraries):
251+
if _is_using_gcc(self):
252+
args = build_info.get('extra_compiler_args') or []
253+
args.append('-std=c99')
254+
build_info['extra_compiler_args'] = args
255+
build_clib.build_a_library(self, build_info, lib_name, libraries)
256+
257+
class new_build_ext(build_ext):
258+
def build_extension(self, ext):
259+
if _is_using_gcc(self):
260+
if '-std=c99' not in ext.extra_compile_args:
261+
ext.extra_compile_args.append('-std=c99')
262+
build_ext.build_extension(self, ext)
263+
return new_build_clib, new_build_ext
264+
265+
231266
def generate_cython():
232267
cwd = os.path.abspath(os.path.dirname(__file__))
233268
print("Cythonizing sources")
@@ -390,6 +425,8 @@ def setup_package():
390425
'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2],
391426
]
392427

428+
cmdclass={"sdist": sdist_checked,
429+
}
393430
metadata = dict(
394431
name = 'numpy',
395432
maintainer = "NumPy Developers",
@@ -408,8 +445,7 @@ def setup_package():
408445
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
409446
platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
410447
test_suite='nose.collector',
411-
cmdclass={"sdist": sdist_checked,
412-
},
448+
cmdclass=cmdclass,
413449
python_requires='>=3.5',
414450
zip_safe=False,
415451
entry_points={
@@ -433,6 +469,8 @@ def setup_package():
433469
generate_cython()
434470

435471
metadata['configuration'] = configuration
472+
# Customize extension building
473+
cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides()
436474
else:
437475
# Version number is added to metadata inside configuration() if build
438476
# is run.

0 commit comments

Comments
 (0)