From 93101699f5e1190184c00c99ab7b6e9717e5019a Mon Sep 17 00:00:00 2001
From: "Robin H. Johnson" <robbat2@gentoo.org>
Date: Wed, 24 Jul 2019 11:11:35 +0200
Subject: [PATCH] Add dynamic static ldflags

Forward-ported from 2.02.178 to 2.03.05
Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
---
 configure.ac                 | 2 ++
 daemons/dmeventd/Makefile.in | 2 +-
 make.tmpl.in                 | 1 +
 tools/Makefile.in            | 2 +-
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1e45c0edcb..cc2625294a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,7 @@ case "$host_os" in
 		CLDFLAGS="${CLDFLAGS:"$LDFLAGS"} -Wl,--version-script,.export.sym"
 		# equivalent to -rdynamic
 		ELDFLAGS="-Wl,--export-dynamic"
+		STATIC_LDFLAGS="-Wl,--no-export-dynamic"
 		# FIXME Generate list and use --dynamic-list=.dlopen.sym
 		CLDWHOLEARCHIVE="-Wl,-whole-archive"
 		CLDNOWHOLEARCHIVE="-Wl,-no-whole-archive"
@@ -1758,6 +1759,7 @@ AC_SUBST(SYSCONFDIR)
 AC_SUBST(SYSTEMD_LIBS)
 AC_SUBST(SNAPSHOTS)
 AC_SUBST(STATICDIR)
+AC_SUBST(STATIC_LDFLAGS)
 AC_SUBST(STATIC_LINK)
 AC_SUBST(TESTSUITE_DATA)
 AC_SUBST(THIN)
diff --git a/daemons/dmeventd/Makefile.in b/daemons/dmeventd/Makefile.in
index 6bd36d0325..a3c30ec1a0 100644
--- a/daemons/dmeventd/Makefile.in
+++ b/daemons/dmeventd/Makefile.in
@@ -66,7 +66,7 @@ dmeventd: $(LIB_SHARED) dmeventd.o
 
 dmeventd.static: $(LIB_STATIC) dmeventd.o
 	@echo "    [CC] $@"
-	$(Q) $(CC) $(CFLAGS) $(LDFLAGS) -static -L. -L$(interfacebuilddir) dmeventd.o \
+	$(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(STATIC_LDFLAGS) -static -L. -L$(interfacebuilddir) dmeventd.o \
 		-o $@ $(DL_LIBS) $(DMEVENT_LIBS) $(LIBS) $(STATIC_LIBS)
 
 ifeq ("@PKGCONFIG@", "yes")
diff --git a/make.tmpl.in b/make.tmpl.in
index f3332e91c1..1489c2afad 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -68,6 +68,7 @@ DEFS += @DEFS@
 # FIXME set this only where it's needed, not globally?
 CFLAGS ?= @COPTIMISE_FLAG@ @CFLAGS@
 LDFLAGS ?= @LDFLAGS@
+STATIC_LDFLAGS += @STATIC_LDFLAGS@
 CLDFLAGS += @CLDFLAGS@
 ELDFLAGS += @ELDFLAGS@
 LDDEPS += @LDDEPS@
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 2620daa17c..e5fc9c4ae4 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -136,7 +136,7 @@ man-generator: man-generator.o
 
 lvm.static: $(OBJECTS) lvm-static.o $(LVMINTERNAL_LIBS)
 	@echo "    [CC] $@"
-	$(Q) $(CC) $(CFLAGS) $(LDFLAGS) -static -L$(interfacebuilddir) -o $@ $+ \
+	$(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(STATIC_LDFLAGS) -static -L$(interfacebuilddir) -o $@ $+ \
 	      $(DMEVENT_LIBS) $(STATIC_LIBS) $(LVMLIBS)
 
 liblvm2cmd.a: $(top_builddir)/lib/liblvm-internal.a $(OBJECTS) lvmcmdlib.o lvm2cmd.o
-- 
2.22.0

