Skip to contentSkip to conversation

Add pkg-config support

PATCH Superseded Jeremy Sowden 3 participants 15 messages Jan 6, 2022 – Jan 8, 2022 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add pkg-config support

A number of third-party libraries have added pkg-config support over the years. This patch-set updates configure to make use it where it is available. It also fixes some conflicting option definitions and adds patches that causes configure to fail if a plugin has been explicitly requested but the related third-party library is not available.

Patch 1: switch from --with-blah to --enable-blah for output
plugins.
Patches 2-5: use pkg-config for libdbi, mysql, libpcap and libpq if
available.
Patches 6-10: abort configure when an output plugin has been explicitly
enabled, but the related library is not available.

Jeremy Sowden (10):
build: use --enable-blah flags for output plugins
build: use pkg-config for libdbi
build: use pkg-config or upstream M4 for mysql
build: use pkg-config or pcap-config for libpcap
build: use pkg-config for libpq if available
build: if --enable-dbi is yes abort if DBI is not found
build: if --enable-mysql is yes abort if MySQL is not found
build: if --enable-pcap is yes abort if libpcap is not found
build: if --enable-pgsql is yes abort if libpq is not found
build: if --enable-sqlite3 is yes abort if libsqlite3 is not found

 acinclude.m4             | 351 ---------------------------------------
 configure.ac             | 192 +++++++++++++++++----
 output/dbi/Makefile.am   |   4 +-
 output/pgsql/Makefile.am |   4 +-
 4 files changed, 161 insertions(+), 390 deletions(-)
 delete mode 100644 acinclude.m4
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/10 build: use `--enable-blah` flags for output plugins

Currently, we use AC_ARG_WITH for output plugins. However, this is not consistent with the input plugins, which use AC_ARG_ENABLE, and in some cases (dbi, mysql, pgsql) the macro calls in configure.ac conflict with other calls in acinclude.m4. Use AC_ARG_ENABLE instead and change the name of the flag for the JSON plugin from jansson to json.

Fixes 51ba7aec8951 ("Fix automagic support of dbi, pcap and sqlite3")
Fixes c61c05c2d050 ("configure.ac: Add --without-{mysql,pgsql}")
---
 configure.ac | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
configure.ac +20 -20
index b3e1c8f6b926..b24357dcd4b4 100644
@@ -78,47 +78,47 @@ AS_IF([test "x$enable_nfacct" = "xyes"],
       [enable_nfacct=no])
 AM_CONDITIONAL([BUILD_NFACCT], [test "x$enable_nfacct" = "xyes"])
 
-AC_ARG_WITH([pgsql],
-            [AS_HELP_STRING([--without-pgsql], [Build without postgresql output plugin [default=test]])])
-AS_IF([test "x$with_pgsql" != "xno"],
+AC_ARG_ENABLE([pgsql],
+              [AS_HELP_STRING([--enable-pgsql], [Enable PostgreSQL output plugin [default=test]])])
+AS_IF([test "x$enable_pgsql" != "xno"],
       [CT_CHECK_POSTGRES_DB()])
 AS_IF([test "x$PQLIBPATH" != "x"], [enable_pgsql=yes], [enable_pgsql=no])
 AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"])
 
-AC_ARG_WITH([mysql],
-            [AS_HELP_STRING([--without-mysql], [Build without mysql output plugin [default=test]])])
-AS_IF([test "x$with_mysql" != "xno"],
+AC_ARG_ENABLE([mysql],
+              [AS_HELP_STRING([--enable-mysql], [Enable MySQL output plugin [default=test]])])
+AS_IF([test "x$enable_mysql" != "xno"],
       [CT_CHECK_MYSQL_DB()])
 AS_IF([test "x$MYSQL_LIB" != "x"], [enable_mysql=yes], [enable_mysql=no])
 AM_CONDITIONAL([HAVE_MYSQL], [test "x$MYSQL_LIB" != "x"])
 
-AC_ARG_WITH([sqlite],
-            [AS_HELP_STRING([--without-sqlite], [Build without SQLITE3 output plugin [default=test]])])
-AS_IF([test "x$with_sqlite" != "xno"],
+AC_ARG_ENABLE([sqlite3],
+              [AS_HELP_STRING([--enable-sqlite3], [Enable SQLITE3 output plugin [default=test]])])
+AS_IF([test "x$enable_sqlite3" != "xno"],
       [PKG_CHECK_MODULES([libsqlite3], [sqlite3], [], [:])])
 AS_IF([test "x$libsqlite3_LIBS" != "x"], [enable_sqlite3=yes], [enable_sqlite3=no])
 AM_CONDITIONAL([HAVE_SQLITE3], [test "x$libsqlite3_LIBS" != "x"])
 
-AC_ARG_WITH([dbi],
-            [AS_HELP_STRING([--without-dbi], [Build without DBI output plugin [default=test]])])
-AS_IF([test "x$with_dbi" != "xno"],
+AC_ARG_ENABLE([dbi],
+              [AS_HELP_STRING([--enable-dbi], [Enable DBI output plugin [default=test]])])
+AS_IF([test "x$enable_dbi" != "xno"],
       [CT_CHECK_DBI()])
 AS_IF([test "x$DBI_LIB" != "x"], [enable_dbi=yes], [enable_dbi=no])
 AM_CONDITIONAL(HAVE_DBI, [test "x$DBI_LIB" != "x"])
 
-AC_ARG_WITH([pcap],
-            [AS_HELP_STRING([--without-pcap], [Build without PCAP output plugin [default=test]])])
-AS_IF([test "x$with_pcap" != "xno"],
+AC_ARG_ENABLE([pcap],
+              [AS_HELP_STRING([--enable-pcap], [Enable PCAP output plugin [default=test]])])
+AS_IF([test "x$enable_pcap" != "xno"],
       [AC_SEARCH_LIBS([pcap_close], [pcap], [libpcap_LIBS="-lpcap"; LIBS=""])
        AC_SUBST([libpcap_LIBS])])
 AS_IF([test "x$libpcap_LIBS" != "x"], [enable_pcap=yes], [enable_pcap=no])
 AM_CONDITIONAL([HAVE_PCAP], [test "x$libpcap_LIBS" != "x"])
 
-AC_ARG_WITH([jansson],
-            [AS_HELP_STRING([--without-jansson], [Build without JSON output plugin [default=test]])])
-AS_IF([test "x$with_jansson" != "xno"],
+AC_ARG_ENABLE([json],
+              [AS_HELP_STRING([--enable-json], [Enable JSON output plugin [default=test]])])
+AS_IF([test "x$enable_json" != "xno"],
       [PKG_CHECK_MODULES([libjansson], [jansson], [], [:])])
-AS_IF([test "x$libjansson_LIBS" != "x"], [enable_jansson=yes], [enable_jansson=no])
+AS_IF([test "x$libjansson_LIBS" != "x"], [enable_json=yes], [enable_json=no])
 AM_CONDITIONAL([HAVE_JANSSON], [test "x$libjansson_LIBS" != "x"])
 
 AC_ARG_WITH([ulogd2libdir],
@@ -182,6 +182,6 @@ Ulogd configuration:
     MySQL plugin:			${enable_mysql}
     SQLITE3 plugin:			${enable_sqlite3}
     DBI plugin:				${enable_dbi}
-    JSON plugin:			${enable_jansson}
+    JSON plugin:			${enable_json}
 "
 echo "You can now run 'make' and 'make install'"
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/10 build: use pkg-config for libdbi

In reply to Jeremy Sowden

libdbi introduced pkg-config support in 0.9.0, which was released in 2013. Use it.

---
 acinclude.m4           | 84 ------------------------------------------
 configure.ac           |  6 +--
 output/dbi/Makefile.am |  4 +-
 3 files changed, 5 insertions(+), 89 deletions(-)
acinclude.m4 +0 -84
index 8388c452aade..c7a1c67280f7 100644
@@ -265,87 +265,3 @@ fi
 
 ])
 
-dnl @synopsis CT_CHECK_DBI
-dnl
-dnl This macro tries to find the headers and libraries for libdbi.
-dnl
-dnl If includes are found, the variable DBI_INC will be set. If
-dnl libraries are found, the variable DBI_LIB will be set. if no check
-dnl was successful, the script exits with a error message.
-dnl
-dnl @category InstalledPackages
-dnl @author Pierre Chifflier <[email protected]>
-dnl @version 2008-10-30
-dnl @license AllPermissive
-
-AC_DEFUN([CT_CHECK_DBI], [
-
-AC_ARG_WITH(dbi,
-	[  --with-dbi=PREFIX		Prefix of your libdbi installation],
-	[dbi=$withval], [dbi_prefix=])
-AC_ARG_WITH(dbi-inc,
-	[  --with-dbi-inc=PATH		Path to the include directory of dbi],
-	[dbi_inc=$withval], [dbi_inc=/usr/include])
-AC_ARG_WITH(dbi-lib,
-	[  --with-dbi-lib=PATH		Path to the libraries of dbi],
-	[dbi_lib=$withval], [dbi_lib=/usr/lib])
-
-
-AC_SUBST(DBI_INC)
-AC_SUBST(DBI_LIB)
-
-if test "$dbi_prefix" != "no"; then
-
-if test "$dbi_prefix" != ""; then
-   AC_MSG_CHECKING([for libdbi includes in $dbi_prefix/include])
-   if test -f "$dbi_prefix/include/dbi.h" ; then
-      DBI_INC="-I$dbi_prefix/include"
-      AC_MSG_RESULT([yes])
-   elif test -f "$dbi_prefix/include/dbi/dbi.h" ; then
-      DBI_INC="-I$dbi_prefix/include/dbi"
-      AC_MSG_RESULT([yes])
-   else
-      AC_MSG_WARN(dbi.h not found)
-   fi
-   AC_MSG_CHECKING([for libdbi in $dbi_prefix/lib])
-   if test -f "$dbi_prefix/lib/libdbi.so" ; then
-      DBI_LIB="-L$dbi_prefix/lib -ldbi";
-      AC_MSG_RESULT([yes])
-   else
-      AC_MSG_WARN(libdbi.so not found)
-   fi
-else
-  if test "$dbi_inc" != ""; then
-    AC_MSG_CHECKING([for libdbi includes in $dbi_inc])
-    if test -f "$dbi_inc/dbi.h" ; then
-      DBI_INC="-I$dbi_inc"
-      AC_MSG_RESULT([yes])
-    elif test -f "$dbi_inc/dbi/dbi.h" ; then
-      DBI_INC="-I$dbi_inc/dbi"
-      AC_MSG_RESULT([yes])
-    else
-      AC_MSG_WARN(dbi.h not found)
-    fi
-  fi
-  if test "$dbi_lib" != ""; then
-    AC_MSG_CHECKING([for libdbi in $dbi_lib])
-    if test -f "$dbi_lib/libdbi.so" ; then
-      DBI_LIB="-L$dbi_lib -ldbi";
-      AC_MSG_RESULT([yes])
-    else
-      AC_MSG_WARN(libdbi.so not found)
-    fi
-  fi
-fi
-
-if test "$DBI_INC" = "" ; then
-  AC_CHECK_HEADER([dbi.h], [], AC_MSG_WARN(dbi.h not found))
-fi
-if test "$DBI_LIB" = "" ; then
-  AC_CHECK_LIB(dbi, dbi_close, [], AC_MSG_WARN(libdbi.so not found))
-fi
-
-fi
-
-])
-
configure.ac +3 -3
index b24357dcd4b4..a3ad198a1d33 100644
@@ -102,9 +102,9 @@ AM_CONDITIONAL([HAVE_SQLITE3], [test "x$libsqlite3_LIBS" != "x"])
 AC_ARG_ENABLE([dbi],
               [AS_HELP_STRING([--enable-dbi], [Enable DBI output plugin [default=test]])])
 AS_IF([test "x$enable_dbi" != "xno"],
-      [CT_CHECK_DBI()])
-AS_IF([test "x$DBI_LIB" != "x"], [enable_dbi=yes], [enable_dbi=no])
-AM_CONDITIONAL(HAVE_DBI, [test "x$DBI_LIB" != "x"])
+      [PKG_CHECK_MODULES([libdbi], [dbi], [], [:])])
+AS_IF([test "x$libdbi_LIBS" != "x"], [enable_dbi=yes], [enable_dbi=no])
+AM_CONDITIONAL([HAVE_DBI], [test "x$libdbi_LIBS" != "x"])
 
 AC_ARG_ENABLE([pcap],
               [AS_HELP_STRING([--enable-pcap], [Enable PCAP output plugin [default=test]])])
output/dbi/Makefile.am +2 -2
index f8b0a9c68c78..9a618b160559 100644
@@ -1,9 +1,9 @@
 include $(top_srcdir)/Make_global.am
 
-AM_CPPFLAGS += $(DBI_INC)
+AM_CPPFLAGS += $(libdbi_CFLAGS)
 
 pkglib_LTLIBRARIES = ulogd_output_DBI.la
 
 ulogd_output_DBI_la_SOURCES = ulogd_output_DBI.c ../../util/db.c
-ulogd_output_DBI_la_LIBADD  = ${DBI_LIB}
+ulogd_output_DBI_la_LIBADD  = $(libdbi_LIBS)
 ulogd_output_DBI_la_LDFLAGS = -avoid-version -module
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/10 build: use pkg-config or upstream M4 for mysql

In reply to Jeremy Sowden

Recent versions of mariadb and mysql have supported pkg-config. Older versions provide an m4 file containing macros for use with autoconf. Use them in preference to rolling our own.

---
 acinclude.m4 | 93 ----------------------------------------------------
 configure.ac | 53 +++++++++++++++++++++++++++---
 2 files changed, 49 insertions(+), 97 deletions(-)
acinclude.m4 +0 -93
index c7a1c67280f7..a49ed316e65a 100644
@@ -93,99 +93,6 @@ fi
 
 ])
 
-dnl @synopsis CT_CHECK_MYSQL_DB
-dnl
-dnl This macro tries to find the headers and librariess for the
-dnl MySQL database to build client applications.
-dnl
-dnl If includes are found, the variable MYSQL_INC will be set. If
-dnl libraries are found, the variable MYSQL_LIB will be set. if no check
-dnl was successful, the script exits with a error message.
-dnl
-dnl @category InstalledPackages
-dnl @author Harald Welte <[email protected]>
-dnl @version 2006-01-07
-dnl @license AllPermissive
-
-AC_DEFUN([CT_CHECK_MYSQL_DB], [
-
-AC_ARG_WITH(mysql,
-	[  --with-mysql=PREFIX		Prefix of your MySQL installation],
-	[my_prefix=$withval], [my_prefix=])
-AC_ARG_WITH(mysql-inc,
-	[  --with-mysql-inc=PATH		Path to the include directory of MySQL],
-	[my_inc=$withval], [my_inc=])
-AC_ARG_WITH(mysql-lib,
-	[  --with-mysql-lib=PATH		Path to the libraries of MySQL],
-	[my_lib=$withval], [my_lib=])
-
-
-AC_SUBST(MYSQL_INC)
-AC_SUBST(MYSQL_LIB)
-
-if test "$my_prefix" != "no"; then
-
-AC_MSG_CHECKING([for MySQL mysql_config program])
-for d in $my_prefix/bin /usr/bin /usr/local/bin /usr/local/mysql/bin /opt/mysql/bin /opt/packages/mysql/bin
-do
-	if test -x $d/mysql_config -a "$cross_compiling" = "no";
-	then
-		AC_MSG_RESULT(found mysql_config in $d)
-		MYSQL_INC=`$d/mysql_config --include`
-		MYSQL_LIB=`$d/mysql_config --libs`
-		break
-	fi
-done
-
-if test "$MYSQL_INC" = ""; then
-   if test "$my_prefix" != ""; then
-      AC_MSG_CHECKING([for MySQL includes in $my_prefix/include])
-      if test -f "$my_prefix/include/mysql.h" ; then
-         MYSQL_INC="-I$my_prefix/include"
-         AC_MSG_RESULT([yes])
-      else
-         AC_MSG_WARN(mysql.h not found)
-      fi
-      AC_MSG_CHECKING([for MySQL libraries in $my_prefix/lib])
-      if test -f "$my_prefix/lib/libmysql.so" ; then
-         MYSQL_LIB="-L$my_prefix/lib -lmysqlclient"
-         AC_MSG_RESULT([yes])
-      else
-         AC_MSG_WARN(libmysqlclient.so not found)
-      fi
-   else
-     if test "$my_inc" != ""; then
-       AC_MSG_CHECKING([for MySQL includes in $my_inc])
-       if test -f "$my_inc/mysql.h" ; then
-         MYSQL_INC="-I$my_inc"
-         AC_MSG_RESULT([yes])
-       else
-         AC_MSG_WARN(mysql.h not found)
-       fi
-     fi
-     if test "$my_lib" != ""; then
-       AC_MSG_CHECKING([for MySQL libraries in $my_lib])
-       if test -f "$my_lib/libmysqlclient.so" ; then
-         MYSQL_LIB="-L$my_lib -lmysqlclient"
-         AC_MSG_RESULT([yes])
-       else
-         AC_MSG_WARN(libmysqlclient.so not found)
-       fi
-     fi
-   fi
-fi
-
-if test "$MYSQL_INC" = "" ; then
-  AC_CHECK_HEADER([mysql.h], [], AC_MSG_WARN(mysql.h not found))
-fi
-if test "$MYSQL_LIB" = "" ; then
-  AC_CHECK_LIB(mysqlclient, mysql_close, [], AC_MSG_WARN(libmysqlclient.so not found))
-fi
-
-fi
-
-])
-
 dnl @synopsis CT_CHECK_PCAP
 dnl
 dnl This macro tries to find the headers and libraries for libpcap.
configure.ac +49 -4

59 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [ulogd2 PATCH 03/10] build: use pkg-config or upstream M4 for mysql

Quoted 1 line · Jeremy Sowden

Recent versions of mariadb and mysql have supported pkg-config.

(This made me read up on Stackexchange about exact rules for present perfect, only to find it is not neatly delineated.) IMO better to just use present. They (still) support pkg-config.

configure.ac AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"])

Quoted 4 lines
configure.ac +2 -0
+  dnl Recent versions of MySQL and MariaDB have included pkg-config support.
 
 
+  dnl Older versions have included an mysql.m4 file which provides macros to

"had included", as I don't see that m4 file anymore on my (mariadb) systems. (There are a few mysql-related m4 files in autoconf-archive,
but that's not the same package as mysql/mariadb, I suppose.)

configure.ac AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"]) · line 108

Quoted 3 lines
configure.ac +3 -0
+    dnl The [MYSQL_CLIENT] macro calls [_MYSQL_CONFIG] to locate mysql_config.
+
+    _MYSQL_CONFIG

One caveat of m4 macros is that they may be left unexpanded if not found, and it is up to the tarball producer to ensure the m4 macro is expanded. Over the years, I built the opinion that this is not always a nice experience to have.

I would do away with _MYSQL_CONFIG and just attempt to run mysql_config out the blue. sh failing to execute mysql_config, or a compiler failing to find mysql.h as part of AC_CHECK_HEADER is a nicer experience than _MYSQL_CONFIG being left accidentally unexpanded.

Quoted 1 line

+ dnl Some distro's don't put mysql_config in the same package as the

distros

#5 lore raw

Re: [ulogd2 PATCH 03/10] build: use pkg-config or upstream M4 for mysql

Quoted 9 lines · Jan Engelhardt
Quoted 1 line · Jeremy Sowden

Recent versions of mariadb and mysql have supported pkg-config.

(This made me read up on Stackexchange about exact rules for present perfect, only to find it is not neatly delineated.) IMO better to just use present. They (still) support pkg-config.

+ dnl Recent versions of MySQL and MariaDB include pkg-config support.

Quoted 2 lines

Suggest imperfect past tense, to match "recent versions" suggestion.

+ dnl Older versions included a mysql.m4 file which provided macros to

Quoted 23 lines

"had included", as I don't see that m4 file anymore on my (mariadb) systems. (There are a few mysql-related m4 files in autoconf-archive,
but that's not the same package as mysql/mariadb, I suppose.)

configure.ac AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"]) · line 108

Quoted 3 lines
configure.ac +3 -0
+    dnl The [MYSQL_CLIENT] macro calls [_MYSQL_CONFIG] to locate mysql_config.
+
+    _MYSQL_CONFIG

One caveat of m4 macros is that they may be left unexpanded if not found, and it is up to the tarball producer to ensure the m4 macro is expanded. Over the years, I built the opinion that this is not always a nice experience to have.

I would do away with _MYSQL_CONFIG and just attempt to run mysql_config out the blue. sh failing to execute mysql_config, or a compiler failing to find mysql.h as part of AC_CHECK_HEADER is a nicer experience than _MYSQL_CONFIG being left accidentally unexpanded.

Quoted 1 line

+ dnl Some distro's don't put mysql_config in the same package as the

distros

#6 lore raw

Re: [ulogd2 PATCH 03/10] build: use pkg-config or upstream M4 for mysql

In reply to Jan Engelhardt
Quoted 7 lines · Jan Engelhardt
Quoted 1 line · Jeremy Sowden

Recent versions of mariadb and mysql have supported pkg-config.

(This made me read up on Stackexchange about exact rules for present perfect, only to find it is not neatly delineated.) IMO better to just use present. They (still) support pkg-config.

Agreed.

Quoted 6 lines

configure.ac AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"]) · line 93

Quoted 2 lines
configure.ac +2 -0
+  dnl Recent versions of MySQL and MariaDB have included pkg-config support.
+  dnl Older versions have included an mysql.m4 file which provides macros to

"had included", as I don't see that m4 file anymore on my (mariadb) systems. (There are a few mysql-related m4 files in autoconf-archive,
but that's not the same package as mysql/mariadb, I suppose.)

It's still present in the libmariadb-dev 10.6 package in Debian Unstable.

Quoted 9 lines

configure.ac AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"]) · line 108

Quoted 3 lines
configure.ac +3 -0
+    dnl The [MYSQL_CLIENT] macro calls [_MYSQL_CONFIG] to locate mysql_config.
+
+    _MYSQL_CONFIG

One caveat of m4 macros is that they may be left unexpanded if not found, and it is up to the tarball producer to ensure the m4 macro is expanded. Over the years, I built the opinion that this is not always a nice experience to have.

Quoted 4 lines

I would do away with _MYSQL_CONFIG and just attempt to run mysql_config out the blue. sh failing to execute mysql_config, or a compiler failing to find mysql.h as part of AC_CHECK_HEADER is a nicer experience than _MYSQL_CONFIG being left accidentally unexpanded.

I'll use m4_ifdef to add a fall-back.

J.

#7 lore raw

Re: [ulogd2 PATCH 03/10] build: use pkg-config or upstream M4 for mysql

Quoted 11 lines · Jeremy Sowden
Quoted 10 lines · Jan Engelhardt

configure.ac AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"]) · line 108

Quoted 3 lines · Jeremy Sowden
configure.ac +3 -0
+    dnl The [MYSQL_CLIENT] macro calls [_MYSQL_CONFIG] to locate mysql_config.
+
+    _MYSQL_CONFIG

One caveat of m4 macros is that they may be left unexpanded if not found, and it is up to the tarball producer to ensure the m4 macro is expanded. Over the years, I built the opinion that this is not always a nice experience to have.

Quoted 6 lines
Quoted 4 lines

I would do away with _MYSQL_CONFIG and just attempt to run mysql_config out the blue. sh failing to execute mysql_config, or a compiler failing to find mysql.h as part of AC_CHECK_HEADER is a nicer experience than _MYSQL_CONFIG being left accidentally unexpanded.

I'll use m4_ifdef to add a fall-back.

I took another look at what the macros in mysql.m4 give us, and all we need is what we implement for libpcap and libpq, so I've updated the mysql patch to match those.

J.

#8 lore raw

PATCH 4/10 build: use pkg-config or pcap-config for libpcap

In reply to Jeremy Sowden

Recent versions of libpcap have supported pkg-config. Older versions provide an pcap-config script. Use pkg-config if available, otherwise fall back to pcap_config.

---
 acinclude.m4 | 79 ----------------------------------------------------
 configure.ac | 30 ++++++++++++++++++--
 2 files changed, 27 insertions(+), 82 deletions(-)
acinclude.m4 +0 -79
index a49ed316e65a..6d88c3a53cff 100644
@@ -93,82 +93,3 @@ fi
 
 ])
 
-dnl @synopsis CT_CHECK_PCAP
-dnl
-dnl This macro tries to find the headers and libraries for libpcap.
-dnl
-dnl If includes are found, the variable PCAP_INC will be set. If
-dnl libraries are found, the variable PCAP_LIB will be set. if no check
-dnl was successful, the script exits with a error message.
-dnl
-dnl @category InstalledPackages
-dnl @author Harald Welte <[email protected]>
-dnl @version 2006-01-07
-dnl @license AllPermissive
-
-AC_DEFUN([CT_CHECK_PCAP], [
-
-AC_ARG_WITH(pcap,
-	[  --with-pcap=PREFIX		Prefix of your libpcap installation],
-	[pcap_prefix=$withval], [pcap_prefix=])
-AC_ARG_WITH(pcap-inc,
-	[  --with-pcap-inc=PATH		Path to the include directory of pcap],
-	[pcap_inc=$withval], [pcap_inc=/usr/include])
-AC_ARG_WITH(pcap-lib,
-	[  --with-pcap-lib=PATH		Path to the libraries of pcap],
-	[pcap_lib=$withval], [pcap_lib=/usr/lib])
-
-
-AC_SUBST(PCAP_INC)
-AC_SUBST(PCAP_LIB)
-AC_SUBST(HAVE_PCAP_LIB)
-
-if test "$pcap_prefix" != "no"; then
-
-if test "$pcap_prefix" != ""; then
-   AC_MSG_CHECKING([for libpcap includes in $pcap_prefix/include])
-   if test -f "$pcap_prefix/include/pcap.h" ; then
-      PCAP_INC="-I$pcap_prefix/include"
-      AC_MSG_RESULT([yes])
-   else
-      AC_MSG_WARN(pcap.h not found)
-   fi
-   AC_MSG_CHECKING([for libpcap in $pcap_prefix/lib])
-   if test -f "$pcap_prefix/lib/libpcap.so" ; then
-      PCAP_LIB="-L$pcap_prefix/lib -lpcap";
-      AC_MSG_RESULT([yes])
-   else
-      AC_MSG_WARN(libpcap.so not found)
-   fi
-else
-  if test "$pcap_inc" != ""; then
-    AC_MSG_CHECKING([for libpcap includes in $pcap_inc])
-    if test -f "$pcap_inc/pcap.h" ; then
-      PCAP_INC="-I$pcap_inc"
-      AC_MSG_RESULT([yes])
-    else
-      AC_MSG_WARN(pcap.h not found)
-    fi
-  fi
-  if test "$pcap_lib" != ""; then
-    AC_MSG_CHECKING([for libpcap in $pcap_lib])
-    if test -f "$pcap_lib/libpcap.so" ; then
-      PCAP_LIB="-L$pcap_lib -lpcap";
-      AC_MSG_RESULT([yes])
-    else
-      AC_MSG_WARN(libpcap.so not found)
-    fi
-  fi
-fi
-
-if test "$PCAP_INC" = "" ; then
-  AC_CHECK_HEADER([pcap.h], [], AC_MSG_WARN(pcap.h not found))
-fi
-if test "$PCAP_LIB" = "" ; then
-  AC_CHECK_LIB(pcap, pcap_close, [HAVE_PCAP_LIB="yes"], AC_MSG_WARN(libpcap.so not found))
-fi
-
-fi
-
-])
-
configure.ac +27 -3
index 524fc151e2f3..bbca53e4c394 100644
@@ -153,9 +153,33 @@ AM_CONDITIONAL([HAVE_DBI], [test "x$libdbi_LIBS" != "x"])
 
 AC_ARG_ENABLE([pcap],
               [AS_HELP_STRING([--enable-pcap], [Enable PCAP output plugin [default=test]])])
-AS_IF([test "x$enable_pcap" != "xno"],
-      [AC_SEARCH_LIBS([pcap_close], [pcap], [libpcap_LIBS="-lpcap"; LIBS=""])
-       AC_SUBST([libpcap_LIBS])])
+AS_IF([test "x$enable_pcap" != "xno"], [
+
+  PKG_CHECK_EXISTS([libpcap], [PKG_CHECK_MODULES([libpcap], [libpcap])], [
+
+    AC_ARG_WITH([pcap-config],
+                [AS_HELP_STRING([--with-pcap-config=PATH], [Path to the pcap-config script])],
+                [pcap_config="$withval"], [pcap_config=pcap-config])
+
+    AC_MSG_CHECKING([for pcap-config])
+
+    AS_IF([command -v "$pcap_config" >/dev/null], [
+
+      libpcap_CFLAGS="`$pcap_config --cflags`"
+      libpcap_LIBS="`$pcap_config --libs`"
+
+      AC_SUBST([libpcap_CFLAGS])
+      AC_SUBST([libpcap_LIBS])
+
+      AC_MSG_RESULT([$pcap_config])
+
+    ], [
+      AC_MSG_RESULT([no])
+    ])
+
+  ])
+
+])
 AS_IF([test "x$libpcap_LIBS" != "x"], [enable_pcap=yes], [enable_pcap=no])
 AM_CONDITIONAL([HAVE_PCAP], [test "x$libpcap_LIBS" != "x"])
 
Signature · 1 line
2.34.1
#9 lore raw

PATCH 5/10 build: use pkg-config for libpq if available

In reply to Jeremy Sowden

Recent versions of postgresql have supported pkg-config. Use pkg-config if available, otherwise fall back to pg_config.

---
 acinclude.m4             | 95 ----------------------------------------
 configure.ac             | 33 ++++++++++++--
 output/pgsql/Makefile.am |  4 +-
 3 files changed, 31 insertions(+), 101 deletions(-)
 delete mode 100644 acinclude.m4
acinclude.m4 deleted +0 -95
deleted file mode 100644
index 6d88c3a53cff..000000000000
@@ -1,95 +0,0 @@
-dnl @synopsis CT_CHECK_POSTGRES_DB
-dnl
-dnl This macro tries to find the headers and libraries for the
-dnl PostgreSQL database to build client applications.
-dnl
-dnl If includes are found, the variable PQINCPATH will be set. If
-dnl libraries are found, the variable PQLIBPATH will be set. if no check
-dnl was successful, the script exits with a error message.
-dnl
-dnl @category InstalledPackages
-dnl @author Christian Toepp <[email protected]>
-dnl @version 2005-12-30
-dnl @license AllPermissive
-
-AC_DEFUN([CT_CHECK_POSTGRES_DB], [
-
-AC_ARG_WITH(pgsql,
-	[  --with-pgsql=PREFIX		Prefix of your PostgreSQL installation],
-	[pg_prefix=$withval], [pg_prefix=])
-AC_ARG_WITH(pgsql-inc,
-	[  --with-pgsql-inc=PATH		Path to the include directory of PostgreSQL],
-	[pg_inc=$withval], [pg_inc=])
-AC_ARG_WITH(pgsql-lib,
-	[  --with-pgsql-lib=PATH		Path to the libraries of PostgreSQL],
-	[pg_lib=$withval], [pg_lib=])
-
-
-AC_SUBST(PQINCPATH)
-AC_SUBST(PQLIBPATH)
-AC_SUBST(PQLIBS)
-PQLIBS=-lpq
-
-if test "$pg_prefix" != "no"; then
-
-AC_MSG_CHECKING([for PostgreSQL pg_config program])
-for d in $pg_prefix/bin /usr/bin /usr/local/bin /usr/local/pgsql/bin /opt/pgsql/bin /opt/packages/pgsql/bin
-do
-	if test -x $d/pg_config -a "$cross_compiling" = "no";
-	then
-		AC_MSG_RESULT(found pg_config in $d)
-		PQINCPATH=`$d/pg_config --includedir`
-		PQLIBPATH=`$d/pg_config --libdir`
-		break
-	fi
-done
-
-if test "$PQINCPATH" = ""; then
-   if test "$pg_prefix" != ""; then
-      AC_MSG_CHECKING([for PostgreSQL includes in $pg_prefix/include])
-      if test -f "$pg_prefix/include/libpq-fe.h" ; then
-         PQINCPATH="-I$pg_prefix/include"
-         AC_MSG_RESULT([yes])
-      else
-         AC_MSG_WARN(libpq-fe.h not found)
-      fi
-      AC_MSG_CHECKING([for PostgreSQL libraries in $pg_prefix/lib])
-      if test -f "$pg_prefix/lib/libpq.so" ; then
-         PQLIBPATH="-L$pg_prefix/lib"
-         AC_MSG_RESULT([yes])
-      else
-         AC_MSG_WARN(libpq.so not found)
-      fi
-   else
-     if test "$pg_inc" != ""; then
-       AC_MSG_CHECKING([for PostgreSQL includes in $pg_inc])
-       if test -f "$pg_inc/libpq-fe.h" ; then
-         PQINCPATH="-I$pg_inc"
-         AC_MSG_RESULT([yes])
-       else
-         AC_MSG_WARN(libpq-fe.h not found)
-       fi
-     fi
-     if test "$pg_lib" != ""; then
-       AC_MSG_CHECKING([for PostgreSQL libraries in $pg_lib])
-       if test -f "$pg_lib/libpq.so" ; then
-         PQLIBPATH="-L$pg_lib"
-         AC_MSG_RESULT([yes])
-       else
-         AC_MSG_WARN(libpq.so not found)
-       fi
-     fi
-   fi
-fi
-
-if test "$PQINCPATH" = "" ; then
-  AC_CHECK_HEADER([libpq-fe.h], [], AC_MSG_WARN(libpq-fe.h not found))
-fi
-if test "$PQLIBPATH" = "" ; then
-  AC_CHECK_LIB(pq, PQconnectdb, [], AC_MSG_WARN(libpq.so not found))
-fi
-
-fi
-
-])
-
configure.ac +29 -4
index bbca53e4c394..df6fa543e81f 100644
@@ -80,10 +80,35 @@ AM_CONDITIONAL([BUILD_NFACCT], [test "x$enable_nfacct" = "xyes"])
 
 AC_ARG_ENABLE([pgsql],
               [AS_HELP_STRING([--enable-pgsql], [Enable PostgreSQL output plugin [default=test]])])
-AS_IF([test "x$enable_pgsql" != "xno"],
-      [CT_CHECK_POSTGRES_DB()])
-AS_IF([test "x$PQLIBPATH" != "x"], [enable_pgsql=yes], [enable_pgsql=no])
-AM_CONDITIONAL([HAVE_PGSQL], [test "x$PQLIBPATH" != "x"])
+AS_IF([test "x$enable_pgsql" != "xno"], [
+
+  PKG_CHECK_EXISTS([libpq], [PKG_CHECK_MODULES([libpq], [libpq])], [
+
+    AC_ARG_WITH([pg_config],
+                [AS_HELP_STRING([--with-pg-config=PATH], [Path to the pg_config script])],
+                [pg_config="$withval"], [pg_config=pg_config])
+
+    AC_MSG_CHECKING([for pg_config])
+
+    AS_IF([command -v "$pg_config" >/dev/null], [
+
+      libpq_CFLAGS="`$pg_config --includedir`"
+      libpq_LIBS="`$pg_config --libdir` -lpq"
+
+      AC_SUBST([libpq_CFLAGS])
+      AC_SUBST([libpq_LIBS])
+
+      AC_MSG_RESULT([$pg_config])
+
+    ], [
+      AC_MSG_RESULT([no])
+    ])
+
+  ])
+
+])
+AS_IF([test "x$libpq_LIBS" != "x"], [enable_pgsql=yes], [enable_pgsql=no])
+AM_CONDITIONAL([HAVE_PGSQL], [test "x$libpq_LIBS" != "x"])
 
 AC_ARG_ENABLE([mysql],
               [AS_HELP_STRING([--enable-mysql], [Enable MySQL output plugin [default=test]])])
output/pgsql/Makefile.am +2 -2
index 9cdf22d7f765..c458c04900ba 100644
@@ -1,9 +1,9 @@
 include $(top_srcdir)/Make_global.am
 
-AM_CPPFLAGS += -I$(PQINCPATH)
+AM_CPPFLAGS += -I$(libpq_CFLAGS)
 
 pkglib_LTLIBRARIES = ulogd_output_PGSQL.la
 
 ulogd_output_PGSQL_la_SOURCES = ulogd_output_PGSQL.c ../../util/db.c
-ulogd_output_PGSQL_la_LIBADD  = ${PQLIBS}
+ulogd_output_PGSQL_la_LIBADD  = $(libpq_LIBS)
 ulogd_output_PGSQL_la_LDFLAGS = -avoid-version -module
Signature · 1 line
2.34.1
#10 lore raw

PATCH 6/10 build: if `--enable-dbi` is `yes` abort if DBI is not found

In reply to Jeremy Sowden

If DBI support has been explicitly requested, abort if it is not available.

---
 configure.ac | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
configure.ac +7 -2
index df6fa543e81f..b6b44de888ec 100644
@@ -171,8 +171,13 @@ AM_CONDITIONAL([HAVE_SQLITE3], [test "x$libsqlite3_LIBS" != "x"])
 
 AC_ARG_ENABLE([dbi],
               [AS_HELP_STRING([--enable-dbi], [Enable DBI output plugin [default=test]])])
-AS_IF([test "x$enable_dbi" != "xno"],
-      [PKG_CHECK_MODULES([libdbi], [dbi], [], [:])])
+AS_IF([test "x$enable_dbi" != "xno"], [
+  PKG_CHECK_MODULES([libdbi], [dbi], [], [
+    AS_IF([test "x$enable_dbi" = "xyes"], [
+      AC_MSG_ERROR([$libdbi_PKG_ERRORS])
+    ])
+  ])
+])
 AS_IF([test "x$libdbi_LIBS" != "x"], [enable_dbi=yes], [enable_dbi=no])
 AM_CONDITIONAL([HAVE_DBI], [test "x$libdbi_LIBS" != "x"])
 
Signature · 1 line
2.34.1
#11 lore raw

PATCH 7/10 build: if `--enable-mysql` is `yes` abort if MySQL is not found

In reply to Jeremy Sowden

If MySQL support has been explicitly requested, abort if it is not available.

---
 configure.ac | 6 ++++++
 1 file changed, 6 insertions(+)
configure.ac +6 -0
index b6b44de888ec..67f489c22433 100644
@@ -156,6 +156,12 @@ AS_IF([test "x$enable_mysql" != "xno"], [
 
     ])
 
+    AS_IF([test "x$libmysqlclient_LIBS" = "x"], [
+      AS_IF([test "x$enable_mysql" = "xyes"], [
+        AC_MSG_ERROR([libmysqlclient not found])
+      ])
+    ])
+
   ])
 
 ])
Signature · 1 line
2.34.1
#12 lore raw

PATCH 8/10 build: if `--enable-pcap` is `yes` abort if libpcap is not found

In reply to Jeremy Sowden

If libpcap support has been explicitly requested, abort if it is not available.

---
 configure.ac | 6 ++++++
 1 file changed, 6 insertions(+)
configure.ac +6 -0
index 67f489c22433..4d65d234be69 100644
@@ -213,6 +213,12 @@ AS_IF([test "x$enable_pcap" != "xno"], [
       AC_MSG_RESULT([no])
     ])
 
+    AS_IF([test "x$libpcap_LIBS" = "x"], [
+      AS_IF([test "x$enable_pcap" = "xyes"], [
+        AC_MSG_ERROR([libpcap not found])
+      ])
+    ])
+
   ])
 
 ])
Signature · 1 line
2.34.1
#13 lore raw

PATCH 9/10 build: if `--enable-pgsql` is `yes` abort if libpq is not found

In reply to Jeremy Sowden

If PostgreSQL support has been explicitly requested, abort if it is not available.

---
 configure.ac | 6 ++++++
 1 file changed, 6 insertions(+)
configure.ac +6 -0
index 4d65d234be69..fd033164b872 100644
@@ -104,6 +104,12 @@ AS_IF([test "x$enable_pgsql" != "xno"], [
       AC_MSG_RESULT([no])
     ])
 
+    AS_IF([test "x$libpq_LIBS" = "x"], [
+      AS_IF([test "x$enable_pgsql" = "xyes"], [
+        AC_MSG_ERROR([libpq not found])
+      ])
+    ])
+
   ])
 
 ])
Signature · 1 line
2.34.1
#14 lore raw

PATCH 10/10 build: if `--enable-sqlite3` is `yes` abort if libsqlite3 is not found

In reply to Jeremy Sowden

If SQLITE3 support has been explicitly requested, abort if it is not available.

---
 configure.ac | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
configure.ac +7 -2
index fd033164b872..1469f0f253d7 100644
@@ -176,8 +176,13 @@ AM_CONDITIONAL([HAVE_MYSQL], [test "x$libmysqlclient_LIBS" != "x"])
 
 AC_ARG_ENABLE([sqlite3],
               [AS_HELP_STRING([--enable-sqlite3], [Enable SQLITE3 output plugin [default=test]])])
-AS_IF([test "x$enable_sqlite3" != "xno"],
-      [PKG_CHECK_MODULES([libsqlite3], [sqlite3], [], [:])])
+AS_IF([test "x$enable_sqlite3" != "xno"], [
+  PKG_CHECK_MODULES([libsqlite3], [sqlite3], [], [
+    AS_IF([test "x$enable_sqlite3" = "xyes"], [
+      AC_MSG_ERROR([$libsqlite3_PKG_ERRORS])
+    ])
+  ])
+])
 AS_IF([test "x$libsqlite3_LIBS" != "x"], [enable_sqlite3=yes], [enable_sqlite3=no])
 AM_CONDITIONAL([HAVE_SQLITE3], [test "x$libsqlite3_LIBS" != "x"])
 
Signature · 1 line
2.34.1