updated
[claws.git] / ac / 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                         LIBS_save="$LIBS"
42         
43                         case $with_openssl_libs in
44                         ""|-L*) ;;
45                         *) with_openssl_libs="-L$with_openssl_libs" ;;
46                         esac
47         
48                         AC_CHECK_LIB(dl, dlopen, DL_LIBS="-ldl", DL_LIBS="")
49                         AC_CACHE_CHECK([for OpenSSL libraries], openssl_libs,
50                         [
51                                 LIBS="$LIBS $with_openssl_libs -lssl -lcrypto $DL_LIBS"
52                                 AC_TRY_LINK_FUNC(SSL_read, openssl_libs="yes", openssl_libs="no")
53                                 LIBS="$LIBS_save"
54                         ])
55                         if test "x${openssl_libs}" != "xno"; then
56                                 AC_DEFINE(USE_OPENSSL, 1, [Define if you use OpenSSL to support SSL])
57                                 USE_OPENSSL=1
58                                 msg_ssl="yes (OpenSSL)"
59                                 OPENSSL_LIBS="$with_openssl_libs -lssl -lcrypto $DL_LIBS"
60                         else
61                                 OPENSSL_CFLAGS=""
62                                 OPENSSL_LIBS=""
63                         fi
64                 else
65                         AC_MSG_CHECKING(for OpenSSL libraries)
66                         AC_MSG_RESULT(no)
67                 fi
68         else
69                 OPENSSL_CFLAGS=""
70                 OPENSSL_LIBS=""
71                 ac_cv_enable_openssl="no"
72         fi
73
74         AC_SUBST(OPENSSL_CFLAGS)
75         AC_SUBST(OPENSSL_LIBS)
76 ])