char p[0];
};
+static void oom(void)
+{
+ fprintf(stderr, "Out of memory.\n");
+ exit(1);
+}
+
+static char *mstrdup(const char *p)
+{
+ char *n = strdup(p);
+ if (n == NULL)
+ oom();
+ return n;
+}
+
static void not_null(const char *p)
{
if (p == NULL) {
fprintf(stderr, "-o cannot be used twice.\n");
exit(1);
}
- target = strdup(p);
+ target = mstrdup(p);
}
static const char *opt;
fprintf(stderr, "fcc: -O cannot be used twice.\n");
exit(1);
}
- opt = strdup(p);
+ opt = mstrdup(p);
if (*opt && sscanf(opt, "%d", &optcode) != 1) {
fprintf(stderr, "fcc: -O requires a value\n");
exit(1);
fprintf(stderr, "-M cannot be used twice.\n");
exit(1);
}
- map = strdup(p);
+ map = mstrdup(p);
}
static const char *cpu;
fprintf(stderr, "-m cannot be used twice.\n");
exit(1);
}
- cpu = strdup(p);
+ cpu = mstrdup(p);
if (strcmp(cpu, "z80") && strcmp(cpu, "z180")) {
fprintf(stderr,"fcc: only z80 and z180 targets currently handled.\n");
exit(1);
}
}
+static const char *platform = "";
+
+static void set_platform(const char *p)
+{
+ char *n;
+ not_null(p);
+ if (*platform) {
+ fprintf(stderr, "-t cannot be used twice.\n");
+ exit(1);
+ }
+ n = malloc(strlen(p) + 2);
+ if (n == NULL)
+ oom();
+ sprintf(n, "-%s", p);
+ platform = n;
+}
+
static int debug;
static int pedantic;
static int werror;
static char *chopname(const char *i)
{
- char *p = strdup(i);
+ char *p = mstrdup(i);
char *t;
if (p == NULL) {
fprintf(stderr, "Out of memory.\n");
static void build_command(void)
{
+ char buf[128];
+
add_argument("sdcc");
/* Set up the basic parameters we will inflict on the user */
add_argument("--std-c99");
add_argument("--no-std-crt0");
add_argument("--nostdlib");
add_argument("--code-loc");
- add_argument("0x100");
+ /* FIXME: we need a nice way to avoid these being special cased */
+ if (strcmp(platform, "-zx128") == 0)
+ add_argument("0x8000");
+ else
+ add_argument("0x100");
add_argument("--data-loc");
add_argument("0x0");
}
exit(1);
}
add_option("-o", target);
- add_argument(FCC_DIR "/lib/crt0.rel");
+ snprintf(buf, sizeof(buf), FCC_DIR "/lib/crt0%s.rel", platform);
+ add_argument(buf);
}
if (srchead) {
if (mode == MODE_OBJ)
char *t;
int i;
int ret;
+ char buf[128];
for(i = 1; i < argc; i++) {
p = argv[i];
else
set_map(p + 2);
break;
+ case 't':
+ if (p[2] == 0)
+ set_platform(argv[++i]);
+ else
+ set_platform(p + 2);
+ break;
case 'g':
debug = 1;
break;
}
add_include_path(FCC_DIR "/include/");
add_library_path(FCC_DIR "/lib/");
- add_library("c");
+ snprintf(buf, sizeof(buf), "c%s", platform);
+ add_library(buf);
if (mode == MODE_OBJ) {
while (srchead) {