Skip to contentSkip to conversation

btrfs-progs: btrfsutil: add pkg-config files for btrfsutil

PATCH Superseded Sheng Mao 3 participants 5 messages Aug 19, 2020 – Oct 2, 2020

Subsystems (2)
lore
Share & tools
lore

Sheng Mao

author
#0 lore raw

PATCH 1/1 btrfs-progs: btrfsutil: add pkg-config files for btrfsutil

Add pc files for dynamic and static btrfsutil
libraries. Users can use pkg-config to set up
compilation and linking flags.

The paths in pc files depend on prefix variable but ignore DESTDIR. DESTDIR is used for packaging and it should not affect the paths in pc files.

---
 .gitignore                             |  1 +
 Makefile                               | 10 +++++-
 Makefile.inc.in                        |  1 +
 configure.ac                           | 13 ++++++++
 libbtrfsutil/libbtrfsutil-static.pc.in | 11 +++++++
 libbtrfsutil/libbtrfsutil.pc.in        | 11 +++++++
 tests/pkg-config-tests.sh              | 45 ++++++++++++++++++++++++++
 7 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 libbtrfsutil/libbtrfsutil-static.pc.in
 create mode 100644 libbtrfsutil/libbtrfsutil.pc.in
 create mode 100644 tests/pkg-config-tests.sh
.gitignore +1 -0
index 1c70ec94..67404361 100644
@@ -97,3 +97,4 @@
 /Documentation/mkfs.btrfs.8
 
 *.patch
+*.pc
Makefile +9 -1
index c788b91b..ecb00389 100644
@@ -436,13 +436,18 @@ test-clean:
 	@echo "Cleaning tests"
 	$(Q)bash tests/clean-tests.sh
 
+test-pkg-config:
+	@echo "Test pkg-config settings"
+	export libdir incdir
+	$(Q)bash tests/pkg-config-tests.sh
+
 test-inst: all
 	@tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
 		echo "Test installation to $$tmpdest" && \
 		$(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \
 		$(RM) -rf -- $$tmpdest
 
-test: test-check test-check-lowmem test-mkfs test-misc test-cli test-convert test-fuzz
+test: test-check test-check-lowmem test-mkfs test-misc test-cli test-convert test-fuzz test-pkg-config
 
 testsuite: btrfs-corrupt-block btrfs-find-root btrfs-select-super fssum
 	@echo "Export tests as a package"
@@ -779,6 +784,9 @@ endif
 	$(INSTALL) -m755 -d $(DESTDIR)$(incdir)/btrfs
 	$(INSTALL) -m644 $(libbtrfs_headers) $(DESTDIR)$(incdir)/btrfs
 	$(INSTALL) -m644 libbtrfsutil/btrfsutil.h $(DESTDIR)$(incdir)
+	$(INSTALL) -m755 -d $(DESTDIR)$(pkgconfigdir)
+	$(INSTALL) -m644 libbtrfsutil/libbtrfsutil.pc $(DESTDIR)$(pkgconfigdir)
+	$(INSTALL) -m644 libbtrfsutil/libbtrfsutil-static.pc $(DESTDIR)$(pkgconfigdir)
 endif
 
 ifeq ($(PYTHON_BINDINGS),1)
Makefile.inc.in +1 -0
index f3cd2733..9f493371 100644
@@ -41,6 +41,7 @@ libdir ?= @libdir@
 incdir = @includedir@
 udevdir = @UDEVDIR@
 udevruledir = ${udevdir}/rules.d
+pkgconfigdir = @pkgconfigdir@
 
 # external libs required by various binaries; for btrfs-foo,
 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules in Makefile
configure.ac +13 -0
index 7c2c9b8d..80dd2077 100644
@@ -12,6 +12,10 @@ LIBBTRFS_MAJOR=0
 LIBBTRFS_MINOR=1
 LIBBTRFS_PATCHLEVEL=2
 
+BTRFS_UTIL_VERSION_MAJOR=1
+BTRFS_UTIL_VERSION_MINOR=2
+BTRFS_UTIL_VERSION_PATCH=0
+
 CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2"}
 AC_SUBST([CFLAGS])
 
@@ -300,18 +304,26 @@ AC_SUBST([LZO2_LIBS])
 AC_SUBST([LZO2_LIBS_STATIC])
 AC_SUBST([LZO2_CFLAGS])
 
+dnl call PKG_INSTALLDIR from pkg.m4 to set pkgconfigdir
+m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], [AC_MSG_ERROR([please install pkgconf])])
 
 dnl library stuff
 AC_SUBST([LIBBTRFS_MAJOR])
 AC_SUBST([LIBBTRFS_MINOR])
 AC_SUBST([LIBBTRFS_PATCHLEVEL])
 
+AC_SUBST([BTRFS_UTIL_VERSION_MAJOR])
+AC_SUBST([BTRFS_UTIL_VERSION_MINOR])
+AC_SUBST([BTRFS_UTIL_VERSION_PATCH])
+
 AC_CONFIG_HEADERS([config.h])
 
 AC_CONFIG_FILES([
 Makefile.inc
 Documentation/Makefile
 version.h
+libbtrfsutil/libbtrfsutil.pc
+libbtrfsutil/libbtrfsutil-static.pc
 ])
 
 AC_OUTPUT
@@ -325,6 +337,7 @@ AC_MSG_RESULT([
 	bindir:             ${bindir}
 	libdir:             ${libdir}
 	includedir:         ${includedir}
+	pkgconfigdir:       ${pkgconfigdir}
 
 	compiler:           ${CC}
 	cflags:             ${CFLAGS}
libbtrfsutil/libbtrfsutil-static.pc.in new file +11 -0
new file mode 100644
index 00000000..071b2594
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libbtrfsutil-static
+Description: libbtrfsutil static library
+Version: @BTRFS_UTIL_VERSION_MAJOR@.@BTRFS_UTIL_VERSION_MINOR@.@BTRFS_UTIL_VERSION_PATCH@
+URL: http://btrfs.wiki.kernel.org
+Cflags: -I${includedir}
+Libs: @libdir@/libbtrfsutil.a
libbtrfsutil/libbtrfsutil.pc.in new file +11 -0
new file mode 100644
index 00000000..81e66622
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libbtrfsutil
+Description: libbtrfsutil library
+Version: @BTRFS_UTIL_VERSION_MAJOR@.@BTRFS_UTIL_VERSION_MINOR@.@BTRFS_UTIL_VERSION_PATCH@
+URL: http://btrfs.wiki.kernel.org
+Cflags: -I${includedir}
+Libs: -L${libdir} -lbtrfsutil
tests/pkg-config-tests.sh new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Sheng Mao

Add pc files for dynamic and static btrfsutil libraries. Users can use pkg-config to set up compilation and linking flags.

The paths in pc files depend on prefix variable but ignore DESTDIR. DESTDIR is used for packaging and it should not affect the paths in pc files.

There should be no separate pkgconfig file for static libraries, since you can tell a compiler to prefer the static library over the dynamic library when using -lbtrfsutil with -Bstatic flag.

This also reminds me that I need to submit that patch set to fix the versioning for the btrfs libraries, because they're completely out of whack and make life difficult...

--
真実はいつも一つ!/ Always, there's only one truth!

author
#2 lore raw

PATCH v2 1/1 btrfs-progs: btrfsutil: add pkg-config files for btrfsutil

Add pc file for btrfsutil libraries. Users can use pkg-config to set up compilation and linking flags.

The paths in pc file depend on prefix variable but ignore DESTDIR. DESTDIR is used for packaging and it should not affect the paths in pc file.

---
 .gitignore                      |  1 +
 Makefile                        |  9 +++++++-
 Makefile.inc.in                 |  1 +
 configure.ac                    | 12 ++++++++++
 libbtrfsutil/libbtrfsutil.pc.in | 11 +++++++++
 tests/pkg-config-tests.sh       | 41 +++++++++++++++++++++++++++++++++
 6 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 libbtrfsutil/libbtrfsutil.pc.in
 create mode 100644 tests/pkg-config-tests.sh
.gitignore +1 -0
index 1c70ec94..67404361 100644
@@ -97,3 +97,4 @@
 /Documentation/mkfs.btrfs.8
 
 *.patch
+*.pc
Makefile +8 -1
index c788b91b..42ba9d7f 100644
@@ -436,13 +436,18 @@ test-clean:
 	@echo "Cleaning tests"
 	$(Q)bash tests/clean-tests.sh
 
+test-pkg-config:
+	@echo "Test pkg-config settings"
+	export libdir incdir
+	$(Q)bash tests/pkg-config-tests.sh
+
 test-inst: all
 	@tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
 		echo "Test installation to $$tmpdest" && \
 		$(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \
 		$(RM) -rf -- $$tmpdest
 
-test: test-check test-check-lowmem test-mkfs test-misc test-cli test-convert test-fuzz
+test: test-check test-check-lowmem test-mkfs test-misc test-cli test-convert test-fuzz test-pkg-config
 
 testsuite: btrfs-corrupt-block btrfs-find-root btrfs-select-super fssum
 	@echo "Export tests as a package"
@@ -779,6 +784,8 @@ endif
 	$(INSTALL) -m755 -d $(DESTDIR)$(incdir)/btrfs
 	$(INSTALL) -m644 $(libbtrfs_headers) $(DESTDIR)$(incdir)/btrfs
 	$(INSTALL) -m644 libbtrfsutil/btrfsutil.h $(DESTDIR)$(incdir)
+	$(INSTALL) -m755 -d $(DESTDIR)$(pkgconfigdir)
+	$(INSTALL) -m644 libbtrfsutil/libbtrfsutil.pc $(DESTDIR)$(pkgconfigdir)
 endif
 
 ifeq ($(PYTHON_BINDINGS),1)
Makefile.inc.in +1 -0
index f3cd2733..9f493371 100644
@@ -41,6 +41,7 @@ libdir ?= @libdir@
 incdir = @includedir@
 udevdir = @UDEVDIR@
 udevruledir = ${udevdir}/rules.d
+pkgconfigdir = @pkgconfigdir@
 
 # external libs required by various binaries; for btrfs-foo,
 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules in Makefile
configure.ac +12 -0
index 7c2c9b8d..a693ad4e 100644
@@ -12,6 +12,10 @@ LIBBTRFS_MAJOR=0
 LIBBTRFS_MINOR=1
 LIBBTRFS_PATCHLEVEL=2
 
+BTRFS_UTIL_VERSION_MAJOR=1
+BTRFS_UTIL_VERSION_MINOR=2
+BTRFS_UTIL_VERSION_PATCH=0
+
 CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2"}
 AC_SUBST([CFLAGS])
 
@@ -300,18 +304,25 @@ AC_SUBST([LZO2_LIBS])
 AC_SUBST([LZO2_LIBS_STATIC])
 AC_SUBST([LZO2_CFLAGS])
 
+dnl call PKG_INSTALLDIR from pkg.m4 to set pkgconfigdir
+m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], [AC_MSG_ERROR([please install pkgconf])])
 
 dnl library stuff
 AC_SUBST([LIBBTRFS_MAJOR])
 AC_SUBST([LIBBTRFS_MINOR])
 AC_SUBST([LIBBTRFS_PATCHLEVEL])
 
+AC_SUBST([BTRFS_UTIL_VERSION_MAJOR])
+AC_SUBST([BTRFS_UTIL_VERSION_MINOR])
+AC_SUBST([BTRFS_UTIL_VERSION_PATCH])
+
 AC_CONFIG_HEADERS([config.h])
 
 AC_CONFIG_FILES([
 Makefile.inc
 Documentation/Makefile
 version.h
+libbtrfsutil/libbtrfsutil.pc
 ])
 
 AC_OUTPUT
@@ -325,6 +336,7 @@ AC_MSG_RESULT([
 	bindir:             ${bindir}
 	libdir:             ${libdir}
 	includedir:         ${includedir}
+	pkgconfigdir:       ${pkgconfigdir}
 
 	compiler:           ${CC}
 	cflags:             ${CFLAGS}
libbtrfsutil/libbtrfsutil.pc.in new file +11 -0
new file mode 100644
index 00000000..81e66622
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libbtrfsutil
+Description: libbtrfsutil library
+Version: @BTRFS_UTIL_VERSION_MAJOR@.@BTRFS_UTIL_VERSION_MINOR@.@BTRFS_UTIL_VERSION_PATCH@
+URL: http://btrfs.wiki.kernel.org
+Cflags: -I${includedir}
+Libs: -L${libdir} -lbtrfsutil
tests/pkg-config-tests.sh new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw
Quoted 8 lines · Sheng Mao

Add pc file for btrfsutil libraries. Users can use pkg-config to set up compilation and linking flags.

The paths in pc file depend on prefix variable but ignore DESTDIR. DESTDIR is used for packaging and it should not affect the paths in pc file.

Thanks, I've added it to devel.

Makefile test-clean: · line 442

Quoted 4 lines
Makefile +4 -0
+test-pkg-config:
+	@echo "Test pkg-config settings"
+	export libdir incdir
+	$(Q)bash tests/pkg-config-tests.sh

I've deleted this section and the script, there's no point testing it like that.

configure.ac LIBBTRFS_MAJOR=0 · line 17

Quoted 9 lines
configure.ac +3 -0
@@ -12,6 +12,10 @@ LIBBTRFS_MAJOR=0
 LIBBTRFS_MINOR=1
 LIBBTRFS_PATCHLEVEL=2
 
+BTRFS_UTIL_VERSION_MAJOR=1
+BTRFS_UTIL_VERSION_MINOR=2
+BTRFS_UTIL_VERSION_PATCH=0

This would duplicate the version definition, so this needs to parse it from libbtrfsutil/btrfsutil.h.

author
#4 lore raw
Quoted 26 lines · David Sterba
Quoted 8 lines · Sheng Mao

Add pc file for btrfsutil libraries. Users can use pkg-config to set up compilation and linking flags.

The paths in pc file depend on prefix variable but ignore DESTDIR. DESTDIR is used for packaging and it should not affect the paths in pc file.

Thanks, I've added it to devel.

Makefile test-clean: · line 442

Quoted 4 lines
Makefile +4 -0
+test-pkg-config:
+	@echo "Test pkg-config settings"
+	export libdir incdir
+	$(Q)bash tests/pkg-config-tests.sh

I've deleted this section and the script, there's no point testing it like that.

Quoted 6 lines
configure.ac +0 -0
@@ -12,6 +12,10 @@ LIBBTRFS_MAJOR=0
  LIBBTRFS_MINOR=1
  LIBBTRFS_PATCHLEVEL=2
 
Quoted 7 lines

configure.ac LIBBTRFS_MAJOR=0 · line 17

Quoted 3 lines
configure.ac +3 -0
+BTRFS_UTIL_VERSION_MAJOR=1
+BTRFS_UTIL_VERSION_MINOR=2
+BTRFS_UTIL_VERSION_PATCH=0

This would duplicate the version definition, so this needs to parse it from libbtrfsutil/btrfsutil.h.

Hi David,

Thank you for reviewing and merging the code! I agree with you, the test code doesn't make sense and it is right to remove it.

Also, thank you Neal for helping me improving the patch!

Thank you!

Regards,
Sheng