From bfa8da78a6240935b82caa8f15966f53aaf55bb0 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 02:04:45 +0200 Subject: [PATCH] Add -MP option Adds a phony target to every included file, mimicking gcc's --- include/asm/main.h | 2 ++ src/asm/fstack.c | 10 ++++++++-- src/asm/main.c | 21 +++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/asm/main.h b/include/asm/main.h index 63812f5e..341b58be 100644 --- a/include/asm/main.h +++ b/include/asm/main.h @@ -36,6 +36,8 @@ extern struct sOptions CurrentOptions; extern FILE *dependfile; +extern bool oGeneratePhonyDeps; + void opt_Push(void); void opt_Pop(void); void opt_Parse(char *s); diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 9a19df73..621442f9 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -337,8 +337,11 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) f = fopen(fname, "rb"); if (f != NULL || errno != ENOENT) { - if (dependfile) + if (dependfile) { fprintf(dependfile, "%s: %s\n", tzObjectname, fname); + if (oGeneratePhonyDeps) + fprintf(dependfile, "%s:\n", fname); + } return f; } @@ -364,8 +367,11 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) if (f != NULL || errno != ENOENT) { if (dependfile) { fprintf(dependfile, "%s: %s\n", tzObjectname, - path); + fname); + if (oGeneratePhonyDeps) + fprintf(dependfile, "%s:\n", fname); } + if (incPathUsed) *incPathUsed = IncludePaths[i]; return f; diff --git a/src/asm/main.c b/src/asm/main.c index f74b8277..6ae6e550 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -47,6 +47,8 @@ uint32_t unionStart[128], unionSize[128]; FILE *dependfile; +bool oGeneratePhonyDeps; + /* * Option stack */ @@ -270,7 +272,7 @@ static void print_usage(void) { fputs( "Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n" -" [-M depend_file] [-o out_file] [-p pad_value] [-r depth]\n" +" [-M depend_file] [-MP] [-o out_file] [-p pad_value] [-r depth]\n" " [-W warning] ...\n" "Useful options:\n" " -E, --export-all export all labels\n" @@ -306,6 +308,7 @@ int main(int argc, char *argv[]) /* yydebug=1; */ nMaxRecursionDepth = 64; + oGeneratePhonyDeps = false; DefaultOptions.gbgfx[0] = '0'; DefaultOptions.gbgfx[1] = '1'; @@ -361,9 +364,19 @@ int main(int argc, char *argv[]) newopt.optimizeloads = false; break; case 'M': - dependfile = fopen(optarg, "w"); - if (dependfile == NULL) - err(1, "Could not open dependfile %s", optarg); + ep = strchr("P", optarg[0]); + if (!ep || !*ep || optarg[1]) { + dependfile = fopen(optarg, "w"); + if (dependfile == NULL) + err(1, "Could not open dependfile %s", + optarg); + } else { + switch (optarg[0]) { + case 'P': + oGeneratePhonyDeps = true; + break; + } + } break; case 'o':