ide; (#975) fixed space char in resources file name regression.
[sdk] / ide / src / project / ProjectNode.ec
index db79e25..aaf2e93 100644 (file)
@@ -14,6 +14,15 @@ static define app = ((GuiApplication)__thisModule);
 
 #define OPTION(x) ((uint)(&((ProjectOptions)0).x))
 
+static void OutputLog(char * string)
+{
+#ifdef MAKEFILE_GENERATOR
+   printf(string);
+#else
+   ide.outputView.buildBox.Log(string);
+#endif
+}
+
 bool eString_PathInsideOfMore(char * path, char * of, char * pathRest)
 {
    if(!path[0] || !of[0])
@@ -43,8 +52,8 @@ enum NodeTypes { project, file, folder, resources, folderOpen };
 enum NodeIcons
 {
    genFile, ewsFile, epjFile, folder, openFolder, ecFile, ehFile,
-   cFile, hFile, cppFile, hppFile, textFile, webFile, pictureFile, soundFile,
-   archiveFile, packageFile, opticalMediaImageFile, mFile;
+   sFile, cFile, hFile, cppFile, hppFile, textFile, webFile, pictureFile, soundFile,
+   archiveFile, packageFile, opticalMediaImageFile, mFile, mmFile;
 
    NodeIcons ::SelectFileIcon(char * filePath)
    {
@@ -69,12 +78,16 @@ enum NodeIcons
             else if(!strcmpi(extension, "hpp") || !strcmpi(extension, "hh") ||
                   !strcmpi(extension, "hxx"))
                icon = hppFile;
+            else if(!strcmpi(extension, "s"))
+               icon = sFile;
             else if(!strcmpi(extension, "c"))
                icon = cFile;
             else if(!strcmpi(extension, "h"))
                icon = hFile;
             else if(!strcmpi(extension, "m"))
                icon = mFile;
+            else if(!strcmpi(extension, "mm"))
+               icon = mmFile;
             else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
                   !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
                icon = textFile;
@@ -164,6 +177,8 @@ class TwoStrings : struct
    }
 }
 
+enum IntermediateFileType { none, ec, c, sym, imp, bowl, o };
+
 class ProjectNode : ListItem
 {
 public:
@@ -465,6 +480,51 @@ private:
       return buffer;
    }
 
+   char * GetObjectFileName(char * buffer, Map<String, NameCollisionInfo> namesInfo, IntermediateFileType type, bool dotMain)
+   {
+      if(buffer && (this.type == file || (this.type == project && dotMain == true)))
+      {
+         bool collision;
+         char extension[MAX_EXTENSION];
+         char moduleName[MAX_FILENAME];
+         NameCollisionInfo info;
+
+         GetExtension(name, extension);
+         ReplaceSpaces(moduleName, name);
+         StripExtension(moduleName);
+         info = namesInfo[moduleName];
+         collision = info ? info.IsExtensionColliding(extension) : false;
+
+         if(dotMain)
+         {
+            ReplaceSpaces(buffer, project.moduleName);
+            StripExtension(buffer);
+            strcat(buffer, ".main.ec");
+         }
+         else
+            strcpy(buffer, name);
+         if(!strcmp(extension, "ec") || dotMain)
+         {
+            if(type == c)
+               ChangeExtension(buffer, "c", buffer);
+            else if(type == sym)
+               ChangeExtension(buffer, "sym", buffer);
+            else if(type == imp)
+               ChangeExtension(buffer, "imp", buffer);
+            else if(type == bowl)
+               ChangeExtension(buffer, "bowl", buffer);
+         }
+         if(type == o)
+         {
+            if(collision)
+               strcat(buffer, ".o");
+            else
+               ChangeExtension(buffer, "o", buffer);
+         }
+      }
+      return buffer;
+   }
+
    char * GetFileSysMatchingPath(char * buffer)
    {
       if(buffer)
@@ -969,6 +1029,17 @@ private:
 
    ProjectNode FindByFullPath(char * path, bool includeResources)
    {
+      if(files)
+      {
+         char name[MAX_FILENAME];
+         GetLastDirectory(path, name);
+         return InternalFindByFullPath(path, includeResources, name);
+      }
+      return null;
+   }
+
+   ProjectNode InternalFindByFullPath(char * path, bool includeResources, char * lastDirName)
+   {
       ProjectNode result = null;
       if(files)
       {
@@ -976,7 +1047,9 @@ private:
          {
             if(includeResources || child.type != resources)
             {
-               if(child.type != folder && child.name)
+               if(child.type != file)
+                  result = child.InternalFindByFullPath(path, includeResources, lastDirName);
+               else if(child.name && !strcmpi(lastDirName, child.name))
                {
                   char p[MAX_LOCATION];
                   child.GetFullFilePath(p);
@@ -986,7 +1059,6 @@ private:
                      break;
                   }
                }
-               result = child.FindByFullPath(path, includeResources);
                if(result)
                   break;
             }
@@ -995,6 +1067,36 @@ private:
       return result;
    }
 
+   ProjectNode FindByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, Map<String, NameCollisionInfo> namesInfo)
+   {
+      char p[MAX_LOCATION];
+      ProjectNode result = null;
+      if(dotMain == true && this.type == project)
+      {
+         GetObjectFileName(p, namesInfo, type, dotMain);
+         if(!strcmpi(p, fileName))
+            result = this;
+      }
+      else if(files)
+      {
+         for(child : files; child.type != resources)
+         {
+            if(child.type != file && (result = child.FindByObjectFileName(fileName, type, dotMain, namesInfo)))
+               break;
+            else if(child.type == file && child.name)
+            {
+               child.GetObjectFileName(p, namesInfo, type, dotMain);
+               if(!strcmpi(p, fileName))
+               {
+                  result = child;
+                  break;
+               }
+            }
+         }
+      }
+      return result;
+   }
+
    ProjectNode FindSpecial(char * name, bool recursive, bool includeResources, bool includeFolders)
    {
       ProjectNode result = null;
@@ -1080,51 +1182,54 @@ private:
    ProjectNode Add(Project project, char * filePath, ProjectNode after, NodeTypes type, NodeIcons icon, bool checkIfExists)
    {
       ProjectNode node = null;
-      char temp[MAX_LOCATION];
-      Map<Platform, SetBool> exclusionInfo { };
-
-      GetLastDirectory(filePath, temp);
-      //if(!checkIfExists || !project.topNode.Find(temp, false))
-      
-      // TOCHECK: Shouldn't this apply either for all configs or none?
-      CollectExclusionInfo(exclusionInfo, project.config);
-      if(!checkIfExists || !project.topNode.FindSameNameConflict(temp, false, exclusionInfo, project.config))
+      if(!project.topNode.FindByFullPath(filePath, true))
       {
-         // Do the check for folder in the same parent or resource files only here
-         if(type == folder || !checkIfExists)
+         char temp[MAX_LOCATION];
+         Map<Platform, SetBool> exclusionInfo { };
+
+         GetLastDirectory(filePath, temp);
+         //if(!checkIfExists || !project.topNode.Find(temp, false))
+
+         // TOCHECK: Shouldn't this apply either for all configs or none?
+         CollectExclusionInfo(exclusionInfo, project.config);
+         if(!checkIfExists || type == folder || !project.topNode.FindSameNameConflict(temp, false, exclusionInfo, project.config))
          {
-            for(node : files)
+            // Do the check for folder in the same parent or resource files only here
+            if(type == folder || !checkIfExists)
             {
-               if(node.name && !strcmpi(node.name, temp))
-                  return null;
+               for(node : files)
+               {
+                  if(node.name && !strcmpi(node.name, temp))
+                     return null;
+               }
             }
-         }
 
-         node = ProjectNode { parent = this, indent = indent + 1, type = type, icon = icon, name = CopyString(temp) };
-         if(type != file)
-         {
-            node.files = { }; 
-            node.nodeType = folder;
-         }
-         if(type != folder)
-         {
-            if(filePath)
+            node = ProjectNode { parent = this, indent = indent + 1, type = type, icon = icon, name = CopyString(temp) };
+            if(type != file)
             {
-               StripLastDirectory(filePath, temp);
-               MakePathRelative(temp, project.topNode.path, temp);
-               node.path = CopyUnixPath(temp);
+               node.files = { };
+               node.nodeType = folder;
             }
-            node.nodeType = file;
-         }
-         else
-         {
-            strcpy(temp, (type == NodeTypes::project) ? "" : path);
-            PathCatSlash(temp, node.name);
-            node.path = CopyString(temp);
+            if(type != folder)
+            {
+               if(filePath)
+               {
+                  StripLastDirectory(filePath, temp);
+                  MakePathRelative(temp, project.topNode.path, temp);
+                  node.path = CopyUnixPath(temp);
+               }
+               node.nodeType = file;
+            }
+            else
+            {
+               strcpy(temp, (type == NodeTypes::project) ? "" : path);
+               PathCatSlash(temp, node.name);
+               node.path = CopyString(temp);
+            }
+            files.Insert(after, node);
          }
-         files.Insert(after, node);
+         delete exclusionInfo;
       }
-      delete exclusionInfo;
       return node;
    }
 
@@ -1274,9 +1379,9 @@ private:
       {
          char extension[MAX_EXTENSION];
          GetExtension(name, extension);
-         if(!strcmpi(extension, "ec") || !strcmpi(extension, "c") ||
-               !strcmpi(extension, "cpp") || !strcmpi(extension, "cc") ||
-               !strcmpi(extension, "cxx") || !strcmpi(extension, "m"))
+         if(!strcmpi(extension, "ec") || !strcmpi(extension, "s") || !strcmpi(extension, "c") ||
+               !strcmpi(extension, "rc") || !strcmpi(extension, "cpp") || !strcmpi(extension, "cc") ||
+               !strcmpi(extension, "cxx") || !strcmpi(extension, "m") || !strcmpi(extension, "mm"))
          {
             char moduleName[MAX_FILENAME];
             NameCollisionInfo info;
@@ -1288,8 +1393,12 @@ private:
             info.count++; // += 1; unless this is for a bug?
             if(!strcmpi(extension, "ec"))
                info.ec = true;
+            else if(!strcmpi(extension, "s"))
+               info.s = true;
             else if(!strcmpi(extension, "c"))
                info.c = true;
+            else if(!strcmpi(extension, "rc"))
+               info.rc = true;
             else if(!strcmpi(extension, "cpp"))
                info.cpp = true;
             else if(!strcmpi(extension, "cc"))
@@ -1298,6 +1407,8 @@ private:
                info.cxx = true;
             else if(!strcmpi(extension, "m"))
                info.m = true;
+            else if(!strcmpi(extension, "mm"))
+               info.mm = true;
             namesInfo[moduleName] = info;
          }
       }
@@ -1341,20 +1452,19 @@ private:
                strcpy(tempPath, path);
                PathCatSlash(tempPath, name);
             }
-            ReplaceSpaces(modulePath, tempPath);
+            EscapeForMake(modulePath, tempPath, false, true, false);
             sprintf(s, "%s%s%s%s", ts.a, useRes ? "$(RES)" : "", modulePath, ts.b);
             items.Add(CopyString(s));
          }
          else if(printType == sources)
          {
-            if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
+            if(!strcmpi(extension, "s") || !strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
                   !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") ||
-                  !strcmpi(extension, "m"))
+                  !strcmpi(extension, "m") || !strcmpi(extension, "mm"))
             {
                char modulePath[MAX_LOCATION];
-
-               ReplaceSpaces(modulePath, path);
-               ReplaceSpaces(moduleName, name);
+               EscapeForMake(modulePath, path, false, true, false);
+               EscapeForMake(moduleName, name, false, true, false);
                sprintf(s, "%s%s%s%s%s", ts.a, modulePath, path[0] ? SEPS : "", moduleName, ts.b);
                items.Add(CopyString(s));
             }
@@ -1364,24 +1474,35 @@ private:
             if(!strcmpi(extension, "ec"))
             {
                char modulePath[MAX_LOCATION];
-
-               ReplaceUnwantedMakeChars(modulePath, path);
-               ReplaceUnwantedMakeChars(moduleName, name);
+               EscapeForMake(modulePath, path, true, true, false);
+               EscapeForMake(moduleName, name, true, true, false);
                sprintf(s, "%s%s%s%s%s", ts.a, modulePath, path[0] ? SEPS : "", moduleName, ts.b);
                items.Add(CopyString(s));
                count++;
             }
          }
-         else if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
+         else if(printType == rcSources)
+         {
+            if(!strcmpi(extension, "rc"))
+            {
+               char modulePath[MAX_LOCATION];
+               EscapeForMake(modulePath, path, false, true, false);
+               EscapeForMake(moduleName, name, false, true, false);
+               sprintf(s, "%s%s%s%s%s", ts.a, modulePath, path[0] ? SEPS : "", moduleName, ts.b);
+               items.Add(CopyString(s));
+               count++;
+            }
+         }
+         else if(!strcmpi(extension, "s") || !strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
                !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") ||
-               !strcmpi(extension, "m"))
+               !strcmpi(extension, "m") || !strcmpi(extension, "mm"))
          {
             if(printType == objects)
             {
                bool collision;
                NameCollisionInfo info;
                count++;
-               ReplaceSpaces(moduleName, name);
+               EscapeForMake(moduleName, name, false, true, false);
                StripExtension(moduleName);
                info = namesInfo[moduleName];
                collision = info ? info.IsExtensionColliding(extension) : false;
@@ -1515,8 +1636,8 @@ private:
                   GenMakePrintNodeFlagsVariable(this, nodeECFlagsMapping, "ECFLAGS", f);
                   GenMakePrintNodeFlagsVariable(this, nodeCFlagsMapping, "PRJ_CFLAGS", f);
 
-                  f.Printf(" -c %s%s.%s -o $(OBJ)%s.sym\n",
-                     modulePath, moduleName, extension, moduleName);
+                  f.Printf(" -c %s%s.%s -o $@\n",
+                     modulePath, moduleName, extension);
                   if(ifCount) f.Puts("endif\n");
                   f.Puts("\n");
 #if 0
@@ -1585,7 +1706,6 @@ private:
             OpenRulesPlatformExclusionIfs(f, &ifCount, platforms);
             f.Printf("$(OBJ)%s$(EC): %s%s.%s\n",
                moduleName, modulePath, moduleName, extension);
-            //$(CPP) -x c -E ../extras/gui/controls/DirectoriesBox.ec -o $(OBJ)DirectoriesBox$(EC)
             /*f.Printf("\t$(CPP) %s%s.%s %s$(S)\n\n",
                modulePath, moduleName, extension, moduleName);*/
 
@@ -1752,8 +1872,8 @@ private:
             GenMakePrintNodeFlagsVariable(this, nodeCFlagsMapping, "PRJ_CFLAGS", f);
             f.Puts(" $(FVISIBILITY)");
 
-            f.Printf(" -c %s%s.%s -o $(OBJ)%s.c -symbols $(OBJ)\n",
-               modulePath, moduleName, extension, moduleName);
+            f.Printf(" -c %s%s.%s -o $@ -symbols $(OBJ)\n",
+               modulePath, moduleName, extension);
             if(ifCount) f.Puts("endif\n");
             f.Puts("\n");
          }
@@ -1806,12 +1926,9 @@ private:
          char moduleName[MAX_FILENAME];
 
          GetExtension(name, extension);
-         /*if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
-               !strcmpi(extension, "ec") || !strcmpi(extension, "cc") ||
-               !strcmpi(extension, "cxx"))*/
-         if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
-               !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") ||
-               !strcmpi(extension, "m") || !strcmpi(extension, "ec"))
+         if(!strcmpi(extension, "s") || !strcmpi(extension, "c") || !strcmpi(extension, "rc") ||
+               !strcmpi(extension, "cpp") || !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") ||
+               !strcmpi(extension, "m") || !strcmpi(extension, "mm") || !strcmpi(extension, "ec"))
          {
             DualPipe dep;
             char command[2048];
@@ -1826,6 +1943,8 @@ private:
             ReplaceSpaces(modulePath, path);
             if(modulePath[0]) strcat(modulePath, SEPS);
 
+            /*
+#if 0
             // *** Dependency command ***
             if(!strcmpi(extension, "ec"))
                sprintf(command, "%s -MT $(OBJ)%s.o -MM $(OBJ)%s.c", "$(CPP)", moduleName, moduleName);
@@ -1833,9 +1952,6 @@ private:
                sprintf(command, "%s -MT $(OBJ)%s.o -MM %s%s.%s", (!strcmpi(extension, "cc") || !strcmpi(extension, "cxx") || !strcmpi(extension, "cpp")) ? "$(CXX)" : "$(CC)",
                   moduleName, modulePath, moduleName, extension);
 
-            OpenRulesPlatformExclusionIfs(f, &ifCount, platforms);
-            /*
-#if 0
             if(!strcmpi(extension, "ec"))
             {
                f.Printf("$(OBJ)%s.o: $(OBJ)%s.c\n", moduleName, moduleName);
@@ -1913,23 +2029,37 @@ private:
             }
 #endif
          */
+            if(!strcmpi(extension, "rc"))
+            {
+               ifCount++;
+               f.Puts("ifdef WINDOWS_TARGET\n\n");
+            }
+            else
+               OpenRulesPlatformExclusionIfs(f, &ifCount, platforms);
+
             if(!strcmpi(extension, "ec"))
                f.Printf("$(OBJ)%s.o: $(OBJ)%s.c\n", moduleName, moduleName);
             else
                f.Printf("$(OBJ)%s%s%s.o: %s%s.%s\n", moduleName, 
                      collision ? "." : "", collision ? extension : "", modulePath, moduleName, extension);
-            f.Printf("\t$(%s)", (!strcmpi(extension, "cc") || !strcmpi(extension, "cpp") || !strcmpi(extension, "cxx")) ? "CXX" : "CC");
-
-            f.Puts(" $(CFLAGS)");
-            GenMakePrintNodeFlagsVariable(this, nodeCFlagsMapping, "PRJ_CFLAGS", f);
-
-            if(!strcmpi(extension, "ec"))
-               f.Printf(" $(FVISIBILITY) -c $(OBJ)%s.c -o $(OBJ)%s.o\n", moduleName, moduleName);
+            if(!strcmpi(extension, "cc") || !strcmpi(extension, "cpp") || !strcmpi(extension, "cxx"))
+               f.Printf("\t$(CXX)");
+            else if(!strcmpi(extension, "rc"))
+               f.Printf("\t$(WINDRES) $(WINDRES_FLAGS) $< $@\n");
             else
-               f.Printf(" -c %s%s.%s -o $(OBJ)%s%s%s.o\n",
-                     modulePath, moduleName, !strcmpi(extension, "ec") ? "c" : extension, moduleName,
-                     collision ? "." : "", collision ? extension : "");
+               f.Printf("\t$(CC)");
+
+            if(strcmpi(extension, "rc") != 0)
+            {
+               f.Puts(" $(CFLAGS)");
+               GenMakePrintNodeFlagsVariable(this, nodeCFlagsMapping, "PRJ_CFLAGS", f);
 
+               if(!strcmpi(extension, "ec"))
+                  f.Printf(" $(FVISIBILITY) -c $(OBJ)%s.c -o $@\n", moduleName);
+               else
+                  f.Printf(" -c %s%s.%s -o $@\n",
+                        modulePath, moduleName, !strcmpi(extension, "ec") ? "c" : extension);
+            }
             if(ifCount) f.Puts("endif\n");
             f.Puts("\n");
          }
@@ -1981,8 +2111,6 @@ private:
                char tempPath[MAX_LOCATION];
                char resPath[MAX_LOCATION];
 
-               char * quotes;
-
                // $(EAR) aw%s --- /*quiet ? "q" : */""
                if(count == 0)
                   f.Printf("\t%s$(EAR) aw$(EARFLAGS) $(TARGET)", ts.a);
@@ -1999,12 +2127,8 @@ private:
                   strcpy(tempPath, child.path);
                   PathCatSlash(tempPath, child.name);
                }
-               ReplaceSpaces(resPath, tempPath);
-               if(strchr(tempPath, ' '))
-                  quotes = "\"";
-               else
-                  quotes = "";
-               f.Printf(" %s%s%s%s", quotes, useRes ? "$(RES)" : "", tempPath, quotes);
+               EscapeForMake(resPath, tempPath, false, true, false);
+               f.Printf(" %s%s", useRes ? "$(RES)" : "", resPath);
                count++;
             }
             if(count == 10 || (count > 0 && (ts || !child.next)))
@@ -2260,21 +2384,90 @@ private:
       return platforms;
    }
 
-   void GetTargets(ProjectConfig prjConfig, char * objDir, DynamicString output)
+   void GetTargets(ProjectConfig prjConfig, Map<String, NameCollisionInfo> namesInfo, char * objDir, DynamicString output)
    {
+      char moduleName[MAX_FILENAME];
       if(type == file)
       {
-         //output.concat(" $(OBJ)");
+         bool headerAltFailed = false;
+         bool collision;
+         char extension[MAX_EXTENSION];
+         NameCollisionInfo info;
+         Project prj = property::project;
+         Map<String, String> headerToSource { [ { "eh", "ec" }, { "h", "c" }, { "hh", "cc" }, { "hpp", "cpp" }, { "hxx", "cxx" } ] };
+
+         GetExtension(name, extension);
+         ReplaceSpaces(moduleName, name);
+         StripExtension(moduleName);
+         info = namesInfo[moduleName];
+         collision = info ? info.IsExtensionColliding(extension) : false;
+
+         for(h2s : headerToSource)
+         {
+            if(!strcmpi(extension, &h2s))
+            {
+               char filePath[MAX_LOCATION];
+               GetFullFilePath(filePath);
+               OutputLog($"No compilation required for header file "); OutputLog(filePath); OutputLog("\n");
+               ChangeExtension(moduleName, h2s, moduleName);
+               if(prj.topNode.Find(moduleName, false))
+               {
+                  strcpy(extension, h2s);
+                  collision = info ? info.IsExtensionColliding(extension) : false;
+                  ChangeExtension(filePath, h2s, filePath);
+                  OutputLog($"Compiling source file "); OutputLog(filePath); OutputLog($" instead\n");
+                  StripExtension(moduleName);
+               }
+               else
+               {
+                  headerAltFailed = true;
+                  OutputLog($"Unable to locate source file "); OutputLog(moduleName); OutputLog($" to compile instead of "); OutputLog(filePath); OutputLog($"\n");
+                  StripExtension(moduleName);
+               }
+               break;
+            }
+         }
+
+         if(!headerAltFailed)
+         {
+            output.concat(" \"");
+            output.concat(objDir); //.concat(" $(OBJ)");
+            output.concat("/");
+
+            if(collision)
+            {
+               strcat(moduleName, ".");
+               strcat(moduleName, extension);
+            }
+            strcat(moduleName, ".o");
+            output.concat(moduleName);
+            output.concat("\"");
+         }
+      }
+      else if(type == project && ContainsFilesWithExtension("ec"))
+      {
+         Project prj = property::project;
+
+         ReplaceSpaces(moduleName, prj.moduleName);
+         strcat(moduleName, ".main.ec");
          output.concat(" \"");
          output.concat(objDir);
          output.concat("/");
-         {
-            char fileName[MAX_FILENAME];
-            strcpy(fileName, name);
-            // TODO/NOTE: this will not be correct for file.o instead of file.c.o when whe have both a file.c and a file.ec in a project.
-            ChangeExtension(fileName, "o", fileName);
-            output.concat(fileName);
-         }
+         output.concat(moduleName);
+         output.concat("\"");
+
+         ChangeExtension(moduleName, "c", moduleName);
+         output.concat(" \"");
+         output.concat(objDir);
+         output.concat("/");
+         output.concat(moduleName);
+         output.concat("\"");
+
+         ChangeExtension(moduleName, "o", moduleName);
+         output.concat(" \"");
+         output.concat(objDir);
+         output.concat("/");
+         output.concat(moduleName);
          output.concat("\"");
       }
       else if(files)
@@ -2282,49 +2475,52 @@ private:
          for(child : files)
          {
             if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               child.GetTargets(prjConfig, objDir, output);
+               child.GetTargets(prjConfig, namesInfo, objDir, output);
          }
       }
    }
 
-   void DeleteIntermediateFiles(CompilerConfig compiler, ProjectConfig prjConfig)
+   void DeleteIntermediateFiles(CompilerConfig compiler, ProjectConfig prjConfig, int bitDepth, Map<String, NameCollisionInfo> namesInfo, bool onlyCObject)
    {
       if(type == file)
       {
-         char fileName[MAX_FILENAME];
+         bool collision;
          char extension[MAX_EXTENSION];
+         char fileName[MAX_FILENAME];
+         char moduleName[MAX_FILENAME];
+         NameCollisionInfo info;
          Project prj = property::project;
-         DirExpression objDir = prj.GetObjDir(compiler, prjConfig);
+         DirExpression objDir = prj.GetObjDir(compiler, prjConfig, bitDepth);
+
+         GetExtension(name, extension);
+         ReplaceSpaces(moduleName, name);
+         StripExtension(moduleName);
+         info = namesInfo[moduleName];
+         collision = info ? info.IsExtensionColliding(extension) : false;
 
          strcpy(fileName, prj.topNode.path);
          PathCatSlash(fileName, objDir.dir);
          PathCatSlash(fileName, name);
 
-         // TODO/NOTE: this will not delete file.c.o when whe have both a file.c and a file.ec in a project.
-         ChangeExtension(fileName, "o", fileName);
-         if(FileExists(fileName))
-            DeleteFile(fileName);
-
-         GetExtension(name, extension);
-         if(!strcmp(extension, "ec"))
+         if(!onlyCObject && !strcmp(extension, "ec"))
          {
             ChangeExtension(fileName, "c", fileName);
-            if(FileExists(fileName))
-               DeleteFile(fileName);
-
+            if(FileExists(fileName)) DeleteFile(fileName);
             ChangeExtension(fileName, "sym", fileName);
-            if(FileExists(fileName))
-               DeleteFile(fileName);
-
+            if(FileExists(fileName)) DeleteFile(fileName);
             ChangeExtension(fileName, "imp", fileName);
-            if(FileExists(fileName))
-               DeleteFile(fileName);
-
+            if(FileExists(fileName)) DeleteFile(fileName);
             ChangeExtension(fileName, "bowl", fileName);
-            if(FileExists(fileName))
-               DeleteFile(fileName);
+            if(FileExists(fileName)) DeleteFile(fileName);
+            ChangeExtension(fileName, "ec", fileName);
          }
 
+         if(collision)
+            strcat(fileName, ".o");
+         else
+            ChangeExtension(fileName, "o", fileName);
+         if(FileExists(fileName)) DeleteFile(fileName);
+
          delete objDir;
       }
       else if(files)
@@ -2332,7 +2528,7 @@ private:
          for(child : files)
          {
             if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               child.DeleteIntermediateFiles(compiler, prjConfig);
+               child.DeleteIntermediateFiles(compiler, prjConfig, bitDepth, namesInfo, onlyCObject);
          }
       }
    }
@@ -2399,8 +2595,8 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
       mergeValues = true;
       caseSensitive = true;
       bool OptionCheck(ProjectOptions options, int option) {
-         String string = *(String*)((byte *)options + option);
-         return string && string[0];
+         Array<String> strings = *(Array<String>*)((byte *)options + option);
+         return strings && strings.count;
       }
       bool OptionSet(ProjectOptions options, int option) {
          Array<String> strings = *(Array<String>*)((byte *)options + option);
@@ -2470,16 +2666,6 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
          *(OptimizationStrategy*)((byte *)output + option) = value;
       }
    };
-   GenericOptionTools<BuildBitDepth>        utilBuildBitDepth {
-      bool OptionCheck(ProjectOptions options, int option) {
-         BuildBitDepth value = *(BuildBitDepth*)((byte *)options + option);
-         return value && value != all;
-      }
-      void LoadOption(ProjectOptions options, int option, int priority, Array<Array<String>> optionTempStrings, ProjectOptions output) {
-         BuildBitDepth value = options ? *(BuildBitDepth*)((byte *)options + option) : (BuildBitDepth)0;
-         *(BuildBitDepth*)((byte *)output + option) = value;
-      }
-   };
 
    Map<int, GenericOptionTools> ot { };
 
@@ -2501,8 +2687,6 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
 
    ot[OPTION(optimization)] =            utilOptimizationStrategy;
 
-   ot[OPTION(buildBitDepth)] =           utilBuildBitDepth;
-
    for(n = node; n; n = n.parent)
    {
       ProjectConfig nodeConfig = null;
@@ -2595,7 +2779,6 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
    delete utilStringArrays;
    delete utilWarningsOption;
    delete utilOptimizationStrategy;
-   delete utilBuildBitDepth;
 
    delete ot;
 
@@ -2644,8 +2827,6 @@ static void CollectPlatformsCommonOptions(Map<Platform, ProjectOptions> byPlatfo
             commonOptions.warnings = unset;
          if(commonOptions.optimization && options.optimization != commonOptions.optimization)
             commonOptions.optimization = unset;
-         if(commonOptions.buildBitDepth && options.buildBitDepth != commonOptions.buildBitDepth)
-            commonOptions.buildBitDepth = all;
 
          if(commonOptions.defaultNameSpace && strcmp(options.defaultNameSpace, commonOptions.defaultNameSpace))
             delete commonOptions.defaultNameSpace;
@@ -2679,8 +2860,6 @@ static void CollectPlatformsCommonOptions(Map<Platform, ProjectOptions> byPlatfo
          options.warnings = unset;
       if(options.optimization && options.optimization == commonOptions.optimization)
          options.optimization = unset;
-      if(options.buildBitDepth && options.buildBitDepth == commonOptions.buildBitDepth)
-         options.buildBitDepth = all;
 
       if(options.defaultNameSpace && !strcmp(options.defaultNameSpace, commonOptions.defaultNameSpace))
          delete options.defaultNameSpace;
@@ -2895,8 +3074,6 @@ static void GenCFlagsFromProjectOptions(ProjectOptions options, bool prjWithEcFi
          }
          else if(commonOptions)
             s.concat(" $(if $(DEBUG),-g)");
-         if(options.buildBitDepth || (commonOptions && prjWithEcFiles))
-            s.concatf(" %s", (!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? "$(FORCE_32_BIT)" : "$(FORCE_64_BIT)");
          if(commonOptions)
             s.concat(" $(FPIC)");
       }
@@ -2910,9 +3087,9 @@ static void GenCFlagsFromProjectOptions(ProjectOptions options, bool prjWithEcFi
    }
 
    if(options && options.preprocessorDefinitions)
-      ListOptionToDynamicString("D", options.preprocessorDefinitions, false, lineEach, "\t\t\t", false, s);
+      ListOptionToDynamicString(s, _D, options.preprocessorDefinitions, false, lineEach, "\t\t\t");
    if(options && options.includeDirs)
-      ListOptionToDynamicString("I", options.includeDirs, true, lineEach, "\t\t\t", true, s);
+      ListOptionToDynamicString(s, _I, options.includeDirs, true, lineEach, "\t\t\t");
 }
 
 static void GenECFlagsFromProjectOptions(ProjectOptions options, bool prjWithEcFiles, DynamicString s)
@@ -2927,15 +3104,15 @@ static void GenECFlagsFromProjectOptions(ProjectOptions options, bool prjWithEcF
       s.concatf(" -defaultns %s", options.defaultNameSpace);
 }
 
-static void ListOptionToDynamicString(char * option, Array<String> list, bool prioritize,
-      ListOutputMethod method, String newLineStart, bool noSpace, DynamicString s)
+static void ListOptionToDynamicString(DynamicString output, ToolchainFlag flag, Array<String> list, bool prioritize,
+      LineOutputMethod lineMethod, String newLineStart)
 {
    if(list.count)
    {
-      if(method == newLine)
+      if(lineMethod == newLine)
       {
-         s.concat(" \\\n");
-         s.concat(newLineStart);
+         output.concat(" \\\n");
+         output.concat(newLineStart);
       }
       if(prioritize)
       {
@@ -2946,17 +3123,14 @@ static void ListOptionToDynamicString(char * option, Array<String> list, bool pr
          for(mn = sortedList.root.minimum; mn; mn = mn.next)
          {
             char * start = strstr(mn.key, "\n");
-            if(method == lineEach)
+            if(lineMethod == lineEach)
             {
-               s.concat(" \\\n");
-               s.concat(newLineStart);
+               output.concat(" \\\n");
+               output.concat(newLineStart);
             }
-            s.concat(" -");
-            s.concat(option);
-            if(noSpace)
-               StringNoSpaceToDynamicString(s, start ? start+1 : mn.key);
-            else
-               s.concat(start ? start+1 : mn.key);
+            output.concat(" ");
+            output.concat(flagNames[flag]);
+            EscapeForMakeToDynString(output, start ? start+1 : mn.key, false, true, flag == _D);
          }
          delete sortedList;
       }
@@ -2964,17 +3138,14 @@ static void ListOptionToDynamicString(char * option, Array<String> list, bool pr
       {
          for(item : list)
          {
-            if(method == lineEach)
+            if(lineMethod == lineEach)
             {
-               s.concat(" \\\n");
-               s.concat(newLineStart);
+               output.concat(" \\\n");
+               output.concat(newLineStart);
             }
-            s.concat(" -");
-            s.concat(option);
-            if(noSpace)
-               StringNoSpaceToDynamicString(s, item);
-            else
-               s.concat(item);
+            output.concat(" ");
+            output.concat(flagNames[flag]);
+            EscapeForMakeToDynString(output, item, false, true, flag == _D);
          }
       }
    }
@@ -3008,21 +3179,28 @@ class StringArrayOptionTools : GenericOptionTools<Array<String>>
 class NameCollisionInfo
 {
    bool ec;
+   bool s;
    bool c;
+   bool rc;
    bool cpp;
    bool cc;
    bool cxx;
    bool m;
+   bool mm;
    byte count;
 
    bool IsExtensionColliding(char * extension)
    {
       bool colliding;
-      if(count > 1 && ((!strcmpi(extension, "c") && ec) ||
-            (!strcmpi(extension, "cpp") && (ec || c)) ||
-            (!strcmpi(extension, "cc") && (ec || c || cpp)) ||
-            (!strcmpi(extension, "cxx") && (ec || c || cpp || cc)) ||
-            !strcmpi(extension, "m")))
+      if(count > 1 &&
+            ((!strcmpi(extension, "c")   && ec) ||
+             (!strcmpi(extension, "rc")  && (ec || c)) ||
+             (!strcmpi(extension, "s")   && (ec || c || rc)) ||
+             (!strcmpi(extension, "cpp") && (ec || c || rc || s)) ||
+             (!strcmpi(extension, "cc")  && (ec || c || rc || s || cpp)) ||
+             (!strcmpi(extension, "cxx") && (ec || c || rc || s || cpp || cc)) ||
+             (!strcmpi(extension, "m")   && (ec || c || rc || s || cpp || cc || m)) ||
+              !strcmpi(extension, "mm")))
          colliding = true;
       else
          colliding = false;