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