>From 8b3c7b6039de993f9f7b2aa05b36b7403b13e839 Mon Sep 17 00:00:00 2001 From: bauen1 Date: Sat, 1 Feb 2020 11:54:50 +0100 Subject: [PATCH] Added -MP option Please note that gcc will complain about using -MP without -MD but in this patch -MD is implied by -MP --- libtcc.c | 5 +++++ tcc-doc.texi | 4 ++++ tcc.c | 1 + tcctools.c | 10 ++++++++++ 4 files changed, 20 insertions(+) diff --git a/libtcc.c b/libtcc.c index db30223..f972997 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1507,6 +1507,7 @@ enum { TCC_OPTION_pipe, TCC_OPTION_E, TCC_OPTION_MD, + TCC_OPTION_MP, TCC_OPTION_MF, TCC_OPTION_x, TCC_OPTION_ar, @@ -1571,6 +1572,7 @@ static const TCCOption tcc_options[] = { { "pipe", TCC_OPTION_pipe, 0}, { "E", TCC_OPTION_E, 0}, { "MD", TCC_OPTION_MD, 0}, + { "MP", TCC_OPTION_MP, 0}, { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG }, { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG }, { "ar", TCC_OPTION_ar, 0}, @@ -1983,6 +1985,9 @@ reparse: case TCC_OPTION_MD: s->gen_deps = 1; break; + case TCC_OPTION_MP: + s->gen_deps = 2; + break; case TCC_OPTION_MF: s->deps_outfile = tcc_strdup(optarg); break; diff --git a/tcc-doc.texi b/tcc-doc.texi index 9266cf1..4407b36 100644 --- a/tcc-doc.texi +++ b/tcc-doc.texi @@ -369,6 +369,10 @@ Misc options: @item -MD Generate makefile fragment with dependencies. +@item -MP +Generate phony targets for every dependency except the main source file. +This is typically used to work around make errors when a header file is moved without updating the dependency files. + @item -MF depfile Use @file{depfile} as output for -MD. diff --git a/tcc.c b/tcc.c index 388d353..e726f8d 100644 --- a/tcc.c +++ b/tcc.c @@ -69,6 +69,7 @@ static const char help[] = " -nostdlib do not link with standard crt and libraries\n" " -Bdir set tcc's private include/library dir\n" " -MD generate dependency file for make\n" + " -MP generate phony targets for dependencies for make\n" " -MF file specify dependency file name\n" " -m32/64 defer to i386/x86_64 cross compiler\n" "Tools:\n" diff --git a/tcctools.c b/tcctools.c index 1d4424e..1692b4d 100644 --- a/tcctools.c +++ b/tcctools.c @@ -539,6 +539,16 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename) fprintf(depout, "%s: \\\n", target); for (i=0; inb_target_deps; ++i) fprintf(depout, " %s \\\n", s->target_deps[i]); + + if (s->gen_deps == 2) { + fprintf(depout, "\n"); + + /* XXX: we need to skip the source file */ + for (i = 1; i < s->nb_target_deps; i++) { + fprintf(depout, "%s: \n\n", s->target_deps[i]); + } + } + fprintf(depout, "\n"); fclose(depout); } -- 2.25.0