]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
configure: cache results of AC_*_IFELSE checks
authorDaiki Ueno <ueno@gnu.org>
Tue, 24 Dec 2024 01:15:45 +0000 (10:15 +0900)
committerDaiki Ueno <ueno@gnu.org>
Thu, 9 Jan 2025 05:04:23 +0000 (14:04 +0900)
This make the configure process a little faster when --cache-file is
given from the previous build, as it avoids running compilers, etc.,
as well as makes the features configurable through cached variables.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
configure.ac
m4/hooks.m4
tests/Makefile.am
tests/cert-tests/Makefile.am
tests/scripts/common.sh
tests/suite/Makefile.am

index c79c9622b252da79a8246ba4a219ded48957ac0d..5e0a37d95398b23814bb3eecc5ba2868decd619d 100644 (file)
@@ -77,31 +77,31 @@ AS_IF([test -n "$FAKETIME"], [FAKETIME_F_OPT="-f"; AC_SUBST([FAKETIME_F_OPT])],
   ])
 ])
 
-AC_MSG_CHECKING([whether faketime program works])
-AC_RUN_IFELSE(
-  [AC_LANG_PROGRAM(
-    [[#include <stdio.h>
-      #include <stdlib.h>
-      #include <time.h>
-    ]],
-    [[time_t t = time(NULL);
-      struct tm *tmp = localtime(&t);
-      char outstr[200];
-      if (!tmp) return 0;
-      if (!strftime(outstr, sizeof(outstr), "%s", tmp)) return 0;
-      puts(outstr);
-      return 0;
-    ]])],
-  [AS_IF([test -n "$FAKETIME" && test "`TZ=UTC $FAKETIME $FAKETIME_F_OPT "2006-09-23 00:00:00" ./conftest$EXEEXT`" = "1158969600"], [
-     ac_cv_faketime_works=yes
-   ], [
-     ac_cv_faketime_works=no
-   ])],
-  [ac_cv_faketime_works=no],
-  [ac_cv_faketime_works=cross-compiling])
-
-AC_MSG_RESULT([$ac_cv_faketime_works])
-AC_SUBST([ac_cv_faketime_works])
+AC_CACHE_CHECK([whether faketime program works], [gnutls_cv_prog_faketime_works],
+  [AC_RUN_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <stdio.h>
+        #include <stdlib.h>
+        #include <time.h>
+      ]],
+      [[time_t t = time(NULL);
+        struct tm *tmp = localtime(&t);
+        char outstr[200];
+        if (!tmp) return 0;
+        if (!strftime(outstr, sizeof(outstr), "%s", tmp)) return 0;
+        puts(outstr);
+        return 0;
+      ]])],
+    [AS_IF([test -n "$FAKETIME" && test "`TZ=UTC $FAKETIME $FAKETIME_F_OPT "2006-09-23 00:00:00" ./conftest$EXEEXT`" = "1158969600"], [
+       gnutls_cv_prog_faketime_works=yes
+     ], [
+       gnutls_cv_prog_faketime_works=no
+     ])],
+    [gnutls_cv_prog_faketime_works=no],
+    [gnutls_cv_prog_faketime_works=cross-compiling])])
+
+AC_MSG_RESULT([$gnutls_cv_faketime_works])
+AC_SUBST([gnutls_cv_faketime_works])
 
 AC_ARG_ENABLE(bash-tests,
   AS_HELP_STRING([--disable-bash-tests], [skip some tests that badly need bash]),
@@ -255,15 +255,21 @@ if test "$hw_accel" = aarch64; then
 fi
 
 # check for gcc's __get_cpuid_count functionality
-AC_MSG_CHECKING([for __get_cpuid_count])
-AC_LINK_IFELSE(
-   [AC_LANG_SOURCE([
-    #include <cpuid.h>
-    int main(void) { unsigned t1; return __get_cpuid_count(7, 0, &t1, &t1, &t1, &t1); }
-   ])],
-   [AC_DEFINE([HAVE_GET_CPUID_COUNT], [1], [use __get_cpuid_count]) AC_MSG_RESULT([yes])],
-   [AC_MSG_RESULT([no])]
-)
+AC_CACHE_CHECK([for __get_cpuid_count], [gnutls_cv_func___get_cpuid_count],
+  [AC_LINK_IFELSE(
+     [AC_LANG_PROGRAM(
+       [[#include <cpuid.h>
+       ]],
+       [[unsigned t1;
+         return __get_cpuid_count(7, 0, &t1, &t1, &t1, &t1);
+       ]])],
+     [gnutls_cv_func___get_cpuid_count=yes],
+     [gnutls_cv_func___get_cpuid_count=no]
+  )])
+
+AS_IF([test "$ac_cv_have___get_cpuid_count" = yes], [
+  AC_DEFINE([HAVE_GET_CPUID_COUNT], [1], [use __get_cpuid_count])
+])
 
 fi
 
@@ -322,53 +328,60 @@ AM_CONDITIONAL(ASM_X86, test x"$hw_accel" = x"x86" || test x"$hw_accel" = x"x86-
 AM_CONDITIONAL(HAVE_GCC_GNU89_INLINE_OPTION, test "$gnu89_inline" = "yes"])
 AM_CONDITIONAL(HAVE_GCC, test "$GCC" = "yes")
 
-dnl check for getrandom()
+dnl check for getrandom, KERN_ARND, and getentropy, in the order of precedence
 rnd_variant="auto-detect"
-AC_MSG_CHECKING([for getrandom])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([
-          #include <sys/random.h>],[
-                  getrandom(0, 0, 0);
-                 ])],
-                 [AC_MSG_RESULT(yes)
-                  AC_DEFINE([HAVE_GETRANDOM], 1, [Enable the Linux getrandom function])
-                  rnd_variant=getrandom],
-                 [AC_MSG_RESULT(no)])
-
-AC_MSG_CHECKING([for KERN_ARND])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([
-          #include <sys/sysctl.h>
-           #ifdef __linux__
-           #error 1
-           #endif
-           static int name[] = {CTL_KERN, KERN_ARND};
-          ],[
-                  sysctl(0, 0, 0, 0, 0, 0);
-                 ])],
-                 [AC_MSG_RESULT(yes)
-                  AC_DEFINE([HAVE_KERN_ARND], 1, [Enable the BSD sysctl(KERN_ARND) function])
-                  rnd_variant=kern_arnd],
-                 [AC_MSG_RESULT(no)])
-
-AM_CONDITIONAL(HAVE_KERN_ARND, test "$rnd_variant" = "kern_arnd")
-
-AC_MSG_CHECKING([for getentropy])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([
-          #include <unistd.h>
-           #ifdef __APPLE__
-           #include <sys/random.h>
-           #endif
-           #ifdef __linux__
-           #error 1
-           #endif
-          ],[
-                  getentropy(0, 0);
-                 ])],
-                 [AC_MSG_RESULT(yes)
-                  AC_DEFINE([HAVE_GETENTROPY], 1, [Enable the OpenBSD getentropy function])
-                  rnd_variant=getentropy],
-                 [AC_MSG_RESULT(no)])
 
-AM_CONDITIONAL(HAVE_GETENTROPY, test "$rnd_variant" = "getentropy")
+AC_CACHE_CHECK([for getrandom], [gnutls_cv_func_getrandom],
+  [AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <sys/random.h>
+      ]],
+      [[getrandom(0, 0, 0);]])],
+    [gnutls_cv_func_getrandom=yes],
+    [gnutls_cv_func_getrandom=no])])
+
+AS_IF([test "$gnutls_cv_func_getrandom" = yes], [
+  AC_DEFINE([HAVE_GETRANDOM], 1, [Enable the Linux getrandom function])
+  rnd_variant=getrandom
+])
+
+AC_CACHE_CHECK([for KERN_ARND], [gnutls_cv_kern_arnd],
+  [AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <sys/sysctl.h>
+        #ifdef __linux__
+        #error 1
+        #endif
+        static int name[] = {CTL_KERN, KERN_ARND};
+      ]],
+      [[sysctl(0, 0, 0, 0, 0, 0);]])],
+    [gnutls_cv_kern_arnd=yes],
+    [gnutls_cv_kern_arnd=no])])
+
+AM_CONDITIONAL(HAVE_KERN_ARND, test "$gnutls_cv_kern_arnd" = yes)
+AM_COND_IF([HAVE_KERN_ARND],
+  [AC_DEFINE([HAVE_KERN_ARND], 1, [Enable the BSD sysctl(KERN_ARND) function])
+   rnd_variant=kern_arnd])
+
+AC_CACHE_CHECK([for getentropy], [gnutls_cv_func_getentropy],
+  [AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <unistd.h>
+        #ifdef __APPLE__
+        #include <sys/random.h>
+        #endif
+        #ifdef __linux__
+        #error 1
+        #endif
+      ]],
+      [[getentropy(0, 0);]])],
+    [gnutls_cv_func_getentropy=yes],
+    [gnutls_cv_func_getentropy=no])])
+
+AM_CONDITIONAL(HAVE_GETENTROPY, test "$gnutls_cv_func_getentropy" = yes)
+AM_COND_IF([HAVE_GETENTROPY],
+  [AC_DEFINE([HAVE_GETENTROPY], 1, [Enable the OpenBSD getentropy function])
+   rnd_variant=getentropy])
 
 dnl Try the hooks.m4
 LIBGNUTLS_HOOKS
@@ -409,16 +422,31 @@ dnl headers. If we bypass the headers and just try linking (as AC_CHECK_FUNCS
 dnl does), we will accidentally detect functions which we shouldn't use. Set
 dnl ac_cv_func_* as well, to avoid later AC_CHECK_FUNCS from other included
 dnl scripts from overriding it.
-AC_MSG_CHECKING([for clock_gettime])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>], [clock_gettime(0, 0);])],
-  [AC_MSG_RESULT(yes); ac_cv_func_clock_gettime=yes
-  AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Define to 1 if you have the `clock_gettime' function.])],
-  [AC_MSG_RESULT(no); ac_cv_func_clock_gettime=no])
-AC_MSG_CHECKING([for fmemopen])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [fmemopen(0, 0, 0);])],
-  [AC_MSG_RESULT(yes); ac_cv_func_fmemopen=yes
-  AC_DEFINE([HAVE_FMEMOPEN], 1, [Define to 1 if you have the `fmemopen' function.])],
-  [AC_MSG_RESULT(no); ac_cv_func_fmemopen=no])
+AC_CACHE_CHECK([for clock_gettime], [gnutls_cv_func_clock_gettime],
+  [AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <time.h>
+      ]],
+      [[clock_gettime(0, 0);]])],
+    [gnutls_cv_func_clock_gettime=yes],
+    [gnutls_cv_func_clock_gettime=no])])
+
+AS_IF([test "$gnutls_cv_func_clock_gettime" = yes], [
+  AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Define to 1 if you have the `clock_gettime' function.])
+])
+
+AC_CACHE_CHECK([for fmemopen], [gnutls_cv_func_fmemopen],
+  [AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <stdio.h>
+      ]],
+      [[fmemopen(0, 0, 0);]])],
+    [gnutls_cv_func_fmemopen=yes],
+    [gnutls_cv_func_fmemopen=no])])
+
+AS_IF([test "$gnutls_cv_func_fmemopen" = yes], [
+  AC_DEFINE([HAVE_FMEMOPEN], 1, [Define to 1 if you have the `fmemopen' function.])
+])
 
 AM_CONDITIONAL(HAVE_FORK, test "$ac_cv_func_fork" != "no")
 
@@ -456,7 +484,7 @@ if test "$ac_cv_func_nanosleep" != "yes";then
   gnutls_needs_librt=yes
 fi
 
-if test "$ac_cv_func_clock_gettime" != "yes";then
+if test "$gnutls_cv_func_clock_gettime" != "yes";then
   AC_LIB_HAVE_LINKFLAGS(rt,, [#include <time.h>], [clock_gettime (0, 0);])
   gnutls_needs_librt=yes
 fi
@@ -972,23 +1000,20 @@ LIBGNUTLS_CHECK_SONAME([m], [AC_LANG_PROGRAM([
 LIBS="$save_LIBS"
 CFLAGS="$save_CFLAGS"
 
-AC_MSG_CHECKING([whether we can dlopen helper-libraries])
-
-AC_RUN_IFELSE(
-  [AC_LANG_PROGRAM(
-    [[#include <dlfcn.h>
-      #include <stdlib.h>
-    ]],
-    [[void *handle = dlopen("$M_LIBRARY_SONAME", RTLD_LAZY | RTLD_GLOBAL);
-      return handle != NULL ? 0 : 1;
-    ]])],
-  [ac_cv_dlopen_soname_works=yes],
-  [ac_cv_dlopen_soname_works=no],
-  [ac_cv_dlopen_soname_works=cross-compiling])
-
-AC_MSG_RESULT([$ac_cv_dlopen_soname_works])
-
-AM_CONDITIONAL([ENABLE_DLOPEN], [test "$ac_cv_dlopen_soname_works" = yes])
+AC_CACHE_CHECK([whether dlopen works with SONAME], [gnutls_cv_dlopen_soname_works],
+  [AC_RUN_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <dlfcn.h>
+        #include <stdlib.h>
+      ]],
+      [[void *handle = dlopen("$M_LIBRARY_SONAME", RTLD_LAZY | RTLD_GLOBAL);
+        return handle != NULL ? 0 : 1;
+      ]])],
+    [gnutls_cv_dlopen_soname_works=yes],
+    [gnutls_cv_dlopen_soname_works=no],
+    [gnutls_cv_dlopen_soname_works=cross-compiling])])
+
+AM_CONDITIONAL([ENABLE_DLOPEN], [test "$gnutls_cv_dlopen_soname_works" = yes])
 need_ltlibdl=no
 
 AC_ARG_WITH(tpm2,
index efba6e21a1cbc70197389c818208f415010924aa..ae50938d817b82b39221b77c0289310f08158ded 100644 (file)
@@ -426,18 +426,13 @@ AC_DEFUN([LIBGNUTLS_CHECK_SONAME],
 [
   m4_pushdef([soname], AS_TR_SH([$1]))
   m4_pushdef([SONAME], AS_TR_CPP([$1]))
-  AC_MSG_CHECKING([$1 [soname]])
-  AC_LINK_IFELSE([$2],
-       [soname[]_so=`(eval "$LDDPROG conftest$EXEEXT $LDDPOSTPROC") | grep '^lib[]$1\.so'`],
-       [soname[]_so=none])
-  if test -z "$soname[]_so"; then
-       soname[]_so=none
-  fi
-  AC_MSG_RESULT($soname[]_so)
-  if test "$soname[]_so" != none; then
-       SONAME[]_LIBRARY_SONAME="$soname[]_so"
-       AC_DEFINE_UNQUOTED([SONAME[]_LIBRARY_SONAME], ["$soname[]_so"], [The soname of $1 library])
-  fi
+  AC_CACHE_CHECK([$1 [soname]], [gnutls_cv_soname_[]soname],
+    [AC_LINK_IFELSE([$2],
+      [gnutls_cv_soname_[]soname=`(eval "$LDDPROG conftest$EXEEXT $LDDPOSTPROC") | grep '^lib[]$1\.so'`],
+      [gnutls_cv_soname_[]soname=none])])
+  AS_IF([test -z "$gnutls_cv_soname_[]soname"], [gnutls_cv_soname_[]soname=none],
+        [SONAME[]_LIBRARY_SONAME="$gnutls_cv_soname_[]soname"
+        AC_DEFINE_UNQUOTED([SONAME[]_LIBRARY_SONAME], ["$gnutls_cv_soname_[]soname"], [The soname of $1 library])])
   m4_popdef([soname])
   m4_popdef([SONAME])
 ])
index c1dbe8b85827ac1c14152025edcf10632a37918a..9f5801845be6c8223baf64245415d05212442b03 100644 (file)
@@ -672,7 +672,7 @@ endif
 TESTS_ENVIRONMENT +=                                   \
        FAKETIME="$(FAKETIME)"                          \
        FAKETIME_F_OPT="$(FAKETIME_F_OPT)"              \
-       ac_cv_faketime_works="$(ac_cv_faketime_works)"
+       gnutls_cv_faketime_works="$(gnutls_cv_faketime_works)"
 
 TEST_EXTENSIONS = .sh
 SH_LOG_COMPILER = $(SHELL)
index 5a695dbebcd3edad0558e070d2d0032d212b2148..57c08a7b22cf9dbbfc2a1c284c87890fbc614994 100644 (file)
@@ -199,7 +199,7 @@ endif
 TESTS_ENVIRONMENT +=                                   \
        FAKETIME="$(FAKETIME)"                          \
        FAKETIME_F_OPT="$(FAKETIME_F_OPT)"              \
-       ac_cv_faketime_works="$(ac_cv_faketime_works)"
+       gnutls_cv_faketime_works="$(gnutls_cv_faketime_works)"
 
 TEST_EXTENSIONS = .sh
 SH_LOG_COMPILER = $(SHELL)
index cf943d7817e058e3f8118f1a5d47281aa374d8d1..47355cf025fd3dc99b4c6877d19cd48b55d1785f 100644 (file)
@@ -96,7 +96,7 @@ GETPORT='
 '
 
 skip_if_no_datefudge() {
-       if test "$ac_cv_faketime_works" != yes; then
+       if test "$gnutls_cv_faketime_works" != yes; then
                exit 77
        fi
 }
index ef49b391399d180e02c481115b4cef1b912439da..ee22108a1baf7f1c35f7ea5b9a3efd552b012355 100644 (file)
@@ -79,7 +79,7 @@ endif
 TESTS_ENVIRONMENT +=                                   \
        FAKETIME="$(FAKETIME)"                          \
        FAKETIME_F_OPT="$(FAKETIME_F_OPT)"              \
-       ac_cv_faketime_works="$(ac_cv_faketime_works)"
+       gnutls_cv_faketime_works="$(gnutls_cv_faketime_works)"
 
 if ENABLE_OLDGNUTLS_INTEROP
 scripts_to_test += testcompat-oldgnutls.sh