diff --git a/autoconf/ast_pkgconfig.m4 b/autoconf/ast_pkgconfig.m4
new file mode 100644
index 0000000000000000000000000000000000000000..8641f94a94b805da08746f7a42bda82f95b3a667
--- /dev/null
+++ b/autoconf/ast_pkgconfig.m4
@@ -0,0 +1,17 @@
+# Check for pkg-config component $2:
+# AST_PKG_CONFIG_CHECK([package], [component])
+AC_DEFUN([AST_PKG_CONFIG_CHECK],
+[
+   if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
+      PKG_CHECK_MODULES($1, $2, [
+            PBX_$1=1
+            $1_INCLUDE="$$1_CFLAGS"
+            $1_LIB="$$1_LIBS"
+            AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
+         ], [
+            PBX_$1=0
+         ]
+      )
+   fi
+])
+
diff --git a/configure b/configure
index 9a468950dce6ec6fc3de1920c77a8043f5dc0ce7..42730ee74df673d0da427e65d871d0d7793e98f2 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 361968 .
+# From configure.ac Revision: 364444 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.68 for asterisk trunk.
 #
@@ -622,13 +622,16 @@ PBX_SYSLOG_FACILITY_LOG_AUTH
 PBX_GENERIC_ODBC
 GENERIC_ODBC_INCLUDE
 GENERIC_ODBC_LIB
+GTK2_LIBS
+GTK2_CFLAGS
 PBX_LAUNCHD
 CONFIG_SDL
 PBX_SO_NOSIGPIPE
 PBX_MSG_NOSIGNAL
 PBX_IXJUSER
 PBX_H323
-CONFIG_GMIME
+GMIME_LIBS
+GMIME_CFLAGS
 OPENH323_BUILD
 OPENH323_SUFFIX
 OPENH323_LIBDIR
@@ -648,7 +651,9 @@ PBX_MISDN_FAC_ERROR
 PBX_MISDN_FAC_RESULT
 GSM_INTERNAL
 PBX_DAHDI_HALF_FULL
-PKGCONFIG
+PKG_CONFIG_LIBDIR
+PKG_CONFIG_PATH
+PKG_CONFIG
 PBX_DLADDR
 PBX_IP_MTU_DISCOVER
 PBX_GLOB_BRACE
@@ -1260,7 +1265,14 @@ CPP
 CXX
 CXXFLAGS
 CCC
-CXXCPP'
+CXXCPP
+PKG_CONFIG
+PKG_CONFIG_PATH
+PKG_CONFIG_LIBDIR
+GMIME_CFLAGS
+GMIME_LIBS
+GTK2_CFLAGS
+GTK2_LIBS'
 
 
 # Initialize some variables set by options.
@@ -1973,6 +1985,16 @@ Some influential environment variables:
   CXX         C++ compiler command
   CXXFLAGS    C++ compiler flags
   CXXCPP      C++ preprocessor
+  PKG_CONFIG  path to pkg-config utility
+  PKG_CONFIG_PATH
+              directories to add to pkg-config's search path
+  PKG_CONFIG_LIBDIR
+              path overriding pkg-config's built-in search path
+  GMIME_CFLAGS
+              C compiler flags for GMIME, overriding pkg-config
+  GMIME_LIBS  linker flags for GMIME, overriding pkg-config
+  GTK2_CFLAGS C compiler flags for GTK2, overriding pkg-config
+  GTK2_LIBS   linker flags for GTK2, overriding pkg-config
 
 Use these variables to override the choices made by `configure' or to help
 it to find libraries and programs with nonstandard names/locations.
@@ -16698,25 +16720,35 @@ rm -f core conftest.err conftest.$ac_objext \
 LIBS=${old_LIBS}
 
 # PKGCONFIG is used in later tests
-if test -n "$ac_tool_prefix"; then
+
+
+
+
+
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
 set dummy ${ac_tool_prefix}pkg-config; 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_PKGCONFIG+:} false; then :
+if ${ac_cv_path_PKG_CONFIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$PKGCONFIG"; then
-  ac_cv_prog_PKGCONFIG="$PKGCONFIG" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  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 { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_PKGCONFIG="${ac_tool_prefix}pkg-config"
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -16724,12 +16756,13 @@ done
   done
 IFS=$as_save_IFS
 
+  ;;
+esac
 fi
-fi
-PKGCONFIG=$ac_cv_prog_PKGCONFIG
-if test -n "$PKGCONFIG"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5
-$as_echo "$PKGCONFIG" >&6; }
+PKG_CONFIG=$ac_cv_path_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; }
@@ -16737,26 +16770,28 @@ fi
 
 
 fi
-if test -z "$ac_cv_prog_PKGCONFIG"; then
-  ac_ct_PKGCONFIG=$PKGCONFIG
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
   # Extract the first word of "pkg-config", so it can be a program name with args.
 set dummy pkg-config; 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_ac_ct_PKGCONFIG+:} false; then :
+if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_PKGCONFIG"; then
-  ac_cv_prog_ac_ct_PKGCONFIG="$ac_ct_PKGCONFIG" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  case $ac_pt_PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  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 { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_PKGCONFIG="pkg-config"
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -16764,19 +16799,20 @@ done
   done
 IFS=$as_save_IFS
 
+  ;;
+esac
 fi
-fi
-ac_ct_PKGCONFIG=$ac_cv_prog_ac_ct_PKGCONFIG
-if test -n "$ac_ct_PKGCONFIG"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_PKGCONFIG" >&5
-$as_echo "$ac_ct_PKGCONFIG" >&6; }
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
-  if test "x$ac_ct_PKGCONFIG" = x; then
-    PKGCONFIG="No"
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
   else
     case $cross_compiling:$ac_tool_warned in
 yes:)
@@ -16784,12 +16820,26 @@ yes:)
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
-    PKGCONFIG=$ac_ct_PKGCONFIG
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
   fi
 else
-  PKGCONFIG="$ac_cv_prog_PKGCONFIG"
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
 fi
 
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=0.9.0
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	else
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+		PKG_CONFIG=""
+	fi
+fi
 
 
 # do the package library checks now
@@ -27176,171 +27226,99 @@ rm -f core conftest.err conftest.$ac_objext \
 fi
 
 
-    if test "x${PBX_GMIME}" != "x1" -a "${USE_GMIME}" != "no"; then
-	PBX_GMIME=0
-	if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}gmime-config", so it can be a program name with args.
-set dummy ${ac_tool_prefix}gmime-config; 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_path_CONFIG_GMIME+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $CONFIG_GMIME in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_CONFIG_GMIME="$CONFIG_GMIME" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="${GMIME_DIR}/bin:$PATH"
-for as_dir in $as_dummy
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_CONFIG_GMIME="$as_dir/$ac_word$ac_exec_ext"
-    $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
+for ver in 2.0 2.2 2.4 2.6; do
 
-  ;;
-esac
+   if test "x${PBX_GMIME}" != "x1" -a "${USE_GMIME}" != "no"; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GMIME" >&5
+$as_echo_n "checking for GMIME... " >&6; }
+
+if test -n "$GMIME_CFLAGS"; then
+    pkg_cv_GMIME_CFLAGS="$GMIME_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gmime-\$ver\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gmime-$ver") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GMIME_CFLAGS=`$PKG_CONFIG --cflags "gmime-$ver" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
-CONFIG_GMIME=$ac_cv_path_CONFIG_GMIME
-if test -n "$CONFIG_GMIME"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CONFIG_GMIME" >&5
-$as_echo "$CONFIG_GMIME" >&6; }
+if test -n "$GMIME_LIBS"; then
+    pkg_cv_GMIME_LIBS="$GMIME_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gmime-\$ver\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gmime-$ver") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GMIME_LIBS=`$PKG_CONFIG --libs "gmime-$ver" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
 
 
-fi
-if test -z "$ac_cv_path_CONFIG_GMIME"; then
-  ac_pt_CONFIG_GMIME=$CONFIG_GMIME
-  # Extract the first word of "gmime-config", so it can be a program name with args.
-set dummy gmime-config; 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_path_ac_pt_CONFIG_GMIME+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $ac_pt_CONFIG_GMIME in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_ac_pt_CONFIG_GMIME="$ac_pt_CONFIG_GMIME" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="${GMIME_DIR}/bin:$PATH"
-for as_dir in $as_dummy
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_ac_pt_CONFIG_GMIME="$as_dir/$ac_word$ac_exec_ext"
-    $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
 
-  ;;
-esac
-fi
-ac_pt_CONFIG_GMIME=$ac_cv_path_ac_pt_CONFIG_GMIME
-if test -n "$ac_pt_CONFIG_GMIME"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_CONFIG_GMIME" >&5
-$as_echo "$ac_pt_CONFIG_GMIME" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-fi
 
-  if test "x$ac_pt_CONFIG_GMIME" = x; then
-    CONFIG_GMIME="No"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    CONFIG_GMIME=$ac_pt_CONFIG_GMIME
-  fi
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
 else
-  CONFIG_GMIME="$ac_cv_path_CONFIG_GMIME"
+        _pkg_short_errors_supported=no
 fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GMIME_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gmime-$ver" 2>&1`
+        else
+	        GMIME_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gmime-$ver" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GMIME_PKG_ERRORS" >&5
 
-	if test ! "x${CONFIG_GMIME}" = xNo; then
-	    if test x"" = x ; then A=--cflags ; else A="" ; fi
-	    GMIME_INCLUDE=$(${CONFIG_GMIME} $A)
-	    if test x"" = x ; then A=--libs ; else A="" ; fi
-	    GMIME_LIB=$(${CONFIG_GMIME} $A)
-	    if test x"#include <gmime/gmime.h>" != x ; then
-		saved_cppflags="${CPPFLAGS}"
-		if test "x${GMIME_DIR}" != "x"; then
-		    GMIME_INCLUDE="-I${GMIME_DIR}/include"
-		fi
-		CPPFLAGS="${CPPFLAGS} ${GMIME_INCLUDE}"
 
-		saved_libs="${LIBS}"
-		LIBS="${GMIME_LIB}"
+            PBX_GMIME=0
 
-		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-  #include <gmime/gmime.h>
-int
-main ()
-{
- gboolean q = g_mime_check_version(0,0,0);;
 
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-     PBX_GMIME=1
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-$as_echo "#define HAVE_GMIME 1" >>confdefs.h
+            PBX_GMIME=0
 
 
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-		CPPFLAGS="${saved_cppflags}"
-		LIBS="${saved_libs}"
-	    else
-		PBX_GMIME=1
+else
+	GMIME_CFLAGS=$pkg_cv_GMIME_CFLAGS
+	GMIME_LIBS=$pkg_cv_GMIME_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 
-$as_echo "#define HAVE_GMIME 1" >>confdefs.h
+            PBX_GMIME=1
+            GMIME_INCLUDE="$GMIME_CFLAGS"
+            GMIME_LIB="$GMIME_LIBS"
 
-	    fi
-	fi
-    fi
+$as_echo "#define HAVE_GMIME 1" >>confdefs.h
 
-if test "x${PBX_GMIME}" = "x0" -a "${PKGCONFIG}" != "No"; then
-	# Later versions of GMime use pkg-config
-	for ver in 2.0 2.2 2.4 2.6; do
-		if ! ${PKGCONFIG} --exists gmime-$ver; then
-			continue
-		fi
-		# If we got here, we have this version:
-		GMIME_INCLUDE=$(${PKGCONFIG} gmime-$ver --cflags 2>/dev/null)
-		GMIME_LIB=$(${PKGCONFIG} gmime-$ver --libs)
-		PBX_GMIME=1
 
-$as_echo "#define HAVE_GMIME 1" >>confdefs.h
+fi
+   fi
 
+	if test "$PBX_GMIME" = 1; then
 		break;
-	done
-fi
+	fi
+done
 
 
 if test "x${PBX_HOARD}" != "x1" -a "${USE_HOARD}" != "no"; then
@@ -28916,18 +28894,94 @@ fi
 fi
 
 
-PBX_GTK2=0
-if test "${PKGCONFIG}" != "No"; then
-   GTK2_INCLUDE=$(${PKGCONFIG} gtk+-2.0 --cflags 2>/dev/null)
-   GTK2_LIB=$(${PKGCONFIG} gtk+-2.0 --libs)
-   PBX_GTK2=1
 
-$as_echo "#define HAVE_GTK2 1" >>confdefs.h
+   if test "x${PBX_GTK2}" != "x1" -a "${USE_GTK2}" != "no"; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GTK2" >&5
+$as_echo_n "checking for GTK2... " >&6; }
 
+if test -n "$GTK2_CFLAGS"; then
+    pkg_cv_GTK2_CFLAGS="$GTK2_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gtk+-2.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gtk+-2.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GTK2_CFLAGS=`$PKG_CONFIG --cflags "gtk+-2.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GTK2_LIBS"; then
+    pkg_cv_GTK2_LIBS="$GTK2_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gtk+-2.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gtk+-2.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GTK2_LIBS=`$PKG_CONFIG --libs "gtk+-2.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
 
 
 
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GTK2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gtk+-2.0" 2>&1`
+        else
+	        GTK2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gtk+-2.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GTK2_PKG_ERRORS" >&5
+
+
+            PBX_GTK2=0
+
+
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+            PBX_GTK2=0
+
+
+else
+	GTK2_CFLAGS=$pkg_cv_GTK2_CFLAGS
+	GTK2_LIBS=$pkg_cv_GTK2_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+            PBX_GTK2=1
+            GTK2_INCLUDE="$GTK2_CFLAGS"
+            GTK2_LIB="$GTK2_LIBS"
+
+$as_echo "#define HAVE_GTK2 1" >>confdefs.h
+
+
+fi
+   fi
+
 
 # build a GENERIC_ODBC result based on the presence of either UnixODBC (preferred)
 # or iODBC
diff --git a/configure.ac b/configure.ac
index 5d1064499c27799dd85893239f8a502d2bb268ff..d94f58dac9b629301f12a1b9e1c0770885d10b06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1142,7 +1142,7 @@ AC_LINK_IFELSE(
 LIBS=${old_LIBS}
 
 # PKGCONFIG is used in later tests
-AC_CHECK_TOOL(PKGCONFIG, pkg-config, No)
+PKG_PROG_PKG_CONFIG()
 
 
 # do the package library checks now
@@ -2079,21 +2079,13 @@ then
     CFLAGS="${saved_cflags}"
 fi
 
-AST_EXT_TOOL_CHECK([GMIME], [gmime-config], [], [], [#include <gmime/gmime.h>], [gboolean q = g_mime_check_version(0,0,0);])
-if test "x${PBX_GMIME}" = "x0" -a "${PKGCONFIG}" != "No"; then
-	# Later versions of GMime use pkg-config
-	for ver in 2.0 2.2 2.4 2.6; do
-		if ! ${PKGCONFIG} --exists gmime-$ver; then
-			continue
-		fi
-		# If we got here, we have this version:
-		GMIME_INCLUDE=$(${PKGCONFIG} gmime-$ver --cflags 2>/dev/null)
-		GMIME_LIB=$(${PKGCONFIG} gmime-$ver --libs)
-		PBX_GMIME=1
-		AC_DEFINE([HAVE_GMIME], 1, [Define if your system has the GMIME libraries.])
+
+for ver in 2.0 2.2 2.4 2.6; do
+	AST_PKG_CONFIG_CHECK([GMIME], gmime-$ver)
+	if test "$PBX_GMIME" = 1; then
 		break;
-	done
-fi
+	fi
+done
 
 AST_EXT_LIB_CHECK([HOARD], [hoard], [malloc], [])
 
@@ -2214,16 +2206,7 @@ then
 fi
 AC_SUBST(PBX_LAUNCHD)
 
-PBX_GTK2=0
-if test "${PKGCONFIG}" != "No"; then
-   GTK2_INCLUDE=$(${PKGCONFIG} gtk+-2.0 --cflags 2>/dev/null)
-   GTK2_LIB=$(${PKGCONFIG} gtk+-2.0 --libs)
-   PBX_GTK2=1
-   AC_DEFINE([HAVE_GTK2], 1, [Define if your system has the GTK2 libraries.])
-fi
-AC_SUBST(PBX_GTK2)
-AC_SUBST(GTK2_INCLUDE)
-AC_SUBST(GTK2_LIB)
+AST_PKG_CONFIG_CHECK([GTK2], [gtk+-2.0])
 
 # build a GENERIC_ODBC result based on the presence of either UnixODBC (preferred)
 # or iODBC