make: fix "make clean" against directories generated at build

This change removes the directory created from xtest build and
xtest test TAs build.

Prevent trailing "/." in path string, i.e "$O"=="some/relative/path/.".
These fail are rejected by the rmdir command.
Allow O=. or O=./ by preventing execution of rmdir.

From TA root Makefile and as $(O) can be a relative path or absolute
path, change to makefile directory to 'rmdir' target from make command
execution path.

Let ta/Makefile handle the "ta/" sub-directory info in build/clean.
Let host/xtest/Makefile handle the "xtest/" sub-directory info in
build/clean.

Build output subdirectory should be nicely empty and ready to be
remove if exists. Root output directory is removed only if empty
as it might contain other stuff than our build artifacts.

As 'clean' rules can be ran from partially built environment, only
remove existing directories.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey)
Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (b2260, qemu)
diff --git a/scripts/common.mk b/scripts/common.mk
new file mode 100644
index 0000000..103a415
--- /dev/null
+++ b/scripts/common.mk
@@ -0,0 +1,9 @@
+# Makefile script used in various OP-TEE test components
+
+# Since 'clean' make rules rely on 'rmdir', removed directories shall
+# not end with 'current directory' (./ or .) subpath information.
+# This macro remove trailing './' info from input path.
+define strip-trailing-slashes-and-dots
+$(eval _o := $(patsubst %/,%,$(patsubst %/.,%,$(1))))$(if \
+	$(filter-out $(1),$(_o)),$(call strip-trailing-slashes-and-dots,$(_o)),$(_o))
+endef