summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-02-10 21:32:11 +0100
committerBruno Haible <bruno@clisp.org>2023-02-10 21:32:11 +0100
commit03257cffa06276be7e7b12180245312e3094b342 (patch)
tree3a790a5365380293c3445e369c87ac1fd35fd447 /m4
parent8b7951189567916bd94cdf46832f49e49e3a9e04 (diff)
downloadgnulib-03257cffa06276be7e7b12180245312e3094b342.tar.gz
Fix code duplication in last commit.
* m4/gnulib-common.m4 (gl_CHECK_FUNCS_DEFAULT_CASE, gl_CHECK_FUNCS_CASE_FOR_ANDROID, gl_CHECK_FUNCS_CASE_FOR_MACOS, gl_CHECK_FUNCS_SET_RESULTS): New macros, extracted from gl_CHECK_FUNCS_ANDROID, gl_CHECK_FUNCS_MACOS, gl_CHECK_FUNCS_ANDROID_MACOS. (gl_CHECK_FUNCS_ANDROID, gl_CHECK_FUNCS_MACOS, gl_CHECK_FUNCS_ANDROID_MACOS): Use them.
Diffstat (limited to 'm4')
-rw-r--r--m4/gnulib-common.m4275
1 files changed, 117 insertions, 158 deletions
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index ff2ea3d4f6..c84a2afd9c 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1095,6 +1095,113 @@ AC_DEFUN([gl_CONDITIONAL_HEADER],
m4_popdef([gl_header_name])
])
+dnl Preparations for gl_CHECK_FUNCS_MACOS.
+AC_DEFUN([gl_PREPARE_CHECK_FUNCS_MACOS],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([gl_COMPILER_CLANG])
+ AC_CACHE_CHECK([for compiler option needed when checking for future declarations],
+ [gl_cv_compiler_check_future_option],
+ [case "$host_os" in
+ dnl This is only needed on macOS.
+ darwin*)
+ if test $gl_cv_compiler_clang = yes; then
+ dnl Test whether the compiler supports the option
+ dnl '-Werror=unguarded-availability-new'.
+ save_ac_compile="$ac_compile"
+ ac_compile="$ac_compile -Werror=unguarded-availability-new"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
+ [gl_cv_compiler_check_future_option='-Werror=unguarded-availability-new'],
+ [gl_cv_compiler_check_future_option=none])
+ ac_compile="$save_ac_compile"
+ else
+ gl_cv_compiler_check_future_option=none
+ fi
+ ;;
+ *) gl_cv_compiler_check_future_option=none ;;
+ esac
+ ])
+])
+
+dnl Pieces of the expansion of
+dnl gl_CHECK_FUNCS_ANDROID
+dnl gl_CHECK_FUNCS_MACOS
+dnl gl_CHECK_FUNCS_ANDROID_MACOS
+
+AC_DEFUN([gl_CHECK_FUNCS_DEFAULT_CASE],
+[
+ *)
+ AC_CHECK_FUNC([$1])
+ [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
+ ;;
+])
+
+AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_ANDROID],
+[
+ linux*-android*)
+ AC_CHECK_DECL([$1], , , [$2])
+ if test $[ac_cv_have_decl_][$1] = yes; then
+ AC_CHECK_FUNC([[$1]])
+ if test $[ac_cv_func_][$1] = yes; then
+ [gl_cv_onwards_func_][$1]=yes
+ else
+ dnl The function is declared but does not exist. This should not
+ dnl happen normally. But anyway, we know that a future version
+ dnl of Android will have the function.
+ [gl_cv_onwards_func_][$1]='future OS version'
+ fi
+ else
+ [gl_cv_onwards_func_][$1]='future OS version'
+ fi
+ ;;
+])
+
+AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_MACOS],
+[
+ darwin*)
+ if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
+ dnl Use a compile test, not a link test.
+ save_ac_compile="$ac_compile"
+ ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
+ save_ac_compile_for_check_decl="$ac_compile_for_check_decl"
+ ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
+ unset [ac_cv_have_decl_][$1]
+ AC_CHECK_DECL([$1], , , [$2])
+ ac_compile="$save_ac_compile"
+ ac_compile_for_check_decl="$save_ac_compile_for_check_decl"
+ [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
+ if test $[ac_cv_func_][$1] = yes; then
+ [gl_cv_onwards_func_][$1]=yes
+ else
+ unset [ac_cv_have_decl_][$1]
+ AC_CHECK_DECL([$1], , , [$2])
+ if test $[ac_cv_have_decl_][$1] = yes; then
+ [gl_cv_onwards_func_][$1]='future OS version'
+ else
+ [gl_cv_onwards_func_][$1]=no
+ fi
+ fi
+ else
+ AC_CHECK_FUNC([$1])
+ [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
+ fi
+ ;;
+])
+
+AC_DEFUN([gl_CHECK_FUNCS_SET_RESULTS],
+[
+ case "$[gl_cv_onwards_func_][$1]" in
+ future*) [ac_cv_func_][$1]=no ;;
+ *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
+ esac
+ if test $[ac_cv_func_][$1] = yes; then
+ AC_DEFINE([HAVE_]m4_translit([[$1]],
+ [abcdefghijklmnopqrstuvwxyz],
+ [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
+ [1], [Define to 1 if you have the `$1' function.])
+ fi
+])
+
dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
dnl on Android.
@@ -1137,67 +1244,12 @@ AC_DEFUN([gl_CHECK_FUNCS_ANDROID],
[[gl_cv_onwards_func_][$1]],
[gl_SILENT([
case "$host_os" in
- linux*-android*)
- AC_CHECK_DECL([$1], , , [$2])
- if test $[ac_cv_have_decl_][$1] = yes; then
- AC_CHECK_FUNC([[$1]])
- if test $[ac_cv_func_][$1] = yes; then
- [gl_cv_onwards_func_][$1]=yes
- else
- dnl The function is declared but does not exist. This should not
- dnl happen normally. But anyway, we know that a future version
- dnl of Android will have the function.
- [gl_cv_onwards_func_][$1]='future OS version'
- fi
- else
- [gl_cv_onwards_func_][$1]='future OS version'
- fi
- ;;
- *)
- AC_CHECK_FUNC([$1])
- [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
- ;;
+ gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
+ gl_CHECK_FUNCS_DEFAULT_CASE([$1])
esac
])
])
- case "$[gl_cv_onwards_func_][$1]" in
- future*) [ac_cv_func_][$1]=no ;;
- *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
- esac
- if test $[ac_cv_func_][$1] = yes; then
- AC_DEFINE([HAVE_]m4_translit([[$1]],
- [abcdefghijklmnopqrstuvwxyz],
- [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
- [1], [Define to 1 if you have the `$1' function.])
- fi
-])
-
-dnl Preparations for gl_CHECK_FUNCS_MACOS.
-AC_DEFUN([gl_PREPARE_CHECK_FUNCS_MACOS],
-[
- AC_REQUIRE([AC_CANONICAL_HOST])
- AC_REQUIRE([gl_COMPILER_CLANG])
- AC_CACHE_CHECK([for compiler option needed when checking for future declarations],
- [gl_cv_compiler_check_future_option],
- [case "$host_os" in
- dnl This is only needed on macOS.
- darwin*)
- if test $gl_cv_compiler_clang = yes; then
- dnl Test whether the compiler supports the option
- dnl '-Werror=unguarded-availability-new'.
- save_ac_compile="$ac_compile"
- ac_compile="$ac_compile -Werror=unguarded-availability-new"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
- [gl_cv_compiler_check_future_option='-Werror=unguarded-availability-new'],
- [gl_cv_compiler_check_future_option=none])
- ac_compile="$save_ac_compile"
- else
- gl_cv_compiler_check_future_option=none
- fi
- ;;
- *) gl_cv_compiler_check_future_option=none ;;
- esac
- ])
+ gl_CHECK_FUNCS_SET_RESULTS([$1])
])
dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
@@ -1246,51 +1298,12 @@ AC_DEFUN([gl_CHECK_FUNCS_MACOS],
[[gl_cv_onwards_func_][$1]],
[gl_SILENT([
case "$host_os" in
- darwin*)
- if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
- dnl Use a compile test, not a link test.
- save_ac_compile="$ac_compile"
- ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
- save_ac_compile_for_check_decl="$ac_compile_for_check_decl"
- ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
- unset [ac_cv_have_decl_][$1]
- AC_CHECK_DECL([$1], , , [$2])
- ac_compile="$save_ac_compile"
- ac_compile_for_check_decl="$save_ac_compile_for_check_decl"
- [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
- if test $[ac_cv_func_][$1] = yes; then
- [gl_cv_onwards_func_][$1]=yes
- else
- unset [ac_cv_have_decl_][$1]
- AC_CHECK_DECL([$1], , , [$2])
- if test $[ac_cv_have_decl_][$1] = yes; then
- [gl_cv_onwards_func_][$1]='future OS version'
- else
- [gl_cv_onwards_func_][$1]=no
- fi
- fi
- else
- AC_CHECK_FUNC([$1])
- [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
- fi
- ;;
- *)
- AC_CHECK_FUNC([$1])
- [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
- ;;
+ gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
+ gl_CHECK_FUNCS_DEFAULT_CASE([$1])
esac
])
])
- case "$[gl_cv_onwards_func_][$1]" in
- future*) [ac_cv_func_][$1]=no ;;
- *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
- esac
- if test $[ac_cv_func_][$1] = yes; then
- AC_DEFINE([HAVE_]m4_translit([[$1]],
- [abcdefghijklmnopqrstuvwxyz],
- [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
- [1], [Define to 1 if you have the `$1' function.])
- fi
+ gl_CHECK_FUNCS_SET_RESULTS([$1])
])
dnl gl_CHECK_FUNCS_ANDROID_MACOS([func], [[#include <foo.h>]])
@@ -1305,67 +1318,13 @@ AC_DEFUN([gl_CHECK_FUNCS_ANDROID_MACOS],
[[gl_cv_onwards_func_][$1]],
[gl_SILENT([
case "$host_os" in
- linux*-android*)
- AC_CHECK_DECL([$1], , , [$2])
- if test $[ac_cv_have_decl_][$1] = yes; then
- AC_CHECK_FUNC([[$1]])
- if test $[ac_cv_func_][$1] = yes; then
- [gl_cv_onwards_func_][$1]=yes
- else
- dnl The function is declared but does not exist. This should not
- dnl happen normally. But anyway, we know that a future version
- dnl of Android will have the function.
- [gl_cv_onwards_func_][$1]='future OS version'
- fi
- else
- [gl_cv_onwards_func_][$1]='future OS version'
- fi
- ;;
- darwin*)
- if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
- dnl Use a compile test, not a link test.
- save_ac_compile="$ac_compile"
- ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
- save_ac_compile_for_check_decl="$ac_compile_for_check_decl"
- ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
- unset [ac_cv_have_decl_][$1]
- AC_CHECK_DECL([$1], , , [$2])
- ac_compile="$save_ac_compile"
- ac_compile_for_check_decl="$save_ac_compile_for_check_decl"
- [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
- if test $[ac_cv_func_][$1] = yes; then
- [gl_cv_onwards_func_][$1]=yes
- else
- unset [ac_cv_have_decl_][$1]
- AC_CHECK_DECL([$1], , , [$2])
- if test $[ac_cv_have_decl_][$1] = yes; then
- [gl_cv_onwards_func_][$1]='future OS version'
- else
- [gl_cv_onwards_func_][$1]=no
- fi
- fi
- else
- AC_CHECK_FUNC([$1])
- [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
- fi
- ;;
- *)
- AC_CHECK_FUNC([$1])
- [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
- ;;
+ gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
+ gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
+ gl_CHECK_FUNCS_DEFAULT_CASE([$1])
esac
])
])
- case "$[gl_cv_onwards_func_][$1]" in
- future*) [ac_cv_func_][$1]=no ;;
- *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
- esac
- if test $[ac_cv_func_][$1] = yes; then
- AC_DEFINE([HAVE_]m4_translit([[$1]],
- [abcdefghijklmnopqrstuvwxyz],
- [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
- [1], [Define to 1 if you have the `$1' function.])
- fi
+ gl_CHECK_FUNCS_SET_RESULTS([$1])
])
dnl Expands to some code for use in .c programs that, on native Windows, defines