mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add -MQ
Just like GCC's -MQ, this is basically -MT but the file name is escaped.
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
@@ -238,6 +239,27 @@ static void opt_ParseDefines(void)
|
|||||||
sym_AddString(cldefines[i], cldefines[i + 1]);
|
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 */
|
/* Short options */
|
||||||
static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
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;
|
newopt.optimizeloads = false;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
ep = strchr("PT", optarg[0]);
|
ep = strchr("PQT", optarg[0]);
|
||||||
if (!ep || !*ep || optarg[1]) {
|
if (!ep || !*ep || optarg[1]) {
|
||||||
dependfile = fopen(optarg, "w");
|
dependfile = fopen(optarg, "w");
|
||||||
if (dependfile == NULL)
|
if (dependfile == NULL)
|
||||||
@@ -377,13 +399,20 @@ int main(int argc, char *argv[])
|
|||||||
case 'P':
|
case 'P':
|
||||||
oGeneratePhonyDeps = true;
|
oGeneratePhonyDeps = true;
|
||||||
break;
|
break;
|
||||||
}
|
case 'Q':
|
||||||
|
if (optind == argc)
|
||||||
|
errx(1, "-MQ takes a target file name argument");
|
||||||
|
tzTargetFileName =
|
||||||
|
make_escape(argv[optind]);
|
||||||
|
optind++;
|
||||||
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
if (optind == argc)
|
if (optind == argc)
|
||||||
errx(1, "-MT takes a target file name argument");
|
errx(1, "-MT takes a target file name argument");
|
||||||
tzTargetFileName = argv[optind];
|
tzTargetFileName = argv[optind];
|
||||||
optind++;
|
optind++;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -447,7 +476,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (dependfile) {
|
if (dependfile) {
|
||||||
if (!tzTargetFileName)
|
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);
|
fprintf(dependfile, "%s: %s\n", tzTargetFileName, tzMainfile);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user