dev  

dbd pgsql autotools patch

Bob Rossi
Thu, 15 May 2008 06:09:38 -0700

Hi,

I just downloaded and installed postgresql, and installed it into a
root. Then I used the apr-util option --with-pgsql. The apr-util
autotools machinary failed. That's because it tries to link a program
against -lpg, but doesn't use the other libs specified in pg_config. So,
I get a link error, because it needs to link against -lcrypt.

Attached is the patch that fixes the problem, what do you think?

Bob Rossi
--- apr-util-2006-12-14-cvs-2/apr-util-2006-12-14-cvs/build/dbd.m4	2006-12-14 20:41:02.000000000 -0500
+++ apr-util-2006-12-14-cvs-3/apr-util-2006-12-14-cvs/build/dbd.m4	2008-05-15 08:50:59.000000000 -0400
@@ -29,9 +29,14 @@
   ], [
     apu_have_pgsql=0
     if test "$withval" = "yes"; then
-      AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
+      AC_PATH_PROG([PG_CONFIG],[pg_config])
+      if test "x$PG_CONFIG" != 'x'; then
+          pgsql_LIBS="`$withval/bin/pg_config --libs`"
+      fi
+
+      AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1], [], [$pgsql_LIBS]))
       if test "$apu_have_pgsql" = "0"; then
-        AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
+        AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1], [], [$pgsql_LIBS]))
       fi
     elif test "$withval" = "no"; then
       apu_have_pgsql=0
@@ -41,18 +46,21 @@
 
       pgsql_CPPFLAGS="-I$withval/include"
       pgsql_LDFLAGS="-L$withval/lib "
+      if test -e "$withval/bin/pg_config"; then
+        pgsql_LIBS="`$withval/bin/pg_config --libs`"
+      fi
 
       APR_ADDTO(CPPFLAGS, [$pgsql_CPPFLAGS])
       APR_ADDTO(LDFLAGS, [$pgsql_LDFLAGS])
 
       AC_MSG_NOTICE(checking for pgsql in $withval)
-      AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
+      AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1], [], [$pgsql_LIBS]))
       if test "$apu_have_pgsql" != "0"; then
         APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
       fi
       if test "$apu_have_pgsql" != "1"; then
-        AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
+        AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1], [], [$pgsql_LIBS]))
         if test "$apu_have_pgsql" != "0"; then
           APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include/postgresql])
           APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
@@ -70,8 +78,8 @@
   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
   dnl we know the library is there.
   if test "$apu_have_pgsql" = "1"; then
-    APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lpq])
-    APR_ADDTO(APRUTIL_LIBS,[-lpq])
+    APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lpq $pgsql_LIBS])
+    APR_ADDTO(APRUTIL_LIBS,[-lpq $pgsql_LIBS])
   fi
 ])
 dnl