diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2001-06-04 15:34:22 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2001-06-04 15:34:22 (GMT) |
commit | b6d823a7c1573dd48a05269f27935646850dc485 (patch) | |
tree | decd010a31e35efb77850a4b86f25539d31e4279 /Source | |
parent | a3cfcd9894a5d626b8beba80fc8b5934ea3f46cf (diff) | |
download | CMake-b6d823a7c1573dd48a05269f27935646850dc485.zip CMake-b6d823a7c1573dd48a05269f27935646850dc485.tar.gz CMake-b6d823a7c1573dd48a05269f27935646850dc485.tar.bz2 |
ENH: try to better handle control-c during make Makefiles
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratedFileStream.h | 28 | ||||
-rw-r--r-- | Source/cmUnixMakefileGenerator.cxx | 14 |
2 files changed, 37 insertions, 5 deletions
diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index 26c48d7..8607ad3 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -63,7 +63,8 @@ public: m_Name(name), m_TempName(m_Name+".tmp"), m_Stream(m_TempName.c_str()), - m_Copied(false) + m_Copied(false), + m_AlwaysCopy(false) {} /** @@ -87,7 +88,11 @@ public: * real file name to occur. */ void close() { this->DoCopy(); } - + /** + * If always copy is true, then copy the file all the time without + * checking for differences. The default is false. + */ + bool SetAlwaysCopy(bool v) { m_AlwaysCopy = v; return v;} private: /** * The name of the real file where output will be copied if it has changed. @@ -110,14 +115,29 @@ private: bool m_Copied; /** - * Closes the temporary file and does the copy-if-different to the real file. + * If always copy is true, then copy the file all the time without + * checking for differences. The default is false. + */ + bool m_AlwaysCopy; + + /** + * Closes the temporary file and does the copy-if-different to the + * real file. */ void DoCopy() { if(!m_Copied) { m_Stream.close(); - cmSystemTools::CopyFileIfDifferent(m_TempName.c_str(), m_Name.c_str()); + if(m_AlwaysCopy) + { + cmSystemTools::cmCopyFile(m_TempName.c_str(), m_Name.c_str()); + } + else + { + cmSystemTools::CopyFileIfDifferent(m_TempName.c_str(), + m_Name.c_str()); + } cmSystemTools::RemoveFile(m_TempName.c_str()); m_Copied = true; } diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx index 73de1a4..5f8c399 100644 --- a/Source/cmUnixMakefileGenerator.cxx +++ b/Source/cmUnixMakefileGenerator.cxx @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cmSourceFile.h" #include "cmMakeDepend.h" #include "cmCacheManager.h" +#include "cmGeneratedFileStream.h" cmUnixMakefileGenerator::cmUnixMakefileGenerator() { @@ -93,7 +94,12 @@ void cmUnixMakefileGenerator::OutputMakefile(const char* file) cmSystemTools::MakeDirectory(i->c_str()); } } - std::ofstream fout(file); + // Create a stream that writes to a temporary file + // then does a copy at the end. This is to allow users + // to hit control-c during the make of the makefile + cmGeneratedFileStream tempFile(file); + tempFile.SetAlwaysCopy(true); + std::ostream& fout = tempFile.GetStream(); if(!fout) { cmSystemTools::Error("Error can not open for write: ", file); @@ -950,6 +956,12 @@ void cmUnixMakefileGenerator::OutputMakeRules(std::ostream& fout) "${CMAKE_COMMAND}", 0, "echo \"cmake might be out of date\""); + this->OutputMakeRule(fout, + "Rule to keep make from removing Makefiles " + "if control-C is hit during a run of cmake.", + ".PRECIOUS", + "Makefile cmake.depends", + 0); } |