From: Karl Fleischmann Date: Wed, 8 Jun 2022 11:10:00 +0000 (+0200) Subject: m4: Rewrite want_pgsql.m4 to use pkg_config X-Git-Tag: 2.4.0~3860 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=863af406a550f71783dd40935bc5ccaf9a65cc5e;p=thirdparty%2Fdovecot%2Fcore.git m4: Rewrite want_pgsql.m4 to use pkg_config 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. --- diff --git a/configure.ac b/configure.ac index 991807631a..bea523e94c 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/m4/want_pgsql.m4 b/m4/want_pgsql.m4 index b8e6ef3627..a53b02fddb 100644 --- a/m4/want_pgsql.m4 +++ b/m4/want_pgsql.m4 @@ -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]) + ]) ])