From c150e7773764d100a21eb5ee4c586fe1edf4673b Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 28 Nov 2020 22:10:00 +0100 Subject: [PATCH 1/4] build: Add a pkg-config file The .pc are a better replacement for library detection and linking usage, than libtool .la files or hardcoding the flags in the using code. --- .gitignore | 1 + configure.ac | 1 + lib/Makefile.am | 5 +++++ lib/libsysfs.pc.in | 11 +++++++++++ 4 files changed, 18 insertions(+) create mode 100644 lib/libsysfs.pc.in diff --git a/.gitignore b/.gitignore index 735b217..021f4f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.la *.lo *.o +*.pc .deps .libs INSTALL diff --git a/configure.ac b/configure.ac index ec531fc..8db6952 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,7 @@ AC_CHECK_FUNCS([bzero isascii memset strchr strerror strrchr strstr strtol]) AC_CONFIG_FILES([Makefile lib/Makefile + lib/libsysfs.pc cmd/Makefile test/Makefile]) AC_CONFIG_HEADERS([config.h]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 42bb338..e8f6123 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,3 +1,8 @@ +EXTRA_DIST = libsysfs.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libsysfs.pc + lib_LTLIBRARIES = libsysfs.la libsysfs_la_SOURCES = sysfs_utils.c sysfs_attr.c sysfs_class.c dlist.c \ sysfs_device.c sysfs_driver.c sysfs_bus.c sysfs_module.c sysfs.h diff --git a/lib/libsysfs.pc.in b/lib/libsysfs.pc.in new file mode 100644 index 0000000..1ca1691 --- /dev/null +++ b/lib/libsysfs.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libsysfs +Description: interface to Linux sysfs +Version: @VERSION@ +URL: https://github.com/linux-ras/sysfsutils +Libs: -L${libdir} -lsysfs +Cflags: -I${includedir} From a168e879e9bca2edf1606b41612bb6220669730e Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 28 Nov 2020 22:12:27 +0100 Subject: [PATCH 2/4] build: Add silent rule support for test.h generation Use the generic automake silent prefix macros for this file. --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile.am b/test/Makefile.am index 3236afa..98d2122 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = dlist_test get_device get_driver get_module testlibsysfs BUILT_SOURCES = test.h CLEANFILES = test.h test.h: libsysfs.conf create-test - ./create-test + $(AM_V_GEN) ./create-test get_device_SOURCES = get_device.c get_driver_SOURCES = get_driver.c get_module_SOURCES = get_module.c From 84aa8f6472f3c52c4f0a3a324d8ffeb33cd98899 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 28 Nov 2020 22:20:08 +0100 Subject: [PATCH 3/4] build: Move test program into check_PROGRAMS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are unit tests which should not end up installed on the system, and should not be built as part of «make all». These will be built as part of «make check» instead. Ideally they would also be executed as part of the test suite, but they currently depend on the host systems' sysfs. --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile.am b/test/Makefile.am index 98d2122..c675ef3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = dlist_test get_device get_driver get_module testlibsysfs +check_PROGRAMS = dlist_test get_device get_driver get_module testlibsysfs BUILT_SOURCES = test.h CLEANFILES = test.h test.h: libsysfs.conf create-test From 81c3e01d056c30abf8b67b1f4cc7a777c606d68e Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 28 Nov 2020 22:32:08 +0100 Subject: [PATCH 4/4] build: Fix out-of-tree builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In out-of-tree builds the current directory is the build directory which is different to the source directory. As a consequence this also fixes «make distcheck» to work. --- cmd/Makefile.am | 4 ++-- lib/Makefile.am | 2 +- test/Makefile.am | 6 +++--- test/create-test | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/Makefile.am b/cmd/Makefile.am index d6f6b40..bd2c1fb 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = systool systool_SOURCES = systool.c names.c names.h -LDADD = ../lib/libsysfs.la +LDADD = $(top_builddir)/lib/libsysfs.la EXTRA_CFLAGS = @EXTRA_CFLAGS@ -AM_CPPFLAGS = -I../include +AM_CPPFLAGS = -I$(top_srcdir)/include AM_CFLAGS = -Wall -W -Wextra -Wstrict-prototypes $(EXTRA_CFLAGS) diff --git a/lib/Makefile.am b/lib/Makefile.am index e8f6123..14e1096 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -6,7 +6,7 @@ pkgconfig_DATA = libsysfs.pc lib_LTLIBRARIES = libsysfs.la libsysfs_la_SOURCES = sysfs_utils.c sysfs_attr.c sysfs_class.c dlist.c \ sysfs_device.c sysfs_driver.c sysfs_bus.c sysfs_module.c sysfs.h -libsysfs_la_CPPFLAGS = -I../include +libsysfs_la_CPPFLAGS = -I$(top_srcdir)/include libsysfs_la_LDFLAGS = -version-info 2:1:0 EXTRA_CFLAGS = @EXTRA_CLFAGS@ libsysfs_la_CFLAGS = -Wall -W -Wextra -Wstrict-prototypes $(EXTRA_CLFAGS) diff --git a/test/Makefile.am b/test/Makefile.am index c675ef3..d108210 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,15 +2,15 @@ check_PROGRAMS = dlist_test get_device get_driver get_module testlibsysfs BUILT_SOURCES = test.h CLEANFILES = test.h test.h: libsysfs.conf create-test - $(AM_V_GEN) ./create-test + $(AM_V_GEN) $(srcdir)/create-test $(srcdir)/libsysfs.conf get_device_SOURCES = get_device.c get_driver_SOURCES = get_driver.c get_module_SOURCES = get_module.c testlibsysfs_SOURCES = test.c test_attr.c test_bus.c test_class.c \ test_device.c test_driver.c test_module.c test_utils.c \ testout.c test-defs.h libsysfs.conf create-test -AM_CPPFLAGS = -I../include -LDADD = ../lib/libsysfs.la +AM_CPPFLAGS = -I$(top_srcdir)/include +LDADD = $(top_builddir)/lib/libsysfs.la EXTRA_CFLAGS = @EXTRA_CLFAGS@ AM_CFLAGS = -Wall -W -Wextra -Wstrict-prototypes $(EXTRA_CLFAGS) diff --git a/test/create-test b/test/create-test index 78ce1a2..54903fa 100755 --- a/test/create-test +++ b/test/create-test @@ -2,7 +2,7 @@ rm -f test.h -conf_file=./libsysfs.conf +conf_file=${1:-libsysfs.conf} . $conf_file