mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
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.
This commit is contained in:
@@ -36,7 +36,8 @@ extern struct sOptions CurrentOptions;
|
|||||||
|
|
||||||
extern FILE *dependfile;
|
extern FILE *dependfile;
|
||||||
extern char *tzTargetFileName;
|
extern char *tzTargetFileName;
|
||||||
|
extern bool oGeneratedMissingIncludes;
|
||||||
|
extern bool oFailedOnMissingInclude;
|
||||||
extern bool oGeneratePhonyDeps;
|
extern bool oGeneratePhonyDeps;
|
||||||
|
|
||||||
void opt_Push(void);
|
void opt_Push(void);
|
||||||
|
|||||||
@@ -1004,16 +1004,22 @@ set : T_LABEL T_POP_SET const
|
|||||||
include : T_POP_INCLUDE string
|
include : T_POP_INCLUDE string
|
||||||
{
|
{
|
||||||
fstk_RunInclude($2);
|
fstk_RunInclude($2);
|
||||||
|
if (oFailedOnMissingInclude)
|
||||||
|
YYACCEPT;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
incbin : T_POP_INCBIN string
|
incbin : T_POP_INCBIN string
|
||||||
{
|
{
|
||||||
out_BinaryFile($2);
|
out_BinaryFile($2);
|
||||||
|
if (oFailedOnMissingInclude)
|
||||||
|
YYACCEPT;
|
||||||
}
|
}
|
||||||
| T_POP_INCBIN string comma uconst comma uconst
|
| T_POP_INCBIN string comma uconst comma uconst
|
||||||
{
|
{
|
||||||
out_BinaryFileSlice($2, $4, $6);
|
out_BinaryFileSlice($2, $4, $6);
|
||||||
|
if (oFailedOnMissingInclude)
|
||||||
|
YYACCEPT;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -325,6 +325,15 @@ void fstk_AddIncludePath(char *s)
|
|||||||
fatalerror("Include path too long '%s'", 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)
|
FILE *fstk_FindFile(char *fname, char **incPathUsed)
|
||||||
{
|
{
|
||||||
char path[_MAX_PATH];
|
char path[_MAX_PATH];
|
||||||
@@ -337,13 +346,7 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed)
|
|||||||
f = fopen(fname, "rb");
|
f = fopen(fname, "rb");
|
||||||
|
|
||||||
if (f != NULL || errno != ENOENT) {
|
if (f != NULL || errno != ENOENT) {
|
||||||
if (dependfile) {
|
printdep(fname);
|
||||||
fprintf(dependfile, "%s: %s\n", tzTargetFileName,
|
|
||||||
fname);
|
|
||||||
if (oGeneratePhonyDeps)
|
|
||||||
fprintf(dependfile, "%s:\n", fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,12 +369,7 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed)
|
|||||||
f = fopen(path, "rb");
|
f = fopen(path, "rb");
|
||||||
|
|
||||||
if (f != NULL || errno != ENOENT) {
|
if (f != NULL || errno != ENOENT) {
|
||||||
if (dependfile) {
|
printdep(fname);
|
||||||
fprintf(dependfile, "%s: %s\n",
|
|
||||||
tzTargetFileName, fname);
|
|
||||||
if (oGeneratePhonyDeps)
|
|
||||||
fprintf(dependfile, "%s:\n", fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (incPathUsed)
|
if (incPathUsed)
|
||||||
*incPathUsed = IncludePaths[i];
|
*incPathUsed = IncludePaths[i];
|
||||||
@@ -380,6 +378,8 @@ FILE *fstk_FindFile(char *fname, char **incPathUsed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
|
if (oGeneratedMissingIncludes)
|
||||||
|
printdep(fname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,8 +391,13 @@ void fstk_RunInclude(char *tzFileName)
|
|||||||
char *incPathUsed = "";
|
char *incPathUsed = "";
|
||||||
FILE *f = fstk_FindFile(tzFileName, &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);
|
err(1, "Unable to open included file '%s'", tzFileName);
|
||||||
|
}
|
||||||
|
|
||||||
pushcontext();
|
pushcontext();
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ uint32_t unionStart[128], unionSize[128];
|
|||||||
/* extern int yydebug; */
|
/* extern int yydebug; */
|
||||||
|
|
||||||
FILE *dependfile;
|
FILE *dependfile;
|
||||||
|
bool oGeneratedMissingIncludes;
|
||||||
|
bool oFailedOnMissingInclude;
|
||||||
bool oGeneratePhonyDeps;
|
bool oGeneratePhonyDeps;
|
||||||
char *tzTargetFileName;
|
char *tzTargetFileName;
|
||||||
|
|
||||||
@@ -294,7 +295,7 @@ static void print_usage(void)
|
|||||||
{
|
{
|
||||||
fputs(
|
fputs(
|
||||||
"Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n"
|
"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] <file> ...\n"
|
" [-o out_file] [-p pad_value] [-r depth] [-W warning] <file> ...\n"
|
||||||
"Useful options:\n"
|
"Useful options:\n"
|
||||||
" -E, --export-all export all labels\n"
|
" -E, --export-all export all labels\n"
|
||||||
@@ -331,6 +332,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
nMaxRecursionDepth = 64;
|
nMaxRecursionDepth = 64;
|
||||||
oGeneratePhonyDeps = false;
|
oGeneratePhonyDeps = false;
|
||||||
|
oGeneratedMissingIncludes = true;
|
||||||
|
oFailedOnMissingInclude = false;
|
||||||
tzTargetFileName = NULL;
|
tzTargetFileName = NULL;
|
||||||
size_t nTargetFileNameLen = 0;
|
size_t nTargetFileNameLen = 0;
|
||||||
|
|
||||||
@@ -388,7 +391,7 @@ int main(int argc, char *argv[])
|
|||||||
newopt.optimizeloads = false;
|
newopt.optimizeloads = false;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
ep = strchr("PQT", optarg[0]);
|
ep = strchr("GPQT", 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)
|
||||||
@@ -396,6 +399,9 @@ int main(int argc, char *argv[])
|
|||||||
optarg);
|
optarg);
|
||||||
} else {
|
} else {
|
||||||
switch (optarg[0]) {
|
switch (optarg[0]) {
|
||||||
|
case 'G':
|
||||||
|
oGeneratedMissingIncludes = true;
|
||||||
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
oGeneratePhonyDeps = true;
|
oGeneratePhonyDeps = true;
|
||||||
break;
|
break;
|
||||||
@@ -511,6 +517,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (yyparse() != 0 || nbErrors != 0)
|
if (yyparse() != 0 || nbErrors != 0)
|
||||||
errx(1, "Assembly aborted (%ld errors)!", nbErrors);
|
errx(1, "Assembly aborted (%ld errors)!", nbErrors);
|
||||||
|
if (dependfile)
|
||||||
|
fclose(dependfile);
|
||||||
|
|
||||||
if (nIFDepth != 0)
|
if (nIFDepth != 0)
|
||||||
errx(1, "Unterminated IF construct (%ld levels)!", nIFDepth);
|
errx(1, "Unterminated IF construct (%ld levels)!", nIFDepth);
|
||||||
@@ -535,6 +543,9 @@ int main(int argc, char *argv[])
|
|||||||
(int)(60 / timespent * nTotalLines));
|
(int)(60 / timespent * nTotalLines));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oFailedOnMissingInclude)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* If no path specified, don't write file */
|
/* If no path specified, don't write file */
|
||||||
if (tzObjectname != NULL)
|
if (tzObjectname != NULL)
|
||||||
out_WriteObject();
|
out_WriteObject();
|
||||||
|
|||||||
@@ -880,8 +880,13 @@ void out_BinaryFile(char *s)
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
f = fstk_FindFile(s, NULL);
|
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);
|
err(1, "Unable to open incbin file '%s'", s);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t fsize;
|
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");
|
fatalerror("Number of bytes to read must be greater than zero");
|
||||||
|
|
||||||
f = fstk_FindFile(s, NULL);
|
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);
|
err(1, "Unable to open included file '%s'", s);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t fsize;
|
int32_t fsize;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user