Build system refactoring

The source tree is configured for a specific target as defined in the
targets directory.

The common target components are defined in targets/common. Targets
for real platform should include this directory to get the default
target libraries setup.

Change-Id: I7fced4bfacec97432cbbd4125bd5b4cdd21122e3
diff --git a/targets/corstone-300/retarget.c b/targets/corstone-300/retarget.c
index 1598427..d53431f 100644
--- a/targets/corstone-300/retarget.c
+++ b/targets/corstone-300/retarget.c
@@ -183,7 +183,28 @@
 }
 
 void RETARGET(_exit)(int return_code) {
-    exit(return_code);
+    char exit_code_buffer[64] = {0};
+    const char *p = exit_code_buffer;
+
+    /* Print out the exit code on the uart so any reader know how we exit. */
+    /* By appending 0x04, ASCII for end-of-transmission the FVP model exits,
+     * if the configuration parameter shutdown_on_eot on the uart is enabled.
+     * For some versions of FVP, the shutdown_on_eot is broken, but the same
+     * behaviour can be created by passing specifying a shutdown_tag= for the
+     * uart when starting the model so that is added last as well.
+     */
+
+    snprintf(exit_code_buffer, sizeof(exit_code_buffer),
+            "Application exit code: %d.\n"  // Let the readers know how we exit
+            "\04\n"                         // end-of-transmission
+            "EXITTHESIM\n",                 // shutdown_tag
+            return_code);
+
+    while (*p != '\0') {
+        uart_putc(*p++);
+    }
+
+    while (1) {}
 }
 
 int system(const char *cmd) {
@@ -231,12 +252,6 @@
     return 0;
 }
 
-void exit(int code) {
-    uart_putc((char)0x4);
-    uart_putc((char)code);
-    while (1) {}
-}
-
 int fputc(int ch, FILE *f) {
     (void)(f);
     return uart_putc(ch);