shithub: rgbds

Download patch

ref: 581133ecce7f868b9aeab5eede7da0e2a995b1d6
parent: 2ea2e47231bb98437dfa00908a65ca3052275f42
author: Anthony J. Bentley <anthony@anjbe.name>
date: Thu Dec 10 20:06:19 EST 2015

Output make-style dependencies with -M.

--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -36,6 +36,9 @@
 
 ULONG ulMacroReturnValue;
 
+extern char *tzObjectname;
+extern FILE *dependfile;
+
 /*
  * defines for nCurrentStatus
  */
@@ -190,6 +193,9 @@
 	FILE *f;
 
 	if ((f = fopen(fname, "rb")) != NULL || errno != ENOENT) {
+		if (dependfile) {
+			fprintf(dependfile, "%s: %s\n", tzObjectname, fname);
+		}
 		return f;
 	}
 
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -28,6 +28,9 @@
 
 extern int yydebug;
 
+FILE *dependfile;
+extern char *tzObjectname;
+
 /*
  * Option stack
  */
@@ -258,7 +261,7 @@
 {
 	printf(
 "Usage: rgbasm [-hv] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
-"              [-o outfile] [-p pad_value] file.asm\n");
+"              [-M dependfile] [-o outfile] [-p pad_value] file.asm\n");
 	exit(1);
 }
 
@@ -272,6 +275,8 @@
 
 	char *tzMainfile;
 
+	dependfile = NULL;
+
 	cldefines_size = 32;
 	cldefines = reallocarray(cldefines, cldefines_size,
 	                        2 * sizeof(void *));
@@ -301,7 +306,7 @@
 
 	newopt = CurrentOptions;
 
-	while ((ch = getopt(argc, argv, "b:D:g:hi:o:p:v")) != -1) {
+	while ((ch = getopt(argc, argv, "b:D:g:hi:M:o:p:v")) != -1) {
 		switch (ch) {
 		case 'b':
 			if (strlen(optarg) == 2) {
@@ -332,6 +337,11 @@
 		case 'i':
 			fstk_AddIncludePath(optarg);
 			break;
+		case 'M':
+			if ((dependfile = fopen(optarg, "w")) == NULL) {
+				err(1, "Could not open dependfile %s", optarg);
+			}
+			break;
 		case 'o':
 			out_SetFileName(optarg);
 			break;
@@ -368,6 +378,10 @@
 
 	if (CurrentOptions.verbose) {
 		printf("Assembling %s\n", tzMainfile);
+	}
+
+	if (dependfile) {
+		fprintf(dependfile, "%s: %s\n", tzObjectname, tzMainfile);
 	}
 
 	nStartClock = clock();
--- a/src/asm/rgbasm.1
+++ b/src/asm/rgbasm.1
@@ -45,6 +45,11 @@
 option disables this behavior.
 .It Fl i Ar path
 Add an include path.
+.It Fl M Ar dependfile
+Print
+.Xr make 1
+dependencies to
+.Ar dependfile .
 .It Fl o Ar outfile
 Write an object file to the given filename.
 .It Fl p Ar pad_value
--