Index: m4/ax_codepatterns.m4
===================================================================
--- m4/ax_codepatterns.m4	(revision cdf2e4b35fbdd7c3205205e770e338e51473ef11)
+++ m4/ax_codepatterns.m4	(revision 392a790dccf19cbcf2dcb014e987e0d37c968eb5)
@@ -1,4 +1,4 @@
 dnl
-dnl AM_PATH_CODEPATTERNS(MINIMUM-VERSION, [no]debug, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl AM_PATH_CODEPATTERNS(MINIMUM-VERSION, [HAVE_DEBUG=no,yes,full], [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
 dnl
 
@@ -25,10 +25,14 @@
   # try to set PKG_CONFIG_PATH
   if test x$codepatterns_prefix != xno; then
-    PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$codepatterns_prefix/lib/pkgconfig/"
+    if test -z $PKG_CONFIG_PATH; then
+      export PKG_CONFIG_PATH="$codepatterns_prefix/lib/pkgconfig/"
+    else
+      export PKG_CONFIG_PATH="$codepatterns_prefix/lib/pkgconfig/:$PKG_CONFIG_PATH"
+    fi
   fi
   # 1. test whether pkg-config works
   CodePatterns_CONFIG="no"
-  #AC_MSG_NOTICE([PKG_CONFIG_PATH is $PKG_CONFIG_PATH])
-  if test x$codepatterns_debug != x0; then
+  #AC_MSG_NOTICE([PKG_CONFIG_PATH is $PKG_CONFIG_PATH.])
+  if test x$codepatterns_debug != xno; then
     codepatterns_libname="CodePatterns-debug"
     PKG_CHECK_MODULES([CodePatterns_debug], [CodePatterns >= $codepatterns_version_min], [
@@ -55,7 +59,11 @@
       AC_PATH_PROG(CodePatterns_CONFIG, codepatterns-config, no)
       if test "x$CodePatterns_CONFIG" = xno && test x$codepatterns_prefix != x ; then
+        AC_MSG_CHECKING([for alternative codepatterns-config location])
         if test -e $codepatterns_prefix/bin/codepatterns-config; then
           codepatterns_pkgconfig=no
           CodePatterns_CONFIG="$codepatterns_prefix/bin/codepatterns-config"
+          AC_MSG_RESULT([yes])
+        else
+          AC_MSG_RESULT([no])
         fi
       fi
@@ -67,6 +75,10 @@
   if test "x$CodePatterns_CONFIG" != xno; then 
     CodePatterns_CFLAGS=`$CodePatterns_CONFIG --cflags`
-    CodePatterns_LIBS=`$CodePatterns_CONFIG --libs`
-    AC_MSG_NOTICE([codepatterns-config found and used.])
+    if test x$codepatterns_pkgconfig = xno; then
+      CodePatterns_LIBS=`$CodePatterns_CONFIG --ldflags --libs`
+    else
+      CodePatterns_LIBS=`$CodePatterns_CONFIG --libs`
+    fi
+    #AC_MSG_NOTICE([codepatterns-config found and used.])
   fi
 
@@ -75,5 +87,5 @@
     if test -e $codepatterns_include_prefix/include; then
       CodePatterns_CFLAGS="$codepatterns_include_prefix/include"
-      AC_MSG_NOTICE([codepatterns include found and used.])
+      #AC_MSG_NOTICE([codepatterns include found and used.])
     else
       AC_MSG_WARN([codepatterns include not found at $codepatterns_include_prefix/include.])
@@ -83,5 +95,5 @@
     if test -e "$cp_cv_codepatterns_libs_prefix/lib/lib$codepatterns_libname.so"; then
       CodePatterns_LIBS="-L$cp_cv_codepatterns_libs_prefix/lib -l$codepatterns_libname"
-      AC_MSG_NOTICE([codepatterns libs found and used.])
+      #AC_MSG_NOTICE([codepatterns libs found and used.])
     else
       AC_MSG_WARN([codepatterns libs not found at $cp_cv_codepatterns_libs_prefix.])
@@ -166,18 +178,21 @@
       fi
     fi
-
-    # check presence of lib
-    SAVE_CPPFLAGS="$CPPFLAGS"
-    SAVE_LIBS="$LIBS"
-    CPPFLAGS="$CodePatterns_CFLAGS"
-    LIBS="$CodePatterns_LIBS -lboost_thread"
-    if test x$codepatterns_version = xyes; then
-      AC_CACHE_CHECK(for $codepatterns_libname lib, cp_cv_codepatterns_lib, [
-        AC_LANG_PUSH([C++])
-        AC_LINK_IFELSE(
-          [
-            AC_LANG_PROGRAM([
-#include "Patterns/Singleton.hpp"
-#include "Patterns/Singleton_impl.hpp"
+  else
+    # with pkg-config version is checked
+    codepatterns_version=yes
+  fi
+  # check presence of lib
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  SAVE_LIBS="$LIBS"
+  CPPFLAGS="$CodePatterns_CFLAGS"
+  LIBS="$CodePatterns_LIBS -lboost_thread"
+  if test x$codepatterns_version = xyes; then
+    AC_CACHE_CHECK(for $codepatterns_libname lib, cp_cv_codepatterns_lib, [
+      AC_LANG_PUSH([C++])
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM([
+#include "CodePatterns/Singleton.hpp"
+#include "CodePatterns/Singleton_impl.hpp"
 
 // some necessary stubs
@@ -206,24 +221,23 @@
 SingletonStub::getInstance();
 ])
-          ],[
-            cp_cv_codepatterns_lib="yes"
-          ], [
-            cp_cv_codepatterns_lib="no"
-          ]
-        )
-        AC_LANG_POP([C++])
-      ])
-    fi
-    CPPFLAGS="$SAVE_CPPFLAGS"
-    LIBS="$SAVE_LIBS"
-
-    if test "x$cp_cv_codepatterns_lib" = xyes ; then
-       ifelse([$3], , :, [$3])     
-    else
-       CodePatterns_CFLAGS=""
-       CodePatterns_LDFLAGS=""
-       CodePatterns_LIBS=""
-       ifelse([$4], , :, [$4])
-    fi
+        ],[
+          cp_cv_codepatterns_lib="yes"
+        ], [
+          cp_cv_codepatterns_lib="no"
+        ]
+      )
+      AC_LANG_POP([C++])
+    ])
+  fi
+  CPPFLAGS="$SAVE_CPPFLAGS"
+  LIBS="$SAVE_LIBS"
+
+  if test "x$cp_cv_codepatterns_lib" = xyes ; then
+    ifelse([$3], , :, [$3])
+  else
+     CodePatterns_CFLAGS=""
+     CodePatterns_LDFLAGS=""
+     CodePatterns_LIBS=""
+     ifelse([$4], , :, [$4])
   fi
   
