summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2017-07-12 10:43:32 -0700
committerOri Bernstein <ori@markovcorp.com>2017-07-12 10:43:32 -0700
commit40f9a316cfacf07650558b3fa516a3c0c42e1210 (patch)
tree35bdbd5d48a061f6398ce7a259832db23d892289 /6
parent0b1ae8fb344e5e5a26f50fa5c2f0dbb5c1318b87 (diff)
downloadmc-40f9a316cfacf07650558b3fa516a3c0c42e1210.tar.gz
Add support for -O in 6m.
First step to not polluting source dirs.
Diffstat (limited to '6')
-rw-r--r--6/main.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/6/main.c b/6/main.c
index fb3ba9f..d705de1 100644
--- a/6/main.c
+++ b/6/main.c
@@ -27,6 +27,7 @@ int writeasm;
int extracheck = 1;
int p9asm;
char *outfile;
+char *objdir;
char **incpaths;
char *localincpath;
size_t nincpaths;
@@ -35,9 +36,10 @@ Asmsyntax asmsyntax;
static void
usage(char *prog)
{
- printf("%s [-?|-h] [-o outfile] [-d[dbgopts]] inputs\n", prog);
+ printf("%s [-?|-h] [-o outfile] [-O dir] [-d[dbgopts]] inputs\n", prog);
printf("\t-?|-h\tPrint this help\n");
printf("\t-o\tOutput to outfile\n");
+ printf("\t-O dir\tOutput to dir\n");
printf("\t-S\tGenerate assembly source alongside object code\n");
printf("\t-c\tEnable additional (possibly flaky) checking\n");
printf("\t-I path\tAdd 'path' to use search path\n");
@@ -70,17 +72,20 @@ assemble(char *asmsrc, char *path)
char objfile[1024];
char *psuffix;
char **p, **cmd;
- size_t ncmd;
+ size_t ncmd, i;
int pid, status;
if (outfile != NULL)
strncpy(objfile, outfile, 1024);
else {
psuffix = strrchr(path, '+');
+ i = 0;
+ if (objdir)
+ i = bprintf(objfile, sizeof objfile, "%s/", objdir);
if (psuffix != NULL)
- swapsuffix(objfile, 1024, path, psuffix, Objsuffix);
+ swapsuffix(objfile + i, sizeof objfile - i, path, psuffix, Objsuffix);
else
- swapsuffix(objfile, 1024, path, ".myr", Objsuffix);
+ swapsuffix(objfile + i, sizeof objfile - i, path, ".myr", Objsuffix);
}
cmd = NULL;
ncmd = 0;
@@ -162,15 +167,19 @@ genuse(char *path)
FILE *f;
char buf[1024];
char *psuffix;
+ size_t i;
if (outfile != NULL)
swapout(buf, 1024, ".use");
else {
psuffix = strrchr(path, '+');
+ i = 0;
+ if (objdir)
+ i = bprintf(buf, sizeof buf, "%s/", objdir);
if (psuffix != NULL)
- swapsuffix(buf, 1024, path, psuffix, ".use");
+ swapsuffix(buf + i, sizeof buf - i, path, psuffix, ".use");
else
- swapsuffix(buf, 1024, path, ".myr", ".use");
+ swapsuffix(buf + i, sizeof buf - i, path, ".myr", ".use");
}
f = fopen(buf, "w");
if (!f) {
@@ -191,10 +200,13 @@ main(int argc, char **argv)
outfile = NULL;
- optinit(&ctx, "cd:?hSo:I:9G:", argv, argc);
+ optinit(&ctx, "cd:?hSo:I:9G:O:", argv, argc);
asmsyntax = Defaultasm;
while (!optdone(&ctx)) {
switch (optnext(&ctx)) {
+ case 'D':
+ objdir = ctx.optarg;
+ break;
case 'o':
outfile = ctx.optarg;
break;