epj2make, ide: makefile generation, global settings dialog: add CXXFLAGS to compiler...
[sdk] / ide / src / project / ProjectNode.ec
index 6ac134c..d6c478d 100644 (file)
@@ -1,4 +1,4 @@
-#ifndef MAKEFILE_GENERATOR
+#if !defined(ECERE_DOCUMENTOR) && !defined(ECERE_EPJ2MAKE)
 import "ide"
 #else
 #ifdef ECERE_STATIC
@@ -12,9 +12,18 @@ import "Project"
 static define app = ((GuiApplication)__thisModule);
 #endif
 
-#define OPTION(x) ((uint)(&((ProjectOptions)0).x))
+#define OPTION(x) ((uint)(uintptr)(&((ProjectOptions)0).x))
 
-bool eString_PathInsideOfMore(char * path, char * of, char * pathRest)
+static void OutputLog(const char * string)
+{
+#if !defined(ECERE_DOCUMENTOR) && !defined(ECERE_EPJ2MAKE)
+   ide.outputView.buildBox.Log(string);
+#else
+   printf("%s", string);
+#endif
+}
+
+bool eString_PathInsideOfMore(const char * path, const char * of, char * pathRest)
 {
    if(!path[0] || !of[0])
       return false;  // What to do here? Ever used?
@@ -26,7 +35,7 @@ bool eString_PathInsideOfMore(char * path, char * of, char * pathRest)
       strcpy(pathRest, path);
       for(; ofRest[0] && pathRest[0];)
       {
-         SplitDirectory(ofRest, ofPart, ofRest);      
+         SplitDirectory(ofRest, ofPart, ofRest);
          SplitDirectory(pathRest, pathPart, pathRest);
          if(fstrcmp(pathPart, ofPart))
             return false;
@@ -44,9 +53,9 @@ enum NodeIcons
 {
    genFile, ewsFile, epjFile, folder, openFolder, ecFile, ehFile,
    sFile, cFile, hFile, cppFile, hppFile, textFile, webFile, pictureFile, soundFile,
-   archiveFile, packageFile, opticalMediaImageFile, mFile;
+   archiveFile, packageFile, opticalMediaImageFile, mFile, mmFile;
 
-   NodeIcons ::SelectFileIcon(char * filePath)
+   NodeIcons ::SelectFileIcon(const char * filePath)
    {
       NodeIcons icon;
       if(filePath && filePath[0])
@@ -77,6 +86,8 @@ enum NodeIcons
                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;
@@ -166,6 +177,57 @@ class TwoStrings : struct
    }
 }
 
+class DotMain : bool
+{
+   //property char * { set { } }
+   DotMain ::FromFileName(const char * fileName)
+   {
+      DotMain dotMain = false;
+      if(fileName && fileName[0])
+      {
+         char ext[MAX_EXTENSION];
+         GetExtension(fileName, ext);
+         if(!strcmp(ext, "c") || !strcmp(ext, "ec"))
+         {
+            char stripExt[MAX_LOCATION];
+            strcpy(stripExt, fileName);
+            StripExtension(stripExt);
+            GetExtension(stripExt, ext);
+            if(!strcmp(ext, "main"))
+               dotMain = true;
+         }
+      }
+      return dotMain;
+   }
+}
+
+enum IntermediateFileType
+{
+   none, ec, c, sym, imp, bowl, o;
+
+   //property char * { set { } }
+   IntermediateFileType ::FromExtension(char * extension)
+   {
+      IntermediateFileType type = none;
+      if(extension && extension[0])
+      {
+         if(!fstrcmp(extension, "ec"))
+            type = ec;
+         else if(!fstrcmp(extension, "c"))
+            type = c;
+         else if(!fstrcmp(extension, "sym"))
+            type = sym;
+         else if(!fstrcmp(extension, "imp"))
+            type = imp;
+         else if(!fstrcmp(extension, "bowl"))
+            type = bowl;
+         else if(!fstrcmp(extension, "o"))
+            type = o;
+      }
+      return type;
+   }
+};
+
 class ProjectNode : ListItem
 {
 public:
@@ -212,7 +274,7 @@ public:
       }
       isset { return nodeType == folder; }
    };
-   property String fileName
+   property const String fileName
    {
       set
       {
@@ -374,14 +436,14 @@ private:
    // For folders, it includes the folder it refers to. If there is a name difference between the
    // file system folder and the grouping folder of the project view, it maps to that folder.
    char * path;
-   
+
    NodeTypes type;
    NodeIcons icon;
    int indent;
    DataRow row;
 
    bool modified;
-   
+
    // This is only set for Top Nodes
    Project project;
 
@@ -389,9 +451,9 @@ private:
    {
       if(!platforms.Find(unknown))  // unknown is "Common"
       {
-         // e.g. ifneq "$(or $(or $(OSX_TARGET),$(LINUX_TARGET)),$(WINDOWS_TARGET))"
+         // e.g. ifneq ($(or $(or $(OSX_TARGET),$(LINUX_TARGET)),$(WINDOWS_TARGET)),)
          int i = 0;
-         f.Puts("ifneq \"");
+         f.Puts("ifneq (");
          for(i = 0; platforms.count && i < platforms.count - 1; i++)
             f.Puts("$(or ");
          i = 0;
@@ -406,7 +468,7 @@ private:
                f.Puts(")");
             i++;
          }
-         f.Puts("\" \"\"\n");
+         f.Puts(",)\n");
          (*ifCount)++;
       }
       else
@@ -437,7 +499,7 @@ private:
    {
       get
       {
-         bool result;
+         bool result = false;
          if(files)
          {
             for(child : files)
@@ -456,13 +518,82 @@ private:
       }
    }
 
-   char * GetFullFilePath(char * buffer)
+   char * GetFullFilePath(char * buffer, bool resolveVars)
    {
       if(buffer)
       {
          strcpy(buffer, root.path);
-         PathCatSlash(buffer, path);
-         PathCatSlash(buffer, name);
+         if(resolveVars)
+         {
+            if(path && path[0])
+            {
+               DirExpression pathExp { };
+               Project project = property::project;
+               CompilerConfig compiler = GetCompilerConfig();
+               ProjectConfig config = project.config;
+               int bitDepth = GetBitDepth();
+               pathExp.Evaluate(path, project, compiler, config, bitDepth);
+               PathCatSlash(buffer, pathExp.dir);
+               delete compiler;
+               delete pathExp;
+            }
+            PathCatSlash(buffer, name);
+         }
+         else
+         {
+            PathCatSlash(buffer, path);
+            PathCatSlash(buffer, name);
+         }
+      }
+      return buffer;
+   }
+
+   char * GetObjectFileName(char * buffer, Map<String, NameCollisionInfo> namesInfo, IntermediateFileType type, bool dotMain, const char * objectFileExt)
+   {
+      if(buffer && (this.type == file || (this.type == project && dotMain == true)))
+      {
+         bool collision;
+         char extension[MAX_EXTENSION];
+         char moduleName[MAX_FILENAME];
+         const char * objFileExt = objectFileExt ? objectFileExt : objectDefaultFileExt;
+         NameCollisionInfo info;
+
+         GetExtension(name, extension);
+         ReplaceSpaces(moduleName, name);
+         StripExtension(moduleName);
+         info = namesInfo[moduleName];
+         collision = info ? info.IsExtensionColliding(extension) : false;
+
+         if(dotMain)
+         {
+            Project prj = property::project;
+            ReplaceSpaces(buffer, prj.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, ".");
+               strcat(buffer, objFileExt);
+            }
+            else
+               ChangeExtension(buffer, objFileExt, buffer);
+         }
       }
       return buffer;
    }
@@ -500,7 +631,6 @@ private:
       // TODO: Check how to fix duplication of following options when configuration is made per-config-per-file
       while((node = nodeStack.lastIterator.data))
       {
-         ProjectConfig config = GetMatchingNodeConfig(prjConfig);
          ProjectOptions nodeOptions = node.property::options;
          if(nodeOptions && nodeOptions.preprocessorDefinitions)
          {
@@ -536,9 +666,9 @@ private:
          while(n && n.type != project) n = n.parent;
          return n ? (*&n.project) : null;
       }
-   }   
+   }
 
-   void RenameConfig(char * oldName, char * newName)
+   void RenameConfig(const char * oldName, const char * newName)
    {
       if(files)
       {
@@ -567,7 +697,7 @@ private:
          {
             ProjectConfig config = c.data;
             if(!strcmp(configToDelete.name, config.name))
-            {               
+            {
                c.Remove();
                delete config;
                break;
@@ -686,7 +816,7 @@ private:
       }
    }
 
-   char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
    {
       if(!needClass)
       {
@@ -753,7 +883,8 @@ private:
       // note: unknown platform is for common
       Map<Platform, SetBool> exclusionInfo { };
       MapNode<Platform, SetBool> mn;
-      char * exp, * var;
+      char * exp;
+      const char * var;
       int len;
       SetBool common;
 
@@ -785,7 +916,7 @@ private:
             {
                if(mn.key != unknown)
                {
-                  char * comma = mn.next ? "," : "";
+                  const char * comma = mn.next ? "," : "";
 
                   var = PlatformToMakefileTargetVariable(mn.key);
 
@@ -834,7 +965,7 @@ private:
          result.b = exp;
       }
       delete exclusionInfo;
-      
+
       return result;
    }
 
@@ -866,6 +997,19 @@ private:
       return result;
    }
 
+   bool GetIsExcludedForCompiler(ProjectConfig prjConfig, CompilerConfig compiler)
+   {
+      bool result;
+      Map<Platform, SetBool> exclusionInfo { };
+      SetBool common, platform;
+      CollectExclusionInfo(exclusionInfo, prjConfig);
+      common = exclusionInfo[unknown];
+      platform = exclusionInfo[compiler.targetPlatform];
+      result = platform == true || (common == true && platform == unset);
+      delete exclusionInfo;
+      return result;
+   }
+
    void CollectExclusionInfo(Map<Platform, SetBool> output, ProjectConfig prjConfig)
    {
       // note: unknown platform is for common
@@ -873,7 +1017,6 @@ private:
       ProjectConfig config = GetMatchingNodeConfig(prjConfig);
       ProjectOptions options = property::options;
       Array<PlatformOptions> platforms = property::platforms;
-      List<ProjectConfig> configurations = property::configurations;
 
       if(parent)
          parent.CollectExclusionInfo(output, prjConfig);
@@ -882,7 +1025,7 @@ private:
 
       if(options && options.excludeFromBuild)
          output[unknown] = options.excludeFromBuild;
-      
+
       if(config && config.options && config.options.excludeFromBuild)
          output[unknown] = config.options.excludeFromBuild;
 
@@ -917,7 +1060,7 @@ private:
          parent.files.Delete(this);
    }
 
-   ProjectNode Find(char * name, bool includeResources)
+   ProjectNode Find(const char * name, bool includeResources)
    {
       ProjectNode result = null;
       if(files)
@@ -940,7 +1083,7 @@ private:
       return result;
    }
 
-   ProjectNode FindWithPath(char * name, bool includeResources)
+   ProjectNode FindWithPath(const char * name, bool includeResources)
    {
       ProjectNode result = null;
       if(files)
@@ -969,7 +1112,18 @@ private:
       return result;
    }
 
-   ProjectNode FindByFullPath(char * path, bool includeResources)
+   ProjectNode FindByFullPath(const char * path, bool includeResources)
+   {
+      if(files)
+      {
+         char name[MAX_FILENAME];
+         GetLastDirectory(path, name);
+         return InternalFindByFullPath(path, includeResources, name);
+      }
+      return null;
+   }
+
+   ProjectNode InternalFindByFullPath(const char * path, bool includeResources, const char * lastDirName)
    {
       ProjectNode result = null;
       if(files)
@@ -978,17 +1132,18 @@ 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 && !fstrcmp(lastDirName, child.name))
                {
                   char p[MAX_LOCATION];
-                  child.GetFullFilePath(p);
-                  if(!strcmpi(p, path))
+                  child.GetFullFilePath(p, true);
+                  if(!fstrcmp(p, path))
                   {
                      result = child;
                      break;
                   }
                }
-               result = child.FindByFullPath(path, includeResources);
                if(result)
                   break;
             }
@@ -997,7 +1152,37 @@ private:
       return result;
    }
 
-   ProjectNode FindSpecial(char * name, bool recursive, bool includeResources, bool includeFolders)
+   ProjectNode FindByObjectFileName(const char * fileName, IntermediateFileType type, bool dotMain, Map<String, NameCollisionInfo> namesInfo, const char * objectFileExt)
+   {
+      char p[MAX_LOCATION];
+      ProjectNode result = null;
+      if(dotMain == true && this.type == project)
+      {
+         GetObjectFileName(p, namesInfo, type, dotMain, objectFileExt);
+         if(!fstrcmp(p, fileName))
+            result = this;
+      }
+      else if(files)
+      {
+         for(child : files; child.type != resources)
+         {
+            if(child.type != file && (result = child.FindByObjectFileName(fileName, type, dotMain, namesInfo, objectFileExt)))
+               break;
+            else if(child.type == file && child.name)
+            {
+               child.GetObjectFileName(p, namesInfo, type, dotMain, objectFileExt);
+               if(!fstrcmp(p, fileName))
+               {
+                  result = child;
+                  break;
+               }
+            }
+         }
+      }
+      return result;
+   }
+
+   ProjectNode FindSpecial(const char * name, bool recursive, bool includeResources, bool includeFolders)
    {
       ProjectNode result = null;
       if(files)
@@ -1021,7 +1206,7 @@ private:
       return result;
    }
 
-   ProjectNode FindSameNameConflict(char * name, bool includeResources,
+   ProjectNode FindSameNameConflict(const char * name, bool includeResources,
       Map<Platform, SetBool> exclusionInfo, ProjectConfig prjConfig)
    {
       ProjectNode result = null;
@@ -1079,62 +1264,64 @@ private:
       return result;
    }
 
-   ProjectNode Add(Project project, char * filePath, ProjectNode after, NodeTypes type, NodeIcons icon, bool checkIfExists)
+   ProjectNode Add(Project project, const 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;
    }
 
-#ifndef MAKEFILE_GENERATOR
+#if !defined(ECERE_DOCUMENTOR) && !defined(ECERE_EPJ2MAKE)
    void OnDisplay(Surface surface, int x, int y, int width, ProjectView projectView, Alignment alignment, DataDisplayFlags displayFlags)
    {
       char label[MAX_FILENAME];
-      int indent = 16;
       int xStart;
       int len;
       int w, h;
@@ -1145,10 +1332,10 @@ private:
       {
          showConfig = false;
          projectView = ide.projectView;
-      }         
-      
+      }
+
       bmp = projectView.icons[icon].bitmap;
-      xStart = /*indent * indent + */x + (bmp ? (bmp.width + 5) : 0);
+      xStart = x + (bmp ? (bmp.width + 5) : 0);
 
       GetLastDirectory(name, label);
       if(!showConfig || projectView.drawingInProjectSettingsDialogHeader)
@@ -1157,8 +1344,7 @@ private:
          {
             if(projectView.projectSettingsDialog && projectView.projectSettingsDialog.buildTab)
             {
-               char * addendum;
-               addendum = projectView.projectSettingsDialog.buildTab.selectedConfigName;
+               const char * addendum = projectView.projectSettingsDialog.buildTab.selectedConfigName;
                if(strlen(addendum))
                {
                   strcat(label, " (");
@@ -1189,7 +1375,7 @@ private:
          }
       }
       len = strlen(label);
-      
+
       if(!bmp)
       {
          if(type == folder || type == folderOpen)
@@ -1200,15 +1386,15 @@ private:
       surface.TextOpacity(false);
       surface.TextExtent(label, len, &w, &h);
       h = Max(h, 16);
-    
+
       // Draw the current row stipple
       if(displayFlags.selected)
          //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
          //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
          surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
-      
+
       surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
-      
+
       if(!app.textMode)
       {
          if(displayFlags.current)
@@ -1240,7 +1426,7 @@ private:
 
    int OnCompare(ProjectNode b)
    {
-      int result;
+      int result = 0;
       if(type == b.type /*|| type >= TYPE_DRIVE*/)
          result = strcmpi(name, b.name);
       else
@@ -1251,9 +1437,9 @@ private:
       return result;
    }
 
-   bool ContainsFilesWithExtension(char * extension)
+   bool ContainsFilesWithExtension(const char * extension, ProjectConfig prjConfig)
    {
-      if(type == file)
+      if(type == file && name && name[0])
       {
          char ext[MAX_EXTENSION];
          GetExtension(name, ext);
@@ -1262,10 +1448,14 @@ private:
       }
       else if(files)
       {
-         bool needed = false;
          for(child : files)
-            if(child.ContainsFilesWithExtension(extension))
-               return true;
+         {
+            if(child.type != resources && (child.type == folder || !prjConfig || !child.GetIsExcluded(prjConfig)))
+            {
+               if(child.ContainsFilesWithExtension(extension, prjConfig))
+                  return true;
+            }
+         }
       }
       return false;
    }
@@ -1277,8 +1467,8 @@ private:
          char extension[MAX_EXTENSION];
          GetExtension(name, extension);
          if(!strcmpi(extension, "ec") || !strcmpi(extension, "s") || !strcmpi(extension, "c") ||
-               !strcmpi(extension, "cpp") || !strcmpi(extension, "cc") ||
-               !strcmpi(extension, "cxx") || !strcmpi(extension, "m"))
+               !strcmpi(extension, "rc") || !strcmpi(extension, "cpp") || !strcmpi(extension, "cc") ||
+               !strcmpi(extension, "cxx") || !strcmpi(extension, "m") || !strcmpi(extension, "mm"))
          {
             char moduleName[MAX_FILENAME];
             NameCollisionInfo info;
@@ -1294,6 +1484,8 @@ private:
                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"))
@@ -1302,6 +1494,8 @@ private:
                info.cxx = true;
             else if(!strcmpi(extension, "m"))
                info.m = true;
+            else if(!strcmpi(extension, "mm"))
+               info.mm = true;
             namesInfo[moduleName] = info;
          }
       }
@@ -1314,7 +1508,7 @@ private:
          }
       }
    }
-   
+
    int GenMakefilePrintNode(File f, Project project, GenMakefilePrintTypes printType,
       Map<String, NameCollisionInfo> namesInfo, Array<String> items,
       ProjectConfig prjConfig, bool * containsCXX)
@@ -1345,7 +1539,7 @@ 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));
          }
@@ -1353,12 +1547,11 @@ private:
          {
             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));
             }
@@ -1368,9 +1561,20 @@ 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(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++;
@@ -1378,22 +1582,23 @@ private:
          }
          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;
-               sprintf(s, "%s$(OBJ)%s%s%s.o%s", ts.a, moduleName, collision ? "." : "", collision ? extension : "", ts.b);
+               sprintf(s, "%s$(OBJ)%s%s%s$(O)%s", ts.a, moduleName, collision ? "." : "", collision ? extension : "", ts.b);
                items.Add(CopyString(s));
-               if(containsCXX && (!strcmpi(extension, "cpp") || !strcmpi(extension, "cc") || !strcmpi(extension, "cxx")))
-                  *containsCXX = true;
             }
+            else if(printType == noPrint && containsCXX &&
+                  (!strcmpi(extension, "cpp") || !strcmpi(extension, "cc") || !strcmpi(extension, "cxx")))
+               *containsCXX = true;
          }
          delete ts;
       }
@@ -1428,8 +1633,8 @@ private:
          GetExtension(name, extension);
          if(!strcmpi(extension, "ec"))
          {
-            DualPipe dep;
-            char command[2048];
+            //DualPipe dep;
+            //char command[2048];
 
             ReplaceSpaces(moduleName, name);
             StripExtension(moduleName);
@@ -1476,7 +1681,7 @@ private:
             }
 
             // Execute it
-            if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
+            if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
             {
                char line[1024];
                bool firstLine = true;
@@ -1519,8 +1724,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 $(call quote_path,%s%s.%s) -o $(call quote_path,$@)\n",
+                     modulePath, moduleName, extension);
                   if(ifCount) f.Puts("endif\n");
                   f.Puts("\n");
 #if 0
@@ -1531,19 +1736,7 @@ private:
       }
       if(files)
       {
-         bool needed = false;
-         if(ContainsFilesWithExtension("ec"))
-         {
-            for(child : files)
-            {
-               if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               {
-                  needed = true;
-                  break;
-               }
-            }
-         }
-         if(needed)
+         if(ContainsFilesWithExtension("ec", prjConfig))
          {
             for(child : files)
             {
@@ -1561,7 +1754,6 @@ private:
          Map<intptr, int> nodeCFlagsMapping, Map<intptr, int> nodeECFlagsMapping)
    {
       int ifCount = 0;
-      ProjectConfig config = GetMatchingNodeConfig(prjConfig);
       Array<Platform> platforms = GetPlatformsArrayFromExclusionInfo(prjConfig);
       //ProjectNode child;
       //char objDir[MAX_LOCATION];
@@ -1577,9 +1769,6 @@ private:
          GetExtension(name, extension);
          if(!strcmpi(extension, "ec"))
          {
-            DualPipe dep;
-            char command[2048];
-
             ReplaceSpaces(moduleName, name);
             StripExtension(moduleName);
 
@@ -1589,7 +1778,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);*/
 
@@ -1608,19 +1796,7 @@ private:
       }
       if(files)
       {
-         bool needed = false;
-         if(ContainsFilesWithExtension("ec"))
-         {
-            for(child : files)
-            {
-               if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               {
-                  needed = true;
-                  break;
-               }
-            }
-         }
-         if(needed)
+         if(ContainsFilesWithExtension("ec", prjConfig))
          {
             for(child : files)
             {
@@ -1638,7 +1814,6 @@ private:
       Map<intptr, int> nodeCFlagsMapping, Map<intptr, int> nodeECFlagsMapping)
    {
       int ifCount = 0;
-      ProjectConfig config = GetMatchingNodeConfig(prjConfig);
       Array<Platform> platforms = GetPlatformsArrayFromExclusionInfo(prjConfig);
       //ProjectNode child;
       //char objDir[MAX_LOCATION];
@@ -1653,8 +1828,8 @@ private:
          GetExtension(name, extension);
          if(!strcmpi(extension, "ec"))
          {
-            DualPipe dep;
-            char command[2048];
+            //DualPipe dep;
+            //char command[2048];
 
             ReplaceSpaces(moduleName, name);
             StripExtension(moduleName);
@@ -1701,7 +1876,7 @@ private:
             }
 
             // Execute it
-            if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
+            if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
             {
                char line[1024];
                bool result = true;
@@ -1756,27 +1931,15 @@ 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 $(call quote_path,%s%s.%s) -o $(call quote_path,$@) -symbols $(OBJ)\n",
+               modulePath, moduleName, extension);
             if(ifCount) f.Puts("endif\n");
             f.Puts("\n");
          }
       }
       if(files)
       {
-         bool needed = false;
-         if(ContainsFilesWithExtension("ec"))
-         {
-            for(child : files)
-            {
-               if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               {
-                  needed = true;
-                  break;
-               }
-            }
-         }
-         if(needed)
+         if(ContainsFilesWithExtension("ec", prjConfig))
          {
             for(child : files)
             {
@@ -1796,7 +1959,6 @@ private:
       Map<intptr, int> nodeCFlagsMapping, Map<intptr, int> nodeECFlagsMapping)
    {
       int ifCount = 0;
-      ProjectConfig config = GetMatchingNodeConfig(prjConfig);
       Array<Platform> platforms = GetPlatformsArrayFromExclusionInfo(prjConfig);
       //ProjectNode child;
       //char objDir[MAX_LOCATION];
@@ -1810,15 +1972,12 @@ 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, "s") || !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];
+            //DualPipe dep;
+            //char command[2048];
             NameCollisionInfo info;
 
             ReplaceSpaces(moduleName, name);
@@ -1826,10 +1985,12 @@ private:
 
             info = namesInfo[moduleName];
             collision = info ? info.IsExtensionColliding(extension) : false;
-            
+
             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);
@@ -1837,9 +1998,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);
@@ -1879,7 +2037,7 @@ private:
                }
 
                // Execute it
-               if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
+               if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true, input = false }, command)))
                {
                   char line[1024];
                   bool firstLine = true;
@@ -1917,23 +2075,38 @@ private:
             }
 #endif
          */
-            if(!strcmpi(extension, "ec"))
-               f.Printf("$(OBJ)%s.o: $(OBJ)%s.c\n", moduleName, moduleName);
+            if(!strcmpi(extension, "rc"))
+            {
+               ifCount++;
+               f.Puts("ifdef WINDOWS_TARGET\n\n");
+            }
             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);
+               OpenRulesPlatformExclusionIfs(f, &ifCount, platforms);
 
             if(!strcmpi(extension, "ec"))
-               f.Printf(" $(FVISIBILITY) -c $(OBJ)%s.c -o $(OBJ)%s.o\n", moduleName, moduleName);
+               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);
+            if(!strcmpi(extension, "cc") || !strcmpi(extension, "cpp") || !strcmpi(extension, "cxx"))
+               f.Printf("\t$(CXX) $(CXXFLAGS)");
+            else if(!strcmpi(extension, "rc"))
+               f.Printf("\t$(WINDRES) $(WINDRES_FLAGS) $< \"$(call escspace,$(call quote_path,$@))\"\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) $(CFLAGS)");
+
+            if(strcmpi(extension, "rc") != 0)
+            {
+               GenMakePrintNodeFlagsVariable(this, nodeCFlagsMapping, "PRJ_CFLAGS", f);
 
+               if(!strcmpi(extension, "ec"))
+                  f.Printf(" $(FVISIBILITY) -c $(call quote_path,$(OBJ)%s.c) -o $(call quote_path,$@)\n",
+                        moduleName);
+               else
+                  f.Printf(" -c $(call quote_path,%s%s.%s) -o $(call quote_path,$@)\n",
+                        modulePath, moduleName, !strcmpi(extension, "ec") ? "c" : extension);
+            }
             if(ifCount) f.Puts("endif\n");
             f.Puts("\n");
          }
@@ -1962,7 +2135,7 @@ private:
       delete platforms;
    }
 
-   void GenMakefileAddResources(File f, String resourcesPath, ProjectConfig prjConfig)
+   void GenMakefileAddResources(File f, String resourcesPath, ProjectConfig prjConfig, const char * resourcesTarget)
    {
       int count = 0;
       if(files)
@@ -1985,11 +2158,9 @@ 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);
+                  f.Printf("\t%s$(EAR) aw$(EARFLAGS) $(%s)", ts.a, resourcesTarget);
 
                tempPath[0] = '\0';
                if(eString_PathInsideOfMore(child.path, resourcesPath, tempPath))
@@ -2003,12 +2174,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)))
@@ -2039,7 +2206,7 @@ private:
          for(child : files)
          {
             if(child.type == folder)
-               child.GenMakefileAddResources(f, resourcesPath, prjConfig);
+               child.GenMakefileAddResources(f, resourcesPath, prjConfig, resourcesTarget);
          }
       }
    }
@@ -2209,7 +2376,6 @@ private:
                nodeECFlagsMapping[(intptr)this] = nodeECFlagsMapping[(intptr)parent];
             }
          }
-
       }
       if(files)
       {
@@ -2264,31 +2430,90 @@ private:
       return platforms;
    }
 
-   void GetTargets(ProjectConfig prjConfig, Map<String, NameCollisionInfo> namesInfo, char * objDir, DynamicString output)
+   void GetTargets(ProjectConfig prjConfig, Map<String, NameCollisionInfo> namesInfo, char * objDir, const char * objectFileExt, DynamicString output)
    {
+      char moduleName[MAX_FILENAME];
       if(type == file)
       {
+         bool headerAltFailed = false;
          bool collision;
          char extension[MAX_EXTENSION];
-         char moduleName[MAX_FILENAME];
          NameCollisionInfo info;
          Project prj = property::project;
+         Map<String, const String> headerToSource { [ { "eh", "ec" }, { "h", "c" }, { "hh", "cc" }, { "hpp", "cpp" }, { "hxx", "cxx" } ] };
 
          GetExtension(name, extension);
-         ReplaceSpaces(moduleName, name);
+         strcpy(moduleName, name);
          StripExtension(moduleName);
          info = namesInfo[moduleName];
          collision = info ? info.IsExtensionColliding(extension) : false;
 
-         output.concat(" \"");
-         output.concat(objDir); //.concat(" $(OBJ)");
-         output.concat("/");
-         if(collision)
+         for(h2s : headerToSource)
+         {
+            if(!strcmpi(extension, &h2s))
+            {
+               char filePath[MAX_LOCATION];
+               GetFullFilePath(filePath, true);
+               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, ".");
-            strcat(moduleName, extension);
+            strcat(moduleName, objectFileExt);
+            output.concat(moduleName);
+            output.concat("\"");
          }
-         strcat(moduleName, ".o");
+      }
+      else if(type == project && ContainsFilesWithExtension("ec", prjConfig))
+      {
+         Project prj = property::project;
+
+         ReplaceSpaces(moduleName, prj.moduleName);
+         strcat(moduleName, ".main.ec");
+         output.concat(" \"");
+         output.concat(objDir);
+         output.concat("/");
+         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("\"");
       }
@@ -2297,22 +2522,23 @@ private:
          for(child : files)
          {
             if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               child.GetTargets(prjConfig, namesInfo, objDir, output);
+               child.GetTargets(prjConfig, namesInfo, objDir, objectFileExt, output);
          }
       }
    }
 
-   void DeleteIntermediateFiles(CompilerConfig compiler, ProjectConfig prjConfig, Map<String, NameCollisionInfo> namesInfo)
+   void DeleteIntermediateFiles(CompilerConfig compiler, ProjectConfig prjConfig, int bitDepth, Map<String, NameCollisionInfo> namesInfo, bool onlyCObject)
    {
       if(type == file)
       {
          bool collision;
+         const char * objectFileExt = compiler ? compiler.objectFileExt : objectDefaultFileExt;
          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);
@@ -2324,7 +2550,7 @@ private:
          PathCatSlash(fileName, objDir.dir);
          PathCatSlash(fileName, name);
 
-         if(!strcmp(extension, "ec"))
+         if(!onlyCObject && !strcmp(extension, "ec"))
          {
             ChangeExtension(fileName, "c", fileName);
             if(FileExists(fileName)) DeleteFile(fileName);
@@ -2338,9 +2564,12 @@ private:
          }
 
          if(collision)
-            strcat(fileName, ".o");
+         {
+            strcat(fileName, ".");
+            strcat(fileName, objectFileExt);
+         }
          else
-            ChangeExtension(fileName, "o", fileName);
+            ChangeExtension(fileName, objectFileExt, fileName);
          if(FileExists(fileName)) DeleteFile(fileName);
 
          delete objDir;
@@ -2350,7 +2579,7 @@ private:
          for(child : files)
          {
             if(child.type != resources && (child.type == folder || !child.GetIsExcluded(prjConfig)))
-               child.DeleteIntermediateFiles(compiler, prjConfig, namesInfo);
+               child.DeleteIntermediateFiles(compiler, prjConfig, bitDepth, namesInfo, onlyCObject);
          }
       }
    }
@@ -2385,16 +2614,16 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
    //         p Platform
    //         u Utility (GenericOptionTools)
 
-   int e;
    int o;
    int priority = 0;
    int includeDirsOption = OPTION(includeDirs);
    ProjectNode n;
-   char * platformName = platform ? platform.OnGetString(0,0,0) : null;
+   const char * platformName = platform ? platform.OnGetString(0,0,0) : null;
 
-   Array<bool> optionConfigXplatformSet   { size = OPTION(postbuildCommands) };
-   Array<bool> optionDone                 { size = OPTION(postbuildCommands) };
-   Array<Array<String>> optionTempStrings { size = OPTION(postbuildCommands) };
+   // OPTION(ProjectOptions' last member) for size
+   Array<bool> optionConfigXplatformSet   { size = OPTION(installCommands) };
+   Array<bool> optionDone                 { size = OPTION(installCommands) };
+   Array<Array<String>> optionTempStrings { size = OPTION(installCommands) };
 
    GenericOptionTools<SetBool>              utilSetBool {
       bool OptionCheck(ProjectOptions options, int option) {
@@ -2430,7 +2659,7 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
       void LoadOption(ProjectOptions options, int option, int priority, Array<Array<String>> optionTempStrings, ProjectOptions output) {
          if(mergeValues)
          {
-            Array<String> strings = options ? *((Array<String>*)((byte *)options + option) : null;
+            Array<String> strings = options ? *(Array<String>*)((byte *)options + option) : null;
             if(strings)
             {
                int order = 0;
@@ -2488,16 +2717,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 { };
 
@@ -2519,8 +2738,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;
@@ -2613,7 +2830,6 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
    delete utilStringArrays;
    delete utilWarningsOption;
    delete utilOptimizationStrategy;
-   delete utilBuildBitDepth;
 
    delete ot;
 
@@ -2622,9 +2838,7 @@ static ProjectOptions BlendFileConfigPlatformProjectOptions(ProjectNode node, Pr
 
 static void CollectPlatformsCommonOptions(Map<Platform, ProjectOptions> byPlatformOptions, ProjectOptions * platformsCommonOptions)
 {
-   char * s;
-   int i;
-   ProjectOptions first;
+   ProjectOptions first = null;
    ProjectOptions commonOptions;
 
    Map<String, int> countIncludeDirs { };
@@ -2634,7 +2848,7 @@ static void CollectPlatformsCommonOptions(Map<Platform, ProjectOptions> byPlatfo
 
    for(options : byPlatformOptions) { first = options; break; }
 
-   *platformsCommonOptions = commonOptions = first.Copy();
+   *platformsCommonOptions = commonOptions = first ? first.Copy() : { };
 
    if(commonOptions.includeDirs)
       commonOptions.includeDirs.Free();
@@ -2662,8 +2876,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;
@@ -2697,8 +2909,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;
@@ -2797,7 +3007,8 @@ static bool StringsAreSameOrMore(Array<String> strings, Array<String> originals,
             break;
          }
          else
-            map[s] = null;
+            mit.Remove();
+            // TOFIX: Templates map[s] = null;
       }
       if(result)
       {
@@ -2834,7 +3045,7 @@ static void GetPlatformsCommonStrings(Map<String, int> counts, int goodCount, Ma
       int i = it;
       if(i == goodCount)
       {
-         char * s = &it;
+         const char * s = &it;
          strings.Add(CopyString(s));
          common[s] = true;
       }
@@ -2864,7 +3075,7 @@ static void RemovePlatformsCommonStrings(Map<String, bool> common, Array<String>
    }
 }
 
-static void GenMakePrintNodeFlagsVariable(ProjectNode node, Map<intptr, int> nodeFlagsMapping, String variableName, File f)
+static void GenMakePrintNodeFlagsVariable(ProjectNode node, Map<intptr, int> nodeFlagsMapping, const String variableName, File f)
 {
    int customFlags;
    customFlags = nodeFlagsMapping[(intptr)node];
@@ -2874,7 +3085,7 @@ static void GenMakePrintNodeFlagsVariable(ProjectNode node, Map<intptr, int> nod
       f.Printf(" $(%s)", variableName);
 }
 
-static void DynStringPrintNodeFlagsVariable(ProjectNode node, Map<intptr, int> nodeFlagsMapping, String variableName, DynamicString s)
+static void DynStringPrintNodeFlagsVariable(ProjectNode node, Map<intptr, int> nodeFlagsMapping, const String variableName, DynamicString s)
 {
    int customFlags;
    customFlags = nodeFlagsMapping[(intptr)node];
@@ -2913,8 +3124,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)");
       }
@@ -2925,12 +3134,14 @@ static void GenCFlagsFromProjectOptions(ProjectOptions options, bool prjWithEcFi
       }
       if(options.profile)
          s.concat(" -pg");
+      if(commonOptions)
+         s.concat(" -DREPOSITORY_VERSION=\"\\\"$(REPOSITORY_VER)\\\"\"");
    }
 
    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)
@@ -2945,15 +3156,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, const 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)
       {
@@ -2964,17 +3175,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;
       }
@@ -2982,17 +3190,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);
          }
       }
    }
@@ -3028,10 +3233,12 @@ 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)
@@ -3039,11 +3246,13 @@ class NameCollisionInfo
       bool colliding;
       if(count > 1 &&
             ((!strcmpi(extension, "c")   && ec) ||
-             (!strcmpi(extension, "s")   && (ec || c)) ||
-             (!strcmpi(extension, "cpp") && (ec || c || s)) ||
-             (!strcmpi(extension, "cc")  && (ec || c || s || cpp)) ||
-             (!strcmpi(extension, "cxx") && (ec || c || s || cpp || cc)) ||
-              !strcmpi(extension, "m")))
+             (!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;