@@ -446,8 +446,6 @@ def derive_setup_local(
446446    # agrees fully with the distribution's knowledge of extensions. So we can 
447447    # treat our metadata as canonical. 
448448
449-     RE_DEFINE  =  re .compile (rb"-D[^=]+=[^\s]+" )
450- 
451449    # Translate our YAML metadata into Setup lines. 
452450
453451    section_lines  =  {
@@ -456,12 +454,6 @@ def derive_setup_local(
456454        "static" : [],
457455    }
458456
459-     # makesetup parses lines with = as extra config options. There appears 
460-     # to be no easy way to define e.g. -Dfoo=bar in Setup.local. We hack 
461-     # around this by producing a Makefile supplement that overrides the build 
462-     # rules for certain targets to include these missing values. 
463-     extra_cflags  =  {}
464- 
465457    enabled_extensions  =  {}
466458
467459    for  name , info  in  sorted (extension_modules .items ()):
@@ -520,6 +512,10 @@ def derive_setup_local(
520512
521513        line  =  name 
522514
515+         # Keep track of defines separately to work around makesetup's treatment of = signs 
516+         defines  =  set ()
517+         def_name  =  name .upper () +  "DEFS" 
518+ 
523519        for  source  in  info .get ("sources" , []):
524520            line  +=  " %s"  %  source 
525521
@@ -553,7 +549,7 @@ def derive_setup_local(
553549                    line  +=  f" { source }  " 
554550
555551        for  define  in  info .get ("defines" , []):
556-             line   +=   f"  -D{ define }  "
552+             defines . add ( f" -D{ define }  ") 
557553
558554        for  entry  in  info .get ("defines-conditional" , []):
559555            if  targets  :=  entry .get ("targets" , []):
@@ -569,7 +565,10 @@ def derive_setup_local(
569565            )
570566
571567            if  target_match  and  (python_min_match  and  python_max_match ):
572-                 line  +=  f" -D{ entry ['define' ]}  " 
568+                 defines .add (f"-D{ entry ['define' ]}  " )
569+ 
570+         if  defines :
571+             line  +=  f" $({ def_name }  )" 
573572
574573        for  path  in  info .get ("includes" , []):
575574            line  +=  f" -I{ path }  " 
@@ -638,23 +637,15 @@ def derive_setup_local(
638637        if  not  parsed :
639638            raise  Exception ("we should always parse a setup line we generated" )
640639
641-         # makesetup parses lines with = as extra config options. There appears 
642-         # to be no easy way to define e.g. -Dfoo=bar in Setup.local. We hack 
643-         # around this by detecting the syntax we'd like to support and move the 
644-         # variable defines to a Makefile supplement that overrides variables for 
645-         # specific targets. 
646-         for  m  in  RE_DEFINE .finditer (parsed ["line" ]):
647-             for  obj_path  in  sorted (parsed ["posix_obj_paths" ]):
648-                 extra_cflags .setdefault (bytes (obj_path ), []).append (m .group (0 ))
649- 
650-         line  =  RE_DEFINE .sub (b"" , line )
651- 
652640        if  b"="  in  line :
653641            raise  Exception (
654642                "= appears in EXTRA_MODULES line; will confuse " 
655643                "makesetup: %s"  %  line .decode ("utf-8" )
656644            )
657645
646+         if  defines :
647+             defines_str  =  " " .join (sorted (defines ))
648+             section_lines [section ].append (f"{ def_name }  ={ defines_str }  " .encode ("ascii" ))
658649        section_lines [section ].append (line )
659650        enabled_extensions [name ]["setup_line" ] =  line 
660651
@@ -669,18 +660,7 @@ def derive_setup_local(
669660
670661    dest_lines .append (b"" )
671662
672-     make_lines  =  []
673- 
674-     for  target  in  sorted (extra_cflags ):
675-         make_lines .append (
676-             b"%s: PY_STDMODULE_CFLAGS += %s"  %  (target , b" " .join (extra_cflags [target ]))
677-         )
678- 
679-     return  {
680-         "extensions" : enabled_extensions ,
681-         "setup_local" : b"\n " .join (dest_lines ),
682-         "make_data" : b"\n " .join (make_lines ),
683-     }
663+     return  {"extensions" : enabled_extensions , "setup_local" : b"\n " .join (dest_lines )}
684664
685665
686666RE_INITTAB_ENTRY  =  re .compile (r'\{"([^"]+)", ([^\}]+)\},' )
0 commit comments