summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-02-17 22:21:41 -0800
committerOri Bernstein <ori@eigenstate.org>2017-02-17 23:32:19 -0800
commit61a91a2cc9be621ee517b2cb4114922bd5da351f (patch)
tree2dbf60c0c0d4b03c65c59146f44e4f7c8f1c9cb2 /6
parent210b24e9cf07baef21fb0fd943f81f38a3196945 (diff)
downloadmc-61a91a2cc9be621ee517b2cb4114922bd5da351f.tar.gz
Search for usefiles relative to the output.
For most uses, this is equivalent to compiler cwd, but supports out of tree builds better. It also means that builds behave the same way regardless of the directory that the compiler is run from, which is convenient for testing. This also drops support for `.use` suffixes on local uses.
Diffstat (limited to '6')
-rw-r--r--6/main.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/6/main.c b/6/main.c
index b3218d8..056f27c 100644
--- a/6/main.c
+++ b/6/main.c
@@ -28,6 +28,7 @@ int extracheck = 1;
int p9asm;
char *outfile;
char **incpaths;
+char *localincpath;
size_t nincpaths;
Asmsyntax asmsyntax;
@@ -99,6 +100,17 @@ static void assemble(char *asmsrc, char *path)
}
}
+static char *dirname(char *path)
+{
+ char *p;
+
+ p = strrchr(path, '/');
+ if (p)
+ return strdupn(path, p - path);
+ else
+ return xstrdup(".");
+}
+
static char *gentempfile(char *buf, size_t bufsz, char *path, char *suffix)
{
char *tmpdir;
@@ -216,11 +228,15 @@ int main(int argc, char **argv)
if (ctx.nargs == 0) {
fprintf(stderr, "No input files given\n");
exit(1);
- }
- else if (ctx.nargs > 1)
+ } else if (ctx.nargs > 1)
outfile = NULL;
for (i = 0; i < ctx.nargs; i++) {
+ if (outfile)
+ localincpath = dirname(outfile);
+ else
+ localincpath = dirname(ctx.args[i]);
+
globls = mkstab(0);
tyinit(globls);
tokinit(ctx.args[i]);
@@ -250,6 +266,8 @@ int main(int argc, char **argv)
genuse(ctx.args[i]);
gen(file, buf);
assemble(buf, ctx.args[i]);
+
+ free(localincpath);
}
return 0;