From 581133ecce7f868b9aeab5eede7da0e2a995b1d6 Mon Sep 17 00:00:00 2001 From: "Anthony J. Bentley" Date: Fri, 11 Dec 2015 01:06:19 -0700 Subject: [PATCH 1/3] Output make-style dependencies with -M. --- src/asm/fstack.c | 6 ++++++ src/asm/main.c | 18 ++++++++++++++++-- src/asm/rgbasm.1 | 5 +++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 56fc46d0..dbbf2bb3 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -36,6 +36,9 @@ ULONG nCurrentREPTBlockCount; ULONG ulMacroReturnValue; +extern char *tzObjectname; +extern FILE *dependfile; + /* * defines for nCurrentStatus */ @@ -190,6 +193,9 @@ fstk_FindFile(char *fname) FILE *f; if ((f = fopen(fname, "rb")) != NULL || errno != ENOENT) { + if (dependfile) { + fprintf(dependfile, "%s: %s\n", tzObjectname, fname); + } return f; } diff --git a/src/asm/main.c b/src/asm/main.c index 99a7cc39..cc2c1315 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -28,6 +28,9 @@ ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors; extern int yydebug; +FILE *dependfile; +extern char *tzObjectname; + /* * Option stack */ @@ -258,7 +261,7 @@ usage(void) { 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 @@ main(int argc, char *argv[]) char *tzMainfile; + dependfile = NULL; + cldefines_size = 32; cldefines = reallocarray(cldefines, cldefines_size, 2 * sizeof(void *)); @@ -301,7 +306,7 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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; @@ -370,6 +380,10 @@ main(int argc, char *argv[]) printf("Assembling %s\n", tzMainfile); } + if (dependfile) { + fprintf(dependfile, "%s: %s\n", tzObjectname, tzMainfile); + } + nStartClock = clock(); nLineNo = 1; diff --git a/src/asm/rgbasm.1 b/src/asm/rgbasm.1 index 9434729a..a8cef72e 100644 --- a/src/asm/rgbasm.1 +++ b/src/asm/rgbasm.1 @@ -45,6 +45,11 @@ The 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 From 739b113f57915fbcb6c3bb10c97cc443b7fce4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Mon, 17 Apr 2017 20:27:58 +0100 Subject: [PATCH 2/3] Print dependencies of all included files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Files that weren't found with the absolute path weren't added as dependencies even if they were found after considering the list of include directories. This patch makes rgbasm print the complete path (including the include directory path) in these cases. Signed-off-by: Antonio Niño Díaz --- src/asm/fstack.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 73391668..c15c0eb1 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -217,6 +217,9 @@ fstk_FindFile(char *fname) } if ((f = fopen(path, "rb")) != NULL || errno != ENOENT) { + if (dependfile) { + fprintf(dependfile, "%s: %s\n", tzObjectname, path); + } return f; } } From cde607c09cc5964b4e7836da08adb7b558a3a275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Mon, 17 Apr 2017 22:02:18 +0100 Subject: [PATCH 3/3] Deps file can only be created if object file specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Antonio Niño Díaz --- src/asm/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/asm/main.c b/src/asm/main.c index 19bfab71..e21c1544 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -403,6 +403,9 @@ main(int argc, char *argv[]) } 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); }