+# --with-libssl {{{
+with_libssl_cflags=""
+with_libssl_ldflags=""
+AC_ARG_WITH(libssl, [AS_HELP_STRING([--with-libssl@<:@=PREFIX@:>@], [Path to libssl.])],
+[
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"
+ then
+ with_libssl_cppflags="-I$withval/include"
+ with_libssl_ldflags="-L$withval/lib"
+ with_libssl="yes"
+ else
+ with_libssl="$withval"
+ fi
+],
+[
+ with_libssl="yes"
+])
+if test "x$with_libssl" = "xyes"
+then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libssl_cppflags"
+
+ AC_CHECK_HEADERS(openssl/sha.h openssl/blowfish.h openssl/rand.h,
+ [with_libssl="yes"],
+ [with_libssl="no (ssl header not found)"])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libssl" = "xyes"
+then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libssl_cppflags"
+ LDFLAGS="$LDFLAGS $with_libssl_ldflags"
+
+ AC_CHECK_LIB(ssl, OPENSSL_init_ssl, [with_libssl="yes"], [with_libssl="no (Symbol 'SSL_library_init' not found)"])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+if test "x$with_libssl" = "xyes"
+then
+ BUILD_WITH_LIBSSL_CFLAGS="$with_libssl_cflags"
+ BUILD_WITH_LIBSSL_LDFLAGS="$with_libssl_ldflags"
+ BUILD_WITH_LIBSSL_LIBS="-lssl -lcrypto"
+ AC_SUBST(BUILD_WITH_LIBSSL_CFLAGS)
+ AC_SUBST(BUILD_WITH_LIBSSL_LDFLAGS)
+ AC_SUBST(BUILD_WITH_LIBSSL_LIBS)
+ AC_DEFINE(HAVE_LIBSSL, 1, [Define if libssl is present and usable.])
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBSSL, test "x$with_libssl" = "xyes")
+# }}}
+