When linking final executables consiting of various object files foo.o, one may define foo.libs variable to hold libraries needed to be linked with foo.o.
This way, we may specify dependencies inside the makefile fragments where corresponding objects are defined. Signed-off-by: Michael Tokarev <m...@tls.msk.ru> --- rules.mak | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rules.mak b/rules.mak index a6bb4f1..69764b9 100644 --- a/rules.mak +++ b/rules.mak @@ -22,10 +22,14 @@ QEMU_INCLUDES += -I$(<D) -I$(@D) %.o: %.rc $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@") +# check all .o files and extract any object-specific .libs +# we remove leading ../ in case the build is done in a subdir. +extract-libs = $(strip $(foreach o, $(patsubst ../%, %, $(filter %.o, $1)), $($(o:%.o=%.libs)))) + ifeq ($(LIBTOOL),) LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \ - $(LIBS)," LINK $(TARGET_DIR)$@") + $(LIBS) $(call extract-libs, $1)," LINK $(TARGET_DIR)$@") else LIBTOOL += $(if $(V),,--quiet) %.lo: %.c @@ -41,7 +45,7 @@ LINK = $(call quiet-command,\ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \ $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \ $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \ - $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@") + $(LIBS) $(call extract-libs, $1),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@") endif %.asm: %.S -- 1.7.10.4