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