summaryrefslogtreecommitdiffstats
path: root/Source/CPack/cmCPackSTGZGenerator.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2006-04-18 12:25:24 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2006-04-18 12:25:24 (GMT)
commit4709c76f0f6f1a9aba80f01b13cbabfe8b80c187 (patch)
tree4a10a57446a8c9b8c3dc686fc97ec1c07d90f50d /Source/CPack/cmCPackSTGZGenerator.cxx
parent77771481dd0fedee9bd1df420bf29d298e3c337a (diff)
downloadCMake-4709c76f0f6f1a9aba80f01b13cbabfe8b80c187.zip
CMake-4709c76f0f6f1a9aba80f01b13cbabfe8b80c187.tar.gz
CMake-4709c76f0f6f1a9aba80f01b13cbabfe8b80c187.tar.bz2
ENH: More cleanups and add stgz header script, so it does not have to be hard-coded. Also, the user can overwrite it
Diffstat (limited to 'Source/CPack/cmCPackSTGZGenerator.cxx')
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.cxx98
1 files changed, 74 insertions, 24 deletions
diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx
index 1ce9935..d31b120 100644
--- a/Source/CPack/cmCPackSTGZGenerator.cxx
+++ b/Source/CPack/cmCPackSTGZGenerator.cxx
@@ -24,6 +24,11 @@
#include "cmMakefile.h"
#include "cmCPackLog.h"
+#include "CPack/cmCPackSTGZGeneratorEncodedHeader.h"
+
+#include <cmsys/ios/sstream>
+#include <sys/types.h>
+#include <sys/stat.h>
//----------------------------------------------------------------------
cmCPackSTGZGenerator::cmCPackSTGZGenerator()
@@ -39,36 +44,81 @@ cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
int cmCPackSTGZGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
+
+ std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
+ if ( inFile.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find template file: "
+ << inFile.c_str() << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
+ this->SetOption("CPACK_AT_SIGN", "@");
+
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------
+int cmCPackSTGZGenerator::CompressFiles(const char* outFileName,
+ const char* toplevel, const std::vector<std::string>& files)
+{
+ if ( !this->Superclass::CompressFiles(outFileName, toplevel, files) )
+ {
+ return 0;
+ }
+ return cmSystemTools::SetPermissions(outFileName,
+#if defined( _MSC_VER ) || defined( __MINGW32__ )
+ S_IREAD | S_IWRITE | S_IEXEC
+#elif defined( __BORLANDC__ )
+ S_IRUSR | S_IWUSR | S_IXUSR
+#else
+ S_IRUSR | S_IWUSR | S_IXUSR |
+ S_IRGRP | S_IWGRP | S_IXGRP |
+ S_IROTH | S_IWOTH | S_IXOTH
+#endif
+ );
+}
+
+//----------------------------------------------------------------------
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
- *os
- << "#!/bin/sh" << std::endl
- << "echo \"" << this->GetOption("CPACK_PACKAGE_NAME")
- << " - self-extracting archive.\"" << std::endl
- << "echo \"If you want to stop extracting, please press <ctrl-C>.\""
- << std::endl
- << "read line" << std::endl
- << "echo \"Extracting... Please wait...\"" << std::endl
- << "echo \"\"" << std::endl
- << "" << std::endl
- << "# take the archive portion of this file and pipe it to tar"
- << std::endl
- << "# the NUMERIC parameter in this command should be one more"
- << std::endl
- << "# than the number of lines in this header file" << std::endl
- << "tail +18 \"$0\" | gunzip | tar xf -" << std::endl
- << "" << std::endl
- << "exit 0" << std::endl
- << "echo \"\"" << std::endl
- << "#-----------------------------------------------------------"
- << std::endl
- << "# Start of TAR.GZ file" << std::endl
- << "#-----------------------------------------------------------"
- << std::endl;
+ cmsys_ios::ostringstream str;
+ int counter = 0;
+
+ const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
+
+ // Create the header
+ std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
+ std::string line;
+ std::ifstream ifs(inFile.c_str());
+ std::string packageHeaderText;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ packageHeaderText += line + "\n";
+ }
+
+ // Configure in the values
+ std::string res;
+ this->ConfigureString(packageHeaderText, res);
+
+ // Count the lines
+ const char* ptr = res.c_str();
+ while ( *ptr )
+ {
+ if ( *ptr == '\n' )
+ {
+ counter ++;
+ }
+ ++ptr;
+ }
+ counter ++;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Counter: " << counter << std::endl);
+ char buffer[1024];
+ sprintf(buffer, "%d", counter);
+ cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
+
+ // Write in file
+ *os << res.c_str();
return this->Superclass::GenerateHeader(os);
}