958e1b
From 237c8da272492bbb2c5fdbcb0c96f8d4ace88b72 Mon Sep 17 00:00:00 2001
958e1b
From: Fam Zheng <famz@redhat.com>
958e1b
Date: Wed, 16 Jul 2014 02:20:26 -0500
958e1b
Subject: [CHANGE 26/29] rules.mak: fix $(obj) to a real relative path
958e1b
To: rhvirt-patches@redhat.com,
958e1b
    jen@redhat.com
958e1b
958e1b
RH-Author: Fam Zheng <famz@redhat.com>
958e1b
Message-id: <1405477228-11490-3-git-send-email-famz@redhat.com>
958e1b
Patchwork-id: 59921
958e1b
O-Subject: [RHEL-7 qemu-kvm PATCH 2/4] rules.mak: fix $(obj) to a real relative path
958e1b
Bugzilla: 1017685
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
958e1b
From: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
958e1b
Upstream: ba1183da9a10b94611cad88c44a5c6df005f9b55
958e1b
958e1b
Makefile.target includes rule.mak and unnested common-obj-y, then prefix
958e1b
them with '../', this will ignore object specific QEMU_CFLAGS in subdir
958e1b
Makefile.objs:
958e1b
958e1b
$(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)
958e1b
958e1b
Because $(obj) here is './block', instead of '../block'. This doesn't
958e1b
hurt compiling because we basically build all .o from top Makefile,
958e1b
before entering Makefile.target, but it will affact arriving per-object
958e1b
libs support.
958e1b
958e1b
The starting point of $(obj) is passed in as argument of unnest-vars, as
958e1b
well as nested variables, so that different Makefiles can pass in a
958e1b
right value.
958e1b
958e1b
Signed-off-by: Fam Zheng <famz@redhat.com>
958e1b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
958e1b
This is manual backport.
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
Signed-off-by: Fam Zheng <famz@redhat.com>
958e1b
---
958e1b
 Makefile        | 14 ++++++++++++++
958e1b
 Makefile.objs   | 16 +---------------
958e1b
 Makefile.target | 17 +++++++++++++----
958e1b
 configure       |  1 +
958e1b
 rules.mak       | 14 +++++++++-----
958e1b
 5 files changed, 38 insertions(+), 24 deletions(-)
958e1b
958e1b
Signed-off-by: jen <jen@redhat.com>
958e1b
---
958e1b
 Makefile        | 14 ++++++++++++++
958e1b
 Makefile.objs   | 16 +---------------
958e1b
 Makefile.target | 17 +++++++++++++----
958e1b
 configure       |  1 +
958e1b
 rules.mak       | 14 +++++++++-----
958e1b
 5 files changed, 38 insertions(+), 24 deletions(-)
958e1b
958e1b
diff --git a/Makefile b/Makefile
958e1b
index 66774de..f504754 100644
958e1b
--- a/Makefile
958e1b
+++ b/Makefile
958e1b
@@ -120,6 +120,16 @@ defconfig:
958e1b
 
958e1b
 ifneq ($(wildcard config-host.mak),)
958e1b
 include $(SRC_PATH)/Makefile.objs
958e1b
+endif
958e1b
+
958e1b
+dummy := $(call unnest-vars,, \
958e1b
+                stub-obj-y \
958e1b
+                util-obj-y \
958e1b
+                qga-obj-y \
958e1b
+                block-obj-y \
958e1b
+                common-obj-y)
958e1b
+
958e1b
+ifneq ($(wildcard config-host.mak),)
958e1b
 include $(SRC_PATH)/tests/Makefile
958e1b
 endif
958e1b
 ifeq ($(CONFIG_SMARTCARD_NSS),y)
958e1b
@@ -128,6 +138,10 @@ endif
958e1b
 
958e1b
 all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
958e1b
 
958e1b
+vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
958e1b
+
958e1b
+vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
958e1b
+
958e1b
 config-host.h: config-host.h-timestamp
958e1b
 config-host.h-timestamp: config-host.mak
958e1b
 qemu-options.def: $(SRC_PATH)/qemu-options.hx
958e1b
diff --git a/Makefile.objs b/Makefile.objs
958e1b
index 67b4a28..f83a5b2 100644
958e1b
--- a/Makefile.objs
958e1b
+++ b/Makefile.objs
958e1b
@@ -40,7 +40,7 @@ libcacard-y += libcacard/vcardt.o
958e1b
 # single QEMU executable should support all CPUs and machines.
958e1b
 
958e1b
 ifeq ($(CONFIG_SOFTMMU),y)
958e1b
-common-obj-y = $(block-obj-y) blockdev.o blockdev-nbd.o block/
958e1b
+common-obj-y = blockdev.o blockdev-nbd.o block/
958e1b
 common-obj-y += net/
958e1b
 common-obj-y += readline.o
958e1b
 common-obj-y += qdev-monitor.o device-hotplug.o
958e1b
@@ -103,17 +103,3 @@ common-obj-y += disas/
958e1b
 # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
958e1b
 # by libqemuutil.a.  These should be moved to a separate .json schema.
958e1b
 qga-obj-y = qga/ qapi-types.o qapi-visit.o
958e1b
-
958e1b
-vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
958e1b
-
958e1b
-vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
958e1b
-
958e1b
-QEMU_CFLAGS+=$(GLIB_CFLAGS)
958e1b
-
958e1b
-nested-vars += \
958e1b
-	stub-obj-y \
958e1b
-	util-obj-y \
958e1b
-	qga-obj-y \
958e1b
-	block-obj-y \
958e1b
-	common-obj-y
958e1b
-dummy := $(call unnest-vars)
958e1b
diff --git a/Makefile.target b/Makefile.target
958e1b
index 1cafb17..b871dda 100644
958e1b
--- a/Makefile.target
958e1b
+++ b/Makefile.target
958e1b
@@ -135,13 +135,22 @@ endif # CONFIG_SOFTMMU
958e1b
 # Workaround for http://gcc.gnu.org/PR55489, see configure.
958e1b
 %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
958e1b
 
958e1b
-nested-vars += obj-y
958e1b
+dummy := $(call unnest-vars,,obj-y)
958e1b
 
958e1b
-# This resolves all nested paths, so it must come last
958e1b
+# we are making another call to unnest-vars with different vars, protect obj-y,
958e1b
+# it can be overriden in subdir Makefile.objs
958e1b
+obj-y-save := $(obj-y)
958e1b
+
958e1b
+block-obj-y :=
958e1b
+common-obj-y :=
958e1b
 include $(SRC_PATH)/Makefile.objs
958e1b
+dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
958e1b
 
958e1b
-all-obj-y = $(obj-y)
958e1b
-all-obj-y += $(addprefix ../, $(common-obj-y))
958e1b
+# Now restore obj-y
958e1b
+obj-y := $(obj-y-save)
958e1b
+
958e1b
+all-obj-y = $(obj-y) $(common-obj-y)
958e1b
+all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
958e1b
 
958e1b
 ifndef CONFIG_HAIKU
958e1b
 LIBS+=-lm
958e1b
diff --git a/configure b/configure
958e1b
index 0ac437c..8c6f4e5 100755
958e1b
--- a/configure
958e1b
+++ b/configure
958e1b
@@ -2333,6 +2333,7 @@ if $pkg_config --atleast-version=$glib_req_ver gthread-2.0 gmodule-2.0 > /dev/nu
958e1b
 then
958e1b
     glib_cflags=`$pkg_config --cflags gthread-2.0 gmodule-2.0 2>/dev/null`
958e1b
     glib_libs=`$pkg_config --libs gthread-2.0 gmodule-2.0 2>/dev/null`
958e1b
+    CFLAGS="$glib_cflags $CFLAGS"
958e1b
     LIBS="$glib_libs $LIBS"
958e1b
     libs_qga="$glib_libs $libs_qga"
958e1b
 else
958e1b
diff --git a/rules.mak b/rules.mak
958e1b
index 4499745..0c5125d 100644
958e1b
--- a/rules.mak
958e1b
+++ b/rules.mak
958e1b
@@ -103,9 +103,6 @@ clean: clean-timestamp
958e1b
 
958e1b
 # magic to descend into other directories
958e1b
 
958e1b
-obj := .
958e1b
-old-nested-dirs :=
958e1b
-
958e1b
 define push-var
958e1b
 $(eval save-$2-$1 = $(value $1))
958e1b
 $(eval $1 :=)
958e1b
@@ -119,9 +116,11 @@ endef
958e1b
 
958e1b
 define unnest-dir
958e1b
 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
958e1b
-$(eval obj := $(obj)/$1)
958e1b
+$(eval obj-parent-$1 := $(obj))
958e1b
+$(eval obj := $(if $(obj),$(obj)/$1,$1))
958e1b
 $(eval include $(SRC_PATH)/$1/Makefile.objs)
958e1b
-$(eval obj := $(patsubst %/$1,%,$(obj)))
958e1b
+$(eval obj := $(obj-parent-$1))
958e1b
+$(eval obj-parent-$1 := )
958e1b
 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
958e1b
 endef
958e1b
 
958e1b
@@ -136,7 +135,12 @@ $(if $(nested-dirs),
958e1b
 endef
958e1b
 
958e1b
 define unnest-vars
958e1b
+$(eval obj := $1)
958e1b
+$(eval nested-vars := $2)
958e1b
+$(eval old-nested-dirs := )
958e1b
 $(call unnest-vars-1)
958e1b
+$(if $1,$(foreach v,$(nested-vars),$(eval \
958e1b
+	$v := $(addprefix $1/,$($v)))))
958e1b
 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
958e1b
 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
958e1b
 $(foreach var,$(nested-vars), $(eval \
958e1b
-- 
958e1b
1.9.3
958e1b