e50b399bd9d7a79c7c75da2591fd614324d93f9a
[claws.git] / ac / openssl.m4
1 dnl ******************************
2 dnl OpenSSL
3 dnl ******************************
4
5 AC_DEFUN(AM_PATH_OPENSSL,
6 [dnl
7         AC_ARG_ENABLE(openssl, [  --enable-openssl        Attempt to use OpenSSL for SSL support.],
8                 [ac_cv_enable_openssl=$enableval], [ac_cv_enable_openssl=no])
9
10         dnl delect OpenSSL
11         if test "x${ac_cv_enable_openssl}" != "xno"; then
12                 AC_ARG_WITH(openssl-includes, [  --with-openssl-includes=PREFIX     Location of OpenSSL includes.],
13                         with_openssl_includes="$withval", with_openssl_includes="/usr/include")
14                 have_openssl_includes="no"
15                 if test "x${with_openssl_includes}" != "xno"; then
16                         CPPFLAGS_save="$CPPFLAGS"
17                 
18                         AC_MSG_CHECKING(for OpenSSL includes)
19                         AC_MSG_RESULT("")
20                 
21                         CPPFLAGS="$CPPFLAGS -I$with_openssl_includes"
22                         AC_CHECK_HEADERS(openssl/ssl.h openssl/x509.h, [ openssl_includes="yes" ])
23                         CPPFLAGS="$CPPFLAGS_save"
24                 
25                         if test "x{$openssl_includes}" != "xno" -a "x{$openssl_includes}" != "x"; then
26                                 have_openssl_includes="yes"
27                                 OPENSSL_CFLAGS="-I$with_openssl_includes"
28                         else
29                                 OPENSSL_CFLAGS=""
30                         fi
31                 else
32                         AC_MSG_CHECKING(for OpenSSL includes)
33                         AC_MSG_RESULT(no)
34                 fi
35         
36                 AC_ARG_WITH(openssl-libs, [  --with-openssl-libs=PREFIX         Location of OpenSSL libs.],
37                         with_openssl_libs="$withval")
38                 if test "x${with_openssl_libs}" != "xno" -a "x${have_openssl_includes}" != "xno"; then
39                         LIBS_save="$LIBS"
40         
41                         case $with_openssl_libs in
42                         ""|-L*) ;;
43                         *) with_openssl_libs="-L$with_openssl_libs" ;;
44                         esac
45         
46                         AC_CHECK_LIB(dl, dlopen, DL_LIBS="-ldl", DL_LIBS="")
47                         AC_CACHE_CHECK([for OpenSSL libraries], openssl_libs,
48                         [
49                                 LIBS="$LIBS $with_openssl_libs -lssl -lcrypto $DL_LIBS"
50                                 AC_TRY_LINK_FUNC(SSL_read, openssl_libs="yes", openssl_libs="no")
51                                 LIBS="$LIBS_save"
52                         ])
53                         if test "x${openssl_libs}" != "xno"; then
54                                 AC_DEFINE(USE_OPENSSL, 1, [Define if you use OpenSSL to support SSL])
55                                 msg_ssl="yes (OpenSSL)"
56                                 OPENSSL_LIBS="$with_openssl_libs -lssl -lcrypto $DL_LIBS"
57                         else
58                                 OPENSSL_CFLAGS=""
59                                 OPENSSL_LIBS=""
60                         fi
61                 else
62                         AC_MSG_CHECKING(for OpenSSL libraries)
63                         AC_MSG_RESULT(no)
64                 fi
65         else
66                 OPENSSL_CFLAGS=""
67                 OPENSSL_LIBS=""
68                 ac_cv_enable_openssl="no"
69         fi
70
71         AC_SUBST(OPENSSL_CFLAGS)
72         AC_SUBST(OPENSSL_LIBS)
73 ])