diff mbox series

[fsverity-utils,1/2] Use pkg-config to get libcrypto build flags

Message ID 20201022175934.2999543-1-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>

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(-)

Comments

Eric Biggers Oct. 24, 2020, 4:07 a.m. UTC | #1
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
Luca Boccassi Oct. 26, 2020, 11:16 a.m. UTC | #2
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.
diff mbox series

Patch

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