Index: m4/ax_codepatterns.m4
===================================================================
--- m4/ax_codepatterns.m4	(revision 1153789c0fdd2face0a0ff8e099fb6e0a7454307)
+++ m4/ax_codepatterns.m4	(revision cdf2e4b35fbdd7c3205205e770e338e51473ef11)
@@ -1,4 +1,4 @@
 dnl
-dnl AM_PATH_CODEPATTERNS(MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl AM_PATH_CODEPATTERNS(MINIMUM-VERSION, [no]debug, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
 dnl
 
@@ -15,4 +15,5 @@
 
   codepatterns_version_min=$1
+  codepatterns_debug=$2
 
   CodePatterns_CFLAGS=""
@@ -27,13 +28,15 @@
   fi
   # 1. test whether pkg-config works
-  CodePatterns_CONFIG=""
+  CodePatterns_CONFIG="no"
   #AC_MSG_NOTICE([PKG_CONFIG_PATH is $PKG_CONFIG_PATH])
-  PKG_CHECK_MODULES([CodePatterns], [CodePatterns >= $codepatterns_version_min], [
+  if test x$codepatterns_debug != x0; then
+    codepatterns_libname="CodePatterns-debug"
+    PKG_CHECK_MODULES([CodePatterns_debug], [CodePatterns >= $codepatterns_version_min], [
       codepatterns_pkgconfig=yes
-      CodePatterns_CONFIG="pkg-config CodePatterns"
+      CodePatterns_CONFIG="pkg-config $codepatterns_libname"
     ], [
     # 2. if failed, test for binary codepatterns-config
       AC_PATH_PROG(CodePatterns_CONFIG, codepatterns-config, no)
-      if test x$CodePatterns_CONFIG = xno && test x$codepatterns_prefix != x ; then
+      if test "x$CodePatterns_CONFIG" = xno && test x$codepatterns_prefix != x ; then
         if test -e $codepatterns_prefix/bin/codepatterns-config; then
           codepatterns_pkgconfig=no
@@ -41,9 +44,26 @@
         fi
       fi
-    ]
-  )
+    ])
+
+  else
+    codepatterns_libname="CodePatterns"
+    PKG_CHECK_MODULES([CodePatterns], [CodePatterns >= $codepatterns_version_min], [
+      codepatterns_pkgconfig=yes
+      CodePatterns_CONFIG="pkg-config $codepatterns_libname"
+    ], [
+    # 2. if failed, test for binary codepatterns-config
+      AC_PATH_PROG(CodePatterns_CONFIG, codepatterns-config, no)
+      if test "x$CodePatterns_CONFIG" = xno && test x$codepatterns_prefix != x ; then
+        if test -e $codepatterns_prefix/bin/codepatterns-config; then
+          codepatterns_pkgconfig=no
+          CodePatterns_CONFIG="$codepatterns_prefix/bin/codepatterns-config"
+        fi
+      fi
+    ])
+
+  fi
 
   # try to set values via CodePatterns_CONFIG
-  if test ! -z "$CodePatterns_CONFIG"; then 
+  if test "x$CodePatterns_CONFIG" != xno; then 
     CodePatterns_CFLAGS=`$CodePatterns_CONFIG --cflags`
     CodePatterns_LIBS=`$CodePatterns_CONFIG --libs`
@@ -61,6 +81,6 @@
   fi
   if test x$cp_cv_codepatterns_libs_prefix != x ; then
-    if test -e "$cp_cv_codepatterns_libs_prefix/lib/libCodePatterns.so"; then
-      CodePatterns_LIBS="-L$cp_cv_codepatterns_libs_prefix/lib -lCodePatterns"
+    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.])
     else
@@ -82,6 +102,6 @@
     codepatterns_version=no
     if test x$codepatterns = xyes; then
-      AC_MSG_CHECKING(for CodePatterns - version >= $codepatterns_version_min)
-      if test "x$CodePatterns_CONFIG" != "x"; then
+      AC_MSG_CHECKING(for $codepatterns_libname - version >= $codepatterns_version_min)
+      if test "x$CodePatterns_CONFIG" != xno; then
         codepatterns_version=`$CodePatterns_CONFIG --version`
       else
@@ -153,5 +173,5 @@
     LIBS="$CodePatterns_LIBS -lboost_thread"
     if test x$codepatterns_version = xyes; then
-      AC_CACHE_CHECK(for CodePatterns lib, cp_cv_codepatterns_lib, [
+      AC_CACHE_CHECK(for $codepatterns_libname lib, cp_cv_codepatterns_lib, [
         AC_LANG_PUSH([C++])
         AC_LINK_IFELSE(
@@ -199,10 +219,10 @@
 
     if test "x$cp_cv_codepatterns_lib" = xyes ; then
-       ifelse([$2], , :, [$2])     
+       ifelse([$3], , :, [$3])     
     else
        CodePatterns_CFLAGS=""
        CodePatterns_LDFLAGS=""
        CodePatterns_LIBS=""
-       ifelse([$3], , :, [$3])
+       ifelse([$4], , :, [$4])
     fi
   fi
