DS800C400 fun, improved ROM interface and tinibios
[fw/sdcc] / src / z80 / main.c
index 233574c1d9fcc312101d54ea2f67c654ac8db815..2ff5b561c18e6f56090a3bdee189bb213aae4202 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sys/stat.h>
 #include "z80.h"
 #include "MySystem.h"
 #include "BuildCmd.h"
 #include "SDCCutil.h"
+#include "dbuf.h"
 
 static char _z80_defaultRules[] =
 {
@@ -285,8 +287,44 @@ _setValues(void)
 
   if (options.nostdlib == FALSE)
     {
-      setMainValue ("z80libspec", "-l\"{port}.lib\"");
-      setMainValue ("z80crt0", "\"crt0{objext}\"");
+      const char *s;
+      char path[PATH_MAX];
+      struct dbuf_s dbuf;
+
+      dbuf_init(&dbuf, PATH_MAX);
+
+      for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet))
+        {
+          buildCmdLine2(path, sizeof path, "-k\"%s" DIR_SEPARATOR_STRING "{port}\" ", s);
+          dbuf_append(&dbuf, path, strlen(path));
+        }
+      buildCmdLine2(path, sizeof path, "-l\"{port}.lib\"", s);
+      dbuf_append(&dbuf, path, strlen(path));
+
+      setMainValue ("z80libspec", dbuf_c_str(&dbuf));
+      dbuf_destroy(&dbuf);
+
+      for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet))
+        {
+          struct stat stat_buf;
+
+          buildCmdLine2(path, sizeof path, "%s" DIR_SEPARATOR_STRING "{port}" DIR_SEPARATOR_STRING "crt0{objext}", s);
+          if (stat(path, &stat_buf) == 0)
+            break;
+        }
+
+      if (s == NULL)
+        setMainValue ("z80crt0", "\"crt0{objext}\"");
+      else
+        {
+          char *buf;
+          size_t len = strlen(path) + 3;
+
+          buf = Safe_alloc(len);
+          SNPRINTF(buf, len, "\"%s\"", path);
+          setMainValue("z80crt0", buf);
+          Safe_free(buf);
+        } 
     }
   else
     {
@@ -504,6 +542,7 @@ PORT z80_port =
     NULL,
     1
   },
+  { NULL, NULL },
   {
     -1, 0, 0, 4, 0, 2
   },
@@ -598,6 +637,7 @@ PORT gbz80_port =
     NULL,
     1
   },
+  { NULL, NULL },
   {
     -1, 0, 0, 2, 0, 4
   },