2009-02-22 10:43:35 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Using Directives ---
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2009-08-25 14:36:19 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using OpenTK.Build.Properties;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Build
|
|
|
|
|
{
|
|
|
|
|
class Project
|
|
|
|
|
{
|
|
|
|
|
static string RootPath;
|
|
|
|
|
static string SourcePath;
|
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
const string bindings = "Generator.Prebuild.xml";
|
|
|
|
|
const string opentk = "OpenTK.Prebuild.xml";
|
|
|
|
|
const string quickstart = "QuickStart.Prebuild.xml";
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
static readonly Assembly Prebuild = Assembly.Load(Resources.Prebuild);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
enum BuildTarget
|
|
|
|
|
{
|
|
|
|
|
VS2005,
|
2009-08-25 14:36:19 +00:00
|
|
|
|
VS2008,
|
|
|
|
|
Mono,
|
|
|
|
|
Net,
|
2009-02-22 10:43:35 +00:00
|
|
|
|
Clean,
|
|
|
|
|
DistClean,
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
static BuildTarget target = BuildTarget.VS2005;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
static void PrintUsage()
|
|
|
|
|
{
|
2009-08-25 14:36:19 +00:00
|
|
|
|
Console.WriteLine("Usage: Build.exe target");
|
|
|
|
|
Console.WriteLine(" target: one of vs, vs9, clean, distclean");
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2009-02-28 16:26:25 +00:00
|
|
|
|
if (args.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
PrintUsage();
|
2009-02-28 22:01:39 +00:00
|
|
|
|
|
2009-05-31 15:02:27 +00:00
|
|
|
|
args = new string[2] { String.Empty, String.Empty };
|
2009-02-28 22:01:39 +00:00
|
|
|
|
Console.Write("Select build target: ");
|
|
|
|
|
args[0] = Console.ReadLine();
|
2009-05-21 09:26:07 +00:00
|
|
|
|
if (args[0] == String.Empty)
|
|
|
|
|
args[0] = "vs";
|
2009-02-28 16:26:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
RootPath = Directory.GetCurrentDirectory();
|
2009-02-22 10:43:35 +00:00
|
|
|
|
SourcePath = Path.Combine(RootPath, "Source");
|
2009-08-25 14:36:19 +00:00
|
|
|
|
|
|
|
|
|
File.WriteAllText(bindings, Resources.Generator);
|
|
|
|
|
File.WriteAllText(opentk, Resources.OpenTK);
|
|
|
|
|
File.WriteAllText(quickstart, Resources.QuickStart);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-05-21 09:26:07 +00:00
|
|
|
|
// Workaroung for nant on x64 windows (safe for other platforms too, as this affects only the current process).
|
2009-02-22 10:43:35 +00:00
|
|
|
|
Environment.SetEnvironmentVariable("CommonProgramFiles(x86)", String.Empty, EnvironmentVariableTarget.Process);
|
|
|
|
|
Environment.SetEnvironmentVariable("ProgramFiles(x86)", String.Empty, EnvironmentVariableTarget.Process);
|
|
|
|
|
|
2009-02-28 16:26:25 +00:00
|
|
|
|
foreach (string s in args)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-05-31 15:02:27 +00:00
|
|
|
|
string arg = s.ToLower().Trim();
|
2009-02-28 16:26:25 +00:00
|
|
|
|
switch (arg)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-08-25 14:36:19 +00:00
|
|
|
|
case "":
|
2009-05-21 09:26:07 +00:00
|
|
|
|
break;
|
2009-02-28 16:26:25 +00:00
|
|
|
|
|
2009-05-21 09:26:07 +00:00
|
|
|
|
case "mono":
|
2009-08-25 14:36:19 +00:00
|
|
|
|
case "xbuild":
|
2009-05-21 09:26:07 +00:00
|
|
|
|
target = BuildTarget.Mono;
|
|
|
|
|
break;
|
2009-02-28 16:26:25 +00:00
|
|
|
|
|
2009-05-21 09:26:07 +00:00
|
|
|
|
case "net":
|
2009-08-25 14:36:19 +00:00
|
|
|
|
case "msbuild":
|
2009-05-21 09:26:07 +00:00
|
|
|
|
target = BuildTarget.Net;
|
|
|
|
|
break;
|
2009-02-28 16:26:25 +00:00
|
|
|
|
|
|
|
|
|
case "vs2005":
|
2009-08-25 14:36:19 +00:00
|
|
|
|
case "vs8":
|
2009-02-28 16:26:25 +00:00
|
|
|
|
case "vs":
|
|
|
|
|
target = BuildTarget.VS2005;
|
|
|
|
|
break;
|
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
case "vs2008":
|
|
|
|
|
case "vs9":
|
|
|
|
|
target = BuildTarget.VS2008;
|
|
|
|
|
break;
|
|
|
|
|
|
2009-02-28 16:26:25 +00:00
|
|
|
|
case "clean":
|
|
|
|
|
target = BuildTarget.Clean;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "distclean":
|
|
|
|
|
target = BuildTarget.DistClean;
|
|
|
|
|
break;
|
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
default:
|
2009-05-31 15:02:27 +00:00
|
|
|
|
Console.WriteLine("Unknown command: {0}", s);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
PrintUsage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-05-31 15:02:27 +00:00
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-05-31 15:02:27 +00:00
|
|
|
|
switch (target)
|
|
|
|
|
{
|
2009-08-25 14:36:19 +00:00
|
|
|
|
//case BuildTarget.Mono:
|
|
|
|
|
// Console.WriteLine("Building OpenTK using Mono/XBuild.");
|
|
|
|
|
// ExecuteProcess(PrebuildPath, "/target nant /file " + PrebuildXml);
|
|
|
|
|
// Console.WriteLine();
|
|
|
|
|
// ExecuteProcess(
|
|
|
|
|
// "nant",
|
|
|
|
|
// "-buildfile:./Build/OpenTK.build -t:mono-2.0 " + (mode == BuildMode.Debug ? "build-debug" : "build-release"));
|
|
|
|
|
// CopyBinaries();
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
//case BuildTarget.Net:
|
|
|
|
|
// Console.WriteLine("Building OpenTK using .Net");
|
|
|
|
|
// ExecuteProcess(PrebuildPath, "/target nant /file " + PrebuildXml);
|
|
|
|
|
// Console.WriteLine();
|
|
|
|
|
// ExecuteProcess(
|
|
|
|
|
// "nant",
|
|
|
|
|
// "-buildfile:./Build/OpenTK.build -t:net-2.0 " + (mode == BuildMode.Debug ? "build-debug" : "build-release"));
|
|
|
|
|
// CopyBinaries();
|
|
|
|
|
// break;
|
2009-05-31 15:02:27 +00:00
|
|
|
|
|
|
|
|
|
case BuildTarget.VS2005:
|
|
|
|
|
Console.WriteLine("Creating VS2005 project files");
|
2009-08-25 14:36:19 +00:00
|
|
|
|
ExecutePrebuild("/target", "vs2008", "/file", bindings);
|
|
|
|
|
ExecutePrebuild("/target", "vs2005", "/file", opentk);
|
|
|
|
|
ExecutePrebuild("/target", "vs2005", "/file", quickstart);
|
2009-05-31 15:02:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
case BuildTarget.VS2008:
|
|
|
|
|
Console.WriteLine("Creating VS2008 project files");
|
|
|
|
|
ExecutePrebuild("/target", "vs2008", "/file", bindings);
|
|
|
|
|
ExecutePrebuild("/target", "vs2008", "/file", opentk);
|
|
|
|
|
ExecutePrebuild("/target", "vs2008", "/file", quickstart);
|
|
|
|
|
break;
|
|
|
|
|
|
2009-05-31 15:02:27 +00:00
|
|
|
|
case BuildTarget.Clean:
|
|
|
|
|
Console.WriteLine("Cleaning intermediate object files.");
|
2009-08-25 14:36:19 +00:00
|
|
|
|
ExecutePrebuild("/clean", "/yes", "/file", bindings);
|
|
|
|
|
ExecutePrebuild("/clean", "/yes", "/file", opentk);
|
|
|
|
|
ExecutePrebuild("/clean", "/yes", "/file", quickstart);
|
2009-05-31 15:02:27 +00:00
|
|
|
|
DeleteDirectories(RootPath, "obj");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BuildTarget.DistClean:
|
|
|
|
|
Console.WriteLine("Cleaning intermediate and final object files.");
|
2009-08-25 14:36:19 +00:00
|
|
|
|
ExecutePrebuild("/clean", "/yes", "/file", bindings);
|
|
|
|
|
ExecutePrebuild("/clean", "/yes", "/file", opentk);
|
|
|
|
|
ExecutePrebuild("/clean", "/yes", "/file", quickstart);
|
2009-05-31 15:02:27 +00:00
|
|
|
|
DeleteDirectories(RootPath, "obj");
|
|
|
|
|
DeleteDirectories(RootPath, "bin");
|
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
string binaries_path = Path.Combine(RootPath, "Binaries");
|
|
|
|
|
if (Directory.Exists(binaries_path))
|
|
|
|
|
Directory.Delete(binaries_path, true);
|
|
|
|
|
|
2009-05-31 15:02:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Console.WriteLine("Unknown target: {0}", target);
|
|
|
|
|
PrintUsage();
|
|
|
|
|
return;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
2009-05-31 15:02:27 +00:00
|
|
|
|
|
2009-08-25 14:36:19 +00:00
|
|
|
|
// Wait until Prebuild releases the input files.
|
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
File.Delete(bindings);
|
|
|
|
|
File.Delete(opentk);
|
|
|
|
|
File.Delete(quickstart);
|
|
|
|
|
|
|
|
|
|
if (Debugger.IsAttached)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Press any key to continue...");
|
|
|
|
|
Console.ReadKey(true);
|
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void DeleteDirectories(string root_path, string search)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Deleting {0} directories", search);
|
|
|
|
|
List<string> matches = new List<string>();
|
|
|
|
|
FindDirectories(root_path, search, matches);
|
|
|
|
|
foreach (string m in matches)
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(m, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void FindDirectories(string directory, string search, List<string> matches)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (string d in Directory.GetDirectories(directory))
|
|
|
|
|
{
|
|
|
|
|
foreach (string f in Directory.GetDirectories(d, search))
|
|
|
|
|
{
|
|
|
|
|
matches.Add(f);
|
|
|
|
|
}
|
|
|
|
|
FindDirectories(d, search, matches);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void FindFiles(string directory, string search, List<string> matches)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (string f in Directory.GetFiles(directory, search, SearchOption.AllDirectories))
|
|
|
|
|
{
|
|
|
|
|
matches.Add(f);
|
|
|
|
|
}
|
|
|
|
|
//FindFiles(d, search, matches);
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-25 14:36:19 +00:00
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
static void ExecuteProcess(string path, string args)
|
|
|
|
|
{
|
2009-05-31 15:02:27 +00:00
|
|
|
|
ProcessStartInfo sinfo = new ProcessStartInfo();
|
2009-02-22 10:43:35 +00:00
|
|
|
|
using (Process p = new Process())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Environment.OSVersion.Platform == PlatformID.Unix && !path.ToLower().Contains("nant"))
|
|
|
|
|
{
|
|
|
|
|
sinfo.FileName = "mono";
|
|
|
|
|
sinfo.Arguments = path + " " + args;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sinfo.FileName = path;
|
|
|
|
|
sinfo.Arguments = args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sinfo.WorkingDirectory = RootPath;
|
|
|
|
|
sinfo.CreateNoWindow = true;
|
|
|
|
|
sinfo.RedirectStandardOutput = true;
|
|
|
|
|
sinfo.UseShellExecute = false;
|
|
|
|
|
p.StartInfo = sinfo;
|
|
|
|
|
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
|
|
|
|
|
p.Start();
|
|
|
|
|
p.BeginOutputReadLine();
|
|
|
|
|
//StreamReader sr = p.StandardOutput;
|
|
|
|
|
//while (!p.HasExited)
|
|
|
|
|
//{
|
|
|
|
|
// Console.WriteLine(sr.ReadLine());
|
|
|
|
|
// Console.Out.Flush();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
p.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2009-05-31 15:02:27 +00:00
|
|
|
|
Console.WriteLine("Failed to execute process: {0}", sinfo.FileName);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(e.Data))
|
|
|
|
|
{
|
|
|
|
|
// Eat the last \n, we use WriteLine instead. This way we get the same result
|
|
|
|
|
// in both windows and linux (linux would interpret both \n and WriteLine).
|
|
|
|
|
Console.WriteLine(e.Data.TrimEnd('\n'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void FileCopy(string srcdir, string destdir, Regex match)
|
|
|
|
|
{
|
|
|
|
|
//DirectoryInfo dir;
|
|
|
|
|
//FileInfo[] files;
|
|
|
|
|
//DirectoryInfo[] dirs;
|
|
|
|
|
//string tmppath;
|
|
|
|
|
|
|
|
|
|
//determine if the destination directory exists, if not create it
|
|
|
|
|
if (!Directory.Exists(destdir))
|
|
|
|
|
Directory.CreateDirectory(destdir);
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(srcdir))
|
|
|
|
|
throw new ArgumentException("source dir doesn't exist -> " + srcdir);
|
|
|
|
|
|
|
|
|
|
string[] files = Directory.GetFiles(srcdir);
|
|
|
|
|
foreach (string f in files)
|
|
|
|
|
//if (Path.GetExtension(f).ToLower() == ext.ToLower())
|
|
|
|
|
if (match.IsMatch(Path.GetExtension(f)))
|
|
|
|
|
File.Copy(f, Path.Combine(destdir, Path.GetFileName(f)), true);
|
|
|
|
|
|
|
|
|
|
foreach (string dir in Directory.GetDirectories(srcdir))
|
|
|
|
|
{
|
|
|
|
|
string name = dir.Substring(dir.LastIndexOf(Path.DirectorySeparatorChar)+1);
|
|
|
|
|
if (!name.StartsWith("."))
|
|
|
|
|
FileCopy(dir, Path.Combine(destdir, name), match);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-25 14:36:19 +00:00
|
|
|
|
|
|
|
|
|
static void ExecutePrebuild(params string[] options)
|
|
|
|
|
{
|
|
|
|
|
Prebuild.EntryPoint.Invoke(null, new object[] { options });
|
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|