> 3) Another workaround could be to add the '-Werror=unguarded-availability-new' > compiler option for AC_CHECK_DECL's compiler invocations, just like Autoconf > already adds the '-Werror' option as a workaround against the first bug > mentioned above.
Here's a proposed fix for the issue along these lines. Verified by rebuilding the 'minos' tarball on macOS 12.6: $ CC=clang ./configure ... checking for clang options needed to detect all undeclared functions... none needed ... checking for clang options needed to ignore functions from future Darwin versions... -Werror=unguarded-availability-new ... checking whether mkfifoat is declared... no ... $ make $ ./foo $ echo $? 0
>From 4d54a043a646471c18ec2ebdd7d5f6f446187982 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 24 May 2025 12:22:28 +0200 Subject: [PATCH] Fix AC_CHECK_DECL to ignore functions that exist only in future Darwin versions. * lib/autoconf/general.m4 (_AC_COMPILER_CLANG, _AC_FUTURE_DARWIN): New macros. (AC_CHECK_DECL): Require per-language _AC_COMPILER_CLANG. Require per-language _AC_FUTURE_DARWIN. Use $ac_c_future_darwin_options alongside with $ac_c_undeclared_builtin_options. * NEWS: Mention the fix. --- NEWS | 3 ++ lib/autoconf/general.m4 | 68 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 1e4e513e..8c323887 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,9 @@ GNU Autoconf NEWS - User visible changes. ** Notable bug fixes +*** AC_CHECK_DECL and AC_CHECK_DECLS will, on macOS, now report "no" for + functions that are declared as existing in future macOS versions only. + *** AC_DEFINE_UNQUOTED no longer mishandles double-quotes inside $(...) and ${...}. diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index 7eae5bd2..af3b6d05 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -3093,6 +3093,28 @@ AC_DEFUN([AC_CHECK_FILES], ## Checking for declared symbols. ## ## ------------------------------- ## +# _AC_COMPILER_CLANG +# ------------------ +# Set ac_cv_[]_AC_LANG_ABBREV[]_is_clang to yes or no, depending on whether +# the compiler is clang. +AC_DEFUN([_AC_COMPILER_CLANG], +[AC_CACHE_CHECK([whether $[]_AC_CC is clang], + [ac_cv_[]_AC_LANG_ABBREV[]_is_clang], + [dnl Use _AC_COMPILE_IFELSE instead of AC_EGREP_CPP, to avoid error + dnl "circular dependency of AC_LANG_COMPILER(C)" if AC_PROG_CC has + dnl not yet been invoked. + _AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #ifdef __clang__ + barfbarf + #endif + ]],[[]]) + ], + [ac_cv_[]_AC_LANG_ABBREV[]_is_clang=no], + [ac_cv_[]_AC_LANG_ABBREV[]_is_clang=yes]) + ]) +]) + # _AC_UNDECLARED_BUILTIN # ---------------------- # Set ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options to any options @@ -3145,6 +3167,40 @@ extern void ac_decl (int, char *); [ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options=$ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options]) ]) +# _AC_FUTURE_DARWIN +# ----------------- +# Set ac_[]_AC_LANG_ABBREV[]_future_darwin_options to any options needed +# to make the compiler issue a hard error, not a warning, when a function +# is used that is declared in the .h files but that is introduced in a +# version *after* the current minimum OS version. +# These options should not cause any other unrelated warnings to become +# errors. +AC_DEFUN([_AC_FUTURE_DARWIN], +[AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK( + [for $[]_AC_CC options needed to ignore functions from future Darwin versions], + [ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options], + [ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options='none needed' + dnl This is only needed on macOS. + AS_CASE([$host_os], + [darwin*], + [if test $ac_cv_[]_AC_LANG_ABBREV[]_is_clang = yes; then + dnl Test whether the compiler supports the option + dnl '-Werror=unguarded-availability-new'. + ac_compile_saved="$ac_compile" + ac_compile="$ac_compile -Werror=unguarded-availability-new" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])], + [ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options='-Werror=unguarded-availability-new']) + ac_compile="$ac_compile_saved" + fi + ]) + ]) + AS_CASE([$ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options], + ['none needed'], + [ac_[]_AC_LANG_ABBREV[]_future_darwin_options=''], + [ac_[]_AC_LANG_ABBREV[]_future_darwin_options=$ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options]) +]) + # _AC_CHECK_DECL_BODY # ------------------- # Shell function body for AC_CHECK_DECL. @@ -3191,14 +3247,24 @@ AC_DEFUN([AC_CHECK_DECL], [Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR accordingly. Pass EXTRA-OPTIONS to the compiler, using FLAG-VAR.])], [_$0_BODY])]dnl +dnl Initialize each $ac_cv_[]_AC_LANG_ABBREV[]_is_clang once. +[AC_DEFUN([_AC_COMPILER_CLANG_]_AC_LANG_ABBREV, + [_AC_COMPILER_CLANG])]dnl +[AC_REQUIRE([_AC_COMPILER_CLANG_]_AC_LANG_ABBREV)]dnl dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options once. [AC_DEFUN([_AC_UNDECLARED_BUILTIN_]_AC_LANG_ABBREV, [_AC_UNDECLARED_BUILTIN])]dnl [AC_REQUIRE([_AC_UNDECLARED_BUILTIN_]_AC_LANG_ABBREV)]dnl +dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_future_darwin_options once. +[AC_DEFUN([_AC_FUTURE_DARWIN_]_AC_LANG_ABBREV, + [_AC_FUTURE_DARWIN])]dnl +[AC_REQUIRE([_AC_FUTURE_DARWIN_]_AC_LANG_ABBREV)]dnl [AS_VAR_PUSHDEF([ac_Symbol], [ac_cv_have_decl_$1])]dnl [ac_fn_check_decl ]dnl ["$LINENO" "$1" "ac_Symbol" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])" ]dnl -["$ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options" "_AC_LANG_PREFIX[]FLAGS"] +["$ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options]dnl +[$ac_[]_AC_LANG_ABBREV[]_future_darwin_options" ]dnl +["_AC_LANG_PREFIX[]FLAGS"] [AS_VAR_IF([ac_Symbol], [yes], [$2], [$3])]dnl [AS_VAR_POPDEF([ac_Symbol])]dnl )# AC_CHECK_DECL -- 2.43.0