ref: f1f314270d814a13a56f7cf84dee68a81ac79d88
parent: 1fb9f90f0f0d1a170910116c47d9d72c2e954ff9
author: ISSOtm <[email protected]>
date: Mon Sep 9 23:29:14 EDT 2019
Add -MQ Just like GCC's -MQ, this is basically -MT but the file name is escaped.
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <errno.h>
#include "asm/symbol.h"
#include "asm/fstack.h"
@@ -238,6 +239,27 @@
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 @@
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,7 +399,13 @@
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");
@@ -384,6 +412,7 @@
tzTargetFileName = argv[optind];
optind++;
break;
+ }
}
break;
@@ -447,7 +476,7 @@
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);
}