25
25
import sys
26
26
import subprocess
27
27
import textwrap
28
+ import sysconfig
28
29
29
30
30
31
if sys .version_info [:2 ] < (3 , 5 ):
@@ -228,6 +229,40 @@ def run(self):
228
229
sdist .run (self )
229
230
230
231
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
+
231
266
def generate_cython ():
232
267
cwd = os .path .abspath (os .path .dirname (__file__ ))
233
268
print ("Cythonizing sources" )
@@ -390,6 +425,8 @@ def setup_package():
390
425
'f2py%s.%s = numpy.f2py.f2py2e:main' % sys .version_info [:2 ],
391
426
]
392
427
428
+ cmdclass = {"sdist" : sdist_checked ,
429
+ }
393
430
metadata = dict (
394
431
name = 'numpy' ,
395
432
maintainer = "NumPy Developers" ,
@@ -408,8 +445,7 @@ def setup_package():
408
445
classifiers = [_f for _f in CLASSIFIERS .split ('\n ' ) if _f ],
409
446
platforms = ["Windows" , "Linux" , "Solaris" , "Mac OS-X" , "Unix" ],
410
447
test_suite = 'nose.collector' ,
411
- cmdclass = {"sdist" : sdist_checked ,
412
- },
448
+ cmdclass = cmdclass ,
413
449
python_requires = '>=3.5' ,
414
450
zip_safe = False ,
415
451
entry_points = {
@@ -433,6 +469,8 @@ def setup_package():
433
469
generate_cython ()
434
470
435
471
metadata ['configuration' ] = configuration
472
+ # Customize extension building
473
+ cmdclass ['build_clib' ], cmdclass ['build_ext' ] = get_build_overrides ()
436
474
else :
437
475
# Version number is added to metadata inside configuration() if build
438
476
# is run.
0 commit comments