[mkbundle] Fix compiler warnings.
[mono.git] / mcs / tools / mkbundle / mkbundle.cs
index 3b3774c5725b08b9f6a15f4b0fb66fa01ac9ab64..dbf21c44beb0b90cc5fb273b8e9215601c27eae8 100755 (executable)
@@ -299,7 +299,7 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
 
                        // 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;
@@ -334,7 +334,7 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                        // 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 (".", "_");
 
@@ -467,15 +467,16 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
 
                        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 (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 + "\""; };
 
@@ -492,19 +493,20 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                                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));
@@ -514,13 +516,10 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                        }
                        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";
@@ -576,7 +575,7 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                                }
                        
                                assemblies.Add (a.CodeBase);
-                       } catch (Exception e) {
+                       } catch (Exception) {
                                if (skip_scan) {
                                        Console.WriteLine ("File will not be scanned: {0}", name);
                                        assemblies.Add (new Uri (new FileInfo (name).FullName).ToString ());
@@ -622,7 +621,7 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                                if (!QueueAssembly (files, a.CodeBase))
                                        return false;
                        }
-               } catch (Exception e) {
+               } catch (Exception) {
                        if (!skip_scan)
                                throw;
                }
@@ -745,7 +744,7 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
        static void Execute (string cmdLine)
        {
                if (IsUnix) {
-                       Console.WriteLine (cmdLine);
+                       Console.WriteLine ("[execute cmd]: " + cmdLine);
                        int ret = system (cmdLine);
                        if (ret != 0)
                        {
@@ -837,4 +836,15 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                }
                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);
+       }
 }