ide; ear/extract: (#937) Not calling UPX for 64 bit Windows executables (not supported)
[sdk] / ide / src / project / Project.ec
old mode 100755 (executable)
new mode 100644 (file)
index 9fdfb87..e93ba87
@@ -46,6 +46,7 @@ IDESettingsContainer settingsContainer
 #ifndef MAKEFILE_GENERATOR
       globalSettingsDialog.ideSettings = settings;
       ide.UpdateRecentMenus();
+      ide.UpdateCompilerConfigs(true);
 #endif
    }
 };
@@ -373,15 +374,48 @@ define PEEK_RESOLUTION = (18.2 * 10);
 #define SEPS    "/"
 #define SEP     '/'
 
+static Array<String> notLinkerOptions
+{ [
+   "-static-libgcc",
+   "-shared",
+   "-static",
+   "-s",
+   "-shared-libgcc",
+   "-nostartfiles",
+   "-nodefaultlibs",
+   "-nostdlib",
+   "-pie",
+   "-rdynamic",
+   "-static-libasan",
+   "-static-libtsan",
+   "-static libstdc++",
+   "-symbolic",
+   "-Wl,"
+   //"-T ",
+   //"-Xlinker ",
+   //"-u "
+] };
+
+static bool IsLinkerOption(String s)
+{
+   for(i : notLinkerOptions)
+      if(strstr(s, "-Wl,") || !strcmp(s, i))
+         return false;
+   return true;
+}
+
 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
 
-enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
+enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources, rcSources };
 
 define WorkspaceExtension = "ews";
 define ProjectExtension = "epj";
 
 define stringInFileIncludedFrom = "In file included from ";
+define stringFrom =               "                 from ";
 
+// This function cannot accept same pointer for source and output
+// todo: rename ReplaceSpaces to EscapeSpaceAndSpecialChars or something
 void ReplaceSpaces(char * output, char * source)
 {
    int c, dc;
@@ -390,6 +424,8 @@ void ReplaceSpaces(char * output, char * source)
    for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
    {
       if(ch == ' ') output[dc++] = '\\';
+      if(ch == '\"') output[dc++] = '\\';
+      if(ch == '&') output[dc++] = '\\';
       if(pch != '$')
       {
          if(ch == '(' || ch == ')') output[dc++] = '\\';
@@ -402,37 +438,81 @@ void ReplaceSpaces(char * output, char * source)
    output[dc] = '\0';
 }
 
-void ReplaceUnwantedMakeChars(char * output, char * source)
-{
-   int c, dc;
-   char ch, pch = 0;
+// chars refused for project name: windowsFileNameCharsNotAllowed + " &,."
 
-   for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
+//define gnuMakeCharsNeedEscaping = "$%";
+
+//define windowsFileNameCharsNotAllowed = "*/:<>?\\\"|";
+//define linuxFileNameCharsNotAllowed = "/";
+
+//define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
+//define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
+
+// NOTES: - this function should get only unescaped unix style paths
+//        - paths with literal $(somestring) in them are not supported
+//          my_$(messed_up)_path would likely become my__path
+void EscapeForMake(char * output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
+{
+   char ch, *i = input, *o = output;
+   bool inVar = false;
+#ifdef _DEBUG
+   int len = strlen(input);
+   if(len && ((input[0] == '"' && input[len-1] == '"') || strchr(input, '\\') || strchr(input, 127) || (!allowDblQuote && strchr(input, '"'))))
+      PrintLn("Invalid input for EscapeForMake! -- ", input);
+#endif
+   while((ch = *i++))
    {
-      if(pch != '$')
+      if(ch == '(')
       {
-         if(ch == '(' || ch == ')') output[dc++] = '\\';
-         pch = ch;
+         if(i-1 != input && *(i-2) == '$' && allowVars)
+            inVar = true;
+         else
+            *o++ = '\\';
       }
       else if(ch == ')')
-         pch = 0;
+      {
+         if(inVar == true && allowVars)
+            inVar = false;
+         else
+            *o++ = '\\';
+      }
+      else if(ch == '$' && *i != '(')
+         *o++ = '$';
+      else if(ch == '&')
+         *o++ = '\\';
+      else if(ch == '"')
+         *o++ = '\\';
       if(ch == ' ')
-         output[dc] = 127;
+      {
+         if(hideSpace)
+            *o++ = 127;
+         else
+         {
+            *o++ = '\\';
+            *o++ = ch;
+         }
+      }
       else
-         output[dc] = ch;
+         *o++ = ch;
    }
-   output[dc] = '\0';
+   *o = '\0';
 }
 
-static void OutputNoSpace(File f, char * source)
+void EscapeForMakeToFile(File output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
 {
-   char * output = new char[strlen(source)+1024];
-   ReplaceSpaces(output, source);
-   f.Puts(output);
-   delete output;
+   char * buf = new char[strlen(input)*2+1];
+   EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
+   output.Print(buf);
+   delete buf;
 }
 
-enum ListOutputMethod { inPlace, newLine, lineEach };
+void EscapeForMakeToDynString(DynamicString output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
+{
+   char * buf = new char[strlen(input)*2+1];
+   EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
+   output.concat(buf);
+   delete buf;
+}
 
 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
 {
@@ -524,6 +604,18 @@ int OutputFileList(File f, char * name, Array<String> list, Map<String, int> var
    return numOfBreaks;
 }
 
+void OutputLinkObjectActions(File f, char * name, int parts)
+{
+   if(parts > 1)
+   {
+      int c;
+      for(c=0; c<parts; c++)
+         f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
+   } else if(parts) {
+      f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
+   }
+}
+
 void OutputCleanActions(File f, char * name, int parts)
 {
    if(parts > 1)
@@ -536,33 +628,35 @@ void OutputCleanActions(File f, char * name, int parts)
       f.Printf("\t$(call rmq,$(%s))\n", name);
 }
 
-void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
+enum LineOutputMethod { inPlace, newLine, lineEach };
+enum StringOutputMethod { asIs, escape, escapePath};
+
+enum ToolchainFlag { any, _D, _I, _isystem, _Wl, _L/*, _Wl-rpath*/ };
+String flagNames[ToolchainFlag] = { "", "-D", "-I", "-isystem ", "-Wl,", "-Wl,--library-path="/*, "-Wl,-rpath "*/ };
+void OutputFlags(File f, ToolchainFlag flag, Array<String> list, LineOutputMethod lineMethod)
 {
    if(list.count)
    {
-      if(method == newLine)
+      if(lineMethod == newLine)
          f.Puts(" \\\n\t");
       for(item : list)
       {
-         if(method == lineEach)
+         if(lineMethod == lineEach)
             f.Puts(" \\\n\t");
-         f.Printf(" -%s", option);
-         if(noSpace)
-            OutputNoSpace(f, item);
+         f.Printf(" %s", flagNames[flag]);
+         if(flag != _D && flag != _Wl && flag != any)
+         {
+            char * tmp = new char[strlen(item)*2+1];
+            EscapeForMake(tmp, item, false, true, false);
+            f.Printf("$(call quote_path,%s)", tmp);
+            delete tmp;
+         }
          else
-            f.Printf("%s", item);
+            EscapeForMakeToFile(f, item, false, true, true);
       }
    }
 }
 
-void StringNoSpaceToDynamicString(DynamicString s, char * path)
-{
-   char * output = new char[strlen(path)+1024];
-   ReplaceSpaces(output, path);
-   s.concat(output);
-   delete output;
-}
-
 static void OutputLibraries(File f, Array<String> libraries)
 {
    for(item : libraries)
@@ -588,7 +682,7 @@ static void OutputLibraries(File f, Array<String> libraries)
          f.Puts(" \\\n\t$(call _L,");
          usedFunction = true;
       }
-      OutputNoSpace(f, s);
+      EscapeForMakeToFile(f, s, false, false, false);
       if(usedFunction)
          f.Puts(")");
    }
@@ -696,6 +790,13 @@ char * GetConfigName(ProjectConfig config)
    return config ? config.name : "Common";
 }
 
+public enum SingleFileCompileMode
+{
+   normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
+
+   property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
+};
+
 class Project : struct
 {
    class_no_expansion;  // To use Find on the Container<Project> in Workspace::projects
@@ -705,6 +806,34 @@ public:
    float version;
    String moduleName;
 
+   property char * moduleVersion
+   {
+      set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
+      get { return moduleVersion ? moduleVersion : ""; }                                     //       version number should only use digits and dots
+      isset { return moduleVersion != null && moduleVersion[0]; }                            //       add leading/trailing 0 if value start/ends with dot(s)
+   }
+
+   property char * description
+   {
+      set { delete description; if(value && value[0]) description = CopyString(value); }
+      get { return description ? description : ""; }
+      isset { return description != null && description[0]; }
+   }
+
+   property char * license
+   {
+      set { delete license; if(value && value[0]) license = CopyString(value); }
+      get { return license ? license : ""; }
+      isset { return license != null && license[0]; }
+   }
+
+   property char * compilerConfigsDir
+   {
+      set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
+      get { return compilerConfigsDir ? compilerConfigsDir : ""; }
+      isset { return compilerConfigsDir && compilerConfigsDir[0]; }
+   }
+
    property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
    property Array<PlatformOptions> platforms
    {
@@ -740,27 +869,6 @@ public:
    String resourcesPath;
    LinkList<ProjectNode> resources;
 
-   property char * description
-   {
-      set { delete description; if(value && value[0]) description = CopyString(value); }
-      get { return description ? description : ""; }
-      isset { return description != null && description[0]; }
-   }
-
-   property char * license
-   {
-      set { delete license; if(value && value[0]) license = CopyString(value); }
-      get { return license ? license : ""; }
-      isset { return license != null && license[0]; }
-   }
-
-   property char * compilerConfigsDir
-   {
-      set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
-      get { return compilerConfigsDir ? compilerConfigsDir : ""; }
-      isset { return compilerConfigsDir && compilerConfigsDir[0]; }
-   }
-
 private:
    // topNode.name holds the file name (.epj)
    ProjectOptions options;
@@ -777,6 +885,13 @@ private:
    String description;
    String license;
    String compilerConfigsDir;
+   String moduleVersion;
+
+   String lastBuildConfigName;
+   String lastBuildCompilerName;
+
+   Map<String, NameCollisionInfo> lastBuildNamesInfo;
+
 #ifndef MAKEFILE_GENERATOR
    FileMonitor fileMonitor
    {
@@ -811,32 +926,47 @@ private:
       if(MessageBox { type = yesNo, master = ide,
             text = $"Project has been modified", contents = temp }.Modal() == yes)
       {
-         Project project = LoadProject(filePath, config.name);
+         Project project = LoadProject(filePath, config ? config.name : null);
          if(project)
          {
             ProjectView projectView = ide.projectView;
             DataRow prev = topNode.row ? topNode.row.previous : null;
             FileMonitor fm = fileMonitor;
-
-            if(projectView) projectView.DeleteNode(topNode);
-
-            *this = *project;
-            delete fileMonitor;
-            fileMonitor = fm;
-            topNode.project = this;
+            bool confirmation = true;
 
             if(projectView)
             {
-               CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
-               projectView.AddNode(topNode, null);
-               topNode.row.Move(prev);
+               if(projectView.projectSettingsDialog)
+               {
+                  confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
+                  if(confirmation)
+                     projectView.projectSettingsDialog.Destroy(0);
+               }
+               if(confirmation)
+                  projectView.DeleteNode(topNode);
+            }
+            if(confirmation)
+            {
+               *this = *project;
+               delete fileMonitor;
+               fileMonitor = fm;
+               topNode.project = this;
 
-               projectView.ShowOutputBuildLog(true);
-               projectView.DisplayCompiler(compiler, false);
-               projectView.ProjectUpdateMakefileForAllConfigs(this);
-               delete compiler;
+               if(projectView)
+               {
+                  CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
+                  projectView.AddNode(topNode, null);
+                  topNode.row.Move(prev);
+
+                  projectView.ShowOutputBuildLog(true);
+                  projectView.DisplayCompiler(compiler, false);
+                  projectView.ProjectUpdateMakefileForAllConfigs(this);
+                  delete compiler;
+               }
+               eSystem_Delete(project);
             }
-            eSystem_Delete(project);
+            else
+               delete project;
          }
          return true;
       }
@@ -861,9 +991,13 @@ private:
       delete license;
       delete compilerConfigsDir;
       delete moduleName;
+      delete moduleVersion;
       delete filePath;
       delete topNode;
       delete name;
+      delete lastBuildConfigName;
+      delete lastBuildCompilerName;
+      if(lastBuildNamesInfo) { lastBuildNamesInfo.Free(); delete lastBuildNamesInfo; }
    }
 
    ~Project()
@@ -885,6 +1019,7 @@ private:
          topNode.info = CopyString(GetConfigName(config));
       }
    }
+
    property char * filePath
    {
       set
@@ -907,6 +1042,29 @@ private:
       }
    }
 
+   ProjectConfig GetConfig(char * configName)
+   {
+      ProjectConfig result = null;
+      if(configName && configName[0] && configurations.count)
+      {
+         for(cfg : configurations; !strcmpi(cfg.name, configName))
+         {
+            result = cfg;
+            break;
+         }
+      }
+      return result;
+   }
+
+   ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
+   {
+      ProjectNode result;
+      if(!lastBuildNamesInfo)
+         ProjectLoadLastBuildNamesInfo(this, config);
+      result = topNode.FindByObjectFileName(fileName, type, dotMain, lastBuildNamesInfo);
+      return result;
+   }
+
    TargetTypes GetTargetType(ProjectConfig config)
    {
       TargetTypes targetType = localTargetType;
@@ -926,7 +1084,6 @@ private:
       return false;
    }
 
-
    char * GetObjDirExpression(ProjectConfig config)
    {
       // TODO: Support platform options
@@ -936,11 +1093,11 @@ private:
       return expression;
    }
 
-   DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
+   DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
    {
       char * expression = GetObjDirExpression(config);
       DirExpression objDir { type = intermediateObjectsDir };
-      objDir.Evaluate(expression, this, compiler, config);
+      objDir.Evaluate(expression, this, compiler, config, bitDepth);
       return objDir;
    }
 
@@ -953,11 +1110,11 @@ private:
       return expression;
    }
 
-   DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
+   DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
    {
       char * expression = GetTargetDirExpression(config);
       DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
-      targetDir.Evaluate(expression, this, compiler, config);
+      targetDir.Evaluate(expression, this, compiler, config, bitDepth);
       return targetDir;
    }
 
@@ -1050,10 +1207,10 @@ private:
 #endif
    }
 
-   void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
+   void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
    {
 #ifndef MAKEFILE_GENERATOR
-      ide.SetPath(projectsDirs, compiler, config);
+      ide.SetPath(projectsDirs, compiler, config, bitDepth);
 #endif
    }
 
@@ -1111,6 +1268,7 @@ private:
             DirExpression objDirExp;
             CompilerConfig compiler = ide.debugger.currentCompiler;
             ProjectConfig config = ide.debugger.prjConfig;
+            int bitDepth = ide.debugger.bitDepth;
             // This is not perfect, as multiple source files exist for the symbol loader module...
             // We try to set it in the debug config object directory.
             if(!compiler || !config)
@@ -1128,12 +1286,11 @@ private:
                   }
                }
             }
-            objDirExp = GetObjDir(compiler, config);
+            objDirExp = GetObjDir(compiler, config, bitDepth);
             strcpy(objDir, objDirExp.dir);
             delete objDirExp;
             ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
-            ReplaceSpaces(objDir, objDir);
-            strcpy(relativePath, objDir);
+            ReplaceSpaces(relativePath, objDir);
             *sl = '.';
             PathCatSlash(relativePath, moduleName);
             return true;
@@ -1174,6 +1331,11 @@ private:
                strcat(string, ".dylib");
             else
                strcat(string, ".so");
+            if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
+            {
+               strcat(string, ".");
+               strcat(string, moduleVersion);
+            }
             break;
          case staticLibrary:
             strcat(string, ".a");
@@ -1216,7 +1378,7 @@ private:
       char temp[MAX_LOCATION];
       bool result = false;
       strcpy(cfDir, topNode.path);
-      if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
+      if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
       {
          PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
          result = true;
@@ -1264,6 +1426,10 @@ private:
          if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
                (!c.options || !cfg.options)))
             cfg.symbolGenModified = true;
+         if(c && ((c.options && cfg.options && 
+               ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) ) 
+            || (!c.options || !cfg.options)))
+            cfg.linkingModified = true;
 
          cfg.makingModified = true;
       }
@@ -1310,15 +1476,16 @@ private:
          }
 
          property::config = cfg.data;
+         ide.UpdateToolBarActiveConfigs(true);
          ide.workspace.modified = true;
          ide.projectView.Update(null);
       }
    }
 
-   void ProcessPipeOutputRaw(DualPipe f)
+   bool ProcessPipeOutputRaw(DualPipe f)
    {
       char line[65536];
-      while(!f.Eof() && !ide.ShouldStopBuild())
+      while(!f.Eof() && !ide.projectView.stopBuild)
       {
          bool result = true;
          double lastTime = GetTime();
@@ -1342,62 +1509,78 @@ private:
          }
          //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
       }
-      if(ide.ShouldStopBuild())
+      if(ide.projectView.stopBuild)
       {
          ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
          f.Terminate();
       }
+      return !ide.projectView.stopBuild;
    }
 
-   bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
-      CompilerConfig compiler, ProjectConfig config)
+   bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
+      CompilerConfig compiler, ProjectConfig config, int bitDepth)
    {
       char line[65536];
       bool compiling = false, linking = false, precompiling = false;
       int compilingEC = 0;
       int numErrors = 0, numWarnings = 0;
       bool loggedALine = false;
-      char * configName = config ? config.name : "Common";
       int lenMakeCommand = strlen(compiler.makeCommand);
+      int testLen = 0;
+      char * t;
+      char moduleName[MAX_FILENAME];
+      char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
+
+      DynamicString test { };
+      DynamicString ecp { };
+      DynamicString ecc { };
+      DynamicString ecs { };
+      DynamicString ear { };
+      DynamicString prefix { };
+      DynamicString cpp { };
+      DynamicString cc { };
+      DynamicString cxx { };
+      DynamicString strip { };
+      DynamicString ar { };
+      DynamicString windres { };
+      /*
+      if(bitDepth == 64 && compiler.targetPlatform == win32) 
+         gnuToolchainPrefix = "x86_64-w64-mingw32-";
+      else if(bitDepth == 32 && compiler.targetPlatform == win32)
+         gnuToolchainPrefix = "i686-w64-mingw32-";
+      */
+      ecp.concatx(compiler.ecpCommand, " ");
+      ecc.concatx(compiler.eccCommand, " ");
+      ecs.concatx(compiler.ecsCommand, " ");
+      ear.concatx(compiler.earCommand, " ");
 
-      char cppCommand[MAX_LOCATION];
-      char ccCommand[MAX_LOCATION];
-      char cxxCommand[MAX_LOCATION];
-      char stripCommand[MAX_LOCATION];
-      char ecpCommand[MAX_LOCATION];
-      char eccCommand[MAX_LOCATION];
-      char ecsCommand[MAX_LOCATION];
-      char earCommand[MAX_LOCATION];
-
-      char * cc = compiler.ccCommand;
-      char * cxx = compiler.cxxCommand;
-      char * cpp = compiler.cppCommand;
-      char * strip = compiler.cppCommand;
-      sprintf(cppCommand, "%s%s%s%s ",
-            compiler.ccacheEnabled ? "ccache " : "",
-            compiler.distccEnabled ? "distcc " : "",
-            compiler.gccPrefix ? compiler.gccPrefix : "",
-            compiler.cppCommand);
-      sprintf(ccCommand, "%s%s%s%s ",
-            compiler.ccacheEnabled ? "ccache " : "",
-            compiler.distccEnabled ? "distcc " : "",
-            compiler.gccPrefix ? compiler.gccPrefix : "",
-            compiler.ccCommand);
-      sprintf(cxxCommand, "%s%s%s%s ",
+      prefix.concatx(
             compiler.ccacheEnabled ? "ccache " : "",
             compiler.distccEnabled ? "distcc " : "",
-            compiler.gccPrefix ? compiler.gccPrefix : "",
-            compiler.cxxCommand);
-
-      sprintf(stripCommand, "%sstrip ",
-            compiler.gccPrefix ? compiler.gccPrefix : "");
-
-      sprintf(ecpCommand, "%s ", compiler.ecpCommand);
-      sprintf(eccCommand, "%s ", compiler.eccCommand);
-      sprintf(ecsCommand, "%s ", compiler.ecsCommand);
-      sprintf(earCommand, "%s ", compiler.earCommand);
-
-      while(!f.Eof() && !ide.ShouldStopBuild())
+            gnuToolchainPrefix);
+
+      cpp.concatx((String)prefix, compiler.cppCommand, " ");
+      cc.concatx((String)prefix, compiler.ccCommand,  " ");
+      cxx.concatx((String)prefix, compiler.cxxCommand, " ");
+
+      strip.concatx(gnuToolchainPrefix, "strip ");
+      ar.concatx(gnuToolchainPrefix, "ar rcs");
+      windres.concatx(gnuToolchainPrefix, "windres ");
+
+      testLen = Max(testLen, ecp.size);
+      testLen = Max(testLen, ecc.size);
+      testLen = Max(testLen, ecs.size);
+      testLen = Max(testLen, ear.size);
+      testLen = Max(testLen, cpp.size);
+      testLen = Max(testLen, cc.size);
+      testLen = Max(testLen, cxx.size);
+      testLen = Max(testLen, strip.size);
+      testLen = Max(testLen, ar.size);
+      testLen = Max(testLen, windres.size);
+      testLen = Max(testLen, strlen("mkdir "));
+      testLen++;
+
+      while(!f.Eof() && !ide.projectView.stopBuild)
       {
          bool result = true;
          double lastTime = GetTime();
@@ -1405,9 +1588,12 @@ private:
          while(result)
          {
             //printf("Peeking and GetLine...\n");
-            if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
+            if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
             {
+               char * message = null;
                char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
+               char * from = strstr(line, stringFrom);
+               test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
                if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
                {
                   char * module = strstr(line, "No rule to make target `");
@@ -1430,41 +1616,46 @@ private:
                      //numErrors++;
                   //}
                }
-               else if(strstr(line, "ear ") == line);
-               else if(strstr(line, stripCommand) == line);
-               else if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
+               else if(strstr(test, "mkdir ") == test);
+               else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
+               else if(strstr(test, ear) == test);
+               else if(strstr(test, strip) == test);
+               else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
                {
-                  char moduleName[MAX_FILENAME];
-                  byte * tokens[1];
                   char * module;
                   bool isPrecomp = false;
+                  bool gotCC = false;
 
-                  if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line)
+                  if(strstr(test, cc) == test || strstr(test, cxx) == test)
                   {
                      module = strstr(line, " -c ");
                      if(module) module += 4;
+                     gotCC = true;
                   }
-                  else if(strstr(line, eccCommand) == line)
+                  else if(strstr(test, ecc) == test)
                   {
                      module = strstr(line, " -c ");
                      if(module) module += 4;
                      //module = line + 3;
                      // Don't show GCC warnings about generated C code because it does not compile clean yet...
                      compilingEC = 3;//2;
+                     gotCC = true;
                   }
-                  else if(strstr(line, ecpCommand) == line)
+                  else if(strstr(test, ecp) == test)
                   {
                      // module = line + 8;
                      module = strstr(line, " -c ");
                      if(module) module += 4;
                      isPrecomp = true;
                      compilingEC = 0;
+                     gotCC = true;
                   }
 
                   loggedALine = true;
 
                   if(module)
                   {
+                     byte * tokens[1];
                      if(!compiling && !isPrecomp)
                      {
                         ide.outputView.buildBox.Logf($"Compiling...\n");
@@ -1476,7 +1667,7 @@ private:
                         precompiling = true;
                      }
                      // Changed escapeBackSlashes here to handle paths with spaces
-                     Tokenize(module, 1, tokens, true); // false);
+                     Tokenize(module, 1, tokens, (BackSlashEscaping)true); // fix #139
                      GetLastDirectory(module, moduleName);
                      ide.outputView.buildBox.Logf("%s\n", moduleName);
                   }
@@ -1490,29 +1681,47 @@ private:
                   else
                   {
                      ide.outputView.buildBox.Logf("%s\n", line);
-                     numErrors++;
+                     if(strstr(line, "warning:") || strstr(line, "note:"))
+                        numWarnings++;
+                     else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
+                        numErrors++;
                   }
 
                   if(compilingEC) compilingEC--;
                }
-               else if(strstr(line, "ar rcs") == line)
+               else if(strstr(test, windres) == test)
+               {
+                  char * module;
+                  module = strstr(line, " ");
+                  if(module) module++;
+                  if(module)
+                  {
+                     byte * tokens[1];
+                     Tokenize(module, 1, tokens, (BackSlashEscaping)true); // fix #139
+                     GetLastDirectory(module, moduleName);
+                     ide.outputView.buildBox.Logf("%s\n", moduleName);
+                  }
+               }
+               else if(strstr(test, ar) == test)
                   ide.outputView.buildBox.Logf($"Building library...\n");
-               else if(strstr(line, ecsCommand) == line)
+               else if(strstr(test, ecs) == test)
                   ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
                else
                {
                   if(linking || compiling || precompiling)
                   {
-                     char * colon = strstr(line, ":"); //, * bracket;
+                     char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
+                     char * colon = strstr(start, ":"); //, * bracket;
                      if(colon && (colon[1] == '/' || colon[1] == '\\'))
                         colon = strstr(colon + 1, ":");
                      if(colon)
                      {
+                        char * sayError = "";
                         char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
                         char * pointer;
                         char * error;
-                        char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
                         int len = (int)(colon - start);
+                        char ext[MAX_EXTENSION];
                         len = Min(len, MAX_LOCATION-1);
                         // Don't be mistaken by the drive letter colon
                         // Cut module name
@@ -1529,10 +1738,52 @@ private:
                         //if(bracket) *bracket = '\0';
 
                         GetLastDirectory(moduleName, temp);
+                        GetExtension(temp, ext);
+
+                        if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
+                        {
+                           char * cColon = strstr(colon+1, ":");
+                           if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
+                              cColon = strstr(cColon + 1, ":");
+                           if(cColon)
+                           {
+                              int len = (int)(cColon - (colon+1));
+                              char mName[MAX_LOCATION];
+                              len = Min(len, MAX_LOCATION-1);
+                              strncpy(mName, colon+1, len);
+                              mName[len] = '\0';
+                              GetLastDirectory(mName, temp);
+                              GetExtension(temp, ext);
+                              if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
+                              {
+                                 colon = cColon;
+                                 strcpy(moduleName, mName);
+                              }
+                           }
+                        }
                         if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
                         {
-                           numErrors++;
-                           strcpy(moduleName, $"Linker Error");
+                           moduleName[0] = 0;
+                           if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
+                           {
+                              message = $"Linker Message: ";
+                              colon = line;
+                           }
+                           else
+                           {
+                              numErrors++;
+                              message = $"Linker Error";
+                           }
+                        }
+                        else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
+                        {
+                           moduleName[0] = 0;
+                           colon = line;
+                           if(!strstr(line, "error:"))
+                           {
+                              message = $"Linker Error: ";
+                              numErrors++;
+                           }
                         }
                         else
                         {
@@ -1540,31 +1791,33 @@ private:
                            PathCatSlash(temp, moduleName);
                            MakePathRelative(temp, topNode.path, moduleName);
                         }
-                        if(strstr(line, "error:"))
-                           numErrors ++;
+                        error = strstr(line, "error:");
+                        if(!message && error && error > colon)
+                           numErrors++;
                         else
                         {
-                           // Silence warnings for compiled EC
+                           // Silence warnings for compiled eC
                            char * objDir = strstr(moduleName, objDirExp.dir);
                         
                            if(linking)
                            {
                               if((pointer = strstr(line, "undefined"))  ||
+                                   (pointer = strstr(line, "multiple definition")) ||
                                    (pointer = strstr(line, "No such file")) ||
                                    (pointer = strstr(line, "token")))
                               {
                                  strncat(moduleName, colon, pointer - colon);
-                                 strcat(moduleName, "error: ");
+                                 sayError = "error: ";
                                  colon = pointer;
-                                 numErrors ++;
+                                 numErrors++;
                               }
                            }
                            else if((pointer = strstr(line, "No such file")))
                            {
                               strncat(moduleName, colon, pointer - colon);
-                              strcat(moduleName, "error: ");
+                              sayError = "error: ";
                               colon = pointer;
-                              numErrors ++;
+                              numErrors++;
                            }
                            else if(compilingEC == 1 || (objDir && objDir == moduleName))
                               continue;
@@ -1573,16 +1826,88 @@ private:
                               numWarnings++;
                            }
                         }
-                        if(this == ide.workspace.projects.firstIterator.data)
-                           ide.outputView.buildBox.Logf("   %s%s\n", moduleName, colon);
+                        if(message)
+                           ide.outputView.buildBox.Logf("   %s%s\n", message, colon);
+                        /*else if(this == ide.workspace.projects.firstIterator.data)
+                           ide.outputView.buildBox.Logf("   %s%s%s\n", moduleName, sayError, colon);*/
                         else
                         {
                            char fullModuleName[MAX_LOCATION];
-                           strcpy(fullModuleName, topNode.path);
-                           PathCat(fullModuleName, moduleName);
-                           MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
-                           MakeSystemPath(fullModuleName);
-                           ide.outputView.buildBox.Logf("   %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
+                           FileAttribs found = 0;
+                           Project foundProject = this;
+                           if(moduleName[0])
+                           {
+                              char * loc = strstr(moduleName, ":");
+                              if(loc) *loc = 0;
+                              strcpy(fullModuleName, topNode.path);
+                              PathCat(fullModuleName, moduleName);
+                              found = FileExists(fullModuleName);
+                              if(!found && !strcmp(ext, "c"))
+                              {
+                                 char ecName[MAX_LOCATION];
+                                 ChangeExtension(fullModuleName, "ec", ecName);
+                                 found = FileExists(ecName);
+                              }
+                              if(!found)
+                              {
+                                 char path[MAX_LOCATION];
+                                 if(ide && ide.workspace)
+                                 {
+                                    for(prj : ide.workspace.projects)
+                                    {
+                                       ProjectNode node;
+                                       MakePathRelative(fullModuleName, prj.topNode.path, path);
+
+                                       if((node = prj.topNode.FindWithPath(path, false)))
+                                       {
+                                          strcpy(fullModuleName, prj.topNode.path);
+                                          PathCatSlash(fullModuleName, node.path);
+                                          PathCatSlash(fullModuleName, node.name);
+                                          found = FileExists(fullModuleName);
+                                          if(found)
+                                          {
+                                             foundProject = prj;
+                                             break;
+                                          }
+                                       }
+                                    }
+                                    if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
+                                    {
+                                       for(prj : ide.workspace.projects)
+                                       {
+                                          ProjectNode node;
+                                          if((node = prj.topNode.Find(moduleName, false)))
+                                          {
+                                             strcpy(fullModuleName, prj.topNode.path);
+                                             PathCatSlash(fullModuleName, node.path);
+                                             PathCatSlash(fullModuleName, node.name);
+                                             found = FileExists(fullModuleName);
+                                             if(found)
+                                             {
+                                                foundProject = prj;
+                                                break;
+                                             }
+                                          }
+                                       }
+                                    }
+                                 }
+                              }
+                              if(found)
+                              {
+                                 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
+                                 MakeSystemPath(fullModuleName);
+                              }
+                              else
+                                 strcpy(fullModuleName, moduleName);
+                              if(loc)
+                              {
+                                 strcat(fullModuleName, ":");
+                                 strcat(fullModuleName, loc + 1);
+                              }
+                           }
+                           else
+                              fullModuleName[0] = 0;
+                           ide.outputView.buildBox.Logf("   %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
                         }
                      }
                      else
@@ -1610,7 +1935,7 @@ private:
          }
          //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
       }
-      if(ide.ShouldStopBuild())
+      if(ide.projectView.stopBuild)
       {
          ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
          f.Terminate();
@@ -1624,8 +1949,13 @@ private:
          }
          else
          {
-            if(!onlyNode)
-               ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
+            if(!onlyNodes)
+            {
+               char targetFileName[MAX_LOCATION];
+               targetFileName[0] = '\0';
+               CatTargetFileName(targetFileName, compiler, config);
+               ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
+            }
             if(numErrors)
                ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
             else
@@ -1637,7 +1967,20 @@ private:
                ide.outputView.buildBox.Logf($"no warning\n");
          }
       }
-      return numErrors == 0;
+
+      delete test;
+      delete ecp;
+      delete ecc;
+      delete ecs;
+      delete ear;
+      delete prefix;
+      delete cpp;
+      delete cc;
+      delete cxx;
+      delete strip;
+      delete ar;
+
+      return numErrors == 0 && !ide.projectView.stopBuild;
    }
 
    void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
@@ -1651,9 +1994,10 @@ private:
          double lastTime = GetTime();
          while(result)
          {
-            if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
+            if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
             {
                if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
+               else if(strstr(line, "mkdir") == line);
                else if(strstr(line, "del") == line);
                else if(strstr(line, "rm") == line);
                else if(strstr(line, "Could Not Find") == line);
@@ -1675,30 +2019,37 @@ private:
       }
    }
 
-   bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
+   bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
    {
       bool result = false;
       DualPipe f;
       char targetFileName[MAX_LOCATION] = "";
-      char makeTarget[MAX_LOCATION] = "";
+      DynamicString makeTargets { };
       char makeFile[MAX_LOCATION];
       char makeFilePath[MAX_LOCATION];
       char configName[MAX_LOCATION];
-      DirExpression objDirExp = GetObjDir(compiler, config);
+      DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
       PathBackup pathBackup { };
       bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
       char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
 
+      bool eC_Debug = mode.eC_ToolsDebug;
+      bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
       int numJobs = compiler.numJobs;
-      char command[MAX_LOCATION];
-      char * compilerName;
+      char command[MAX_F_STRING*4];
+      char * compilerName = CopyString(compiler.name);
+
+      delete lastBuildConfigName;
+      lastBuildConfigName = CopyString(config ? config.name : "Common");
+      delete lastBuildCompilerName;
+      lastBuildCompilerName = CopyString(compiler.name);
+      ProjectLoadLastBuildNamesInfo(this, config);
 
-      compilerName = CopyString(compiler.name);
       CamelCase(compilerName);
 
       strcpy(configName, config ? config.name : "Common");
 
-      SetPath(false, compiler, config); //true
+      SetPath(false, compiler, config, bitDepth); //true
       CatTargetFileName(targetFileName, compiler, config);
 
       strcpy(makeFilePath, topNode.path);
@@ -1706,7 +2057,7 @@ private:
       PathCatSlash(makeFilePath, makeFile);
 
       // TODO: TEST ON UNIX IF \" around makeTarget is ok
-      if(onlyNode)
+      if(onlyNodes)
       {
          if(compiler.type.isVC)
          {
@@ -1723,27 +2074,32 @@ private:
             // Create object dir if it does not exist already
             if(!FileExists(objDirExp.dir).isDirectory)
             {
-               sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s objdir -C \"%s\" -f \"%s\"",
+               sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
                      compiler.makeCommand, cfDir,
-                     crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
-                     compilerName, topNode.path, makeFilePath);
-#ifdef _DEBUG
-               PrintLn(command);
-               ide.outputView.buildBox.Logf("command: %s\n", command);
-#endif
+                     crossCompiling ? " TARGET_PLATFORM=" : "",
+                     targetPlatform,
+                     bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
+                     /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
+
+                     compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
+               if(justPrint)
+                  ide.outputView.buildBox.Logf("%s\n", command);
                Execute(command);
             }
 
             ChangeWorkingDir(pushD);
 
-            PathCatSlash(makeTarget+1, objDirExp.dir);
-            PathCatSlash(makeTarget+1, onlyNode.name);
-            StripExtension(makeTarget+1);
-            strcat(makeTarget+1, ".o");
-            makeTarget[0] = '\"';
-            len = strlen(makeTarget);
-            makeTarget[len++] = '\"';
-            makeTarget[len++] = '\0';
+            for(node : onlyNodes)
+            {
+               if(node.GetIsExcluded(config))
+                  ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
+               else
+               {
+                  if(!eC_Debug)
+                     node.DeleteIntermediateFiles(compiler, config, bitDepth, lastBuildNamesInfo, mode == cObject ? true : false);
+                  node.GetTargets(config, lastBuildNamesInfo, objDirExp.dir, makeTargets);
+               }
+            }
          }
       }
 
@@ -1754,12 +2110,10 @@ private:
          GetWorkingDir(oldwd, sizeof(oldwd));
          ChangeWorkingDir(topNode.path);
 
+         // TODO: support justPrint
          sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
-         ide.outputView.buildBox.Logf("command: %s\n", command);
-#ifdef _DEBUG
-         PrintLn(command);
-         ide.outputView.buildBox.Logf("command: %s\n", command);
-#endif
+         if(justPrint)
+            ide.outputView.buildBox.Logf("%s\n", command);
          if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
          {
             ProcessPipeOutputRaw(f);
@@ -1768,42 +2122,88 @@ private:
          }
          ChangeWorkingDir(oldwd);
       }
+      else if(onlyNodes && strlen(makeTargets) == 0)
+      {
+         ide.outputView.buildBox.Log("No targets to compile.\n");
+      }
       else
       {
          char cfDir[MAX_LOCATION];
          GetIDECompilerConfigsDir(cfDir, true, true);
-         sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"",
-               compiler.makeCommand, cfDir,
-               crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
-               compilerName, numJobs,
-               compiler.ccacheEnabled ? "CCACHE=y " : "",
-               compiler.distccEnabled ? "DISTCC=y " : "",
-               makeTarget, topNode.path, makeFilePath);
-#ifdef _DEBUG
-         PrintLn(command);
-         ide.outputView.buildBox.Logf("command: %s\n", command);
-#endif
+         sprintf(command, "%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
+               compiler.makeCommand,
+               mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
+               cfDir,
+               crossCompiling ? " TARGET_PLATFORM=" : "",
+               targetPlatform,
+               bitDepth ? " ARCH=" : "",
+               bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
+               /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
+               compilerName, eC_Debug ? "--always-make " : "", numJobs,
+               (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
+               (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
+               (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
+         if(justPrint)
+            ide.outputView.buildBox.Logf("%s\n", command);
+
          if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
          {
-            result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
+            bool found = false;
+            bool error = false;
+            if(eC_Debug)
+            {
+               char line[65536];
+               if(justPrint)
+                  ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
+               while(!f.Eof())
+               {
+                  bool result = true;
+                  while(result)
+                  {
+                     if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
+                     {
+                        if(justPrint)
+                           ide.outputView.buildBox.Logf("%s\n", line);
+                        if(!error && !found && strstr(line, "echo ") == line)
+                        {
+                           strcpy(command, line+5);
+                           error = true;
+                        }
+                        if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
+                        {
+                           strcpy(command, line);
+                           found = true;
+                        }
+                     }
+                  }
+               }
+               if(found)
+                  result = true;
+            }
+            else if(justPrint)
+               result = ProcessPipeOutputRaw(f);
+            else
+               result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config, bitDepth);
             delete f;
+            if(error)
+               ide.outputView.buildBox.Logf("%s\n", command);
+            else if(justPrint && found)
+               ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
+            else if(found)
+               Execute(command);
          }
          else
-         {
             ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
-#ifndef _DEBUG
-            ide.outputView.buildBox.Logf("command: %s\n", command);
-#endif
-         }
       }
 
       delete pathBackup;
       delete objDirExp;
       delete compilerName;
+      delete makeTargets;
       return result;
    }
 
-   void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
+   void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
    {
       char makeFile[MAX_LOCATION];
       char makeFilePath[MAX_LOCATION];
@@ -1817,7 +2217,7 @@ private:
       compilerName = CopyString(compiler.name);
       CamelCase(compilerName);
 
-      SetPath(false, compiler, config);
+      SetPath(false, compiler, config, bitDepth);
 
       strcpy(makeFilePath, topNode.path);
       CatMakeFileName(makeFile, config);
@@ -1830,12 +2230,10 @@ private:
          GetWorkingDir(oldwd, sizeof(oldwd));
          ChangeWorkingDir(topNode.path);
          
+         // TODO: justPrint support
          sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
-         ide.outputView.buildBox.Logf("command: %s\n", command);
-#ifdef _DEBUG
-         PrintLn(command);
-         ide.outputView.buildBox.Logf("command: %s\n", command);
-#endif
+         if(justPrint)
+            ide.outputView.buildBox.Logf("%s\n", command);
          if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
          {
             ProcessPipeOutputRaw(f);
@@ -1849,21 +2247,28 @@ private:
       {
          char cfDir[MAX_LOCATION];
          GetIDECompilerConfigsDir(cfDir, true, true);
-         sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"",
+         sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
                compiler.makeCommand, cfDir,
                crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
-               compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
-#ifdef _DEBUG
-         PrintLn(command);
-         ide.outputView.buildBox.Logf("command: %s\n", command);
-#endif
+               bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
+               compilerName,
+               cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
+               topNode.path, justPrint ? " -n": "", makeFilePath);
+         if(justPrint)
+            ide.outputView.buildBox.Logf("%s\n", command);
          if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
          {
-            ide.outputView.buildBox.Tell($"Deleting target and object files...");
-            ProcessCleanPipeOutput(f, compiler, config);
+            ide.outputView.buildBox.Tellf($"Deleting %s%s...",
+                  cleanType == realClean ? $"intermediate objects directory" : $"target",
+                  cleanType == clean ? $" and object files" : "");
+            if(justPrint)
+               ProcessPipeOutputRaw(f);
+            else
+               ProcessCleanPipeOutput(f, compiler, config);
+            ide.outputView.buildBox.Logf($"%s%s deleted\n",
+                  cleanType == realClean ? $"Intermediate objects directory" : $"Target",
+                  cleanType == clean ? $" and object files" : "");
             delete f;
-
-            ide.outputView.buildBox.Logf($"Target and object files deleted\n");
          }
       }
 
@@ -1871,20 +2276,17 @@ private:
       delete compilerName;
    }
 
-   void Run(char * args, CompilerConfig compiler, ProjectConfig config)
+   void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
    {   
       String target = new char[maxPathLen];
       char oldDirectory[MAX_LOCATION];
-      DirExpression targetDirExp = GetTargetDir(compiler, config);
+      char * executableLauncher = compiler.executableLauncher;
+      DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
       PathBackup pathBackup { };
 
-      // Build(project, ideMain, true, null);
+      // Build(project, ideMain, true, null, false);
 
-   #if defined(__WIN32__)
       strcpy(target, topNode.path);
-   #else
-      strcpy(target, "");
-   #endif
       PathCatSlash(target, targetDirExp.dir);
       CatTargetFileName(target, compiler, config);
       sprintf(target, "%s %s", target, args);
@@ -1900,12 +2302,12 @@ private:
       else
          ChangeWorkingDir(topNode.path);
       // ChangeWorkingDir(topNode.path);
-      SetPath(true, compiler, config);
-      if(compiler.execPrefixCommand)
+      SetPath(true, compiler, config, bitDepth);
+      if(executableLauncher)
       {
-         char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
+         char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 2];
          prefixedTarget[0] = '\0';
-         strcat(prefixedTarget, compiler.execPrefixCommand);
+         strcat(prefixedTarget, executableLauncher);
          strcat(prefixedTarget, " ");
          strcat(prefixedTarget, target);
          Execute(prefixedTarget);
@@ -1921,9 +2323,9 @@ private:
       delete target;
    }
 
-   void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
+   bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
    {
-      Build(false, node, compiler, config);
+      return Build(false, nodes, compiler, config, bitDepth, justPrint, mode);
    }
 #endif
 
@@ -1932,8 +2334,6 @@ private:
       fileName[0] = '\0';
       if(targetType == staticLibrary || targetType == sharedLibrary)
          strcat(fileName, "$(LP)");
-      // !!! ReplaceSpaces must be done after all PathCat calls !!!
-      // ReplaceSpaces(s, GetTargetFileName(config));
       strcat(fileName, GetTargetFileName(config));
       switch(targetType)
       {
@@ -1941,7 +2341,7 @@ private:
             strcat(fileName, "$(E)");
             break;
          case sharedLibrary:
-            strcat(fileName, "$(SO)");
+            strcat(fileName, "$(SO)$(VER)");
             break;
          case staticLibrary:
             strcat(fileName, "$(A)");
@@ -1949,7 +2349,7 @@ private:
       }
    }
 
-   bool GenerateCrossPlatformMk()
+   bool GenerateCrossPlatformMk(File altCrossPlatformMk)
    {
       bool result = false;
       char path[MAX_LOCATION];
@@ -1972,12 +2372,13 @@ private:
       if(FileExists(path))
          DeleteFile(path);
       {
-         File include = FileOpen(":crossplatform.mk", read);
+         File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
          if(include)
          {
             File f = FileOpen(path, write);
             if(f)
             {
+               include.Seek(0, start);
                for(; !include.Eof(); )
                {
                   char buffer[4096];
@@ -1988,7 +2389,8 @@ private:
 
                result = true;
             }
-            delete include;
+            if(!altCrossPlatformMk)
+               delete include;
          }
       }
       return result;
@@ -2001,6 +2403,7 @@ private:
       char * name;
       char * compilerName;
       bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
+      char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
       Platform platform = compiler.targetPlatform;
 
       compilerName = CopyString(compiler.name);
@@ -2028,18 +2431,30 @@ private:
          File f = FileOpen(path, write);
          if(f)
          {
+            if(compiler.environmentVars && compiler.environmentVars.count)
+            {
+               f.Puts("# ENVIRONMENT VARIABLES\n");
+               f.Puts("\n");
+               for(e : compiler.environmentVars)
+               {
+                  f.Printf("export %s := %s\n", e.name, e.string);
+               }
+               f.Puts("\n");
+            }
+
             f.Puts("# TOOLCHAIN\n");
             f.Puts("\n");
 
-            if(compiler.gccPrefix && compiler.gccPrefix[0])
+            if(gnuToolchainPrefix && gnuToolchainPrefix[0])
             {
-               f.Printf("GCC_PREFIX := %s\n", compiler.gccPrefix);
+               f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
                f.Puts("\n");
             }
             if(compiler.sysroot && compiler.sysroot[0])
             {
                f.Printf("SYSROOT := %s\n", compiler.sysroot);
-               f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
+               // Moved this to crossplatform.mk
+               //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
                f.Puts("\n");
             }
 
@@ -2047,34 +2462,47 @@ private:
             f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
             f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
             f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
-            f.Printf("ECP := %s\n", compiler.ecpCommand);
-            f.Printf("ECC := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
-            f.Printf("ECS := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.ecsCommand);
+            f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
+            f.Printf("ECC := $(if $(ECC_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecc/ecc.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
+            f.Printf("ECS := $(if $(ECS_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecs/ecs.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)\n", compiler.ecsCommand);
             f.Printf("EAR := %s\n", compiler.earCommand);
 
             f.Puts("AS := $(GCC_PREFIX)as\n");
             f.Puts("LD := $(GCC_PREFIX)ld\n");
             f.Puts("AR := $(GCC_PREFIX)ar\n");
             f.Puts("STRIP := $(GCC_PREFIX)strip\n");
+            f.Puts("ifdef WINDOWS_TARGET\n");
+            f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
+            f.Puts(" ifdef ARCH\n");
+            f.Puts("  ifeq \"$(ARCH)\" \"x32\"\n");
+            f.Puts("WINDRES_FLAGS := -F pe-i386\n");
+            f.Puts("  else\n");
+            f.Puts("   ifeq \"$(ARCH)\" \"x64\"\n");
+            f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
+            f.Puts("   endif\n");
+            f.Puts("  endif\n");
+            f.Puts(" endif\n");
+            f.Puts("endif\n");
             f.Puts("UPX := upx\n");
             f.Puts("\n");
 
-            if(compiler.environmentVars && compiler.environmentVars.count)
-            {
-               f.Puts("# ENVIRONMENT VARIABLES\n");
-               f.Puts("\n");
-               for(e : compiler.environmentVars)
-               {
-                  f.Printf("export %s := %s\n", e.name, e.string);
-               }
-            }
-
             f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
             f.Puts("\n");
 
-            f.Puts("EARFLAGS = aw\n");
+            f.Puts("EARFLAGS = \n");
             f.Puts("\n");
 
+            f.Puts("ifndef ARCH\n");
+            f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
+            f.Puts(" ifdef WINDOWS_HOST\n");
+            f.Puts("  ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
+            f.Puts("     TARGET_ARCH := x86_64\n");
+            f.Puts("  else\n");
+            f.Puts("     TARGET_ARCH := i386\n");
+            f.Puts("  endif\n");
+            f.Puts(" endif\n");
+            f.Puts("endif\n\n");
+
             f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
             f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
             f.Puts("\n");
@@ -2090,21 +2518,21 @@ private:
             if(compiler.includeDirs && compiler.includeDirs.count)
             {
                f.Puts("\nCFLAGS +=");
-               OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
+               OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
                f.Puts("\n");
             }
             if(compiler.prepDirectives && compiler.prepDirectives.count)
             {
                f.Puts("\nCFLAGS +=");
-               OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
+               OutputFlags(f, _D, compiler.prepDirectives, inPlace);
                f.Puts("\n");
             }
             if(compiler.libraryDirs && compiler.libraryDirs.count)
             {
                f.Puts("\nLDFLAGS +=");
-               OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
+               OutputFlags(f, _L, compiler.libraryDirs, lineEach);
                // We would need a bool option to know whether we want to add to rpath as well...
-               // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
+               // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
                f.Puts("\n");
             }
             if(compiler.excludeLibs && compiler.excludeLibs.count)
@@ -2116,17 +2544,25 @@ private:
                   f.Puts(l);
                }
             }
+            if(compiler.compilerFlags && compiler.compilerFlags.count)
+            {
+               f.Puts("\nCFLAGS +=");
+               OutputFlags(f, any, compiler.compilerFlags, inPlace);
+               f.Puts("\n");
+            }
             if(compiler.linkerFlags && compiler.linkerFlags.count)
             {
                f.Puts("\nLDFLAGS +=");
-               OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
+               OutputFlags(f, _Wl, compiler.linkerFlags, inPlace);
                f.Puts("\n");
             }
-            f.Printf("\nFORCE_64_BIT := %s", compiler.supportsBitDepth ? "-m64" : "");
-            f.Printf("\nFORCE_32_BIT := %s", compiler.supportsBitDepth ? "-m32" : "");
             f.Puts("\n");
             f.Puts("\nOFLAGS += $(LDFLAGS)");
             f.Puts("\n");
+            f.Puts("ifdef ARCH_FLAGS\n");
+            f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
+            f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
+            f.Puts("endif\n");
 
             delete f;
 
@@ -2173,27 +2609,30 @@ private:
          char fixedModuleName[MAX_FILENAME];
          char fixedConfigName[MAX_FILENAME];
          int c, len;
+         int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
          // Non-zero if we're building eC code
          // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
          int numCObjects = 0;
          int numObjects = 0;
+         int numRCObjects = 0;
          bool containsCXX = false; // True if the project contains a C++ file
-         bool sameObjTargetDirs;
+         bool relObjDir, sameOrRelObjTargetDirs;
          String objDirExp = GetObjDirExpression(config);
          TargetTypes targetType = GetTargetType(config);
 
          char cfDir[MAX_LOCATION];
-         int objectsParts = 0, eCsourcesParts = 0;
+         int objectsParts = 0;
+         int eCsourcesParts = 0;
+         int rcSourcesParts = 0;
          Array<String> listItems { };
          Map<String, int> varStringLenDiffs { };
          Map<String, NameCollisionInfo> namesInfo { };
-         bool forceBitDepth = false;
 
          Map<String, int> cflagsVariations { };
-         Map<int, int> nodeCFlagsMapping { };
+         Map<intptr, int> nodeCFlagsMapping { };
 
          Map<String, int> ecflagsVariations { };
-         Map<int, int> nodeECFlagsMapping { };
+         Map<intptr, int> nodeECFlagsMapping { };
 
          ReplaceSpaces(objDirNoSpaces, objDirExp);
          strcpy(targetDir, GetTargetDirExpression(config));
@@ -2201,20 +2640,30 @@ private:
 
          strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
          ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
-         ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
+         {
+            char temp[MAX_LOCATION];
+            ReplaceSpaces(temp, objDirExpNoSpaces);
+            strcpy(objDirExpNoSpaces, temp);
+         }
          ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
          ReplaceSpaces(fixedModuleName, moduleName);
          ReplaceSpaces(fixedConfigName, GetConfigName(config));
          CamelCase(fixedConfigName);
 
-         sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
+         lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
+         relObjDir = lenObjDirExpNoSpaces == 0 ||
+               (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
+         lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
+         sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
+               (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
+               !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
 
-         f.Printf(".PHONY: all objdir%s clean realclean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
+         f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
 
          f.Puts("# CORE VARIABLES\n\n");
 
          f.Printf("MODULE := %s\n", fixedModuleName);
-         //f.Printf("VERSION = %s\n", version);
+         f.Printf("VERSION := %s\n", property::moduleVersion);
          f.Printf("CONFIG := %s\n", fixedConfigName);
          f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
          f.Puts("\n");
@@ -2304,7 +2753,7 @@ private:
          // test = GetTargetTypeIsSetByPlatform(config);
          {
             char target[MAX_LOCATION];
-            char targetNoSpaces[MAX_LOCATION];
+            char temp[MAX_LOCATION];
             if(test)
             {
                TargetTypes type;
@@ -2319,19 +2768,19 @@ private:
                      f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
 
                      GetMakefileTargetFileName(type, target, config);
-                     strcpy(targetNoSpaces, targetDir);
-                     PathCatSlash(targetNoSpaces, target);
-                     ReplaceSpaces(targetNoSpaces, targetNoSpaces);
-                     f.Printf("TARGET = %s\n", targetNoSpaces);
+                     strcpy(temp, targetDir);
+                     PathCatSlash(temp, target);
+                     ReplaceSpaces(target, temp);
+                     f.Printf("TARGET = %s\n", target);
                   }
                }
                f.Puts("else\n");
             }
             GetMakefileTargetFileName(targetType, target, config);
-            strcpy(targetNoSpaces, targetDir);
-            PathCatSlash(targetNoSpaces, target);
-            ReplaceSpaces(targetNoSpaces, targetNoSpaces);
-            f.Printf("TARGET = %s\n", targetNoSpaces);
+            strcpy(temp, targetDir);
+            PathCatSlash(temp, target);
+            ReplaceSpaces(target, temp);
+            f.Printf("TARGET = %s\n", target);
 
             if(test)
             {
@@ -2386,14 +2835,60 @@ private:
             }
          }
 
+         numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
+         if(numRCObjects)
+         {
+            f.Puts("ifdef WINDOWS_TARGET\n\n");
+
+            rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
+
+            f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
+            if(rcSourcesParts > 1)
+            {
+               for(c = 1; c <= rcSourcesParts; c++)
+                  f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
+            }
+            f.Puts("\n");
+            if(rcSourcesParts > 1)
+            {
+               int n;
+               f.Printf("%s =", "RCOBJECTS");
+               for(n = 1; n <= rcSourcesParts; n++)
+                  f.Printf(" $(%s%d)", "RCOBJECTS", n);
+               f.Puts("\n");
+               for(n = 1; n <= rcSourcesParts; n++)
+                  f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
+            }
+            else if(rcSourcesParts == 1)
+               f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
+            f.Puts("\n");
+
+            f.Puts("else\n");
+            f.Puts("RCSOURCES =\n");
+            f.Puts("RCOBJECTS =\n");
+            f.Puts("endif\n\n");
+         }
+
          numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
          if(numObjects)
             objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
-         f.Printf("OBJECTS =%s%s%s\n", numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "", numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "");
+         f.Printf("OBJECTS =%s%s%s%s\n",
+               numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
+               numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
+               numRCObjects ? " $(RCOBJECTS)" : "");
          f.Puts("\n");
 
          topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
-         OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, numCObjects ? "$(ECSOURCES)" : null);
+         {
+            char * prefix;
+            if(numCObjects && numRCObjects)
+               prefix = "$(ECSOURCES) $(RCSOURCES)";
+            else if(numCObjects)
+               prefix = "$(ECSOURCES)";
+            else
+               prefix = null;
+            OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
+         }
 
          if(!noResources)
             resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
@@ -2442,22 +2937,67 @@ private:
                   f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
                   f.Puts("\n");
 
+                  if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
+                     (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
+                  {
+                     f.Puts("CFLAGS +=");
+                     if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
+                     {
+                        f.Puts(" \\\n\t ");
+                        for(s : projectPlatformOptions.options.compilerOptions)
+                           f.Printf(" %s", s);
+                     }
+                     if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
+                     {
+                        f.Puts(" \\\n\t ");
+                        for(s : configPlatformOptions.options.compilerOptions)
+                           f.Printf(" %s", s);
+                     }
+                     f.Puts("\n");
+                     f.Puts("\n");
+                  }
+
                   if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
                      (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
                   {
-                     f.Puts("PRJ_CFLAGS +=");
-                     // tocheck: does any of that -Wl stuff from linkerOptions have any business being in CFLAGS?
+                     f.Puts("OFLAGS +=");
                      if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
                      {
-                        f.Puts(" \\\n\t -Wl");
+                        bool needWl = false;
+                        f.Puts(" \\\n\t ");
                         for(s : projectPlatformOptions.options.linkerOptions)
-                           f.Printf(",%s", s);
+                        {
+                           if(!IsLinkerOption(s))
+                              f.Printf(" %s", s);
+                           else
+                              needWl = true;
+                        }
+                        if(needWl)
+                        {
+                           f.Puts(" -Wl");
+                           for(s : projectPlatformOptions.options.linkerOptions)
+                              if(IsLinkerOption(s))
+                                 f.Printf(",%s", s);
+                        }
                      }
                      if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
                      {
-                        f.Puts(" \\\n\t -Wl");
+                        bool needWl = false;
+                        f.Puts(" \\\n\t ");
                         for(s : configPlatformOptions.options.linkerOptions)
-                           f.Printf(",%s", s);
+                        {
+                           if(IsLinkerOption(s))
+                              f.Printf(" %s", s);
+                           else
+                              needWl = true;
+                        }
+                        if(needWl)
+                        {
+                           f.Puts(" -Wl");
+                           for(s : configPlatformOptions.options.linkerOptions)
+                              if(!IsLinkerOption(s))
+                                 f.Printf(",%s", s);
+                        }
                      }
                      f.Puts("\n");
                      f.Puts("\n");
@@ -2474,13 +3014,13 @@ private:
                      {
                         f.Puts("OFLAGS +=");
                         if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
-                           OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
+                           OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
                         if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
-                           OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
+                           OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
                         f.Puts("\n");
                      }
 
-                     if((configPlatformOptions && configPlatformOptions.options.libraries))
+                     if(configPlatformOptions && configPlatformOptions.options.libraries)
                      {
                         if(configPlatformOptions.options.libraries.count)
                         {
@@ -2511,45 +3051,104 @@ private:
             f.Puts("\n");
          }
 
-         // tocheck: does any of that -Wl stuff from linkerOptions have any business being in CFLAGS?
-         if(options && options.linkerOptions && options.linkerOptions.count)
+         if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
+               (options && options.compilerOptions && options.compilerOptions.count))
          {
-            f.Puts("PRJ_CFLAGS +=");
-            f.Puts(" \\\n\t -Wl");
-            for(s : options.linkerOptions)
-               f.Printf(",%s", s);
+            f.Puts("CFLAGS +=");
+            f.Puts(" \\\n\t");
+
+            if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
+            {
+               for(s : config.options.compilerOptions)
+                  f.Printf(" %s", s);
+            }
+            if(options && options.compilerOptions && options.compilerOptions.count)
+            {
+               for(s : options.compilerOptions)
+                  f.Printf(" %s", s);
+            }
+            f.Puts("\n");
+            f.Puts("\n");
+         }
+
+         if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
+               (options && options.linkerOptions && options.linkerOptions.count))
+         {
+            f.Puts("OFLAGS +=");
+            f.Puts(" \\\n\t");
+
+            if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
+            {
+               bool needWl = false;
+               for(s : config.options.linkerOptions)
+               {
+                  if(!IsLinkerOption(s))
+                     f.Printf(" %s", s);
+                  else
+                     needWl = true;
+               }
+               if(needWl)
+               {
+                  f.Puts(" -Wl");
+                  for(s : config.options.linkerOptions)
+                     if(IsLinkerOption(s))
+                        f.Printf(",%s", s);
+               }
+            }
+            if(options && options.linkerOptions && options.linkerOptions.count)
+            {
+               bool needWl = false;
+               for(s : options.linkerOptions)
+               {
+                  if(!IsLinkerOption(s))
+                     f.Printf(" %s", s);
+                  else
+                     needWl = true;
+               }
+               if(needWl)
+               {
+                  f.Puts(" -Wl");
+                  for(s : options.linkerOptions)
+                     if(IsLinkerOption(s))
+                        f.Printf(",%s", s);
+               }
+            }
+            f.Puts("\n");
+            f.Puts("\n");
          }
-         f.Puts("\n");
-         f.Puts("\n");
 
          f.Puts("CECFLAGS += -cpp $(_CPP)");
          f.Puts("\n");
          f.Puts("\n");
 
-         f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
-         f.Puts("OFLAGS +=");
-         forceBitDepth = (options && options.buildBitDepth) || numCObjects;
-         if(forceBitDepth)
-            f.Puts((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " $(FORCE_32_BIT)" : " $(FORCE_64_BIT) \\\n");
-
          if(GetProfile(config))
-            f.Puts(" -pg");
-         if(config && config.options && config.options.libraryDirs)
-            OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
-         if(options && options.libraryDirs)
-            OutputListOption(f, "L", options.libraryDirs, lineEach, true);
-         f.Puts("\n");
-         f.Puts("endif\n");
-         f.Puts("\n");
+            f.Puts("OFLAGS += -pg\n\n");
+
+         if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
+         {
+            f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
+            f.Puts("OFLAGS +=");
+            if(config && config.options && config.options.libraryDirs)
+               OutputFlags(f, _L, config.options.libraryDirs, lineEach);
+            if(options && options.libraryDirs)
+               OutputFlags(f, _L, options.libraryDirs, lineEach);
+            f.Puts("\n");
+            f.Puts("endif\n");
+            f.Puts("\n");
+         }
 
          f.Puts("# TARGETS\n");
          f.Puts("\n");
 
-         f.Printf("all: objdir%s $(TARGET)\n", sameObjTargetDirs ? "" : " targetdir");
+         f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
          f.Puts("\n");
 
          f.Puts("objdir:\n");
+         if(!relObjDir)
             f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
+
+            f.Puts("\t$(if $(ECERE_SDK_SRC),$(if $(wildcard $(call escspace,$(ECERE_SDK_SRC)/crossplatform.mk)),,@$(call echo,Ecere SDK Source Warning: The value of ECERE_SDK_SRC is pointing to an incorrect ($(ECERE_SDK_SRC)) location.)),)\n");
+            f.Puts("\t$(if $(ECERE_SDK_SRC),,$(if $(ECP_DEBUG)$(ECC_DEBUG)$(ECS_DEBUG),@$(call echo,ECC Debug Warning: Please define ECERE_SDK_SRC before using ECP_DEBUG, ECC_DEBUG or ECS_DEBUG),))\n");
          //f.Puts("# PRE-BUILD COMMANDS\n");
          if(options && options.prebuildCommands)
          {
@@ -2599,7 +3198,7 @@ private:
          }
          f.Puts("\n");
 
-         if(!sameObjTargetDirs)
+         if(!sameOrRelObjTargetDirs)
          {
             f.Puts("targetdir:\n");
                f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
@@ -2611,32 +3210,49 @@ private:
             // Main Module (Linking) for ECERE C modules
             f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
             // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
-            f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n", 
+            f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $@\n",
                GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
             f.Puts("\n");
             // Main Module (Linking) for ECERE C modules
             f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
-            f.Puts("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(PRJ_CFLAGS)"
+            f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
                   " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
-            f.Puts("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
-                  " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n");
+            f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
+                  " -c $(OBJ)$(MODULE).main.ec -o $@ -symbols $(OBJ)\n");
             f.Puts("\n");
          }
 
          // *** Target ***
 
          // This would not rebuild the target on updated objects
-         // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
+         // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
 
          // This should fix it for good!
          f.Puts("$(SYMBOLS): | objdir\n");
          f.Puts("$(OBJECTS): | objdir\n");
 
          // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
-         f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
+         f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
+               rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
+
+         f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
+         f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
+         OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
+         if(rcSourcesParts)
+         {
+            f.Puts("ifdef WINDOWS_TARGET\n");
+            OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
+            f.Puts("endif\n");
+         }
+         if(numCObjects)
+         {
+            f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
+            OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
+         }
 
          f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
-         f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
+
+         f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
          if(!GetDebug(config))
          {
             f.Puts("ifndef NOSTRIP\n");
@@ -2650,14 +3266,25 @@ private:
                   f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
                f.Puts("endif\n");
                f.Puts("else\n");
+               f.Puts("ifneq \"$(TARGET_ARCH)\" \"x86_64\"");
                   f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
                f.Puts("endif\n");
+               f.Puts("endif\n");
             }
          }
          if(resNode.files && resNode.files.count && !noResources)
             resNode.GenMakefileAddResources(f, resNode.path, config);
          f.Puts("else\n");
-         f.Puts("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
+         f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
+         f.Puts("endif\n");
+         f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
+         f.Puts("ifdef LINUX_TARGET\n");
+         f.Puts("ifdef LINUX_HOST\n");
+         // TODO?: support symlinks for longer version numbers
+         f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
+         f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
+         f.Puts("endif\n");
+         f.Puts("endif\n");
          f.Puts("endif\n");
 
          //f.Puts("# POST-BUILD COMMANDS\n");
@@ -2711,41 +3338,48 @@ private:
 
          f.Puts("# SYMBOL RULES\n");
          f.Puts("\n");
-         {
-            Map<Platform, bool> excludedPlatforms { };
-            topNode.GenMakefilePrintSymbolRules(f, this, config, excludedPlatforms,
-                  nodeCFlagsMapping, nodeECFlagsMapping);
-            delete excludedPlatforms;
-         }
+
+         topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
 
          f.Puts("# C OBJECT RULES\n");
          f.Puts("\n");
-         {
-            Map<Platform, bool> excludedPlatforms { };
-            topNode.GenMakefilePrintCObjectRules(f, this, config, excludedPlatforms,
-                  nodeCFlagsMapping, nodeECFlagsMapping);
-            delete excludedPlatforms;
-         }
+
+         topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
 
          f.Puts("# OBJECT RULES\n");
          f.Puts("\n");
          // todo call this still but only generate rules whith specific options
          // see we-have-file-specific-options in ProjectNode.ec
-         {
-            Map<Platform, bool> excludedPlatforms { };
-            topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, excludedPlatforms,
-                  nodeCFlagsMapping, nodeECFlagsMapping);
-            delete excludedPlatforms;
-         }
+         topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
 
          if(numCObjects)
             GenMakefilePrintMainObjectRule(f, config);
 
-         f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
-         f.Printf("\t$(call rmq,%s$(TARGET))\n", numCObjects ? "$(OBJ)$(MODULE).main.o $(OBJ)$(MODULE).main.c $(OBJ)$(MODULE).main.ec $(OBJ)$(MODULE).main$(I) $(OBJ)$(MODULE).main$(S) " : "");
+         f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
+         f.Puts("\t$(call rmq,$(TARGET))\n");
+         f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
+         f.Puts("ifdef LINUX_TARGET\n");
+         f.Puts("ifdef LINUX_HOST\n");
+         // TODO?: support symlinks for longer version numbers
+         f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
+         f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
+         f.Puts("endif\n");
+         f.Puts("endif\n");
+         f.Puts("endif\n");
+         f.Puts("\n");
+
+         f.Puts("clean: cleantarget\n");
+         f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
          OutputCleanActions(f, "_OBJECTS", objectsParts);
+         if(rcSourcesParts)
+         {
+            f.Puts("ifdef WINDOWS_TARGET\n");
+            OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
+            f.Puts("endif\n");
+         }
          if(numCObjects)
          {
+            f.Printf("\t$(call rmq,%s)\n", "$(OBJ)$(MODULE).main.o $(OBJ)$(MODULE).main.c $(OBJ)$(MODULE).main.ec $(OBJ)$(MODULE).main$(I) $(OBJ)$(MODULE).main$(S)");
             OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
             OutputCleanActions(f, "COBJECTS", eCsourcesParts);
             OutputCleanActions(f, "BOWLS", eCsourcesParts);
@@ -2754,14 +3388,17 @@ private:
          }
          f.Puts("\n");
 
-         f.Puts("realclean: clean\n");
+         f.Puts("realclean: cleantarget\n");
          f.Puts("\t$(call rmrq,$(OBJ))\n");
-         if(!sameObjTargetDirs)
+         if(!sameOrRelObjTargetDirs)
             f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
          f.Puts("\n");
 
-         f.Puts("distclean:\n");
-         f.Puts("\t$(call rmrq,obj/)\n");
+         f.Puts("distclean: cleantarget\n");
+         if(!sameOrRelObjTargetDirs)
+            f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
+         if(!relObjDir)
+            f.Puts("\t$(call rmrq,obj/)\n");
 
          delete f;
 
@@ -2874,13 +3511,12 @@ private:
          {
 #endif
             f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
+            f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $@\n", extension);
+            f.Puts("\n");
 #if 0
          }
       }
 #endif
-
-      f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n", extension);
-      f.Puts("\n");
    }
 
    void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
@@ -2897,13 +3533,11 @@ private:
                else
                   f.Printf("CUSTOM%d_%s =", v-1, variableName);
                f.Puts(&v ? &v : "");
-               f.Puts("\n");
-               f.Puts("\n");
+               f.Puts("\n\n");
                break;
             }
          }
       }
-      f.Puts("\n");
    }
 
    void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
@@ -2936,6 +3570,17 @@ private:
    }
 }
 
+static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
+{
+   if(prj.lastBuildNamesInfo)
+   {
+      prj.lastBuildNamesInfo.Free();
+      delete prj.lastBuildNamesInfo;
+   }
+   prj.lastBuildNamesInfo = { };
+   prj.topNode.GenMakefileGetNameCollisionInfo(prj.lastBuildNamesInfo, cfg);
+}
+
 Project LegacyBinaryLoadProject(File f, char * filePath)
 {
    Project project = null;
@@ -3609,13 +4254,13 @@ void CombineIdenticalConfigOptions(Project project)
                         
                         if(type.type == noHeadClass || type.type == normalClass)
                         {
-                           result = type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+                           result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                               *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
                               *(void **)((byte *)cfg.options         + member.offset + member._class.offset));
                         }
                         else
                         {
-                           result = type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+                           result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                               (byte *)firstConfig.options + member.offset + member._class.offset,
                               (byte *)cfg.options         + member.offset + member._class.offset);
                         }
@@ -3631,14 +4276,14 @@ void CombineIdenticalConfigOptions(Project project)
                {
                   if(type.type == noHeadClass || type.type == normalClass)
                   {
-                     if(!type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+                     if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                         *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
                         *(void **)((byte *)nullOptions         + member.offset + member._class.offset)))
                         continue;
                   }
                   else
                   {
-                     if(!type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+                     if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                         (byte *)firstConfig.options + member.offset + member._class.offset,
                         (byte *)nullOptions         + member.offset + member._class.offset))
                         continue;
@@ -3648,7 +4293,7 @@ void CombineIdenticalConfigOptions(Project project)
                   
                   /*if(type.type == noHeadClass || type.type == normalClass)
                   {
-                     type._vTbl[__ecereVMethodID_class_OnCopy](type, 
+                     ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type, 
                         (byte *)project.options + member.offset + member._class.offset,
                         *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
                   }
@@ -3656,7 +4301,7 @@ void CombineIdenticalConfigOptions(Project project)
                   {
                      void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
                      // TOFIX: ListBox::SetData / OnCopy mess
-                     type._vTbl[__ecereVMethodID_class_OnCopy](type, 
+                     ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type, 
                         (byte *)project.options + member.offset + member._class.offset,
                         (type.typeSize > 4) ? address : 
                            ((type.typeSize == 4) ? (void *)*(uint32 *)address : 
@@ -3675,13 +4320,13 @@ void CombineIdenticalConfigOptions(Project project)
                         
                         if(type.type == noHeadClass || type.type == normalClass)
                         {
-                           result = type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+                           result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                               *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
                               *(void **)((byte *)cfg.options         + member.offset + member._class.offset));
                         }
                         else
                         {
-                           result = type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+                           result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                               (byte *)firstConfig.options + member.offset + member._class.offset,
                               (byte *)cfg.options         + member.offset + member._class.offset);
                         }
@@ -3692,12 +4337,12 @@ void CombineIdenticalConfigOptions(Project project)
                      {
                         if(type.type == noHeadClass || type.type == normalClass)
                         {
-                           type._vTbl[__ecereVMethodID_class_OnFree](type, 
+                           ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, 
                               *(void **)((byte *)cfg.options + member.offset + member._class.offset));
                         }
                         else
                         {
-                           type._vTbl[__ecereVMethodID_class_OnFree](type, 
+                           ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, 
                               (byte *)cfg.options + member.offset + member._class.offset);
                         }
                         memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
@@ -3769,6 +4414,17 @@ Project LoadProject(char * filePath, char * activeConfigName)
             delete project.topNode.files;
             if(!project.files) project.files = { };
             project.topNode.files = project.files;
+
+            {
+               char topNodePath[MAX_LOCATION];
+               GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
+               MakeSlashPath(topNodePath);
+               PathCatSlash(topNodePath, filePath);
+               project.filePath = topNodePath;//filePath;
+            }
+
+            project.topNode.FixupNode(insidePath);
+
             project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
             delete project.resNode.path;
             project.resNode.path = project.resourcesPath;
@@ -3780,15 +4436,7 @@ Project LoadProject(char * filePath, char * activeConfigName)
             project.resources = null;
             if(!project.configurations) project.configurations = { };
 
-            {
-               char topNodePath[MAX_LOCATION];
-               GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
-               MakeSlashPath(topNodePath);
-               PathCatSlash(topNodePath, filePath);
-               project.filePath = topNodePath;//filePath;
-            }
-
-            project.topNode.FixupNode(insidePath);
+            project.resNode.FixupNode(insidePath);
          }
          delete parser;
       }
@@ -3801,16 +4449,7 @@ Project LoadProject(char * filePath, char * activeConfigName)
       {
          if(!project.options) project.options = { };
          if(activeConfigName && activeConfigName[0] && project.configurations)
-         {
-            for(cfg : project.configurations)
-            {
-               if(!strcmpi(cfg.name, activeConfigName))
-               {
-                  project.config = cfg;
-                  break;
-               }
-            }
-         }
+            project.config = project.GetConfig(activeConfigName);
          if(!project.config && project.configurations)
             project.config = project.configurations.firstIterator.data;