ecere/com: Fixed 32 bit cross-compiling issues in EDASQLite
[sdk] / compiler / ecs / ecs.ec
index 8004c54..fd06ebd 100644 (file)
@@ -10,6 +10,7 @@ static define localeDir = "locale";
 static bool i18n;
 
 static Platform targetPlatform;
+static int targetBits;
 
 static bool isConsole;
 static bool isDynamicLibrary;
@@ -686,7 +687,7 @@ static void WriteMain(char * fileName)
       }
       if(!isDynamicLibrary && thisAppClass)
       {
-         f.Printf("   __currentModule._vTbl[12](__currentModule);\n");
+         f.Printf("   ((void(*)(void *))(void *)__currentModule._vTbl[12])(__currentModule);\n");
       }
 
       if(isDynamicLibrary)
@@ -911,7 +912,7 @@ static void BindDCOMClient()
                            resultType = MkTypeName(specs, decl);
 
                            f.Printf("            ");
-                           OutputTypeName(resultType, f);
+                           OutputTypeName(resultType, f, false);
                            f.Printf(";\n");
                         }
 
@@ -953,7 +954,7 @@ static void BindDCOMClient()
                               paramTypeName = MkTypeName(specs, decl);
 
                               f.Printf("            ");
-                              OutputTypeName(paramTypeName, f);
+                              OutputTypeName(paramTypeName, f, false);
 
                               f.Printf(";\n");
                            }
@@ -1105,7 +1106,7 @@ static void BindDCOMClient()
                      resultType = MkTypeName(specs, decl);
 
                      f.Printf("      ");
-                     OutputTypeName(resultType, f);
+                     OutputTypeName(resultType, f, false);
                      if(method.dataType.returnType.kind == structType)
                         f.Printf(" = { 0 }");
                      else if(method.dataType.returnType.kind == classType && method.dataType.returnType._class.registered && method.dataType.returnType._class.registered.type == structClass)
@@ -1299,7 +1300,7 @@ static void BindDCOMServer()
                         resultType = MkTypeName(specs, decl);
 
                         f.Printf("            ");
-                        OutputTypeName(resultType, f);
+                        OutputTypeName(resultType, f, false);
                         f.Printf(";\n");
                      }
 
@@ -1341,7 +1342,7 @@ static void BindDCOMServer()
                            paramTypeName = MkTypeName(specs, decl);
 
                            f.Printf("            ");
-                           OutputTypeName(paramTypeName, f);
+                           OutputTypeName(paramTypeName, f, false);
 
                            f.Printf(";\n");
                         }
@@ -1483,7 +1484,7 @@ static void BindDCOMServer()
                            resultType = MkTypeName(specs, decl);
 
                            f.Printf("      ");
-                           OutputTypeName(resultType, f);
+                           OutputTypeName(resultType, f, false);
                            if(method.dataType.returnType.kind == structType)
                               f.Printf(" = { 0 }");
                            else if(method.dataType.returnType.kind == classType && method.dataType.returnType._class.registered && method.dataType.returnType._class.registered.type == structClass)
@@ -1616,6 +1617,7 @@ class SymbolgenApp : Application
       char * output = null;
 
       targetPlatform = GetRuntimePlatform();
+      targetBits = GetHostBits();
 
       /*
       for(c = 0; c<this.argc; c++)
@@ -1649,7 +1651,11 @@ class SymbolgenApp : Application
          char * arg = argv[c];
          if(arg[0] == '-')
          {
-            if(!strcmp(arg+1, "o"))
+            if(!strcmp(arg + 1, "m32") || !strcmp(arg + 1, "m64"))
+            {
+               targetBits = !strcmp(arg + 1, "m32") ? 32 : 64;
+            }
+            else if(!strcmp(arg+1, "o"))
             {
                if(!output && c + 1 < argc)
                {
@@ -1718,8 +1724,10 @@ class SymbolgenApp : Application
          SetTopContext(theGlobalContext);
          SetCurrentContext(theGlobalContext);
          SetTargetPlatform(targetPlatform);
+         SetTargetBits(targetBits);
+         SetInSymbolGen(true);
 
-         privateModule = __ecere_COM_Initialize(true, 1, null);
+         privateModule = (Module)__ecere_COM_Initialize(true | (targetBits == sizeof(uintptr)*8 ? 0 : targetBits == 64 ? 2 : targetBits==32 ? 4 : 0) | 8, 1, null);
          SetPrivateModule(privateModule);
          mainModule = ModuleImport { };
          SetMainModule(mainModule);
@@ -1727,6 +1735,9 @@ class SymbolgenApp : Application
 
          //if(!strcmp(ext, "c"))
          {
+            String symbolsDir = GetSymbolsDir();
+            // Only generating .pot files when building from release.* directory for now
+            bool outputPot = symbolsDir && SearchString(symbolsDir, 0, "release.", false, false);
             Map<ContextStringPair, List<String> > intlStrings { };
             MapIterator<ContextStringPair, List<String>> it { map = intlStrings };
 
@@ -1905,17 +1916,33 @@ class SymbolgenApp : Application
             }
             WriteMain(output);
 
-            if(intlStrings.count)
+            if(outputPot && intlStrings.count)
             {
                File potFile;
                char potFileName[MAX_LOCATION];
                //strcpy(potFileName, output);
                //StripExtension(potFileName);
-               strcpy(potFileName, projectName);
+               strcpy(potFileName, "locale");
+               MakeDir(potFileName);
+               PathCat(potFileName, projectName);
                ChangeExtension(potFileName, "pot", potFileName);
                potFile = FileOpen(potFileName, write);
                if(potFile)
                {
+                  // Write header:
+                  potFile.Puts("msgid \"\"\n");
+                  potFile.Puts("msgstr \"\"\n");
+                  potFile.Puts("\"Project-Id-Version: \\n\"\n");
+                  potFile.Puts("\"POT-Creation-Date: \\n\"\n");
+                  potFile.Puts("\"PO-Revision-Date: \\n\"\n");
+                  potFile.Puts("\"Last-Translator: \\n\"\n");
+                  potFile.Puts("\"Language-Team: \\n\"\n");
+                  potFile.Puts("\"MIME-Version: 1.0\\n\"\n");
+                  potFile.Puts("\"Content-Type: text/plain; charset=iso-8859-1\\n\"\n");
+                  potFile.Puts("\"Content-Transfer-Encoding: 8bit\\n\"\n");
+                  potFile.Puts("\"X-Poedit-Basepath: ../\\n\"\n");
+                  potFile.Puts("\n");
+
                   for(i : intlStrings)
                   {
                      ContextStringPair pair = &i;
@@ -1926,11 +1953,11 @@ class SymbolgenApp : Application
                         potFile.Puts("\n");
                      }
 
-                     potFile.Puts("msgid \""); potFile.Puts(pair.string); potFile.Puts("\"\n");
                      if(pair.context)
                      {
                         potFile.Puts("msgctxt \""); potFile.Puts(pair.context); potFile.Puts("\"\n");
                      }
+                     potFile.Puts("msgid \""); potFile.Puts(pair.string); potFile.Puts("\"\n");
                      potFile.Puts("msgstr \""); potFile.Puts(pair.string); potFile.Puts("\"\n");
                      potFile.Puts("\n");
                   }