diff --git a/libtcc.c b/libtcc.c index 1dba5174..1514a94a 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1613,6 +1613,7 @@ enum { TCC_OPTION_MF, TCC_OPTION_MM, TCC_OPTION_MMD, + TCC_OPTION_MP, TCC_OPTION_x, TCC_OPTION_ar, TCC_OPTION_impdef, @@ -1693,6 +1694,7 @@ static const TCCOption tcc_options[] = { { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG }, { "MM", TCC_OPTION_MM, 0}, { "MMD", TCC_OPTION_MMD, 0}, + { "MP", TCC_OPTION_MP, 0}, { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG }, { "ar", TCC_OPTION_ar, 0}, #ifdef TCC_TARGET_PE @@ -2133,6 +2135,9 @@ dorun: case TCC_OPTION_MF: s->deps_outfile = tcc_strdup(optarg); break; + case TCC_OPTION_MP: + s->gen_phony_deps = 1; + break; case TCC_OPTION_dumpversion: printf ("%s\n", TCC_VERSION); exit(0); diff --git a/tcc.h b/tcc.h index b49b7f94..e4173863 100644 --- a/tcc.h +++ b/tcc.h @@ -796,6 +796,7 @@ struct TCCState { unsigned char just_deps; /* option -M */ unsigned char gen_deps; /* option -MD */ unsigned char include_sys_deps; /* option -MD */ + unsigned char gen_phony_deps; /* option -MP */ /* compile with debug symbol (and use them if error during execution) */ unsigned char do_debug; diff --git a/tcctools.c b/tcctools.c index bef21ef6..799218f3 100644 --- a/tcctools.c +++ b/tcctools.c @@ -624,6 +624,22 @@ ST_FUNC int gen_makedeps(TCCState *s1, const char *target, const char *filename) next:; } fprintf(depout, "\n"); + if (s1->gen_phony_deps) { + /* Skip first file, which is the c file. + * This will still print any additional c files specified + * on command-line, but e.g. clang produces broken dependency + * files in this case as well, printing only dependencies for last + * file in command line. So ignore this case. */ + for (i = 1; inb_target_deps; ++i) { + for (k = 0; k < i; ++k) + if (0 == strcmp(s1->target_deps[i], s1->target_deps[k])) + goto next2; + escaped_target = escape_target_dep(s1->target_deps[i]); + fprintf(depout, "%s:\n", escaped_target); + tcc_free(escaped_target); + next2:; + } + } fclose(depout); return 0; }