commit 399b69db4783a278f4e69a560b5bbc1b325761ee
parent 5d1e33b49e2a382979ecfca1266052e94cdf7ef0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 25 Jan 2017 15:13:57 +0100
[cc1] Implement -M flag
This flag enables the inclusion mode where cc1 only prints
the inclusion dependencies of the input file.
Diffstat:
6 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -453,9 +453,11 @@ extern unsigned short yylen;
extern int disexpand;
extern unsigned cppctx;
extern Input *input;
-extern int lexmode, namespace, onlycpp;
+extern int lexmode, namespace;
+extern int onlycpp, onlyheader;
extern unsigned curctx;
extern Symbol *curfun, *zero, *one;
+extern char *infile, *outfile;
extern Type *voidtype, *pvoidtype, *booltype,
*uchartype, *chartype, *schartype,
diff --git a/cc1/code.c b/cc1/code.c
@@ -159,7 +159,7 @@ emit(unsigned op, void *arg)
{
extern int failure;
- if (failure || onlycpp)
+ if (failure || onlycpp || onlyheader)
return;
(*opcode[op])(op, arg);
}
diff --git a/cc1/cpp.c b/cc1/cpp.c
@@ -788,6 +788,8 @@ outcpp(void)
char c, *s, *t;
for (next(); yytoken != EOFTOK; next()) {
+ if (onlyheader)
+ continue;
if (yytoken != STRING) {
printf("%s ", yytext);
continue;
diff --git a/cc1/lex.c b/cc1/lex.c
@@ -89,6 +89,8 @@ addinput(char *fname, Symbol *hide, char *buffer)
if ((fp = fopen(fname, "r")) == NULL)
return 0;
flags = IFILE;
+ if (input && onlyheader)
+ printf("%s: %s\n", infile, fname);
} else {
/* reading from stdin */
fp = stdin;
diff --git a/cc1/main.c b/cc1/main.c
@@ -10,22 +10,22 @@ static char sccsid[] = "@(#) ./cc1/main.c";
#include "../inc/cc.h"
#include "cc1.h"
-char *argv0;
+char *argv0, *infile, *outfile;
int warnings;
jmp_buf recover;
-static char *output;
static struct items uflags;
-int onlycpp;
+int onlycpp, onlyheader;
+
extern int failure;
static void
clean(void)
{
- if (failure && output)
- remove(output);
+ if (failure && outfile)
+ remove(outfile);
}
static void
@@ -62,6 +62,9 @@ main(int argc, char *argv[])
case 'D':
defmacro(EARGF(usage()));
break;
+ case 'M':
+ onlyheader = 1;
+ break;
case 'E':
onlycpp = 1;
break;
@@ -75,7 +78,7 @@ main(int argc, char *argv[])
DBGON();
break;
case 'o':
- output = EARGF(usage());
+ outfile = EARGF(usage());
break;
case 'w':
warnings = 1;
@@ -87,17 +90,18 @@ main(int argc, char *argv[])
if (argc > 1)
usage();
- if (output && !freopen(output, "w", stdout))
+ if (outfile && !freopen(outfile, "w", stdout))
die("error opening output: %s", strerror(errno));
for (i = 0; i < uflags.n; ++i)
undefmacro(uflags.s[i]);
+ infile = (*argv) ? *argv : "<stdin>";
if (!addinput(*argv, NULL, NULL)) {
die("error: failed to open input file '%s': %s",
*argv, strerror(errno));
}
- if (onlycpp) {
+ if (onlycpp || onlyheader) {
outcpp();
} else {
for (next(); yytoken != EOFTOK; decl())
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
@@ -54,7 +54,7 @@ static char *arch, *execpath, *objfile, *outfile;
static char *tmpdir;
static size_t tmpdirln;
static struct items objtmp, objout;
-static int Eflag, Sflag, cflag, kflag, sflag;
+static int Mflag, Eflag, Sflag, cflag, kflag, sflag;
extern int failure;
@@ -326,7 +326,7 @@ buildfile(char *file, int tool)
for (; tool < LAST_TOOL; tool = nexttool) {
switch (tool) {
case CC1:
- if (Eflag)
+ if (Eflag || Mflag)
nexttool = LAST_TOOL;
else
nexttool = kflag ? TEEIR : CC2;
@@ -400,10 +400,10 @@ usage(void)
{
die("usage: scc [-D def[=val]]... [-U def]... [-I dir]... "
"[-L dir]... [-l dir]...\n"
- " [-gksw] [-m arch] [-E|-S] [-o outfile] file...\n"
+ " [-gksw] [-m arch] [-M|-E|-S] [-o outfile] file...\n"
" scc [-D def[=val]]... [-U def]... [-I dir]... "
"[-L dir]... [-l dir]...\n"
- " [-gksw] [-m arch] [-E|-S] -c file...\n"
+ " [-gksw] [-m arch] [-M|-E|-S] -c file...\n"
" scc [-D def[=val]]... [-U def]... [-I dir]... "
"[-L dir]... [-l dir]...\n"
" [-gksw] [-m arch] -c -o outfile file");
@@ -427,6 +427,10 @@ main(int argc, char *argv[])
addarg(CC1, "-D");
addarg(CC1, EARGF(usage()));
break;
+ case 'M':
+ Mflag = 1;
+ addarg(CC1, "-M");
+ break;
case 'E':
Eflag = 1;
addarg(CC1, "-E");
@@ -486,7 +490,9 @@ operand:
for (; *argv; --argc, ++argv)
goto operand;
- if (Eflag && (Sflag || kflag) || linkchain.n == 0 ||
+ if (Eflag && Mflag ||
+ (Eflag || Mflag) && (Sflag || kflag) ||
+ linkchain.n == 0 ||
linkchain.n > 1 && cflag && outfile)
usage();
@@ -494,7 +500,7 @@ operand:
tmpdir = ".";
tmpdirln = strlen(tmpdir);
- build(&linkchain, (link = !(Eflag || Sflag || cflag)));
+ build(&linkchain, (link = !(Mflag || Eflag || Sflag || cflag)));
if (!(link || cflag))
return failure;