Add -MP option.

This commit is contained in:
Reimar Döffinger 2023-10-29 15:20:16 +01:00
parent 1bfed06c2a
commit 7a53029e4d
3 changed files with 22 additions and 0 deletions

View file

@ -1613,6 +1613,7 @@ enum {
TCC_OPTION_MF, TCC_OPTION_MF,
TCC_OPTION_MM, TCC_OPTION_MM,
TCC_OPTION_MMD, TCC_OPTION_MMD,
TCC_OPTION_MP,
TCC_OPTION_x, TCC_OPTION_x,
TCC_OPTION_ar, TCC_OPTION_ar,
TCC_OPTION_impdef, TCC_OPTION_impdef,
@ -1693,6 +1694,7 @@ static const TCCOption tcc_options[] = {
{ "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG }, { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG },
{ "MM", TCC_OPTION_MM, 0}, { "MM", TCC_OPTION_MM, 0},
{ "MMD", TCC_OPTION_MMD, 0}, { "MMD", TCC_OPTION_MMD, 0},
{ "MP", TCC_OPTION_MP, 0},
{ "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG }, { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG },
{ "ar", TCC_OPTION_ar, 0}, { "ar", TCC_OPTION_ar, 0},
#ifdef TCC_TARGET_PE #ifdef TCC_TARGET_PE
@ -2133,6 +2135,9 @@ dorun:
case TCC_OPTION_MF: case TCC_OPTION_MF:
s->deps_outfile = tcc_strdup(optarg); s->deps_outfile = tcc_strdup(optarg);
break; break;
case TCC_OPTION_MP:
s->gen_phony_deps = 1;
break;
case TCC_OPTION_dumpversion: case TCC_OPTION_dumpversion:
printf ("%s\n", TCC_VERSION); printf ("%s\n", TCC_VERSION);
exit(0); exit(0);

1
tcc.h
View file

@ -796,6 +796,7 @@ struct TCCState {
unsigned char just_deps; /* option -M */ unsigned char just_deps; /* option -M */
unsigned char gen_deps; /* option -MD */ unsigned char gen_deps; /* option -MD */
unsigned char include_sys_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) */ /* compile with debug symbol (and use them if error during execution) */
unsigned char do_debug; unsigned char do_debug;

View file

@ -624,6 +624,22 @@ ST_FUNC int gen_makedeps(TCCState *s1, const char *target, const char *filename)
next:; next:;
} }
fprintf(depout, "\n"); 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; i<s1->nb_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); fclose(depout);
return 0; return 0;
} }