shithub: rgbds

Download patch

ref: 1fb9f90f0f0d1a170910116c47d9d72c2e954ff9
parent: bfa8da78a6240935b82caa8f15966f53aaf55bb0
author: ISSOtm <[email protected]>
date: Mon Sep 9 23:02:53 EDT 2019

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.

--- a/include/asm/main.h
+++ b/include/asm/main.h
@@ -35,6 +35,7 @@
 extern struct sOptions CurrentOptions;
 
 extern FILE *dependfile;
+extern char *tzTargetFileName;
 
 extern bool oGeneratePhonyDeps;
 
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -338,7 +338,8 @@
 
 	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 @@
 
 		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);
 			}
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -48,6 +48,7 @@
 FILE *dependfile;
 
 bool oGeneratePhonyDeps;
+char *tzTargetFileName;
 
 /*
  * Option stack
@@ -272,8 +273,8 @@
 {
 	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] <file> ...\n"
+"              [-M depend_file] [-MP] [-MT target_file] [-o out_file]\n"
+"              [-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"
@@ -309,6 +310,7 @@
 
 	nMaxRecursionDepth = 64;
 	oGeneratePhonyDeps = false;
+	tzTargetFileName = NULL;
 
 	DefaultOptions.gbgfx[0] = '0';
 	DefaultOptions.gbgfx[1] = '1';
@@ -364,7 +366,7 @@
 			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 @@
 					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 @@
 	argc -= optind;
 	argv += optind;
 
+	if (tzTargetFileName == NULL)
+		tzTargetFileName = tzObjectname;
+
 	opt_SetCurrentOptions(&newopt);
 
 	DefaultOptions = CurrentOptions;
@@ -435,10 +446,10 @@
 		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();