diff --git a/ChangeLog b/ChangeLog
index 6680820e..6e240196 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,9 @@
 	* configure.ac: Use pkg-config to check for openssl presence and
 	fallback to the previous code if that doesn't work.
 
+	* configure.ac: Use pkg-config to check for gnutls presence and
+	fallback to the previous code if that doesn't work.
+
 2014-07-28  Ángel González <keisial@gmail.com>
 	* contrib: Created contrib folder.
 	* contrib/tsocked-wget: Added wrapper for usage with socks proxy.
diff --git a/configure.ac b/configure.ac
index 0d170cbf..c2fbda80 100644
--- a/configure.ac
+++ b/configure.ac
@@ -348,18 +348,26 @@ AS_IF([test x"$with_ssl" = xopenssl], [
     with_ssl=gnutls
 
     dnl Now actually check for -lgnutls
-    AC_LIB_HAVE_LINKFLAGS([gnutls], [], [
-#include <gnutls/gnutls.h>
-    ], [gnutls_global_init()])
-    if test x"$LIBGNUTLS" != x
-    then
-      ssl_found=yes
+    PKG_CHECK_MODULES([GNUTLS], [gnutls], [
       AC_MSG_NOTICE([compiling in support for SSL via GnuTLS])
       AC_LIBOBJ([gnutls])
-      LIBS="$LIBGNUTLS $LIBS"
-    else
-      AC_MSG_ERROR([--with-ssl=gnutls was given, but GNUTLS is not available.])
-    fi
+      LIBS="$GNUTLS_LIBS $LIBS"
+      CFLAGS="$GNUTLS_CFLAGS -DHAVE_LIBGNUTLS $CFLAGS"
+      AC_DEFINE([HAVE_LIBGNUTLS], [1], [Define if using gnutls.])
+    ], [
+      AC_LIB_HAVE_LINKFLAGS([gnutls], [], [
+#include <gnutls/gnutls.h>
+      ], [gnutls_global_init()])
+      if test x"$LIBGNUTLS" != x
+      then
+        ssl_found=yes
+        AC_MSG_NOTICE([compiling in support for SSL via GnuTLS])
+        AC_LIBOBJ([gnutls])
+        LIBS="$LIBGNUTLS $LIBS"
+      else
+        AC_MSG_ERROR([--with-ssl=gnutls was given, but GNUTLS is not available.])
+      fi
+    ])
 
     AC_CHECK_FUNCS(gnutls_priority_set_direct)
   ]) # endif: --with-ssl != no?