cmCPackCygwinBinaryGenerator.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCPackCygwinBinaryGenerator.h"
  11. #include "cmake.h"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmSystemTools.h"
  15. #include "cmMakefile.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmCPackLog.h"
  18. #include <cmsys/SystemTools.hxx>
  19. //----------------------------------------------------------------------
  20. cmCPackCygwinBinaryGenerator::cmCPackCygwinBinaryGenerator()
  21. {
  22. this->Compress = false;
  23. }
  24. //----------------------------------------------------------------------
  25. cmCPackCygwinBinaryGenerator::~cmCPackCygwinBinaryGenerator()
  26. {
  27. }
  28. //----------------------------------------------------------------------
  29. int cmCPackCygwinBinaryGenerator::InitializeInternal()
  30. {
  31. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
  32. this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
  33. std::vector<std::string> path;
  34. std::string pkgPath = cmSystemTools::FindProgram("bzip2", path, false);
  35. if ( pkgPath.empty() )
  36. {
  37. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find BZip2" << std::endl);
  38. return 0;
  39. }
  40. this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  41. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Compress program: "
  42. << pkgPath.c_str()
  43. << std::endl);
  44. return this->Superclass::InitializeInternal();
  45. }
  46. //----------------------------------------------------------------------
  47. int cmCPackCygwinBinaryGenerator::CompressFiles(const char* outFileName,
  48. const char* toplevel, const std::vector<std::string>& files)
  49. {
  50. std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
  51. packageName += "-";
  52. packageName += this->GetOption("CPACK_PACKAGE_VERSION");
  53. packageName = cmsys::SystemTools::LowerCase(packageName);
  54. std::string manifest = "/usr/share/doc/";
  55. manifest += packageName;
  56. manifest += "/MANIFEST";
  57. std::string manifestFile
  58. = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  59. // Create a MANIFEST file that contains all of the files in
  60. // the tar file
  61. std::string tempdir = manifestFile;
  62. manifestFile += manifest;
  63. // create an extra scope to force the stream
  64. // to create the file before the super class is called
  65. {
  66. cmGeneratedFileStream ofs(manifestFile.c_str());
  67. for(std::vector<std::string>::const_iterator i = files.begin();
  68. i != files.end(); ++i)
  69. {
  70. // remove the temp dir and replace with /usr
  71. ofs << (*i).substr(tempdir.size()) << "\n";
  72. }
  73. ofs << manifest << "\n";
  74. }
  75. // add the manifest file to the list of all files
  76. std::vector<std::string> filesWithManifest = files;
  77. filesWithManifest.push_back(manifestFile);
  78. // create the bzip2 tar file
  79. return this->Superclass::CompressFiles(outFileName, toplevel,
  80. filesWithManifest);
  81. }
  82. const char* cmCPackCygwinBinaryGenerator::GetOutputExtension()
  83. {
  84. this->OutputExtension = "-";
  85. const char* patchNumber =this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  86. if(!patchNumber)
  87. {
  88. patchNumber = "1";
  89. cmCPackLogger(cmCPackLog::LOG_WARNING,
  90. "CPACK_CYGWIN_PATCH_NUMBER not specified using 1"
  91. << std::endl);
  92. }
  93. this->OutputExtension += patchNumber;
  94. this->OutputExtension += ".tar.bz2";
  95. return this->OutputExtension.c_str();
  96. }