Revert "Revert "Build System: Solve dependency problem for test""

This reverts commit 6fe7f194b9ba0375aeee6f0d93f74f95a820084b.

Reason for revert: Fixed all build break.

Change-Id: I0a4842df1225399752515a4cd7a7c14173a5bf7b
diff --git a/core/definitions.mk b/core/definitions.mk
index c46a873..e880fa5 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2478,6 +2478,25 @@
 	$$(align-package)
 endef
 
+# Create copy pair for compatibility suite
+# Filter out $(LOCAL_INSTALLED_MODULE) to prevent overriding target
+# $(1): source path
+# $(2): destination path
+# The format of copy pair is src:dst
+define compat-copy-pair
+$(if $(filter-out $(2), $(LOCAL_INSTALLED_MODULE)), $(1):$(2))
+endef
+
+# Create copy pair for $(1) $(2)
+# If $(2) is substring of $(3) do nothing.
+# $(1): source path
+# $(2): destination path
+# $(3): filter-out target
+# The format of copy pair is src:dst
+define filter-copy-pair
+$(if $(findstring $(2), $(3)),,$(1):$(2))
+endef
+
 # Copies many files.
 # $(1): The files to copy.  Each entry is a ':' separated src:dst pair
 # $(2): An optional directory to prepend to the destination