ide: tweak compiler config support for specifying output file extensions.
authorRejean Loyer <redj@ecere.com>
Sun, 7 Dec 2014 00:09:06 +0000 (19:09 -0500)
committerRejean Loyer <redj@ecere.com>
Mon, 16 Mar 2015 05:31:58 +0000 (01:31 -0400)
crossplatform.mk
default.cf
ide/src/IDESettings.ec
ide/src/dialogs/GlobalSettingsDialog.ec
ide/src/project/Project.ec
ide/src/project/ProjectView.ec

index 8f829d6..ed9b130 100644 (file)
@@ -237,24 +237,6 @@ else
    quote_path = $(1)
 endif
 
-# PREFIXES AND EXTENSIONS
-EC := .ec
-S := .sym
-I := .imp
-B := .bowl
-C := .c
-ifndef O
-O := .o
-endif
-A := .a
-E := $(if $(WINDOWS_TARGET),.exe,)
-SO := $(if $(WINDOWS_TARGET),.dll,$(if $(OSX_TARGET),.dylib,.so))
-LP := $(if $(WINDOWS_TARGET),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
-HOST_E := $(if $(WINDOWS_HOST),.exe,)
-HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so))
-HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
-.SUFFIXES: .c .ec .sym .imp .bowl $(O) $(A)
-
 # TARGET VERSION
 VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),)
 
index aa3d8aa..b42f82f 100644 (file)
@@ -7,8 +7,22 @@ ifdef WINDOWS_HOST
  endif
 endif
 
-# EXTENSIONS
+# PREFIXES AND EXTENSIONS
+EC := .ec
+S := .sym
+I := .imp
+B := .bowl
+C := .c
+O := .o
+A := .a
+SO := $(if $(WINDOWS_TARGET),.dll,$(if $(OSX_TARGET),.dylib,.so))
+E := $(if $(WINDOWS_TARGET),.exe,)
 OUT := $(if $(STATIC_LIBRARY_TARGET),$(A),$(if $(SHARED_LIBRARY_TARGET),$(SO)$(VER),$(if $(EXECUTABLE_TARGET),$(E),.x)))
+LP := $(if $(WINDOWS_TARGET),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
+HOST_E := $(if $(WINDOWS_HOST),.exe,)
+HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so))
+HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
+.SUFFIXES: .c .ec .sym .imp .bowl $(O) $(A)
 
 # TOOLCHAIN
 export CC      = $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)gcc$(_SYSROOT)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)
index 2314200..53191c2 100644 (file)
@@ -416,8 +416,12 @@ private:
                ccfg.arCommand = arDefaultCommand;
             if(!ccfg.objectFileExt || !ccfg.objectFileExt[0])
                ccfg.objectFileExt = objectDefaultFileExt;
-            /*if(!ccfg.outputFileExt || !ccfg.outputFileExt[0])
-               ccfg.outputFileExt = outputDefaultFileExt;*/
+            /*if(!ccfg.staticLibFileExt || !ccfg.staticLibFileExt[0])
+               ccfg.staticLibFileExt = staticLibDefaultFileExt;*/
+            /*if(!ccfg.sharedLibFileExt || !ccfg.sharedLibFileExt[0])
+               ccfg.sharedLibFileExt = sharedLibDefaultFileExt;*/
+            /*if(!ccfg.executableFileExt || !ccfg.executableFileExt[0])
+               ccfg.executableFileExt = outputDefaultFileExt;*/
             incref ccfg;
          }
       }
@@ -933,17 +937,30 @@ public:
       get { return ldCommand; }
       isset { return ldCommand && ldCommand[0]; }
    }
+   bool noStripTarget;
    property const char * objectFileExt
    {
       set { delete objectFileExt; if(value && value[0]) objectFileExt = CopyString(value); }
       get { return objectFileExt && objectFileExt[0] ? objectFileExt : objectDefaultFileExt ; }
       isset { return objectFileExt && objectFileExt[0] && strcmp(objectFileExt, objectDefaultFileExt); }
    }
-   property const char * outputFileExt
+   property const char * staticLibFileExt
+   {
+      set { delete staticLibFileExt; if(value && value[0]) staticLibFileExt = CopyString(value); }
+      get { return staticLibFileExt; }
+      isset { return staticLibFileExt && staticLibFileExt[0]; }
+   }
+   property const char * sharedLibFileExt
    {
-      set { delete outputFileExt; if(value && value[0]) outputFileExt = CopyString(value); }
-      get { return outputFileExt; }
-      isset { return outputFileExt && outputFileExt[0]; }
+      set { delete sharedLibFileExt; if(value && value[0]) sharedLibFileExt = CopyString(value); }
+      get { return sharedLibFileExt; }
+      isset { return sharedLibFileExt && sharedLibFileExt[0]; }
+   }
+   property const char * executableFileExt
+   {
+      set { delete executableFileExt; if(value && value[0]) executableFileExt = CopyString(value); }
+      get { return executableFileExt; }
+      isset { return executableFileExt && executableFileExt[0]; }
    }
    property const char * executableLauncher
    {
@@ -1114,6 +1131,23 @@ public:
       get { return executableLauncher; }
       isset { return false; }
    }
+   property const char * outputFileExt
+   {
+      set { delete executableFileExt; if(value && value[0]) executableFileExt = CopyString(value); }
+      get { return executableFileExt; }
+      isset { return false; }
+   }
+   // utility
+   property bool hasDocumentOutput
+   {
+      get
+      {
+         bool result = executableFileExt && executableFileExt[0] &&
+               (!strcmpi(executableFileExt, "htm") || !strcmpi(executableFileExt, "html"));
+         return result;
+      }
+      isset { return false; }
+   }
 private:
    Array<String> includeDirs { };
    Array<String> libraryDirs { };
@@ -1138,7 +1172,9 @@ private:
    char * ldCommand;
    char * arCommand;
    char * objectFileExt;
-   char * outputFileExt;
+   char * staticLibFileExt;
+   char * sharedLibFileExt;
+   char * executableFileExt;
    char * executableLauncher;
    char * distccHosts;
    char * gnuToolchainPrefix;
@@ -1162,7 +1198,9 @@ private:
       delete ldCommand;
       delete arCommand;
       delete objectFileExt;
-      delete outputFileExt;
+      delete staticLibFileExt;
+      delete sharedLibFileExt;
+      delete executableFileExt;
       delete makeCommand;
       delete executableLauncher;
       delete distccHosts;
@@ -1199,8 +1237,11 @@ public:
          cxxCommand,
          arCommand,
          ldCommand,
+         noStripTarget,
          objectFileExt,
-         outputFileExt,
+         staticLibFileExt,
+         sharedLibFileExt,
+         executableFileExt,
          executableLauncher,
          ccacheEnabled,
          distccEnabled,
index 620bb2c..989fe48 100755 (executable)
@@ -849,9 +849,10 @@ class CompilerToolchainTab : CompilersSubTab
          ecsLabel.disabled = ecs.disabled = disabled;
          earLabel.disabled = ear.disabled = disabled;
          cppLabel.disabled = cpp.disabled = isVC || disabled;
-         cxxLabel.disabled = cxx.disabled = isVC || disabled;
          ccLabel.disabled = cc.disabled = isVC || disabled;
-         ldLabel.disabled = cxx.disabled = isVC || disabled;
+         cxxLabel.disabled = cxx.disabled = isVC || disabled;
+         ldLabel.disabled = ld.disabled = isVC || disabled;
+         arLabel.disabled = ar.disabled = isVC || disabled;
          makeLabel.disabled = make.disabled = disabled;
          executableLauncherLabel.disabled = executableLauncher.disabled = disabled;
          gnuToolchainPrefixLabel.disabled = gnuToolchainPrefix.disabled = disabled;
@@ -1135,10 +1136,10 @@ class CompilerOptionsTab : CompilersSubTab
       }
    };
 
-   Label outputFileExtLabel { this, position = { 8, 306 }, labeledWindow = outputFileExt };
-   EditBox outputFileExt
+   Label staticLibFileExtLabel { this, position = { 8, 306 }, labeledWindow = staticLibFileExt };
+   EditBox staticLibFileExt
    {
-      this, text = $"Output file extension";//, hotKey = altH;
+      this, text = $"Output (a, so, exe) file extension";//, hotKey = altH;
       position = { 168, 304 }, size = { 80, 22 };
 
       bool NotifyModified(EditBox editBox)
@@ -1146,7 +1147,59 @@ class CompilerOptionsTab : CompilersSubTab
          CompilerConfig compiler = loadedCompiler;
          if(compiler)
          {
-            compiler.outputFileExt = editBox.contents;
+            compiler.staticLibFileExt = editBox.contents;
+            modifiedDocument = true;
+            compilersTab.modifiedDocument = true;
+         }
+         return true;
+      }
+   };
+   EditBox sharedLibFileExt
+   {
+      this;
+      position = { 256, 304 }, size = { 80, 22 };
+
+      bool NotifyModified(EditBox editBox)
+      {
+         CompilerConfig compiler = loadedCompiler;
+         if(compiler)
+         {
+            compiler.sharedLibFileExt = editBox.contents;
+            modifiedDocument = true;
+            compilersTab.modifiedDocument = true;
+         }
+         return true;
+      }
+   };
+   EditBox executableFileExt
+   {
+      this;
+      position = { 344, 304 }, size = { 80, 22 };
+
+      bool NotifyModified(EditBox editBox)
+      {
+         CompilerConfig compiler = loadedCompiler;
+         if(compiler)
+         {
+            compiler.executableFileExt = editBox.contents;
+            modifiedDocument = true;
+            compilersTab.modifiedDocument = true;
+         }
+         return true;
+      }
+   };
+
+   Button stripTarget
+   {
+      this, text = $"Strip target", hotKey = altC, position = { 8, 334 };
+      isCheckbox = true;
+
+      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
+      {
+         CompilerConfig compiler = loadedCompiler;
+         if(compiler)
+         {
+            compiler.noStripTarget = !button.checked;
             modifiedDocument = true;
             compilersTab.modifiedDocument = true;
          }
@@ -1185,7 +1238,10 @@ class CompilerOptionsTab : CompilersSubTab
          compilerFlags.strings = compiler.compilerFlags;
          linkerFlags.strings = compiler.linkerFlags;
          objectFileExt.contents = compiler.objectFileExt;
-         outputFileExt.contents = compiler.outputFileExt;
+         staticLibFileExt.contents = compiler.staticLibFileExt;
+         sharedLibFileExt.contents = compiler.sharedLibFileExt;
+         executableFileExt.contents = compiler.executableFileExt;
+         stripTarget.checked = !compiler.noStripTarget;
 
          labelTargetPlatform.disabled = disabled;
          targetPlatform.disabled = disabled;
index 3c4ec44..37aff11 100644 (file)
@@ -1253,11 +1253,21 @@ private:
       switch(targetType)
       {
          case executable:
-            if(compiler.targetPlatform == win32)
+            if(compiler.executableFileExt)
+            {
+               strcat(string, ".");
+               strcat(string, compiler.executableFileExt);
+            }
+            else if(compiler.targetPlatform == win32)
                strcat(string, ".exe");
             break;
          case sharedLibrary:
-            if(compiler.targetPlatform == win32)
+            if(compiler.sharedLibFileExt)
+            {
+               strcat(string, ".");
+               strcat(string, compiler.sharedLibFileExt);
+            }
+            else if(compiler.targetPlatform == win32)
                strcat(string, ".dll");
             else if(compiler.targetPlatform == apple)
                strcat(string, ".dylib");
@@ -1270,7 +1280,13 @@ private:
             }
             break;
          case staticLibrary:
-            strcat(string, ".a");
+            if(compiler.staticLibFileExt)
+            {
+               strcat(string, ".");
+               strcat(string, compiler.staticLibFileExt);
+            }
+            else
+               strcat(string, ".a");
             break;
       }
    }
@@ -1555,9 +1571,10 @@ private:
       cpp.concatx((String)prefix, compiler.cppCommand, " ");
       cc.concatx((String)prefix, compiler.ccCommand,  " ");
       cxx.concatx((String)prefix, compiler.cxxCommand, " ");
+      ar.concatx((String)gnuToolchainPrefix, compiler.arCommand,  " ");
+      //ar.concatx(gnuToolchainPrefix, "ar rcs");
 
       strip.concatx(gnuToolchainPrefix, "strip ");
-      ar.concatx(gnuToolchainPrefix, "ar rcs");
       windres.concatx(gnuToolchainPrefix, "windres ");
 
       testLen = Max(testLen, ecp.size);
@@ -2101,7 +2118,6 @@ private:
       char command[MAX_F_STRING*4];
       char * compilerName = CopyString(compiler.name);
       Map<String, NameCollisionInfo> cfgNameCollisions;
-      const char * objFileExt = strcmp(compiler.objectFileExt, objectDefaultFileExt) != 0 ? compiler.objectFileExt : null;
 
       delete lastBuildConfigName;
       lastBuildConfigName = CopyString(config ? config.name : "Common");
@@ -2140,14 +2156,14 @@ private:
             // Create object dir if it does not exist already
             if(!FileExists(objDirExp.dir).isDirectory)
             {
-               sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s%s%s objdir -C \"%s\"%s -f \"%s\"",
+               sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s%s objdir -C \"%s\"%s -f \"%s\"",
                      compiler.makeCommand, cfDir,
                      crossCompiling ? " TARGET_PLATFORM=" : "",
                      targetPlatform,
                      bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
                      /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
                      compilerName,
-                     objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
+                     compiler.noStripTarget ? " NOSTRIP=y" : "",
                      topNode.path, justPrint ? " -n" : "", makeFilePath);
                if(justPrint || raw)
                   ide.outputView.buildBox.Logf("%s\n", command);
@@ -2199,7 +2215,7 @@ private:
          GccVersionInfo cxxVersion = GetGccVersionInfo(compiler, compiler.cxxCommand);
          char cfDir[MAX_LOCATION];
          GetIDECompilerConfigsDir(cfDir, true, true);
-         sprintf(command, "%s%s %sCF_DIR=\"%s\"%s%s%s%s%s%s COMPILER=%s%s%s %s%s%s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
+         sprintf(command, "%s%s %sCF_DIR=\"%s\"%s%s%s%s%s%s COMPILER=%s%s %s%s%s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
 #if defined(__WIN32__)
                "",
 #else
@@ -2215,7 +2231,7 @@ private:
                ide.workspace.useValgrind ? " DISABLED_POOLING=1" : "",
                /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
                compilerName,
-               objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
+               compiler.noStripTarget ? " NOSTRIP=y" : "",
                eC_Debug ? "--always-make " : "",
                ccVersion == post4_8 ? "GCC_CC_FLAGS=-fno-diagnostics-show-caret " : "",
                cxxVersion == post4_8 ? "GCC_CXX_FLAGS=-fno-diagnostics-show-caret " : "",
@@ -2293,7 +2309,6 @@ private:
       PathBackup pathBackup { };
       bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
       const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
-      const char * objFileExt = strcmp(compiler.objectFileExt, objectDefaultFileExt) ? compiler.objectFileExt : null;
 
       compilerName = CopyString(compiler.name);
       CamelCase(compilerName);
@@ -2328,12 +2343,12 @@ private:
       {
          char cfDir[MAX_LOCATION];
          GetIDECompilerConfigsDir(cfDir, true, true);
-         sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s%s%s %sclean%s -C \"%s\"%s -f \"%s\"",
+         sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s%s %sclean%s -C \"%s\"%s -f \"%s\"",
                compiler.makeCommand, cfDir,
                crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
                bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
                compilerName,
-               objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
+               compiler.noStripTarget ? " NOSTRIP=y" : "",
                cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
                topNode.path, justPrint ? " -n": "", makeFilePath);
          if(justPrint || raw)
@@ -2358,7 +2373,7 @@ private:
       delete compilerName;
    }
 
-   void Run(const char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
+   void Run(const char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool shellOpen)
    {
       String target = new char[maxPathLen];
       char oldDirectory[MAX_LOCATION];
@@ -2371,7 +2386,8 @@ private:
       strcpy(target, topNode.path);
       PathCatSlash(target, targetDirExp.dir);
       CatTargetFileName(target, compiler, config);
-      sprintf(target, "%s %s", target, args);
+      if(args[0] && (executableLauncher || !shellOpen))
+         sprintf(target, "%s %s", target, args);
       GetWorkingDir(oldDirectory, MAX_LOCATION);
 
       if(ide.workspace.debugDir && strlen(ide.workspace.debugDir))
@@ -2394,6 +2410,8 @@ private:
          Execute(prefixedTarget);
          delete prefixedTarget;
       }
+      else if(shellOpen)
+         ShellOpen(target);
       else
          Execute(target);
 
@@ -2514,15 +2532,27 @@ private:
                f.Puts("\n");
             }
 
+            f.Puts("# PREFIXES AND EXTENSIONS\n");
+            f.Puts("EC := .ec\n");
+            f.Puts("S := .sym\n");
+            f.Puts("I := .imp\n");
+            f.Puts("B := .bowl\n");
+            f.Puts("C := .c\n");
+            f.Printf("O := .%s\n", compiler.objectFileExt ? compiler.objectFileExt  : "o");
+            f.Printf("A := .%s\n", compiler.staticLibFileExt ? compiler.staticLibFileExt  : "a");
+            f.Printf("SO := .%s\n", compiler.sharedLibFileExt ? compiler.sharedLibFileExt : "$(if $(WINDOWS_TARGET),dll,$(if $(OSX_TARGET),dylib,so))");
+            f.Printf("E := %s%s\n", compiler.executableFileExt ? "." : "",
+                  compiler.executableFileExt ? compiler.executableFileExt : "$(if $(WINDOWS_TARGET),.exe,)");
+            f.Puts("OUT := $(if $(STATIC_LIBRARY_TARGET),$(A),$(if $(SHARED_LIBRARY_TARGET),$(SO)$(VER),$(if $(EXECUTABLE_TARGET),$(E),.x)))\n");
+            f.Puts("LP := $(if $(WINDOWS_TARGET),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)\n");
+            f.Puts("HOST_E := $(if $(WINDOWS_HOST),.exe,)\n");
+            f.Puts("HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so))\n");
+            f.Puts("HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)\n");
+            f.Puts(".SUFFIXES: .c .ec .sym .imp .bowl $(O) $(A)\n");
+
             f.Puts("# TOOLCHAIN\n");
             f.Puts("\n");
 
-            f.Puts("# EXTENSIONS\n");
-            if(compiler.outputFileExt)
-               f.Printf("OUT := %s\n", compiler.outputFileExt);
-            else
-               f.Puts("OUT := $(if $(STATIC_LIBRARY_TARGET),$(A),$(if $(SHARED_LIBRARY_TARGET),$(SO)$(VER),$(if $(EXECUTABLE_TARGET),$(E),.x)))\n");
-
             if(gnuToolchainPrefix && gnuToolchainPrefix[0])
             {
                f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
index b306607..65d261a 100644 (file)
@@ -1549,17 +1549,18 @@ class ProjectView : Window
       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.activeCompiler);
       ProjectConfig config = project.config;
       int bitDepth = ide.workspace.bitDepth;
+      bool shellOpen = compiler.hasDocumentOutput;
       String args = new char[maxPathLen];
       args[0] = '\0';
       if(ide.workspace.commandLineArgs)
          //ide.debugger.GetCommandLineArgs(args);
          strcpy(args, ide.workspace.commandLineArgs);
       if(ide.debugger.isActive)
-         project.Run(args, compiler, config, bitDepth);
+         project.Run(args, compiler, config, bitDepth, shellOpen);
       /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
          MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
       else if(BuildInterrim(project, run, compiler, config, bitDepth, false, false))
-         project.Run(args, compiler, config, bitDepth);
+         project.Run(args, compiler, config, bitDepth, shellOpen);
       delete args;
       delete compiler;
       return true;
@@ -1600,6 +1601,10 @@ class ProjectView : Window
 
                delete pathBackup;
             }
+            else if(compiler.hasDocumentOutput)
+            {
+               project.Run("", compiler, config, bitDepth, true);
+            }
             else
             {
                ide.debugger.Start(compiler, config, bitDepth, useValgrind);