md5, sha1, sha256, sha512: support mandating use of openssl
[gnulib.git] / m4 / gl-openssl.m4
1 # gl-openssl.m4 serial 1
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_CRYPTO_CHECK],
8 [
9   AC_ARG_WITH([openssl],
10     [AS_HELP_STRING([--with-openssl],
11       [use libcrypto hash routines. Valid ARGs are:
12        'yes', 'no', 'optional' => use if available])],
13     [],
14     [with_openssl=no])
15
16   if test "x$1" = xMD5; then
17     ALG_header=md5.h
18   else
19     ALG_header=sha.h
20   fi
21
22   LIB_CRYPTO=
23   AC_SUBST([LIB_CRYPTO])
24   if test "x$with_openssl" != xno; then
25     AC_CHECK_LIB([crypto], [$1],
26       [AC_CHECK_HEADERS([openssl/$ALG_header],
27         [LIB_CRYPTO='-lcrypto'
28          AC_DEFINE([HAVE_OPENSSL_$1],[1],
29            [Define to 1 if libcrypto is used for $1])])])
30     if test "x$LIB_CRYPTO" = x; then
31       if test "x$with_openssl" = xyes; then
32         AC_MSG_ERROR([openssl development library not found for $1])
33       else
34         AC_MSG_WARN([openssl development library not found for $1])
35       fi
36     fi
37   fi
38 ])