All of lore.kernel.org
 help / color / mirror / Atom feed
* [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags
@ 2020-10-22 17:59 luca.boccassi
  2020-10-22 17:59 ` [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc luca.boccassi
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: luca.boccassi @ 2020-10-22 17:59 UTC (permalink / raw)
  To: linux-fscrypt

From: Luca Boccassi <luca.boccassi@microsoft.com>

Especially when cross-compiling or other such cases, it might be necessary
to pass additional compiler flags. This is commonly done via pkg-config,
so use it if available, and fall back to the hardcoded -lcrypto if not.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
---
 Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3fc1bec..122c0a2 100644
--- a/Makefile
+++ b/Makefile
@@ -58,6 +58,7 @@ BINDIR          ?= $(PREFIX)/bin
 INCDIR          ?= $(PREFIX)/include
 LIBDIR          ?= $(PREFIX)/lib
 DESTDIR         ?=
+PKGCONF         ?= pkg-config
 
 # Rebuild if a user-specified setting that affects the build changed.
 .build-config: FORCE
@@ -69,7 +70,8 @@ DESTDIR         ?=
 
 DEFAULT_TARGETS :=
 COMMON_HEADERS  := $(wildcard common/*.h)
-LDLIBS          := -lcrypto
+LDLIBS          := $(shell $(PKGCONF) libcrypto --libs 2>/dev/null || echo -lcrypto)
+CFLAGS          += $(shell $(PKGCONF) libcrypto --cflags 2>/dev/null || echo)
 
 # If we are dynamically linking, when running tests we need to override
 # LD_LIBRARY_PATH as no RPATH is set
-- 
2.20.1


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

* [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc
  2020-10-22 17:59 [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags luca.boccassi
@ 2020-10-22 17:59 ` luca.boccassi
  2020-10-24  3:56   ` Eric Biggers
  2020-10-24  4:07 ` [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags Eric Biggers
  2020-10-26 11:15 ` [fsverity-utils PATCH v2 " luca.boccassi
  2 siblings, 1 reply; 10+ messages in thread
From: luca.boccassi @ 2020-10-22 17:59 UTC (permalink / raw)
  To: linux-fscrypt

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:
+	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"
 
-- 
2.20.1


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

* Re: [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc
  2020-10-22 17:59 ` [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc luca.boccassi
@ 2020-10-24  3:56   ` Eric Biggers
  2020-10-26 11:16     ` Luca Boccassi
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Biggers @ 2020-10-24  3:56 UTC (permalink / raw)
  To: luca.boccassi; +Cc: linux-fscrypt

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

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

* Re: [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags
  2020-10-22 17:59 [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags luca.boccassi
  2020-10-22 17:59 ` [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc luca.boccassi
@ 2020-10-24  4:07 ` Eric Biggers
  2020-10-26 11:16   ` Luca Boccassi
  2020-10-26 11:15 ` [fsverity-utils PATCH v2 " luca.boccassi
  2 siblings, 1 reply; 10+ messages in thread
From: Eric Biggers @ 2020-10-24  4:07 UTC (permalink / raw)
  To: luca.boccassi; +Cc: linux-fscrypt

On Thu, Oct 22, 2020 at 06:59:33PM +0100, luca.boccassi@gmail.com wrote:
> From: Luca Boccassi <luca.boccassi@microsoft.com>
> 
> Especially when cross-compiling or other such cases, it might be necessary
> to pass additional compiler flags. This is commonly done via pkg-config,
> so use it if available, and fall back to the hardcoded -lcrypto if not.
> 
> Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
> ---
>  Makefile | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 3fc1bec..122c0a2 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -58,6 +58,7 @@ BINDIR          ?= $(PREFIX)/bin
>  INCDIR          ?= $(PREFIX)/include
>  LIBDIR          ?= $(PREFIX)/lib
>  DESTDIR         ?=
> +PKGCONF         ?= pkg-config
>  
>  # Rebuild if a user-specified setting that affects the build changed.
>  .build-config: FORCE
> @@ -69,7 +70,8 @@ DESTDIR         ?=
>  
>  DEFAULT_TARGETS :=
>  COMMON_HEADERS  := $(wildcard common/*.h)
> -LDLIBS          := -lcrypto
> +LDLIBS          := $(shell $(PKGCONF) libcrypto --libs 2>/dev/null || echo -lcrypto)
> +CFLAGS          += $(shell $(PKGCONF) libcrypto --cflags 2>/dev/null || echo)

There should be a way to prevent pkg-config from being used if someone wants to
link to a local copy of libcrypto.  One might expect setting PKGCONF to an empty
string to work, and it kind of does, but then the shell command executes
"libcrypto", which is strange.  How about quoting "$(PKGCONF)" so that the shell
command is guaranteed to fail as expected in that case?

- Eric

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

* [fsverity-utils PATCH v2 1/2] Use pkg-config to get libcrypto build flags
  2020-10-22 17:59 [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags luca.boccassi
  2020-10-22 17:59 ` [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc luca.boccassi
  2020-10-24  4:07 ` [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags Eric Biggers
@ 2020-10-26 11:15 ` luca.boccassi
  2020-10-26 11:15   ` [fsverity-utils PATCH v2 2/2] Generate and install libfsverity.pc luca.boccassi
  2020-10-26 17:32   ` [fsverity-utils PATCH v2 1/2] Use pkg-config to get libcrypto build flags Eric Biggers
  2 siblings, 2 replies; 10+ messages in thread
From: luca.boccassi @ 2020-10-26 11:15 UTC (permalink / raw)
  To: linux-fscrypt

From: Luca Boccassi <luca.boccassi@microsoft.com>

Especially when cross-compiling or other such cases, it might be necessary
to pass additional compiler flags. This is commonly done via pkg-config,
so use it if available, and fall back to the hardcoded -lcrypto if not.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
---
v2: quote PKGCONF in shell invocation

 Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3fc1bec..d7e6eb2 100644
--- a/Makefile
+++ b/Makefile
@@ -58,6 +58,7 @@ BINDIR          ?= $(PREFIX)/bin
 INCDIR          ?= $(PREFIX)/include
 LIBDIR          ?= $(PREFIX)/lib
 DESTDIR         ?=
+PKGCONF         ?= pkg-config
 
 # Rebuild if a user-specified setting that affects the build changed.
 .build-config: FORCE
@@ -69,7 +70,8 @@ DESTDIR         ?=
 
 DEFAULT_TARGETS :=
 COMMON_HEADERS  := $(wildcard common/*.h)
-LDLIBS          := -lcrypto
+LDLIBS          := $(shell "$(PKGCONF)" libcrypto --libs 2>/dev/null || echo -lcrypto)
+CFLAGS          += $(shell "$(PKGCONF)" libcrypto --cflags 2>/dev/null || echo)
 
 # If we are dynamically linking, when running tests we need to override
 # LD_LIBRARY_PATH as no RPATH is set
-- 
2.20.1


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

* [fsverity-utils PATCH v2 2/2] Generate and install libfsverity.pc
  2020-10-26 11:15 ` [fsverity-utils PATCH v2 " luca.boccassi
@ 2020-10-26 11:15   ` luca.boccassi
  2020-10-26 17:32     ` Eric Biggers
  2020-10-26 17:32   ` [fsverity-utils PATCH v2 1/2] Use pkg-config to get libcrypto build flags Eric Biggers
  1 sibling, 1 reply; 10+ messages in thread
From: luca.boccassi @ 2020-10-26 11:15 UTC (permalink / raw)
  To: linux-fscrypt

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>
---
v2: add pc file to .gitignore
    add and use QUIET_GEN prefix
    add install variables to .build-config
    have libfsverity.pc depend on lib/libfsverity.pc.in

 .gitignore            |  1 +
 Makefile              | 16 ++++++++++++++--
 lib/libfsverity.pc.in | 10 ++++++++++
 scripts/do-release.sh |  2 ++
 4 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 lib/libfsverity.pc.in

diff --git a/.gitignore b/.gitignore
index 04f9a6f..572da31 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,5 +9,6 @@
 /run-tests.log
 /test_*
 cscope.*
+libfsverity.pc
 ncscope.*
 tags
diff --git a/Makefile b/Makefile
index d7e6eb2..6fdf91a 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,7 @@ QUIET_CC        = @echo '  CC      ' $@;
 QUIET_CCLD      = @echo '  CCLD    ' $@;
 QUIET_AR        = @echo '  AR      ' $@;
 QUIET_LN        = @echo '  LN      ' $@;
+QUIET_GEN       = @echo '  GEN     ' $@;
 endif
 USE_SHARED_LIB  ?=
 PREFIX          ?= /usr/local
@@ -62,7 +63,7 @@ PKGCONF         ?= pkg-config
 
 # Rebuild if a user-specified setting that affects the build changed.
 .build-config: FORCE
-	@flags='$(CC):$(CFLAGS):$(CPPFLAGS):$(LDFLAGS):$(USE_SHARED_LIB)'; \
+	@flags='$(CC):$(CFLAGS):$(CPPFLAGS):$(LDFLAGS):$(USE_SHARED_LIB):$(PREFIX):$(LIBDIR):$(INCDIR):$(BINDIR)'; \
 	if [ "$$flags" != "`cat $@ 2>/dev/null`" ]; then		\
 		[ -e $@ ] && echo "Rebuilding due to new settings";	\
 		echo "$$flags" > $@;					\
@@ -119,6 +120,15 @@ libfsverity.so:libfsverity.so.$(SOVERSION)
 
 DEFAULT_TARGETS += libfsverity.so
 
+# Create the pkg-config file
+libfsverity.pc: lib/libfsverity.pc.in
+	$(QUIET_GEN) sed -e "s|@PREFIX@|$(PREFIX)|" \
+		-e "s|@LIBDIR@|$(LIBDIR)|" \
+		-e "s|@INCDIR@|$(INCDIR)|" \
+		$< > $@
+
+DEFAULT_TARGETS += libfsverity.pc
+
 ##############################################################################
 
 #### Programs
@@ -190,11 +200,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 +213,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"
 
-- 
2.20.1


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

* Re: [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags
  2020-10-24  4:07 ` [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags Eric Biggers
@ 2020-10-26 11:16   ` Luca Boccassi
  0 siblings, 0 replies; 10+ messages in thread
From: Luca Boccassi @ 2020-10-26 11:16 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-fscrypt

On Fri, 2020-10-23 at 21:07 -0700, Eric Biggers wrote:
> On Thu, Oct 22, 2020 at 06:59:33PM +0100, luca.boccassi@gmail.com wrote:
> > From: Luca Boccassi <luca.boccassi@microsoft.com>
> > 
> > Especially when cross-compiling or other such cases, it might be necessary
> > to pass additional compiler flags. This is commonly done via pkg-config,
> > so use it if available, and fall back to the hardcoded -lcrypto if not.
> > 
> > Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
> > ---
> >  Makefile | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Makefile b/Makefile
> > index 3fc1bec..122c0a2 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -58,6 +58,7 @@ BINDIR          ?= $(PREFIX)/bin
> >  INCDIR          ?= $(PREFIX)/include
> >  LIBDIR          ?= $(PREFIX)/lib
> >  DESTDIR         ?=
> > +PKGCONF         ?= pkg-config
> >  
> >  # Rebuild if a user-specified setting that affects the build changed.
> >  .build-config: FORCE
> > @@ -69,7 +70,8 @@ DESTDIR         ?=
> >  
> >  DEFAULT_TARGETS :=
> >  COMMON_HEADERS  := $(wildcard common/*.h)
> > -LDLIBS          := -lcrypto
> > +LDLIBS          := $(shell $(PKGCONF) libcrypto --libs 2>/dev/null || echo -lcrypto)
> > +CFLAGS          += $(shell $(PKGCONF) libcrypto --cflags 2>/dev/null || echo)
> 
> There should be a way to prevent pkg-config from being used if someone wants to
> link to a local copy of libcrypto.  One might expect setting PKGCONF to an empty
> string to work, and it kind of does, but then the shell command executes
> "libcrypto", which is strange.  How about quoting "$(PKGCONF)" so that the shell
> command is guaranteed to fail as expected in that case?
> 
> - Eric

Sure, done in v2.

-- 
Kind regards,
Luca Boccassi


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

* Re: [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc
  2020-10-24  3:56   ` Eric Biggers
@ 2020-10-26 11:16     ` Luca Boccassi
  0 siblings, 0 replies; 10+ messages in thread
From: Luca Boccassi @ 2020-10-26 11:16 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-fscrypt

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.

-- 
Kind regards,
Luca Boccassi


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

* Re: [fsverity-utils PATCH v2 1/2] Use pkg-config to get libcrypto build flags
  2020-10-26 11:15 ` [fsverity-utils PATCH v2 " luca.boccassi
  2020-10-26 11:15   ` [fsverity-utils PATCH v2 2/2] Generate and install libfsverity.pc luca.boccassi
@ 2020-10-26 17:32   ` Eric Biggers
  1 sibling, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2020-10-26 17:32 UTC (permalink / raw)
  To: luca.boccassi; +Cc: linux-fscrypt

On Mon, Oct 26, 2020 at 11:15:05AM +0000, luca.boccassi@gmail.com wrote:
> From: Luca Boccassi <luca.boccassi@microsoft.com>
> 
> Especially when cross-compiling or other such cases, it might be necessary
> to pass additional compiler flags. This is commonly done via pkg-config,
> so use it if available, and fall back to the hardcoded -lcrypto if not.
> 
> Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>

Applied with one fixup.  Thanks!

- Eric

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

* Re: [fsverity-utils PATCH v2 2/2] Generate and install libfsverity.pc
  2020-10-26 11:15   ` [fsverity-utils PATCH v2 2/2] Generate and install libfsverity.pc luca.boccassi
@ 2020-10-26 17:32     ` Eric Biggers
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2020-10-26 17:32 UTC (permalink / raw)
  To: luca.boccassi; +Cc: linux-fscrypt

On Mon, Oct 26, 2020 at 11:15:06AM +0000, 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>

Applied with a couple fixups.  Thanks!

- Eric

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

end of thread, other threads:[~2020-10-26 17:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 17:59 [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags luca.boccassi
2020-10-22 17:59 ` [fsverity-utils PATCH 2/2] Generate and install libfsverity.pc luca.boccassi
2020-10-24  3:56   ` Eric Biggers
2020-10-26 11:16     ` Luca Boccassi
2020-10-24  4:07 ` [fsverity-utils PATCH 1/2] Use pkg-config to get libcrypto build flags Eric Biggers
2020-10-26 11:16   ` Luca Boccassi
2020-10-26 11:15 ` [fsverity-utils PATCH v2 " luca.boccassi
2020-10-26 11:15   ` [fsverity-utils PATCH v2 2/2] Generate and install libfsverity.pc luca.boccassi
2020-10-26 17:32     ` Eric Biggers
2020-10-26 17:32   ` [fsverity-utils PATCH v2 1/2] Use pkg-config to get libcrypto build flags Eric Biggers

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.