diff --git a/autoconf/ast_check_openh323.m4 b/autoconf/ast_check_openh323.m4
index 35f8a54..185171c 100644
--- a/autoconf/ast_check_openh323.m4
+++ b/autoconf/ast_check_openh323.m4
@@ -5,6 +5,17 @@ AC_LANG_PUSH([C++])
 if test "${OPENH323DIR:-unset}" != "unset" ; then
   AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
 fi
+OPENH323_PKGCONFIG=
+PKG_CHECK_MODULES(OPENH323, opal, [
+  set -x
+  OPENH323_LIB="${OPENH323_LIBS}"
+  HAS_OPENH323=1
+  OPENH323_PKGCONFIG=1
+  set +x
+],[
+  echo >&2 "ptlib not found through pkg-config"
+  exit 30
+]) 
 if test "${HAS_OPENH323:-unset}" = "unset" ; then
   AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
   if test "${HAS_OPENH323:-unset}" != "unset" ; then
@@ -52,7 +63,7 @@ if test "${HAS_OPENH323:-unset}" = "unset" ; then
   fi
 fi
 
-if test "${HAS_OPENH323:-unset}" != "unset" ; then
+if test "${HAS_OPENH323:-unset}" != "unset" && test "${OPENH323_PKGCONFIG}" = ''; then
   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
     OPENH323_INCDIR="${OPENH323DIR}/include"
   fi
diff --git a/autoconf/ast_check_pwlib.m4 b/autoconf/ast_check_pwlib.m4
index 9d53dda..e4d2738 100644
--- a/autoconf/ast_check_pwlib.m4
+++ b/autoconf/ast_check_pwlib.m4
@@ -87,6 +87,13 @@ AC_DEFUN([AST_CHECK_PWLIB], [
 PWLIB_INCDIR=
 PWLIB_LIBDIR=
 AC_LANG_PUSH([C++])
+PKG_PROG_PKG_CONFIG
+PWLIB_PKGCONFIG=
+PKG_CHECK_MODULES(PWLIB, ptlib, [
+  PWLIB_LIB="${PWLIB_LIBS}"
+  HAS_PWLIB=1
+  PWLIB_PKGCONFIG=1
+]) 
 if test "${PWLIBDIR:-unset}" != "unset" ; then
   AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
 fi
@@ -147,7 +154,7 @@ fi
 #  exit
 #fi
 
-if test "${HAS_PWLIB:-unset}" != "unset" ; then
+if test "${HAS_PWLIB:-unset}" != "unset" && test "$PWLIB_PKGCONFIG" = ''; then
   if test "${PWLIBDIR:-unset}" = "unset" ; then
     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
       PWLIBDIR=`$PTLIB_CONFIG --prefix`
@@ -190,6 +197,7 @@ fi
   AC_LANG_POP([C++])
 ])
 
+dnl AST_CHECK_PWLIB_VERSION([PWLib], [PWLIB], [ptbuildopts.h], [1], [9], [2], [P[[WT]]LIB_VERSION])
 AC_DEFUN([AST_CHECK_PWLIB_VERSION], [
 	if test "x$7" != "x"; then
 	   	VNAME="$7"
@@ -197,7 +205,7 @@ AC_DEFUN([AST_CHECK_PWLIB_VERSION], [
 	   	VNAME="$2_VERSION"
 	fi
 
-	if test "${HAS_$2:-unset}" != "unset"; then
+	if test "${HAS_$2:-unset}" != "unset" && test "${$2_PKGCONFIG}" = ''; then
 		$2_VERSION=`grep "$VNAME" ${$2_INCDIR}/$3 | sed -e 's/[[[:space:]]]\{1,\}/ /g' | cut -f3 -d ' ' | sed -e 's/"//g'`
 		$2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
 		$2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
@@ -214,22 +222,37 @@ AC_DEFUN([AST_CHECK_PWLIB_VERSION], [
 		fi
 	fi
 ])
-
+dnl                 AST_CHECK_PWLIB_BUILD([PWLib], [PWLIB],
+dnl                     [Define if your system has the PWLib libraries.],
+dnl                     [#include "ptlib.h"],
+dnl                     [int q = (int) PTime::IsDaylightSavings();])
 AC_DEFUN([AST_CHECK_PWLIB_BUILD], [
 	if test "${HAS_$2:-unset}" != "unset"; then
 	   AC_MSG_CHECKING($1 installation validity)
 
 	   saved_cppflags="${CPPFLAGS}"
 	   saved_libs="${LIBS}"
+set -x
+	   echo >&2 "$2_LIB = <${$2_LIB}>"
 	   if test "${$2_LIB:-unset}" != "unset"; then
-	      LIBS="${LIBS} ${$2_LIB} $7"
+	      if test "${PTLIB_CONFIG}" != ''; then
+	         LIBS="${LIBS} ${$2_LIB}"
+	      else
+	         LIBS="${LIBS} ${$2_LIB} $7"
+	      fi
 	   else
     	      LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
 	   fi
-	   CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
+	   if test "${$2_CFLAGS}" = ""; then
+	      CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
+	   else
+	      CPPFLAGS="${CPPFLAGS} ${$2_CFLAGS}"
+	   fi
+set +x
 
 	   AC_LANG_PUSH([C++])
 
+	   set -x
 	   AC_LINK_IFELSE(
 		[AC_LANG_PROGRAM([$4],[$5])],
 		[	AC_MSG_RESULT(yes) 
@@ -239,6 +262,7 @@ AC_DEFUN([AST_CHECK_PWLIB_BUILD], [
 			ac_cv_lib_$2="no" 
 		]
 		)
+	   set +x
 
 	   AC_LANG_POP([C++])
 
diff --git a/configure b/configure
diff --git a/configure.ac b/configure.ac
index 922e7c4..289b121 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1543,8 +1543,8 @@ if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
 	AST_CHECK_PWLIB_BUILD([OpenH323], [OPENH323],
 		[Define if your system has the OpenH323 libraries.],
 		[#include "ptlib.h"
-		#include "h323.h"
-		#include "h323ep.h"],
+		#include <opal/h323/h323.h>
+		#include <opal/h323/h323ep.h>],
 		[H323EndPoint ep = H323EndPoint();],
 		[${PWLIB_INCLUDE}], [${PWLIB_LIB}])
 fi
