From fc757abab9a3ec3e91bd6428ce79e9bd187e8d1a Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Tue, 7 Mar 2017 14:40:40 +0100 Subject: [PATCH] build: check for udev and kmod using pkg-config Using AC_CHECK_LIB is dangerous because it modifies the global LIBS variable that will be passed to each linker invocation. If care is not taken, each binary will end up depending on libraries listed in this variable. A typical way to avoid this is to save and restore the LIBS variable before and after the AC_CHECK_LIB function, respectively. That's quite tedious, though, and often a better solution is to detect the presence as well as compile and linker flags with pkg-config. This can be done using the PKG_CHECK_MODULES autoconf macro. Both udev and kmod ship pkg-config files, so use PKG_CHECK_MODULES for them. Signed-off-by: Thierry Reding Signed-off-by: Bartosz Golaszewski --- configure.ac | 12 +++--------- tests/unit/Makefile.am | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 946059b..8117e45 100644 --- a/configure.ac +++ b/configure.ac @@ -96,21 +96,15 @@ AC_ARG_ENABLE([tests], [with_tests=false]) AM_CONDITIONAL([WITH_TESTS], [test "x$with_tests" = xtrue]) -AC_DEFUN([HEADER_NOT_FOUND_TESTS], - [ERR_NOT_FOUND([$1 header], [tests])]) - AC_DEFUN([FUNC_NOT_FOUND_TESTS], [ERR_NOT_FOUND([$1()], [tests])]) if test "x$with_tests" = xtrue then - AC_CHECK_LIB([kmod], [kmod_module_probe_insert_module], [], - [AC_MSG_ERROR([libkmod not found (needed to build tests])]) - AC_CHECK_LIB([udev], [udev_monitor_new_from_netlink], [], - [AC_MSG_ERROR([libudev not found (needed to build tests])]) - AC_CHECK_HEADERS([libkmod.h], [], [HEADER_NOT_FOUND_TESTS([libkmod.h])]) - AC_CHECK_HEADERS([libudev.h], [], [HEADER_NOT_FOUND_TESTS([libudev.h])]) AC_CHECK_FUNC([qsort], [], [FUNC_NOT_FOUND_TESTS([qsort])]) + + PKG_CHECK_MODULES(KMOD, libkmod) + PKG_CHECK_MODULES(UDEV, libudev) fi AC_CHECK_PROG([has_doxygen], [doxygen], [true], [false]) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index c42286e..031be75 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -7,8 +7,8 @@ # AM_CFLAGS = -I$(top_srcdir)/include/ -include $(top_builddir)/config.h -AM_CFLAGS += -Wall -Wextra -g -LDADD = ../../src/lib/libgpiod.la -lkmod -ludev +AM_CFLAGS += -Wall -Wextra -g $(KMOD_CFLAGS) $(UDEV_CFLAGS) +LDADD = ../../src/lib/libgpiod.la $(KMOD_LIBS) $(UDEV_LIBS) check_PROGRAMS = gpiod-unit -- 2.30.2