diff mbox series

[fsverity-utils,2/2] Generate and install libfsverity.pc

Message ID 20201022175934.2999543-2-luca.boccassi@gmail.com (mailing list archive)
State Superseded
Headers show
Series [fsverity-utils,1/2] Use pkg-config to get libcrypto build flags | expand

Commit Message

Luca Boccassi Oct. 22, 2020, 5:59 p.m. UTC
From: Luca Boccassi <luca.boccassi@microsoft.com>

pkg-config is commonly used by libraries to convey information about
compiler flags and dependencies.
As packagers, we heavily rely on it so that all our tools do the right
thing by default regardless of the environment.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
---
 Makefile              | 13 ++++++++++++-
 lib/libfsverity.pc.in | 10 ++++++++++
 scripts/do-release.sh |  2 ++
 3 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 lib/libfsverity.pc.in

Comments

Eric Biggers Oct. 24, 2020, 3:56 a.m. UTC | #1
On Thu, Oct 22, 2020 at 06:59:34PM +0100, luca.boccassi@gmail.com wrote:
> From: Luca Boccassi <luca.boccassi@microsoft.com>
> 
> pkg-config is commonly used by libraries to convey information about
> compiler flags and dependencies.
> As packagers, we heavily rely on it so that all our tools do the right
> thing by default regardless of the environment.
> 
> Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
> ---
>  Makefile              | 13 ++++++++++++-
>  lib/libfsverity.pc.in | 10 ++++++++++
>  scripts/do-release.sh |  2 ++
>  3 files changed, 24 insertions(+), 1 deletion(-)
>  create mode 100644 lib/libfsverity.pc.in
> 
> diff --git a/Makefile b/Makefile
> index 122c0a2..07b828f 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -119,6 +119,15 @@ libfsverity.so:libfsverity.so.$(SOVERSION)
>  
>  DEFAULT_TARGETS += libfsverity.so
>  
> +# Create the pkg-config file
> +libfsverity.pc:

The dependency on lib/libfsverity.pc.in should be listed here.

Also, this depends on $(PREFIX), $(LIBDIR), and $(INCDIR).  Can you also add
those and $(BINDIR) to the string that gets written to .build-config, then add a
dependency on .build-config?

> +	sed -e "s|@PREFIX@|$(PREFIX)|" \
> +		-e "s|@LIBDIR@|$(LIBDIR)|" \
> +		-e "s|@INCDIR@|$(INCDIR)|" \
> +		lib/libfsverity.pc.in > $@
> +

This looks messy in the build output:

	$ make
	  CC       lib/compute_digest.o
	  CC       lib/hash_algs.o
	  CC       lib/sign_digest.o
	  CC       lib/utils.o
	  AR       libfsverity.a
	  CC       lib/compute_digest.shlib.o
	  CC       lib/hash_algs.shlib.o
	  CC       lib/sign_digest.shlib.o
	  CC       lib/utils.shlib.o
	  CCLD     libfsverity.so.0
	  LN       libfsverity.so
	sed -e "s|@PREFIX@|/usr/local|" \
		-e "s|@LIBDIR@|/usr/local/lib|" \
		-e "s|@INCDIR@|/usr/local/include|" \
		lib/libfsverity.pc.in > libfsverity.pc
	  CC       programs/utils.o
	  CC       programs/cmd_enable.o
	  CC       programs/cmd_measure.o
	  CC       programs/cmd_sign.o
	  CC       programs/fsverity.o
	  CCLD     fsverity

Below QUIET_LN, can you add:

	QUIET_GEN       = @echo '  GEN     ' $@;

Then prefix the sed command with $(QUIET_GEN) so the output looks nice.

Also, $< can be used instead of lib/libfsverity.pc.in, once the dependency is
added.

> +DEFAULT_TARGETS += libfsverity.pc
> +
>  ##############################################################################
>  
>  #### Programs
> @@ -190,11 +199,12 @@ check:fsverity test_programs
>  	@echo "All tests passed!"
>  
>  install:all
> -	install -d $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR) $(DESTDIR)$(BINDIR)
> +	install -d $(DESTDIR)$(LIBDIR)/pkgconfig $(DESTDIR)$(INCDIR) $(DESTDIR)$(BINDIR)
>  	install -m755 fsverity $(DESTDIR)$(BINDIR)
>  	install -m644 libfsverity.a $(DESTDIR)$(LIBDIR)
>  	install -m755 libfsverity.so.$(SOVERSION) $(DESTDIR)$(LIBDIR)
>  	ln -sf libfsverity.so.$(SOVERSION) $(DESTDIR)$(LIBDIR)/libfsverity.so
> +	install -m644 libfsverity.pc $(DESTDIR)$(LIBDIR)/pkgconfig
>  	install -m644 include/libfsverity.h $(DESTDIR)$(INCDIR)
>  
>  uninstall:
> @@ -202,6 +212,7 @@ uninstall:
>  	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.a
>  	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.so.$(SOVERSION)
>  	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.so
> +	rm -f $(DESTDIR)$(LIBDIR)/pkgconfig/libfsverity.pc
>  	rm -f $(DESTDIR)$(INCDIR)/libfsverity.h

'make clean' should remove libfsverity.pc as well.

Also, libfsverity.pc should be listed in .gitignore.

- Eric
Luca Boccassi Oct. 26, 2020, 11:16 a.m. UTC | #2
On Fri, 2020-10-23 at 20:56 -0700, Eric Biggers wrote:
> On Thu, Oct 22, 2020 at 06:59:34PM +0100, luca.boccassi@gmail.com wrote:
> > From: Luca Boccassi <luca.boccassi@microsoft.com>
> > 
> > pkg-config is commonly used by libraries to convey information about
> > compiler flags and dependencies.
> > As packagers, we heavily rely on it so that all our tools do the right
> > thing by default regardless of the environment.
> > 
> > Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
> > ---
> >  Makefile              | 13 ++++++++++++-
> >  lib/libfsverity.pc.in | 10 ++++++++++
> >  scripts/do-release.sh |  2 ++
> >  3 files changed, 24 insertions(+), 1 deletion(-)
> >  create mode 100644 lib/libfsverity.pc.in
> > 
> > diff --git a/Makefile b/Makefile
> > index 122c0a2..07b828f 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -119,6 +119,15 @@ libfsverity.so:libfsverity.so.$(SOVERSION)
> >  
> >  DEFAULT_TARGETS += libfsverity.so
> >  
> > +# Create the pkg-config file
> > +libfsverity.pc:
> 
> The dependency on lib/libfsverity.pc.in should be listed here.
> 
> Also, this depends on $(PREFIX), $(LIBDIR), and $(INCDIR).  Can you also add
> those and $(BINDIR) to the string that gets written to .build-config, then add a
> dependency on .build-config?
> 
> > +	sed -e "s|@PREFIX@|$(PREFIX)|" \
> > +		-e "s|@LIBDIR@|$(LIBDIR)|" \
> > +		-e "s|@INCDIR@|$(INCDIR)|" \
> > +		lib/libfsverity.pc.in > $@
> > +
> 
> This looks messy in the build output:
> 
> 	$ make
> 	  CC       lib/compute_digest.o
> 	  CC       lib/hash_algs.o
> 	  CC       lib/sign_digest.o
> 	  CC       lib/utils.o
> 	  AR       libfsverity.a
> 	  CC       lib/compute_digest.shlib.o
> 	  CC       lib/hash_algs.shlib.o
> 	  CC       lib/sign_digest.shlib.o
> 	  CC       lib/utils.shlib.o
> 	  CCLD     libfsverity.so.0
> 	  LN       libfsverity.so
> 	sed -e "s|@PREFIX@|/usr/local|" \
> 		-e "s|@LIBDIR@|/usr/local/lib|" \
> 		-e "s|@INCDIR@|/usr/local/include|" \
> 		lib/libfsverity.pc.in > libfsverity.pc
> 	  CC       programs/utils.o
> 	  CC       programs/cmd_enable.o
> 	  CC       programs/cmd_measure.o
> 	  CC       programs/cmd_sign.o
> 	  CC       programs/fsverity.o
> 	  CCLD     fsverity
> 
> Below QUIET_LN, can you add:
> 
> 	QUIET_GEN       = @echo '  GEN     ' $@;
> 
> Then prefix the sed command with $(QUIET_GEN) so the output looks nice.
> 
> Also, $< can be used instead of lib/libfsverity.pc.in, once the dependency is
> added.
> 
> > +DEFAULT_TARGETS += libfsverity.pc
> > +
> >  ##############################################################################
> >  
> >  #### Programs
> > @@ -190,11 +199,12 @@ check:fsverity test_programs
> >  	@echo "All tests passed!"
> >  
> >  install:all
> > -	install -d $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR) $(DESTDIR)$(BINDIR)
> > +	install -d $(DESTDIR)$(LIBDIR)/pkgconfig $(DESTDIR)$(INCDIR) $(DESTDIR)$(BINDIR)
> >  	install -m755 fsverity $(DESTDIR)$(BINDIR)
> >  	install -m644 libfsverity.a $(DESTDIR)$(LIBDIR)
> >  	install -m755 libfsverity.so.$(SOVERSION) $(DESTDIR)$(LIBDIR)
> >  	ln -sf libfsverity.so.$(SOVERSION) $(DESTDIR)$(LIBDIR)/libfsverity.so
> > +	install -m644 libfsverity.pc $(DESTDIR)$(LIBDIR)/pkgconfig
> >  	install -m644 include/libfsverity.h $(DESTDIR)$(INCDIR)
> >  
> >  uninstall:
> > @@ -202,6 +212,7 @@ uninstall:
> >  	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.a
> >  	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.so.$(SOVERSION)
> >  	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.so
> > +	rm -f $(DESTDIR)$(LIBDIR)/pkgconfig/libfsverity.pc
> >  	rm -f $(DESTDIR)$(INCDIR)/libfsverity.h
> 
> 'make clean' should remove libfsverity.pc as well.
> 
> Also, libfsverity.pc should be listed in .gitignore.
> 
> - Eric

All done in v2. 'make clean' already removes the .pc file, as it's part
of the DEFAULT_TARGETS list.
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 122c0a2..07b828f 100644
--- a/Makefile
+++ b/Makefile
@@ -119,6 +119,15 @@  libfsverity.so:libfsverity.so.$(SOVERSION)
 
 DEFAULT_TARGETS += libfsverity.so
 
+# Create the pkg-config file
+libfsverity.pc:
+	sed -e "s|@PREFIX@|$(PREFIX)|" \
+		-e "s|@LIBDIR@|$(LIBDIR)|" \
+		-e "s|@INCDIR@|$(INCDIR)|" \
+		lib/libfsverity.pc.in > $@
+
+DEFAULT_TARGETS += libfsverity.pc
+
 ##############################################################################
 
 #### Programs
@@ -190,11 +199,12 @@  check:fsverity test_programs
 	@echo "All tests passed!"
 
 install:all
-	install -d $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR) $(DESTDIR)$(BINDIR)
+	install -d $(DESTDIR)$(LIBDIR)/pkgconfig $(DESTDIR)$(INCDIR) $(DESTDIR)$(BINDIR)
 	install -m755 fsverity $(DESTDIR)$(BINDIR)
 	install -m644 libfsverity.a $(DESTDIR)$(LIBDIR)
 	install -m755 libfsverity.so.$(SOVERSION) $(DESTDIR)$(LIBDIR)
 	ln -sf libfsverity.so.$(SOVERSION) $(DESTDIR)$(LIBDIR)/libfsverity.so
+	install -m644 libfsverity.pc $(DESTDIR)$(LIBDIR)/pkgconfig
 	install -m644 include/libfsverity.h $(DESTDIR)$(INCDIR)
 
 uninstall:
@@ -202,6 +212,7 @@  uninstall:
 	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.a
 	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.so.$(SOVERSION)
 	rm -f $(DESTDIR)$(LIBDIR)/libfsverity.so
+	rm -f $(DESTDIR)$(LIBDIR)/pkgconfig/libfsverity.pc
 	rm -f $(DESTDIR)$(INCDIR)/libfsverity.h
 
 help:
diff --git a/lib/libfsverity.pc.in b/lib/libfsverity.pc.in
new file mode 100644
index 0000000..613e9bc
--- /dev/null
+++ b/lib/libfsverity.pc.in
@@ -0,0 +1,10 @@ 
+prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCDIR@
+
+Name: libfsverity
+Description: fs-verity library
+Version: 1.2
+Libs: -L${libdir} -lfsverity
+Requires.private: libcrypto
+Cflags: -I${includedir}
diff --git a/scripts/do-release.sh b/scripts/do-release.sh
index 255fc53..352fcf1 100755
--- a/scripts/do-release.sh
+++ b/scripts/do-release.sh
@@ -28,6 +28,8 @@  minor=$(echo "$VERS" | cut -d. -f2)
 sed -E -i -e "/FSVERITY_UTILS_MAJOR_VERSION/s/[0-9]+/$major/" \
 	  -e "/FSVERITY_UTILS_MINOR_VERSION/s/[0-9]+/$minor/" \
 	  include/libfsverity.h
+sed -E -i "/Version:/s/[0-9]+\.[0-9]+/$VERS/" \
+	  lib/libfsverity.pc.in
 git commit -a --signoff --message="v$VERS"
 git tag --sign "v$VERS" --message="$PKG"