shithub: rgbds

Download patch

ref: 323922d85436f26cd3e52b25c13cdbdb60e39e15
parent: f97e3bad33e654cc0d7fa4f301e6fc22f02d68b6
parent: cde607c09cc5964b4e7836da08adb7b558a3a275
author: Antonio Niño Díaz <[email protected]>
date: Sat Apr 22 07:40:16 EDT 2017

Merge pull request #174 from makedepend

Generate make-style dependency files

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- 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
  */
@@ -198,6 +201,9 @@
 	FILE *f;
 
 	if ((f = fopen(fname, "rb")) != NULL || errno != ENOENT) {
+		if (dependfile) {
+			fprintf(dependfile, "%s: %s\n", tzObjectname, fname);
+		}
 		return f;
 	}
 
@@ -211,6 +217,9 @@
 		}
 
 		if ((f = fopen(path, "rb")) != NULL || errno != ENOENT) {
+			if (dependfile) {
+				fprintf(dependfile, "%s: %s\n", tzObjectname, path);
+			}
 			return f;
 		}
 	}
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -26,6 +26,9 @@
 
 extern int yydebug;
 
+FILE *dependfile;
+extern char *tzObjectname;
+
 /*
  * Option stack
  */
@@ -274,7 +277,7 @@
 {
 	printf(
 "Usage: rgbasm [-hvE] [-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);
 }
 
@@ -288,6 +291,8 @@
 
 	char *tzMainfile;
 
+	dependfile = NULL;
+
 	cldefines_size = 32;
 	cldefines = reallocarray(cldefines, cldefines_size,
 	                        2 * sizeof(void *));
@@ -317,7 +322,7 @@
 
 	newopt = CurrentOptions;
 
-	while ((ch = getopt(argc, argv, "b:D:g:hi:o:p:vEw")) != -1) {
+	while ((ch = getopt(argc, argv, "b:D:g:hi:M:o:p:vEw")) != -1) {
 		switch (ch) {
 		case 'b':
 			if (strlen(optarg) == 2) {
@@ -348,6 +353,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;
@@ -390,6 +400,13 @@
 
 	if (CurrentOptions.verbose) {
 		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");
+
+		fprintf(dependfile, "%s: %s\n", tzObjectname, tzMainfile);
 	}
 
 	nStartClock = clock();
--- a/src/asm/rgbasm.1
+++ b/src/asm/rgbasm.1
@@ -61,6 +61,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