From ba1183da9a10b94611cad88c44a5c6df005f9b55 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 14:48:52 +0800 Subject: rules.mak: fix $(obj) to a real relative path 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 passed in as argument of unnest-vars, as well as nested variables, so that different Makefiles can pass in a right value. Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 807054b3a1..52b1958b4b 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,16 @@ defconfig: ifneq ($(wildcard config-host.mak),) include $(SRC_PATH)/Makefile.objs +endif + +dummy := $(call unnest-vars,, \ + stub-obj-y \ + util-obj-y \ + qga-obj-y \ + block-obj-y \ + common-obj-y) + +ifneq ($(wildcard config-host.mak),) include $(SRC_PATH)/tests/Makefile endif ifeq ($(CONFIG_SMARTCARD_NSS),y) @@ -130,6 +140,10 @@ endif all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) + +vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS) + config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak qemu-options.def: $(SRC_PATH)/qemu-options.hx -- cgit v1.2.1 From 17969268f5938ae1d7f3dedbd73e507badb6146d Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 14:48:56 +0800 Subject: rules.mak: introduce DSO rules Add necessary rules and flags for shared object generation. The new rules introduced here are: 1) %.o in $(common-obj-m) is compiled to %.o, then linked to %.so. 2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern matching in Makefile. It's linked to "-shared" with all its dependencies (multiple *.o) as input. Which means the list of depended objects must be specified in each sub-Makefile.objs: foo.mo-objs := bar.o baz.o qux.o in the same style with foo.o-cflags and foo.o-libs. The objects here will be prefixed with "$(obj)/" if it's a subdirectory Makefile.objs. 3) For all files ending up in %.so, the following is added automatically: foo.o-cflags += -fPIC -DBUILD_DSO Also introduce --enable-modules in configure, the option will enable support of shared object build. Otherwise objects are static linked to executables. Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 52b1958b4b..9d53117832 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ 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 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) @@ -256,6 +256,8 @@ 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 $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ rm -f fsdev/*.pod rm -rf .libs */.libs -- cgit v1.2.1 From e26110cfc67d48331a76e9b1e6f7fed7569e1ab3 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 14:48:57 +0800 Subject: module: implement module loading This patch adds loading, stamp checking and initialization of modules. The init function of dynamic module is no longer directly called as __attribute__((constructor)) in static linked version, it is called only after passed the checking of presense of stamp symbol: qemu_stamp_$RELEASEHASH where $RELEASEHASH is generated by hashing version strings and content of configure script. With this, modules built from a different tree/version/configure will not be loaded. The module loading code requires gmodule-2.0. Modules are searched under - CONFIG_MODDIR - executable folder (to allow running qemu-{img,io} in the build directory) - ../ of executable folder (to allow running system emulator in the build directory) Modules are linked under their subdir respectively, then copied to top level of build directory for above convinience, e.g.: $(BUILD_DIR)/block/curl.so -> $(BUILD_DIR)/block-curl.so Signed-off-by: Paolo Bonzini Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9d53117832..07d1ed7d83 100644 --- a/Makefile +++ b/Makefile @@ -201,6 +201,9 @@ Makefile: $(version-obj-y) $(version-lobj-y) libqemustub.a: $(stub-obj-y) libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o +block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL +util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)' + ###################################################################### qemu-img.o: qemu-img-cmds.h -- cgit v1.2.1 From e3be6f0ecc7e2c8e47ae7a49d523c50bc1bdf621 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 14:48:58 +0800 Subject: Makefile: install modules with "make install" Install all the modules to ${MODDIR}. Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 07d1ed7d83..57d83a3dae 100644 --- a/Makefile +++ b/Makefile @@ -368,6 +368,12 @@ install-datadir install-localstatedir ifneq ($(TOOLS),) $(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)" endif +ifneq ($(CONFIG_MODULES),) + $(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)" + for s in $(patsubst %.mo,%$(DSOSUF),$(modules-m)); do \ + $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$${s//\//-}"; \ + done +endif ifneq ($(HELPERS-y),) $(INSTALL_DIR) "$(DESTDIR)$(libexecdir)" $(INSTALL_PROG) $(STRIP_OPT) $(HELPERS-y) "$(DESTDIR)$(libexecdir)" -- cgit v1.2.1 From cc47569881d56ab11bd33b6fbaf60aeedb25e8a9 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 14:48:59 +0800 Subject: Makefile: introduce common-obj-m and block-obj-m for DSO $(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does for $(block-obj-y). Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 57d83a3dae..992cd23856 100644 --- a/Makefile +++ b/Makefile @@ -129,7 +129,9 @@ dummy := $(call unnest-vars,, \ util-obj-y \ qga-obj-y \ block-obj-y \ - common-obj-y) + block-obj-m \ + common-obj-y \ + common-obj-m) ifneq ($(wildcard config-host.mak),) include $(SRC_PATH)/tests/Makefile -- cgit v1.2.1