Index: pjproject/trunk/aconfigure
===================================================================
--- pjproject/trunk/aconfigure	(revision 5679)
+++ pjproject/trunk/aconfigure	(revision 5725)
@@ -643,7 +643,10 @@
 ac_no_opencore_amrwb
 ac_no_opencore_amrnb
+libgnutls_present
+gnutls_h_present
 libcrypto_present
 libssl_present
 openssl_h_present
+ac_ssl_backend
 ac_ssl_has_aes_gcm
 ac_no_ssl
@@ -759,5 +762,4 @@
 oldincludedir
 includedir
-runstatedir
 localstatedir
 sharedstatedir
@@ -820,4 +822,5 @@
 with_ipp_arch
 with_ssl
+with_gnutls
 enable_ssl
 with_opencore_amrnb
@@ -884,5 +887,4 @@
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
-runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
@@ -1137,13 +1139,4 @@
     silent=yes ;;
 
-  -runstatedir | --runstatedir | --runstatedi | --runstated \
-  | --runstate | --runstat | --runsta | --runst | --runs \
-  | --run | --ru | --r)
-    ac_prev=runstatedir ;;
-  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
-  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
-  | --run=* | --ru=* | --r=*)
-    runstatedir=$ac_optarg ;;
-
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
@@ -1283,5 +1276,5 @@
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir runstatedir
+		libdir localedir mandir
 do
   eval ac_val=\$$ac_var
@@ -1436,5 +1429,4 @@
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
-  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
@@ -1555,5 +1547,9 @@
   --with-ipp-arch=ARCH    Specify the Intel IPP ARCH suffix, e.g. "64" or
                           "em64t. Default is blank for IA32"
-  --with-ssl=DIR          Specify alternate libssl prefix
+  --with-ssl=DIR          Specify alternate SSL library prefix. This option
+                          will try to find OpenSSL first, then if not found,
+                          GnuTLS. To skip OpenSSL finding, use --with-gnutls
+                          option instead.
+  --with-gnutls=DIR       Specify alternate GnuTLS prefix
   --with-opencore-amrnb=DIR
                           This option is obsolete and replaced by
@@ -7860,5 +7856,15 @@
 
 
-if test "x$ac_cross_compile" != "x" -a "x$with_ssl" = "xno"; then
+
+# Check whether --with-gnutls was given.
+if test "${with_gnutls+set}" = set; then :
+  withval=$with_gnutls;
+else
+  with_gnutls=no
+
+fi
+
+
+if test "x$ac_cross_compile" != "x" -a "x$with_ssl" = "xno" -a "x$with_gnutls" = "xno"; then
     enable_ssl=no
 fi
@@ -7866,4 +7872,5 @@
 
 ac_ssl_has_aes_gcm=0
+
 
 # Check whether --enable-ssl was given.
@@ -7878,6 +7885,4 @@
 else
 
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for OpenSSL installations.." >&5
-$as_echo "checking for OpenSSL installations.." >&6; }
                 if test "x$with_ssl" != "xno" -a "x$with_ssl" != "x"; then
                     CFLAGS="$CFLAGS -I$with_ssl/include"
@@ -7887,7 +7892,12 @@
                 fi
 
-
-
-		ac_fn_c_check_header_mongrel "$LINENO" "openssl/ssl.h" "ac_cv_header_openssl_ssl_h" "$ac_includes_default"
+	        if test "x$with_gnutls" = "xno"; then
+
+		    { $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for OpenSSL installations.." >&5
+$as_echo "checking for OpenSSL installations.." >&6; }
+
+
+
+		    ac_fn_c_check_header_mongrel "$LINENO" "openssl/ssl.h" "ac_cv_header_openssl_ssl_h" "$ac_includes_default"
 if test "x$ac_cv_header_openssl_ssl_h" = xyes; then :
   openssl_h_present=1
@@ -7895,5 +7905,5 @@
 
 
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ERR_load_BIO_strings in -lcrypto" >&5
+		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ERR_load_BIO_strings in -lcrypto" >&5
 $as_echo_n "checking for ERR_load_BIO_strings in -lcrypto... " >&6; }
 if ${ac_cv_lib_crypto_ERR_load_BIO_strings+:} false; then :
@@ -7935,5 +7945,5 @@
 fi
 
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_CTX_new in -lssl" >&5
+		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_CTX_new in -lssl" >&5
 $as_echo_n "checking for SSL_CTX_new in -lssl... " >&6; }
 if ${ac_cv_lib_ssl_SSL_CTX_new+:} false; then :
@@ -7975,5 +7985,5 @@
 fi
 
-		if test "x$openssl_h_present" = "x1" -a "x$libssl_present" = "x1" -a "x$libcrypto_present" = "x1"; then
+		    if test "x$openssl_h_present" = "x1" -a "x$libssl_present" = "x1" -a "x$libcrypto_present" = "x1"; then
 	        	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: OpenSSL library found, SSL support enabled" >&5
 $as_echo "OpenSSL library found, SSL support enabled" >&6; }
@@ -8051,8 +8061,143 @@
 			$as_echo "#define PJ_HAS_SSL_SOCK 1" >>confdefs.h
 
-		else
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ** OpenSSL libraries not found, disabling SSL support **" >&5
-$as_echo "** OpenSSL libraries not found, disabling SSL support **" >&6; }
+			$as_echo "#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_OPENSSL" >>confdefs.h
+
+			ac_ssl_backend="openssl"
+		    else
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ** OpenSSL libraries not found **" >&5
+$as_echo "** OpenSSL libraries not found **" >&6; }
+		    fi
+
 		fi
+
+    		if test "x$ac_ssl_backend" = "x"; then
+
+		    if test "x$with_gnutls" != "xno" -a "x$with_gnutls" != "x"; then
+        	        CFLAGS="$CFLAGS -I$with_gnutls/include"
+        	        LDFLAGS="$LDFLAGS -L$with_gnutls/lib"
+        	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using GnuTLS prefix... $with_gnutls" >&5
+$as_echo "Using GnuTLS prefix... $with_gnutls" >&6; }
+    		    fi
+
+        	    for ac_prog in $host-pkg-config pkg-config "python pkgconfig.py"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_PKG_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$PKG_CONFIG"; then
+  ac_cv_prog_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_PKG_CONFIG="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+PKG_CONFIG=$ac_cv_prog_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$PKG_CONFIG" && break
+done
+test -n "$PKG_CONFIG" || PKG_CONFIG="none"
+
+        	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for GnuTLS installations.." >&5
+$as_echo "checking for GnuTLS installations.." >&6; }
+
+
+        	    ac_fn_c_check_header_mongrel "$LINENO" "gnutls/gnutls.h" "ac_cv_header_gnutls_gnutls_h" "$ac_includes_default"
+if test "x$ac_cv_header_gnutls_gnutls_h" = xyes; then :
+  gnutls_h_present=1
+fi
+
+
+
+        	    if test "$PKG_CONFIG" != "none"; then
+            	    	if $PKG_CONFIG --exists gnutls; then
+                	    LIBS="$LIBS `$PKG_CONFIG --libs gnutls`"
+                	    libgnutls_present=1
+            		else
+                	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gnutls_certificate_set_x509_system_trust in -lgnutls" >&5
+$as_echo_n "checking for gnutls_certificate_set_x509_system_trust in -lgnutls... " >&6; }
+if ${ac_cv_lib_gnutls_gnutls_certificate_set_x509_system_trust+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lgnutls  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gnutls_certificate_set_x509_system_trust ();
+int
+main ()
+{
+return gnutls_certificate_set_x509_system_trust ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_gnutls_gnutls_certificate_set_x509_system_trust=yes
+else
+  ac_cv_lib_gnutls_gnutls_certificate_set_x509_system_trust=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gnutls_gnutls_certificate_set_x509_system_trust" >&5
+$as_echo "$ac_cv_lib_gnutls_gnutls_certificate_set_x509_system_trust" >&6; }
+if test "x$ac_cv_lib_gnutls_gnutls_certificate_set_x509_system_trust" = xyes; then :
+  libgnutls_present=1 &&
+                              LIBS="$LIBS -lgnutls"
+fi
+
+            		fi
+        	    else
+            		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: *** Warning: neither pkg-config nor python is available, disabling gnutls. ***" >&5
+$as_echo "*** Warning: neither pkg-config nor python is available, disabling gnutls. ***" >&6; }
+        	    fi
+
+        	    if test "x$gnutls_h_present" = "x1" -a "x$libgnutls_present" = "x1"; then
+           		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: GnuTLS library found, SSL support enabled" >&5
+$as_echo "GnuTLS library found, SSL support enabled" >&6; }
+			$as_echo "#define PJ_HAS_SSL_SOCK 1" >>confdefs.h
+
+			$as_echo "#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_GNUTLS" >>confdefs.h
+
+            		ac_ssl_backend="gnutls"
+        	    else
+            		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ** No GnuTLS libraries found, disabling SSL support **" >&5
+$as_echo "** No GnuTLS libraries found, disabling SSL support **" >&6; }
+        	    fi
+
+        	fi
 
 fi
