]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
m4: Rewrite want_pgsql.m4 to use pkg_config
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Wed, 8 Jun 2022 11:10:00 +0000 (13:10 +0200)
committerKarl Fleischmann <karl.fleischmann@open-xchange.com>
Mon, 4 Jul 2022 09:43:26 +0000 (11:43 +0200)
Manually checking for headers/libraries requires the user to know and
pass non-default library-paths when configuring the project. Using
pkg_config simplifies the macro and automatically sets the
compiler/linker flags accordingly.

configure.ac
m4/want_pgsql.m4

index 991807631a8497147a15ebf444ef77bf9cecb707..bea523e94c130c55b46e88a239a86449a4ea346e 100644 (file)
@@ -557,8 +557,6 @@ AC_SUBST(SQL_CFLAGS)
 AC_SUBST(SQL_LIBS)
 AC_SUBST(MYSQL_CFLAGS)
 AC_SUBST(MYSQL_LIBS)
-AC_SUBST(PGSQL_CFLAGS)
-AC_SUBST(PGSQL_LIBS)
 
 AC_SUBST(DICT_LIBS)
 AC_SUBST(CDB_LIBS)
index b8e6ef36278d83324a8846a2cedc46ead2909170..a53b02fddbccab49f6d1ddf5718b2e2def07833e 100644 (file)
@@ -1,61 +1,25 @@
 AC_DEFUN([DOVECOT_WANT_PGSQL], [
-  if test $want_pgsql != no; then
-    AC_CHECK_PROG(PG_CONFIG, pg_config, pg_config, NO)
-    if test $PG_CONFIG = NO; then
-      # based on code from PHP
-      for i in /usr /usr/local /usr/local/pgsql; do
-        for j in include include/pgsql include/postgres include/postgresql ""; do
-       if test -r "$i/$j/libpq-fe.h"; then
-         PGSQL_INCLUDE=$i/$j
-       fi
-        done
-        for lib in lib lib64; do
-       for j in $lib $lib/pgsql $lib/postgres $lib/postgresql ""; do
-         if test -f "$i/$j/libpq.so" || test -f "$i/$j/libpq.a"; then
-           PGSQL_LIBDIR=$i/$j
-         fi
-       done
-        done
-      done
-    else
-      PGSQL_INCLUDE="`$PG_CONFIG --includedir`"
-      PGSQL_LIBDIR="`$PG_CONFIG --libdir`"  
-    fi
-  
-    old_LIBS=$LIBS
-    if test "$PGSQL_LIBDIR" != ""; then
-      LIBS="$LIBS -L$PGSQL_LIBDIR"
-    fi
-  
-    AC_CHECK_LIB(pq, PQconnectdb, [
-         AC_CHECK_LIB(pq, PQescapeStringConn, [
-                 AC_DEFINE(HAVE_PQESCAPE_STRING_CONN,, [Define if libpq has PQescapeStringConn function])
-         ])
-         old_CPPFLAGS=$CPPFLAGS
-         if test "$PGSQL_INCLUDE" != ""; then
-                 CPPFLAGS="$CPPFLAGS -I$PGSQL_INCLUDE"
-         fi
-         AC_CHECK_HEADER(libpq-fe.h, [
-                 if test "$PGSQL_INCLUDE" != ""; then
-                         PGSQL_CFLAGS="$PGSQL_CFLAGS -I$PGSQL_INCLUDE"
-                 fi
-                 if test "$PGSQL_LIBDIR" != ""; then
-                         PGSQL_LIBS="$PGSQL_LIBS -L$PGSQL_LIBDIR"
-                 fi
-                 PGSQL_LIBS="$PGSQL_LIBS -lpq"
-                 AC_DEFINE(HAVE_PGSQL,, [Build with PostgreSQL support])
-                 found_sql_drivers="$found_sql_drivers pgsql"
-         ], [
-           if test $want_pgsql = yes; then
-             AC_MSG_ERROR(cannot build with PostgreSQL support: libpq-fe.h not found)
-           fi
-         ])
-         CPPFLAGS=$old_CPPFLAGS
-    ], [
-      if test $want_pgsql = yes; then
-        AC_MSG_ERROR(cannot build with PostgreSQL support: libpq not found)
-      fi
+  have_pgsql=no
+
+  AS_IF([test "$want_pgsql" != "no"], [
+    PKG_CHECK_MODULES([PGSQL], [libpq], [have_pgsql=yes], [
+      have_pgsql=no
+
+      AS_IF([test "$want_pgsql" = "yes"], [
+        AC_MSG_ERROR([cannot build with PostgreSQL support: PostgreSQL library (libpq) not found])
+      ])
     ])
-    LIBS=$old_LIBS
-  fi
+  ])
+
+  AS_IF([test "$have_pgsql" != "no"], [
+    found_sql_drivers="$found_sql_drivers pgsql"
+
+    AC_CHECK_LIB(pq, PQescapeStringConn, [
+      AC_DEFINE(HAVE_PQESCAPE_STRING_CONN,, [
+        Define if libpq has PQescapeStringConn function
+      ])
+    ],, $PGSQL_LIBS)
+
+    AC_DEFINE(HAVE_PGSQL,, [Build with PostgreSQL support])
+  ])
 ])