1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPackSTGZGenerator.cxx,v $
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"
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>
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");
49 cmCPackLogger(cmCPackLog::LOG_ERROR
, "Cannot find template file: "
50 << inFile
.c_str() << std::endl
);
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
) )
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
73 S_IRUSR
| S_IWUSR
| S_IXUSR
|
74 S_IRGRP
| S_IWGRP
| S_IXGRP
|
75 S_IROTH
| S_IWOTH
| S_IXOTH
80 //----------------------------------------------------------------------
81 int cmCPackSTGZGenerator::GenerateHeader(std::ostream
* os
)
83 cmCPackLogger(cmCPackLog::LOG_DEBUG
, "Writing header" << std::endl
);
84 cmsys_ios::ostringstream str
;
87 std::string inLicFile
= this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
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",
98 const char headerLengthTag
[] = "###CPACK_HEADER_LENGTH###";
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
111 this->ConfigureString(packageHeaderText
, res
);
114 const char* ptr
= res
.c_str();
124 cmCPackLogger(cmCPackLog::LOG_DEBUG
,
125 "Number of lines: " << counter
<< std::endl
);
127 sprintf(buffer
, "%d", counter
);
128 cmSystemTools::ReplaceString(res
, headerLengthTag
, buffer
);
132 return this->Superclass::GenerateHeader(os
);