2 public import static "ecere"
9 #ifndef MAKEFILE_GENERATOR
11 // We should have the .sln/.vcproj generation even on other platforms
12 // e.g. detect from an environment variable pointing to a Windows drive
18 import "ProjectConfig"
24 static void DummyFunction()
32 extern int __ecereVMethodID_class_OnCompare;
33 extern int __ecereVMethodID_class_OnFree;
35 IDESettings ideSettings;
37 IDESettingsContainer settingsContainer
40 dataOwner = &ideSettings;
41 dataClass = class(IDESettings);
43 void OnLoad(GlobalSettingsData data)
45 IDESettings settings = (IDESettings)data;
46 #ifndef MAKEFILE_GENERATOR
47 globalSettingsDialog.ideSettings = settings;
48 ide.UpdateRecentMenus();
53 #ifdef MAKEFILE_GENERATOR
54 CompilerConfig defaultCompiler;
57 // LEGACY BINARY EPJ LOADING
59 SetBool ParseTrueFalseValue(char * string)
61 if(!strcmpi(string, "True")) return true;
65 void ParseArrayValue(Array<String> array, char * equal)
67 char * start, * comma;
69 string = CopyString(equal);
73 comma = strstr(start, ",");
76 array.Add(CopyString(start));
86 void ProjectNode::LegacyBinaryLoadNode(File f)
91 f.Read(&len, sizeof(len), 1);
92 name = new char[len+1];
94 f.Read(name, sizeof(char), len+1);
95 f.Read(&len, sizeof(len), 1);
97 path = new char[len+1];
98 f.Read(path, sizeof(char), len+1);
101 fileName = new char[fileNameLen+2];
102 strcpy(fileName, path);
103 if(fileName[0]) strcat(fileName, "/");
104 strcat(fileName, name);
107 f.Read(&type, sizeof(type), 1);
108 f.Read(&count, sizeof(count), 1);
113 icon = NodeIcons::SelectFileIcon(name);
118 icon = NodeIcons::SelectNodeIcon(type);
121 if(count && !files) files = { };
122 for(c = 0; c < count; c++)
124 ProjectNode child { };
127 child.indent = indent + 1;
128 LegacyBinaryLoadNode(child, f);
132 /*void LegacyBinarySaveNode(File f)
137 f.Write(&len, sizeof(len), 1);
138 f.Write(name, sizeof(char), len+1);
142 // Projects Absolute Path Are Not Saved
144 f.Write(&len, sizeof(len), 1);
145 f.Write(&len, sizeof(char), 1);
150 f.Write(&len, sizeof(len), 1);
151 f.Write(path, sizeof(char), len+1);
153 f.Write(&type, sizeof(type), 1);
154 f.Write(&children.count, sizeof(children.count), 1);
155 for(child = children.first; child; child.next)
159 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
162 char printPath[MAX_LOCATION];
164 if(type == project && (files.count /*|| preprocessorDefs.first*/))
166 f.Printf("\n Files\n");
168 else if(type == file)
170 if(!strcmp(path, insidePath))
171 f.Printf("%s - %s\n", indentation, name);
174 strcpy(printPath, path);
175 len = strlen(printPath);
177 if(printPath[len-1] != '/')
178 strcat(printPath, "/");
179 strcat(printPath, name);
180 f.Printf("%s = %s\n", indentation, printPath);
183 f.Printf("\nError\n\n");
185 else if(type == folder)
187 f.Printf("%s + %s\n", indentation, name);
189 else if(type == resources && files.count)
191 PathCatSlash(insidePath, path);
192 f.Printf("\n%sResources\n", indentation);
194 f.Printf("%s Path = %s\n", indentation, path);
197 /*if(buildExclusions.first && type != project)
199 for(item = buildExclusions.first; item; item = item.next)
201 if(item == buildExclusions.first)
202 f.Printf("%s Build Exclusions = %s", indentation, item.name);
204 f.Printf(", %s", item.name);
209 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
211 for(item = preprocessorDefs.first; item; item = item.next)
213 if(item == preprocessorDefs.first)
214 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
216 f.Printf(", %s", item.name);
222 if(type == project && (files.count /*|| preprocessorDefs.first*/))
226 LegacyAsciiSaveNode(child, f, indentation, insidePath);
228 else if(type == folder)
230 strcat(indentation, " ");
231 // WHAT WAS THIS: strcpy(printPath, path);
232 // TOCHECK: why is Unix/PathCat not used here
233 len = strlen(insidePath);
235 if(insidePath[len-1] != '/')
236 strcat(insidePath, "/");
237 strcat(insidePath, name);
240 LegacyAsciiSaveNode(child, f, indentation, insidePath);
241 f.Printf("%s -\n", indentation);
242 indentation[strlen(indentation) - 3] = '\0';
243 StripLastDirectory(insidePath, insidePath);
245 else if(type == resources && files.count)
249 LegacyAsciiSaveNode(child, f, indentation, insidePath);
250 StripLastDirectory(insidePath, insidePath);
255 void ProjectConfig::LegacyProjectConfigSave(File f)
257 char * indentation = " ";
259 //f.Printf("\n * Common\n");
261 f.Printf("\n + %s\n", name);
262 f.Printf("\n Compiler\n\n");
263 if(objDir.expression[0])
264 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
265 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
266 switch(options.optimization)
268 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
269 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
270 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
272 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
274 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
275 if(options.memoryGuard == true)
276 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
277 if(options.strictNameSpaces == true)
278 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
279 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
280 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
281 TOFIX: Compiler Bug {
282 if(options.preprocessorDefinitions.count)
285 for(item : options.preprocessorDefinitions)
289 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
293 f.Printf(", %s", item);
298 if(options.includeDirs.count)
300 f.Printf("\n%sInclude Directories\n", indentation);
301 for(item : options.includeDirs)
302 f.Printf("%s - %s\n", indentation, name);
306 f.Printf("\n%sLinker\n\n", indentation);
307 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
308 switch(options.targetType)
310 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
311 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
312 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
314 if(targetDir.expression[0])
315 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
317 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
319 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
320 if(options.libraries.count)
323 for(item : options.libraries)
327 f.Printf("\n%sLibraries = %s", indentation, name);
331 f.Printf(", %s", item);
335 if(options.libraryDirs.count)
337 f.Printf("\n%sLibrary Directories\n\n", indentation);
338 for(item : options.libraryDirs)
339 f.Printf(" - %s\n", indentation, item);
343 void LegacyAsciiSaveProject(File f, Project project)
345 char indentation[128*3];
346 char path[MAX_LOCATION];
348 f.Printf("\nECERE Project File : Format Version 0.1b\n");
349 f.Printf("\nDescription\n%s\n.\n", project.description);
350 f.Printf("\nLicense\n%s\n.\n", project.license);
351 f.Printf("\nModule Name = %s\n", project.moduleName);
352 f.Printf("\n Configurations\n");
353 //////////////////////////////////////commonConfig.Save(f, true);
354 for(cfg : project.configurations)
355 LegacyProjectConfigSave(cfg, f);
357 strcpy(indentation, " ");
359 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
365 // *** NEW JSON PROJECT FORMAT ***
366 public enum ProjectNodeType { file, folder };
368 // *******************************
370 define PEEK_RESOLUTION = (18.2 * 10);
376 static Array<String> notLinkerOptions
398 static bool IsLinkerOption(String s)
400 for(i : notLinkerOptions)
401 if(strstr(s, "-Wl,") || !strcmp(s, i))
406 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
408 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
410 define WorkspaceExtension = "ews";
411 define ProjectExtension = "epj";
413 define stringInFileIncludedFrom = "In file included from ";
415 void ReplaceSpaces(char * output, char * source)
420 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
422 if(ch == ' ') output[dc++] = '\\';
425 if(ch == '(' || ch == ')') output[dc++] = '\\';
435 void ReplaceUnwantedMakeChars(char * output, char * source)
440 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
444 if(ch == '(' || ch == ')') output[dc++] = '\\';
457 static void OutputNoSpace(File f, char * source)
459 char * output = new char[strlen(source)+1024];
460 ReplaceSpaces(output, source);
465 enum ListOutputMethod { inPlace, newLine, lineEach };
467 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
470 const int breakListLength = 1536;
471 const int breakLineLength = 78; // TODO: turn this into an option.
473 int c, len, itemCount = 0;
474 Array<int> breaks { };
478 MapNode<String, int> mn;
479 for(c=0; c<list.count; c++)
481 len = strlen(list[c]) + 3;
482 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
484 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
486 if(strstr(list[c], mn.key))
490 if(charCount + len > breakListLength)
492 breaks.Add(itemCount);
500 breaks.Add(itemCount);
501 numOfBreaks = breaks.count;
506 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
507 for(c=0; c<numOfBreaks; c++)
508 f.Printf(" $(%s%d)", name, c+1);
512 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
518 for(c=0; c<numOfBreaks; c++)
521 f.Printf("%s%d =", name, c+1);
524 itemCount = breaks[c];
525 for(n=offset; n<offset+itemCount; n++)
527 if(false) // TODO: turn this into an option.
529 int itemLen = strlen(list[n]);
530 if(len > 3 && len + itemLen > breakLineLength)
532 f.Printf(" \\\n\t%s", list[n]);
538 f.Printf(" %s", list[n]);
542 f.Printf(" \\\n\t%s", list[n]);
557 void OutputCleanActions(File f, char * name, int parts)
562 for(c=0; c<parts; c++)
563 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
566 f.Printf("\t$(call rmq,$(%s))\n", name);
569 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
573 if(method == newLine)
577 if(method == lineEach)
579 f.Printf(" -%s", option);
581 OutputNoSpace(f, item);
583 f.Printf("%s", item);
588 void StringNoSpaceToDynamicString(DynamicString s, char * path)
590 char * output = new char[strlen(path)+1024];
591 ReplaceSpaces(output, path);
596 static void OutputLibraries(File f, Array<String> libraries)
598 for(item : libraries)
600 char ext[MAX_EXTENSION];
601 char temp[MAX_LOCATION];
603 bool usedFunction = false;
604 GetExtension(item, ext);
605 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
609 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
611 if(!strncmp(item, "lib", 3))
612 strcpy(temp, item + 3);
615 StripExtension(temp);
618 f.Puts(" \\\n\t$(call _L,");
627 void CamelCase(char * string)
629 int c, len = strlen(string);
630 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
631 string[c] = (char)tolower(string[c]);
634 CompilerConfig GetCompilerConfig()
636 #ifndef MAKEFILE_GENERATOR
637 CompilerConfig compiler = null;
638 if(ide && ide.workspace)
639 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
642 incref defaultCompiler;
643 return defaultCompiler;
647 define localTargetType = config && config.options && config.options.targetType ?
648 config.options.targetType : options && options.targetType ?
649 options.targetType : TargetTypes::executable;
650 define localWarnings = config && config.options && config.options.warnings ?
651 config.options.warnings : options && options.warnings ?
652 options.warnings : WarningsOption::unset;
653 define localDebug = config && config.options && config.options.debug ?
654 config.options.debug : options && options.debug ?
655 options.debug : SetBool::unset;
656 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
657 config.options.memoryGuard : options && options.memoryGuard ?
658 options.memoryGuard : SetBool::unset;
659 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
660 config.options.noLineNumbers : options && options.noLineNumbers ?
661 options.noLineNumbers : SetBool::unset;
662 define localProfile = config && config.options && config.options.profile ?
663 config.options.profile : options && options.profile ?
664 options.profile : SetBool::unset;
665 define localOptimization = config && config.options && config.options.optimization ?
666 config.options.optimization : options && options.optimization ?
667 options.optimization : OptimizationStrategy::none;
668 define localFastMath = config && config.options && config.options.fastMath ?
669 config.options.fastMath : options && options.fastMath ?
670 options.fastMath : SetBool::unset;
671 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
672 config.options.defaultNameSpace : options && options.defaultNameSpace ?
673 options.defaultNameSpace : null;
674 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
675 config.options.strictNameSpaces : options && options.strictNameSpaces ?
676 options.strictNameSpaces : SetBool::unset;
677 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
678 define localTargetFileName = config && config.options && config.options.targetFileName ?
679 config.options.targetFileName : options && options.targetFileName ?
680 options.targetFileName : "";
681 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
682 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
683 options.targetDirectory : null;
684 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
685 ideSettings.projectDefaultIntermediateObjDir[0] ?
686 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
687 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
688 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
689 options.objectsDirectory : null;
690 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
691 ideSettings.projectDefaultIntermediateObjDir[0] ?
692 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
693 define localConsole = config && config.options && config.options.console ?
694 config.options.console : options && options.console ?
695 options.console : SetBool::unset;
696 define localCompress = config && config.options && config.options.compress ?
697 config.options.compress : options && options.compress ?
698 options.compress : SetBool::unset;
700 define platformTargetType =
701 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
702 configPOs.options.targetType :
703 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
704 projectPOs.options.targetType : TargetTypes::unset;
707 char * PlatformToMakefileTargetVariable(Platform platform)
709 return platform == win32 ? "WINDOWS_TARGET" :
710 platform == tux ? "LINUX_TARGET" :
711 platform == apple ? "OSX_TARGET" :
715 char * TargetTypeToMakefileVariable(TargetTypes targetType)
717 return targetType == executable ? "executable" :
718 targetType == sharedLibrary ? "sharedlib" :
719 targetType == staticLibrary ? "staticlib" :
723 // Move this to ProjectConfig? null vs Common to consider...
724 char * GetConfigName(ProjectConfig config)
726 return config ? config.name : "Common";
729 public enum SingleFileCompileMode { normal, debugPrecompile, debugCompile, debugGenerateSymbols };
731 class Project : struct
733 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
734 // We might want to tweak this default behavior of regular classes ?
735 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
740 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
741 property Array<PlatformOptions> platforms
743 get { return platforms; }
746 if(platforms) { platforms.Free(); delete platforms; }
749 List<PlatformOptions> empty { };
750 Iterator<PlatformOptions> it { value };
752 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
753 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
763 if(p.options && !p.options.isEmpty)
770 List<ProjectConfig> configurations;
771 LinkList<ProjectNode> files;
772 String resourcesPath;
773 LinkList<ProjectNode> resources;
775 property char * description
777 set { delete description; if(value && value[0]) description = CopyString(value); }
778 get { return description ? description : ""; }
779 isset { return description != null && description[0]; }
782 property char * license
784 set { delete license; if(value && value[0]) license = CopyString(value); }
785 get { return license ? license : ""; }
786 isset { return license != null && license[0]; }
789 property char * compilerConfigsDir
791 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
792 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
793 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
797 // topNode.name holds the file name (.epj)
798 ProjectOptions options;
799 Array<PlatformOptions> platforms;
800 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
803 ProjectConfig config;
805 // This is the file name stripped of the epj extension
806 // It should NOT be edited, saved or loaded anywhere
811 String compilerConfigsDir;
812 #ifndef MAKEFILE_GENERATOR
813 FileMonitor fileMonitor
815 this, FileChange { modified = true };
816 bool OnFileNotify(FileChange action, char * param)
818 fileMonitor.StopMonitoring();
819 if(OnProjectModified(action, param))
820 fileMonitor.StartMonitoring();
825 bool StartMonitoring()
827 fileMonitor.fileName = filePath;
828 fileMonitor.StartMonitoring();
832 bool StopMonitoring()
834 fileMonitor.StopMonitoring();
838 bool OnProjectModified(FileChange fileChange, char * param)
841 sprintf(temp, $"The project %s was modified by another application.\n"
842 "Would you like to reload it and lose your changes?", name);
843 if(MessageBox { type = yesNo, master = ide,
844 text = $"Project has been modified", contents = temp }.Modal() == yes)
846 Project project = LoadProject(filePath, config.name);
849 ProjectView projectView = ide.projectView;
850 DataRow prev = topNode.row ? topNode.row.previous : null;
851 FileMonitor fm = fileMonitor;
853 if(projectView) projectView.DeleteNode(topNode);
858 topNode.project = this;
862 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
863 projectView.AddNode(topNode, null);
864 topNode.row.Move(prev);
866 projectView.ShowOutputBuildLog(true);
867 projectView.DisplayCompiler(compiler, false);
868 projectView.ProjectUpdateMakefileForAllConfigs(this);
871 eSystem_Delete(project);
880 // This frees contents without freeing the instance
881 // For use from destructor and for file monitor reloading
882 // (To work around JSON loader (LoadProject) always returning a new instance)
885 if(platforms) { platforms.Free(); delete platforms; }
886 if(configurations) { configurations.Free(); delete configurations; }
887 if(files) { files.Free(); delete files; }
888 if(resources) { resources.Free(); delete resources; }
890 delete resourcesPath;
894 delete compilerConfigsDir;
903 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
904 topNode.configurations = null;
905 topNode.platforms = null;
906 topNode.options = null;
911 property ProjectConfig config
917 topNode.info = CopyString(GetConfigName(config));
920 property char * filePath
926 char string[MAX_LOCATION];
927 GetLastDirectory(value, string);
929 topNode.name = CopyString(string);
930 StripExtension(string);
932 name = CopyString(string);
933 StripLastDirectory(value, string);
935 topNode.path = CopyString(string);
937 filePath = CopyString(value);
942 TargetTypes GetTargetType(ProjectConfig config)
944 TargetTypes targetType = localTargetType;
948 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
951 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
953 PlatformOptions projectPOs, configPOs;
954 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
955 if(platformTargetType)
962 char * GetObjDirExpression(ProjectConfig config)
964 // TODO: Support platform options
965 char * expression = localObjectsDirectory;
967 expression = settingsObjectsDirectory;
971 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
973 char * expression = GetObjDirExpression(config);
974 DirExpression objDir { type = intermediateObjectsDir };
975 objDir.Evaluate(expression, this, compiler, config);
979 char * GetTargetDirExpression(ProjectConfig config)
981 // TODO: Support platform options
982 char * expression = localTargetDirectory;
984 expression = settingsTargetDirectory;
988 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
990 char * expression = GetTargetDirExpression(config);
991 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
992 targetDir.Evaluate(expression, this, compiler, config);
996 WarningsOption GetWarnings(ProjectConfig config)
998 WarningsOption warnings = localWarnings;
1002 bool GetDebug(ProjectConfig config)
1004 SetBool debug = localDebug;
1005 return debug == true;
1008 bool GetMemoryGuard(ProjectConfig config)
1010 SetBool memoryGuard = localMemoryGuard;
1011 return memoryGuard == true;
1014 bool GetNoLineNumbers(ProjectConfig config)
1016 SetBool noLineNumbers = localNoLineNumbers;
1017 return noLineNumbers == true;
1020 bool GetProfile(ProjectConfig config)
1022 SetBool profile = localProfile;
1023 return profile == true;
1026 OptimizationStrategy GetOptimization(ProjectConfig config)
1028 OptimizationStrategy optimization = localOptimization;
1029 return optimization;
1032 bool GetFastMath(ProjectConfig config)
1034 SetBool fastMath = localFastMath;
1035 return fastMath == true;
1038 String GetDefaultNameSpace(ProjectConfig config)
1040 String defaultNameSpace = localDefaultNameSpace;
1041 return defaultNameSpace;
1044 bool GetStrictNameSpaces(ProjectConfig config)
1046 SetBool strictNameSpaces = localStrictNameSpaces;
1047 return strictNameSpaces == true;
1050 String GetTargetFileName(ProjectConfig config)
1052 String targetFileName = localTargetFileName;
1053 return targetFileName;
1056 //String targetDirectory;
1057 //String objectsDirectory;
1058 bool GetConsole(ProjectConfig config)
1060 SetBool console = localConsole;
1061 return console == true;
1064 bool GetCompress(ProjectConfig config)
1066 SetBool compress = localCompress;
1067 return compress == true;
1069 //SetBool excludeFromBuild;
1071 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1073 #ifndef MAKEFILE_GENERATOR
1074 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1078 bool GetConfigIsInDebugSession(ProjectConfig config)
1080 #ifndef MAKEFILE_GENERATOR
1081 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1085 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
1087 #ifndef MAKEFILE_GENERATOR
1088 ide.SetPath(projectsDirs, compiler, config);
1092 #ifndef MAKEFILE_GENERATOR
1093 bool Save(char * fileName)
1096 /*char output[MAX_LOCATION];
1097 ChangeExtension(fileName, "json", output);
1098 f = FileOpen(output, write);*/
1099 f = FileOpen(fileName, write);
1102 files = topNode.files;
1103 resources = resNode.files;
1104 resourcesPath = resNode.path;
1106 files.Remove(resNode);
1109 WriteJSONObject(f, class(Project), this, 0);
1115 resourcesPath = null;
1122 // This method is only called from Debugger, should be moved to Debugger class?
1123 #ifndef MAKEFILE_GENERATOR
1124 bool GetRelativePath(char * filePath, char * relativePath)
1127 char moduleName[MAX_FILENAME];
1128 GetLastDirectory(filePath, moduleName);
1129 // try with workspace dir first?
1130 if((node = topNode.Find(moduleName, false)))
1132 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1133 PathCatSlash(relativePath, node.name);
1138 // Tweak for automatically resolving symbol loader modules
1139 char * sl = strstr(moduleName, ".main.ec");
1140 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1142 char objDir[MAX_LOCATION];
1143 DirExpression objDirExp;
1144 CompilerConfig compiler = ide.debugger.currentCompiler;
1145 ProjectConfig config = ide.debugger.prjConfig;
1146 // This is not perfect, as multiple source files exist for the symbol loader module...
1147 // We try to set it in the debug config object directory.
1148 if(!compiler || !config)
1150 // If we're not currently debugging, set a breakpoint in the active compiler/config
1151 compiler = GetCompilerConfig();
1152 config = this.config;
1153 // If the current config is not debuggable, set it in the first debuggable config found
1154 if(config && !config.options.debug)
1156 for(c : configurations; c.options.debug)
1163 objDirExp = GetObjDir(compiler, config);
1164 strcpy(objDir, objDirExp.dir);
1166 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1167 ReplaceSpaces(objDir, objDir);
1168 strcpy(relativePath, objDir);
1170 PathCatSlash(relativePath, moduleName);
1174 // WARNING: On failure, relative path is uninitialized
1179 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1181 TargetTypes targetType = GetTargetType(config);
1182 String targetFileName = GetTargetFileName(config);
1183 if(targetType == staticLibrary)
1185 PathCatSlash(string, "lib");
1186 strcat(string, targetFileName);
1188 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1190 PathCatSlash(string, "lib");
1191 strcat(string, targetFileName);
1194 PathCatSlash(string, targetFileName);
1199 if(compiler.targetPlatform == win32)
1200 strcat(string, ".exe");
1203 if(compiler.targetPlatform == win32)
1204 strcat(string, ".dll");
1205 else if(compiler.targetPlatform == apple)
1206 strcat(string, ".dylib");
1208 strcat(string, ".so");
1211 strcat(string, ".a");
1216 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1218 bool result = false;
1219 char temp[MAX_LOCATION];
1220 strcpy(cfDir, topNode.path);
1221 if(compilerConfigsDir && compilerConfigsDir[0])
1223 PathCatSlash(cfDir, compilerConfigsDir);
1228 strcpy(temp, cfDir);
1229 // Using a relative path makes it less likely to run into spaces issues
1230 // Even with escaped spaces, there still seems to be issues including a config file
1231 // in a path containing spaces
1233 MakePathRelative(temp, topNode.path, cfDir);
1236 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1240 strcpy(temp, cfDir);
1241 ReplaceSpaces(cfDir, temp);
1246 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1248 char temp[MAX_LOCATION];
1249 bool result = false;
1250 strcpy(cfDir, topNode.path);
1251 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1253 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1258 // Default to <ProjectDir>/.configs if unset
1259 PathCatSlash(cfDir, ".configs");
1264 strcpy(temp, cfDir);
1265 // Using a relative path makes it less likely to run into spaces issues
1266 // Even with escaped spaces, there still seems to be issues including a config file
1267 // in a path containing spaces
1268 if(IsPathInsideOf(cfDir, topNode.path))
1269 MakePathRelative(temp, topNode.path, cfDir);
1271 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1275 strcpy(temp, cfDir);
1276 ReplaceSpaces(cfDir, temp);
1281 void CatMakeFileName(char * string, ProjectConfig config)
1283 char projectName[MAX_LOCATION];
1284 strcpy(projectName, name);
1285 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1288 #ifndef MAKEFILE_GENERATOR
1289 void MarkChanges(ProjectNode node)
1291 for(cfg : topNode.configurations)
1293 ProjectConfig c = null;
1294 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1296 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1297 (!c.options || !cfg.options)))
1298 cfg.symbolGenModified = true;
1300 cfg.makingModified = true;
1304 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1306 for(cfg : configurations)
1309 cfg.makingModified = true;
1311 cfg.compilingModified = true;
1313 cfg.linkingModified = true;
1315 cfg.symbolGenModified = true;
1317 if(compiling || linking)
1319 ide.projectView.modifiedDocument = true;
1320 ide.workspace.modified = true;
1324 void RotateActiveConfig(bool forward)
1326 if(configurations.first && configurations.last != configurations.first)
1328 Iterator<ProjectConfig> cfg { configurations };
1329 while(forward ? cfg.Next() : cfg.Prev())
1330 if(cfg.data == config)
1344 property::config = cfg.data;
1345 ide.UpdateToolBarActiveConfigs(true);
1346 ide.workspace.modified = true;
1347 ide.projectView.Update(null);
1351 void ProcessPipeOutputRaw(DualPipe f)
1354 while(!f.Eof() && !ide.ShouldStopBuild())
1357 double lastTime = GetTime();
1361 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1363 ide.outputView.buildBox.Logf("%s\n", line);
1365 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1367 //printf("Processing Input...\n");
1368 if(app.ProcessInput(true))
1370 app.UpdateDisplay();
1373 //printf("Waiting...\n");
1376 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1378 if(ide.ShouldStopBuild())
1380 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1385 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
1386 CompilerConfig compiler, ProjectConfig config)
1389 bool compiling = false, linking = false, precompiling = false;
1390 int compilingEC = 0;
1391 int numErrors = 0, numWarnings = 0;
1392 bool loggedALine = false;
1393 char * configName = config ? config.name : "Common";
1394 int lenMakeCommand = strlen(compiler.makeCommand);
1397 char * gccPrefix = compiler.gccPrefix ? compiler.gccPrefix : "";
1399 DynamicString test { };
1400 DynamicString ecp { };
1401 DynamicString ecc { };
1402 DynamicString ecs { };
1403 DynamicString ear { };
1404 DynamicString prefix { };
1405 DynamicString cpp { };
1406 DynamicString cc { };
1407 DynamicString cxx { };
1408 DynamicString strip { };
1409 DynamicString ar { };
1411 ecp.concatx(compiler.ecpCommand, " ");
1412 ecc.concatx(compiler.eccCommand, " ");
1413 ecs.concatx(compiler.ecsCommand, " ");
1414 ear.concatx(compiler.earCommand, " ");
1417 compiler.ccacheEnabled ? "ccache " : "",
1418 compiler.distccEnabled ? "distcc " : "",
1421 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1422 cc.concatx((String)prefix, compiler.ccCommand, " ");
1423 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1425 strip.concatx(gccPrefix, "strip ");
1426 ar.concatx(gccPrefix, "ar rcs");
1428 testLen = Max(testLen, ecp.size);
1429 testLen = Max(testLen, ecc.size);
1430 testLen = Max(testLen, ecs.size);
1431 testLen = Max(testLen, ear.size);
1432 testLen = Max(testLen, cpp.size);
1433 testLen = Max(testLen, cc.size);
1434 testLen = Max(testLen, cxx.size);
1435 testLen = Max(testLen, strip.size);
1436 testLen = Max(testLen, ar.size);
1439 while(!f.Eof() && !ide.ShouldStopBuild())
1442 double lastTime = GetTime();
1446 //printf("Peeking and GetLine...\n");
1447 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1449 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1450 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1451 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1453 char * module = strstr(line, "No rule to make target `");
1457 module = strchr(module, '`') + 1;
1458 end = strchr(module, '\'');
1462 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1463 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1469 //ide.outputView.buildBox.Logf("error: %s\n", line);
1473 else if(strstr(test, ear) == test);
1474 else if(strstr(test, strip) == test);
1475 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1477 char moduleName[MAX_FILENAME];
1480 bool isPrecomp = false;
1482 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1484 module = strstr(line, " -c ");
1485 if(module) module += 4;
1487 else if(strstr(test, ecc) == test)
1489 module = strstr(line, " -c ");
1490 if(module) module += 4;
1491 //module = line + 3;
1492 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1493 compilingEC = 3;//2;
1495 else if(strstr(test, ecp) == test)
1497 // module = line + 8;
1498 module = strstr(line, " -c ");
1499 if(module) module += 4;
1508 if(!compiling && !isPrecomp)
1510 ide.outputView.buildBox.Logf($"Compiling...\n");
1513 else if(!precompiling && isPrecomp)
1515 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1516 precompiling = true;
1518 // Changed escapeBackSlashes here to handle paths with spaces
1519 Tokenize(module, 1, tokens, true); // false);
1520 GetLastDirectory(module, moduleName);
1521 ide.outputView.buildBox.Logf("%s\n", moduleName);
1523 else if((module = strstr(line, " -o ")))
1526 precompiling = false;
1528 ide.outputView.buildBox.Logf($"Linking...\n");
1532 ide.outputView.buildBox.Logf("%s\n", line);
1536 if(compilingEC) compilingEC--;
1538 else if(strstr(test, ar) == test)
1539 ide.outputView.buildBox.Logf($"Building library...\n");
1540 else if(strstr(test, ecs) == test)
1541 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1544 if(linking || compiling || precompiling)
1546 char * colon = strstr(line, ":"); //, * bracket;
1547 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1548 colon = strstr(colon + 1, ":");
1551 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1554 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1555 int len = (int)(colon - start);
1556 len = Min(len, MAX_LOCATION-1);
1557 // Don't be mistaken by the drive letter colon
1559 // TODO: need to fix colon - line gives char *
1560 // warning: incompatible expression colon - line (char *); expected int
1562 strncpy(moduleName, line, (int)(colon - line));
1563 moduleName[colon - line] = '\0';
1565 strncpy(moduleName, start, len);
1566 moduleName[len] = '\0';
1567 // Remove stuff in brackets
1568 //bracket = strstr(moduleName, "(");
1569 //if(bracket) *bracket = '\0';
1571 GetLastDirectory(moduleName, temp);
1572 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1575 strcpy(moduleName, $"Linker Error");
1579 strcpy(temp, topNode.path);
1580 PathCatSlash(temp, moduleName);
1581 MakePathRelative(temp, topNode.path, moduleName);
1583 if(strstr(line, "error:"))
1587 // Silence warnings for compiled EC
1588 char * objDir = strstr(moduleName, objDirExp.dir);
1592 if((pointer = strstr(line, "undefined")) ||
1593 (pointer = strstr(line, "No such file")) ||
1594 (pointer = strstr(line, "token")))
1596 strncat(moduleName, colon, pointer - colon);
1597 strcat(moduleName, "error: ");
1602 else if((pointer = strstr(line, "No such file")))
1604 strncat(moduleName, colon, pointer - colon);
1605 strcat(moduleName, "error: ");
1609 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1611 else if(strstr(line, "warning:"))
1616 if(this == ide.workspace.projects.firstIterator.data)
1617 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1620 char fullModuleName[MAX_LOCATION];
1621 strcpy(fullModuleName, topNode.path);
1622 PathCat(fullModuleName, moduleName);
1623 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1624 MakeSystemPath(fullModuleName);
1625 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1630 ide.outputView.buildBox.Logf("%s\n", line);
1631 linking = compiling = precompiling = false;
1635 ide.outputView.buildBox.Logf("%s\n", line);
1639 //printf("Done getting line\n");
1640 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1642 //printf("Processing Input...\n");
1643 if(app.ProcessInput(true))
1645 app.UpdateDisplay();
1648 //printf("Waiting...\n");
1651 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1653 if(ide.ShouldStopBuild())
1655 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1658 else if(loggedALine || !isARun)
1660 if(f.GetExitCode() && !numErrors)
1662 bool result = f.GetLine(line, sizeof(line)-1);
1663 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1668 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1670 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1672 ide.outputView.buildBox.Logf($"no error, ");
1675 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1677 ide.outputView.buildBox.Logf($"no warning\n");
1693 return numErrors == 0;
1696 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1699 int lenMakeCommand = strlen(compiler.makeCommand);
1704 double lastTime = GetTime();
1707 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1709 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1710 else if(strstr(line, "del") == line);
1711 else if(strstr(line, "rm") == line);
1712 else if(strstr(line, "Could Not Find") == line);
1715 ide.outputView.buildBox.Logf(line);
1716 ide.outputView.buildBox.Logf("\n");
1720 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1722 if(app.ProcessInput(true))
1724 app.UpdateDisplay();
1727 //Sleep(1.0 / PEEK_RESOLUTION);
1731 bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, bool justPrint, SingleFileCompileMode mode)
1733 bool result = false;
1735 char targetFileName[MAX_LOCATION] = "";
1736 DynamicString makeTargets { };
1737 char makeFile[MAX_LOCATION];
1738 char makeFilePath[MAX_LOCATION];
1739 char configName[MAX_LOCATION];
1740 DirExpression objDirExp = GetObjDir(compiler, config);
1741 PathBackup pathBackup { };
1742 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1743 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1745 int numJobs = compiler.numJobs;
1746 char command[MAX_F_STRING];
1747 char * compilerName;
1749 compilerName = CopyString(compiler.name);
1750 CamelCase(compilerName);
1752 strcpy(configName, config ? config.name : "Common");
1754 SetPath(false, compiler, config); //true
1755 CatTargetFileName(targetFileName, compiler, config);
1757 strcpy(makeFilePath, topNode.path);
1758 CatMakeFileName(makeFile, config);
1759 PathCatSlash(makeFilePath, makeFile);
1761 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1764 if(compiler.type.isVC)
1766 PrintLn("compiling a single file is not yet supported");
1771 char pushD[MAX_LOCATION];
1772 char cfDir[MAX_LOCATION];
1773 GetIDECompilerConfigsDir(cfDir, true, true);
1774 GetWorkingDir(pushD, sizeof(pushD));
1775 ChangeWorkingDir(topNode.path);
1776 // Create object dir if it does not exist already
1777 if(!FileExists(objDirExp.dir).isDirectory)
1779 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
1780 compiler.makeCommand, cfDir,
1781 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1782 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
1784 ide.outputView.buildBox.Logf("%s\n", command);
1788 ChangeWorkingDir(pushD);
1790 for(node : onlyNodes)
1792 if(node.GetIsExcluded(config))
1793 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1796 node.DeleteIntermediateFiles(compiler, config);
1797 node.GetTargets(config, objDirExp.dir, makeTargets);
1803 if(compiler.type.isVC)
1805 bool result = false;
1806 char oldwd[MAX_LOCATION];
1807 GetWorkingDir(oldwd, sizeof(oldwd));
1808 ChangeWorkingDir(topNode.path);
1810 // TODO: support justPrint
1811 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1813 ide.outputView.buildBox.Logf("%s\n", command);
1814 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1816 ProcessPipeOutputRaw(f);
1820 ChangeWorkingDir(oldwd);
1824 char cfDir[MAX_LOCATION];
1825 GetIDECompilerConfigsDir(cfDir, true, true);
1826 sprintf(command, "%s %sCF_DIR=\"%s\"%s%s COMPILER=%s -j%d %s%s%s -C \"%s\"%s -f \"%s\"",
1827 compiler.makeCommand,
1828 mode == normal ? "" : (mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : ""),
1830 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1831 compilerName, numJobs,
1832 compiler.ccacheEnabled ? "CCACHE=y " : "",
1833 compiler.distccEnabled ? "DISTCC=y " : "",
1834 (String)makeTargets, topNode.path, (justPrint || mode != normal) ? " -n" : "", makeFilePath);
1836 ide.outputView.buildBox.Logf("%s\n", command);
1837 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1842 ProcessPipeOutputRaw(f);
1845 else if(mode != normal)
1853 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1855 if(!found && strstr(line, "ide ") == line)
1857 strcpy(command, line);
1865 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config);
1871 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1876 delete compilerName;
1881 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean, bool justPrint)
1883 char makeFile[MAX_LOCATION];
1884 char makeFilePath[MAX_LOCATION];
1885 char command[MAX_LOCATION];
1886 char * compilerName;
1888 PathBackup pathBackup { };
1889 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1890 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1892 compilerName = CopyString(compiler.name);
1893 CamelCase(compilerName);
1895 SetPath(false, compiler, config);
1897 strcpy(makeFilePath, topNode.path);
1898 CatMakeFileName(makeFile, config);
1899 PathCatSlash(makeFilePath, makeFile);
1901 if(compiler.type.isVC)
1903 bool result = false;
1904 char oldwd[MAX_LOCATION];
1905 GetWorkingDir(oldwd, sizeof(oldwd));
1906 ChangeWorkingDir(topNode.path);
1908 // TODO: justPrint support
1909 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1911 ide.outputView.buildBox.Logf("%s\n", command);
1912 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1914 ProcessPipeOutputRaw(f);
1918 ChangeWorkingDir(oldwd);
1923 char cfDir[MAX_LOCATION];
1924 GetIDECompilerConfigsDir(cfDir, true, true);
1925 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s %sclean -C \"%s\"%s -f \"%s\"",
1926 compiler.makeCommand, cfDir,
1927 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1928 compilerName, realclean ? "real" : "", topNode.path, justPrint ? " -n": "", makeFilePath);
1930 ide.outputView.buildBox.Logf("%s\n", command);
1931 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1933 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1935 ProcessPipeOutputRaw(f);
1937 ProcessCleanPipeOutput(f, compiler, config);
1940 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1945 delete compilerName;
1948 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1950 String target = new char[maxPathLen];
1951 char oldDirectory[MAX_LOCATION];
1952 DirExpression targetDirExp = GetTargetDir(compiler, config);
1953 PathBackup pathBackup { };
1955 // Build(project, ideMain, true, null, false);
1957 #if defined(__WIN32__)
1958 strcpy(target, topNode.path);
1962 PathCatSlash(target, targetDirExp.dir);
1963 CatTargetFileName(target, compiler, config);
1964 sprintf(target, "%s %s", target, args);
1965 GetWorkingDir(oldDirectory, MAX_LOCATION);
1967 if(strlen(ide.workspace.debugDir))
1969 char temp[MAX_LOCATION];
1970 strcpy(temp, topNode.path);
1971 PathCatSlash(temp, ide.workspace.debugDir);
1972 ChangeWorkingDir(temp);
1975 ChangeWorkingDir(topNode.path);
1976 // ChangeWorkingDir(topNode.path);
1977 SetPath(true, compiler, config);
1978 if(compiler.execPrefixCommand)
1980 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1981 prefixedTarget[0] = '\0';
1982 strcat(prefixedTarget, compiler.execPrefixCommand);
1983 strcat(prefixedTarget, " ");
1984 strcat(prefixedTarget, target);
1985 Execute(prefixedTarget);
1986 delete prefixedTarget;
1991 ChangeWorkingDir(oldDirectory);
1994 delete targetDirExp;
1998 void Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, bool justPrint, SingleFileCompileMode mode)
2000 Build(false, nodes, compiler, config, justPrint, mode);
2004 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2007 if(targetType == staticLibrary || targetType == sharedLibrary)
2008 strcat(fileName, "$(LP)");
2009 // !!! ReplaceSpaces must be done after all PathCat calls !!!
2010 // ReplaceSpaces(s, GetTargetFileName(config));
2011 strcat(fileName, GetTargetFileName(config));
2015 strcat(fileName, "$(E)");
2018 strcat(fileName, "$(SO)");
2021 strcat(fileName, "$(A)");
2026 bool GenerateCrossPlatformMk()
2028 bool result = false;
2029 char path[MAX_LOCATION];
2031 if(!GetProjectCompilerConfigsDir(path, false, false))
2032 GetIDECompilerConfigsDir(path, false, false);
2034 if(!FileExists(path).isDirectory)
2038 char dirName[MAX_FILENAME];
2039 GetLastDirectory(path, dirName);
2040 if(!strcmp(dirName, ".configs"))
2041 FileSetAttribs(path, FileAttribs { isHidden = true });
2044 PathCatSlash(path, "crossplatform.mk");
2046 if(FileExists(path))
2049 File include = FileOpen(":crossplatform.mk", read);
2052 File f = FileOpen(path, write);
2055 for(; !include.Eof(); )
2058 int count = include.Read(buffer, 1, 4096);
2059 f.Write(buffer, 1, count);
2071 bool GenerateCompilerCf(CompilerConfig compiler)
2073 bool result = false;
2074 char path[MAX_LOCATION];
2076 char * compilerName;
2077 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2078 Platform platform = compiler.targetPlatform;
2080 compilerName = CopyString(compiler.name);
2081 CamelCase(compilerName);
2082 name = PrintString(platform, "-", compilerName, ".cf");
2084 if(!GetProjectCompilerConfigsDir(path, false, false))
2085 GetIDECompilerConfigsDir(path, false, false);
2087 if(!FileExists(path).isDirectory)
2091 char dirName[MAX_FILENAME];
2092 GetLastDirectory(path, dirName);
2093 if(!strcmp(dirName, ".configs"))
2094 FileSetAttribs(path, FileAttribs { isHidden = true });
2097 PathCatSlash(path, name);
2099 if(FileExists(path))
2102 File f = FileOpen(path, write);
2105 if(compiler.environmentVars && compiler.environmentVars.count)
2107 f.Puts("# ENVIRONMENT VARIABLES\n");
2109 for(e : compiler.environmentVars)
2111 f.Printf("export %s := %s\n", e.name, e.string);
2115 f.Puts("# TOOLCHAIN\n");
2118 if(compiler.gccPrefix && compiler.gccPrefix[0])
2120 f.Printf("GCC_PREFIX := %s\n", compiler.gccPrefix);
2123 if(compiler.sysroot && compiler.sysroot[0])
2125 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2126 // Moved this to crossplatform.mk
2127 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2131 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2132 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2133 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2134 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2135 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start $(ECERE_SDK_SRC)/compiler/ecp/ecp.epj -@,%s)\n", compiler.ecpCommand);
2136 f.Printf("ECC := $(if $(ECC_DEBUG),ide -debug-start $(ECERE_SDK_SRC)/compiler/ecc/ecc.epj -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2137 f.Printf("ECS := $(if $(ECS_DEBUG),ide -debug-start $(ECERE_SDK_SRC)/compiler/ecs/ecs.epj -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.ecsCommand);
2138 f.Printf("EAR := %s\n", compiler.earCommand);
2140 f.Puts("AS := $(GCC_PREFIX)as\n");
2141 f.Puts("LD := $(GCC_PREFIX)ld\n");
2142 f.Puts("AR := $(GCC_PREFIX)ar\n");
2143 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2144 f.Puts("UPX := upx\n");
2147 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2150 f.Puts("EARFLAGS = \n");
2153 f.Puts("ifndef ARCH\n");
2154 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2155 f.Puts(" ifdef WINDOWS_HOST\n");
2156 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2157 f.Puts(" TARGET_ARCH := x86_64\n");
2159 f.Puts(" TARGET_ARCH := i386\n");
2162 f.Puts("endif\n\n");
2164 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2165 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2169 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2173 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2176 if(compiler.includeDirs && compiler.includeDirs.count)
2178 f.Puts("\nCFLAGS +=");
2179 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2182 if(compiler.prepDirectives && compiler.prepDirectives.count)
2184 f.Puts("\nCFLAGS +=");
2185 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2188 if(compiler.libraryDirs && compiler.libraryDirs.count)
2190 f.Puts("\nLDFLAGS +=");
2191 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2192 // We would need a bool option to know whether we want to add to rpath as well...
2193 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
2196 if(compiler.excludeLibs && compiler.excludeLibs.count)
2198 f.Puts("\nEXCLUDED_LIBS =");
2199 for(l : compiler.excludeLibs)
2205 if(compiler.linkerFlags && compiler.linkerFlags.count)
2207 f.Puts("\nLDFLAGS +=");
2208 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
2212 f.Puts("\nOFLAGS += $(LDFLAGS)");
2214 f.Puts("ifdef ARCH_FLAGS\n");
2215 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2216 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2225 delete compilerName;
2229 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2231 bool result = false;
2232 char filePath[MAX_LOCATION];
2233 char makeFile[MAX_LOCATION];
2234 // PathBackup pathBackup { };
2235 // char oldDirectory[MAX_LOCATION];
2238 if(!altMakefilePath)
2240 strcpy(filePath, topNode.path);
2241 CatMakeFileName(makeFile, config);
2242 PathCatSlash(filePath, makeFile);
2245 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2247 /*SetPath(false, compiler, config);
2248 GetWorkingDir(oldDirectory, MAX_LOCATION);
2249 ChangeWorkingDir(topNode.path);*/
2256 char targetDir[MAX_LOCATION];
2257 char objDirExpNoSpaces[MAX_LOCATION];
2258 char objDirNoSpaces[MAX_LOCATION];
2259 char resDirNoSpaces[MAX_LOCATION];
2260 char targetDirExpNoSpaces[MAX_LOCATION];
2261 char fixedModuleName[MAX_FILENAME];
2262 char fixedConfigName[MAX_FILENAME];
2264 // Non-zero if we're building eC code
2265 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2266 int numCObjects = 0;
2268 bool containsCXX = false; // True if the project contains a C++ file
2269 bool sameObjTargetDirs;
2270 String objDirExp = GetObjDirExpression(config);
2271 TargetTypes targetType = GetTargetType(config);
2273 char cfDir[MAX_LOCATION];
2274 int objectsParts = 0, eCsourcesParts = 0;
2275 Array<String> listItems { };
2276 Map<String, int> varStringLenDiffs { };
2277 Map<String, NameCollisionInfo> namesInfo { };
2278 bool forceBitDepth = false;
2280 Map<String, int> cflagsVariations { };
2281 Map<intptr, int> nodeCFlagsMapping { };
2283 Map<String, int> ecflagsVariations { };
2284 Map<intptr, int> nodeECFlagsMapping { };
2286 ReplaceSpaces(objDirNoSpaces, objDirExp);
2287 strcpy(targetDir, GetTargetDirExpression(config));
2288 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2290 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2291 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2292 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2293 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2294 ReplaceSpaces(fixedModuleName, moduleName);
2295 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2296 CamelCase(fixedConfigName);
2298 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2300 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2302 f.Puts("# CORE VARIABLES\n\n");
2304 f.Printf("MODULE := %s\n", fixedModuleName);
2305 //f.Printf("VERSION = %s\n", version);
2306 f.Printf("CONFIG := %s\n", fixedConfigName);
2307 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2310 test = GetTargetTypeIsSetByPlatform(config);
2314 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2316 TargetTypes targetType;
2317 PlatformOptions projectPOs, configPOs;
2318 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2319 targetType = platformTargetType;
2325 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2326 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2331 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2336 for(c = 0; c < ifCount; c++)
2342 f.Puts("# FLAGS\n\n");
2344 f.Puts("ECFLAGS =\n");
2345 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2346 f.Puts("PRJ_CFLAGS =\n");
2347 f.Puts("CECFLAGS =\n");
2348 f.Puts("OFLAGS =\n");
2352 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2355 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2356 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2357 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2358 //f.Puts("endif\n");
2361 f.Puts("# INCLUDES\n\n");
2363 if(compilerConfigsDir && compilerConfigsDir[0])
2365 strcpy(cfDir, compilerConfigsDir);
2366 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2371 GetIDECompilerConfigsDir(cfDir, true, true);
2372 // Use CF_DIR environment variable for absolute paths only
2373 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2374 strcpy(cfDir, "$(CF_DIR)");
2377 f.Printf("_CF_DIR = %s\n", cfDir);
2380 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2381 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2384 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2386 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2389 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2392 // test = GetTargetTypeIsSetByPlatform(config);
2394 char target[MAX_LOCATION];
2395 char targetNoSpaces[MAX_LOCATION];
2400 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2402 if(type != targetType)
2407 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2409 GetMakefileTargetFileName(type, target, config);
2410 strcpy(targetNoSpaces, targetDir);
2411 PathCatSlash(targetNoSpaces, target);
2412 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2413 f.Printf("TARGET = %s\n", targetNoSpaces);
2418 GetMakefileTargetFileName(targetType, target, config);
2419 strcpy(targetNoSpaces, targetDir);
2420 PathCatSlash(targetNoSpaces, target);
2421 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2422 f.Printf("TARGET = %s\n", targetNoSpaces);
2428 for(c = 0; c < ifCount; c++)
2435 // Use something fixed here, to not cause Makefile differences across compilers...
2436 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2437 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2439 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2443 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2445 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2448 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2450 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2451 if(eCsourcesParts > 1)
2453 for(c = 1; c <= eCsourcesParts; c++)
2454 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2458 for(c = 0; c < 5; c++)
2460 if(eCsourcesParts > 1)
2463 f.Printf("%s =", map[c][0]);
2464 for(n = 1; n <= eCsourcesParts; n++)
2465 f.Printf(" $(%s%d)", map[c][0], n);
2467 for(n = 1; n <= eCsourcesParts; n++)
2468 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2470 else if(eCsourcesParts == 1)
2471 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2477 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2479 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2480 f.Printf("OBJECTS =%s%s%s\n", numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "", numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "");
2483 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2484 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, numCObjects ? "$(ECSOURCES)" : null);
2487 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2488 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2490 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2492 if((config && config.options && config.options.libraries) ||
2493 (options && options.libraries))
2495 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2497 if(config && config.options && config.options.libraries)
2498 OutputLibraries(f, config.options.libraries);
2499 else if(options && options.libraries)
2500 OutputLibraries(f, options.libraries);
2506 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2507 cflagsVariations, nodeCFlagsMapping,
2508 ecflagsVariations, nodeECFlagsMapping, null);
2510 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2511 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2513 if(platforms || (config && config.platforms))
2516 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2517 //for(platform = win32; platform <= apple; platform++)
2519 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2520 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2522 PlatformOptions projectPlatformOptions, configPlatformOptions;
2523 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2525 if(projectPlatformOptions || configPlatformOptions)
2530 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2533 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2534 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2536 f.Puts("OFLAGS +=");
2537 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2539 bool needWl = false;
2541 for(s : projectPlatformOptions.options.linkerOptions)
2543 if(!IsLinkerOption(s))
2551 for(s : projectPlatformOptions.options.linkerOptions)
2552 if(IsLinkerOption(s))
2556 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2558 bool needWl = false;
2560 for(s : configPlatformOptions.options.linkerOptions)
2562 if(IsLinkerOption(s))
2570 for(s : configPlatformOptions.options.linkerOptions)
2571 if(!IsLinkerOption(s))
2579 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2580 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2581 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2582 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2584 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2585 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2586 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2588 f.Puts("OFLAGS +=");
2589 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2590 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2591 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2592 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2596 if((configPlatformOptions && configPlatformOptions.options.libraries))
2598 if(configPlatformOptions.options.libraries.count)
2601 OutputLibraries(f, configPlatformOptions.options.libraries);
2605 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2607 if(projectPlatformOptions.options.libraries.count)
2610 OutputLibraries(f, projectPlatformOptions.options.libraries);
2621 for(c = 0; c < ifCount; c++)
2627 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
2628 (options && options.linkerOptions && options.linkerOptions.count))
2630 f.Puts("OFLAGS +=");
2633 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
2635 bool needWl = false;
2636 for(s : config.options.linkerOptions)
2638 if(!IsLinkerOption(s))
2646 for(s : config.options.linkerOptions)
2647 if(IsLinkerOption(s))
2651 if(options && options.linkerOptions && options.linkerOptions.count)
2653 bool needWl = false;
2654 for(s : options.linkerOptions)
2656 if(!IsLinkerOption(s))
2664 for(s : options.linkerOptions)
2665 if(IsLinkerOption(s))
2673 f.Puts("CECFLAGS += -cpp $(_CPP)");
2677 if(GetProfile(config))
2678 f.Puts("OFLAGS += -pg\n\n");
2680 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
2682 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2683 f.Puts("OFLAGS +=");
2684 if(config && config.options && config.options.libraryDirs)
2685 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2686 if(options && options.libraryDirs)
2687 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2693 f.Puts("# TARGETS\n");
2696 f.Printf("all: objdir%s $(TARGET)\n", sameObjTargetDirs ? "" : " targetdir");
2699 f.Puts("objdir:\n");
2700 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2701 //f.Puts("# PRE-BUILD COMMANDS\n");
2702 if(options && options.prebuildCommands)
2704 for(s : options.prebuildCommands)
2705 if(s && s[0]) f.Printf("\t%s\n", s);
2707 if(config && config.options && config.options.prebuildCommands)
2709 for(s : config.options.prebuildCommands)
2710 if(s && s[0]) f.Printf("\t%s\n", s);
2712 if(platforms || (config && config.platforms))
2715 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2716 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2718 PlatformOptions projectPOs, configPOs;
2719 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2721 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2722 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2727 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2729 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2731 for(s : projectPOs.options.prebuildCommands)
2732 if(s && s[0]) f.Printf("\t%s\n", s);
2734 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2736 for(s : configPOs.options.prebuildCommands)
2737 if(s && s[0]) f.Printf("\t%s\n", s);
2744 for(c = 0; c < ifCount; c++)
2750 if(!sameObjTargetDirs)
2752 f.Puts("targetdir:\n");
2753 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2759 // Main Module (Linking) for ECERE C modules
2760 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2761 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2762 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n",
2763 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2765 // Main Module (Linking) for ECERE C modules
2766 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2767 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
2768 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2769 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
2770 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n");
2776 // This would not rebuild the target on updated objects
2777 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2779 // This should fix it for good!
2780 f.Puts("$(SYMBOLS): | objdir\n");
2781 f.Puts("$(OBJECTS): | objdir\n");
2783 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2784 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2786 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2787 f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2788 if(!GetDebug(config))
2790 f.Puts("ifndef NOSTRIP\n");
2791 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2794 if(GetCompress(config))
2796 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
2797 f.Puts("ifdef EXECUTABLE_TARGET\n");
2798 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2801 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2805 if(resNode.files && resNode.files.count && !noResources)
2806 resNode.GenMakefileAddResources(f, resNode.path, config);
2808 f.Puts("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2811 //f.Puts("# POST-BUILD COMMANDS\n");
2812 if(options && options.postbuildCommands)
2814 for(s : options.postbuildCommands)
2815 if(s && s[0]) f.Printf("\t%s\n", s);
2817 if(config && config.options && config.options.postbuildCommands)
2819 for(s : config.options.postbuildCommands)
2820 if(s && s[0]) f.Printf("\t%s\n", s);
2822 if(platforms || (config && config.platforms))
2825 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2826 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2828 PlatformOptions projectPOs, configPOs;
2829 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2831 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2832 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2837 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2839 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2841 for(s : projectPOs.options.postbuildCommands)
2842 if(s && s[0]) f.Printf("\t%s\n", s);
2844 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2846 for(s : configPOs.options.postbuildCommands)
2847 if(s && s[0]) f.Printf("\t%s\n", s);
2854 for(c = 0; c < ifCount; c++)
2860 f.Puts("# SYMBOL RULES\n");
2863 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
2865 f.Puts("# C OBJECT RULES\n");
2868 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
2870 f.Puts("# OBJECT RULES\n");
2872 // todo call this still but only generate rules whith specific options
2873 // see we-have-file-specific-options in ProjectNode.ec
2874 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
2877 GenMakefilePrintMainObjectRule(f, config);
2879 f.Printf("cleantarget: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2880 f.Puts("\t$(call rmq,$(TARGET))\n");
2883 f.Puts("clean: cleantarget\n");
2884 OutputCleanActions(f, "_OBJECTS", objectsParts);
2887 f.Printf("\t$(call rmq,%s)\n", "$(OBJ)$(MODULE).main.o $(OBJ)$(MODULE).main.c $(OBJ)$(MODULE).main.ec $(OBJ)$(MODULE).main$(I) $(OBJ)$(MODULE).main$(S)");
2888 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
2889 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2890 OutputCleanActions(f, "BOWLS", eCsourcesParts);
2891 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2892 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2896 f.Puts("realclean: cleantarget\n");
2897 f.Puts("\t$(call rmrq,$(OBJ))\n");
2898 if(!sameObjTargetDirs)
2899 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2902 f.Puts("distclean: cleantarget\n");
2903 if(!sameObjTargetDirs)
2904 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2905 f.Puts("\t$(call rmrq,obj/)\n");
2911 varStringLenDiffs.Free();
2912 delete varStringLenDiffs;
2916 delete cflagsVariations;
2917 delete nodeCFlagsMapping;
2918 delete ecflagsVariations;
2919 delete nodeECFlagsMapping;
2924 // ChangeWorkingDir(oldDirectory);
2925 // delete pathBackup;
2928 config.makingModified = false;
2932 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
2934 char extension[MAX_EXTENSION] = "c";
2935 char modulePath[MAX_LOCATION];
2936 char fixedModuleName[MAX_FILENAME];
2939 char objDirNoSpaces[MAX_LOCATION];
2940 String objDirExp = GetObjDirExpression(config);
2942 ReplaceSpaces(objDirNoSpaces, objDirExp);
2943 ReplaceSpaces(fixedModuleName, moduleName);
2945 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2946 //strcat(fixedModuleName, ".main");
2948 #if 0 // TODO: Fix nospaces stuff
2949 // *** Dependency command ***
2950 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2952 // System Includes (from global settings)
2953 for(item : compiler.dirs[Includes])
2955 strcat(command, " -isystem ");
2956 if(strchr(item.name, ' '))
2958 strcat(command, "\"");
2959 strcat(command, item);
2960 strcat(command, "\"");
2963 strcat(command, item);
2966 for(item = includeDirs.first; item; item = item.next)
2968 strcat(command, " -I");
2969 if(strchr(item.name, ' '))
2971 strcat(command, "\"");
2972 strcat(command, item.name);
2973 strcat(command, "\"");
2976 strcat(command, item.name);
2978 for(item = preprocessorDefs.first; item; item = item.next)
2980 strcat(command, " -D");
2981 strcat(command, item.name);
2985 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2989 bool firstLine = true;
2991 // To do some time: auto save external dependencies?
2994 if(dep.GetLine(line, sizeof(line)-1))
2998 char * colon = strstr(line, ":");
2999 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3013 // If we failed to generate dependencies...
3017 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3018 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n", extension);
3026 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3029 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3031 for(v : cflagsVariations)
3036 f.Printf("%s +=", variableName);
3038 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3039 f.Puts(&v ? &v : "");
3049 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3050 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3052 *projectPlatformOptions = null;
3053 *configPlatformOptions = null;
3058 if(!strcmpi(p.name, platform))
3060 *projectPlatformOptions = p;
3065 if(config && config.platforms)
3067 for(p : config.platforms)
3069 if(!strcmpi(p.name, platform))
3071 *configPlatformOptions = p;
3079 Project LegacyBinaryLoadProject(File f, char * filePath)
3081 Project project = null;
3082 char signature[sizeof(epjSignature)];
3084 f.Read(signature, sizeof(signature), 1);
3085 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3087 char topNodePath[MAX_LOCATION];
3088 /*ProjectConfig newConfig
3090 name = CopyString("Default");
3091 makingModified = true;
3092 compilingModified = true;
3093 linkingModified = true;
3097 project = Project { options = { } };
3098 LegacyBinaryLoadNode(project.topNode, f);
3099 delete project.topNode.path;
3100 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3101 MakeSlashPath(topNodePath);
3103 PathCatSlash(topNodePath, filePath);
3104 project.filePath = topNodePath;
3106 /* THIS IS ALREADY DONE BY filePath property
3107 StripLastDirectory(topNodePath, topNodePath);
3108 project.topNode.path = CopyString(topNodePath);
3110 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3112 // newConfig.options.defaultNameSpace = "";
3113 /*newConfig.objDir.dir = "obj";
3114 newConfig.targetDir.dir = "";*/
3116 //project.configurations = { [ newConfig ] };
3117 //project.config = newConfig;
3124 String targetFileName, targetDirectory, objectsDirectory;
3126 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3127 f.Read(&temp, sizeof(int),1);
3130 case 0: project.options.targetType = executable; break;
3131 case 1: project.options.targetType = sharedLibrary; break;
3132 case 2: project.options.targetType = staticLibrary; break;
3135 f.Read(&len, sizeof(int),1);
3136 targetFileName = new char[len+1];
3137 f.Read(targetFileName, sizeof(char), len+1);
3138 project.options.targetFileName = targetFileName;
3139 delete targetFileName;
3141 f.Read(&len, sizeof(int),1);
3142 targetDirectory = new char[len+1];
3143 f.Read(targetDirectory, sizeof(char), len+1);
3144 project.options.targetDirectory = targetDirectory;
3145 delete targetDirectory;
3147 f.Read(&len, sizeof(int),1);
3148 objectsDirectory = new byte[len+1];
3149 f.Read(objectsDirectory, sizeof(char), len+1);
3150 project.options.objectsDirectory = objectsDirectory;
3151 delete objectsDirectory;
3153 f.Read(&temp, sizeof(int),1);
3154 project./*config.*/options.debug = temp ? true : false;
3155 f.Read(&temp, sizeof(int),1);
3156 project./*config.*/options.optimization = temp ? speed : none;
3157 f.Read(&temp, sizeof(int),1);
3158 project./*config.*/options.profile = temp ? true : false;
3159 f.Read(&temp, sizeof(int),1);
3160 project.options.warnings = temp ? all : unset;
3162 f.Read(&count, sizeof(int),1);
3165 project.options.includeDirs = { };
3166 for(c = 0; c < count; c++)
3169 f.Read(&len, sizeof(int),1);
3170 name = new char[len+1];
3171 f.Read(name, sizeof(char), len+1);
3172 project.options.includeDirs.Add(name);
3176 f.Read(&count, sizeof(int),1);
3179 project.options.libraryDirs = { };
3180 for(c = 0; c < count; c++)
3183 f.Read(&len, sizeof(int),1);
3184 name = new char[len+1];
3185 f.Read(name, sizeof(char), len+1);
3186 project.options.libraryDirs.Add(name);
3190 f.Read(&count, sizeof(int),1);
3193 project.options.libraries = { };
3194 for(c = 0; c < count; c++)
3197 f.Read(&len, sizeof(int),1);
3198 name = new char[len+1];
3199 f.Read(name, sizeof(char), len+1);
3200 project.options.libraries.Add(name);
3204 f.Read(&count, sizeof(int),1);
3207 project.options.preprocessorDefinitions = { };
3208 for(c = 0; c < count; c++)
3211 f.Read(&len, sizeof(int),1);
3212 name = new char[len+1];
3213 f.Read(name, sizeof(char), len+1);
3214 project.options.preprocessorDefinitions.Add(name);
3218 f.Read(&temp, sizeof(int),1);
3219 project.options.console = temp ? true : false;
3222 for(node : project.topNode.files)
3224 if(node.type == resources)
3226 project.resNode = node;
3236 void ProjectConfig::LegacyProjectConfigLoad(File f)
3244 char subSection[128];
3250 f.GetLine(buffer, 65536 - 1);
3251 TrimLSpaces(buffer, buffer);
3252 TrimRSpaces(buffer, buffer);
3255 if(buffer[0] == '-')
3259 TrimLSpaces(equal, equal);
3260 if(!strcmpi(subSection, "LibraryDirs"))
3262 if(!options.libraryDirs)
3263 options.libraryDirs = { [ CopyString(equal) ] };
3265 options.libraryDirs.Add(CopyString(equal));
3267 else if(!strcmpi(subSection, "IncludeDirs"))
3269 if(!options.includeDirs)
3270 options.includeDirs = { [ CopyString(equal) ] };
3272 options.includeDirs.Add(CopyString(equal));
3275 else if(buffer[0] == '+')
3286 TrimLSpaces(equal, equal);
3287 delete name; name = CopyString(equal); // property::name = equal;
3290 else if(!strcmpi(buffer, "Compiler Options"))
3291 strcpy(section, buffer);
3292 else if(!strcmpi(buffer, "IncludeDirs"))
3293 strcpy(subSection, buffer);
3294 else if(!strcmpi(buffer, "Linker Options"))
3295 strcpy(section, buffer);
3296 else if(!strcmpi(buffer, "LibraryDirs"))
3297 strcpy(subSection, buffer);
3298 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3305 equal = strstr(buffer, "=");
3309 TrimRSpaces(buffer, buffer);
3311 TrimLSpaces(equal, equal);
3312 if(!strcmpi(buffer, "Target Name"))
3313 options.targetFileName = /*CopyString(*/equal/*)*/;
3314 else if(!strcmpi(buffer, "Target Type"))
3316 if(!strcmpi(equal, "Executable"))
3317 options.targetType = executable;
3318 else if(!strcmpi(equal, "Shared"))
3319 options.targetType = sharedLibrary;
3320 else if(!strcmpi(equal, "Static"))
3321 options.targetType = staticLibrary;
3323 options.targetType = executable;
3325 else if(!strcmpi(buffer, "Target Directory"))
3326 options.targetDirectory = /*CopyString(*/equal/*)*/;
3327 else if(!strcmpi(buffer, "Console"))
3328 options.console = ParseTrueFalseValue(equal);
3329 else if(!strcmpi(buffer, "Libraries"))
3331 if(!options.libraries) options.libraries = { };
3332 ParseArrayValue(options.libraries, equal);
3334 else if(!strcmpi(buffer, "Intermediate Directory"))
3335 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3336 else if(!strcmpi(buffer, "Debug"))
3337 options.debug = ParseTrueFalseValue(equal);
3338 else if(!strcmpi(buffer, "Optimize"))
3340 if(!strcmpi(equal, "None"))
3341 options.optimization = none;
3342 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3343 options.optimization = speed;
3344 else if(!strcmpi(equal, "Size"))
3345 options.optimization = size;
3347 options.optimization = none;
3349 else if(!strcmpi(buffer, "Compress"))
3350 options.compress = ParseTrueFalseValue(equal);
3351 else if(!strcmpi(buffer, "Profile"))
3352 options.profile = ParseTrueFalseValue(equal);
3353 else if(!strcmpi(buffer, "AllWarnings"))
3354 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3355 else if(!strcmpi(buffer, "MemoryGuard"))
3356 options.memoryGuard = ParseTrueFalseValue(equal);
3357 else if(!strcmpi(buffer, "Default Name Space"))
3358 options.defaultNameSpace = CopyString(equal);
3359 else if(!strcmpi(buffer, "Strict Name Spaces"))
3360 options.strictNameSpaces = ParseTrueFalseValue(equal);
3361 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3363 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3364 ParseArrayValue(options.preprocessorDefinitions, equal);
3370 if(!options.targetDirectory && options.objectsDirectory)
3371 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3372 //if(!objDir.dir) objDir.dir = "obj";
3373 //if(!targetDir.dir) targetDir.dir = "";
3374 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3375 // if(!defaultNameSpace) property::defaultNameSpace = "";
3376 makingModified = true;
3379 Project LegacyAsciiLoadProject(File f, char * filePath)
3381 Project project = null;
3382 ProjectNode node = null;
3384 char parentPath[MAX_LOCATION];
3385 char section[128] = "";
3386 char subSection[128] = "";
3388 bool configurationsPresent = false;
3398 f.GetLine(buffer, 65536 - 1);
3399 TrimLSpaces(buffer, buffer);
3400 TrimRSpaces(buffer, buffer);
3403 if(buffer[0] == '-' || buffer[0] == '=')
3405 bool simple = buffer[0] == '-';
3408 TrimLSpaces(equal, equal);
3409 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3411 if(!project.config.options.libraryDirs)
3412 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3414 project.config.options.libraryDirs.Add(CopyString(equal));
3416 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3418 if(!project.config.options.includeDirs)
3419 project.config.options.includeDirs = { [ CopyString(equal) ] };
3421 project.config.options.includeDirs.Add(CopyString(equal));
3423 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3425 len = strlen(equal);
3428 char temp[MAX_LOCATION];
3429 ProjectNode child { };
3430 // We don't need to do this anymore, fileName is just a property that sets name & path
3431 // child.fileName = CopyString(equal);
3434 child.name = CopyString(equal);
3435 child.path = CopyString(parentPath);
3439 GetLastDirectory(equal, temp);
3440 child.name = CopyString(temp);
3441 StripLastDirectory(equal, temp);
3442 child.path = CopyString(temp);
3444 child.nodeType = file;
3445 child.parent = parent;
3446 child.indent = parent.indent + 1;
3448 child.icon = NodeIcons::SelectFileIcon(child.name);
3449 parent.files.Add(child);
3455 StripLastDirectory(parentPath, parentPath);
3456 parent = parent.parent;
3460 else if(buffer[0] == '+')
3464 TrimLSpaces(equal, equal);
3465 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3467 char temp[MAX_LOCATION];
3468 ProjectNode child { };
3469 // NEW: Folders now have a path set like files
3470 child.name = CopyString(equal);
3471 strcpy(temp, parentPath);
3472 PathCatSlash(temp, child.name);
3473 child.path = CopyString(temp);
3475 child.parent = parent;
3476 child.indent = parent.indent + 1;
3477 child.type = folder;
3478 child.nodeType = folder;
3480 child.icon = folder;
3481 PathCatSlash(parentPath, child.name);
3482 parent.files.Add(child);
3487 else if(!strcmpi(section, "Configurations"))
3489 ProjectConfig newConfig
3491 makingModified = true;
3495 LegacyProjectConfigLoad(newConfig, f);
3496 project.configurations.Add(newConfig);
3499 else if(!strcmpi(buffer, "ECERE Project File"));
3500 else if(!strcmpi(buffer, "Version 0a"))
3501 ; //strcpy(version, "0a");
3502 else if(!strcmpi(buffer, "Version 0.1a"))
3503 ; //strcpy(version, "0.1a");
3504 else if(!strcmpi(buffer, "Configurations"))
3506 project.configurations.Free();
3507 project.config = null;
3508 strcpy(section, buffer);
3509 configurationsPresent = true;
3511 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3513 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3514 char topNodePath[MAX_LOCATION];
3515 // newConfig.defaultNameSpace = "";
3516 //newConfig.objDir.dir = "obj";
3517 //newConfig.targetDir.dir = "";
3518 project = Project { /*options = { }*/ };
3519 project.configurations = { [ newConfig ] };
3520 project.config = newConfig;
3521 // if(project.topNode.path) delete project.topNode.path;
3522 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3523 MakeSlashPath(topNodePath);
3524 PathCatSlash(topNodePath, filePath);
3525 project.filePath = topNodePath;
3526 parentPath[0] = '\0';
3527 parent = project.topNode;
3529 strcpy(section, "Target");
3534 if(equal[0] == '\"')
3536 StripQuotes(equal, equal);
3537 delete project.moduleName; project.moduleName = CopyString(equal);
3541 else if(!strcmpi(buffer, "Compiler Options"));
3542 else if(!strcmpi(buffer, "IncludeDirs"))
3543 strcpy(subSection, buffer);
3544 else if(!strcmpi(buffer, "Linker Options"));
3545 else if(!strcmpi(buffer, "LibraryDirs"))
3546 strcpy(subSection, buffer);
3547 else if(!strcmpi(buffer, "Files"))
3549 strcpy(section, "Target");
3550 strcpy(subSection, buffer);
3552 else if(!strcmpi(buffer, "Resources"))
3554 ProjectNode child { };
3555 parent.files.Add(child);
3556 child.parent = parent;
3557 child.indent = parent.indent + 1;
3558 child.name = CopyString(buffer);
3559 child.path = CopyString("");
3560 child.type = resources;
3562 child.icon = archiveFile;
3563 project.resNode = child;
3566 strcpy(subSection, buffer);
3570 equal = strstr(buffer, "=");
3574 TrimRSpaces(buffer, buffer);
3576 TrimLSpaces(equal, equal);
3578 if(!strcmpi(section, "Target"))
3580 if(!strcmpi(buffer, "Build Exclusions"))
3582 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3584 /*if(node && node.type != NodeTypes::project)
3585 ParseListValue(node.buildExclusions, equal);*/
3588 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3590 delete project.resNode.path;
3591 project.resNode.path = CopyString(equal);
3592 PathCatSlash(parentPath, equal);
3596 else if(!strcmpi(buffer, "Intermediate Directory"))
3597 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3598 else if(!strcmpi(buffer, "Debug"))
3599 project.config.options.debug = ParseTrueFalseValue(equal);
3600 else if(!strcmpi(buffer, "Optimize"))
3602 if(!strcmpi(equal, "None"))
3603 project.config.options.optimization = none;
3604 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3605 project.config.options.optimization = speed;
3606 else if(!strcmpi(equal, "Size"))
3607 project.config.options.optimization = size;
3609 project.config.options.optimization = none;
3611 else if(!strcmpi(buffer, "Profile"))
3612 project.config.options.profile = ParseTrueFalseValue(equal);
3613 else if(!strcmpi(buffer, "MemoryGuard"))
3614 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3617 if(!project.options) project.options = { };
3619 // Project Wide Settings (All configs)
3620 if(!strcmpi(buffer, "Target Name"))
3621 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3622 else if(!strcmpi(buffer, "Target Type"))
3624 if(!strcmpi(equal, "Executable"))
3625 project.options.targetType = executable;
3626 else if(!strcmpi(equal, "Shared"))
3627 project.options.targetType = sharedLibrary;
3628 else if(!strcmpi(equal, "Static"))
3629 project.options.targetType = staticLibrary;
3631 project.options.targetType = executable;
3633 else if(!strcmpi(buffer, "Target Directory"))
3634 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3635 else if(!strcmpi(buffer, "Console"))
3636 project.options.console = ParseTrueFalseValue(equal);
3637 else if(!strcmpi(buffer, "Libraries"))
3639 if(!project.options.libraries) project.options.libraries = { };
3640 ParseArrayValue(project.options.libraries, equal);
3642 else if(!strcmpi(buffer, "AllWarnings"))
3643 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3644 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3646 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3648 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3649 ParseListValue(node.preprocessorDefs, equal);*/
3653 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3654 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3665 SplitPlatformLibraries(project);
3667 if(configurationsPresent)
3668 CombineIdenticalConfigOptions(project);
3672 void SplitPlatformLibraries(Project project)
3674 if(project && project.configurations)
3676 for(cfg : project.configurations)
3678 if(cfg.options.libraries && cfg.options.libraries.count)
3680 Iterator<String> it { cfg.options.libraries };
3684 char * platformName = strstr(l, ":");
3687 PlatformOptions platform = null;
3689 if(!cfg.platforms) cfg.platforms = { };
3690 for(p : cfg.platforms)
3692 if(!strcmpi(platformName, p.name))
3700 platform = { name = CopyString(platformName), options = { libraries = { } } };
3701 cfg.platforms.Add(platform);
3703 *(platformName-1) = 0;
3704 platform.options.libraries.Add(CopyString(l));
3706 cfg.options.libraries.Delete(it.pointer);
3715 void CombineIdenticalConfigOptions(Project project)
3717 if(project && project.configurations && project.configurations.count)
3720 ProjectOptions nullOptions { };
3721 ProjectConfig firstConfig = null;
3722 for(cfg : project.configurations)
3724 if(cfg.options.targetType != staticLibrary)
3731 firstConfig = project.configurations.firstIterator.data;
3733 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3735 if(!member.isProperty)
3737 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3742 for(cfg : project.configurations)
3744 if(cfg != firstConfig)
3746 if(cfg.options.targetType != staticLibrary)
3750 if(type.type == noHeadClass || type.type == normalClass)
3752 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3753 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3754 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3758 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3759 (byte *)firstConfig.options + member.offset + member._class.offset,
3760 (byte *)cfg.options + member.offset + member._class.offset);
3772 if(type.type == noHeadClass || type.type == normalClass)
3774 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3775 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3776 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3781 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3782 (byte *)firstConfig.options + member.offset + member._class.offset,
3783 (byte *)nullOptions + member.offset + member._class.offset))
3787 if(!project.options) project.options = { };
3789 /*if(type.type == noHeadClass || type.type == normalClass)
3791 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
3792 (byte *)project.options + member.offset + member._class.offset,
3793 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3797 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3798 // TOFIX: ListBox::SetData / OnCopy mess
3799 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
3800 (byte *)project.options + member.offset + member._class.offset,
3801 (type.typeSize > 4) ? address :
3802 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3803 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3804 (void *)*(byte *)address )));
3807 (byte *)project.options + member.offset + member._class.offset,
3808 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3810 for(cfg : project.configurations)
3812 if(cfg.options.targetType == staticLibrary)
3816 if(type.type == noHeadClass || type.type == normalClass)
3818 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3819 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3820 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3824 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3825 (byte *)firstConfig.options + member.offset + member._class.offset,
3826 (byte *)cfg.options + member.offset + member._class.offset);
3831 if(cfg != firstConfig)
3833 if(type.type == noHeadClass || type.type == normalClass)
3835 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
3836 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3840 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
3841 (byte *)cfg.options + member.offset + member._class.offset);
3843 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3846 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3853 // Compare Platform Specific Settings
3856 for(cfg : project.configurations)
3858 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3859 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3865 if(same && firstConfig.platforms)
3867 for(cfg : project.configurations)
3869 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3871 if(cfg != firstConfig)
3873 cfg.platforms.Free();
3874 delete cfg.platforms;
3877 project.platforms = firstConfig.platforms;
3878 firstConfig.platforms = null;
3882 // Static libraries can't contain libraries
3883 for(cfg : project.configurations)
3885 if(cfg.options.targetType == staticLibrary)
3887 if(!cfg.options.libraries) cfg.options.libraries = { };
3888 cfg.options.libraries.Free();
3894 Project LoadProject(char * filePath, char * activeConfigName)
3896 Project project = null;
3897 File f = FileOpen(filePath, read);
3900 project = LegacyBinaryLoadProject(f, filePath);
3903 JSONParser parser { f = f };
3904 JSONResult result = parser.GetObject(class(Project), &project);
3907 char insidePath[MAX_LOCATION];
3909 delete project.topNode.files;
3910 if(!project.files) project.files = { };
3911 project.topNode.files = project.files;
3912 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3913 delete project.resNode.path;
3914 project.resNode.path = project.resourcesPath;
3915 project.resourcesPath = null;
3916 project.resNode.nodeType = (ProjectNodeType)-1;
3917 delete project.resNode.files;
3918 project.resNode.files = project.resources;
3919 project.files = null;
3920 project.resources = null;
3921 if(!project.configurations) project.configurations = { };
3924 char topNodePath[MAX_LOCATION];
3925 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3926 MakeSlashPath(topNodePath);
3927 PathCatSlash(topNodePath, filePath);
3928 project.filePath = topNodePath;//filePath;
3931 project.topNode.FixupNode(insidePath);
3936 project = LegacyAsciiLoadProject(f, filePath);
3942 if(!project.options) project.options = { };
3943 if(activeConfigName && activeConfigName[0] && project.configurations)
3945 for(cfg : project.configurations)
3947 if(!strcmpi(cfg.name, activeConfigName))
3949 project.config = cfg;
3954 if(!project.config && project.configurations)
3955 project.config = project.configurations.firstIterator.data;
3957 if(!project.resNode)
3959 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3962 if(!project.moduleName)
3963 project.moduleName = CopyString(project.name);
3964 if(project.config &&
3965 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3966 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3968 //delete project.config.options.targetFileName;
3970 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3971 project.config.options.optimization = none;
3972 project.config.options.debug = true;
3973 //project.config.options.warnings = unset;
3974 project.config.options.memoryGuard = false;
3975 project.config.compilingModified = true;
3976 project.config.linkingModified = true;
3978 else if(!project.topNode.name && project.config)
3980 project.topNode.name = CopyString(project.config.options.targetFileName);
3983 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3984 project.topNode.configurations = project.configurations;
3985 project.topNode.platforms = project.platforms;
3986 project.topNode.options = project.options;*/