public string MsSlnHelper(bool isUnixMode, bool isMcsMode, bool isSln, string slnFile) { bool noCommonTargets = false; bool noProjectTargets = false; bool noFlags = false; StringBuilder MakefileBuilder = new StringBuilder(); m_bIsUnix = isUnixMode; m_bIsMcs = isMcsMode; if (m_bIsUnix == true && m_bIsMcs == true) { m_bIsUsingLib = true; } if (m_bIsUnix) { slash = "/"; } else { slash = "\\"; } try { string d = Path.GetDirectoryName(slnFile); if (d != "") { Directory.SetCurrentDirectory(d); } if (isSln == true) { // Get the sln file version m_strSlnVer = GetSlnFileVersion(slnFile); // We invoke the ParseSolution // by passing the file obtained ParseSolution(slnFile); } else { // Get the Csproj version m_strCsprojVer = GetCsprojFileVersion(slnFile); // We invoke the ParseMsCsProj // by passing the file obtained ParseMsCsProj(slnFile); } if (!noFlags) { if (m_bIsUnix) // gmake { MakefileBuilder.Append("ifndef TARGET\n"); MakefileBuilder.Append("\tTARGET=./bin/Debug\n"); MakefileBuilder.Append("else\n"); MakefileBuilder.Append("\tTARGET=./bin/$(TARGET)\n"); MakefileBuilder.Append("endif\n\n"); if (this.m_bIsMcs == false) { MakefileBuilder.Append("MCS=csc\n"); MakefileBuilder.Append("RESGEN=resgen\n"); MakefileBuilder.Append("MCSFLAGS=-nologo\n\n"); MakefileBuilder.Append("ifdef (RELEASE)\n"); MakefileBuilder.Append("\tMCSFLAGS=$(MCSFLAGS) -optimize+ -d:TRACE\n"); MakefileBuilder.Append("else\n"); MakefileBuilder.Append("\tMCSFLAGS=$(MCSFLAGS) -debug+ -d:TRACE,DEBUG\n"); MakefileBuilder.Append("endif\n"); } else { MakefileBuilder.Append("MCS=mcs\n"); MakefileBuilder.Append("RESGEN=resgen\n"); MakefileBuilder.Append("ifndef (RELEASE)\n"); MakefileBuilder.Append("\tMCSFLAGS=-debug \n"); MakefileBuilder.Append("endif\n"); // Define and add the information used in the -lib: arguments passed to the // compiler to assist in finding non-fullyqualified assembly references. if (m_bIsMcs == true) { string strlibDir = PkgConfigInvoker.GetPkgVariableValue("mono", "libdir"); if (strlibDir == null) { strlibDir = "/usr/lib"; } MakefileBuilder.AppendFormat("LIBS=-lib:{0} -lib:{1}\n\n", Utils.Escape(Path.Combine(strlibDir.TrimEnd(), "mono/1.0")), Utils.Escape(Path.Combine(strlibDir.TrimEnd(), "mono/gtk-sharp")) ); } } } else // nmake { MakefileBuilder.Append("!if !defined (TARGET)\n"); MakefileBuilder.Append("TARGET=.\\bin\\Debug\n"); MakefileBuilder.Append("!else\n"); MakefileBuilder.Append("TARGET=.\\bin\\$(TARGET)\n"); MakefileBuilder.Append("!endif\n\n"); if (m_bIsMcs == false) { MakefileBuilder.Append("MCS=csc\n"); MakefileBuilder.Append("RESGEN=resgen\n"); MakefileBuilder.Append("MCSFLAGS=-nologo\n\n"); MakefileBuilder.Append("!if !defined(RELEASE)\n"); MakefileBuilder.Append("MCSFLAGS=$(MCSFLAGS) -optimize+ -d:TRACE\n"); MakefileBuilder.Append("!else\n"); MakefileBuilder.Append("MCSFLAGS=$(MCSFLAGS) -debug+ -d:TRACE,DEBUG\n"); MakefileBuilder.Append("!endif\n"); } else { MakefileBuilder.Append("MCS=mcs\n"); MakefileBuilder.Append("RESGEN=resgen\n"); MakefileBuilder.Append("!if !defined(RELEASE)\n"); MakefileBuilder.Append("MCSFLAGS=-debug \n"); MakefileBuilder.Append("!endif\n"); } } MakefileBuilder.Append("\n"); } else { MakefileBuilder.Append("!if !defined(MCS)\n"); MakefileBuilder.Append("!error You must provide MCS when making\n"); MakefileBuilder.Append("!endif\n\n"); } foreach (CsprojInfo pi in projNameInfo.Values) { MakefileBuilder.AppendFormat("{0}=$(TARGET){1}{2}\n", pi.makename_ext, slash, pi.assembly_name); MakefileBuilder.AppendFormat("{0}_PDB=$(TARGET){1}{2}\n", pi.makename, slash, pi.assembly_name.Replace(".dll", ".pdb")); MakefileBuilder.AppendFormat("{0}_SRC={1}\n", pi.makename, pi.src); MakefileBuilder.AppendFormat("{0}_RESX={1}\n", pi.makename, pi.resgen); MakefileBuilder.AppendFormat("{0}_RES={1}\n\n", pi.makename, pi.res); } MakefileBuilder.Append("all: "); foreach (CsprojInfo pi in projNameInfo.Values) { MakefileBuilder.AppendFormat("\\\n$({0})", pi.makename_ext); } MakefileBuilder.Append("\n"); foreach (CsprojInfo pi in projNameInfo.Values) { string refs = ""; string deps = ""; Hashtable libdirs = new Hashtable(); foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.Reference rf in pi.Proyecto.CSHARP.Build.References) { if (rf.Package == null || rf.Package.CompareTo("") == 0) { // Add space in between references as // it becomes necessary if (refs != "") { refs += " "; } string assemblyName = rf.AssemblyName; if (rf.HintPath != null) { string potentialPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(pi.csprojpath), rf.HintPath)); if (isUnixMode) { potentialPath = potentialPath.Replace('\\', '/'); } if (System.IO.File.Exists(potentialPath)) { // assemblyName = potentialPath; pi.libdirs.Add(Path.GetDirectoryName(potentialPath)); } } // HACK - under Unix filenames are case sensitive // Under Windows there's no agreement on Xml vs XML ;-) if (0 == String.Compare(assemblyName, "System.Xml", true)) { assemblyName = "System.Xml"; } // Check if this assembly is actually one compiled earlier in the project. // If so we must add the TARGET path to this line. string thisref; if (CheckReference(rf.AssemblyName) == true) { thisref = "-r:$(TARGET)" + Path.DirectorySeparatorChar + assemblyName; } else { thisref = "-r:" + assemblyName; } if (!thisref.EndsWith(".dll")) { thisref += ".dll"; } refs += thisref; } else { try { CsprojInfo pi2 = (CsprojInfo)projGuidInfo[rf.Project]; if (refs != "") { refs += " "; } if (deps != "") { deps += " "; } refs += "-r:$(" + pi2.makename_ext + ")"; deps += "$(" + pi2.makename_ext + ")"; foreach (string libdir in pi2.libdirs) { if (!libdirs.ContainsKey(libdir)) { libdirs[libdir] = 1; } } } catch (System.NullReferenceException) { refs += String.Format("-r:{0}.dll", rf.Name); deps += String.Format("# Missing dependency project {1} ID:{0}?", rf.Project, rf.Name ); Console.WriteLine(String.Format( "Warning: The project {0}, ID: {1} may be required and appears missing.", rf.Name, rf.Project) ); } } } MakefileBuilder.AppendFormat("$({0}): $({1}_SRC) {2}\n", pi.makename_ext, pi.makename, deps); if (isUnixMode) { MakefileBuilder.Append("\t-mkdir -p $(TARGET)\n"); } else { MakefileBuilder.Append("\t-md $(TARGET)\n"); } if (pi.resgen != null && pi.resgen != String.Empty) { MakefileBuilder.AppendFormat("\t$(RESGEN) /compile {0}\n", pi.resgen); } MakefileBuilder.Append("\t$(MCS) $(MCSFLAGS)"); foreach (string libdir in libdirs.Keys) { MakefileBuilder.AppendFormat(" -lib:{0}", Utils.Escape(libdir)); } foreach (string libdir in pi.libdirs) { MakefileBuilder.AppendFormat(" -lib:{0}", Utils.Escape(libdir)); } // Test to see if any configuratino has the Allow unsafe blocks on if (pi.AllowUnsafeCode == true) { MakefileBuilder.Append(" -unsafe"); } // Test for LIBS usage if (m_bIsUsingLib == true) { MakefileBuilder.Append(" $(LIBS)"); } MakefileBuilder.AppendFormat(" {2}{3} -out:$({0}) $({1}_RES) $({1}_SRC)\n", pi.makename_ext, pi.makename, refs, pi.switches); MakefileBuilder.Append("\n"); } if (!noCommonTargets) { MakefileBuilder.Append("\n"); MakefileBuilder.Append("# common targets\n\n"); MakefileBuilder.Append("all:\t"); bool first = true; foreach (CsprojInfo pi in projNameInfo.Values) { if (!first) { MakefileBuilder.Append(" \\\n\t"); } MakefileBuilder.AppendFormat("$({0})", pi.makename_ext); first = false; } MakefileBuilder.Append("\n\n"); MakefileBuilder.Append("clean:\n"); foreach (CsprojInfo pi in projNameInfo.Values) { if (isUnixMode) { MakefileBuilder.AppendFormat("\t-rm -f \"$({0})\" 2> /dev/null\n", pi.makename_ext); MakefileBuilder.AppendFormat("\t-rm -f \"$({0}_PDB)\" 2> /dev/null\n", pi.makename); } else { MakefileBuilder.AppendFormat("\t-del \"$({0})\" 2> nul\n", pi.makename_ext); MakefileBuilder.AppendFormat("\t-del \"$({0}_PDB)\" 2> nul\n", pi.makename); } } MakefileBuilder.Append("\n"); } if (!noProjectTargets) { MakefileBuilder.Append("\n"); MakefileBuilder.Append("# project names as targets\n\n"); foreach (CsprojInfo pi in projNameInfo.Values) { MakefileBuilder.AppendFormat("{0}: $({1})\n", pi.name, pi.makename_ext); } } return(MakefileBuilder.ToString()); } catch (Exception e) { Console.WriteLine("EXCEPTION: {0}\n", e); return(""); } }
protected Mfconsulting.General.Prj2Make.Schema.Prjx.Reference[] GetReferences(Mfconsulting.General.Prj2Make.Schema.Csproj.Reference[] References) { Mfconsulting.General.Prj2Make.Schema.Prjx.Reference[] theReferences = null; int i = 0; // Get the GAC path string strlibDir = PkgConfigInvoker.GetPkgVariableValue("mono", "libdir"); if (strlibDir == null) { strlibDir = "/usr/lib"; } string strBasePathMono1_0 = Path.Combine( strlibDir.TrimEnd(), "mono/1.0"); string strBasePathMono2_0 = Path.Combine( strlibDir.TrimEnd(), "mono/2.0"); string strBasePathGtkSharp = Path.Combine( strlibDir.TrimEnd(), "mono/gtk-sharp"); if (References != null && References.Length > 0) { theReferences = new Mfconsulting.General.Prj2Make.Schema.Prjx.Reference[References.Length]; } else { return(null); } // Iterate through the reference collection of the csproj file foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.Reference rf in References) { Mfconsulting.General.Prj2Make.Schema.Prjx.Reference rfOut = new Mfconsulting.General.Prj2Make.Schema.Prjx.Reference(); string strRefFileName; if (rf.Package == null || rf.Package.CompareTo("") == 0) { bool bIsWhereExpected = false; // HACK - under Unix filenames are case sensitive // Under Windows there's no agreement on Xml vs XML ;-) if (Path.GetFileName(rf.HintPath).CompareTo("System.XML.dll") == 0) { strRefFileName = Path.Combine(strBasePathMono1_0, Path.GetFileName("System.Xml.dll")); // Test to see if file exist in GAC location if (System.IO.File.Exists(strRefFileName) == true) { try { rfOut.refto = System.Reflection.Assembly.LoadFrom(strRefFileName).FullName; rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Gac; rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; bIsWhereExpected = true; } catch (Exception exc) { Console.WriteLine("Error doing Assembly.LoadFrom with File: {0}\nErr Msg: {1}", strRefFileName, exc.Message); } } strRefFileName = Path.Combine(strBasePathMono2_0, Path.GetFileName("System.Xml.dll")); // Test to see if file exist in GAC location if (System.IO.File.Exists(strRefFileName) == true) { try { rfOut.refto = System.Reflection.Assembly.LoadFrom(strRefFileName).FullName; rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Gac; rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; bIsWhereExpected = true; } catch (Exception exc) { Console.WriteLine("Error doing Assembly.LoadFrom with File: {0}\nErr Msg: {1}", strRefFileName, exc.Message); } } } else { strRefFileName = Path.Combine(strBasePathMono1_0, Path.GetFileName(rf.HintPath)); // Test to see if file exist in GAC location if (System.IO.File.Exists(strRefFileName) == true) { try { rfOut.refto = System.Reflection.Assembly.LoadFrom(strRefFileName).FullName; rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Gac; rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; bIsWhereExpected = true; } catch (Exception exc) { Console.WriteLine("Error doing Assembly.LoadFrom with File: {0}\nErr Msg: {1}", strRefFileName, exc.Message); } } strRefFileName = Path.Combine(strBasePathMono2_0, Path.GetFileName(rf.HintPath)); // Test to see if file exist in GAC location if (System.IO.File.Exists(strRefFileName) == true) { try { rfOut.refto = System.Reflection.Assembly.LoadFrom(strRefFileName).FullName; rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Gac; rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; bIsWhereExpected = true; } catch (Exception exc) { Console.WriteLine("Error doing Assembly.LoadFrom with File: {0}\nErr Msg: {1}", strRefFileName, exc.Message); } } strRefFileName = Path.Combine(strBasePathGtkSharp, Path.GetFileName(rf.HintPath)); // Test to see if file exist in GAC location if (System.IO.File.Exists(strRefFileName) == true) { try { rfOut.refto = System.Reflection.Assembly.LoadFrom(strRefFileName).FullName; rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Gac; rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; bIsWhereExpected = true; } catch (Exception exc) { Console.WriteLine("Error doing Assembly.LoadFrom with File: {0}\nErr Msg: {1}", strRefFileName, exc.Message); } } if (bIsWhereExpected == false) { rfOut.refto = Path.GetFileName(rf.HintPath); rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Gac; rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; } } // increment the iterator value theReferences[i++] = rfOut; } else { rfOut.type = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceType.Project; rfOut.refto = Path.GetFileName(rf.Name); rfOut.localcopy = Mfconsulting.General.Prj2Make.Schema.Prjx.ReferenceLocalcopy.True; // increment the iterator value theReferences[i++] = rfOut; } } return(theReferences); }
public string MdCmbxHelper(bool isUnixMode, bool isMcsMode, bool isSln, string slnFile) { bool noCommonTargets = false; bool noProjectTargets = false; bool noFlags = false; int nPos = -1; StringBuilder MakefileBuilder = new StringBuilder(); m_bIsUnix = isUnixMode; m_bIsMcs = isMcsMode; if (m_bIsUnix == true && m_bIsMcs == true) { m_bIsUsingLib = true; } if (m_bIsUnix) { slash = "/"; } else { slash = "\\"; } try { string d = Path.GetDirectoryName(slnFile); if (d != "") { Directory.SetCurrentDirectory(d); } if (isSln == true) { // We invoke the ParseSolution // by passing the file obtained ParseCombine(slnFile); } else { // We invoke the ParseMsCsProj // by passing the file obtained ParseMdCsProj(slnFile); } if (!noFlags) { if (m_bIsUnix) // gmake { MakefileBuilder.Append("ifndef TARGET\n"); MakefileBuilder.Append("\tTARGET=./bin/Debug\n"); MakefileBuilder.Append("else\n"); MakefileBuilder.Append("\tTARGET=./bin/$(TARGET)\n"); MakefileBuilder.Append("endif\n\n"); if (m_bIsMcs == false) { MakefileBuilder.Append("MCS=csc\n"); MakefileBuilder.Append("MCSFLAGS=-nologo\n\n"); MakefileBuilder.Append("ifdef (RELEASE)\n"); MakefileBuilder.Append("\tMCSFLAGS=$(MCSFLAGS) -optimize+ -d:TRACE\n"); MakefileBuilder.Append("else\n"); MakefileBuilder.Append("\tMCSFLAGS=$(MCSFLAGS) -debug+ -d:TRACE,DEBUG\n"); MakefileBuilder.Append("endif\n"); } else { MakefileBuilder.Append("MCS=mcs\n"); MakefileBuilder.Append("ifndef (RELEASE)\n"); MakefileBuilder.Append("\tMCSFLAGS=-debug \n"); MakefileBuilder.Append("endif\n"); // Define and add the information used in the -lib: arguments passed to the // compiler to assist in finding non-fullyqualified assembly references. if (m_bIsUsingLib == true) { string strlibDir = PkgConfigInvoker.GetPkgVariableValue("mono", "libdir"); if (strlibDir == null) { strlibDir = "/usr/lib"; } MakefileBuilder.AppendFormat("\nLIBS=-lib:{0} -lib:{1}\n\n", Utils.Escape(Path.Combine(strlibDir.TrimEnd(), "mono/1.0")), Utils.Escape(Path.Combine(strlibDir.TrimEnd(), "mono/gtk-sharp")) ); } } } else // nmake { MakefileBuilder.Append("!if !defined (TARGET)\n"); MakefileBuilder.Append("TARGET=.\\bin\\Debug\n"); MakefileBuilder.Append("!else\n"); MakefileBuilder.Append("TARGET=.\\bin\\$(TARGET)\n"); MakefileBuilder.Append("!endif\n\n"); if (m_bIsMcs == false) { MakefileBuilder.Append("MCS=csc\n"); MakefileBuilder.Append("MCSFLAGS=-nologo\n\n"); MakefileBuilder.Append("!if !defined(RELEASE)\n"); MakefileBuilder.Append("MCSFLAGS=$(MCSFLAGS) -optimize+ -d:TRACE\n"); MakefileBuilder.Append("!else\n"); MakefileBuilder.Append("MCSFLAGS=$(MCSFLAGS) -debug+ -d:TRACE,DEBUG\n"); MakefileBuilder.Append("!endif\n"); } else { MakefileBuilder.Append("MCS=mcs\n"); MakefileBuilder.Append("!if !defined(RELEASE)\n"); MakefileBuilder.Append("MCSFLAGS=-debug \n"); MakefileBuilder.Append("!endif\n"); } } MakefileBuilder.Append("\n"); } else { MakefileBuilder.Append("!if !defined(MCS)\n"); MakefileBuilder.Append("!error You must provide MCS when making\n"); MakefileBuilder.Append("!endif\n\n"); } foreach (PrjxInfo prjI in projNameInfo.Values) { MakefileBuilder.AppendFormat("{0}=$(TARGET){1}{2}\n", prjI.makename_ext, slash, prjI.assembly_name); MakefileBuilder.AppendFormat("{0}_PDB=$(TARGET){1}{2}\n", prjI.makename, slash, prjI.assembly_name.Replace(".dll", ".pdb")); MakefileBuilder.AppendFormat("{0}_SRC={1}\n", prjI.makename, prjI.src); MakefileBuilder.AppendFormat("{0}_RES={1}\n\n", prjI.makename, prjI.res); } foreach (PrjxInfo pi in projNameInfo.Values) { string refs = ""; string deps = ""; foreach (Mfconsulting.General.Prj2Make.Schema.Prjx.Reference rf in pi.Proyecto.References) { if (refs != "") { refs += " "; } string assemblyName = rf.refto; // HACK - under Unix filenames are case sensitive // Under Windows there's no agreement on Xml vs XML ;-) if (0 == String.Compare(assemblyName, "System.Xml", true)) { assemblyName = "System.Xml"; } // Check to see if there is a coma in the // reference. This could indicate a GAC // style reference nPos = assemblyName.IndexOf(','); if (nPos == -1) { if (System.IO.Path.GetExtension(assemblyName).ToUpper().CompareTo(".DLL") == 0) { refs += "-r:" + assemblyName; } else { refs += "-r:" + assemblyName + ".dll"; } } else { refs += "-r:" + assemblyName.Substring(0, nPos) + ".dll"; } } MakefileBuilder.AppendFormat("$({0}): $({1}_SRC) {2}\n", pi.makename_ext, pi.makename, deps); if (isUnixMode) { MakefileBuilder.Append("\t-mkdir -p $(TARGET)\n"); } else { MakefileBuilder.Append("\t-md $(TARGET)\n"); } MakefileBuilder.Append("\t$(MCS) $(MCSFLAGS)"); // Test to see if any configuratino has the Allow unsafe blocks on if (pi.AllowUnsafeCode == true) { MakefileBuilder.Append(" -unsafe"); } // Test for LIBS usage if (m_bIsUsingLib == true) { MakefileBuilder.Append(" $(LIBS)"); } MakefileBuilder.AppendFormat(" {2}{3} -out:$({0}) $({1}_RES) $({1}_SRC)\n", pi.makename_ext, pi.makename, refs, pi.switches); MakefileBuilder.Append("\n"); } if (!noCommonTargets) { MakefileBuilder.Append("\n"); MakefileBuilder.Append("# common targets\n\n"); MakefileBuilder.Append("all:\t"); bool first = true; foreach (PrjxInfo pi in projNameInfo.Values) { if (!first) { MakefileBuilder.Append(" \\\n\t"); } MakefileBuilder.AppendFormat("$({0})", pi.makename_ext); first = false; } MakefileBuilder.Append("\n\n"); MakefileBuilder.Append("clean:\n"); foreach (PrjxInfo pi in projNameInfo.Values) { if (isUnixMode) { MakefileBuilder.AppendFormat("\t-rm -f \"$({0})\" 2> /dev/null\n", pi.makename_ext); MakefileBuilder.AppendFormat("\t-rm -f \"$({0}_PDB)\" 2> /dev/null\n", pi.makename); } else { MakefileBuilder.AppendFormat("\t-del \"$({0})\" 2> nul\n", pi.makename_ext); MakefileBuilder.AppendFormat("\t-del \"$({0}_PDB)\" 2> nul\n", pi.makename); } } MakefileBuilder.Append("\n"); } if (!noProjectTargets) { MakefileBuilder.Append("\n"); MakefileBuilder.Append("# project names as targets\n\n"); foreach (PrjxInfo pi in projNameInfo.Values) { MakefileBuilder.AppendFormat("{0}: $({1})\n", pi.name, pi.makename_ext); } } } catch (Exception e) { Console.WriteLine("EXCEPTION: {0}\n", e); return(""); } return(MakefileBuilder.ToString()); }