From c3410db9d0f941a6c464acabb8a63633ef614cbf Mon Sep 17 00:00:00 2001
From: Florian Weimer <fweimer@redhat.com>
Date: Fri, 21 Mar 2025 21:40:28 +0100
Subject: [PATCH] Makeconfig: Support $(+nolink-deps) in link flags

This allows adding dependencies to rules, but not linking against
them.

This is more or less a reimplementation of .EXTRA_PREREQS feature from
GNU make 4.3.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
---
 Makeconfig | 12 ++++++++----
 Makerules  |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/Makeconfig b/Makeconfig
index bf50406656..a2ea4f6a33 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -442,7 +442,8 @@ ifndef +link-pie
 	     $(filter-out $(addprefix $(csu-objpfx),start.o \
 						    S$(start-installed-name))\
 			  $(+preinit) $(link-extra-libs) \
-			  $(common-objpfx)libc% $(+postinit),$^) \
+			  $(common-objpfx)libc% $(+postinit) \
+			  $(+nolink-deps),$^) \
 	     $(link-extra-libs)
 +link-pie-after-libc = $(+postctorS) $(+postinit)
 define +link-pie
@@ -473,7 +474,8 @@ ifndef +link-static
 	      $(filter-out $(addprefix $(csu-objpfx),start.o \
 						     $(start-installed-name))\
 			   $(+preinit) $(link-extra-libs-static) \
-			   $(common-objpfx)libc% $(+postinit),$^) \
+			   $(common-objpfx)libc% $(+postinit) \
+			   $(+nolink-deps), $^) \
 	      $(link-extra-libs-static)
 +link-static-after-libc = $(+postctorT) $(+postinit)
 define +link-static
@@ -509,7 +511,8 @@ else  # not build-pie-default
 	      $(filter-out $(addprefix $(csu-objpfx),start.o \
 						     $(start-installed-name))\
 			   $(+preinit) $(link-extra-libs) \
-			   $(common-objpfx)libc% $(+postinit),$^) \
+			   $(common-objpfx)libc% $(+postinit) \
+			   $(+nolink-deps),$^) \
 	      $(link-extra-libs)
 +link-after-libc = $(+postctor) $(+postinit)
 define +link
@@ -549,7 +552,8 @@ endif  # +link
 	      $(filter-out $(addprefix $(csu-objpfx),start.o \
 						     $(start-name-2.0))\
 			   $(+preinit) $(link-extra-libs) \
-			   $(common-objpfx)libc% $(+postinit),$^) \
+			   $(common-objpfx)libc% $(+postinit) \
+			   $(+nolink-deps),$^) \
 	      $(link-extra-libs)
 +link-after-libc = $(+postctor) $(+postinit)
 define +link-2.0-tests
diff --git a/Makerules b/Makerules
index ada616891e..9dc60cc3ce 100644
--- a/Makerules
+++ b/Makerules
@@ -587,7 +587,7 @@ endef
 build-module-helper-objlist = \
 	$(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
 		   $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
-				$(elf-objpfx)sofini.os \
+				$(elf-objpfx)sofini.os $(+nolink-deps) \
 				$(link-libc-deps),$^))
 
 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)