From bfa8da78a6240935b82caa8f15966f53aaf55bb0 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 02:04:45 +0200 Subject: [PATCH 1/9] 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': From 1fb9f90f0f0d1a170910116c47d9d72c2e954ff9 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 03:02:53 +0200 Subject: [PATCH 2/9] 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(); From f1f314270d814a13a56f7cf84dee68a81ac79d88 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 03:29:14 +0200 Subject: [PATCH 3/9] Add -MQ Just like GCC's -MQ, this is basically -MT but the file name is escaped. --- src/asm/main.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/asm/main.c b/src/asm/main.c index db2e7d0f..b7f79342 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "asm/symbol.h" #include "asm/fstack.h" @@ -238,6 +239,27 @@ static void opt_ParseDefines(void) sym_AddString(cldefines[i], cldefines[i + 1]); } +/* Escapes Make-special chars from a string */ +static char *make_escape(const char *str) +{ + char * const escaped_str = malloc(strlen(str) * 2 + 1); + char *dest = escaped_str; + + if (escaped_str == NULL) + errx(1, "%s: Failed to allocate memory: %s", __func__, + strerror(errno)); + + while (*str) { + /* All dollars needs to be doubled */ + if (*str == '$') + *dest++ = '$'; + *dest++ = *str++; + } + *dest = '\0'; + + return escaped_str; +} + /* Short options */ static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w"; @@ -366,7 +388,7 @@ int main(int argc, char *argv[]) newopt.optimizeloads = false; break; case 'M': - ep = strchr("PT", optarg[0]); + ep = strchr("PQT", optarg[0]); if (!ep || !*ep || optarg[1]) { dependfile = fopen(optarg, "w"); if (dependfile == NULL) @@ -377,13 +399,20 @@ int main(int argc, char *argv[]) case 'P': oGeneratePhonyDeps = true; break; - } + case 'Q': + if (optind == argc) + errx(1, "-MQ takes a target file name argument"); + tzTargetFileName = + make_escape(argv[optind]); + optind++; + break; case 'T': if (optind == argc) errx(1, "-MT takes a target file name argument"); tzTargetFileName = argv[optind]; optind++; break; + } } break; @@ -447,7 +476,7 @@ int main(int argc, char *argv[]) if (dependfile) { if (!tzTargetFileName) - errx(1, "Dependency files can only be created if a target file is specified with either -o or -MT.\n"); + errx(1, "Dependency files can only be created if a target file is specified with either -o, -MQ or -MT.\n"); fprintf(dependfile, "%s: %s\n", tzTargetFileName, tzMainfile); } From 0649b360fb4b6b195641b74031c70047d981b11e Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 03:50:54 +0200 Subject: [PATCH 4/9] Allow specifying multiple dependency targets This is done to match GCC's behavior. Also, this unifies the code of -MT and -MQ. --- src/asm/main.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/asm/main.c b/src/asm/main.c index b7f79342..41a54a28 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -246,8 +246,7 @@ static char *make_escape(const char *str) char *dest = escaped_str; if (escaped_str == NULL) - errx(1, "%s: Failed to allocate memory: %s", __func__, - strerror(errno)); + err(1, "%s: Failed to allocate memory", __func__); while (*str) { /* All dollars needs to be doubled */ @@ -295,8 +294,8 @@ static void print_usage(void) { fputs( "Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n" -" [-M depend_file] [-MP] [-MT target_file] [-o out_file]\n" -" [-p pad_value] [-r depth] [-W warning] ...\n" +" [-M depend_file] [-MP] [-MT target_file] [-MQ target_file]\n" +" [-o out_file] [-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" @@ -333,6 +332,7 @@ int main(int argc, char *argv[]) nMaxRecursionDepth = 64; oGeneratePhonyDeps = false; tzTargetFileName = NULL; + size_t nTargetFileNameLen = 0; DefaultOptions.gbgfx[0] = '0'; DefaultOptions.gbgfx[1] = '1'; @@ -400,17 +400,28 @@ int main(int argc, char *argv[]) oGeneratePhonyDeps = true; break; case 'Q': - if (optind == argc) - errx(1, "-MQ takes a target file name argument"); - tzTargetFileName = - make_escape(argv[optind]); - optind++; - break; case 'T': if (optind == argc) - errx(1, "-MT takes a target file name argument"); - tzTargetFileName = argv[optind]; + errx(1, "-M%c takes a target file name argument", + optarg[0]); + ep = argv[optind]; optind++; + if (optarg[0] == 'Q') + ep = make_escape(ep); + + nTargetFileNameLen += strlen(ep) + 1; + tzTargetFileName = + realloc(tzTargetFileName, + nTargetFileNameLen + 1); + if (tzTargetFileName == NULL) + err(1, "Cannot append new file to target file list"); + strcat(tzTargetFileName, ep); + if (optarg[0] == 'Q') + free(ep); + char *ptr = tzTargetFileName + + strlen(tzTargetFileName); + *ptr++ = ' '; + *ptr = '\0'; break; } } From 12f2f654dd9e524048b37654760b0f5d9edc3d13 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 15:09:24 +0200 Subject: [PATCH 5/9] Add -MG This option allows for automatic dependency detection and generation: as soon as a missing file is found, it is output to the dep file, and assembly immediately aborts. (No .o file is produced, even if `-o` was speicified.) This doesn't cause an error, either; the point is that once the file is added to the dep file, the Makefile is re-parsed, and this time the file will be generated, so the dep list builds up automatically. This mimicks GCC's option and behavior. --- include/asm/main.h | 3 ++- src/asm/asmy.y | 6 ++++++ src/asm/fstack.c | 33 +++++++++++++++++++-------------- src/asm/main.c | 17 ++++++++++++++--- src/asm/output.c | 14 ++++++++++++-- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/include/asm/main.h b/include/asm/main.h index 4484a819..bc057906 100644 --- a/include/asm/main.h +++ b/include/asm/main.h @@ -36,7 +36,8 @@ extern struct sOptions CurrentOptions; extern FILE *dependfile; extern char *tzTargetFileName; - +extern bool oGeneratedMissingIncludes; +extern bool oFailedOnMissingInclude; extern bool oGeneratePhonyDeps; void opt_Push(void); diff --git a/src/asm/asmy.y b/src/asm/asmy.y index fe36cdf3..ff7373ff 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -1004,16 +1004,22 @@ set : T_LABEL T_POP_SET const include : T_POP_INCLUDE string { fstk_RunInclude($2); + if (oFailedOnMissingInclude) + YYACCEPT; } ; incbin : T_POP_INCBIN string { out_BinaryFile($2); + if (oFailedOnMissingInclude) + YYACCEPT; } | T_POP_INCBIN string comma uconst comma uconst { out_BinaryFileSlice($2, $4, $6); + if (oFailedOnMissingInclude) + YYACCEPT; } ; diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 0ded999e..11675bd4 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -325,6 +325,15 @@ void fstk_AddIncludePath(char *s) fatalerror("Include path too long '%s'", s); } +static void printdep(const char *fileName) +{ + if (dependfile) { + fprintf(dependfile, "%s: %s\n", tzTargetFileName, fileName); + if (oGeneratePhonyDeps) + fprintf(dependfile, "%s:\n", fileName); + } +} + FILE *fstk_FindFile(char *fname, char **incPathUsed) { char path[_MAX_PATH]; @@ -337,13 +346,7 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) f = fopen(fname, "rb"); if (f != NULL || errno != ENOENT) { - if (dependfile) { - fprintf(dependfile, "%s: %s\n", tzTargetFileName, - fname); - if (oGeneratePhonyDeps) - fprintf(dependfile, "%s:\n", fname); - } - + printdep(fname); return f; } @@ -366,12 +369,7 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) f = fopen(path, "rb"); if (f != NULL || errno != ENOENT) { - if (dependfile) { - fprintf(dependfile, "%s: %s\n", - tzTargetFileName, fname); - if (oGeneratePhonyDeps) - fprintf(dependfile, "%s:\n", fname); - } + printdep(fname); if (incPathUsed) *incPathUsed = IncludePaths[i]; @@ -380,6 +378,8 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) } errno = ENOENT; + if (oGeneratedMissingIncludes) + printdep(fname); return NULL; } @@ -391,8 +391,13 @@ void fstk_RunInclude(char *tzFileName) char *incPathUsed = ""; FILE *f = fstk_FindFile(tzFileName, &incPathUsed); - if (f == NULL) + if (f == NULL) { + if (oGeneratedMissingIncludes) { + oFailedOnMissingInclude = true; + return; + } err(1, "Unable to open included file '%s'", tzFileName); + } pushcontext(); nLineNo = 1; diff --git a/src/asm/main.c b/src/asm/main.c index 41a54a28..35db6dd4 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -47,7 +47,8 @@ uint32_t unionStart[128], unionSize[128]; /* extern int yydebug; */ FILE *dependfile; - +bool oGeneratedMissingIncludes; +bool oFailedOnMissingInclude; bool oGeneratePhonyDeps; char *tzTargetFileName; @@ -294,7 +295,7 @@ static void print_usage(void) { fputs( "Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n" -" [-M depend_file] [-MP] [-MT target_file] [-MQ target_file]\n" +" [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n" " [-o out_file] [-p pad_value] [-r depth] [-W warning] ...\n" "Useful options:\n" " -E, --export-all export all labels\n" @@ -331,6 +332,8 @@ int main(int argc, char *argv[]) nMaxRecursionDepth = 64; oGeneratePhonyDeps = false; + oGeneratedMissingIncludes = true; + oFailedOnMissingInclude = false; tzTargetFileName = NULL; size_t nTargetFileNameLen = 0; @@ -388,7 +391,7 @@ int main(int argc, char *argv[]) newopt.optimizeloads = false; break; case 'M': - ep = strchr("PQT", optarg[0]); + ep = strchr("GPQT", optarg[0]); if (!ep || !*ep || optarg[1]) { dependfile = fopen(optarg, "w"); if (dependfile == NULL) @@ -396,6 +399,9 @@ int main(int argc, char *argv[]) optarg); } else { switch (optarg[0]) { + case 'G': + oGeneratedMissingIncludes = true; + break; case 'P': oGeneratePhonyDeps = true; break; @@ -511,6 +517,8 @@ int main(int argc, char *argv[]) if (yyparse() != 0 || nbErrors != 0) errx(1, "Assembly aborted (%ld errors)!", nbErrors); + if (dependfile) + fclose(dependfile); if (nIFDepth != 0) errx(1, "Unterminated IF construct (%ld levels)!", nIFDepth); @@ -535,6 +543,9 @@ int main(int argc, char *argv[]) (int)(60 / timespent * nTotalLines)); } + if (oFailedOnMissingInclude) + return 0; + /* If no path specified, don't write file */ if (tzObjectname != NULL) out_WriteObject(); diff --git a/src/asm/output.c b/src/asm/output.c index 1a019682..8db62bda 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -880,8 +880,13 @@ void out_BinaryFile(char *s) FILE *f; f = fstk_FindFile(s, NULL); - if (f == NULL) + if (f == NULL) { + if (oGeneratedMissingIncludes) { + oFailedOnMissingInclude = true; + return; + } err(1, "Unable to open incbin file '%s'", s); + } int32_t fsize; @@ -915,8 +920,13 @@ void out_BinaryFileSlice(char *s, int32_t start_pos, int32_t length) fatalerror("Number of bytes to read must be greater than zero"); f = fstk_FindFile(s, NULL); - if (f == NULL) + if (f == NULL) { + if (oGeneratedMissingIncludes) { + oFailedOnMissingInclude = true; + return; + } err(1, "Unable to open included file '%s'", s); + } int32_t fsize; From 6fc50972786b987d1692edc1489dc0b9cf77c1d2 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 10 Sep 2019 15:12:34 +0200 Subject: [PATCH 6/9] Allow outputting dep files to stdout using `-` --- src/asm/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/asm/main.c b/src/asm/main.c index 35db6dd4..bb19395a 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -393,7 +393,10 @@ int main(int argc, char *argv[]) case 'M': ep = strchr("GPQT", optarg[0]); if (!ep || !*ep || optarg[1]) { - dependfile = fopen(optarg, "w"); + if (!strcmp("-", optarg)) + dependfile = stdout; + else + dependfile = fopen(optarg, "w"); if (dependfile == NULL) err(1, "Could not open dependfile %s", optarg); From 4a98b41d577ae5c699dd6737b543b622681d4c98 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Wed, 6 Nov 2019 18:39:14 +0100 Subject: [PATCH 7/9] Fix `-MG` always being enabled --- src/asm/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asm/main.c b/src/asm/main.c index bb19395a..ba7a89d9 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -332,7 +332,7 @@ int main(int argc, char *argv[]) nMaxRecursionDepth = 64; oGeneratePhonyDeps = false; - oGeneratedMissingIncludes = true; + oGeneratedMissingIncludes = false; oFailedOnMissingInclude = false; tzTargetFileName = NULL; size_t nTargetFileNameLen = 0; From a29dd738f2486752dab0eac1f59204da00e0c67e Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Wed, 6 Nov 2019 18:43:05 +0100 Subject: [PATCH 8/9] Reimplement `-M` variants using long options --- src/asm/main.c | 127 ++++++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 59 deletions(-) diff --git a/src/asm/main.c b/src/asm/main.c index ba7a89d9..4cc49c8d 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -263,6 +263,9 @@ static char *make_escape(const char *str) /* Short options */ static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w"; +/* Variables for the long-only options */ +static int depType; /* Variants of `-M` */ + /* * Equivalent long options * Please keep in the same order as short opts @@ -274,21 +277,25 @@ static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w"; * over short opt matching */ static struct option const longopts[] = { - { "binary-digits", required_argument, NULL, 'b' }, - { "define", required_argument, NULL, 'D' }, - { "export-all", no_argument, NULL, 'E' }, - { "gfx-chars", required_argument, NULL, 'g' }, - { "halt-without-nop", no_argument, NULL, 'h' }, - { "include", required_argument, NULL, 'i' }, - { "preserve-ld", no_argument, NULL, 'L' }, - { "dependfile", required_argument, NULL, 'M' }, - { "output", required_argument, NULL, 'o' }, - { "pad-value", required_argument, NULL, 'p' }, - { "recursion-depth", required_argument, NULL, 'r' }, - { "version", no_argument, NULL, 'V' }, - { "verbose", no_argument, NULL, 'v' }, - { "warning", required_argument, NULL, 'W' }, - { NULL, no_argument, NULL, 0 } + { "binary-digits", required_argument, NULL, 'b' }, + { "define", required_argument, NULL, 'D' }, + { "export-all", no_argument, NULL, 'E' }, + { "gfx-chars", required_argument, NULL, 'g' }, + { "halt-without-nop", no_argument, NULL, 'h' }, + { "include", required_argument, NULL, 'i' }, + { "preserve-ld", no_argument, NULL, 'L' }, + { "dependfile", required_argument, NULL, 'M' }, + { "MG", no_argument, &depType, 'G' }, + { "MP", no_argument, &depType, 'P' }, + { "MT", required_argument, &depType, 'T' }, + { "MQ", required_argument, &depType, 'Q' }, + { "output", required_argument, NULL, 'o' }, + { "pad-value", required_argument, NULL, 'p' }, + { "recursion-depth", required_argument, NULL, 'r' }, + { "version", no_argument, NULL, 'V' }, + { "verbose", no_argument, NULL, 'v' }, + { "warning", required_argument, NULL, 'W' }, + { NULL, no_argument, NULL, 0 } }; static void print_usage(void) @@ -391,50 +398,13 @@ int main(int argc, char *argv[]) newopt.optimizeloads = false; break; case 'M': - ep = strchr("GPQT", optarg[0]); - if (!ep || !*ep || optarg[1]) { - if (!strcmp("-", optarg)) - dependfile = stdout; - else - dependfile = fopen(optarg, "w"); - if (dependfile == NULL) - err(1, "Could not open dependfile %s", - optarg); - } else { - switch (optarg[0]) { - case 'G': - oGeneratedMissingIncludes = true; - break; - case 'P': - oGeneratePhonyDeps = true; - break; - case 'Q': - case 'T': - if (optind == argc) - errx(1, "-M%c takes a target file name argument", - optarg[0]); - ep = argv[optind]; - optind++; - if (optarg[0] == 'Q') - ep = make_escape(ep); - - nTargetFileNameLen += strlen(ep) + 1; - tzTargetFileName = - realloc(tzTargetFileName, - nTargetFileNameLen + 1); - if (tzTargetFileName == NULL) - err(1, "Cannot append new file to target file list"); - strcat(tzTargetFileName, ep); - if (optarg[0] == 'Q') - free(ep); - char *ptr = tzTargetFileName + - strlen(tzTargetFileName); - *ptr++ = ' '; - *ptr = '\0'; - break; - } - } - + if (!strcmp("-", optarg)) + dependfile = stdout; + else + dependfile = fopen(optarg, "w"); + if (dependfile == NULL) + err(1, "Could not open dependfile %s", + optarg); break; case 'o': out_SetFileName(optarg); @@ -467,6 +437,45 @@ int main(int argc, char *argv[]) case 'w': newopt.warnings = false; break; + + /* Long-only options */ + case 0: + if (depType) { + switch (depType) { + case 'G': + oGeneratedMissingIncludes = true; + break; + case 'P': + oGeneratePhonyDeps = true; + break; + case 'Q': + case 'T': + if (optind == argc) + errx(1, "-M%c takes a target file name argument", + depType); + ep = optarg; + if (depType == 'Q') + ep = make_escape(ep); + + nTargetFileNameLen += strlen(ep) + 1; + tzTargetFileName = + realloc(tzTargetFileName, + nTargetFileNameLen + 1); + if (tzTargetFileName == NULL) + err(1, "Cannot append new file to target file list"); + strcat(tzTargetFileName, ep); + if (depType == 'Q') + free(ep); + char *ptr = tzTargetFileName + + strlen(tzTargetFileName); + *ptr++ = ' '; + *ptr = '\0'; + break; + } + } + break; + + /* Unrecognized options */ default: print_usage(); /* NOTREACHED */ From 7bb55469fe80dd089019b0fcb198ab8efc24eb45 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sat, 9 Nov 2019 01:33:52 +0100 Subject: [PATCH 9/9] Fix partial paths being output to dep files with `-i` --- src/asm/fstack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 11675bd4..d45dc034 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -369,7 +369,7 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed) f = fopen(path, "rb"); if (f != NULL || errno != ENOENT) { - printdep(fname); + printdep(path); if (incPathUsed) *incPathUsed = IncludePaths[i];