static string machine_config_file = null;
static string config_dir = null;
static string style = "linux";
+ static string os_message = "";
static bool compress;
static bool nomain;
static bool? use_dos2unix = null;
static bool skip_scan;
static string ctor_func;
+ static bool quiet;
static int Main (string [] args)
{
break;
case "--static":
static_link = true;
- Console.WriteLine ("Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking.");
- Console.WriteLine ("See http://www.mono-project.com/Licensing for details on licensing.");
+ if (!quiet) {
+ Console.WriteLine ("Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking.");
+ Console.WriteLine ("See http://www.mono-project.com/Licensing for details on licensing.");
+ }
break;
case "--config":
if (i+1 == top) {
machine_config_file = args [++i];
- Console.WriteLine ("WARNING:\n Check that the machine.config file you are bundling\n doesn't contain sensitive information specific to this machine.");
+ if (!quiet)
+ Console.WriteLine ("WARNING:\n Check that the machine.config file you are bundling\n doesn't contain sensitive information specific to this machine.");
break;
case "--config-dir":
if (i+1 == top) {
case "--dos2unix=false":
use_dos2unix = false;
break;
+ case "-q":
+ case "--quiet":
+ quiet = true;
+ break;
default:
sources.Add (args [i]);
break;
}
- Console.WriteLine ("Sources: {0} Auto-dependencies: {1}", sources.Count, autodeps);
+ if (!quiet) {
+ Console.WriteLine (os_message);
+ Console.WriteLine ("Sources: {0} Auto-dependencies: {1}", sources.Count, autodeps);
+ }
if (sources.Count == 0 || output == null) {
Help ();
Environment.Exit (1);
// Do the file reading and compression in parallel
Action<string> body = delegate (string url) {
- string fname = new Uri (url).LocalPath;
+ string fname = LocateFile (new Uri (url).LocalPath);
Stream stream = File.OpenRead (fname);
long real_size = stream.Length;
// The non-parallel part
byte [] buffer = new byte [8192];
foreach (var url in files) {
- string fname = new Uri (url).LocalPath;
+ string fname = LocateFile (new Uri (url).LocalPath);
string aname = Path.GetFileName (fname);
string encoded = aname.Replace ("-", "_").Replace (".", "_");
var stream = streams [url];
var real_size = sizes [url];
- Console.WriteLine (" embedding: " + fname);
+ if (!quiet)
+ Console.WriteLine (" embedding: " + fname);
WriteSymbol (ts, "assembly_data_" + encoded, stream.Length);
tc.WriteLine ("static CompressedAssembly assembly_bundle_{0} = {{{{\"{1}\"," +
" assembly_data_{0}, {2}}}, {3}}};",
encoded, aname, real_size, stream.Length);
- double ratio = ((double) stream.Length * 100) / real_size;
- Console.WriteLine (" compression ratio: {0:.00}%", ratio);
+ if (!quiet) {
+ double ratio = ((double) stream.Length * 100) / real_size;
+ Console.WriteLine (" compression ratio: {0:.00}%", ratio);
+ }
} else {
tc.WriteLine ("extern const unsigned char assembly_data_{0} [];", encoded);
tc.WriteLine ("static const MonoBundledAssembly assembly_bundle_{0} = {{\"{1}\", assembly_data_{0}, {2}}};",
try {
FileStream cf = File.OpenRead (fname + ".config");
- Console.WriteLine (" config from: " + fname + ".config");
+ if (!quiet)
+ Console.WriteLine (" config from: " + fname + ".config");
tc.WriteLine ("extern const unsigned char assembly_config_{0} [];", encoded);
WriteSymbol (ts, "assembly_config_" + encoded, cf.Length);
WriteBuffer (ts, cf, buffer);
Error (String.Format ("Failure to open {0}", config_file));
return;
}
- Console.WriteLine ("System config from: " + config_file);
+ if (!quiet)
+ Console.WriteLine ("System config from: " + config_file);
tc.WriteLine ("extern const char system_config;");
WriteSymbol (ts, "system_config", config_file.Length);
Error (String.Format ("Failure to open {0}", machine_config_file));
return;
}
- Console.WriteLine ("Machine config from: " + machine_config_file);
+ if (!quiet)
+ Console.WriteLine ("Machine config from: " + machine_config_file);
tc.WriteLine ("extern const char machine_config;");
WriteSymbol (ts, "machine_config", machine_config_file.Length);
tc.Close ();
+ string assembler = GetEnv("AS", "as");
+ string as_cmd = String.Format("{0} -o {1} {2} ", assembler, temp_o, temp_s);
+ Execute(as_cmd);
+
if (compile_only)
return;
- Console.WriteLine("Compiling:");
+
+ if (!quiet)
+ Console.WriteLine("Compiling:");
if (style == "windows")
{
- string assembler = GetEnv("AS", "as");
- string as_cmd = String.Format("{0} -o {1} {2} ", assembler, temp_o, temp_s);
- Execute(as_cmd);
Func<string, string> quote = (pp) => { return "\"" + pp + "\""; };
foreach (string include in includes)
compilerArgs.Add(String.Format ("/I {0}", quote (include)));
- if (static_link) {
- compilerArgs.Add("/MT");
- monoFile = monoPath + @"\lib\mono-2.0.lib";
- }
- else {
- compilerArgs.Add("/MD");
- monoFile = monoPath + @"\lib\mono-2.0.dll";
- }
+ if (static_link)
+ monoFile = LocateFile (monoPath + @"\lib\monosgen-2.0.lib");
+ else
+ monoFile = LocateFile (monoPath + @"\lib\monosgen-2.0.dll");
+ compilerArgs.Add("/MD");
compilerArgs.Add(temp_c);
compilerArgs.Add(temp_o);
compilerArgs.Add("/link");
+ if (nomain)
+ compilerArgs.Add("/NOENTRY");
+ compilerArgs.Add("/DLL");
+
foreach (string lib in libs)
compilerArgs.Add(String.Format ("/LIBPATH:{0}", quote(lib)));
compilerArgs.Add (quote(monoFile));
}
else
{
- string assembler = GetEnv("AS", "as");
- string cmd = String.Format("{0} -o {1} {2} ", assembler, temp_o, temp_s);
- Execute(cmd);
-
string zlib = (compress ? "-lz" : "");
string debugging = "-g";
string cc = GetEnv("CC", "cc");
+ string cmd = null;
if (style == "linux")
debugging = "-ggdb";
Execute (cmd);
}
- Console.WriteLine ("Done");
+ if (!quiet)
+ Console.WriteLine ("Done");
}
}
} finally {
}
assemblies.Add (a.CodeBase);
- } catch (Exception e) {
+ } catch (Exception) {
if (skip_scan) {
- Console.WriteLine ("File will not be scanned: {0}", name);
+ if (!quiet)
+ Console.WriteLine ("File will not be scanned: {0}", name);
assemblies.Add (new Uri (new FileInfo (name).FullName).ToString ());
} else {
throw;
if (!QueueAssembly (files, a.CodeBase))
return false;
}
- } catch (Exception e) {
+ } catch (Exception) {
if (!skip_scan)
throw;
}
}
}
Error ("Cannot find assembly `" + assembly + "'" );
- Console.WriteLine ("Log: \n" + total_log);
+ if (!quiet)
+ Console.WriteLine ("Log: \n" + total_log);
} catch (IKVM.Reflection.BadImageFormatException f) {
if (skip_scan)
throw;
static void DetectOS ()
{
if (!IsUnix) {
- Console.WriteLine ("OS is: Windows");
+ os_message = "OS is: Windows";
style = "windows";
return;
}
IntPtr buf = Marshal.AllocHGlobal (8192);
if (uname (buf) != 0){
- Console.WriteLine ("Warning: Unable to detect OS");
+ os_message = "Warning: Unable to detect OS";
Marshal.FreeHGlobal (buf);
return;
}
string os = Marshal.PtrToStringAnsi (buf);
- Console.WriteLine ("OS is: " + os);
+ os_message = "OS is: " + os;
if (os == "Darwin")
style = "osx";
static void Execute (string cmdLine)
{
if (IsUnix) {
- Console.WriteLine (cmdLine);
+ if (!quiet)
+ Console.WriteLine ("[execute cmd]: " + cmdLine);
int ret = system (cmdLine);
if (ret != 0)
{
Error(String.Format("[Fail] {0}", ret));
}
+ return;
}
// on Windows, we have to pipe the output of a
psi.Arguments = String.Format("-c \"{0}\"", cmdLine);
}
- Console.WriteLine(cmdLine);
+ if (!quiet)
+ Console.WriteLine(cmdLine);
using (Process p = Process.Start (psi)) {
p.WaitForExit ();
int ret = p.ExitCode;
string val = Environment.GetEnvironmentVariable(name);
if (val != null)
{
- Console.WriteLine("{0} = {1}", name, val);
+ if (!quiet)
+ Console.WriteLine("{0} = {1}", name, val);
}
else
{
val = defaultValue;
- Console.WriteLine("{0} = {1} (default)", name, val);
+ if (!quiet)
+ Console.WriteLine("{0} = {1} (default)", name, val);
}
return val;
}
+
+ static string LocateFile(string default_path)
+ {
+ var override_path = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(default_path));
+ if (File.Exists(override_path))
+ return override_path;
+ else if (File.Exists(default_path))
+ return default_path;
+ else
+ throw new FileNotFoundException(default_path);
+ }
}