Resync.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CPack / cmCPackSTGZGenerator.cxx
blob571b20b1367ebfce19bf34fe0ab5804802d4e84c
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPackSTGZGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2006/05/12 18:44:24 $
7 Version: $Revision: 1.15 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "cmCPackSTGZGenerator.h"
20 #include "cmake.h"
21 #include "cmGlobalGenerator.h"
22 #include "cmLocalGenerator.h"
23 #include "cmSystemTools.h"
24 #include "cmMakefile.h"
25 #include "cmCPackLog.h"
27 #include <cmsys/ios/sstream>
28 #include <sys/types.h>
29 #include <sys/stat.h>
31 //----------------------------------------------------------------------
32 cmCPackSTGZGenerator::cmCPackSTGZGenerator()
36 //----------------------------------------------------------------------
37 cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
41 //----------------------------------------------------------------------
42 int cmCPackSTGZGenerator::InitializeInternal()
44 this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
46 std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
47 if ( inFile.empty() )
49 cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find template file: "
50 << inFile.c_str() << std::endl);
51 return 0;
53 this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
54 this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
56 return this->Superclass::InitializeInternal();
59 //----------------------------------------------------------------------
60 int cmCPackSTGZGenerator::CompressFiles(const char* outFileName,
61 const char* toplevel, const std::vector<std::string>& files)
63 if ( !this->Superclass::CompressFiles(outFileName, toplevel, files) )
65 return 0;
67 return cmSystemTools::SetPermissions(outFileName,
68 #if defined( _MSC_VER ) || defined( __MINGW32__ )
69 S_IREAD | S_IWRITE | S_IEXEC
70 #elif defined( __BORLANDC__ )
71 S_IRUSR | S_IWUSR | S_IXUSR
72 #else
73 S_IRUSR | S_IWUSR | S_IXUSR |
74 S_IRGRP | S_IWGRP | S_IXGRP |
75 S_IROTH | S_IWOTH | S_IXOTH
76 #endif
80 //----------------------------------------------------------------------
81 int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
83 cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
84 cmsys_ios::ostringstream str;
85 int counter = 0;
87 std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
88 std::string line;
89 std::ifstream ilfs(inLicFile.c_str());
90 std::string licenseText;
91 while ( cmSystemTools::GetLineFromStream(ilfs, line) )
93 licenseText += line + "\n";
95 this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT",
96 licenseText.c_str());
98 const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
100 // Create the header
101 std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
102 std::ifstream ifs(inFile.c_str());
103 std::string packageHeaderText;
104 while ( cmSystemTools::GetLineFromStream(ifs, line) )
106 packageHeaderText += line + "\n";
109 // Configure in the values
110 std::string res;
111 this->ConfigureString(packageHeaderText, res);
113 // Count the lines
114 const char* ptr = res.c_str();
115 while ( *ptr )
117 if ( *ptr == '\n' )
119 counter ++;
121 ++ptr;
123 counter ++;
124 cmCPackLogger(cmCPackLog::LOG_DEBUG,
125 "Number of lines: " << counter << std::endl);
126 char buffer[1024];
127 sprintf(buffer, "%d", counter);
128 cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
130 // Write in file
131 *os << res.c_str();
132 return this->Superclass::GenerateHeader(os);