diff mbox series

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

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

Commit Message

Luca Boccassi Oct. 26, 2020, 11:15 a.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>
---
v2: quote PKGCONF in shell invocation

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

Comments

Eric Biggers Oct. 26, 2020, 5:32 p.m. UTC | #1
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
diff mbox series

Patch

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