@@ -1396,6 +1396,47 @@ def result(value: Any) -> None:
13961396checking_fn = checking # alias used by link_check to avoid param shadowing
13971397
13981398
1399+ def cache_check (description : str , cache_var : str ) -> Any :
1400+ """AC_CACHE_CHECK — check the cache before running a probe.
1401+
1402+ Prints "checking <description>..." and looks up *cache_var* in the
1403+ cache (which may have been pre-seeded from CONFIG_SITE).
1404+
1405+ Returns the cached value on a hit (also prints "(cached) <value>")
1406+ or None on a miss. The caller is responsible for running the actual
1407+ probe on a miss and storing the result with
1408+ ``cache_store(cache_var, value)`` followed by ``result(value)``.
1409+
1410+ Typical usage::
1411+
1412+ val = pyconf.cache_check("getaddrinfo bug", "ac_cv_buggy_getaddrinfo")
1413+ if val is None:
1414+ val = <run probe>
1415+ pyconf.cache_store("ac_cv_buggy_getaddrinfo", val)
1416+ pyconf.result(val)
1417+ """
1418+ checking (description )
1419+ cached = cache .get (cache_var )
1420+ if cached is not None :
1421+ result (f"(cached) { _format_result (cached )} " )
1422+ return cached
1423+ return None
1424+
1425+
1426+ def cache_store (cache_var : str , value : Any ) -> None :
1427+ """Store *value* in the cache under *cache_var*."""
1428+ cache [cache_var ] = value
1429+
1430+
1431+ def _format_result (value : Any ) -> str :
1432+ """Format a cache value for display (True→'yes', False→'no')."""
1433+ if value is True :
1434+ return "yes"
1435+ if value is False :
1436+ return "no"
1437+ return str (value )
1438+
1439+
13991440def _flush_result (value : Any ) -> None :
14001441 """Emit result(value) if a checking() is pending, otherwise do nothing.
14011442
@@ -1763,7 +1804,14 @@ def _identify_compiler() -> None:
17631804 except (subprocess .CalledProcessError , OSError ):
17641805 ver = ""
17651806
1766- if "clang" in ver .lower ():
1807+ # Detect emcc (Emscripten) before clang — emcc's --version output
1808+ # contains "clang" but autoconf identifies it as "emcc" via the
1809+ # __EMSCRIPTEN__ preprocessor macro.
1810+ if cc_basename == "emcc" or "emscripten" in ver .lower ():
1811+ ac_cv_cc_name = "emcc"
1812+ ac_cv_gcc_compat = True
1813+ GCC = True # emcc is gcc-compatible
1814+ elif "clang" in ver .lower ():
17671815 ac_cv_cc_name = "clang"
17681816 ac_cv_gcc_compat = True
17691817 GCC = True # clang is gcc-compatible
@@ -3207,7 +3255,20 @@ def pkg_check_modules(pkg_var: str, module_spec: str) -> Any:
32073255 Returns a SimpleNamespace with .cflags and .libs on success, None if
32083256 pkg-config is unavailable or the module is not found.
32093257 Sets <PKG_VAR>_CFLAGS and <PKG_VAR>_LIBS in pyconf.substs.
3258+
3259+ Like autoconf's PKG_CHECK_MODULES, if the CFLAGS/LIBS variables are
3260+ already set (e.g. by check_emscripten_port or the user), the pkg-config
3261+ query is skipped and the existing values are used.
32103262 """
3263+ cflags_name = f"{ pkg_var } _CFLAGS"
3264+ libs_name = f"{ pkg_var } _LIBS"
3265+ # If variables are already set (by user, environment, or emscripten port),
3266+ # honour them without querying pkg-config — matches autoconf behaviour.
3267+ existing_cflags = getattr (vars , cflags_name , "" )
3268+ existing_libs = getattr (vars , libs_name , "" )
3269+ if existing_cflags or existing_libs :
3270+ ns = types .SimpleNamespace (cflags = existing_cflags , libs = existing_libs )
3271+ return ns
32113272 pkg_config = shutil .which ("pkg-config" )
32123273 if not pkg_config :
32133274 return None
@@ -3224,10 +3285,10 @@ def pkg_check_modules(pkg_var: str, module_spec: str) -> Any:
32243285 ).strip ()
32253286 except subprocess .CalledProcessError :
32263287 return None
3227- substs [f" { pkg_var } _CFLAGS" ] = cflags
3228- substs [f" { pkg_var } _LIBS" ] = libs
3229- setattr (vars , f" { pkg_var } _CFLAGS" , cflags )
3230- setattr (vars , f" { pkg_var } _LIBS" , libs )
3288+ substs [cflags_name ] = cflags
3289+ substs [libs_name ] = libs
3290+ setattr (vars , cflags_name , cflags )
3291+ setattr (vars , libs_name , libs )
32313292 ns = types .SimpleNamespace (cflags = cflags , libs = libs )
32323293 return ns
32333294
0 commit comments