summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6/main.c26
-rw-r--r--muse/muse.c1
-rw-r--r--parse/parse.h1
-rw-r--r--parse/use.c14
4 files changed, 32 insertions, 10 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;
diff --git a/muse/muse.c b/muse/muse.c
index b7809a1..82debfe 100644
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -18,6 +18,7 @@
/* FIXME: move into one place...? */
Node *file;
char *outfile;
+char *objdir;
char *pkgname;
int show;
char debugopt[128];
diff --git a/parse/parse.h b/parse/parse.h
index a554982..1b70c18 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -538,6 +538,7 @@ int optdone(Optctx *c);
extern char debugopt[128];
extern int asmonly;
extern char *outfile;
+extern char *objdir;
extern char **incpaths;
extern size_t nincpaths;
extern char *localincpath;
diff --git a/parse/use.c b/parse/use.c
index e9a169c..d194576 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -1078,9 +1078,17 @@ readuse(Node *use, Stab *st, Vis vis)
fd = NULL;
p = NULL;
if (use->use.islocal) {
- snprintf(buf,sizeof buf, "%s/%s.use", localincpath, use->use.name);
- p = strdup(buf);
- fd = fopen(p, "r");
+ fd = NULL;
+ if (objdir) {
+ snprintf(buf,sizeof buf, "%s/%s/%s.use", objdir, localincpath, use->use.name);
+ p = strdup(buf);
+ fd = fopen(p, "r");
+ }
+ if (!fd) {
+ snprintf(buf,sizeof buf, "%s/%s.use", localincpath, use->use.name);
+ p = strdup(buf);
+ fd = fopen(p, "r");
+ }
if (!fd) {
fprintf(stderr, "could not open usefile %s\n", buf);
exit(1);