Merge pull request #2043 from RincewindsHat/cleanup/leftovers
[monitoring-plugins.git] / gl / m4 / gl-openssl.m4
blobc5e1f7bafb091f66f6e3ea2a66623b02f9271cdb
1 # gl-openssl.m4
2 # serial 7
3 dnl Copyright (C) 2013-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_SET_CRYPTO_CHECK_DEFAULT],
10   m4_define([gl_CRYPTO_CHECK_DEFAULT], [$1])
12 gl_SET_CRYPTO_CHECK_DEFAULT([no])
14 AC_DEFUN([gl_CRYPTO_CHECK],
16   dnl gnulib users set this before gl_INIT with gl_SET_CRYPTO_CHECK_DEFAULT()
17   m4_divert_once([DEFAULTS], [with_openssl_default='gl_CRYPTO_CHECK_DEFAULT'])
19   dnl Only clear once, so crypto routines can be checked for individually
20   m4_divert_once([DEFAULTS], [LIB_CRYPTO=])
22   AC_ARG_WITH([openssl],
23     [[  --with-openssl[=ARG]    use libcrypto hash routines for the hash functions
24                           MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512.
25                           Valid ARGs are:
26                             'yes',
27                             'no',
28                             'auto' => use if any version available,
29                             'auto-gpl-compat' => use if GPL compatible version
30                                                  available,
31                             'optional' => use if available
32                                           and warn if not available;
33                           Default is ']gl_CRYPTO_CHECK_DEFAULT['.]m4_ifdef([gl_AF_ALG], [
34                           Note also --with-linux-crypto, which will enable the
35                           use of Linux kernel crypto routines (if available),
36                           which has precedence for files.])],
37     [],
38     [with_openssl=$with_openssl_default])
40   AC_SUBST([LIB_CRYPTO])
41   if test "x$with_openssl" != xno; then
42     if test "x$with_openssl" = xauto-gpl-compat; then
43       dnl OpenSSL versions < 3 are under the OpenSSL license, which is not
44       dnl GPL compatible.
45       dnl See <https://www.gnu.org/licenses/license-list.en.html#OpenSSL>.
46       AC_CACHE_CHECK([whether openssl is GPL compatible],
47                      [gl_cv_openssl_gpl_compat],
48         [AC_COMPILE_IFELSE(
49            [AC_LANG_PROGRAM([[
50                 #include <openssl/opensslv.h>
51                 #if OPENSSL_VERSION_MAJOR < 3
52                   #error "openssl >= version 3 not found"
53                 #endif
54               ]])],
55            [gl_cv_openssl_gpl_compat=yes],
56            [gl_cv_openssl_gpl_compat=no])])
57     fi
58     if test "x$with_openssl" != xauto-gpl-compat ||
59        test "x$gl_cv_openssl_gpl_compat" = xyes; then
60       AC_CHECK_LIB([crypto], [$1],
61         [AC_CHECK_HEADERS(
62            m4_if([$1], [MD5], [openssl/md5.h], [openssl/sha.h]),
63            [LIB_CRYPTO=-lcrypto
64             AC_DEFINE([HAVE_OPENSSL_$1], [1],
65               [Define to 1 if libcrypto is used for $1.])])])
66     fi
67     if test "x$LIB_CRYPTO" = x; then
68       message='openssl development library not found for $1.
69   If you want to install it, first find the pre-built package name:
70     - On Debian and Debian-based systems: libssl-dev,
71     - On Red Hat distributions: openssl-devel.
72     - Other: https://repology.org/project/openssl/versions'
73       if test "x$with_openssl" = xyes; then
74         AC_MSG_ERROR([$message])
75       elif test "x$with_openssl" = xoptional; then
76         AC_MSG_WARN([$message])
77       fi
78     fi
79   fi