Skip to content

Commit

Permalink
Add -MP option
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Dec 7, 2020
1 parent 95d5a46 commit 57c1d4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static FileType opt_x;
static StringArray opt_include;
static bool opt_E;
static bool opt_M;
static bool opt_MP;
static bool opt_S;
static bool opt_c;
static bool opt_cc1;
Expand Down Expand Up @@ -188,6 +189,11 @@ static void parse_args(int argc, char **argv) {
continue;
}

if (!strcmp(argv[i], "-MP")) {
opt_MP = true;
continue;
}

if (!strcmp(argv[i], "-cc1-input")) {
base_file = argv[++i];
continue;
Expand Down Expand Up @@ -358,6 +364,10 @@ static void print_dependencies(void) {
for (int i = 0; files[i]; i++)
fprintf(out, " \\\n %s", files[i]->name);
fprintf(out, "\n\n");

if (opt_MP)
for (int i = 1; files[i]; i++)
fprintf(out, "%s:\n\n", files[i]->name);
}

static Token *must_tokenize_file(char *path) {
Expand Down
7 changes: 7 additions & 0 deletions test/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,11 @@ $chibicc -MF $tmp/mf -M -I$tmp $tmp/out.c
grep -q -z '^out.o: .*/out\.c .*/out2\.h .*/out3\.h' $tmp/mf
check -MF

# -MP
$chibicc -MF $tmp/mp -MP -M -I$tmp $tmp/out.c
grep -q '^.*/out2.h:' $tmp/mp
check -MP
grep -q '^.*/out3.h:' $tmp/mp
check -MP

echo OK

0 comments on commit 57c1d4e

Please sign in to comment.