From 1fb9f90f0f0d1a170910116c47d9d72c2e954ff9 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 03:02:53 +0200 Subject: [PATCH] Add -MT option Allows overriding the output file in dependencies, which also allows outputting those without also outputting the object file. This, again, mimicks GCC's option. --- include/asm/main.h | 1 + src/asm/fstack.c | 7 ++++--- src/asm/main.c | 23 +++++++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/asm/main.h b/include/asm/main.h index 341b58be..4484a819 100644 --- a/include/asm/main.h +++ b/include/asm/main.h @@ -35,6 +35,7 @@ extern struct sOptions DefaultOptions; extern struct sOptions CurrentOptions; extern FILE *dependfile; +extern char *tzTargetFileName; extern bool oGeneratePhonyDeps; diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 621442f9..0ded999e 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -338,7 +338,8 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) if (f != NULL || errno != ENOENT) { if (dependfile) { - fprintf(dependfile, "%s: %s\n", tzObjectname, fname); + fprintf(dependfile, "%s: %s\n", tzTargetFileName, + fname); if (oGeneratePhonyDeps) fprintf(dependfile, "%s:\n", fname); } @@ -366,8 +367,8 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) if (f != NULL || errno != ENOENT) { if (dependfile) { - fprintf(dependfile, "%s: %s\n", tzObjectname, - fname); + fprintf(dependfile, "%s: %s\n", + tzTargetFileName, fname); if (oGeneratePhonyDeps) fprintf(dependfile, "%s:\n", fname); } diff --git a/src/asm/main.c b/src/asm/main.c index 6ae6e550..db2e7d0f 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -48,6 +48,7 @@ uint32_t unionStart[128], unionSize[128]; FILE *dependfile; bool oGeneratePhonyDeps; +char *tzTargetFileName; /* * Option stack @@ -272,8 +273,8 @@ static void print_usage(void) { fputs( "Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n" -" [-M depend_file] [-MP] [-o out_file] [-p pad_value] [-r depth]\n" -" [-W warning] ...\n" +" [-M depend_file] [-MP] [-MT target_file] [-o out_file]\n" +" [-p pad_value] [-r depth] [-W warning] ...\n" "Useful options:\n" " -E, --export-all export all labels\n" " -M, --dependfile set the output dependency file\n" @@ -309,6 +310,7 @@ int main(int argc, char *argv[]) nMaxRecursionDepth = 64; oGeneratePhonyDeps = false; + tzTargetFileName = NULL; DefaultOptions.gbgfx[0] = '0'; DefaultOptions.gbgfx[1] = '1'; @@ -364,7 +366,7 @@ int main(int argc, char *argv[]) newopt.optimizeloads = false; break; case 'M': - ep = strchr("P", optarg[0]); + ep = strchr("PT", optarg[0]); if (!ep || !*ep || optarg[1]) { dependfile = fopen(optarg, "w"); if (dependfile == NULL) @@ -376,6 +378,12 @@ int main(int argc, char *argv[]) oGeneratePhonyDeps = true; break; } + case 'T': + if (optind == argc) + errx(1, "-MT takes a target file name argument"); + tzTargetFileName = argv[optind]; + optind++; + break; } break; @@ -418,6 +426,9 @@ int main(int argc, char *argv[]) argc -= optind; argv += optind; + if (tzTargetFileName == NULL) + tzTargetFileName = tzObjectname; + opt_SetCurrentOptions(&newopt); DefaultOptions = CurrentOptions; @@ -435,10 +446,10 @@ int main(int argc, char *argv[]) printf("Assembling %s\n", tzMainfile); if (dependfile) { - if (!tzObjectname) - errx(1, "Dependency files can only be created if an output object file is specified.\n"); + if (!tzTargetFileName) + errx(1, "Dependency files can only be created if a target file is specified with either -o or -MT.\n"); - fprintf(dependfile, "%s: %s\n", tzObjectname, tzMainfile); + fprintf(dependfile, "%s: %s\n", tzTargetFileName, tzMainfile); } nStartClock = clock();