@@ -75,13 +75,19 @@ def export(
7575 """Mark a variable for Makefile substitution (AC_SUBST).
7676
7777 If *value* is given, assigns it to this Vars instance first.
78- Otherwise looks up the value from this Vars instance.
78+ Otherwise looks up the value from this Vars instance (including
79+ environment variables via ``__getattr__``).
7980 The name is recorded in ``self._exports``.
8081 """
8182 self ._exports .add (name )
8283 if value is not self ._SENTINEL :
8384 setattr (self , name , value )
8485 val = self .__dict__ .get (name )
86+ if val is None :
87+ # Fall back to environment variable (mirrors __getattr__),
88+ # matching autoconf where AC_SUBST reads shell variables
89+ # which include inherited environment.
90+ val = os .environ .get (name , None )
8591 if val is not None :
8692 substs [name ] = (
8793 format_yn (val ) if isinstance (val , bool ) else str (val )
@@ -1000,12 +1006,10 @@ def _populate_module_substs() -> None:
10001006 na = info .get ("na" , False )
10011007 if na :
10021008 state = "n/a"
1003- elif not supported and enabled :
1004- state = "missing"
1005- elif not supported :
1006- state = "n/a"
10071009 elif not enabled :
10081010 state = "disabled"
1011+ elif not supported :
1012+ state = "missing"
10091013 else :
10101014 state = "yes"
10111015 # _TRUE="" means "build this module"; only "yes" state builds
@@ -2343,10 +2347,15 @@ def _try(boolean_expr: str) -> bool:
23432347
23442348
23452349def _header_name_to_define (header : str ) -> str :
2346- """Convert 'sys/types.h' → 'HAVE_SYS_TYPES_H'."""
2347- return "HAVE_" + header .upper ().replace ("/" , "_" ).replace (
2348- "." , "_"
2349- ).replace ("-" , "_" )
2350+ """Convert 'sys/types.h' → 'HAVE_SYS_TYPES_H'.
2351+
2352+ Dashes are mapped to '_DASH_' to match autoconf's convention where
2353+ 'gdbm-ndbm.h' produces HAVE_GDBM_DASH_NDBM_H (distinct from
2354+ 'gdbm/ndbm.h' → HAVE_GDBM_NDBM_H).
2355+ """
2356+ return "HAVE_" + header .upper ().replace ("-" , "_DASH_" ).replace (
2357+ "/" , "_"
2358+ ).replace ("." , "_" )
23502359
23512360
23522361def _ac_includes_default () -> str :
@@ -2399,9 +2408,9 @@ def check_header(
23992408 f"check_header: invalid header name { header !r} "
24002409 f"(must match [a-z0-9][a-z0-9_./+-]*)"
24012410 )
2402- cache_key = "ac_cv_header_" + header .replace ("/ " , "_ " ).replace (
2403- ". " , "_"
2404- ).replace ("- " , "_" )
2411+ cache_key = "ac_cv_header_" + header .replace ("- " , "_dash_ " ).replace (
2412+ "/ " , "_"
2413+ ).replace (". " , "_" )
24052414 define_name = _header_name_to_define (header )
24062415 # Print "checking for <header>..." unless the caller already started one.
24072416 own_checking = not _result_pending
@@ -2606,8 +2615,10 @@ def check_sizeof(
26062615 if output_str .strip ().isdigit ():
26072616 size = int (output_str .strip ())
26082617 if size is None :
2609- # Cross-compiling or run failed: compile-time binary search
2610- inc = "#include <stddef.h>\n #include <stdint.h>\n " + extra_includes
2618+ # Cross-compiling or run failed: compile-time binary search.
2619+ # Use AC_INCLUDES_DEFAULT (which includes stdio.h etc.) so that
2620+ # types like fpos_t are visible, matching autoconf behaviour.
2621+ inc = _ac_includes_default () + extra_includes
26112622 size = _compute_int (f"(long int)(sizeof({ type_ } ))" , inc )
26122623 if size is None :
26132624 size = default if default is not None else 0
@@ -3173,7 +3184,10 @@ def replace_funcs(funcs: list[str]) -> None:
31733184 missing = substs .get ("LIBOBJS" , "" ).split ()
31743185 for func in funcs :
31753186 if not check_func (func ):
3176- missing .append (f"{ func } .o" )
3187+ # Match autoconf's final LIBOBJS fixup: prepend ${LIBOBJDIR}
3188+ # and insert $U before the extension so Makefile.pre.in can
3189+ # locate the replacement source under Python/.
3190+ missing .append (f"${{LIBOBJDIR}}{ func } $U.o" )
31773191 substs ["LIBOBJS" ] = " " .join (missing )
31783192
31793193
0 commit comments