@@ -364,57 +364,6 @@ def find_module_file(module, dirlist):
364
364
return os .path .abspath (os .path .join (dirs [0 ], module ))
365
365
366
366
367
- def parse_cflags (flags ):
368
- """Parse a string with compiler flags (-I, -D, -U, extra)
369
-
370
- Distutils appends extra args to the compiler arguments. Some flags like
371
- -I must appear earlier. Otherwise the pre-processor picks up files
372
- from system inclue directories.
373
- """
374
- include_dirs = []
375
- define_macros = []
376
- undef_macros = []
377
- extra_compile_args = []
378
- if flags is not None :
379
- # shlex.split(None) reads from stdin
380
- for token in shlex .split (flags ):
381
- switch = token [0 :2 ]
382
- value = token [2 :]
383
- if switch == '-I' :
384
- include_dirs .append (value )
385
- elif switch == '-D' :
386
- key , _ , val = value .partition ("=" )
387
- if not val :
388
- val = None
389
- define_macros .append ((key , val ))
390
- elif switch == '-U' :
391
- undef_macros .append (value )
392
- else :
393
- extra_compile_args .append (token )
394
-
395
- return include_dirs , define_macros , undef_macros , extra_compile_args
396
-
397
-
398
- def parse_ldflags (flags ):
399
- """Parse a string with linker flags (-L, -l, extra)"""
400
- library_dirs = []
401
- libraries = []
402
- extra_link_args = []
403
- if flags is not None :
404
- # shlex.split(None) reads from stdin
405
- for token in shlex .split (flags ):
406
- switch = token [0 :2 ]
407
- value = token [2 :]
408
- if switch == '-L' :
409
- library_dirs .append (value )
410
- elif switch == '-l' :
411
- libraries .append (value )
412
- else :
413
- extra_link_args .append (token )
414
-
415
- return library_dirs , libraries , extra_link_args
416
-
417
-
418
367
class PyBuildExt (build_ext ):
419
368
420
369
def __init__ (self , dist ):
@@ -430,10 +379,17 @@ def __init__(self, dist):
430
379
if '-j' in os .environ .get ('MAKEFLAGS' , '' ):
431
380
self .parallel = True
432
381
433
- def add (self , ext , * , update_flags = False ):
434
- if update_flags :
435
- self .update_extension_flags (ext )
436
- self .extensions .append (ext )
382
+ def add (self , ext , * , update_flags = True ):
383
+ state = sysconfig .get_config_var (f"MODULE_{ ext .name .upper ()} " )
384
+ if state == "yes" :
385
+ if update_flags :
386
+ self .update_extension_flags (ext )
387
+ self .extensions .append (ext )
388
+ elif state == "disabled" :
389
+ self .disabled_configure .append (ext .name )
390
+ elif state == "missing" :
391
+ self .missing .append (ext .name )
392
+ # state in {"n/a", None}
437
393
438
394
def set_srcdir (self ):
439
395
self .srcdir = sysconfig .get_config_var ('srcdir' )
@@ -478,27 +434,66 @@ def update_sources_depends(self):
478
434
for ext in self .extensions :
479
435
ext .sources = [ find_module_file (filename , moddirlist )
480
436
for filename in ext .sources ]
481
- # Update dependencies from Makefile
482
- makedeps = sysconfig .get_config_var (f"MODULE_{ ext .name .upper ()} _DEPS" )
483
- if makedeps :
437
+ if ext .depends is not None :
438
+ ext .depends = [find_module_file (filename , moddirlist )
439
+ for filename in ext .depends ]
440
+ else :
441
+ ext .depends = []
442
+ # Update dependencies from Makefile, file path have correct prefix
443
+ deps = sysconfig .get_config_var (f"MODULE_{ ext .name .upper ()} _DEPS" )
444
+ if deps :
484
445
# remove backslashes from line break continuations
485
- ext .depends .extend (
486
- dep for dep in makedeps .split () if dep != "\\ "
487
- )
488
- ext .depends = [
489
- find_module_file (filename , moddirlist ) for filename in ext .depends
490
- ]
446
+ deps = deps .replace ("\\ " , " " )
447
+ ext .depends .extend (shlex .split (deps ))
491
448
# re-compile extensions if a header file has been changed
492
449
ext .depends .extend (headers )
493
450
451
+ def is_extension_enabled (self , ext ):
452
+ upper_name = ext .name .upper ()
453
+ return sysconfig .get_config_var (f"MODULE_{ upper_name } " ) == 1
454
+
494
455
def update_extension_flags (self , ext ):
495
- name = ext .name .upper ()
496
- cflags = sysconfig .get_config_var (f"MODULE_{ name } _CFLAGS" )
456
+ """Update extension flags with module CFLAGS and LDFLAGS
457
+
458
+ Reads MODULE_{name}_CFLAGS and _LDFLAGS
459
+
460
+ Distutils appends extra args to the compiler arguments. Some flags like
461
+ -I must appear earlier. Otherwise the pre-processor picks up files
462
+ from system inclue directories.
463
+ """
464
+ upper_name = ext .name .upper ()
465
+
466
+ # Parse compiler flags (-I, -D, -U, extra)
467
+ cflags = sysconfig .get_config_var (f"MODULE_{ upper_name } _CFLAGS" )
497
468
if cflags :
498
- ext .extra_compile_args .extend (shlex .split (cflags ))
499
- ldflags = sysconfig .get_config_var (f"MODULE_{ name } _LDFLAGS" )
469
+ for token in shlex .split (cflags ):
470
+ switch = token [0 :2 ]
471
+ value = token [2 :]
472
+ if switch == '-I' :
473
+ ext .include_dirs .append (value )
474
+ elif switch == '-D' :
475
+ key , _ , val = value .partition ("=" )
476
+ if not val :
477
+ val = None
478
+ ext .define_macros .append ((key , val ))
479
+ elif switch == '-U' :
480
+ ext .undef_macros .append (value )
481
+ else :
482
+ ext .extra_compile_args .append (token )
483
+
484
+ # Parse linker flags (-L, -l, extra)
485
+ ldflags = sysconfig .get_config_var (f"MODULE_{ upper_name } _LDFLAGS" )
500
486
if ldflags :
501
- ext .extra_link_args .extend (shlex .split (ldflags ))
487
+ for token in shlex .split (ldflags ):
488
+ switch = token [0 :2 ]
489
+ value = token [2 :]
490
+ if switch == '-L' :
491
+ ext .library_dirs .append (value )
492
+ elif switch == '-l' :
493
+ ext .libraries .append (value )
494
+ else :
495
+ ext .extra_link_args .append (token )
496
+
502
497
return ext
503
498
504
499
def handle_configured_extensions (self ):
@@ -1539,32 +1534,20 @@ def detect_expat_elementtree(self):
1539
1534
#
1540
1535
# More information on Expat can be found at www.libexpat.org.
1541
1536
#
1542
- cflags = parse_cflags (sysconfig .get_config_var ("EXPAT_CFLAGS" ))
1543
- include_dirs , define_macros , undef_macros , extra_compile_args = cflags
1544
- # ldflags includes either system libexpat or full path to
1545
- # our static libexpat.a.
1546
- ldflags = parse_ldflags (sysconfig .get_config_var ("EXPAT_LDFLAGS" ))
1547
- library_dirs , libraries , extra_link_args = ldflags
1537
+ expat_depends = []
1538
+ libexpat_a = sysconfig .get_config_var ("LIBEXPAT_A" )
1539
+ if libexpat_a :
1540
+ expat_depends .append (libexpat_a )
1548
1541
1549
1542
self .add (Extension ('pyexpat' ,
1550
- include_dirs = include_dirs ,
1551
- define_macros = define_macros ,
1552
- undef_macros = undef_macros ,
1553
- extra_compile_args = extra_compile_args ,
1554
- library_dirs = library_dirs ,
1555
- libraries = libraries ,
1556
- extra_link_args = extra_link_args ,
1557
- sources = ['pyexpat.c' ]))
1543
+ sources = ['pyexpat.c' ],
1544
+ depends = expat_depends ))
1558
1545
1559
1546
# Fredrik Lundh's cElementTree module. Note that this also
1560
1547
# uses expat (via the CAPI hook in pyexpat).
1561
1548
self .add (Extension ('_elementtree' ,
1562
- include_dirs = include_dirs ,
1563
- define_macros = define_macros ,
1564
- undef_macros = undef_macros ,
1565
- extra_compile_args = extra_compile_args ,
1566
- # no EXPAT_LDFLAGS
1567
- sources = ['_elementtree.c' ]))
1549
+ sources = ['_elementtree.c' ],
1550
+ depends = ['pyexpat.c' , * expat_depends ]))
1568
1551
1569
1552
def detect_multibytecodecs (self ):
1570
1553
# Hye-Shik Chang's CJKCodecs modules.
@@ -2060,24 +2043,12 @@ def detect_decimal(self):
2060
2043
# Stefan Krah's _decimal module
2061
2044
sources = ['_decimal/_decimal.c' ]
2062
2045
2063
- cflags = parse_cflags (sysconfig .get_config_var ("DECIMAL_CFLAGS" ))
2064
- include_dirs , define_macros , undef_macros , extra_compile_args = cflags
2065
- # ldflags includes either system libmpdec or full path to
2066
- # our static libmpdec.a.
2067
- ldflags = parse_ldflags (sysconfig .get_config_var ("DECIMAL_LDFLAGS" ))
2068
- library_dirs , libraries , extra_link_args = ldflags
2069
-
2046
+ define_macros = []
2070
2047
# Uncomment for extra functionality:
2071
2048
#define_macros.append(('EXTRA_FUNCTIONALITY', 1))
2072
2049
self .add (Extension ('_decimal' ,
2073
- include_dirs = include_dirs ,
2074
- define_macros = define_macros ,
2075
- undef_macros = undef_macros ,
2076
- extra_compile_args = extra_compile_args ,
2077
- library_dirs = library_dirs ,
2078
- libraries = libraries ,
2079
- extra_link_args = extra_link_args ,
2080
- sources = sources ))
2050
+ sources = sources ,
2051
+ define_macros = define_macros ))
2081
2052
2082
2053
def detect_openssl_hashlib (self ):
2083
2054
# Detect SSL support for the socket module (via _ssl)
@@ -2146,14 +2117,14 @@ def split_var(name, sep):
2146
2117
'_ssl' ,
2147
2118
['_ssl.c' ],
2148
2119
** openssl_extension_kwargs
2149
- ), update_flags = True
2120
+ )
2150
2121
)
2151
2122
self .add (
2152
2123
Extension (
2153
2124
'_hashlib' ,
2154
2125
['_hashopenssl.c' ],
2155
2126
** openssl_extension_kwargs ,
2156
- ), update_flags = True
2127
+ )
2157
2128
)
2158
2129
2159
2130
def detect_hash_builtins (self ):
0 commit comments