[OpenBIOS] [PATCH] Generate Makefile dependencies also from Forth files

Blue Swirl blauwirbel at gmail.com
Thu Dec 30 18:57:33 CET 2010


Dependencies between Forth files were not detected, so
dictionaries were not regenerated automatically in some cases.

Introduce '-M' flag to forthstrap to dump dependency information
in Makefile compatible format, based on the Forth 'include'
directives.

Signed-off-by: Blue Swirl <blauwirbel at gmail.com>
---
 Makefile.target           |    2 +-
 config/xml/dictionary.xsl |    1 +
 kernel/bootstrap.c        |   30 +++++++++++++++++++++++++++---
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 9ae8120..934b95a 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -77,4 +77,4 @@ build: all
 include rules.mak

 # Include automatically generated dependency files
--include $(wildcard $(ODIR)/host/kernel/*.d $(ODIR)/target/*/*.d
$(ODIR)/target/*/*/*.d $(ODIR)/target/*/*/*/*.d)
+-include $(wildcard $(ODIR)/*.d $(ODIR)/host/kernel/*.d
$(ODIR)/target/*/*.d $(ODIR)/target/*/*/*.d $(ODIR)/target/*/*/*/*.d)
diff --git a/config/xml/dictionary.xsl b/config/xml/dictionary.xsl
index fc61359..52d836a 100644
--- a/config/xml/dictionary.xsl
+++ b/config/xml/dictionary.xsl
@@ -126,6 +126,7 @@
      <xsl:text> -I$(ODIR)/forth</xsl:text>

      <xsl:text> -D $@</xsl:text>
+     <xsl:text> -M $@.d</xsl:text>
      <xsl:if test="$init!=''">
       <xsl:text> -d $(ODIR)/</xsl:text><xsl:value-of
select="$init"/><xsl:text>.dict</xsl:text>
      </xsl:if>
diff --git a/kernel/bootstrap.c b/kernel/bootstrap.c
index 3c3356e..8a45fb7 100644
--- a/kernel/bootstrap.c
+++ b/kernel/bootstrap.c
@@ -69,6 +69,7 @@ struct include_path {
 };

 static include includes = { ".", NULL };
+static FILE *depfile;

 static ucell * relocation_address=NULL;
 static int     relocation_length=0;
@@ -465,6 +466,10 @@ static FILE *fopen_include(const char *fil)
 			srclines [ cursrc ] = 1;
 			srcfiles [ cursrc++ ] = ret;

+                        if (depfile) {
+                                fprintf(depfile, " %s", fullpath);
+                        }
+
 			return ret;
 		}

@@ -1025,7 +1030,9 @@ static void new_dictionary(const char *source)
 		"			write to output.dict\n"		\
 		"   -c|--console output.log\n"		\
 		"			write kernel console output to log file\n"	\
-		"   -s|--segfault	install segfault handler\n\n"
+		"   -s|--segfault	install segfault handler\n"     \
+                "   -M|--dependency-dump file\n"                         \
+                "                       dump dependencies in Makefile
format\n\n"
 #else
 #define USAGE   "Usage: %s [options] [dictionary file|source file]\n\n" \
 		"   -h		show this help\n"		\
@@ -1039,7 +1046,7 @@ static void new_dictionary(const char *source)
 		"   -c output.log\n"		\
 		"		write kernel console output to log file\n"	\
 		"   -s		install segfault handler\n\n"
-
+                "   -M file     dump dependencies in Makefile format\n\n"
 #endif

 int main(int argc, char *argv[])
@@ -1050,11 +1057,12 @@ int main(int argc, char *argv[])
 	char *dictname = NULL;
 	char *basedict = NULL;
 	char *consolefile = NULL;
+        char *depfilename = NULL;

 	unsigned char *bootstrapdict[2];
 	int c, cnt;

-	const char *optstring = "VvhsI:d:D:c:?";
+        const char *optstring = "VvhsI:d:D:c:M:?";

 	while (1) {
 #ifdef __GLIBC__
@@ -1068,6 +1076,7 @@ int main(int argc, char *argv[])
 			{"source-dictionary", 1, NULL, 'd'},
 			{"target-dictionary", 1, NULL, 'D'},
 			{"console", 1, NULL, 'c'},
+                        {"dependency-dump", 1, NULL, 'M'},
 		};

 		/*
@@ -1118,6 +1127,11 @@ int main(int argc, char *argv[])
 				consolefile = optarg;
 			}
 			break;
+                case 'M':
+                        if (!depfilename) {
+                                depfilename = optarg;
+                        }
+                        break;
 		default:
 			return 1;
 		}
@@ -1127,6 +1141,7 @@ int main(int argc, char *argv[])
                 printk(BANNER);
                 printk("Using source dictionary '%s'\n", basedict);
                 printk("Dumping final dictionary to '%s'\n", dictname);
+                printk("Dumping dependencies to '%s'\n", depfilename);
         }

 	if (argc < optind + 1) {
@@ -1134,6 +1149,10 @@ int main(int argc, char *argv[])
 		return 1;
 	}

+        if (depfilename) {
+            depfile = fopen(depfilename, "w");
+            fprintf(depfile, "%s: ", dictname);
+        }

 	/*
 	 * Get all required resources
@@ -1203,6 +1222,11 @@ int main(int argc, char *argv[])

 			run_dictionary(basedict, consolefile);
 		}
+                if (depfile) {
+                        fprintf(depfile, "\n");
+                        fclose(depfile);
+                        depfile = NULL;
+                }
 		if(errors)
 			break;
 	}
-- 
1.6.2.4



More information about the OpenBIOS mailing list