shithub: scc

Download patch

ref: 3e5a6b61eba8e57abba4e74540672e521f6a0c21
parent: cfe807ad6019b35141c53981f42e2289c66e9bb1
author: Quentin Rameau <quinq@fifth.space>
date: Thu Jun 16 06:47:41 EDT 2016

[driver] add support for the combination of -c and -o

This is unspecified behaviour[1], but it seems that almost everybody out
there relies on that, so.

[1] “-o outfile: Use the pathname outfile, instead of the default a.out,
for the executable file produced. If the -o option is present with -c or
-E, the result is unspecified.”

--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -52,7 +52,7 @@
 };
 
 char *argv0;
-static char *arch;
+static char *arch, *outfile;
 static struct objects objtmp, objout;
 static int Eflag, Sflag, cflag, kflag, sflag;
 
@@ -144,8 +144,7 @@
 		break;
 	case LD:
 		addarg(tool, "-o");
-		if (!t->outfile)
-			t->outfile = xstrdup("a.out");
+		t->outfile = outfile ? outfile : xstrdup("a.out");
 		addarg(tool, t->outfile);
 		break;
 	case AS:
@@ -212,7 +211,7 @@
 		addarg(tool, t->outfile);
 		break;
 	case AS:
-		t->outfile = outfilename(infile, "o");
+		t->outfile = outfile ? outfile : outfilename(infile, "o");
 		addarg(tool, t->outfile);
 		break;
 	case LD:
@@ -375,8 +374,15 @@
 static void
 usage(void)
 {
-	die("usage: %s [-E|-kS] [-w] [-m arch] [-c] [-o binout] [-s]\n"
-	    "       [-D macro[=val]]... [-I dir]... file...", argv0);
+	die("usage: scc [-D def[=val]]... [-U def]... [-I dir]... "
+	    "[-L dir]... [-l dir]...\n"
+	    "           [-ksw] [-m arch] [-E|-S] [-o outfile] file...\n"
+	    "       scc [-D def[=val]]... [-U def]... [-I dir]... "
+	    "[-L dir]... [-l dir]...\n"
+	    "           [-ksw] [-m arch] [-E|-S] -c file...\n"
+	    "       scc [-D def[=val]]... [-U def]... [-I dir]... "
+	    "[-L dir]... [-l dir]...\n"
+	    "           [-ksw] [-m arch] -c -o outfile file");
 }
 
 int
@@ -424,7 +430,7 @@
 		arch = EARGF(usage());
 		break;
 	case 'o':
-		tools[LD].outfile = xstrdup(EARGF(usage()));
+		outfile = xstrdup(EARGF(usage()));
 		break;
 	case 's':
 		sflag = 1;
@@ -440,7 +446,7 @@
 		usage();
 	} ARGEND
 
-	if (Eflag && (Sflag || kflag))
+	if (Eflag && (Sflag || kflag) || argc > 1 && cflag && outfile)
 		usage();
 
 	if (!argc)