detect openssl via pkg-config if it's available

--- a/configure.ac
+++ b/configure.ac
@@ -234,7 +234,17 @@ dnl
 dnl Checks for libraries.
 dnl
 
+PKG_PROG_PKG_CONFIG
+
 AS_IF([test x"$with_ssl" = xopenssl], [
+    PKG_CHECK_MODULES([OPENSSL], [openssl], [
+        AC_MSG_NOTICE([compiling in support for SSL via OpenSSL])
+        AC_LIBOBJ([openssl])
+        LIBS="$OPENSSL_LIBS $LIBS"
+        CFLAGS="$OPENSSL_CFLAGS -DHAVE_LIBSSL $CFLAGS"
+        LIBSSL=" " # ntlm check below wants this #395349
+    ], [
+
     dnl some versions of openssl use zlib compression
     AC_CHECK_LIB(z, compress)
 
@@ -294,6 +303,8 @@ AS_IF([test x$ssl_found != xyes],
 
 ])
 
+])
+
 ], [
   # --with-ssl is not gnutls: check if it's no
   AS_IF([test x"$with_ssl" != xno], [