md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
[gnulib.git] / m4 / gl-openssl.m4
1 # gl-openssl.m4 serial 3
2 dnl Copyright (C) 2013 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.
6
7 AC_DEFUN([gl_SET_CRYPTO_CHECK_DEFAULT],
8 [
9   m4_define([gl_CRYPTO_CHECK_DEFAULT], [$1])
10 ])
11 gl_SET_CRYPTO_CHECK_DEFAULT([no])
12
13 AC_DEFUN([gl_CRYPTO_CHECK],
14 [
15   m4_divert_once([DEFAULTS], [with_openssl_default='gl_CRYPTO_CHECK_DEFAULT'])
16
17   AC_ARG_WITH([openssl],
18     [AS_HELP_STRING([--with-openssl],
19       [use libcrypto hash routines. Valid ARGs are:
20        'yes', 'no', 'auto' => use if available,
21        'optional' => use if available and warn if not available;
22        default is ']gl_CRYPTO_CHECK_DEFAULT['])],
23     [],
24     [with_openssl=$with_openssl_default])
25
26   if test "x$1" = xMD5; then
27     ALG_header=md5.h
28   else
29     ALG_header=sha.h
30   fi
31
32   LIB_CRYPTO=
33   AC_SUBST([LIB_CRYPTO])
34   if test "x$with_openssl" != xno; then
35     AC_CHECK_LIB([crypto], [$1],
36       [AC_CHECK_HEADERS([openssl/$ALG_header],
37          [LIB_CRYPTO=-lcrypto
38           AC_DEFINE([HAVE_OPENSSL_$1], [1],
39             [Define to 1 if libcrypto is used for $1.])])])
40     if test "x$LIB_CRYPTO" = x; then
41       if test "x$with_openssl" = xyes; then
42         AC_MSG_ERROR([openssl development library not found for $1])
43       elif test "x$with_openssl" = xoptional; then
44         AC_MSG_WARN([openssl development library not found for $1])
45       fi
46     fi
47   fi
48 ])