@@ -190,6 +190,48 @@ def __repr__(self) -> str:
190190]
191191
192192
193+ def _load_config_site () -> None :
194+ """Load CONFIG_SITE file, if set.
195+
196+ CONFIG_SITE is a shell script containing simple VAR=VALUE assignments
197+ used to pre-seed cache variables for cross-compilation. Only lines
198+ matching ``NAME=VALUE`` are processed; comments and blank lines are
199+ skipped. Values already present in ``os.environ`` (e.g. from
200+ command-line ``VAR=VALUE`` arguments) or already set on ``vars`` are
201+ NOT overridden.
202+
203+ ``yes``/``no`` values are converted to ``True``/``False`` via
204+ ``_cache_deserialize`` so that truthiness checks in conf_*.py work
205+ the same way as autoconf's ``test "x$var" = xyes``.
206+ """
207+ config_site = os .environ .get ("CONFIG_SITE" , "" )
208+ if not config_site or not os .path .isfile (config_site ):
209+ return
210+ with open (config_site ) as f :
211+ for line in f :
212+ line = line .strip ()
213+ if not line or line .startswith ("#" ):
214+ continue
215+ m = re .match (r"^([A-Za-z_][A-Za-z0-9_]*)=(.*)" , line )
216+ if not m :
217+ continue
218+ name , value = m .group (1 ), m .group (2 )
219+ # Strip surrounding quotes (single or double)
220+ if len (value ) >= 2 and value [0 ] == value [- 1 ] and value [0 ] in ("'" , '"' ):
221+ value = value [1 :- 1 ]
222+ # Command-line VAR=VALUE (already in os.environ) takes precedence
223+ if name not in os .environ and not vars .is_set (name ):
224+ converted = _cache_deserialize (value )
225+ setattr (vars , name , converted )
226+ # Also populate the cache dict so that check_func(),
227+ # check_header(), etc. honour the pre-seeded value and
228+ # skip the compile/link test (matching autoconf behaviour
229+ # where CONFIG_SITE sets ac_cv_* shell variables that
230+ # AC_CHECK_FUNC reads as cached results).
231+ if name .startswith ("ac_cv_" ):
232+ cache [name ] = converted
233+
234+
193235def init_args () -> None :
194236 """Parse sys.argv early: handle VAR=VALUE, --help, --version, behaviour flags,
195237 and standard directory arguments. Must be called before configure parts run.
@@ -300,6 +342,12 @@ def init_args() -> None:
300342
301343 sys .argv [:] = new_argv
302344
345+ # Load CONFIG_SITE file if set (autoconf compatibility).
346+ # CONFIG_SITE is a shell script with simple VAR=VALUE assignments that
347+ # pre-seed cache variables for cross-compilation. Command-line VAR=VALUE
348+ # arguments (already placed into os.environ above) take precedence.
349+ _load_config_site ()
350+
303351 # Load cache file if requested
304352 if cache_file :
305353 if os .path .exists (cache_file ):
0 commit comments