aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Targets/AutotoolsTarget.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Targets/AutotoolsTarget.cs')
-rw-r--r--Prebuild/src/Core/Targets/AutotoolsTarget.cs1782
1 files changed, 0 insertions, 1782 deletions
diff --git a/Prebuild/src/Core/Targets/AutotoolsTarget.cs b/Prebuild/src/Core/Targets/AutotoolsTarget.cs
deleted file mode 100644
index 5dcbb38..0000000
--- a/Prebuild/src/Core/Targets/AutotoolsTarget.cs
+++ /dev/null
@@ -1,1782 +0,0 @@
1#region BSD License
2/*
3
4Copyright (c) 2004 - 2008
5Matthew Holmes (matthew@wildfiregames.com),
6Dan Moorehead (dan05a@gmail.com),
7Dave Hudson (jendave@yahoo.com),
8C.J. Adams-Collier (cjac@colliertech.org),
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are
12met:
13
14* Redistributions of source code must retain the above copyright
15notice, this list of conditions and the following disclaimer.
16
17* Redistributions in binary form must reproduce the above copyright
18notice, this list of conditions and the following disclaimer in the
19documentation and/or other materials provided with the distribution.
20
21* The name of the author may not be used to endorse or promote
22products derived from this software without specific prior written
23permission.
24
25THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
29INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36
37*/
38#endregion
39
40#region MIT X11 license
41
42/*
43 Portions of this file authored by Lluis Sanchez Gual
44
45 Copyright (C) 2006 Novell, Inc (http://www.novell.com)
46
47 Permission is hereby granted, free of charge, to any person obtaining
48 a copy of this software and associated documentation files (the
49 "Software"), to deal in the Software without restriction, including
50 without limitation the rights to use, copy, modify, merge, publish,
51 distribute, sublicense, and/or sell copies of the Software, and to
52 permit persons to whom the Software is furnished to do so, subject to
53 the following conditions:
54
55 The above copyright notice and this permission notice shall be
56 included in all copies or substantial portions of the Software.
57
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
59 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
61 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
62 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
63 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
64 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 */
66
67#endregion
68using System;
69using System.Collections;
70using System.Collections.Generic;
71using System.Collections.Specialized;
72using System.IO;
73using System.Reflection;
74using System.Text;
75using System.Text.RegularExpressions;
76using System.Xml;
77using System.Xml.Xsl;
78using System.Net;
79using System.Diagnostics;
80
81using Prebuild.Core.Attributes;
82using Prebuild.Core.Interfaces;
83using Prebuild.Core.Nodes;
84using Prebuild.Core.Parse;
85using Prebuild.Core.Utilities;
86
87namespace Prebuild.Core.Targets
88{
89 public enum ClrVersion
90 {
91 Default,
92 Net_1_1,
93 Net_2_0
94 }
95
96 public class SystemPackage
97 {
98 string name;
99 string version;
100 string description;
101 string[] assemblies;
102 bool isInternal;
103 ClrVersion targetVersion;
104
105 public void Initialize(string name,
106 string version,
107 string description,
108 string[] assemblies,
109 ClrVersion targetVersion,
110 bool isInternal)
111 {
112 this.isInternal = isInternal;
113 this.name = name;
114 this.version = version;
115 this.assemblies = assemblies;
116 this.description = description;
117 this.targetVersion = targetVersion;
118 }
119
120 public string Name
121 {
122 get { return name; }
123 }
124
125 public string Version
126 {
127 get { return version; }
128 }
129
130 public string Description
131 {
132 get { return description; }
133 }
134
135 public ClrVersion TargetVersion
136 {
137 get { return targetVersion; }
138 }
139
140 // The package is part of the mono SDK
141 public bool IsCorePackage
142 {
143 get { return name == "mono"; }
144 }
145
146 // The package has been registered by an add-in, and is not installed
147 // in the system.
148 public bool IsInternalPackage
149 {
150 get { return isInternal; }
151 }
152
153 public string[] Assemblies
154 {
155 get { return assemblies; }
156 }
157
158 }
159
160
161 /// <summary>
162 ///
163 /// </summary>
164 [Target("autotools")]
165 public class AutotoolsTarget : ITarget
166 {
167 #region Fields
168
169 Kernel m_Kernel;
170 XmlDocument autotoolsDoc;
171 XmlUrlResolver xr;
172 System.Security.Policy.Evidence e;
173 Hashtable assemblyPathToPackage = new Hashtable();
174 Hashtable assemblyFullNameToPath = new Hashtable();
175 Hashtable packagesHash = new Hashtable();
176 readonly List<SystemPackage> packages = new List<SystemPackage>();
177
178 #endregion
179
180 #region Private Methods
181
182 private void mkdirDashP(string dirName)
183 {
184 DirectoryInfo di = new DirectoryInfo(dirName);
185 if (di.Exists)
186 return;
187
188 string parentDirName = System.IO.Path.GetDirectoryName(dirName);
189 DirectoryInfo parentDi = new DirectoryInfo(parentDirName);
190 if (!parentDi.Exists)
191 mkdirDashP(parentDirName);
192
193 di.Create();
194 }
195
196 private void chkMkDir(string dirName)
197 {
198 System.IO.DirectoryInfo di =
199 new System.IO.DirectoryInfo(dirName);
200
201 if (!di.Exists)
202 di.Create();
203 }
204
205 private void transformToFile(string filename, XsltArgumentList argList, string nodeName)
206 {
207 // Create an XslTransform for this file
208 XslTransform templateTransformer =
209 new XslTransform();
210
211 // Load up the template
212 XmlNode templateNode =
213 autotoolsDoc.SelectSingleNode(nodeName + "/*");
214 templateTransformer.Load(templateNode.CreateNavigator(), xr, e);
215
216 // Create a writer for the transformed template
217 XmlTextWriter templateWriter =
218 new XmlTextWriter(filename, null);
219
220 // Perform transformation, writing the file
221 templateTransformer.Transform
222 (m_Kernel.CurrentDoc, argList, templateWriter, xr);
223 }
224
225 string NormalizeAsmName(string name)
226 {
227 int i = name.IndexOf(", PublicKeyToken=null");
228 if (i != -1)
229 return name.Substring(0, i).Trim();
230 else
231 return name;
232 }
233
234 private void AddAssembly(string assemblyfile, SystemPackage package)
235 {
236 if (!File.Exists(assemblyfile))
237 return;
238
239 try
240 {
241 System.Reflection.AssemblyName an = System.Reflection.AssemblyName.GetAssemblyName(assemblyfile);
242 assemblyFullNameToPath[NormalizeAsmName(an.FullName)] = assemblyfile;
243 assemblyPathToPackage[assemblyfile] = package;
244 }
245 catch
246 {
247 }
248 }
249
250 private List<string> GetAssembliesWithLibInfo(string line, string file)
251 {
252 List<string> references = new List<string>();
253 List<string> libdirs = new List<string>();
254 List<string> retval = new List<string>();
255 foreach (string piece in line.Split(' '))
256 {
257 if (piece.ToLower().Trim().StartsWith("/r:") || piece.ToLower().Trim().StartsWith("-r:"))
258 {
259 references.Add(ProcessPiece(piece.Substring(3).Trim(), file));
260 }
261 else if (piece.ToLower().Trim().StartsWith("/lib:") || piece.ToLower().Trim().StartsWith("-lib:"))
262 {
263 libdirs.Add(ProcessPiece(piece.Substring(5).Trim(), file));
264 }
265 }
266
267 foreach (string refrnc in references)
268 {
269 foreach (string libdir in libdirs)
270 {
271 if (File.Exists(libdir + Path.DirectorySeparatorChar + refrnc))
272 {
273 retval.Add(libdir + Path.DirectorySeparatorChar + refrnc);
274 }
275 }
276 }
277
278 return retval;
279 }
280
281 private List<string> GetAssembliesWithoutLibInfo(string line, string file)
282 {
283 List<string> references = new List<string>();
284 foreach (string reference in line.Split(' '))
285 {
286 if (reference.ToLower().Trim().StartsWith("/r:") || reference.ToLower().Trim().StartsWith("-r:"))
287 {
288 string final_ref = reference.Substring(3).Trim();
289 references.Add(ProcessPiece(final_ref, file));
290 }
291 }
292 return references;
293 }
294
295 private string ProcessPiece(string piece, string pcfile)
296 {
297 int start = piece.IndexOf("${");
298 if (start == -1)
299 return piece;
300
301 int end = piece.IndexOf("}");
302 if (end == -1)
303 return piece;
304
305 string variable = piece.Substring(start + 2, end - start - 2);
306 string interp = GetVariableFromPkgConfig(variable, Path.GetFileNameWithoutExtension(pcfile));
307 return ProcessPiece(piece.Replace("${" + variable + "}", interp), pcfile);
308 }
309
310 private string GetVariableFromPkgConfig(string var, string pcfile)
311 {
312 ProcessStartInfo psi = new ProcessStartInfo("pkg-config");
313 psi.RedirectStandardOutput = true;
314 psi.UseShellExecute = false;
315 psi.Arguments = String.Format("--variable={0} {1}", var, pcfile);
316 Process p = new Process();
317 p.StartInfo = psi;
318 p.Start();
319 string ret = p.StandardOutput.ReadToEnd().Trim();
320 p.WaitForExit();
321 if (String.IsNullOrEmpty(ret))
322 return String.Empty;
323 return ret;
324 }
325
326 private void ParsePCFile(string pcfile)
327 {
328 // Don't register the package twice
329 string pname = Path.GetFileNameWithoutExtension(pcfile);
330 if (packagesHash.Contains(pname))
331 return;
332
333 List<string> fullassemblies = null;
334 string version = "";
335 string desc = "";
336
337 SystemPackage package = new SystemPackage();
338
339 using (StreamReader reader = new StreamReader(pcfile))
340 {
341 string line;
342 while ((line = reader.ReadLine()) != null)
343 {
344 string lowerLine = line.ToLower();
345 if (lowerLine.StartsWith("libs:") && lowerLine.IndexOf(".dll") != -1)
346 {
347 string choppedLine = line.Substring(5).Trim();
348 if (choppedLine.IndexOf("-lib:") != -1 || choppedLine.IndexOf("/lib:") != -1)
349 {
350 fullassemblies = GetAssembliesWithLibInfo(choppedLine, pcfile);
351 }
352 else
353 {
354 fullassemblies = GetAssembliesWithoutLibInfo(choppedLine, pcfile);
355 }
356 }
357 else if (lowerLine.StartsWith("version:"))
358 {
359 // "version:".Length == 8
360 version = line.Substring(8).Trim();
361 }
362 else if (lowerLine.StartsWith("description:"))
363 {
364 // "description:".Length == 12
365 desc = line.Substring(12).Trim();
366 }
367 }
368 }
369
370 if (fullassemblies == null)
371 return;
372
373 foreach (string assembly in fullassemblies)
374 {
375 AddAssembly(assembly, package);
376 }
377
378 package.Initialize(pname,
379 version,
380 desc,
381 fullassemblies.ToArray(),
382 ClrVersion.Default,
383 false);
384 packages.Add(package);
385 packagesHash[pname] = package;
386 }
387
388 void RegisterSystemAssemblies(string prefix, string version, ClrVersion ver)
389 {
390 SystemPackage package = new SystemPackage();
391 List<string> list = new List<string>();
392
393 string dir = Path.Combine(prefix, version);
394 if (!Directory.Exists(dir))
395 {
396 return;
397 }
398
399 foreach (string assembly in Directory.GetFiles(dir, "*.dll"))
400 {
401 AddAssembly(assembly, package);
402 list.Add(assembly);
403 }
404
405 package.Initialize("mono",
406 version,
407 "The Mono runtime",
408 list.ToArray(),
409 ver,
410 false);
411 packages.Add(package);
412 }
413
414 void RunInitialization()
415 {
416 string versionDir;
417
418 if (Environment.Version.Major == 1)
419 {
420 versionDir = "1.0";
421 }
422 else
423 {
424 versionDir = "2.0";
425 }
426
427 //Pull up assemblies from the installed mono system.
428 string prefix = Path.GetDirectoryName(typeof(int).Assembly.Location);
429
430 if (prefix.IndexOf(Path.Combine("mono", versionDir)) == -1)
431 prefix = Path.Combine(prefix, "mono");
432 else
433 prefix = Path.GetDirectoryName(prefix);
434
435 RegisterSystemAssemblies(prefix, "1.0", ClrVersion.Net_1_1);
436 RegisterSystemAssemblies(prefix, "2.0", ClrVersion.Net_2_0);
437
438 string search_dirs = Environment.GetEnvironmentVariable("PKG_CONFIG_PATH");
439 string libpath = Environment.GetEnvironmentVariable("PKG_CONFIG_LIBPATH");
440
441 if (String.IsNullOrEmpty(libpath))
442 {
443 string path_dirs = Environment.GetEnvironmentVariable("PATH");
444 foreach (string pathdir in path_dirs.Split(Path.PathSeparator))
445 {
446 if (pathdir == null)
447 continue;
448 if (File.Exists(pathdir + Path.DirectorySeparatorChar + "pkg-config"))
449 {
450 libpath = Path.Combine(pathdir, "..");
451 libpath = Path.Combine(libpath, "lib");
452 libpath = Path.Combine(libpath, "pkgconfig");
453 break;
454 }
455 }
456 }
457 search_dirs += Path.PathSeparator + libpath;
458 if (!string.IsNullOrEmpty(search_dirs))
459 {
460 List<string> scanDirs = new List<string>();
461 foreach (string potentialDir in search_dirs.Split(Path.PathSeparator))
462 {
463 if (!scanDirs.Contains(potentialDir))
464 scanDirs.Add(potentialDir);
465 }
466 foreach (string pcdir in scanDirs)
467 {
468 if (pcdir == null)
469 continue;
470
471 if (Directory.Exists(pcdir))
472 {
473 foreach (string pcfile in Directory.GetFiles(pcdir, "*.pc"))
474 {
475 ParsePCFile(pcfile);
476 }
477 }
478 }
479 }
480 }
481
482 private void WriteCombine(SolutionNode solution)
483 {
484 #region "Create Solution directory if it doesn't exist"
485 string solutionDir = Path.Combine(solution.FullPath,
486 Path.Combine("autotools",
487 solution.Name));
488 chkMkDir(solutionDir);
489 #endregion
490
491 #region "Write Solution-level files"
492 XsltArgumentList argList = new XsltArgumentList();
493 argList.AddParam("solutionName", "", solution.Name);
494 // $solutionDir is $rootDir/$solutionName/
495 transformToFile(Path.Combine(solutionDir, "configure.ac"),
496 argList, "/Autotools/SolutionConfigureAc");
497 transformToFile(Path.Combine(solutionDir, "Makefile.am"),
498 argList, "/Autotools/SolutionMakefileAm");
499 transformToFile(Path.Combine(solutionDir, "autogen.sh"),
500 argList, "/Autotools/SolutionAutogenSh");
501 #endregion
502
503 foreach (ProjectNode project in solution.ProjectsTableOrder)
504 {
505 m_Kernel.Log.Write(String.Format("Writing project: {0}",
506 project.Name));
507 WriteProject(solution, project);
508 }
509 }
510 private static string PrependPath(string path)
511 {
512 string tmpPath = Helper.NormalizePath(path, '/');
513 Regex regex = new Regex(@"(\w):/(\w+)");
514 Match match = regex.Match(tmpPath);
515 if (match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
516 {
517 tmpPath = Helper.NormalizePath(tmpPath);
518 }
519 else
520 {
521 tmpPath = Helper.NormalizePath("./" + tmpPath);
522 }
523
524 return tmpPath;
525 }
526
527 private static string BuildReference(SolutionNode solution,
528 ReferenceNode refr)
529 {
530 string ret = "";
531 if (solution.ProjectsTable.ContainsKey(refr.Name))
532 {
533 ProjectNode project =
534 (ProjectNode)solution.ProjectsTable[refr.Name];
535 string fileRef = FindFileReference(refr.Name, project);
536 string finalPath =
537 Helper.NormalizePath(Helper.MakeFilePath(project.FullPath +
538 "/$(BUILD_DIR)/$(CONFIG)/",
539 refr.Name, "dll"),
540 '/');
541 ret += finalPath;
542 return ret;
543 }
544 else
545 {
546 ProjectNode project = (ProjectNode)refr.Parent;
547 string fileRef = FindFileReference(refr.Name, project);
548
549 if (refr.Path != null || fileRef != null)
550 {
551 string finalPath = ((refr.Path != null) ?
552 Helper.NormalizePath(refr.Path + "/" +
553 refr.Name + ".dll",
554 '/') :
555 fileRef
556 );
557 ret += Path.Combine(project.Path, finalPath);
558 return ret;
559 }
560
561 try
562 {
563 //Assembly assem = Assembly.Load(refr.Name);
564 //if (assem != null)
565 //{
566 // int index = refr.Name.IndexOf(",");
567 // if ( index > 0)
568 // {
569 // ret += assem.Location;
570 // //Console.WriteLine("Location1: " + assem.Location);
571 // }
572 // else
573 // {
574 // ret += (refr.Name + ".dll");
575 // //Console.WriteLine("Location2: " + assem.Location);
576 // }
577 //}
578 //else
579 //{
580 int index = refr.Name.IndexOf(",");
581 if (index > 0)
582 {
583 ret += refr.Name.Substring(0, index) + ".dll";
584 //Console.WriteLine("Location3: " + assem.Location);
585 }
586 else
587 {
588 ret += (refr.Name + ".dll");
589 //Console.WriteLine("Location4: " + assem.Location);
590 }
591 //}
592 }
593 catch (System.NullReferenceException e)
594 {
595 e.ToString();
596 int index = refr.Name.IndexOf(",");
597 if (index > 0)
598 {
599 ret += refr.Name.Substring(0, index) + ".dll";
600 //Console.WriteLine("Location5: " + assem.Location);
601 }
602 else
603 {
604 ret += (refr.Name + ".dll");
605 //Console.WriteLine("Location6: " + assem.Location);
606 }
607 }
608 }
609 return ret;
610 }
611
612 private static string BuildReferencePath(SolutionNode solution,
613 ReferenceNode refr)
614 {
615 string ret = "";
616 if (solution.ProjectsTable.ContainsKey(refr.Name))
617 {
618 ProjectNode project =
619 (ProjectNode)solution.ProjectsTable[refr.Name];
620 string finalPath =
621 Helper.NormalizePath(Helper.MakeReferencePath(project.FullPath +
622 "/${build.dir}/"),
623 '/');
624 ret += finalPath;
625 return ret;
626 }
627 else
628 {
629 ProjectNode project = (ProjectNode)refr.Parent;
630 string fileRef = FindFileReference(refr.Name, project);
631
632 if (refr.Path != null || fileRef != null)
633 {
634 string finalPath = ((refr.Path != null) ?
635 Helper.NormalizePath(refr.Path, '/') :
636 fileRef
637 );
638 ret += finalPath;
639 return ret;
640 }
641
642 try
643 {
644 Assembly assem = Assembly.Load(refr.Name);
645 if (assem != null)
646 {
647 ret += "";
648 }
649 else
650 {
651 ret += "";
652 }
653 }
654 catch (System.NullReferenceException e)
655 {
656 e.ToString();
657 ret += "";
658 }
659 }
660 return ret;
661 }
662
663 private static string FindFileReference(string refName,
664 ProjectNode project)
665 {
666 foreach (ReferencePathNode refPath in project.ReferencePaths)
667 {
668 string fullPath =
669 Helper.MakeFilePath(refPath.Path, refName, "dll");
670
671 if (File.Exists(fullPath)) {
672 return fullPath;
673 }
674 }
675
676 return null;
677 }
678
679 /// <summary>
680 /// Gets the XML doc file.
681 /// </summary>
682 /// <param name="project">The project.</param>
683 /// <param name="conf">The conf.</param>
684 /// <returns></returns>
685 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
686 {
687 if (conf == null)
688 {
689 throw new ArgumentNullException("conf");
690 }
691 if (project == null)
692 {
693 throw new ArgumentNullException("project");
694 }
695 string docFile = (string)conf.Options["XmlDocFile"];
696 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
697 // {
698 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
699 // }
700 return docFile;
701 }
702
703 /// <summary>
704 /// Normalizes the path.
705 /// </summary>
706 /// <param name="path">The path.</param>
707 /// <returns></returns>
708 public static string NormalizePath(string path)
709 {
710 if (path == null)
711 {
712 return "";
713 }
714
715 StringBuilder tmpPath;
716
717 if (Core.Parse.Preprocessor.GetOS() == "Win32")
718 {
719 tmpPath = new StringBuilder(path.Replace('\\', '/'));
720 tmpPath.Replace("/", @"\\");
721 }
722 else
723 {
724 tmpPath = new StringBuilder(path.Replace('\\', '/'));
725 tmpPath = tmpPath.Replace('/', Path.DirectorySeparatorChar);
726 }
727 return tmpPath.ToString();
728 }
729
730 private void WriteProject(SolutionNode solution, ProjectNode project)
731 {
732 string solutionDir = Path.Combine(solution.FullPath, Path.Combine("autotools", solution.Name));
733 string projectDir = Path.Combine(solutionDir, project.Name);
734 string projectVersion = project.Version;
735 bool hasAssemblyConfig = false;
736 chkMkDir(projectDir);
737
738 List<string>
739 compiledFiles = new List<string>(),
740 contentFiles = new List<string>(),
741 embeddedFiles = new List<string>(),
742
743 binaryLibs = new List<string>(),
744 pkgLibs = new List<string>(),
745 systemLibs = new List<string>(),
746 runtimeLibs = new List<string>(),
747
748 extraDistFiles = new List<string>(),
749 localCopyTargets = new List<string>();
750
751 // If there exists a .config file for this assembly, copy
752 // it to the project folder
753
754 // TODO: Support copying .config.osx files
755 // TODO: support processing the .config file for native library deps
756 string projectAssemblyName = project.Name;
757 if (project.AssemblyName != null)
758 projectAssemblyName = project.AssemblyName;
759
760 if (File.Exists(Path.Combine(project.FullPath, projectAssemblyName) + ".dll.config"))
761 {
762 hasAssemblyConfig = true;
763 System.IO.File.Copy(Path.Combine(project.FullPath, projectAssemblyName + ".dll.config"), Path.Combine(projectDir, projectAssemblyName + ".dll.config"), true);
764 extraDistFiles.Add(project.AssemblyName + ".dll.config");
765 }
766
767 foreach (ConfigurationNode conf in project.Configurations)
768 {
769 if (conf.Options.KeyFile != string.Empty)
770 {
771 // Copy snk file into the project's directory
772 // Use the snk from the project directory directly
773 string source = Path.Combine(project.FullPath, conf.Options.KeyFile);
774 string keyFile = conf.Options.KeyFile;
775 Regex re = new Regex(".*/");
776 keyFile = re.Replace(keyFile, "");
777
778 string dest = Path.Combine(projectDir, keyFile);
779 // Tell the user if there's a problem copying the file
780 try
781 {
782 mkdirDashP(System.IO.Path.GetDirectoryName(dest));
783 System.IO.File.Copy(source, dest, true);
784 }
785 catch (System.IO.IOException e)
786 {
787 Console.WriteLine(e.Message);
788 }
789 }
790 }
791
792 // Copy compiled, embedded and content files into the project's directory
793 foreach (string filename in project.Files)
794 {
795 string source = Path.Combine(project.FullPath, filename);
796 string dest = Path.Combine(projectDir, filename);
797
798 if (filename.Contains("AssemblyInfo.cs"))
799 {
800 // If we've got an AssemblyInfo.cs, pull the version number from it
801 string[] sources = { source };
802 string[] args = { "" };
803 Microsoft.CSharp.CSharpCodeProvider cscp =
804 new Microsoft.CSharp.CSharpCodeProvider();
805
806 string tempAssemblyFile = Path.Combine(Path.GetTempPath(), project.Name + "-temp.dll");
807 System.CodeDom.Compiler.CompilerParameters cparam =
808 new System.CodeDom.Compiler.CompilerParameters(args, tempAssemblyFile);
809
810 System.CodeDom.Compiler.CompilerResults cr =
811 cscp.CompileAssemblyFromFile(cparam, sources);
812
813 foreach (System.CodeDom.Compiler.CompilerError error in cr.Errors)
814 Console.WriteLine("Error! '{0}'", error.ErrorText);
815
816 try {
817 string projectFullName = cr.CompiledAssembly.FullName;
818 Regex verRegex = new Regex("Version=([\\d\\.]+)");
819 Match verMatch = verRegex.Match(projectFullName);
820 if (verMatch.Success)
821 projectVersion = verMatch.Groups[1].Value;
822 }catch{
823 Console.WriteLine("Couldn't compile AssemblyInfo.cs");
824 }
825
826 // Clean up the temp file
827 try
828 {
829 if (File.Exists(tempAssemblyFile))
830 File.Delete(tempAssemblyFile);
831 }
832 catch
833 {
834 Console.WriteLine("Error! '{0}'", e.ToString());
835 }
836
837 }
838
839 // Tell the user if there's a problem copying the file
840 try
841 {
842 mkdirDashP(System.IO.Path.GetDirectoryName(dest));
843 System.IO.File.Copy(source, dest, true);
844 }
845 catch (System.IO.IOException e)
846 {
847 Console.WriteLine(e.Message);
848 }
849
850 switch (project.Files.GetBuildAction(filename))
851 {
852 case BuildAction.Compile:
853 compiledFiles.Add(filename);
854 break;
855 case BuildAction.Content:
856 contentFiles.Add(filename);
857 extraDistFiles.Add(filename);
858 break;
859 case BuildAction.EmbeddedResource:
860 embeddedFiles.Add(filename);
861 break;
862 }
863 }
864
865 // Set up references
866 for (int refNum = 0; refNum < project.References.Count; refNum++)
867 {
868 ReferenceNode refr = (ReferenceNode)project.References[refNum];
869 Assembly refAssembly = Assembly.LoadWithPartialName(refr.Name);
870
871 /* Determine which pkg-config (.pc) file refers to
872 this assembly */
873
874 SystemPackage package = null;
875
876 if (packagesHash.Contains(refr.Name)){
877 package = (SystemPackage)packagesHash[refr.Name];
878
879 }else{
880 string assemblyFullName = string.Empty;
881 if (refAssembly != null)
882 assemblyFullName = refAssembly.FullName;
883
884 string assemblyFileName = string.Empty;
885 if (assemblyFullName != string.Empty &&
886 assemblyFullNameToPath.Contains(assemblyFullName)
887 )
888 assemblyFileName =
889 (string)assemblyFullNameToPath[assemblyFullName];
890
891 if (assemblyFileName != string.Empty &&
892 assemblyPathToPackage.Contains(assemblyFileName)
893 )
894 package = (SystemPackage)assemblyPathToPackage[assemblyFileName];
895
896 }
897
898 /* If we know the .pc file and it is not "mono"
899 (already in the path), add a -pkg: argument */
900
901 if (package != null &&
902 package.Name != "mono" &&
903 !pkgLibs.Contains(package.Name)
904 )
905 pkgLibs.Add(package.Name);
906
907 string fileRef =
908 FindFileReference(refr.Name, (ProjectNode)refr.Parent);
909
910 if (refr.LocalCopy ||
911 solution.ProjectsTable.ContainsKey(refr.Name) ||
912 fileRef != null ||
913 refr.Path != null
914 )
915 {
916
917 /* Attempt to copy the referenced lib to the
918 project's directory */
919
920 string filename = refr.Name + ".dll";
921 string source = filename;
922 if (refr.Path != null)
923 source = Path.Combine(refr.Path, source);
924 source = Path.Combine(project.FullPath, source);
925 string dest = Path.Combine(projectDir, filename);
926
927 /* Since we depend on this binary dll to build, we
928 * will add a compile- time dependency on the
929 * copied dll, and add the dll to the list of
930 * files distributed with this package
931 */
932
933 binaryLibs.Add(refr.Name + ".dll");
934 extraDistFiles.Add(refr.Name + ".dll");
935
936 // TODO: Support copying .config.osx files
937 // TODO: Support for determining native dependencies
938 if (File.Exists(source + ".config"))
939 {
940 System.IO.File.Copy(source + ".config", Path.GetDirectoryName(dest), true);
941 extraDistFiles.Add(refr.Name + ".dll.config");
942 }
943
944 try
945 {
946 System.IO.File.Copy(source, dest, true);
947 }
948 catch (System.IO.IOException)
949 {
950 if (solution.ProjectsTable.ContainsKey(refr.Name)){
951
952 /* If an assembly is referenced, marked for
953 * local copy, in the list of projects for
954 * this solution, but does not exist, put a
955 * target into the Makefile.am to build the
956 * assembly and copy it to this project's
957 * directory
958 */
959
960 ProjectNode sourcePrj =
961 ((ProjectNode)(solution.ProjectsTable[refr.Name]));
962
963 string target =
964 String.Format("{0}:\n" +
965 "\t$(MAKE) -C ../{1}\n" +
966 "\tln ../{2}/$@ $@\n",
967 filename,
968 sourcePrj.Name,
969 sourcePrj.Name );
970
971 localCopyTargets.Add(target);
972 }
973 }
974 }
975 else if( !pkgLibs.Contains(refr.Name) )
976 {
977 // Else, let's assume it's in the GAC or the lib path
978 string assemName = string.Empty;
979 int index = refr.Name.IndexOf(",");
980
981 if (index > 0)
982 assemName = refr.Name.Substring(0, index);
983 else
984 assemName = refr.Name;
985
986 m_Kernel.Log.Write(String.Format(
987 "Warning: Couldn't find an appropriate assembly " +
988 "for reference:\n'{0}'", refr.Name
989 ));
990 systemLibs.Add(assemName);
991 }
992 }
993
994 const string lineSep = " \\\n\t";
995 string compiledFilesString = string.Empty;
996 if (compiledFiles.Count > 0)
997 compiledFilesString =
998 lineSep + string.Join(lineSep, compiledFiles.ToArray());
999
1000 string embeddedFilesString = "";
1001 if (embeddedFiles.Count > 0)
1002 embeddedFilesString =
1003 lineSep + string.Join(lineSep, embeddedFiles.ToArray());
1004
1005 string contentFilesString = "";
1006 if (contentFiles.Count > 0)
1007 contentFilesString =
1008 lineSep + string.Join(lineSep, contentFiles.ToArray());
1009
1010 string extraDistFilesString = "";
1011 if (extraDistFiles.Count > 0)
1012 extraDistFilesString =
1013 lineSep + string.Join(lineSep, extraDistFiles.ToArray());
1014
1015 string pkgLibsString = "";
1016 if (pkgLibs.Count > 0)
1017 pkgLibsString =
1018 lineSep + string.Join(lineSep, pkgLibs.ToArray());
1019
1020 string binaryLibsString = "";
1021 if (binaryLibs.Count > 0)
1022 binaryLibsString =
1023 lineSep + string.Join(lineSep, binaryLibs.ToArray());
1024
1025 string systemLibsString = "";
1026 if (systemLibs.Count > 0)
1027 systemLibsString =
1028 lineSep + string.Join(lineSep, systemLibs.ToArray());
1029
1030 string localCopyTargetsString = "";
1031 if (localCopyTargets.Count > 0)
1032 localCopyTargetsString =
1033 string.Join("\n", localCopyTargets.ToArray());
1034
1035 string monoPath = "";
1036 foreach (string runtimeLib in runtimeLibs)
1037 {
1038 monoPath += ":`pkg-config --variable=libdir " + runtimeLib + "`";
1039 }
1040
1041 // Add the project name to the list of transformation
1042 // parameters
1043 XsltArgumentList argList = new XsltArgumentList();
1044 argList.AddParam("projectName", "", project.Name);
1045 argList.AddParam("solutionName", "", solution.Name);
1046 argList.AddParam("assemblyName", "", projectAssemblyName);
1047 argList.AddParam("compiledFiles", "", compiledFilesString);
1048 argList.AddParam("embeddedFiles", "", embeddedFilesString);
1049 argList.AddParam("contentFiles", "", contentFilesString);
1050 argList.AddParam("extraDistFiles", "", extraDistFilesString);
1051 argList.AddParam("pkgLibs", "", pkgLibsString);
1052 argList.AddParam("binaryLibs", "", binaryLibsString);
1053 argList.AddParam("systemLibs", "", systemLibsString);
1054 argList.AddParam("monoPath", "", monoPath);
1055 argList.AddParam("localCopyTargets", "", localCopyTargetsString);
1056 argList.AddParam("projectVersion", "", projectVersion);
1057 argList.AddParam("hasAssemblyConfig", "", hasAssemblyConfig ? "true" : "");
1058
1059 // Transform the templates
1060 transformToFile(Path.Combine(projectDir, "configure.ac"), argList, "/Autotools/ProjectConfigureAc");
1061 transformToFile(Path.Combine(projectDir, "Makefile.am"), argList, "/Autotools/ProjectMakefileAm");
1062 transformToFile(Path.Combine(projectDir, "autogen.sh"), argList, "/Autotools/ProjectAutogenSh");
1063
1064 if (project.Type == Core.Nodes.ProjectType.Library)
1065 transformToFile(Path.Combine(projectDir, project.Name + ".pc.in"), argList, "/Autotools/ProjectPcIn");
1066 if (project.Type == Core.Nodes.ProjectType.Exe || project.Type == Core.Nodes.ProjectType.WinExe)
1067 transformToFile(Path.Combine(projectDir, project.Name.ToLower() + ".in"), argList, "/Autotools/ProjectWrapperScriptIn");
1068 }
1069
1070 private void WriteProjectOld(SolutionNode solution, ProjectNode project)
1071 {
1072 string projFile = Helper.MakeFilePath(project.FullPath, "Include", "am");
1073 StreamWriter ss = new StreamWriter(projFile);
1074 ss.NewLine = "\n";
1075
1076 m_Kernel.CurrentWorkingDirectory.Push();
1077 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
1078
1079 using (ss)
1080 {
1081 ss.WriteLine(Helper.AssemblyFullName(project.AssemblyName, project.Type) + ":");
1082 ss.WriteLine("\tmkdir -p " + Helper.MakePathRelativeTo(solution.FullPath, project.Path) + "/$(BUILD_DIR)/$(CONFIG)/");
1083 foreach (string file in project.Files)
1084 {
1085 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
1086 {
1087 ss.Write("\tresgen ");
1088 ss.Write(Helper.NormalizePath(Path.Combine(project.Path, file.Substring(0, file.LastIndexOf('.')) + ".resx "), '/'));
1089 if (project.Files.GetResourceName(file) != "")
1090 {
1091 ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + project.Files.GetResourceName(file) + ".resources"), '/'));
1092 }
1093 else
1094 {
1095 ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + file.Substring(0, file.LastIndexOf('.')) + ".resources"), '/'));
1096 }
1097 }
1098 }
1099 ss.WriteLine("\t$(CSC)\t/out:" + Helper.MakePathRelativeTo(solution.FullPath, project.Path) + "/$(BUILD_DIR)/$(CONFIG)/" + Helper.AssemblyFullName(project.AssemblyName, project.Type) + " \\");
1100 ss.WriteLine("\t\t/target:" + project.Type.ToString().ToLower() + " \\");
1101 if (project.References.Count > 0)
1102 {
1103 ss.Write("\t\t/reference:");
1104 bool firstref = true;
1105 foreach (ReferenceNode refr in project.References)
1106 {
1107 if (firstref)
1108 {
1109 firstref = false;
1110 }
1111 else
1112 {
1113 ss.Write(",");
1114 }
1115 ss.Write("{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(solution.FullPath, BuildReference(solution, refr)), '/'));
1116 }
1117 ss.WriteLine(" \\");
1118 }
1119 //ss.WriteLine("\t\tProperties/AssemblyInfo.cs \\");
1120
1121 foreach (string file in project.Files)
1122 {
1123 switch (project.Files.GetBuildAction(file))
1124 {
1125 case BuildAction.EmbeddedResource:
1126 ss.Write("\t\t/resource:");
1127 ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, file), '/') + " \\");
1128 break;
1129 default:
1130 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
1131 {
1132 ss.Write("\t\t/resource:");
1133 if (project.Files.GetResourceName(file) != "")
1134 {
1135 ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + project.Files.GetResourceName(file) + ".resources"), '/') + "," + project.RootNamespace + "." + project.Files.GetResourceName(file) + ".resources" + " \\");
1136 }
1137 else
1138 {
1139 ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + file.Substring(0, file.LastIndexOf('.')) + ".resources"), '/') + "," + project.RootNamespace + "." + file.Substring(0, file.LastIndexOf('.')) + ".resources" + " \\");
1140 }
1141 }
1142 break;
1143 }
1144 }
1145
1146 foreach (ConfigurationNode conf in project.Configurations)
1147 {
1148 if (conf.Options.KeyFile != "")
1149 {
1150 ss.WriteLine("\t\t/keyfile:" + Helper.NormalizePath(Path.Combine(project.Path, conf.Options.KeyFile), '/') + " \\");
1151 break;
1152 }
1153 }
1154 foreach (ConfigurationNode conf in project.Configurations)
1155 {
1156 if (conf.Options.AllowUnsafe)
1157 {
1158 ss.WriteLine("\t\t/unsafe \\");
1159 break;
1160 }
1161 }
1162 if (project.AppIcon != "")
1163 {
1164 ss.WriteLine("\t\t/win32icon:" + Helper.NormalizePath(Path.Combine(project.Path, project.AppIcon), '/') + " \\");
1165 }
1166
1167 foreach (ConfigurationNode conf in project.Configurations)
1168 {
1169 ss.WriteLine("\t\t/define:{0}", conf.Options.CompilerDefines.Replace(';', ',') + " \\");
1170 break;
1171 }
1172
1173 foreach (ConfigurationNode conf in project.Configurations)
1174 {
1175 if (GetXmlDocFile(project, conf) != "")
1176 {
1177 ss.WriteLine("\t\t/doc:" + Helper.MakePathRelativeTo(solution.FullPath, project.Path) + "/$(BUILD_DIR)/$(CONFIG)/" + project.Name + ".xml \\");
1178 break;
1179 }
1180 }
1181 foreach (string file in project.Files)
1182 {
1183 switch (project.Files.GetBuildAction(file))
1184 {
1185 case BuildAction.Compile:
1186 ss.WriteLine("\t\t\\");
1187 ss.Write("\t\t" + NormalizePath(Path.Combine(Helper.MakePathRelativeTo(solution.FullPath, project.Path), file)));
1188 break;
1189 default:
1190 break;
1191 }
1192 }
1193 ss.WriteLine();
1194 ss.WriteLine();
1195
1196 if (project.Type == ProjectType.Library)
1197 {
1198 ss.WriteLine("install-data-local:");
1199 ss.WriteLine(" echo \"$(GACUTIL) /i bin/Release/" + project.Name + ".dll /f $(GACUTIL_FLAGS)\"; \\");
1200 ss.WriteLine(" $(GACUTIL) /i bin/Release/" + project.Name + ".dll /f $(GACUTIL_FLAGS) || exit 1;");
1201 ss.WriteLine();
1202 ss.WriteLine("uninstall-local:");
1203 ss.WriteLine(" echo \"$(GACUTIL) /u " + project.Name + " $(GACUTIL_FLAGS)\"; \\");
1204 ss.WriteLine(" $(GACUTIL) /u " + project.Name + " $(GACUTIL_FLAGS) || exit 1;");
1205 ss.WriteLine();
1206 }
1207 ss.WriteLine("CLEANFILES = $(BUILD_DIR)/$(CONFIG)/" + Helper.AssemblyFullName(project.AssemblyName, project.Type) + " $(BUILD_DIR)/$(CONFIG)/" + project.AssemblyName + ".mdb $(BUILD_DIR)/$(CONFIG)/" + project.AssemblyName + ".pdb " + project.AssemblyName + ".xml");
1208 ss.WriteLine("EXTRA_DIST = \\");
1209 ss.Write(" $(FILES)");
1210 foreach (ConfigurationNode conf in project.Configurations)
1211 {
1212 if (conf.Options.KeyFile != "")
1213 {
1214 ss.Write(" \\");
1215 ss.WriteLine("\t" + conf.Options.KeyFile);
1216 }
1217 break;
1218 }
1219 }
1220 m_Kernel.CurrentWorkingDirectory.Pop();
1221 }
1222 bool hasLibrary = false;
1223
1224 private void WriteCombineOld(SolutionNode solution)
1225 {
1226
1227 /* TODO: These vars should be pulled from the prebuild.xml file */
1228 string releaseVersion = "2.0.0";
1229 string assemblyVersion = "2.1.0.0";
1230 string description =
1231 "Tao Framework " + solution.Name + " Binding For .NET";
1232
1233 hasLibrary = false;
1234 m_Kernel.Log.Write("Creating Autotools make files");
1235 foreach (ProjectNode project in solution.Projects)
1236 {
1237 if (m_Kernel.AllowProject(project.FilterGroups))
1238 {
1239 m_Kernel.Log.Write("...Creating makefile: {0}", project.Name);
1240 WriteProject(solution, project);
1241 }
1242 }
1243
1244 m_Kernel.Log.Write("");
1245 string combFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "am");
1246 StreamWriter ss = new StreamWriter(combFile);
1247 ss.NewLine = "\n";
1248
1249 m_Kernel.CurrentWorkingDirectory.Push();
1250 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
1251
1252 using (ss)
1253 {
1254 foreach (ProjectNode project in solution.ProjectsTableOrder)
1255 {
1256 if (project.Type == ProjectType.Library)
1257 {
1258 hasLibrary = true;
1259 break;
1260 }
1261 }
1262
1263 if (hasLibrary)
1264 {
1265 ss.Write("pkgconfig_in_files = ");
1266 foreach (ProjectNode project in solution.ProjectsTableOrder)
1267 {
1268 if (project.Type == ProjectType.Library)
1269 {
1270 string combFilepc = Helper.MakeFilePath(solution.FullPath, project.Name, "pc.in");
1271 ss.Write(" " + project.Name + ".pc.in ");
1272 StreamWriter sspc = new StreamWriter(combFilepc);
1273 sspc.NewLine = "\n";
1274 using (sspc)
1275 {
1276 sspc.WriteLine("prefix=@prefix@");
1277 sspc.WriteLine("exec_prefix=${prefix}");
1278 sspc.WriteLine("libdir=${exec_prefix}/lib");
1279 sspc.WriteLine();
1280 sspc.WriteLine("Name: @PACKAGE_NAME@");
1281 sspc.WriteLine("Description: @DESCRIPTION@");
1282 sspc.WriteLine("Version: @ASSEMBLY_VERSION@");
1283 sspc.WriteLine("Libs: -r:${libdir}/mono/gac/@PACKAGE_NAME@/@ASSEMBLY_VERSION@__@PUBKEY@/@PACKAGE_NAME@.dll");
1284 }
1285 }
1286 }
1287
1288 ss.WriteLine();
1289 ss.WriteLine("pkgconfigdir=$(prefix)/lib/pkgconfig");
1290 ss.WriteLine("pkgconfig_DATA=$(pkgconfig_in_files:.pc.in=.pc)");
1291 }
1292 ss.WriteLine();
1293 foreach (ProjectNode project in solution.ProjectsTableOrder)
1294 {
1295 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
1296 ss.WriteLine("-include x {0}",
1297 Helper.NormalizePath(Helper.MakeFilePath(path, "Include", "am"), '/'));
1298 }
1299 ss.WriteLine();
1300 ss.WriteLine("all: \\");
1301 ss.Write("\t");
1302 foreach (ProjectNode project in solution.ProjectsTableOrder)
1303 {
1304 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
1305 ss.Write(Helper.AssemblyFullName(project.AssemblyName, project.Type) + " ");
1306
1307 }
1308 ss.WriteLine();
1309 if (hasLibrary)
1310 {
1311 ss.WriteLine("EXTRA_DIST = \\");
1312 ss.WriteLine("\t$(pkgconfig_in_files)");
1313 }
1314 else
1315 {
1316 ss.WriteLine("EXTRA_DIST = ");
1317 }
1318 ss.WriteLine();
1319 ss.WriteLine("DISTCLEANFILES = \\");
1320 ss.WriteLine("\tconfigure \\");
1321 ss.WriteLine("\tMakefile.in \\");
1322 ss.WriteLine("\taclocal.m4");
1323 }
1324 combFile = Helper.MakeFilePath(solution.FullPath, "configure", "ac");
1325 StreamWriter ts = new StreamWriter(combFile);
1326 ts.NewLine = "\n";
1327 using (ts)
1328 {
1329 if (this.hasLibrary)
1330 {
1331 foreach (ProjectNode project in solution.ProjectsTableOrder)
1332 {
1333 if (project.Type == ProjectType.Library)
1334 {
1335 ts.WriteLine("AC_INIT(" + project.Name + ".pc.in)");
1336 break;
1337 }
1338 }
1339 }
1340 else
1341 {
1342 ts.WriteLine("AC_INIT(Makefile.am)");
1343 }
1344 ts.WriteLine("AC_PREREQ(2.53)");
1345 ts.WriteLine("AC_CANONICAL_SYSTEM");
1346
1347 ts.WriteLine("PACKAGE_NAME={0}", solution.Name);
1348 ts.WriteLine("PACKAGE_VERSION={0}", releaseVersion);
1349 ts.WriteLine("DESCRIPTION=\"{0}\"", description);
1350 ts.WriteLine("AC_SUBST(DESCRIPTION)");
1351 ts.WriteLine("AM_INIT_AUTOMAKE([$PACKAGE_NAME],[$PACKAGE_VERSION],[$DESCRIPTION])");
1352
1353 ts.WriteLine("ASSEMBLY_VERSION={0}", assemblyVersion);
1354 ts.WriteLine("AC_SUBST(ASSEMBLY_VERSION)");
1355
1356 ts.WriteLine("PUBKEY=`sn -t $PACKAGE_NAME.snk | grep 'Public Key Token' | awk -F: '{print $2}' | sed -e 's/^ //'`");
1357 ts.WriteLine("AC_SUBST(PUBKEY)");
1358
1359 ts.WriteLine();
1360 ts.WriteLine("AM_MAINTAINER_MODE");
1361 ts.WriteLine();
1362 ts.WriteLine("dnl AC_PROG_INTLTOOL([0.25])");
1363 ts.WriteLine();
1364 ts.WriteLine("AC_PROG_INSTALL");
1365 ts.WriteLine();
1366 ts.WriteLine("MONO_REQUIRED_VERSION=1.1");
1367 ts.WriteLine();
1368 ts.WriteLine("AC_MSG_CHECKING([whether we're compiling from CVS])");
1369 ts.WriteLine("if test -f \"$srcdir/.cvs_version\" ; then");
1370 ts.WriteLine(" from_cvs=yes");
1371 ts.WriteLine("else");
1372 ts.WriteLine(" if test -f \"$srcdir/.svn\" ; then");
1373 ts.WriteLine(" from_cvs=yes");
1374 ts.WriteLine(" else");
1375 ts.WriteLine(" from_cvs=no");
1376 ts.WriteLine(" fi");
1377 ts.WriteLine("fi");
1378 ts.WriteLine();
1379 ts.WriteLine("AC_MSG_RESULT($from_cvs)");
1380 ts.WriteLine();
1381 ts.WriteLine("AC_PATH_PROG(MONO, mono)");
1382 ts.WriteLine("AC_PATH_PROG(GMCS, gmcs)");
1383 ts.WriteLine("AC_PATH_PROG(GACUTIL, gacutil)");
1384 ts.WriteLine();
1385 ts.WriteLine("AC_MSG_CHECKING([for mono])");
1386 ts.WriteLine("dnl if test \"x$MONO\" = \"x\" ; then");
1387 ts.WriteLine("dnl AC_MSG_ERROR([Can't find \"mono\" in your PATH])");
1388 ts.WriteLine("dnl else");
1389 ts.WriteLine(" AC_MSG_RESULT([found])");
1390 ts.WriteLine("dnl fi");
1391 ts.WriteLine();
1392 ts.WriteLine("AC_MSG_CHECKING([for gmcs])");
1393 ts.WriteLine("dnl if test \"x$GMCS\" = \"x\" ; then");
1394 ts.WriteLine("dnl AC_MSG_ERROR([Can't find \"gmcs\" in your PATH])");
1395 ts.WriteLine("dnl else");
1396 ts.WriteLine(" AC_MSG_RESULT([found])");
1397 ts.WriteLine("dnl fi");
1398 ts.WriteLine();
1399 //ts.WriteLine("AC_MSG_CHECKING([for gacutil])");
1400 //ts.WriteLine("if test \"x$GACUTIL\" = \"x\" ; then");
1401 //ts.WriteLine(" AC_MSG_ERROR([Can't find \"gacutil\" in your PATH])");
1402 //ts.WriteLine("else");
1403 //ts.WriteLine(" AC_MSG_RESULT([found])");
1404 //ts.WriteLine("fi");
1405 ts.WriteLine();
1406 ts.WriteLine("AC_SUBST(PATH)");
1407 ts.WriteLine("AC_SUBST(LD_LIBRARY_PATH)");
1408 ts.WriteLine();
1409 ts.WriteLine("dnl CSFLAGS=\"-debug -nowarn:1574\"");
1410 ts.WriteLine("CSFLAGS=\"\"");
1411 ts.WriteLine("AC_SUBST(CSFLAGS)");
1412 ts.WriteLine();
1413 // ts.WriteLine("AC_MSG_CHECKING(--disable-sdl argument)");
1414 // ts.WriteLine("AC_ARG_ENABLE(sdl,");
1415 // ts.WriteLine(" [ --disable-sdl Disable Sdl interface.],");
1416 // ts.WriteLine(" [disable_sdl=$disableval],");
1417 // ts.WriteLine(" [disable_sdl=\"no\"])");
1418 // ts.WriteLine("AC_MSG_RESULT($disable_sdl)");
1419 // ts.WriteLine("if test \"$disable_sdl\" = \"yes\"; then");
1420 // ts.WriteLine(" AC_DEFINE(FEAT_SDL)");
1421 // ts.WriteLine("fi");
1422 ts.WriteLine();
1423 ts.WriteLine("dnl Find pkg-config");
1424 ts.WriteLine("AC_PATH_PROG(PKGCONFIG, pkg-config, no)");
1425 ts.WriteLine("if test \"x$PKG_CONFIG\" = \"xno\"; then");
1426 ts.WriteLine(" AC_MSG_ERROR([You need to install pkg-config])");
1427 ts.WriteLine("fi");
1428 ts.WriteLine();
1429 ts.WriteLine("PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)");
1430 ts.WriteLine("BUILD_DIR=\"bin\"");
1431 ts.WriteLine("AC_SUBST(BUILD_DIR)");
1432 ts.WriteLine("CONFIG=\"Release\"");
1433 ts.WriteLine("AC_SUBST(CONFIG)");
1434 ts.WriteLine();
1435 ts.WriteLine("if test \"x$has_mono\" = \"xtrue\"; then");
1436 ts.WriteLine(" AC_PATH_PROG(RUNTIME, mono, no)");
1437 ts.WriteLine(" AC_PATH_PROG(CSC, gmcs, no)");
1438 ts.WriteLine(" if test `uname -s` = \"Darwin\"; then");
1439 ts.WriteLine(" LIB_PREFIX=");
1440 ts.WriteLine(" LIB_SUFFIX=.dylib");
1441 ts.WriteLine(" else");
1442 ts.WriteLine(" LIB_PREFIX=.so");
1443 ts.WriteLine(" LIB_SUFFIX=");
1444 ts.WriteLine(" fi");
1445 ts.WriteLine("else");
1446 ts.WriteLine(" AC_PATH_PROG(CSC, csc.exe, no)");
1447 ts.WriteLine(" if test x$CSC = \"xno\"; then");
1448 ts.WriteLine(" AC_MSG_ERROR([You need to install either mono or .Net])");
1449 ts.WriteLine(" else");
1450 ts.WriteLine(" RUNTIME=");
1451 ts.WriteLine(" LIB_PREFIX=");
1452 ts.WriteLine(" LIB_SUFFIX=.dylib");
1453 ts.WriteLine(" fi");
1454 ts.WriteLine("fi");
1455 ts.WriteLine();
1456 ts.WriteLine("AC_SUBST(LIB_PREFIX)");
1457 ts.WriteLine("AC_SUBST(LIB_SUFFIX)");
1458 ts.WriteLine();
1459 ts.WriteLine("AC_SUBST(BASE_DEPENDENCIES_CFLAGS)");
1460 ts.WriteLine("AC_SUBST(BASE_DEPENDENCIES_LIBS)");
1461 ts.WriteLine();
1462 ts.WriteLine("dnl Find monodoc");
1463 ts.WriteLine("MONODOC_REQUIRED_VERSION=1.0");
1464 ts.WriteLine("AC_SUBST(MONODOC_REQUIRED_VERSION)");
1465 ts.WriteLine("PKG_CHECK_MODULES(MONODOC_DEPENDENCY, monodoc >= $MONODOC_REQUIRED_VERSION, enable_monodoc=yes, enable_monodoc=no)");
1466 ts.WriteLine();
1467 ts.WriteLine("if test \"x$enable_monodoc\" = \"xyes\"; then");
1468 ts.WriteLine(" AC_PATH_PROG(MONODOC, monodoc, no)");
1469 ts.WriteLine(" if test x$MONODOC = xno; then");
1470 ts.WriteLine(" enable_monodoc=no");
1471 ts.WriteLine(" fi");
1472 ts.WriteLine("else");
1473 ts.WriteLine(" MONODOC=");
1474 ts.WriteLine("fi");
1475 ts.WriteLine();
1476 ts.WriteLine("AC_SUBST(MONODOC)");
1477 ts.WriteLine("AM_CONDITIONAL(ENABLE_MONODOC, test \"x$enable_monodoc\" = \"xyes\")");
1478 ts.WriteLine();
1479 ts.WriteLine("AC_PATH_PROG(GACUTIL, gacutil, no)");
1480 ts.WriteLine("if test \"x$GACUTIL\" = \"xno\" ; then");
1481 ts.WriteLine(" AC_MSG_ERROR([No gacutil tool found])");
1482 ts.WriteLine("fi");
1483 ts.WriteLine();
1484 // foreach(ProjectNode project in solution.ProjectsTableOrder)
1485 // {
1486 // if (project.Type == ProjectType.Library)
1487 // {
1488 // }
1489 // }
1490 ts.WriteLine("GACUTIL_FLAGS='/package $(PACKAGE_NAME) /gacdir $(DESTDIR)$(prefix)'");
1491 ts.WriteLine("AC_SUBST(GACUTIL_FLAGS)");
1492 ts.WriteLine();
1493 ts.WriteLine("winbuild=no");
1494 ts.WriteLine("case \"$host\" in");
1495 ts.WriteLine(" *-*-mingw*|*-*-cygwin*)");
1496 ts.WriteLine(" winbuild=yes");
1497 ts.WriteLine(" ;;");
1498 ts.WriteLine("esac");
1499 ts.WriteLine("AM_CONDITIONAL(WINBUILD, test x$winbuild = xyes)");
1500 ts.WriteLine();
1501 // ts.WriteLine("dnl Check for SDL");
1502 // ts.WriteLine();
1503 // ts.WriteLine("AC_PATH_PROG([SDL_CONFIG], [sdl-config])");
1504 // ts.WriteLine("have_sdl=no");
1505 // ts.WriteLine("if test -n \"${SDL_CONFIG}\"; then");
1506 // ts.WriteLine(" have_sdl=yes");
1507 // ts.WriteLine(" SDL_CFLAGS=`$SDL_CONFIG --cflags`");
1508 // ts.WriteLine(" SDL_LIBS=`$SDL_CONFIG --libs`");
1509 // ts.WriteLine(" #");
1510 // ts.WriteLine(" # sdl-config sometimes emits an rpath flag pointing at its library");
1511 // ts.WriteLine(" # installation directory. We don't want this, as it prevents users from");
1512 // ts.WriteLine(" # linking sdl-viewer against, for example, a locally compiled libGL when a");
1513 // ts.WriteLine(" # version of the library also exists in SDL's library installation");
1514 // ts.WriteLine(" # directory, typically /usr/lib.");
1515 // ts.WriteLine(" #");
1516 // ts.WriteLine(" SDL_LIBS=`echo $SDL_LIBS | sed 's/-Wl,-rpath,[[^ ]]* //'`");
1517 // ts.WriteLine("fi");
1518 // ts.WriteLine("AC_SUBST([SDL_CFLAGS])");
1519 // ts.WriteLine("AC_SUBST([SDL_LIBS])");
1520 ts.WriteLine();
1521 ts.WriteLine("AC_OUTPUT([");
1522 ts.WriteLine("Makefile");
1523 // TODO: this does not work quite right.
1524 //ts.WriteLine("Properties/AssemblyInfo.cs");
1525 foreach (ProjectNode project in solution.ProjectsTableOrder)
1526 {
1527 if (project.Type == ProjectType.Library)
1528 {
1529 ts.WriteLine(project.Name + ".pc");
1530 }
1531 // string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
1532 // ts.WriteLine(Helper.NormalizePath(Helper.MakeFilePath(path, "Include"),'/'));
1533 }
1534 ts.WriteLine("])");
1535 ts.WriteLine();
1536 ts.WriteLine("#po/Makefile.in");
1537 ts.WriteLine();
1538 ts.WriteLine("echo \"---\"");
1539 ts.WriteLine("echo \"Configuration summary\"");
1540 ts.WriteLine("echo \"\"");
1541 ts.WriteLine("echo \" * Installation prefix: $prefix\"");
1542 ts.WriteLine("echo \" * compiler: $CSC\"");
1543 ts.WriteLine("echo \" * Documentation: $enable_monodoc ($MONODOC)\"");
1544 ts.WriteLine("echo \" * Package Name: $PACKAGE_NAME\"");
1545 ts.WriteLine("echo \" * Version: $PACKAGE_VERSION\"");
1546 ts.WriteLine("echo \" * Public Key: $PUBKEY\"");
1547 ts.WriteLine("echo \"\"");
1548 ts.WriteLine("echo \"---\"");
1549 ts.WriteLine();
1550 }
1551
1552 ts.NewLine = "\n";
1553 foreach (ProjectNode project in solution.ProjectsTableOrder)
1554 {
1555 if (project.GenerateAssemblyInfoFile)
1556 {
1557 GenerateAssemblyInfoFile(solution, combFile);
1558 }
1559 }
1560 }
1561
1562 private static void GenerateAssemblyInfoFile(SolutionNode solution, string combFile)
1563 {
1564 System.IO.Directory.CreateDirectory(Helper.MakePathRelativeTo(solution.FullPath, "Properties"));
1565 combFile = Helper.MakeFilePath(solution.FullPath + "/Properties/", "AssemblyInfo.cs", "in");
1566 StreamWriter ai = new StreamWriter(combFile);
1567
1568 using (ai)
1569 {
1570 ai.WriteLine("#region License");
1571 ai.WriteLine("/*");
1572 ai.WriteLine("MIT License");
1573 ai.WriteLine("Copyright (c)2003-2006 Tao Framework Team");
1574 ai.WriteLine("http://www.taoframework.com");
1575 ai.WriteLine("All rights reserved.");
1576 ai.WriteLine("");
1577 ai.WriteLine("Permission is hereby granted, free of charge, to any person obtaining a copy");
1578 ai.WriteLine("of this software and associated documentation files (the \"Software\"), to deal");
1579 ai.WriteLine("in the Software without restriction, including without limitation the rights");
1580 ai.WriteLine("to use, copy, modify, merge, publish, distribute, sublicense, and/or sell");
1581 ai.WriteLine("copies of the Software, and to permit persons to whom the Software is");
1582 ai.WriteLine("furnished to do so, subject to the following conditions:");
1583 ai.WriteLine("");
1584 ai.WriteLine("The above copyright notice and this permission notice shall be included in all");
1585 ai.WriteLine("copies or substantial portions of the Software.");
1586 ai.WriteLine("");
1587 ai.WriteLine("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR");
1588 ai.WriteLine("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,");
1589 ai.WriteLine("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE");
1590 ai.WriteLine("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER");
1591 ai.WriteLine("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,");
1592 ai.WriteLine("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE");
1593 ai.WriteLine("SOFTWARE.");
1594 ai.WriteLine("*/");
1595 ai.WriteLine("#endregion License");
1596 ai.WriteLine("");
1597 ai.WriteLine("using System;");
1598 ai.WriteLine("using System.Reflection;");
1599 ai.WriteLine("using System.Runtime.InteropServices;");
1600 ai.WriteLine("using System.Security;");
1601 ai.WriteLine("using System.Security.Permissions;");
1602 ai.WriteLine("");
1603 ai.WriteLine("[assembly: AllowPartiallyTrustedCallers]");
1604 ai.WriteLine("[assembly: AssemblyCompany(\"Tao Framework -- http://www.taoframework.com\")]");
1605 ai.WriteLine("[assembly: AssemblyConfiguration(\"Retail\")]");
1606 ai.WriteLine("[assembly: AssemblyCopyright(\"Copyright (c)2003-2006 Tao Framework Team. All rights reserved.\")]");
1607 ai.WriteLine("[assembly: AssemblyCulture(\"\")]");
1608 ai.WriteLine("[assembly: AssemblyDefaultAlias(\"@PACKAGE_NAME@\")]");
1609 ai.WriteLine("[assembly: AssemblyDelaySign(false)]");
1610 ai.WriteLine("[assembly: AssemblyDescription(\"@DESCRIPTION@\")]");
1611 ai.WriteLine("[assembly: AssemblyFileVersion(\"@ASSEMBLY_VERSION@\")]");
1612 ai.WriteLine("[assembly: AssemblyInformationalVersion(\"@ASSEMBLY_VERSION@\")]");
1613 ai.WriteLine("[assembly: AssemblyKeyName(\"\")]");
1614 ai.WriteLine("[assembly: AssemblyProduct(\"@PACKAGE_NAME@.dll\")]");
1615 ai.WriteLine("[assembly: AssemblyTitle(\"@DESCRIPTION@\")]");
1616 ai.WriteLine("[assembly: AssemblyTrademark(\"Tao Framework -- http://www.taoframework.com\")]");
1617 ai.WriteLine("[assembly: AssemblyVersion(\"@ASSEMBLY_VERSION@\")]");
1618 ai.WriteLine("[assembly: CLSCompliant(true)]");
1619 ai.WriteLine("[assembly: ComVisible(false)]");
1620 ai.WriteLine("[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.Execution)]");
1621 ai.WriteLine("[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.SkipVerification)]");
1622 ai.WriteLine("[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.UnmanagedCode)]");
1623
1624 }
1625 //return combFile;
1626 }
1627
1628 private void CleanProject(ProjectNode project)
1629 {
1630 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
1631 string projectFile = Helper.MakeFilePath(project.FullPath, "Include", "am");
1632 Helper.DeleteIfExists(projectFile);
1633 }
1634
1635 private void CleanSolution(SolutionNode solution)
1636 {
1637 m_Kernel.Log.Write("Cleaning Autotools make files for", solution.Name);
1638
1639 string slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "am");
1640 Helper.DeleteIfExists(slnFile);
1641
1642 slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "in");
1643 Helper.DeleteIfExists(slnFile);
1644
1645 slnFile = Helper.MakeFilePath(solution.FullPath, "configure", "ac");
1646 Helper.DeleteIfExists(slnFile);
1647
1648 slnFile = Helper.MakeFilePath(solution.FullPath, "configure");
1649 Helper.DeleteIfExists(slnFile);
1650
1651 slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile");
1652 Helper.DeleteIfExists(slnFile);
1653
1654 foreach (ProjectNode project in solution.Projects)
1655 {
1656 CleanProject(project);
1657 }
1658
1659 m_Kernel.Log.Write("");
1660 }
1661
1662 #endregion
1663
1664 #region ITarget Members
1665
1666 /// <summary>
1667 /// Writes the specified kern.
1668 /// </summary>
1669 /// <param name="kern">The kern.</param>
1670 public void Write(Kernel kern)
1671 {
1672 if (kern == null)
1673 {
1674 throw new ArgumentNullException("kern");
1675 }
1676 m_Kernel = kern;
1677 m_Kernel.Log.Write("Parsing system pkg-config files");
1678 RunInitialization();
1679
1680 string streamName = "autotools.xml";
1681 string fqStreamName = String.Format("Prebuild.data.{0}",
1682 streamName
1683 );
1684
1685 // Retrieve stream for the autotools template XML
1686 Stream autotoolsStream = Assembly.GetExecutingAssembly()
1687 .GetManifestResourceStream(fqStreamName);
1688
1689 if(autotoolsStream == null) {
1690
1691 /*
1692 * try without the default namespace prepended, in
1693 * case prebuild.exe assembly was compiled with
1694 * something other than Visual Studio .NET
1695 */
1696
1697 autotoolsStream = Assembly.GetExecutingAssembly()
1698 .GetManifestResourceStream(streamName);
1699 if(autotoolsStream == null){
1700 string errStr =
1701 String.Format("Could not find embedded resource file:\n" +
1702 "'{0}' or '{1}'",
1703 streamName, fqStreamName
1704 );
1705
1706 m_Kernel.Log.Write(errStr);
1707
1708 throw new System.Reflection.TargetException(errStr);
1709 }
1710 }
1711
1712 // Create an XML URL Resolver with default credentials
1713 xr = new System.Xml.XmlUrlResolver();
1714 xr.Credentials = CredentialCache.DefaultCredentials;
1715
1716 // Create a default evidence - no need to limit access
1717 e = new System.Security.Policy.Evidence();
1718
1719 // Load the autotools XML
1720 autotoolsDoc = new XmlDocument();
1721 autotoolsDoc.Load(autotoolsStream);
1722
1723 /* rootDir is the filesystem location where the Autotools
1724 * build tree will be created - for now we'll make it
1725 * $PWD/autotools
1726 */
1727
1728 string pwd = Directory.GetCurrentDirectory();
1729 //string pwd = System.Environment.GetEnvironmentVariable("PWD");
1730 string rootDir = "";
1731 //if (pwd.Length != 0)
1732 //{
1733 rootDir = Path.Combine(pwd, "autotools");
1734 //}
1735 //else
1736 //{
1737 // pwd = Assembly.GetExecutingAssembly()
1738 //}
1739 chkMkDir(rootDir);
1740
1741 foreach (SolutionNode solution in kern.Solutions)
1742 {
1743 m_Kernel.Log.Write(String.Format("Writing solution: {0}",
1744 solution.Name));
1745 WriteCombine(solution);
1746 }
1747 m_Kernel = null;
1748 }
1749
1750 /// <summary>
1751 /// Cleans the specified kern.
1752 /// </summary>
1753 /// <param name="kern">The kern.</param>
1754 public virtual void Clean(Kernel kern)
1755 {
1756 if (kern == null)
1757 {
1758 throw new ArgumentNullException("kern");
1759 }
1760 m_Kernel = kern;
1761 foreach (SolutionNode sol in kern.Solutions)
1762 {
1763 CleanSolution(sol);
1764 }
1765 m_Kernel = null;
1766 }
1767
1768 /// <summary>
1769 /// Gets the name.
1770 /// </summary>
1771 /// <value>The name.</value>
1772 public string Name
1773 {
1774 get
1775 {
1776 return "autotools";
1777 }
1778 }
1779
1780 #endregion
1781 }
1782}