qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support
@ 2013-09-05 10:20 Fam Zheng
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
                   ` (6 more replies)
  0 siblings, 7 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

This series implements feature of shared object building as described in:

http://wiki.qemu.org/Features/Modules

It's achieved in three steps, with extra bonus to change curl to a shared
library module in the end (only to demonstrate the usage, no "make install"
support of .so files yet).

1. Allow per object cflags and libs:

    [01/06] make.rule: fix $(obj) to a real relative path
    [02/06] rule.mak: allow per object cflags and libs

2. Rules for building .so:

    [03/06] Makefile: define curl cflags and libs with object

3. Code to load module. All .so files are scanned and loaded when program
   starts:

    [04/06] Makefile: introduce common-obj-m and block-obj-m for DSO

4. curl adoption:

    [05/06] module: load modules at start
    [06/06] curl: build as shared library



Fam Zheng (6):
  make.rule: fix $(obj) to a real relative path
  rule.mak: allow per object cflags and libs
  Makefile: define curl cflags and libs with object
  Makefile: introduce common-obj-m and block-obj-m for DSO
  module: load modules at start
  curl: build as shared library

 Makefile              | 24 +++++++++++++++++++++---
 Makefile.objs         | 10 +++++++++-
 Makefile.target       |  3 ++-
 block/Makefile.objs   |  3 ++-
 configure             | 28 ++++++++++++++++------------
 include/qemu/module.h |  2 ++
 qemu-img.c            |  2 ++
 qemu-io.c             |  1 +
 qemu-nbd.c            |  1 +
 rules.mak             | 20 ++++++++++++++------
 scripts/create_config |  3 +++
 util/Makefile.objs    |  2 ++
 util/module.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 vl.c                  |  1 +
 14 files changed, 116 insertions(+), 24 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
@ 2013-09-05 10:20 ` Fam Zheng
  2013-09-06  9:41   ` Paolo Bonzini
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 2/6] rule.mak: allow per object cflags and libs Fam Zheng
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

Makefile.target includes rule.mak and unnested common-obj-y, then prefix
them with '../', this will ignore object specific QEMU_CFLAGS in subdir
Makefile.objs:

    $(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)

Because $(obj) here is './block', instead of '../block'. This doesn't
hurt compiling because we basically build all .o from top Makefile,
before entering Makefile.target, but it will affact arriving per-object
libs support.

The starting point of $(obj) is fixed before including ./Makefile.objs,
to get consistency with nested Makefile rules in target rule and
variable definition.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 Makefile.target | 3 ++-
 rules.mak       | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 9a49852..b35e7c1 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -144,12 +144,13 @@ endif # CONFIG_SOFTMMU
 %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
 
 nested-vars += obj-y
+obj := ..
 
 # This resolves all nested paths, so it must come last
 include $(SRC_PATH)/Makefile.objs
 
 all-obj-y = $(obj-y)
-all-obj-y += $(addprefix ../, $(common-obj-y))
+all-obj-y += $(addprefix $(obj)/, $(common-obj-y))
 
 ifndef CONFIG_HAIKU
 LIBS+=-lm
diff --git a/rules.mak b/rules.mak
index 4499745..5758137 100644
--- a/rules.mak
+++ b/rules.mak
@@ -103,7 +103,6 @@ clean: clean-timestamp
 
 # magic to descend into other directories
 
-obj := .
 old-nested-dirs :=
 
 define push-var
@@ -119,9 +118,10 @@ endef
 
 define unnest-dir
 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
-$(eval obj := $(obj)/$1)
+$(eval old-obj := $(obj))
+$(eval obj := $(if $(obj),$(obj)/$1,$1))
 $(eval include $(SRC_PATH)/$1/Makefile.objs)
-$(eval obj := $(patsubst %/$1,%,$(obj)))
+$(eval obj := $(old-obj))
 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
 endef
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [RFC PATCH 2/6] rule.mak: allow per object cflags and libs
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
@ 2013-09-05 10:20 ` Fam Zheng
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 3/6] Makefile: define curl cflags and libs with object Fam Zheng
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

Adds extract-libs in LINK to expand any "per object libs", the syntax to define
such a libs options is like:

        $(obj)/curl.o-libs = $(CURL_LIBS)

in block/Makefile.objs.

Similarly,

        $(obj)foo.o-cflags = $(FOO_CFLAGS)

is also supported.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 rules.mak | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/rules.mak b/rules.mak
index 5758137..8276421 100644
--- a/rules.mak
+++ b/rules.mak
@@ -17,15 +17,17 @@ QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
 QEMU_INCLUDES += -I$(<D) -I$(@D)
 
+extract-libs = $(strip $(foreach o,$1,$($(obj-base)$o-libs)))
+
 %.o: %.c
-	$(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  CC    $(TARGET_DIR)$@")
+	$(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<,"  CC    $(TARGET_DIR)$@")
 %.o: %.rc
 	$(call quiet-command,$(WINDRES) -I. -o $@ $<,"  RC    $(TARGET_DIR)$@")
 
 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)$@")
+       $(call extract-libs,$^) $(LIBS),"  LINK  $(TARGET_DIR)$@")
 else
 LIBTOOL += $(if $(V),,--quiet)
 %.lo: %.c
@@ -41,7 +43,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)$@")
+       $(call extract-libs,$^) $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", "  LINK  ")"$(TARGET_DIR)$@")
 endif
 
 %.asm: %.S
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [RFC PATCH 3/6] Makefile: define curl cflags and libs with object
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 2/6] rule.mak: allow per object cflags and libs Fam Zheng
@ 2013-09-05 10:20 ` Fam Zheng
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

We have per object cflags and libs support now, move CURL_CFLAGS and
CURL_LIBS from global option variables to a per object basis.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/Makefile.objs | 3 ++-
 configure           | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 4cf9aa4..b1e1520 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -23,4 +23,5 @@ common-obj-y += commit.o
 common-obj-y += mirror.o
 common-obj-y += backup.o
 
-$(obj)/curl.o: QEMU_CFLAGS+=$(CURL_CFLAGS)
+$(obj)/curl.o-cflags := $(CURL_CFLAGS)
+$(obj)/curl.o-libs := $(CURL_LIBS)
diff --git a/configure b/configure
index 0a55c20..48e14b8 100755
--- a/configure
+++ b/configure
@@ -2199,8 +2199,6 @@ EOF
   curl_libs=`$curlconfig --libs 2>/dev/null`
   if compile_prog "$curl_cflags" "$curl_libs" ; then
     curl=yes
-    libs_tools="$curl_libs $libs_tools"
-    libs_softmmu="$curl_libs $libs_softmmu"
   else
     if test "$curl" = "yes" ; then
       feature_not_found "curl"
@@ -3878,6 +3876,7 @@ fi
 if test "$curl" = "yes" ; then
   echo "CONFIG_CURL=y" >> $config_host_mak
   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
+  echo "CURL_LIBS=$curl_libs" >> $config_host_mak
 fi
 if test "$brlapi" = "yes" ; then
   echo "CONFIG_BRLAPI=y" >> $config_host_mak
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
                   ` (2 preceding siblings ...)
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 3/6] Makefile: define curl cflags and libs with object Fam Zheng
@ 2013-09-05 10:20 ` Fam Zheng
  2013-09-05 19:24   ` Richard Henderson
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 5/6] module: load modules at start Fam Zheng
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

Add necessary rules and flags for shared object generation.
common-obj-m will include block-obj-m, as common-obj-y for block-obj-y.
The rules introduced here are:

  QEMU_CFLAGS += -shared -fPIC, for all %.o of shared objects.

  1) %.o in $(common-obj-m) is compiled to %.o, with
     "QEMU_CFLAGS += -shared -fPIC". Then "linked" to %.mo, which is an
     incremental object with "ln -r". This step is for consistency with
     %.mod case and has no effect.

  2) %.mod in $(common-obj-m) is generated by "ln -r", with all its
     dependencies (multiple *.o) as input. Which means the list of
     dependency objects must be ruled out in each sub-Makefile.objs
     like:

        $(obj)/foo.mod: $(addprefix $(obj)/,bar.o baz.o qux.o)

     Notice that $(obj)/ is required for both target and dependency in
     the rule.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 Makefile      | 24 +++++++++++++++++++++---
 Makefile.objs | 10 +++++++++-
 configure     |  3 +++
 rules.mak     |  6 ++++++
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 806946e..130a497 100644
--- a/Makefile
+++ b/Makefile
@@ -56,7 +56,7 @@ Makefile: ;
 configure: ;
 
 .PHONY: all clean cscope distclean dvi html info install install-doc \
-	pdf recurse-all speed test dist
+	pdf recurse-all speed test dist modules
 
 $(call set-vpath, $(SRC_PATH))
 
@@ -121,7 +121,22 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y)
 include $(SRC_PATH)/libcacard/Makefile
 endif
 
-all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
+all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules
+
+mod-obj-m = $(patsubst %.o,%$(DSOSUF),$(filter %.o,$(common-obj-m))) \
+          $(patsubst %.mo,%$(DSOSUF),$(filter %.mo,$(common-obj-m)))
+mod-obj-y = $(patsubst %.mo,%.mo.o,$(filter %.mo,$(common-obj-y)))
+
+# Generate rules for single file modules (%.mo: %.o).
+# For multi file modules, dependencies should be listed explicitly in
+# Makefile.objs
+$(foreach o,$(mod-obj-m) $(mod-obj-y),$(eval \
+	$(patsubst %$(DSOSUF),%.mo,$o): $(patsubst %.c,%.o,$(wildcard $(patsubst %$(DSOSUF),%.c,$o))) \
+	))
+
+modules: $(mod-obj-m)
+modules: BUILD_DYNAMIC = 1
+modules: QEMU_CFLAGS += -shared -fPIC
 
 config-host.h: config-host.h-timestamp
 config-host.h-timestamp: config-host.mak
@@ -155,7 +170,7 @@ subdir-dtc:dtc/libfdt dtc/tests
 dtc/%:
 	mkdir -p $@
 
-$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y)
+$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(common-obj-m)
 
 ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
 romsubdir-%:
@@ -235,6 +250,9 @@ clean:
 	rm -f qemu-options.def
 	find . -name '*.[oda]' -type f -exec rm -f {} +
 	find . -name '*.l[oa]' -type f -exec rm -f {} +
+	find . -name '*'$(DSOSUF) -type f -exec rm -f {} +
+	find . -name '*.mo' -type f -exec rm -f {} +
+
 	rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
 	rm -Rf .libs
 	rm -f qemu-img-cmds.h
diff --git a/Makefile.objs b/Makefile.objs
index f46a4cd..2f178af 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -19,6 +19,8 @@ block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
 block-obj-y += qemu-coroutine-sleep.o
 block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
 
+block-obj-m = block/
+
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
 # only pull in the actual virtio-9p device if we also enabled virtio.
@@ -83,6 +85,9 @@ common-obj-$(CONFIG_SMARTCARD_NSS) += $(libcacard-y)
 
 common-obj-y += qmp-marshal.o
 common-obj-y += qmp.o hmp.o
+
+common-obj-m = $(block-obj-m)
+
 endif
 
 ######################################################################
@@ -121,5 +126,8 @@ nested-vars += \
 	util-obj-y \
 	qga-obj-y \
 	block-obj-y \
-	common-obj-y
+	block-obj-m \
+	common-obj-y \
+	common-obj-m
+
 dummy := $(call unnest-vars)
diff --git a/configure b/configure
index 48e14b8..8f0a882 100755
--- a/configure
+++ b/configure
@@ -190,6 +190,7 @@ mingw32="no"
 gcov="no"
 gcov_tool="gcov"
 EXESUF=""
+DSOSUF=".so"
 prefix="/usr/local"
 mandir="\${prefix}/share/man"
 datadir="\${prefix}/share"
@@ -580,6 +581,7 @@ fi
 
 if test "$mingw32" = "yes" ; then
   EXESUF=".exe"
+  DSOSUF=".dll"
   QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
   QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
@@ -4165,6 +4167,7 @@ echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
+echo "DSOSUF=$DSOSUF" >> $config_host_mak
 echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
 echo "POD2MAN=$POD2MAN" >> $config_host_mak
 echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_mak
diff --git a/rules.mak b/rules.mak
index 8276421..090eee1 100644
--- a/rules.mak
+++ b/rules.mak
@@ -58,6 +58,12 @@ endif
 %.o: %.dtrace
 	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   $(TARGET_DIR)$@")
 
+%$(DSOSUF) %.mo.o: %.mo
+	$(call quiet-command,$(LD) $< -o $@ -shared,"  LD[M] $(TARGET_DIR)$@")
+
+%.mo:
+	$(call quiet-command,$(LD) $(sort $^) -r -o $@,"  LD    $(TARGET_DIR)$@")
+
 %$(EXESUF): %.o
 	$(call LINK,$^)
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [RFC PATCH 5/6] module: load modules at start
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
                   ` (3 preceding siblings ...)
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
@ 2013-09-05 10:20 ` Fam Zheng
  2013-09-05 11:43   ` Lluís Vilanova
  2013-09-05 11:49   ` Michael Tokarev
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 6/6] curl: build as shared library Fam Zheng
  2013-09-05 10:25 ` [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
  6 siblings, 2 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

Add module_load_all to load all DSO modules under:
    /usr/lib/qemu/block/
    /usr/lib/qemu/net/
    /usr/lib/qemu/ui/
when starting process.

Requires gmodule-2.0 from glib.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 configure             | 20 +++++++++++---------
 include/qemu/module.h |  2 ++
 qemu-img.c            |  2 ++
 qemu-io.c             |  1 +
 qemu-nbd.c            |  1 +
 scripts/create_config |  3 +++
 util/Makefile.objs    |  2 ++
 util/module.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 vl.c                  |  1 +
 9 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 8f0a882..975853e 100755
--- a/configure
+++ b/configure
@@ -2238,15 +2238,17 @@ if test "$mingw32" = yes; then
 else
     glib_req_ver=2.12
 fi
-if $pkg_config --atleast-version=$glib_req_ver gthread-2.0 > /dev/null 2>&1
-then
-    glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
-    glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
-    LIBS="$glib_libs $LIBS"
-    libs_qga="$glib_libs $libs_qga"
-else
-    error_exit "glib-$glib_req_ver required to compile QEMU"
-fi
+for i in gthread-2.0 gmodule-2.0; do
+    if $pkg_config --atleast-version=$glib_req_ver $i > /dev/null 2>&1
+    then
+        glib_cflags=`$pkg_config --cflags $i 2>/dev/null`
+        glib_libs=`$pkg_config --libs $i 2>/dev/null`
+        LIBS="$glib_libs $LIBS"
+        libs_qga="$glib_libs $libs_qga"
+    else
+        error_exit "glib-$glib_req_ver required to compile QEMU"
+    fi
+done
 
 ##########################################
 # pixman support probe
diff --git a/include/qemu/module.h b/include/qemu/module.h
index c4ccd57..d3500be 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -37,4 +37,6 @@ void register_module_init(void (*fn)(void), module_init_type type);
 
 void module_call_init(module_init_type type);
 
+void module_load_all(void);
+
 #endif
diff --git a/qemu-img.c b/qemu-img.c
index b9a848d..e761027 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -34,6 +34,7 @@
 #include <getopt.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include "qemu/module.h"
 
 #ifdef _WIN32
 #include <windows.h>
@@ -2328,6 +2329,7 @@ int main(int argc, char **argv)
 
     error_set_progname(argv[0]);
 
+    module_load_all();
     qemu_init_main_loop();
     bdrv_init();
     if (argc < 2)
diff --git a/qemu-io.c b/qemu-io.c
index d54dc86..d02e8f5 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -398,6 +398,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
+    module_load_all();
     qemu_init_main_loop();
     bdrv_init();
 
diff --git a/qemu-nbd.c b/qemu-nbd.c
index f044546..ecea543 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -558,6 +558,7 @@ int main(int argc, char **argv)
         snprintf(sockpath, 128, SOCKET_PATH, basename(device));
     }
 
+    module_load_all();
     qemu_init_main_loop();
     bdrv_init();
     atexit(bdrv_close_all);
diff --git a/scripts/create_config b/scripts/create_config
index b1adbf5..3ecb789 100755
--- a/scripts/create_config
+++ b/scripts/create_config
@@ -104,6 +104,9 @@ case $line in
     value=${line#*=}
     echo "#define $name $value"
     ;;
+ DSOSUF=*)
+    echo "#define HOST_DSOSUF \"${line#*=}\""
+    ;;
 esac
 
 done # read
diff --git a/util/Makefile.objs b/util/Makefile.objs
index dc72ab0..33e56b0 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -11,3 +11,5 @@ util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o
 util-obj-y += qemu-option.o qemu-progress.o
 util-obj-y += hexdump.o
 util-obj-y += crc32c.o
+
+$(obj)/module.o-libs := -lglib
diff --git a/util/module.c b/util/module.c
index 7acc33d..29d3a4f 100644
--- a/util/module.c
+++ b/util/module.c
@@ -13,6 +13,8 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
+#include <gmodule.h>
+#include <dirent.h>
 #include "qemu-common.h"
 #include "qemu/queue.h"
 #include "qemu/module.h"
@@ -79,3 +81,41 @@ void module_call_init(module_init_type type)
         e->init();
     }
 }
+
+void module_load_all(void)
+{
+    static const char *module_dir_list[] = {
+        "/usr/lib/qemu/block/",
+        "/usr/lib/qemu/net/",
+        "/usr/lib/qemu/ui/",
+        NULL
+    };
+    const char **path;
+    const char *dsosuf = HOST_DSOSUF;
+    char fname[1024];
+    int suf_len = strlen(dsosuf);
+    DIR *dp;
+    struct dirent *ep = NULL;
+    GModule *g_module;
+    for (path = &module_dir_list[0]; *path != NULL; path++) {
+        dp = opendir(*path);
+        if (!dp) {
+            fprintf(stderr, "Failed to open dir %s\n", *path);
+        }
+        for (ep = readdir(dp); ep; ep = readdir(dp)) {
+            int len = strlen(ep->d_name);
+            if (len > suf_len &&
+                !strcmp(&ep->d_name[len - suf_len], dsosuf)) {
+                pstrcpy(fname, sizeof(fname), *path);
+                pstrcat(fname, sizeof(fname), ep->d_name);
+                g_module = g_module_open(fname, G_MODULE_BIND_LAZY);
+                if (!g_module) {
+                    fprintf(stderr, "Failed to open module file %s\n",
+                            g_module_error());
+                    continue;
+                }
+                printf("Loaded module %s\n", fname);
+            }
+        }
+    }
+}
diff --git a/vl.c b/vl.c
index dfbc071..c72e5a8 100644
--- a/vl.c
+++ b/vl.c
@@ -3873,6 +3873,7 @@ int main(int argc, char **argv, char **envp)
     }
     loc_set_none();
 
+    module_load_all();
     if (qemu_init_main_loop()) {
         fprintf(stderr, "qemu_init_main_loop failed\n");
         exit(1);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [RFC PATCH 6/6] curl: build as shared library
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
                   ` (4 preceding siblings ...)
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 5/6] module: load modules at start Fam Zheng
@ 2013-09-05 10:20 ` Fam Zheng
  2013-09-05 10:25 ` [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
  6 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, famz, stefanha

Produce block/curl.so with --enable-curl. "make install" is not
installing it yet, manually copy it to /usr/lib/qemu/block/curl.so to
make it loaded.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 975853e..ac81a7c 100755
--- a/configure
+++ b/configure
@@ -3878,7 +3878,7 @@ if test "$bswap_h" = "yes" ; then
   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
 fi
 if test "$curl" = "yes" ; then
-  echo "CONFIG_CURL=y" >> $config_host_mak
+  echo "CONFIG_CURL=m" >> $config_host_mak
   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
   echo "CURL_LIBS=$curl_libs" >> $config_host_mak
 fi
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support
  2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
                   ` (5 preceding siblings ...)
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 6/6] curl: build as shared library Fam Zheng
@ 2013-09-05 10:25 ` Fam Zheng
  6 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-05 10:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mjt, stefanha

On Thu, 09/05 18:20, Fam Zheng wrote:
> This series implements feature of shared object building as described in:
> 
> http://wiki.qemu.org/Features/Modules
> 
> It's achieved in three steps, with extra bonus to change curl to a shared
> library module in the end (only to demonstrate the usage, no "make install"
> support of .so files yet).
> 
> 1. Allow per object cflags and libs:
> 
>     [01/06] make.rule: fix $(obj) to a real relative path
>     [02/06] rule.mak: allow per object cflags and libs
> 
> 2. Rules for building .so:
> 
>     [03/06] Makefile: define curl cflags and libs with object

Sorry, misleading. 04 should be this step, 03, 06 is for curl enablement.

> 
> 3. Code to load module. All .so files are scanned and loaded when program
>    starts:
> 
>     [04/06] Makefile: introduce common-obj-m and block-obj-m for DSO
> 

And this should be patch 05.

> 4. curl adoption:
> 
>     [05/06] module: load modules at start
>     [06/06] curl: build as shared library
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 5/6] module: load modules at start
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 5/6] module: load modules at start Fam Zheng
@ 2013-09-05 11:43   ` Lluís Vilanova
  2013-09-06  6:33     ` Fam Zheng
  2013-09-05 11:49   ` Michael Tokarev
  1 sibling, 1 reply; 19+ messages in thread
From: Lluís Vilanova @ 2013-09-05 11:43 UTC (permalink / raw)
  To: Fam Zheng; +Cc: pbonzini, mjt, qemu-devel, stefanha

Fam Zheng writes:

> Add module_load_all to load all DSO modules under:
>     /usr/lib/qemu/block/
>     /usr/lib/qemu/net/
>     /usr/lib/qemu/ui/
> when starting process.

This should probably be based on a define with the prefix set at configure time.

Adding directories from command-line arguments into that list would also be
nice.


Lluis

-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 5/6] module: load modules at start
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 5/6] module: load modules at start Fam Zheng
  2013-09-05 11:43   ` Lluís Vilanova
@ 2013-09-05 11:49   ` Michael Tokarev
  1 sibling, 0 replies; 19+ messages in thread
From: Michael Tokarev @ 2013-09-05 11:49 UTC (permalink / raw)
  To: Fam Zheng; +Cc: pbonzini, qemu-devel, stefanha

05.09.2013 14:20, Fam Zheng wrote:
> Add module_load_all to load all DSO modules under:
>     /usr/lib/qemu/block/
>     /usr/lib/qemu/net/
>     /usr/lib/qemu/ui/
> when starting process.

NACK.

This is wrong, as has been mentioned already.
For example, you can't expect to load ui/*
from qemu-img, because qemu-img provides no
symbols needed to link ui stuff.

Much better approach is to hook this stuff into
object/module registration framework, in module.c.
And either load every object of a given kind at
the init time, or try to load it at lookup time
if the requested object isn't found in current
list.

I implemented this approach in my tree more than
a month ago.

Thanks,

/mjt

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
@ 2013-09-05 19:24   ` Richard Henderson
  2013-09-05 19:41     ` Paolo Bonzini
  2013-09-06  5:53     ` Fam Zheng
  0 siblings, 2 replies; 19+ messages in thread
From: Richard Henderson @ 2013-09-05 19:24 UTC (permalink / raw)
  To: Fam Zheng; +Cc: pbonzini, mjt, qemu-devel, stefanha

On 09/05/2013 03:20 AM, Fam Zheng wrote:
>   1) %.o in $(common-obj-m) is compiled to %.o, with
>      "QEMU_CFLAGS += -shared -fPIC". Then "linked" to %.mo, which is an
>      incremental object with "ln -r". This step is for consistency with
>      %.mod case and has no effect.

As a general rule, you should avoid ld -r unless you know exactly
what that implies for the given machine.  This is the sort of thing
that's highly likely to work on x86 while failing elsewhere.

E.g. ARM and PPC ld would like to add trampolines for direct calls
to reach the PLT entry.  If you create one object that's too large
then that's no longer possible.

E.g. MIPS and Alpha ld require that any one input object file
reference less than 64K worth of got entries.  Every separate
object file can address its own 64K segment of the got.  If you
combine too many objectsyou could overflow the got subsegments.

If our modules are small enough, we may never see any of these, but...

If you really require a single input file to ld for pattern matching
purposes, I highly recommend an ar file, and then use --whole-archive
to force the entire contents of the .a to be included.  This preserves
the original translation-unit boundaries for ld.


r~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-05 19:24   ` Richard Henderson
@ 2013-09-05 19:41     ` Paolo Bonzini
  2013-09-05 21:45       ` Peter Maydell
  2013-09-06  5:53     ` Fam Zheng
  1 sibling, 1 reply; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-05 19:41 UTC (permalink / raw)
  To: Richard Henderson; +Cc: mjt, Fam Zheng, qemu-devel, stefanha

Il 05/09/2013 21:24, Richard Henderson ha scritto:
> On 09/05/2013 03:20 AM, Fam Zheng wrote:
>>   1) %.o in $(common-obj-m) is compiled to %.o, with
>>      "QEMU_CFLAGS += -shared -fPIC". Then "linked" to %.mo, which is an
>>      incremental object with "ln -r". This step is for consistency with
>>      %.mod case and has no effect.
> 
> As a general rule, you should avoid ld -r unless you know exactly
> what that implies for the given machine.  This is the sort of thing
> that's highly likely to work on x86 while failing elsewhere.
> 
> E.g. ARM and PPC ld would like to add trampolines for direct calls
> to reach the PLT entry.  If you create one object that's too large
> then that's no longer possible.
> 
> E.g. MIPS and Alpha ld require that any one input object file
> reference less than 64K worth of got entries.  Every separate
> object file can address its own 64K segment of the got.  If you
> combine too many objectsyou could overflow the got subsegments.
> 
> If our modules are small enough, we may never see any of these, but...
> 
> If you really require a single input file to ld for pattern matching
> purposes, I highly recommend an ar file, and then use --whole-archive
> to force the entire contents of the .a to be included.  This preserves
> the original translation-unit boundaries for ld.

Yes, this is the reason why I suggested using libtool for this.  It
increases the cost of compilation by essentially doing it twice, on the
other hand you can simply use .la convenience libraries and libtool will
be able to link it transparently into either an executable or a shared
library.

Libtool used to be really bad, but most performance problems have been
solved.

Paolo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-05 19:41     ` Paolo Bonzini
@ 2013-09-05 21:45       ` Peter Maydell
  2013-09-06  8:26         ` Paolo Bonzini
  0 siblings, 1 reply; 19+ messages in thread
From: Peter Maydell @ 2013-09-05 21:45 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Fam Zheng, Michael Tokarev, QEMU Developers, Stefan Hajnoczi,
	Richard Henderson

On 5 September 2013 20:41, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Libtool used to be really bad, but most performance problems have been
> solved.

How about the "it silently creates things in dot-directories,
recompiles things at random times when it really shouldn't,
and is an enormous insane shell script" problems? The positives
would have to be really really strong before we let libtool
into the codebase...

-- PMM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-05 19:24   ` Richard Henderson
  2013-09-05 19:41     ` Paolo Bonzini
@ 2013-09-06  5:53     ` Fam Zheng
  2013-09-06  7:20       ` Richard Henderson
  1 sibling, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-06  5:53 UTC (permalink / raw)
  To: Richard Henderson; +Cc: pbonzini, mjt, qemu-devel, stefanha

On Thu, 09/05 12:24, Richard Henderson wrote:
> On 09/05/2013 03:20 AM, Fam Zheng wrote:
> >   1) %.o in $(common-obj-m) is compiled to %.o, with
> >      "QEMU_CFLAGS += -shared -fPIC". Then "linked" to %.mo, which is an
> >      incremental object with "ln -r". This step is for consistency with
> >      %.mod case and has no effect.
> 
> As a general rule, you should avoid ld -r unless you know exactly
> what that implies for the given machine.  This is the sort of thing
> that's highly likely to work on x86 while failing elsewhere.
> 
> E.g. ARM and PPC ld would like to add trampolines for direct calls
> to reach the PLT entry.  If you create one object that's too large
> then that's no longer possible.
> 
> E.g. MIPS and Alpha ld require that any one input object file
> reference less than 64K worth of got entries.  Every separate
> object file can address its own 64K segment of the got.  If you
> combine too many objectsyou could overflow the got subsegments.
> 
> If our modules are small enough, we may never see any of these, but...
> 
> If you really require a single input file to ld for pattern matching
> purposes, I highly recommend an ar file, and then use --whole-archive
> to force the entire contents of the .a to be included.  This preserves
> the original translation-unit boundaries for ld.
> 
OK. Thanks for pointing out. The problem with ar file is that --whole-archive
needs to be done specificly to modules .a, other libs shouldn't be linked with
this flag. I'll drop this step by changing my pattern matching approach in
Makefile, and just compile and link without such intermediate object file.

Fam

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 5/6] module: load modules at start
  2013-09-05 11:43   ` Lluís Vilanova
@ 2013-09-06  6:33     ` Fam Zheng
  0 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-06  6:33 UTC (permalink / raw)
  To: qemu-devel, pbonzini, mjt, stefanha

On Thu, 09/05 14:43, Lluís Vilanova wrote:
> Fam Zheng writes:
> 
> > Add module_load_all to load all DSO modules under:
> >     /usr/lib/qemu/block/
> >     /usr/lib/qemu/net/
> >     /usr/lib/qemu/ui/
> > when starting process.
> 
> This should probably be based on a define with the prefix set at configure time.
> 
Yes, will fix.

> Adding directories from command-line arguments into that list would also be
> nice.
> 
Of course, but I'd like to keep this series focusing on essential framework and
leave it for follow-ups.

Thanks,

Fam

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-06  5:53     ` Fam Zheng
@ 2013-09-06  7:20       ` Richard Henderson
  2013-09-06  7:27         ` Fam Zheng
  0 siblings, 1 reply; 19+ messages in thread
From: Richard Henderson @ 2013-09-06  7:20 UTC (permalink / raw)
  To: famz; +Cc: pbonzini, mjt, qemu-devel, stefanha

On 09/05/2013 10:53 PM, Fam Zheng wrote:
> OK. Thanks for pointing out. The problem with ar file is that --whole-archive
> needs to be done specificly to modules .a, other libs shouldn't be linked with
> this flag.

See also:

  --whole-archive foo.a --no-whole-archive


r~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-06  7:20       ` Richard Henderson
@ 2013-09-06  7:27         ` Fam Zheng
  0 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-06  7:27 UTC (permalink / raw)
  To: Richard Henderson; +Cc: pbonzini, mjt, qemu-devel, stefanha

On Fri, 09/06 00:20, Richard Henderson wrote:
> On 09/05/2013 10:53 PM, Fam Zheng wrote:
> > OK. Thanks for pointing out. The problem with ar file is that --whole-archive
> > needs to be done specificly to modules .a, other libs shouldn't be linked with
> > this flag.
> 
> See also:
> 
>   --whole-archive foo.a --no-whole-archive

Yes, this is a way to do it, but will complicates the link command, and may be
more error prone. I expanded foo.mo to its contained .o for static linking in
the next revision that's coming up.

Thanks,

Fam

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
  2013-09-05 21:45       ` Peter Maydell
@ 2013-09-06  8:26         ` Paolo Bonzini
  0 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-06  8:26 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Michael Tokarev, Fam Zheng, QEMU Developers, Stefan Hajnoczi,
	Richard Henderson

Il 05/09/2013 23:45, Peter Maydell ha scritto:
> On 5 September 2013 20:41, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Libtool used to be really bad, but most performance problems have been
>> solved.
> 
> How about the "it silently creates things in dot-directories,
> recompiles things at random times when it really shouldn't,
> and is an enormous insane shell script" problems? The positives
> would have to be really really strong before we let libtool
> into the codebase...

How about "we'd break compilation on your favorite OS"? :) Darwin ld
doesn't support --whole-archive, it needs a different incantation.
Relatively recent Solaris now has it, but Apple still holds the bastions.

Paolo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path
  2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
@ 2013-09-06  9:41   ` Paolo Bonzini
  0 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-06  9:41 UTC (permalink / raw)
  To: Fam Zheng; +Cc: mjt, qemu-devel, stefanha

Il 05/09/2013 12:20, Fam Zheng ha scritto:
> Makefile.target includes rule.mak and unnested common-obj-y, then prefix
> them with '../', this will ignore object specific QEMU_CFLAGS in subdir
> Makefile.objs:
> 
>     $(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)
> 
> Because $(obj) here is './block', instead of '../block'. This doesn't
> hurt compiling because we basically build all .o from top Makefile,
> before entering Makefile.target, but it will affact arriving per-object
> libs support.
> 
> The starting point of $(obj) is fixed before including ./Makefile.objs,
> to get consistency with nested Makefile rules in target rule and
> variable definition.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  Makefile.target | 3 ++-
>  rules.mak       | 6 +++---
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/Makefile.target b/Makefile.target
> index 9a49852..b35e7c1 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -144,12 +144,13 @@ endif # CONFIG_SOFTMMU
>  %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
>  
>  nested-vars += obj-y
> +obj := ..
>  
>  # This resolves all nested paths, so it must come last
>  include $(SRC_PATH)/Makefile.objs
>  
>  all-obj-y = $(obj-y)
> -all-obj-y += $(addprefix ../, $(common-obj-y))
> +all-obj-y += $(addprefix $(obj)/, $(common-obj-y))

The bug is clearly there, but I'm not sure this is correct.

"obj" is the path to the object file.  obj-y files are built in the
target directory, thus the extra ".." should apply only to common-obj-y;
$(obj-y) should not be prefixed.  So perhaps you need to:

1) move the nested-vars and unnest-vars call from Makefile.objs to
Makefile.  also move this line:

   QEMU_CFLAGS+=$(GLIB_CFLAGS)

which has no business in Makefile.objs.  With this change, Makefile.objs
is just a list, like other */Makefile.objs files.

2) remove the additional complication where common-obj-y is including
block-obj-y, just add it to all-obj-y manually.

3) in Makefile.target, do this:

block-obj-y = ../
common-obj-y = ../
nested-vars = obj-y block-obj-y common-obj-y
dummy := $(call unnest-vars)
all-obj-y = $(obj-y) $(common-obj-y) $(block-obj-y)

(Can all be done in a single patch).

?

>  
>  ifndef CONFIG_HAIKU
>  LIBS+=-lm
> diff --git a/rules.mak b/rules.mak
> index 4499745..5758137 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -103,7 +103,6 @@ clean: clean-timestamp
>  
>  # magic to descend into other directories
>  
> -obj := .
>  old-nested-dirs :=
>  
>  define push-var
> @@ -119,9 +118,10 @@ endef
>  
>  define unnest-dir
>  $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
> -$(eval obj := $(obj)/$1)
> +$(eval old-obj := $(obj))
> +$(eval obj := $(if $(obj),$(obj)/$1,$1))
>  $(eval include $(SRC_PATH)/$1/Makefile.objs)
> -$(eval obj := $(patsubst %/$1,%,$(obj)))
> +$(eval obj := $(old-obj))
>  $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))

old-obj doesn't work if you have multiple levels of nesting.  But you
can call the variable something like obj-parent-$1 instead to solve this
problem.

However, please clean it up afterwards with "$(eval obj-parent-$1 := )".

Paolo

>  endef
>  
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2013-09-06  9:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
2013-09-06  9:41   ` Paolo Bonzini
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 2/6] rule.mak: allow per object cflags and libs Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 3/6] Makefile: define curl cflags and libs with object Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
2013-09-05 19:24   ` Richard Henderson
2013-09-05 19:41     ` Paolo Bonzini
2013-09-05 21:45       ` Peter Maydell
2013-09-06  8:26         ` Paolo Bonzini
2013-09-06  5:53     ` Fam Zheng
2013-09-06  7:20       ` Richard Henderson
2013-09-06  7:27         ` Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 5/6] module: load modules at start Fam Zheng
2013-09-05 11:43   ` Lluís Vilanova
2013-09-06  6:33     ` Fam Zheng
2013-09-05 11:49   ` Michael Tokarev
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 6/6] curl: build as shared library Fam Zheng
2013-09-05 10:25 ` [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).