From 35049389cdc50d4e3a460d40808a72a8c50207e7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Feb 2023 15:54:19 +0100 Subject: [PATCH] Fix static build For static builds, we need to propagate all the static library dependencies to the link of the program. E.g. if libstore-tests-exe depends on libnixstore-tests, and libnixstore-tests depends on libstore, then libstore-tests-exe needs to link against libstore. https://hydra.nixos.org/build/209007480 --- mk/libraries.mk | 5 ++++- mk/programs.mk | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mk/libraries.mk b/mk/libraries.mk index 6541775f3..02e4d47f9 100644 --- a/mk/libraries.mk +++ b/mk/libraries.mk @@ -67,6 +67,7 @@ define build-library $(1)_LDFLAGS_USE := $(1)_LDFLAGS_USE_INSTALLED := + $(1)_LIB_CLOSURE := $(1) $$(eval $$(call create-dir, $$(_d))) @@ -128,10 +129,12 @@ define build-library +$$(trace-ld) $(LD) -Ur -o $$(_d)/$$($(1)_NAME).o $$^ $$(trace-ar) $(AR) crs $$@ $$(_d)/$$($(1)_NAME).o - $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) + $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $(1)_INSTALL_PATH := $$(libdir)/$$($(1)_NAME).a + $(1)_LIB_CLOSURE += $$($(1)_LIBS) + endif $(1)_LDFLAGS_USE += $$($(1)_LDFLAGS_PROPAGATED) diff --git a/mk/programs.mk b/mk/programs.mk index 204409332..1ee1d3fa5 100644 --- a/mk/programs.mk +++ b/mk/programs.mk @@ -30,7 +30,7 @@ define build-program _d := $(buildprefix)$$($(1)_DIR) _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) $(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs)))) - _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) + _libs := $$(foreach lib, $$($(1)_LIBS), $$(foreach lib2, $$($$(lib)_LIB_CLOSURE), $$($$(lib2)_PATH))) $(1)_PATH := $$(_d)/$$($(1)_NAME) $$(eval $$(call create-dir, $$(_d))) @@ -58,7 +58,7 @@ define build-program else $(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $(DESTDIR)$$($(1)_INSTALL_DIR)/ - install -t $(DESTDIR)$$($(1)_INSTALL_DIR) $$< + +$$(trace-install) install -t $(DESTDIR)$$($(1)_INSTALL_DIR) $$< endif endif