[hackers] [scc] [driver] add s flag || Quentin Rameau

From: <git_AT_suckless.org>
Date: Wed, 15 Jun 2016 19:00:06 +0200 (CEST)

commit 0e579894080f22fccf807887b87abf536a9959f8
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Wed Jun 15 14:40:19 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Wed Jun 15 18:50:46 2016 +0200

    [driver] add s flag
    
    Introduce new strip tool. We now handle objects in two different arrays,
    one for temporary objects and another for final objects.

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index f23929b..30b1e97 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -23,6 +23,7 @@ enum {
         TEEAS,
         AS,
         LD,
+ STRIP,
         LAST_TOOL,
 };
 
_AT_@ -34,34 +35,34 @@ static struct tool {
         int nparams, nargs, in, out, init, error;
         pid_t pid;
 } tools[] = {
- [CC1] = { .bin = "cc1", .cmd = PREFIX "/libexec/scc/", },
- [TEEIR] = { .bin = "tee", .cmd = "tee", },
- [CC2] = { .bin = "cc2", .cmd = PREFIX "/libexec/scc/", },
- [TEEQBE] = { .bin = "tee", .cmd = "tee", },
- [QBE] = { .bin = "qbe", .cmd = "qbe", },
- [TEEAS] = { .bin = "tee", .cmd = "tee", },
- [AS] = { .bin = "as", .cmd = "as", },
- [LD] = { .bin = "gcc", .cmd = "gcc", }, /* TODO replace with ld */
+ [CC1] = { .bin = "cc1", .cmd = PREFIX "/libexec/scc/", },
+ [TEEIR] = { .bin = "tee", .cmd = "tee", },
+ [CC2] = { .bin = "cc2", .cmd = PREFIX "/libexec/scc/", },
+ [TEEQBE] = { .bin = "tee", .cmd = "tee", },
+ [QBE] = { .bin = "qbe", .cmd = "qbe", },
+ [TEEAS] = { .bin = "tee", .cmd = "tee", },
+ [AS] = { .bin = "as", .cmd = "as", },
+ [LD] = { .bin = "gcc", .cmd = "gcc", }, /* TODO use ld */
+ [STRIP] = { .bin = "strip", .cmd = "strip", },
+};
+
+struct objects {
+ char **f;
+ int n;
 };
 
 char *argv0;
 static char *arch;
-static char **tmpobjs;
-static int nobjs;
-static int Eflag, Sflag, cflag, kflag;
+static struct objects objtmp, objout;
+static int Eflag, Sflag, cflag, kflag, sflag;
 
 static void
-cleanfiles(int tool)
+cleanobjects(void)
 {
- struct tool *t = &tools[tool];
         int i;
 
- if (tool == LD && !kflag) {
- for (i = 0; i < nobjs; ++i)
- unlink(tmpobjs[i]);
- } else if (t->outfile) {
- unlink(t->outfile);
- }
+ for (i = 0; i < objtmp.n; ++i)
+ unlink(objtmp.f[i]);
 }
 
 static void
_AT_@ -77,7 +78,7 @@ terminate(void)
                         if (t->error)
                                 failed = tool;
                         if (tool >= failed && t->outfile)
- cleanfiles(tool);
+ unlink(t->outfile);
                 }
         }
 }
_AT_@ -215,8 +216,18 @@ settool(int tool, char *infile, int nexttool)
                 addarg(tool, t->outfile);
                 break;
         case LD:
- for (i = 0; i < nobjs; ++i)
- addarg(tool, xstrdup(tmpobjs[i]));
+ for (i = 0; i < objtmp.n; ++i)
+ addarg(tool, xstrdup(objtmp.f[i]));
+ for (i = 0; i < objout.n; ++i)
+ addarg(tool, xstrdup(objout.f[i]));
+ break;
+ case STRIP:
+ if (cflag || kflag) {
+ for (i = 0; i < objout.n; ++i)
+ addarg(tool, xstrdup(objout.f[i]));
+ }
+ if (!cflag && tools[LD].outfile)
+ addarg(tool, tools[LD].outfile);
                 break;
         default:
                 break;
_AT_@ -229,7 +240,7 @@ settool(int tool, char *infile, int nexttool)
                 addarg(tool, xstrdup(infile));
         }
 
- if (nexttool < LAST_TOOL && tool != AS) {
+ if (nexttool < LAST_TOOL) {
                 if (pipe(fds))
                         die("scc: pipe: %s", strerror(errno));
                 t->out = fds[1];
_AT_@ -303,7 +314,6 @@ validatetools(void)
                         }
                         for (i = t->nparams; i < t->nargs; ++i)
                                 free(t->args[i]);
- t->outfile = NULL;
                         t->nargs = t->nparams;
                         t->pid = 0;
                         t->error = 0;
_AT_@ -314,19 +324,11 @@ validatetools(void)
 }
 
 static void
-linkobjs(void)
-{
- spawn(settool(inittool(LD), NULL, LAST_TOOL));
- validatetools();
-
- if (!kflag)
- cleanfiles(LD);
-}
-
-static void
 build(char *file)
 {
- int tool = toolfor(file), nexttool, argfile = (tool == LD) ? 1 : 0;
+ int tool = toolfor(file), nexttool;
+ struct objects *objs = (tool == LD || cflag || kflag) ?
+ &objout : &objtmp;
 
         for (; tool < LAST_TOOL; tool = nexttool) {
                 switch (tool) {
_AT_@ -355,15 +357,8 @@ build(char *file)
                         nexttool = Sflag ? LAST_TOOL : AS;
                         break;
                 case AS:
- nexttool = cflag ? LAST_TOOL : LD;
+ nexttool = LAST_TOOL;
                         break;
- case LD: /* FALLTHROUGH */
- if (argfile) {
- addarg(tool, xstrdup(file));
- } else {
- tmpobjs = newitem(tmpobjs, nobjs++,
- xstrdup(tools[AS].outfile));
- }
                 default:
                         nexttool = LAST_TOOL;
                         continue;
_AT_@ -373,12 +368,14 @@ build(char *file)
         }
 
         validatetools();
+
+ objs->f = newitem(objs->f, objs->n++, outfilename(file, "o"));
 }
 
 static void
 usage(void)
 {
- die("usage: %s [-E|-kS] [-w] [-m arch] [-c] [-o binout]\n"
+ die("usage: %s [-E|-kS] [-w] [-m arch] [-c] [-o binout] [-s]\n"
             " [-D macro[=val]]... [-I dir]... file...", argv0);
 }
 
_AT_@ -425,6 +422,9 @@ main(int argc, char *argv[])
         case 'o':
                 tools[LD].outfile = xstrdup(EARGF(usage()));
                 break;
+ case 's':
+ sflag = 1;
+ break;
         case 'w':
                 addarg(CC1, "-w");
                 break;
_AT_@ -445,8 +445,21 @@ main(int argc, char *argv[])
         for (; *argv; ++argv)
                 build(*argv);
 
- if (!(Eflag || Sflag || cflag))
- linkobjs();
+ if (Eflag || Sflag)
+ return 0;
+
+ if (!cflag) {
+ spawn(settool(inittool(LD), NULL, LAST_TOOL));
+ validatetools();
+ }
+
+ if (sflag) {
+ spawn(settool(inittool(STRIP), NULL, LAST_TOOL));
+ validatetools();
+ }
+
+ if (!kflag)
+ cleanobjects();
 
         return 0;
 }
Received on Wed Jun 15 2016 - 19:00:06 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 15 2016 - 19:00:52 CEST