From a10bd139ab3a00baea7cd3148b08b9880c19fa9d Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 25 Feb 2009 13:59:28 -0800 Subject: [PATCH] Fix dependency file (-M) generation. The dependency file may be written by ivlpp as it loads its own dependencies. Make sure this doesn't mess up the dependencies that are already written by the main program. This requires that ivl, ivlpp and iverilog (driver) cooperate on the opening of the dependency file. --- driver/main.c | 9 +++++++++ ivlpp/main.c | 2 +- load_module.cc | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/driver/main.c b/driver/main.c index 96997d437..d53e3ab4c 100644 --- a/driver/main.c +++ b/driver/main.c @@ -967,6 +967,15 @@ int main(int argc, char **argv) fclose(defines_file); defines_file = 0; + /* If we are planning on opening a dependencies file, then + open and truncate it here. The other phases of compilation + will append to the file, so this is necessray to make sure + it starts out empty. */ + if (depfile) { + FILE*fd = fopen(depfile, "w"); + fclose(fd); + } + if (source_count == 0 && !version_flag) { fprintf(stderr, "%s: no source files.\n\n%s\n", argv[0], HELP); return 1; diff --git a/ivlpp/main.c b/ivlpp/main.c index 5a3e3ee84..df9d1b811 100644 --- a/ivlpp/main.c +++ b/ivlpp/main.c @@ -363,7 +363,7 @@ int main(int argc, char*argv[]) } if(dep_path) { - depend_file = fopen(dep_path, "w"); + depend_file = fopen(dep_path, "a"); if (depend_file == 0) { perror(dep_path); exit(1); diff --git a/load_module.cc b/load_module.cc index 862d205be..e8606e628 100644 --- a/load_module.cc +++ b/load_module.cc @@ -73,6 +73,7 @@ bool load_module(const char*type) if(depend_file) { fprintf(depend_file, "%s\n", path); + fflush(depend_file); } if (ivlpp_string) {