immutable: Add tests.
[gnulib.git] / m4 / gl-openssl.m4
blob96a7268a2796643dfeaed4cbeb0690405a3141ee
1 # gl-openssl.m4 serial 5
2 dnl Copyright (C) 2013-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_SET_CRYPTO_CHECK_DEFAULT],
9   m4_define([gl_CRYPTO_CHECK_DEFAULT], [$1])
11 gl_SET_CRYPTO_CHECK_DEFAULT([no])
13 AC_DEFUN([gl_CRYPTO_CHECK],
15   dnl gnulib users set this before gl_INIT with gl_SET_CRYPTO_CHECK_DEFAULT()
16   m4_divert_once([DEFAULTS], [with_openssl_default='gl_CRYPTO_CHECK_DEFAULT'])
18   dnl Only clear once, so crypto routines can be checked for individually
19   m4_divert_once([DEFAULTS], [LIB_CRYPTO=])
21   AC_ARG_WITH([openssl],
22     [AS_HELP_STRING([--with-openssl],
23       [use libcrypto hash routines. Valid ARGs are:
24        'yes', 'no',
25        'auto' => use if any version available,
26        'auto-gpl-compat' => use if gpl compatible version available,
27        'optional' => use if available and warn if not available;
28        default is ']gl_CRYPTO_CHECK_DEFAULT['.
29        Note also --with-linux-crypto, which will enable
30        use of kernel crypto routines, which have precedence])],
31     [],
32     [with_openssl=$with_openssl_default])
34   AC_SUBST([LIB_CRYPTO])
35   if test "x$with_openssl" != xno; then
36     if test "x$with_openssl" = xauto-gpl-compat; then
37       AC_CACHE_CHECK([whether openssl is GPL compatible],
38                      [gl_cv_openssl_gpl_compat],
39         [AC_COMPILE_IFELSE(
40            [AC_LANG_PROGRAM([[
41                 #include <openssl/opensslv.h>
42                 #if OPENSSL_VERSION_MAJOR < 3
43                   #error "openssl >= version 3 not found"
44                 #endif
45               ]])],
46            [gl_cv_openssl_gpl_compat=yes],
47            [gl_cv_openssl_gpl_compat=no])])
48     fi
49     if test "x$with_openssl" != xauto-gpl-compat ||
50        test "x$gl_cv_openssl_gpl_compat" = xyes; then
51       AC_CHECK_LIB([crypto], [$1],
52         [AC_CHECK_HEADERS(
53            m4_if([$1], [MD5], [openssl/md5.h], [openssl/sha.h]),
54            [LIB_CRYPTO=-lcrypto
55             AC_DEFINE([HAVE_OPENSSL_$1], [1],
56               [Define to 1 if libcrypto is used for $1.])])])
57     fi
58     if test "x$LIB_CRYPTO" = x; then
59       if test "x$with_openssl" = xyes; then
60         AC_MSG_ERROR([openssl development library not found for $1])
61       elif test "x$with_openssl" = xoptional; then
62         AC_MSG_WARN([openssl development library not found for $1])
63       fi
64     fi
65   fi