Rework common.mk

The code added by commits d6536da64deb ("Commonlize xtest compilation
among all platforms") and 070d95595e1d1 ("common build: optee
components") introduces race conditions that break parallel build (make
-jX). This is due to manually launching a make sub-process to run the
-common targets, and can be fixed by just declaring a dependency
instead. Specific flags are appended to common flags, rather than
passed as arguments to a new "make" sub-process.

So, basically:

 foo-common:
 	$(MAKE) -C foo_dir [A=a B=B]

 foo:
 	$(MAKE) foo-common [C=c]

is turned into:

 FOO_COMMON_FLAGS ?= A=a B=b
 foo-common:
 	$(MAKE) -C foo_dir $(FOO_COMMON_FLAGS)

 FOO_COMMON_FLAGS += C=c
 foo: foo-common

At the same time this allows foo: to override flags, for instance
set A=aa in the above example (prior to this, A=a would have had a
higher priority).

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Pascal Brand <pascal.brand@st.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
diff --git a/qemu.mk b/qemu.mk
index 09e0897..3fbe22d 100644
--- a/qemu.mk
+++ b/qemu.mk
@@ -101,23 +101,20 @@
 ################################################################################
 # OP-TEE
 ################################################################################
-optee-os:
-	$(MAKE) \
-		PLATFORM=vexpress \
-		PLATFORM_FLAVOR=qemu_virt \
-		CFG_TEE_CORE_LOG_LEVEL=3 \
-			optee-os-common
+OPTEE_OS_COMMON_FLAGS += PLATFORM=vexpress-qemu_virt
+optee-os: optee-os-common
 
-optee-os-clean:
-	$(MAKE) \
-		PLATFORM=vexpress \
-		PLATFORM_FLAVOR=qemu_virt \
-			optee-os-clean-common
+OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=vexpress-qemu_virt
+optee-os-clean: optee-os-clean-common
 
 optee-client: optee-client-common
+
 optee-client-clean: optee-client-clean-common
-optee-linuxdriver:
-	$(MAKE)	ARCH=arm optee-linuxdriver-common
+
+OPTEE_LINUXDRIVER_COMMON_FLAGS += ARCH=arm
+optee-linuxdriver: optee-linuxdriver-common
+
+OPTEE_LINUXDRIVER_CLEAN_COMMON_FLAGS += ARCH=arm
 optee-linuxdriver-clean: optee-linuxdriver-clean-common
 
 ################################################################################
@@ -132,15 +129,14 @@
 ################################################################################
 # xtest / optee_test
 ################################################################################
-xtest:
-	$(MAKE) xtest-common CFG_ARM32=y
+XTEST_COMMON_FLAGS += CFG_ARM32=y
+xtest: xtest-common
 
-xtest-clean:
-	$(MAKE) xtest-clean-common CFG_ARM32=y
+XTEST_CLEAN_COMMON_FLAGS += CFG_ARM32=y
+xtest-clean: xtest-clean-common
 
-xtest-patch:
-	$(MAKE) xtest-patch-common CFG_ARM32=y
-
+XTEST_PATCH_COMMON_FLAGS += CFG_ARM32=y
+xtest-patch: xtest-patch-common
 
 ################################################################################
 # Root FS
@@ -195,7 +191,8 @@
 
 .PHONY: run
 # This target enforces updating root fs etc
-run: | bios-qemu run-only
+run: all
+	$(MAKE) run-only
 
 .PHONY: run-only
 run-only: