/mcs/tools/prj2make/MainMod.cs

https://github.com/gustavo-melo/mono · C# · 141 lines · 98 code · 24 blank · 19 comment · 18 complexity · a46128e9b3f04c8d21a3a7513cd70215 MD5 · raw file

  1. // created on 4/3/04 at 6:27 a
  2. // This program is free software; you can redistribute it and/or modify
  3. // it under the terms of the GNU General Public License as published by
  4. // the Free Software Foundation; either version 2 of the License, or
  5. // (at your option) any later version.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Library General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program; if not, write to the Free Software
  14. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. using System;
  16. using System.IO;
  17. using Mfconsulting.General.Prj2Make;
  18. namespace Mfconsulting.General.Prj2Make.Cui
  19. {
  20. public class MainMod
  21. {
  22. public string m_AppName = "prj2make-sharp";
  23. public string m_WorkspaceFileName;
  24. public string m_FileNamePath;
  25. public string m_OutputMakefile;
  26. private bool m_IsUnix = false;
  27. private bool m_IsMcs = true;
  28. // Determines the make file type/style
  29. public bool IsUnix
  30. {
  31. get { return m_IsUnix; }
  32. set { m_IsUnix = value; }
  33. }
  34. // Determines what compiler to use MCS or CSC
  35. public bool IsMcs
  36. {
  37. get { return m_IsMcs; }
  38. set { m_IsMcs = value; }
  39. }
  40. protected void MyInitializeComponents()
  41. {
  42. }
  43. public MainMod (string inputFileName)
  44. {
  45. Mfconsulting.General.Prj2Make.Maker mkObj = null;
  46. MyInitializeComponents();
  47. if (inputFileName == null || inputFileName.Length < 1)
  48. {
  49. Console.WriteLine ("No input file has been specified.");
  50. return;
  51. }
  52. if (Path.GetExtension(inputFileName).ToUpper().CompareTo(".SLN") == 0)
  53. {
  54. mkObj = new Mfconsulting.General.Prj2Make.Maker();
  55. mkObj.CreateCombineFromSln(inputFileName);
  56. return;
  57. }
  58. if (Path.GetExtension(inputFileName).ToUpper().CompareTo(".CSPROJ") == 0)
  59. {
  60. mkObj = new Mfconsulting.General.Prj2Make.Maker();
  61. mkObj.CreatePrjxFromCsproj(inputFileName);
  62. return;
  63. }
  64. }
  65. // For command line handling
  66. public MainMod (bool isNmake, bool isCsc, string WorkspaceFile)
  67. {
  68. MyInitializeComponents();
  69. this.IsMcs = (isCsc == true) ? false : true;
  70. this.IsUnix = (isNmake == true) ? false : true;
  71. IniFromCommandLine(WorkspaceFile);
  72. }
  73. void IniFromCommandLine(string WorkspaceFilename)
  74. {
  75. m_WorkspaceFileName = WorkspaceFilename;
  76. m_FileNamePath = System.IO.Path.GetDirectoryName(m_WorkspaceFileName);
  77. m_OutputMakefile = System.IO.Path.Combine(m_FileNamePath, "Makefile");
  78. if (this.IsUnix)
  79. m_OutputMakefile = System.IO.Path.Combine(m_FileNamePath, "Makefile");
  80. else
  81. m_OutputMakefile = System.IO.Path.Combine(m_FileNamePath, "Makefile.Win32");
  82. // Actually follow through and genrate the contents of the Makefile
  83. // to be placed on the textview
  84. CreateMakefile();
  85. }
  86. protected void CreateMakefile()
  87. {
  88. Mfconsulting.General.Prj2Make.Maker mkObj = null;
  89. string slnFile = null;
  90. if (this.m_WorkspaceFileName.Length < 1) {
  91. Console.WriteLine ("No input file has been specified.");
  92. return;
  93. }
  94. else
  95. slnFile = m_WorkspaceFileName;
  96. mkObj = new Mfconsulting.General.Prj2Make.Maker();
  97. SaveMakefileToDisk(mkObj.MakerMain(IsUnix, IsMcs, slnFile));
  98. }
  99. protected void SaveMakefileToDisk (string MakeFileContents)
  100. {
  101. FileStream fs = null;
  102. StreamWriter w = null;
  103. if (MakeFileContents.StartsWith ("Error") || MakeFileContents.StartsWith ("Notice")) {
  104. Console.WriteLine(MakeFileContents);
  105. return;
  106. }
  107. if (m_OutputMakefile != null && m_OutputMakefile.Length > 1) {
  108. fs = new FileStream(m_OutputMakefile, FileMode.Create, FileAccess.Write);
  109. w = new StreamWriter(fs);
  110. }
  111. if (w != null) {
  112. w.WriteLine (MakeFileContents);
  113. w.Close();
  114. }
  115. }
  116. }
  117. }