Patchwork [RFC,2/4] build-sys: allow object-specific libraries to be used to link executables

login
register
mail settings
Submitter Michael Tokarev
Date June 18, 2013, 5:34 p.m.
Message ID <1371576844-28743-3-git-send-email-mjt@msgid.tls.msk.ru>
Download mbox | patch
Permalink /patch/252390/
State New
Headers show

Comments

Michael Tokarev - June 18, 2013, 5:34 p.m.
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 <mjt@tls.msk.ru>
---
 rules.mak |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Patch

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