Skip to content

Commit

Permalink
Fix static build
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edolstra committed Feb 14, 2023
1 parent c184566 commit 3504938
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion mk/libraries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ define build-library

$(1)_LDFLAGS_USE :=
$(1)_LDFLAGS_USE_INSTALLED :=
$(1)_LIB_CLOSURE := $(1)

$$(eval $$(call create-dir, $$(_d)))

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mk/programs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3504938

Please sign in to comment.