All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil
@ 2020-08-19 21:45 Sheng Mao
  2020-08-20  0:23 ` Neal Gompa
  0 siblings, 1 reply; 5+ messages in thread
From: Sheng Mao @ 2020-08-19 21:45 UTC (permalink / raw)
  To: linux-btrfs; +Cc: 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.

Signed-off-by: Sheng Mao <shngmao@gmail.com>
---
 .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

diff --git a/.gitignore b/.gitignore
index 1c70ec94..67404361 100644
--- a/.gitignore
+++ b/.gitignore
@@ -97,3 +97,4 @@
 /Documentation/mkfs.btrfs.8
 
 *.patch
+*.pc
diff --git a/Makefile b/Makefile
index c788b91b..ecb00389 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/Makefile.inc.in b/Makefile.inc.in
index f3cd2733..9f493371 100644
--- a/Makefile.inc.in
+++ b/Makefile.inc.in
@@ -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
diff --git a/configure.ac b/configure.ac
index 7c2c9b8d..80dd2077 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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}
diff --git a/libbtrfsutil/libbtrfsutil-static.pc.in b/libbtrfsutil/libbtrfsutil-static.pc.in
new file mode 100644
index 00000000..071b2594
--- /dev/null
+++ b/libbtrfsutil/libbtrfsutil-static.pc.in
@@ -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
diff --git a/libbtrfsutil/libbtrfsutil.pc.in b/libbtrfsutil/libbtrfsutil.pc.in
new file mode 100644
index 00000000..81e66622
--- /dev/null
+++ b/libbtrfsutil/libbtrfsutil.pc.in
@@ -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
diff --git a/tests/pkg-config-tests.sh b/tests/pkg-config-tests.sh
new file mode 100644
index 00000000..63f614e4
--- /dev/null
+++ b/tests/pkg-config-tests.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+#
+# test pkg-config can find libbtrfsutil
+
+SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ ! -f "$TOP/configure.ac" ]; then
+    exit 0
+fi
+
+export PKG_CONFIG_PATH="$TOP/libbtrfsutil"
+PKG_CONFIG=pkg-config
+SHARED_LIBNAME=libbtrfsutil
+STATIC_LIBNAME=libbtrfsutil-static
+
+die() {
+	echo "ERROR: $@"
+	exit 1
+}
+
+test-exists() {
+    ${PKG_CONFIG} --exists $1 || die "$1 doesn't exist"
+}
+
+test-pkg-config() {
+    if [ "$#" != "3" ]; then
+        echo "$0 needs 3 arguments"
+        exit 1
+    fi
+    libname="$1"
+    flags="$2"
+    actual="$(${PKG_CONFIG} $flags $libname)"
+    expected="$3"
+
+    if [ "$actual" != "$expected" ]; then
+        die "pkg-config $flags failed on $libname: $actual != $expected"
+    fi
+}
+
+test-exists "$SHARED_LIBNAME"
+test-exists "$STATIC_LIBNAME"
+test-pkg-config "$SHARED_LIBNAME" "--cflags" "-I${incdir}"
+test-pkg-config "$STATIC_LIBNAME" "--cflags"  "-I${incdir}"
+test-pkg-config "$SHARED_LIBNAME" "--libs"  "-L${libdir} -lbtrfsutil"
+test-pkg-config "$STATIC_LIBNAME" "--libs" "${libdir}/libbtrfsutil.a"
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil
  2020-08-19 21:45 [PATCH] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil Sheng Mao
@ 2020-08-20  0:23 ` Neal Gompa
  2020-08-20  4:36   ` [PATCH v2] " Sheng Mao
  0 siblings, 1 reply; 5+ messages in thread
From: Neal Gompa @ 2020-08-20  0:23 UTC (permalink / raw)
  To: Sheng Mao; +Cc: Btrfs BTRFS

On Wed, Aug 19, 2020 at 5:47 PM Sheng Mao <shngmao@gmail.com> wrote:
>
> 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!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil
  2020-08-20  0:23 ` Neal Gompa
@ 2020-08-20  4:36   ` Sheng Mao
  2020-10-02 17:54     ` David Sterba
  0 siblings, 1 reply; 5+ messages in thread
From: Sheng Mao @ 2020-08-20  4:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Neal Gompa, 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.

Signed-off-by: Sheng Mao <shngmao@gmail.com>
---
 .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

diff --git a/.gitignore b/.gitignore
index 1c70ec94..67404361 100644
--- a/.gitignore
+++ b/.gitignore
@@ -97,3 +97,4 @@
 /Documentation/mkfs.btrfs.8
 
 *.patch
+*.pc
diff --git a/Makefile b/Makefile
index c788b91b..42ba9d7f 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/Makefile.inc.in b/Makefile.inc.in
index f3cd2733..9f493371 100644
--- a/Makefile.inc.in
+++ b/Makefile.inc.in
@@ -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
diff --git a/configure.ac b/configure.ac
index 7c2c9b8d..a693ad4e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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}
diff --git a/libbtrfsutil/libbtrfsutil.pc.in b/libbtrfsutil/libbtrfsutil.pc.in
new file mode 100644
index 00000000..81e66622
--- /dev/null
+++ b/libbtrfsutil/libbtrfsutil.pc.in
@@ -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
diff --git a/tests/pkg-config-tests.sh b/tests/pkg-config-tests.sh
new file mode 100644
index 00000000..faf15956
--- /dev/null
+++ b/tests/pkg-config-tests.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# test pkg-config can find libbtrfsutil
+
+SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ ! -f "$TOP/configure.ac" ]; then
+    exit 0
+fi
+
+export PKG_CONFIG_PATH="$TOP/libbtrfsutil"
+PKG_CONFIG=pkg-config
+LIBNAME=libbtrfsutil
+
+die() {
+	echo "ERROR: $@"
+	exit 1
+}
+
+test-exists() {
+    ${PKG_CONFIG} --exists $1 || die "$1 doesn't exist"
+}
+
+test-pkg-config() {
+    if [ "$#" != "3" ]; then
+        echo "$0 needs 3 arguments"
+        exit 1
+    fi
+    libname="$1"
+    flags="$2"
+    actual="$(${PKG_CONFIG} $flags $libname | awk '{gsub(/^\s+|\s+$/,"")}1')"
+    expected="$3"
+
+    if [ "$actual" != "$expected" ]; then
+        die "pkg-config $flags failed on $libname: '$actual' != '$expected'"
+    fi
+}
+
+test-exists "$LIBNAME"
+test-pkg-config "$LIBNAME" "--cflags" "-I${incdir}"
+test-pkg-config "$LIBNAME" "--libs"  "-L${libdir} -lbtrfsutil"
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil
  2020-08-20  4:36   ` [PATCH v2] " Sheng Mao
@ 2020-10-02 17:54     ` David Sterba
  2020-10-02 19:15       ` Sheng Mao
  0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2020-10-02 17:54 UTC (permalink / raw)
  To: Sheng Mao; +Cc: linux-btrfs, Neal Gompa

On Wed, Aug 19, 2020 at 10:36:18PM -0600, Sheng Mao wrote:
> 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.
> 
> Signed-off-by: Sheng Mao <shngmao@gmail.com>

Thanks, I've added it to devel.

> +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.

> --- a/configure.ac
> +++ b/configure.ac
> @@ -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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil
  2020-10-02 17:54     ` David Sterba
@ 2020-10-02 19:15       ` Sheng Mao
  0 siblings, 0 replies; 5+ messages in thread
From: Sheng Mao @ 2020-10-02 19:15 UTC (permalink / raw)
  To: linux-btrfs; +Cc: ngompa13, dsterba

On 2020-10-02 11:54 a.m., David Sterba wrote:
> On Wed, Aug 19, 2020 at 10:36:18PM -0600, Sheng Mao wrote:
>> 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.
>>
>> Signed-off-by: Sheng Mao <shngmao@gmail.com>
> 
> Thanks, I've added it to devel.
> 
>> +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.
> 
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -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.
> 

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-02 19:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 21:45 [PATCH] btrfs-progs: btrfsutil: add pkg-config files for btrfsutil Sheng Mao
2020-08-20  0:23 ` Neal Gompa
2020-08-20  4:36   ` [PATCH v2] " Sheng Mao
2020-10-02 17:54     ` David Sterba
2020-10-02 19:15       ` Sheng Mao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.