buildsystem, epj2make, ide: support Emscripten compiler.
[sdk] / ide / src / project / ProjectConfig.ec
index 2cbb556..362b542 100644 (file)
@@ -16,7 +16,7 @@ class DirExpression : struct
       delete dir;
    }
 
-   property char * dir
+   property const char * dir
    {
       get
       {
@@ -32,13 +32,12 @@ class DirExpression : struct
       }
    }
 
-   void Evaluate(char * expression, Project project, CompilerConfig compiler, ProjectConfig config)
+   void Evaluate(const char * expression, Project project, CompilerConfig compiler, ProjectConfig config, int bitDepth)
    {
       int len;
-      char * expr = expression;
+      const char * expr = expression;
       if(!expr || !expr[0])
       {
-         char buffer[MAX_LOCATION];
          if(ideSettings)
          {
          if(type == targetDir)
@@ -52,17 +51,17 @@ class DirExpression : struct
       if((len = strlen(expr)))
       {
          int c, d;
-         char * configName = config && config.name && config.name[0] ? config.name : "Common";
-         char * projectName = project.name ? project.name : "";
-         char * moduleName = project.moduleName ? project.moduleName : "";
-         char * compilerName = (compiler && compiler.name) ? compiler.name : defaultCompilerName;
-         char * targetPlatformName = compiler && compiler.targetPlatform ? compiler.targetPlatform : "";
+         const char * configName = config && config.name && config.name[0] ? config.name : "Common";
+         const char * moduleName = project && project.moduleName ? project.moduleName : "";
+         const char * compilerName = (compiler && compiler.name) ? compiler.name : defaultCompilerName;
+         const char * targetPlatformName = compiler && compiler.targetPlatform ? compiler.targetPlatform : "";
          char buffer[MAX_LOCATION];
          for(c = 0, d = 0; c < len; c++)
          {
             if(expr[c] == '$' && c < len - 1 && expr[c + 1] == '(')
             {
                int i;
+               bool matched = false;
                for(i = c + 2; i < len; i++)
                {
                   if(expr[i] == ')')
@@ -77,6 +76,7 @@ class DirExpression : struct
                            CamelCase(&buffer[d]);
                            d += strlen(configName);
                            c = i;
+                           matched = true;
                         }
                         else if(!strnicmp(&expr[c + 2], "Module", n) || !strnicmp(&expr[c + 2], "Project", n))
                         {
@@ -85,6 +85,7 @@ class DirExpression : struct
                            //CamelCase(&buffer[d]);
                            d += strlen(moduleName);
                            c = i;
+                           matched = true;
                         }
                         else if(!strnicmp(&expr[c + 2], "Platform", n))
                         {
@@ -93,6 +94,7 @@ class DirExpression : struct
                            CamelCase(&buffer[d]);
                            d += strlen(targetPlatformName);
                            c = i;
+                           matched = true;
                         }
                         else if(!strnicmp(&expr[c + 2], "Compiler", n))
                         {
@@ -101,30 +103,57 @@ class DirExpression : struct
                            CamelCase(&buffer[d]);
                            d += strlen(compilerName);
                            c = i;
+                           matched = true;
                         }
                         else if(!strnicmp(&expr[c + 2], "Debug_Suffix", n))
                         {
                            // We don't support .debug from the IDE yet...
                            c = i;
+                           matched = true;
                         }
                         else if(!strnicmp(&expr[c + 2], "Compiler_Suffix", n))
                         {
-                           if(compilerName[0] && strcmpi(compilerName, "default"))
+                           if(bitDepth || (compilerName[0] && strcmpi(compilerName, "default")))
                            {
-                              buffer[d] = '.';
-                              buffer[d+1] = '\0';
-                              strcat(buffer, compilerName);
-                              CamelCase(&buffer[d]);
-                              d += strlen(compilerName)+1;
-                              c = i;
+                              if(compilerName[0] && strcmpi(compilerName, "default"))
+                              {
+                                 buffer[d++] = '.';
+                                 buffer[d] = '\0';
+                                 strcat(buffer, compilerName);
+                                 CamelCase(&buffer[d]);
+                                 d += strlen(compilerName);
+                              }
+                              if(bitDepth == 32)
+                              {
+                                 strcat(buffer, ".x32");
+                                 d += 4;
+                              }
+                              else if(bitDepth == 64)
+                              {
+                                 strcat(buffer, ".x64");
+                                 d += 4;
+                              }
                            }
-                           else
-                              c = i;
+                           c = i;
+                           matched = true;
                         }
-                        else
+                        else if(compiler && compiler.environmentVars && compiler.environmentVars.count)
                         {
-                           buffer[d++] = expr[c];
+                           for(ev : compiler.environmentVars;
+                                 ev.name && ev.string && ev.name[0] && ev.string[0] && !strnicmp(&expr[c + 2], ev.name, n) && strlen(ev.name) == n)
+                           {
+                              buffer[d] = '\0';
+                              ChangeCh(ev.string, '\\', '/');
+                              strcat(buffer, ev.string);
+                              ChangeCh(ev.string, '/', '\\');
+                              d += strlen(ev.string);
+                              c = i;
+                              matched = true;
+                              break;
+                           }
                         }
+                        if(!matched)
+                           buffer[d++] = expr[c];
                      }
                      else
                      {
@@ -248,6 +277,7 @@ public:
       isset { return objectsDirectory != null/*&& objectsDirectory[0]*/; }
    }
    Array<String> libraries;
+   Array<String> compilerOptions;
    Array<String> linkerOptions;
    property Array<String> libraryDirs
    {
@@ -273,6 +303,7 @@ public:
    SetBool console;
    SetBool compress;
 
+   // todo; move those to compiler/linker sections
    SetBool excludeFromBuild;
    BuildBitDepth buildBitDepth;
    SetBool fastMath;
@@ -319,6 +350,27 @@ public:
       get { return postbuildCommands; }
       isset { return  postbuildCommands && postbuildCommands.count; }
    }
+   property Array<String> installCommands
+   {
+      set
+      {
+         if(installCommands)
+            installCommands.Free();
+         if(value && value.count)
+         {
+            if(!installCommands)
+               installCommands = { };
+            for(s : value)
+               installCommands.Add(CopyValidateMakefilePath(s));
+            value.Free();
+            delete value;
+         }
+         else
+            delete installCommands;
+      }
+      get { return installCommands; }
+      isset { return  installCommands && installCommands.count; }
+   }
 
    ProjectOptions Copy()
    {
@@ -340,18 +392,46 @@ public:
          console = console,
          compress = compress,
          excludeFromBuild = excludeFromBuild,
-         buildBitDepth = buildBitDepth,
          fastMath = fastMath,
          preprocessorDefinitions = CopyArrayString(preprocessorDefinitions),
          includeDirs = CopyArrayString(includeDirs),
          libraries = CopyArrayString(libraries),
+         compilerOptions = CopyArrayString(compilerOptions),
          linkerOptions = CopyArrayString(linkerOptions),
          libraryDirs = CopyArrayString(libraryDirs),
          prebuildCommands = CopyArrayString(prebuildCommands),
-         postbuildCommands = CopyArrayString(postbuildCommands)
+         postbuildCommands = CopyArrayString(postbuildCommands),
+         installCommands = CopyArrayString(installCommands)
       };
    }
 
+#ifdef _DEBUG
+   void print()
+   {
+      PrintLn("warnings:", warnings);
+      PrintLn("debug:", debug);
+      PrintLn("memoryGuard:", memoryGuard);
+      PrintLn("profile:", profile);
+      //PrintLn("noLineNumbers:", noLineNumbers);
+      PrintLn("optimization:", optimization);
+
+      //...
+      //PrintLn("dddddddd:", dddddddd);
+
+      PrintLn("fastMath:", fastMath);
+
+      PrintLn("preprocessorDefinitions:", preprocessorDefinitions);
+      PrintLn("compilerOptions:", compilerOptions);
+      PrintLn("linkerOptions:", linkerOptions);
+      PrintLn("includeDirs:", includeDirs);
+
+      //...
+      //PrintLn("dddddddd:", dddddddd);
+
+      PrintLn("");
+   }
+#endif
+
    ~ProjectOptions()
    {
       if(preprocessorDefinitions) { preprocessorDefinitions.Free(); delete preprocessorDefinitions; }
@@ -361,10 +441,12 @@ public:
       delete targetDirectory;
       delete objectsDirectory;
       if(libraries) { libraries.Free(); delete libraries; }
+      if(compilerOptions) { compilerOptions.Free(); delete compilerOptions; }
       if(linkerOptions) { linkerOptions.Free(); delete linkerOptions; }
       if(libraryDirs) { libraryDirs.Free(); delete libraryDirs; }
       if(prebuildCommands) { prebuildCommands.Free(); delete prebuildCommands; }
       if(postbuildCommands) { postbuildCommands.Free(); delete postbuildCommands; }
+      if(installCommands) { installCommands.Free(); delete installCommands; }
    }
 private:
    Array<String> includeDirs;
@@ -374,6 +456,7 @@ private:
    Array<String> libraryDirs;
    Array<String> prebuildCommands;
    Array<String> postbuildCommands;
+   Array<String> installCommands;
 
    property bool isEmpty
    {
@@ -394,15 +477,18 @@ private:
             !targetDirectory &&
             !objectsDirectory &&
             !libraries &&
+            !compilerOptions &&
             !linkerOptions &&
             (!libraryDirs || !libraryDirs.count) &&
             console == unset &&
             compress == unset &&
             excludeFromBuild == unset &&
+            fastMath == unset &&
             (!prebuildCommands || !prebuildCommands.count) &&
-            (!postbuildCommands || !postbuildCommands.count) )
+            (!postbuildCommands || !postbuildCommands.count) &&
+            (!installCommands || !installCommands.count))
             return true;
-         return false;          
+         return false;
       }
    }
 }