shithub: rgbds

Download patch

ref: 0649b360fb4b6b195641b74031c70047d981b11e
parent: f1f314270d814a13a56f7cf84dee68a81ac79d88
author: ISSOtm <[email protected]>
date: Mon Sep 9 23:50:54 EDT 2019

Allow specifying multiple dependency targets
This is done to match GCC's behavior.
Also, this unifies the code of -MT and -MQ.

--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -246,8 +246,7 @@
 	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 @@
 {
 	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] <file> ...\n"
+"              [-M depend_file] [-MP] [-MT target_file] [-MQ target_file]\n"
+"              [-o out_file] [-p pad_value] [-r depth] [-W warning] <file> ...\n"
 "Useful options:\n"
 "    -E, --export-all         export all labels\n"
 "    -M, --dependfile <path>  set the output dependency file\n"
@@ -333,6 +332,7 @@
 	nMaxRecursionDepth = 64;
 	oGeneratePhonyDeps = false;
 	tzTargetFileName = NULL;
+	size_t nTargetFileNameLen = 0;
 
 	DefaultOptions.gbgfx[0] = '0';
 	DefaultOptions.gbgfx[1] = '1';
@@ -400,17 +400,28 @@
 					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;
 				}
 			}