shithub: mc

Download patch

ref: 40f9a316cfacf07650558b3fa516a3c0c42e1210
parent: 0b1ae8fb344e5e5a26f50fa5c2f0dbb5c1318b87
author: Ori Bernstein <ori@markovcorp.com>
date: Wed Jul 12 06:43:32 EDT 2017

Add support for -O in 6m.

	First step to not polluting source dirs.

--- a/6/main.c
+++ b/6/main.c
@@ -27,6 +27,7 @@
 int extracheck = 1;
 int p9asm;
 char *outfile;
+char *objdir;
 char **incpaths;
 char *localincpath;
 size_t nincpaths;
@@ -35,9 +36,10 @@
 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,7 +72,7 @@
 	char objfile[1024];
 	char *psuffix;
 	char **p, **cmd;
-	size_t ncmd;
+	size_t ncmd, i;
 	int pid, status;
 
 	if (outfile != NULL)
@@ -77,10 +79,13 @@
 		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 @@
 	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 @@
 
 	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;
--- 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];
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -538,6 +538,7 @@
 extern char debugopt[128];
 extern int asmonly;
 extern char *outfile;
+extern char *objdir;
 extern char **incpaths;
 extern size_t nincpaths;
 extern char *localincpath;
--- a/parse/use.c
+++ b/parse/use.c
@@ -1078,9 +1078,17 @@
 	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);