util/cbmem/Makfile: Add rule `junit.xml` for Jenkins

The rule has the target `junit.xml` and runs `make clean` and `make` and
logs the result in the file `junit.xml` suitable for consumption by
Jenkins.

Change-Id: I42a31f6c7a45fa9c3773969d78f745fcc4e09dbd
Signed-off-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-on: http://review.coreboot.org/4611
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
diff --git a/util/cbmem/Makefile b/util/cbmem/Makefile
index 51ee927..fe9e923 100644
--- a/util/cbmem/Makefile
+++ b/util/cbmem/Makefile
@@ -42,3 +42,21 @@
 .PHONY: all clean distclean
 
 -include .dependencies
+
+junit.xml:
+	echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
+	$(MAKE) clean; \
+	echo "<testcase classname='cbmem' name='cbmem'>" >> $@.tmp; \
+	$(MAKE) >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \
+	if [ $$type = "failure" ]; then \
+		echo "<failure type='buildFailed'>" >> $@.tmp; \
+	else \
+		echo "<$$type>" >> $@.tmp; \
+	fi; \
+	echo '<![CDATA[' >> $@.tmp; \
+	cat $@.tmp.2 >> $@.tmp; \
+	echo "]]></$$type>" >>$@.tmp; \
+	rm -f $@.tmp.2; \
+	echo "</testcase>" >> $@.tmp; \
+	echo "</testsuite>" >> $@.tmp
+	mv $@.tmp $@