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