diff --git a/main.c b/main.c index cdb99cf..00eee92 100644 --- a/main.c +++ b/main.c @@ -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; @@ -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; @@ -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) { diff --git a/test/driver.sh b/test/driver.sh index 187cc5b..b870846 100755 --- a/test/driver.sh +++ b/test/driver.sh @@ -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