qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-


From: Fam Zheng
Subject: [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO
Date: Thu, 5 Sep 2013 18:20:46 +0800

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]