@@ -217,7 +217,11 @@ def _load_config_site() -> None:
217217 continue
218218 name , value = m .group (1 ), m .group (2 )
219219 # Strip surrounding quotes (single or double)
220- if len (value ) >= 2 and value [0 ] == value [- 1 ] and value [0 ] in ("'" , '"' ):
220+ if (
221+ len (value ) >= 2
222+ and value [0 ] == value [- 1 ]
223+ and value [0 ] in ("'" , '"' )
224+ ):
221225 value = value [1 :- 1 ]
222226 # Command-line VAR=VALUE (already in os.environ) takes precedence
223227 if name not in os .environ and not vars .is_set (name ):
@@ -1588,7 +1592,7 @@ def _canonicalize(triplet: str) -> str:
15881592 host_parts = host .split ("-" , 2 )
15891593 host_cpu = host_parts [0 ]
15901594 if build_arg :
1591- cross_compiling = ( host != build )
1595+ cross_compiling = host != build
15921596 else :
15931597 # autoconf sets "maybe" when --host is given without --build
15941598 cross_compiling = "maybe" if host != build else False
@@ -2280,6 +2284,7 @@ def _compute_int(expr: str, includes: str = "") -> int | None:
22802284
22812285 Returns the integer value, or None if it could not be determined.
22822286 """
2287+
22832288 def _try (boolean_expr : str ) -> bool :
22842289 src = (
22852290 f"{ includes } \n "
@@ -2602,10 +2607,7 @@ def check_sizeof(
26022607 size = int (output_str .strip ())
26032608 if size is None :
26042609 # Cross-compiling or run failed: compile-time binary search
2605- inc = (
2606- "#include <stddef.h>\n "
2607- "#include <stdint.h>\n " + extra_includes
2608- )
2610+ inc = "#include <stddef.h>\n #include <stdint.h>\n " + extra_includes
26092611 size = _compute_int (f"(long int)(sizeof({ type_ } ))" , inc )
26102612 if size is None :
26112613 size = default if default is not None else 0
@@ -2658,10 +2660,7 @@ def check_alignof(type_: str) -> int:
26582660 # Cross-compiling or run failed: compile-time binary search using
26592661 # offsetof(struct{char c; TYPE x;}, x), matching autoconf.
26602662 inc = "#include <stddef.h>\n "
2661- expr = (
2662- f"(long int)(offsetof("
2663- f"struct {{ char c; { type_ } x; }}, x))"
2664- )
2663+ expr = f"(long int)(offsetof(struct {{ char c; { type_ } x; }}, x))"
26652664 alignment = _compute_int (expr , inc )
26662665 if alignment is None :
26672666 alignment = 0
@@ -3044,10 +3043,12 @@ def check_decl(
30443043 extra_includes : list [str ] | None = None ,
30453044 on_found : Any = None ,
30463045 on_notfound : Any = None ,
3046+ define_name : str | None = None ,
30473047) -> bool :
30483048 """AC_CHECK_DECL — check if declaration/macro *decl* is available.
30493049
30503050 *includes* / *extra_includes*: headers to include in the test.
3051+ *define_name*: if given, define this macro to 1 when found (0 when not).
30513052 Calls *on_found()* or *on_notfound()* callbacks. Returns bool.
30523053 """
30533054 if not _RE_DECL_NAME .match (decl ):
@@ -3057,14 +3058,25 @@ def check_decl(
30573058 )
30583059 all_includes = list (includes or []) + list (extra_includes or [])
30593060 inc_lines = "" .join (f"#include <{ h } >\n " for h in all_includes )
3060- src = f"{ inc_lines } \n int main(void) {{\n (void){ decl } ;\n return 0;\n }}\n "
3061- found = _compile_test (src )
3062- # AC_CHECK_DECL always writes HAVE_DECL_<name> as 0 or 1
3063- define (
3064- "HAVE_DECL_" + decl .upper (),
3065- 1 if found else 0 ,
3066- f"Define to 1 if you have the declaration of `{ decl } '." ,
3061+ # Use #ifndef guard so macros (e.g. NetBSD's dirfd) are detected too.
3062+ # If decl is a macro, the #ifndef body is skipped and compilation
3063+ # succeeds. If it's a real declaration, (void)decl compiles.
3064+ src = (
3065+ f"{ inc_lines } \n "
3066+ f"int main(void) {{\n "
3067+ f"#ifndef { decl } \n "
3068+ f" (void){ decl } ;\n "
3069+ f"#endif\n "
3070+ f" return 0;\n "
3071+ f"}}\n "
30673072 )
3073+ found = _compile_test (src )
3074+ if define_name :
3075+ define (
3076+ define_name ,
3077+ 1 if found else 0 ,
3078+ f"Define to 1 if you have the declaration of `{ decl } '." ,
3079+ )
30683080 if found and callable (on_found ):
30693081 on_found ()
30703082 elif not found and callable (on_notfound ):
@@ -3084,11 +3096,11 @@ def check_decls(
30843096 names = [decls ] if isinstance (decls , str ) else decls
30853097 all_includes = list (includes or []) + list (extra_includes or [])
30863098 for d in names :
3087- found = check_decl ( d , includes = all_includes )
3088- define (
3089- "HAVE_DECL_" + d . upper () ,
3090- 1 if found else 0 ,
3091- f"Define to 1 if you have the declaration of ` { d } '." ,
3099+ # AC_CHECK_DECLS defines HAVE_DECL_<NAME> as 1 or 0 (always defined )
3100+ check_decl (
3101+ d ,
3102+ includes = all_includes ,
3103+ define_name = "HAVE_DECL_" + d . upper () ,
30923104 )
30933105
30943106
0 commit comments