diff mbox series

[1/2] livepatch-tools: add -largp option when required

Message ID 20231113160940.52430-2-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show
Series livepatch-tools: fixes for building on non-glibc | expand

Commit Message

Roger Pau Monne Nov. 13, 2023, 4:09 p.m. UTC
crate-diff-object makes use of argp library, and depending on the libc
used by the system (ie: musl or BSD libc) argp is a separate library
and requires the addition of -largp to the build rune.

Introduce some shell logic to detect whether -largp is required for
linking create-diff-object.

I haven't done this as a reusable macro because I'm not sure there's
much point in doing so, the only library we need to test for is argp,
anything else is likely to be a mandatory library flag that doesn't
require such testing (like libelf for example).

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index f96b150539d2..2f74c3433336 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,10 @@  LIBEXECDIR = $(DESTDIR)$(PREFIX)/libexec/livepatch-build-tools
 CFLAGS  += -Iinsn -Wall -g
 LDFLAGS = -lelf
 
+# Non GNU libc systems usually have argp as a standalone library.
+LDFLAGS += $(shell if test -z "`$(CC) -largp 2>&1 | grep '\-largp'`"; \
+                      then echo "-largp"; fi;)
+
 TARGETS = create-diff-object prelink
 CREATE_DIFF_OBJECT_OBJS = create-diff-object.o lookup.o insn/insn.o insn/inat.o common.o
 PRELINK_OBJS = prelink.o lookup.o insn/insn.o insn/inat.o common.o