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();
49 ide.UpdateCompilerConfigs(true);
54 #ifdef MAKEFILE_GENERATOR
55 CompilerConfig defaultCompiler;
58 // LEGACY BINARY EPJ LOADING
60 SetBool ParseTrueFalseValue(char * string)
62 if(!strcmpi(string, "True")) return true;
66 void ParseArrayValue(Array<String> array, char * equal)
68 char * start, * comma;
70 string = CopyString(equal);
74 comma = strstr(start, ",");
77 array.Add(CopyString(start));
87 void ProjectNode::LegacyBinaryLoadNode(File f)
92 f.Read(&len, sizeof(len), 1);
93 name = new char[len+1];
95 f.Read(name, sizeof(char), len+1);
96 f.Read(&len, sizeof(len), 1);
98 path = new char[len+1];
99 f.Read(path, sizeof(char), len+1);
102 fileName = new char[fileNameLen+2];
103 strcpy(fileName, path);
104 if(fileName[0]) strcat(fileName, "/");
105 strcat(fileName, name);
108 f.Read(&type, sizeof(type), 1);
109 f.Read(&count, sizeof(count), 1);
114 icon = NodeIcons::SelectFileIcon(name);
119 icon = NodeIcons::SelectNodeIcon(type);
122 if(count && !files) files = { };
123 for(c = 0; c < count; c++)
125 ProjectNode child { };
128 child.indent = indent + 1;
129 LegacyBinaryLoadNode(child, f);
133 /*void LegacyBinarySaveNode(File f)
138 f.Write(&len, sizeof(len), 1);
139 f.Write(name, sizeof(char), len+1);
143 // Projects Absolute Path Are Not Saved
145 f.Write(&len, sizeof(len), 1);
146 f.Write(&len, sizeof(char), 1);
151 f.Write(&len, sizeof(len), 1);
152 f.Write(path, sizeof(char), len+1);
154 f.Write(&type, sizeof(type), 1);
155 f.Write(&children.count, sizeof(children.count), 1);
156 for(child = children.first; child; child.next)
160 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
163 char printPath[MAX_LOCATION];
165 if(type == project && (files.count /*|| preprocessorDefs.first*/))
167 f.Printf("\n Files\n");
169 else if(type == file)
171 if(!strcmp(path, insidePath))
172 f.Printf("%s - %s\n", indentation, name);
175 strcpy(printPath, path);
176 len = strlen(printPath);
178 if(printPath[len-1] != '/')
179 strcat(printPath, "/");
180 strcat(printPath, name);
181 f.Printf("%s = %s\n", indentation, printPath);
184 f.Printf("\nError\n\n");
186 else if(type == folder)
188 f.Printf("%s + %s\n", indentation, name);
190 else if(type == resources && files.count)
192 PathCatSlash(insidePath, path);
193 f.Printf("\n%sResources\n", indentation);
195 f.Printf("%s Path = %s\n", indentation, path);
198 /*if(buildExclusions.first && type != project)
200 for(item = buildExclusions.first; item; item = item.next)
202 if(item == buildExclusions.first)
203 f.Printf("%s Build Exclusions = %s", indentation, item.name);
205 f.Printf(", %s", item.name);
210 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
212 for(item = preprocessorDefs.first; item; item = item.next)
214 if(item == preprocessorDefs.first)
215 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
217 f.Printf(", %s", item.name);
223 if(type == project && (files.count /*|| preprocessorDefs.first*/))
227 LegacyAsciiSaveNode(child, f, indentation, insidePath);
229 else if(type == folder)
231 strcat(indentation, " ");
232 // WHAT WAS THIS: strcpy(printPath, path);
233 // TOCHECK: why is Unix/PathCat not used here
234 len = strlen(insidePath);
236 if(insidePath[len-1] != '/')
237 strcat(insidePath, "/");
238 strcat(insidePath, name);
241 LegacyAsciiSaveNode(child, f, indentation, insidePath);
242 f.Printf("%s -\n", indentation);
243 indentation[strlen(indentation) - 3] = '\0';
244 StripLastDirectory(insidePath, insidePath);
246 else if(type == resources && files.count)
250 LegacyAsciiSaveNode(child, f, indentation, insidePath);
251 StripLastDirectory(insidePath, insidePath);
256 void ProjectConfig::LegacyProjectConfigSave(File f)
258 char * indentation = " ";
260 //f.Printf("\n * Common\n");
262 f.Printf("\n + %s\n", name);
263 f.Printf("\n Compiler\n\n");
264 if(objDir.expression[0])
265 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
266 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
267 switch(options.optimization)
269 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
270 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
271 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
273 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
275 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
276 if(options.memoryGuard == true)
277 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
278 if(options.strictNameSpaces == true)
279 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
280 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
281 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
282 TOFIX: Compiler Bug {
283 if(options.preprocessorDefinitions.count)
286 for(item : options.preprocessorDefinitions)
290 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
294 f.Printf(", %s", item);
299 if(options.includeDirs.count)
301 f.Printf("\n%sInclude Directories\n", indentation);
302 for(item : options.includeDirs)
303 f.Printf("%s - %s\n", indentation, name);
307 f.Printf("\n%sLinker\n\n", indentation);
308 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
309 switch(options.targetType)
311 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
312 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
313 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
315 if(targetDir.expression[0])
316 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
318 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
320 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
321 if(options.libraries.count)
324 for(item : options.libraries)
328 f.Printf("\n%sLibraries = %s", indentation, name);
332 f.Printf(", %s", item);
336 if(options.libraryDirs.count)
338 f.Printf("\n%sLibrary Directories\n\n", indentation);
339 for(item : options.libraryDirs)
340 f.Printf(" - %s\n", indentation, item);
344 void LegacyAsciiSaveProject(File f, Project project)
346 char indentation[128*3];
347 char path[MAX_LOCATION];
349 f.Printf("\nECERE Project File : Format Version 0.1b\n");
350 f.Printf("\nDescription\n%s\n.\n", project.description);
351 f.Printf("\nLicense\n%s\n.\n", project.license);
352 f.Printf("\nModule Name = %s\n", project.moduleName);
353 f.Printf("\n Configurations\n");
354 //////////////////////////////////////commonConfig.Save(f, true);
355 for(cfg : project.configurations)
356 LegacyProjectConfigSave(cfg, f);
358 strcpy(indentation, " ");
360 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
366 // *** NEW JSON PROJECT FORMAT ***
367 public enum ProjectNodeType { file, folder };
369 // *******************************
371 define PEEK_RESOLUTION = (18.2 * 10);
377 static Array<String> notLinkerOptions
399 static bool IsLinkerOption(String s)
401 for(i : notLinkerOptions)
402 if(strstr(s, "-Wl,") || !strcmp(s, i))
407 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
409 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
411 define WorkspaceExtension = "ews";
412 define ProjectExtension = "epj";
414 define stringInFileIncludedFrom = "In file included from ";
416 void ReplaceSpaces(char * output, char * source)
421 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
423 if(ch == ' ') output[dc++] = '\\';
426 if(ch == '(' || ch == ')') output[dc++] = '\\';
436 void ReplaceUnwantedMakeChars(char * output, char * source)
441 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
445 if(ch == '(' || ch == ')') output[dc++] = '\\';
458 static void OutputNoSpace(File f, char * source)
460 char * output = new char[strlen(source)+1024];
461 ReplaceSpaces(output, source);
466 enum ListOutputMethod { inPlace, newLine, lineEach };
468 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
471 const int breakListLength = 1536;
472 const int breakLineLength = 78; // TODO: turn this into an option.
474 int c, len, itemCount = 0;
475 Array<int> breaks { };
479 MapNode<String, int> mn;
480 for(c=0; c<list.count; c++)
482 len = strlen(list[c]) + 3;
483 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
485 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
487 if(strstr(list[c], mn.key))
491 if(charCount + len > breakListLength)
493 breaks.Add(itemCount);
501 breaks.Add(itemCount);
502 numOfBreaks = breaks.count;
507 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
508 for(c=0; c<numOfBreaks; c++)
509 f.Printf(" $(%s%d)", name, c+1);
513 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
519 for(c=0; c<numOfBreaks; c++)
522 f.Printf("%s%d =", name, c+1);
525 itemCount = breaks[c];
526 for(n=offset; n<offset+itemCount; n++)
528 if(false) // TODO: turn this into an option.
530 int itemLen = strlen(list[n]);
531 if(len > 3 && len + itemLen > breakLineLength)
533 f.Printf(" \\\n\t%s", list[n]);
539 f.Printf(" %s", list[n]);
543 f.Printf(" \\\n\t%s", list[n]);
558 void OutputLinkObjectActions(File f, char * name, int parts)
563 for(c=0; c<parts; c++)
564 f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
566 f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
570 void OutputCleanActions(File f, char * name, int parts)
575 for(c=0; c<parts; c++)
576 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
579 f.Printf("\t$(call rmq,$(%s))\n", name);
582 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
586 if(method == newLine)
590 if(method == lineEach)
592 f.Printf(" -%s", option);
594 OutputNoSpace(f, item);
596 f.Printf("%s", item);
601 void StringNoSpaceToDynamicString(DynamicString s, char * path)
603 char * output = new char[strlen(path)+1024];
604 ReplaceSpaces(output, path);
609 static void OutputLibraries(File f, Array<String> libraries)
611 for(item : libraries)
613 char ext[MAX_EXTENSION];
614 char temp[MAX_LOCATION];
616 bool usedFunction = false;
617 GetExtension(item, ext);
618 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
622 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
624 if(!strncmp(item, "lib", 3))
625 strcpy(temp, item + 3);
628 StripExtension(temp);
631 f.Puts(" \\\n\t$(call _L,");
640 void CamelCase(char * string)
642 int c, len = strlen(string);
643 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
644 string[c] = (char)tolower(string[c]);
647 CompilerConfig GetCompilerConfig()
649 #ifndef MAKEFILE_GENERATOR
650 CompilerConfig compiler = null;
651 if(ide && ide.workspace)
652 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
655 incref defaultCompiler;
656 return defaultCompiler;
660 define localTargetType = config && config.options && config.options.targetType ?
661 config.options.targetType : options && options.targetType ?
662 options.targetType : TargetTypes::executable;
663 define localWarnings = config && config.options && config.options.warnings ?
664 config.options.warnings : options && options.warnings ?
665 options.warnings : WarningsOption::unset;
666 define localDebug = config && config.options && config.options.debug ?
667 config.options.debug : options && options.debug ?
668 options.debug : SetBool::unset;
669 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
670 config.options.memoryGuard : options && options.memoryGuard ?
671 options.memoryGuard : SetBool::unset;
672 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
673 config.options.noLineNumbers : options && options.noLineNumbers ?
674 options.noLineNumbers : SetBool::unset;
675 define localProfile = config && config.options && config.options.profile ?
676 config.options.profile : options && options.profile ?
677 options.profile : SetBool::unset;
678 define localOptimization = config && config.options && config.options.optimization ?
679 config.options.optimization : options && options.optimization ?
680 options.optimization : OptimizationStrategy::none;
681 define localFastMath = config && config.options && config.options.fastMath ?
682 config.options.fastMath : options && options.fastMath ?
683 options.fastMath : SetBool::unset;
684 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
685 config.options.defaultNameSpace : options && options.defaultNameSpace ?
686 options.defaultNameSpace : null;
687 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
688 config.options.strictNameSpaces : options && options.strictNameSpaces ?
689 options.strictNameSpaces : SetBool::unset;
690 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
691 define localTargetFileName = config && config.options && config.options.targetFileName ?
692 config.options.targetFileName : options && options.targetFileName ?
693 options.targetFileName : "";
694 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
695 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
696 options.targetDirectory : null;
697 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
698 ideSettings.projectDefaultIntermediateObjDir[0] ?
699 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
700 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
701 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
702 options.objectsDirectory : null;
703 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
704 ideSettings.projectDefaultIntermediateObjDir[0] ?
705 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
706 define localConsole = config && config.options && config.options.console ?
707 config.options.console : options && options.console ?
708 options.console : SetBool::unset;
709 define localCompress = config && config.options && config.options.compress ?
710 config.options.compress : options && options.compress ?
711 options.compress : SetBool::unset;
713 define platformTargetType =
714 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
715 configPOs.options.targetType :
716 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
717 projectPOs.options.targetType : TargetTypes::unset;
720 char * PlatformToMakefileTargetVariable(Platform platform)
722 return platform == win32 ? "WINDOWS_TARGET" :
723 platform == tux ? "LINUX_TARGET" :
724 platform == apple ? "OSX_TARGET" :
728 char * TargetTypeToMakefileVariable(TargetTypes targetType)
730 return targetType == executable ? "executable" :
731 targetType == sharedLibrary ? "sharedlib" :
732 targetType == staticLibrary ? "staticlib" :
736 // Move this to ProjectConfig? null vs Common to consider...
737 char * GetConfigName(ProjectConfig config)
739 return config ? config.name : "Common";
742 public enum SingleFileCompileMode { normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject };
744 class Project : struct
746 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
747 // We might want to tweak this default behavior of regular classes ?
748 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
753 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
754 property Array<PlatformOptions> platforms
756 get { return platforms; }
759 if(platforms) { platforms.Free(); delete platforms; }
762 List<PlatformOptions> empty { };
763 Iterator<PlatformOptions> it { value };
765 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
766 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
776 if(p.options && !p.options.isEmpty)
783 List<ProjectConfig> configurations;
784 LinkList<ProjectNode> files;
785 String resourcesPath;
786 LinkList<ProjectNode> resources;
788 property char * description
790 set { delete description; if(value && value[0]) description = CopyString(value); }
791 get { return description ? description : ""; }
792 isset { return description != null && description[0]; }
795 property char * license
797 set { delete license; if(value && value[0]) license = CopyString(value); }
798 get { return license ? license : ""; }
799 isset { return license != null && license[0]; }
802 property char * compilerConfigsDir
804 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
805 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
806 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
809 property char * moduleVersion
811 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
812 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
813 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
817 // topNode.name holds the file name (.epj)
818 ProjectOptions options;
819 Array<PlatformOptions> platforms;
820 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
823 ProjectConfig config;
825 // This is the file name stripped of the epj extension
826 // It should NOT be edited, saved or loaded anywhere
831 String compilerConfigsDir;
832 String moduleVersion;
834 #ifndef MAKEFILE_GENERATOR
835 FileMonitor fileMonitor
837 this, FileChange { modified = true };
838 bool OnFileNotify(FileChange action, char * param)
840 fileMonitor.StopMonitoring();
841 if(OnProjectModified(action, param))
842 fileMonitor.StartMonitoring();
847 bool StartMonitoring()
849 fileMonitor.fileName = filePath;
850 fileMonitor.StartMonitoring();
854 bool StopMonitoring()
856 fileMonitor.StopMonitoring();
860 bool OnProjectModified(FileChange fileChange, char * param)
863 sprintf(temp, $"The project %s was modified by another application.\n"
864 "Would you like to reload it and lose your changes?", name);
865 if(MessageBox { type = yesNo, master = ide,
866 text = $"Project has been modified", contents = temp }.Modal() == yes)
868 Project project = LoadProject(filePath, config.name);
871 ProjectView projectView = ide.projectView;
872 DataRow prev = topNode.row ? topNode.row.previous : null;
873 FileMonitor fm = fileMonitor;
874 bool confirmation = true;
878 if(projectView.projectSettingsDialog)
880 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
882 projectView.projectSettingsDialog.Destroy(0);
885 projectView.DeleteNode(topNode);
892 topNode.project = this;
896 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
897 projectView.AddNode(topNode, null);
898 topNode.row.Move(prev);
900 projectView.ShowOutputBuildLog(true);
901 projectView.DisplayCompiler(compiler, false);
902 projectView.ProjectUpdateMakefileForAllConfigs(this);
905 eSystem_Delete(project);
917 // This frees contents without freeing the instance
918 // For use from destructor and for file monitor reloading
919 // (To work around JSON loader (LoadProject) always returning a new instance)
922 if(platforms) { platforms.Free(); delete platforms; }
923 if(configurations) { configurations.Free(); delete configurations; }
924 if(files) { files.Free(); delete files; }
925 if(resources) { resources.Free(); delete resources; }
927 delete resourcesPath;
931 delete compilerConfigsDir;
933 delete moduleVersion;
941 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
942 topNode.configurations = null;
943 topNode.platforms = null;
944 topNode.options = null;
949 property ProjectConfig config
955 topNode.info = CopyString(GetConfigName(config));
958 property char * filePath
964 char string[MAX_LOCATION];
965 GetLastDirectory(value, string);
967 topNode.name = CopyString(string);
968 StripExtension(string);
970 name = CopyString(string);
971 StripLastDirectory(value, string);
973 topNode.path = CopyString(string);
975 filePath = CopyString(value);
980 TargetTypes GetTargetType(ProjectConfig config)
982 TargetTypes targetType = localTargetType;
986 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
989 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
991 PlatformOptions projectPOs, configPOs;
992 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
993 if(platformTargetType)
1000 char * GetObjDirExpression(ProjectConfig config)
1002 // TODO: Support platform options
1003 char * expression = localObjectsDirectory;
1005 expression = settingsObjectsDirectory;
1009 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1011 char * expression = GetObjDirExpression(config);
1012 DirExpression objDir { type = intermediateObjectsDir };
1013 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1017 char * GetTargetDirExpression(ProjectConfig config)
1019 // TODO: Support platform options
1020 char * expression = localTargetDirectory;
1022 expression = settingsTargetDirectory;
1026 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1028 char * expression = GetTargetDirExpression(config);
1029 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1030 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1034 WarningsOption GetWarnings(ProjectConfig config)
1036 WarningsOption warnings = localWarnings;
1040 bool GetDebug(ProjectConfig config)
1042 SetBool debug = localDebug;
1043 return debug == true;
1046 bool GetMemoryGuard(ProjectConfig config)
1048 SetBool memoryGuard = localMemoryGuard;
1049 return memoryGuard == true;
1052 bool GetNoLineNumbers(ProjectConfig config)
1054 SetBool noLineNumbers = localNoLineNumbers;
1055 return noLineNumbers == true;
1058 bool GetProfile(ProjectConfig config)
1060 SetBool profile = localProfile;
1061 return profile == true;
1064 OptimizationStrategy GetOptimization(ProjectConfig config)
1066 OptimizationStrategy optimization = localOptimization;
1067 return optimization;
1070 bool GetFastMath(ProjectConfig config)
1072 SetBool fastMath = localFastMath;
1073 return fastMath == true;
1076 String GetDefaultNameSpace(ProjectConfig config)
1078 String defaultNameSpace = localDefaultNameSpace;
1079 return defaultNameSpace;
1082 bool GetStrictNameSpaces(ProjectConfig config)
1084 SetBool strictNameSpaces = localStrictNameSpaces;
1085 return strictNameSpaces == true;
1088 String GetTargetFileName(ProjectConfig config)
1090 String targetFileName = localTargetFileName;
1091 return targetFileName;
1094 //String targetDirectory;
1095 //String objectsDirectory;
1096 bool GetConsole(ProjectConfig config)
1098 SetBool console = localConsole;
1099 return console == true;
1102 bool GetCompress(ProjectConfig config)
1104 SetBool compress = localCompress;
1105 return compress == true;
1107 //SetBool excludeFromBuild;
1109 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1111 #ifndef MAKEFILE_GENERATOR
1112 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1116 bool GetConfigIsInDebugSession(ProjectConfig config)
1118 #ifndef MAKEFILE_GENERATOR
1119 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1123 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1125 #ifndef MAKEFILE_GENERATOR
1126 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1130 #ifndef MAKEFILE_GENERATOR
1131 bool Save(char * fileName)
1134 /*char output[MAX_LOCATION];
1135 ChangeExtension(fileName, "json", output);
1136 f = FileOpen(output, write);*/
1137 f = FileOpen(fileName, write);
1140 files = topNode.files;
1141 resources = resNode.files;
1142 resourcesPath = resNode.path;
1144 files.Remove(resNode);
1147 WriteJSONObject(f, class(Project), this, 0);
1153 resourcesPath = null;
1160 // This method is only called from Debugger, should be moved to Debugger class?
1161 #ifndef MAKEFILE_GENERATOR
1162 bool GetRelativePath(char * filePath, char * relativePath)
1165 char moduleName[MAX_FILENAME];
1166 GetLastDirectory(filePath, moduleName);
1167 // try with workspace dir first?
1168 if((node = topNode.Find(moduleName, false)))
1170 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1171 PathCatSlash(relativePath, node.name);
1176 // Tweak for automatically resolving symbol loader modules
1177 char * sl = strstr(moduleName, ".main.ec");
1178 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1180 char objDir[MAX_LOCATION];
1181 DirExpression objDirExp;
1182 CompilerConfig compiler = ide.debugger.currentCompiler;
1183 ProjectConfig config = ide.debugger.prjConfig;
1184 int bitDepth = ide.debugger.bitDepth;
1185 // This is not perfect, as multiple source files exist for the symbol loader module...
1186 // We try to set it in the debug config object directory.
1187 if(!compiler || !config)
1189 // If we're not currently debugging, set a breakpoint in the active compiler/config
1190 compiler = GetCompilerConfig();
1191 config = this.config;
1192 // If the current config is not debuggable, set it in the first debuggable config found
1193 if(config && !config.options.debug)
1195 for(c : configurations; c.options.debug)
1202 objDirExp = GetObjDir(compiler, config, bitDepth);
1203 strcpy(objDir, objDirExp.dir);
1205 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1206 ReplaceSpaces(objDir, objDir);
1207 strcpy(relativePath, objDir);
1209 PathCatSlash(relativePath, moduleName);
1213 // WARNING: On failure, relative path is uninitialized
1218 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1220 TargetTypes targetType = GetTargetType(config);
1221 String targetFileName = GetTargetFileName(config);
1222 if(targetType == staticLibrary)
1224 PathCatSlash(string, "lib");
1225 strcat(string, targetFileName);
1227 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1229 PathCatSlash(string, "lib");
1230 strcat(string, targetFileName);
1233 PathCatSlash(string, targetFileName);
1238 if(compiler.targetPlatform == win32)
1239 strcat(string, ".exe");
1242 if(compiler.targetPlatform == win32)
1243 strcat(string, ".dll");
1244 else if(compiler.targetPlatform == apple)
1245 strcat(string, ".dylib");
1247 strcat(string, ".so");
1248 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1250 strcat(string, ".");
1251 strcat(string, moduleVersion);
1255 strcat(string, ".a");
1260 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1262 bool result = false;
1263 char temp[MAX_LOCATION];
1264 strcpy(cfDir, topNode.path);
1265 if(compilerConfigsDir && compilerConfigsDir[0])
1267 PathCatSlash(cfDir, compilerConfigsDir);
1272 strcpy(temp, cfDir);
1273 // Using a relative path makes it less likely to run into spaces issues
1274 // Even with escaped spaces, there still seems to be issues including a config file
1275 // in a path containing spaces
1277 MakePathRelative(temp, topNode.path, cfDir);
1280 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1284 strcpy(temp, cfDir);
1285 ReplaceSpaces(cfDir, temp);
1290 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1292 char temp[MAX_LOCATION];
1293 bool result = false;
1294 strcpy(cfDir, topNode.path);
1295 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1297 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1302 // Default to <ProjectDir>/.configs if unset
1303 PathCatSlash(cfDir, ".configs");
1308 strcpy(temp, cfDir);
1309 // Using a relative path makes it less likely to run into spaces issues
1310 // Even with escaped spaces, there still seems to be issues including a config file
1311 // in a path containing spaces
1312 if(IsPathInsideOf(cfDir, topNode.path))
1313 MakePathRelative(temp, topNode.path, cfDir);
1315 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1319 strcpy(temp, cfDir);
1320 ReplaceSpaces(cfDir, temp);
1325 void CatMakeFileName(char * string, ProjectConfig config)
1327 char projectName[MAX_LOCATION];
1328 strcpy(projectName, name);
1329 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1332 #ifndef MAKEFILE_GENERATOR
1333 void MarkChanges(ProjectNode node)
1335 for(cfg : topNode.configurations)
1337 ProjectConfig c = null;
1338 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1340 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1341 (!c.options || !cfg.options)))
1342 cfg.symbolGenModified = true;
1344 cfg.makingModified = true;
1348 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1350 for(cfg : configurations)
1353 cfg.makingModified = true;
1355 cfg.compilingModified = true;
1357 cfg.linkingModified = true;
1359 cfg.symbolGenModified = true;
1361 if(compiling || linking)
1363 ide.projectView.modifiedDocument = true;
1364 ide.workspace.modified = true;
1368 void RotateActiveConfig(bool forward)
1370 if(configurations.first && configurations.last != configurations.first)
1372 Iterator<ProjectConfig> cfg { configurations };
1373 while(forward ? cfg.Next() : cfg.Prev())
1374 if(cfg.data == config)
1388 property::config = cfg.data;
1389 ide.UpdateToolBarActiveConfigs(true);
1390 ide.workspace.modified = true;
1391 ide.projectView.Update(null);
1395 void ProcessPipeOutputRaw(DualPipe f)
1398 while(!f.Eof() && !ide.ShouldStopBuild())
1401 double lastTime = GetTime();
1405 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1407 ide.outputView.buildBox.Logf("%s\n", line);
1409 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1411 //printf("Processing Input...\n");
1412 if(app.ProcessInput(true))
1414 app.UpdateDisplay();
1417 //printf("Waiting...\n");
1420 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1422 if(ide.ShouldStopBuild())
1424 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1429 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
1430 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1433 bool compiling = false, linking = false, precompiling = false;
1434 int compilingEC = 0;
1435 int numErrors = 0, numWarnings = 0;
1436 bool loggedALine = false;
1437 char * configName = config ? config.name : "Common";
1438 int lenMakeCommand = strlen(compiler.makeCommand);
1441 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1443 DynamicString test { };
1444 DynamicString ecp { };
1445 DynamicString ecc { };
1446 DynamicString ecs { };
1447 DynamicString ear { };
1448 DynamicString prefix { };
1449 DynamicString cpp { };
1450 DynamicString cc { };
1451 DynamicString cxx { };
1452 DynamicString strip { };
1453 DynamicString ar { };
1455 if(bitDepth == 64 && compiler.targetPlatform == win32)
1456 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1457 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1458 gnuToolchainPrefix = "i686-w64-mingw32-";
1460 ecp.concatx(compiler.ecpCommand, " ");
1461 ecc.concatx(compiler.eccCommand, " ");
1462 ecs.concatx(compiler.ecsCommand, " ");
1463 ear.concatx(compiler.earCommand, " ");
1466 compiler.ccacheEnabled ? "ccache " : "",
1467 compiler.distccEnabled ? "distcc " : "",
1468 gnuToolchainPrefix);
1470 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1471 cc.concatx((String)prefix, compiler.ccCommand, " ");
1472 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1474 strip.concatx(gnuToolchainPrefix, "strip ");
1475 ar.concatx(gnuToolchainPrefix, "ar rcs");
1477 testLen = Max(testLen, ecp.size);
1478 testLen = Max(testLen, ecc.size);
1479 testLen = Max(testLen, ecs.size);
1480 testLen = Max(testLen, ear.size);
1481 testLen = Max(testLen, cpp.size);
1482 testLen = Max(testLen, cc.size);
1483 testLen = Max(testLen, cxx.size);
1484 testLen = Max(testLen, strip.size);
1485 testLen = Max(testLen, ar.size);
1488 while(!f.Eof() && !ide.ShouldStopBuild())
1491 double lastTime = GetTime();
1495 //printf("Peeking and GetLine...\n");
1496 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1498 char * message = null;
1499 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1500 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1501 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1503 char * module = strstr(line, "No rule to make target `");
1507 module = strchr(module, '`') + 1;
1508 end = strchr(module, '\'');
1512 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1513 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1519 //ide.outputView.buildBox.Logf("error: %s\n", line);
1523 else if(strstr(test, ear) == test);
1524 else if(strstr(test, strip) == test);
1525 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1527 char moduleName[MAX_FILENAME];
1530 bool isPrecomp = false;
1533 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1535 module = strstr(line, " -c ");
1536 if(module) module += 4;
1539 else if(strstr(test, ecc) == test)
1541 module = strstr(line, " -c ");
1542 if(module) module += 4;
1543 //module = line + 3;
1544 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1545 compilingEC = 3;//2;
1548 else if(strstr(test, ecp) == test)
1550 // module = line + 8;
1551 module = strstr(line, " -c ");
1552 if(module) module += 4;
1562 if(!compiling && !isPrecomp)
1564 ide.outputView.buildBox.Logf($"Compiling...\n");
1567 else if(!precompiling && isPrecomp)
1569 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1570 precompiling = true;
1572 // Changed escapeBackSlashes here to handle paths with spaces
1573 Tokenize(module, 1, tokens, true); // false);
1574 GetLastDirectory(module, moduleName);
1575 ide.outputView.buildBox.Logf("%s\n", moduleName);
1577 else if((module = strstr(line, " -o ")))
1580 precompiling = false;
1582 ide.outputView.buildBox.Logf($"Linking...\n");
1586 ide.outputView.buildBox.Logf("%s\n", line);
1587 if(strstr(line, "warning:") || strstr(line, "note:"))
1589 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from"))
1593 if(compilingEC) compilingEC--;
1595 else if(strstr(test, ar) == test)
1596 ide.outputView.buildBox.Logf($"Building library...\n");
1597 else if(strstr(test, ecs) == test)
1598 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1601 if(linking || compiling || precompiling)
1603 char * colon = strstr(line, ":"); //, * bracket;
1604 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1605 colon = strstr(colon + 1, ":");
1608 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1611 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1612 int len = (int)(colon - start);
1613 len = Min(len, MAX_LOCATION-1);
1614 // Don't be mistaken by the drive letter colon
1616 // TODO: need to fix colon - line gives char *
1617 // warning: incompatible expression colon - line (char *); expected int
1619 strncpy(moduleName, line, (int)(colon - line));
1620 moduleName[colon - line] = '\0';
1622 strncpy(moduleName, start, len);
1623 moduleName[len] = '\0';
1624 // Remove stuff in brackets
1625 //bracket = strstr(moduleName, "(");
1626 //if(bracket) *bracket = '\0';
1628 GetLastDirectory(moduleName, temp);
1629 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1631 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1632 message = $"Linker Message";
1636 message = $"Linker Error";
1641 strcpy(temp, topNode.path);
1642 PathCatSlash(temp, moduleName);
1643 MakePathRelative(temp, topNode.path, moduleName);
1645 error = strstr(line, "error:");
1646 if(error && error > colon)
1650 // Silence warnings for compiled EC
1651 char * objDir = strstr(moduleName, objDirExp.dir);
1655 if((pointer = strstr(line, "undefined")) ||
1656 (pointer = strstr(line, "No such file")) ||
1657 (pointer = strstr(line, "token")))
1659 strncat(moduleName, colon, pointer - colon);
1660 strcat(moduleName, "error: ");
1665 else if((pointer = strstr(line, "No such file")))
1667 strncat(moduleName, colon, pointer - colon);
1668 strcat(moduleName, "error: ");
1672 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1674 else if(strstr(line, "warning:"))
1680 ide.outputView.buildBox.Logf(" %s: %s\n", message, line);
1681 else if(this == ide.workspace.projects.firstIterator.data)
1682 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1685 char fullModuleName[MAX_LOCATION];
1686 strcpy(fullModuleName, topNode.path);
1687 PathCat(fullModuleName, moduleName);
1688 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1689 MakeSystemPath(fullModuleName);
1690 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1695 ide.outputView.buildBox.Logf("%s\n", line);
1696 linking = compiling = precompiling = false;
1700 ide.outputView.buildBox.Logf("%s\n", line);
1704 //printf("Done getting line\n");
1705 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1707 //printf("Processing Input...\n");
1708 if(app.ProcessInput(true))
1710 app.UpdateDisplay();
1713 //printf("Waiting...\n");
1716 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1718 if(ide.ShouldStopBuild())
1720 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1723 else if(loggedALine || !isARun)
1725 if(f.GetExitCode() && !numErrors)
1727 bool result = f.GetLine(line, sizeof(line)-1);
1728 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1734 char targetFileName[MAX_LOCATION];
1735 targetFileName[0] = '\0';
1736 CatTargetFileName(targetFileName, compiler, config);
1737 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, configName);
1740 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1742 ide.outputView.buildBox.Logf($"no error, ");
1745 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1747 ide.outputView.buildBox.Logf($"no warning\n");
1763 return numErrors == 0;
1766 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1769 int lenMakeCommand = strlen(compiler.makeCommand);
1774 double lastTime = GetTime();
1777 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1779 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1780 else if(strstr(line, "del") == line);
1781 else if(strstr(line, "rm") == line);
1782 else if(strstr(line, "Could Not Find") == line);
1785 ide.outputView.buildBox.Logf(line);
1786 ide.outputView.buildBox.Logf("\n");
1790 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1792 if(app.ProcessInput(true))
1794 app.UpdateDisplay();
1797 //Sleep(1.0 / PEEK_RESOLUTION);
1801 bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
1803 bool result = false;
1805 char targetFileName[MAX_LOCATION] = "";
1806 DynamicString makeTargets { };
1807 char makeFile[MAX_LOCATION];
1808 char makeFilePath[MAX_LOCATION];
1809 char configName[MAX_LOCATION];
1810 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
1811 PathBackup pathBackup { };
1812 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1813 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1815 int numJobs = compiler.numJobs;
1816 char command[MAX_F_STRING];
1817 char * compilerName;
1819 compilerName = CopyString(compiler.name);
1820 CamelCase(compilerName);
1822 strcpy(configName, config ? config.name : "Common");
1824 SetPath(false, compiler, config, bitDepth); //true
1825 CatTargetFileName(targetFileName, compiler, config);
1827 strcpy(makeFilePath, topNode.path);
1828 CatMakeFileName(makeFile, config);
1829 PathCatSlash(makeFilePath, makeFile);
1831 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1834 if(compiler.type.isVC)
1836 PrintLn("compiling a single file is not yet supported");
1841 char pushD[MAX_LOCATION];
1842 char cfDir[MAX_LOCATION];
1843 Map<String, NameCollisionInfo> namesInfo { };
1844 GetIDECompilerConfigsDir(cfDir, true, true);
1845 GetWorkingDir(pushD, sizeof(pushD));
1846 ChangeWorkingDir(topNode.path);
1847 // Create object dir if it does not exist already
1848 if(!FileExists(objDirExp.dir).isDirectory)
1850 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
1851 compiler.makeCommand, cfDir,
1852 crossCompiling ? " TARGET_PLATFORM=" : "",
1854 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
1855 (bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : "",
1857 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
1859 ide.outputView.buildBox.Logf("%s\n", command);
1863 ChangeWorkingDir(pushD);
1865 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1866 for(node : onlyNodes)
1868 if(node.GetIsExcluded(config))
1869 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1872 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, mode == cObject ? true : false);
1873 node.GetTargets(config, namesInfo, objDirExp.dir, makeTargets);
1881 if(compiler.type.isVC)
1883 bool result = false;
1884 char oldwd[MAX_LOCATION];
1885 GetWorkingDir(oldwd, sizeof(oldwd));
1886 ChangeWorkingDir(topNode.path);
1888 // TODO: support justPrint
1889 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1891 ide.outputView.buildBox.Logf("%s\n", command);
1892 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1894 ProcessPipeOutputRaw(f);
1898 ChangeWorkingDir(oldwd);
1902 char cfDir[MAX_LOCATION];
1903 GetIDECompilerConfigsDir(cfDir, true, true);
1904 sprintf(command, "%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s -j%d %s%s%s -C \"%s\"%s -f \"%s\"",
1905 compiler.makeCommand,
1906 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
1908 crossCompiling ? " TARGET_PLATFORM=" : "",
1910 bitDepth ? " ARCH=" : "",
1911 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
1912 (bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : "",
1913 compilerName, numJobs,
1914 compiler.ccacheEnabled ? "CCACHE=y " : "",
1915 compiler.distccEnabled ? "DISTCC=y " : "",
1916 (String)makeTargets, topNode.path, (justPrint || (mode != normal && mode != cObject)) ? " -n" : "", makeFilePath);
1918 ide.outputView.buildBox.Logf("%s\n", command);
1919 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1924 ProcessPipeOutputRaw(f);
1927 else if(mode != normal && mode != cObject)
1935 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1937 if(!found && strstr(line, "ide ") == line)
1939 strcpy(command, line);
1947 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config, bitDepth);
1953 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1958 delete compilerName;
1963 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
1965 char makeFile[MAX_LOCATION];
1966 char makeFilePath[MAX_LOCATION];
1967 char command[MAX_LOCATION];
1968 char * compilerName;
1970 PathBackup pathBackup { };
1971 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1972 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1974 compilerName = CopyString(compiler.name);
1975 CamelCase(compilerName);
1977 SetPath(false, compiler, config, bitDepth);
1979 strcpy(makeFilePath, topNode.path);
1980 CatMakeFileName(makeFile, config);
1981 PathCatSlash(makeFilePath, makeFile);
1983 if(compiler.type.isVC)
1985 bool result = false;
1986 char oldwd[MAX_LOCATION];
1987 GetWorkingDir(oldwd, sizeof(oldwd));
1988 ChangeWorkingDir(topNode.path);
1990 // TODO: justPrint support
1991 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1993 ide.outputView.buildBox.Logf("%s\n", command);
1994 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1996 ProcessPipeOutputRaw(f);
2000 ChangeWorkingDir(oldwd);
2005 char cfDir[MAX_LOCATION];
2006 GetIDECompilerConfigsDir(cfDir, true, true);
2007 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2008 compiler.makeCommand, cfDir,
2009 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2010 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2012 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2013 topNode.path, justPrint ? " -n": "", makeFilePath);
2015 ide.outputView.buildBox.Logf("%s\n", command);
2016 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2018 ide.outputView.buildBox.Tell($"Deleting target and object files...");
2020 ProcessPipeOutputRaw(f);
2022 ProcessCleanPipeOutput(f, compiler, config);
2025 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
2030 delete compilerName;
2033 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2035 String target = new char[maxPathLen];
2036 char oldDirectory[MAX_LOCATION];
2037 char * executableLauncher = compiler.executableLauncher;
2038 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2039 PathBackup pathBackup { };
2041 // Build(project, ideMain, true, null, false);
2043 #if defined(__WIN32__)
2044 strcpy(target, topNode.path);
2048 PathCatSlash(target, targetDirExp.dir);
2049 CatTargetFileName(target, compiler, config);
2050 sprintf(target, "%s %s", target, args);
2051 GetWorkingDir(oldDirectory, MAX_LOCATION);
2053 if(strlen(ide.workspace.debugDir))
2055 char temp[MAX_LOCATION];
2056 strcpy(temp, topNode.path);
2057 PathCatSlash(temp, ide.workspace.debugDir);
2058 ChangeWorkingDir(temp);
2061 ChangeWorkingDir(topNode.path);
2062 // ChangeWorkingDir(topNode.path);
2063 SetPath(true, compiler, config, bitDepth);
2064 if(executableLauncher)
2066 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 2];
2067 prefixedTarget[0] = '\0';
2068 strcat(prefixedTarget, executableLauncher);
2069 strcat(prefixedTarget, " ");
2070 strcat(prefixedTarget, target);
2071 Execute(prefixedTarget);
2072 delete prefixedTarget;
2077 ChangeWorkingDir(oldDirectory);
2080 delete targetDirExp;
2084 void Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2086 Build(false, nodes, compiler, config, bitDepth, justPrint, mode);
2090 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2093 if(targetType == staticLibrary || targetType == sharedLibrary)
2094 strcat(fileName, "$(LP)");
2095 // !!! ReplaceSpaces must be done after all PathCat calls !!!
2096 // ReplaceSpaces(s, GetTargetFileName(config));
2097 strcat(fileName, GetTargetFileName(config));
2101 strcat(fileName, "$(E)");
2104 strcat(fileName, "$(SO)$(VER)");
2107 strcat(fileName, "$(A)");
2112 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2114 bool result = false;
2115 char path[MAX_LOCATION];
2117 if(!GetProjectCompilerConfigsDir(path, false, false))
2118 GetIDECompilerConfigsDir(path, false, false);
2120 if(!FileExists(path).isDirectory)
2124 char dirName[MAX_FILENAME];
2125 GetLastDirectory(path, dirName);
2126 if(!strcmp(dirName, ".configs"))
2127 FileSetAttribs(path, FileAttribs { isHidden = true });
2130 PathCatSlash(path, "crossplatform.mk");
2132 if(FileExists(path))
2135 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2138 File f = FileOpen(path, write);
2141 include.Seek(0, start);
2142 for(; !include.Eof(); )
2145 int count = include.Read(buffer, 1, 4096);
2146 f.Write(buffer, 1, count);
2152 if(!altCrossPlatformMk)
2159 bool GenerateCompilerCf(CompilerConfig compiler)
2161 bool result = false;
2162 char path[MAX_LOCATION];
2164 char * compilerName;
2165 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2166 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2167 Platform platform = compiler.targetPlatform;
2169 compilerName = CopyString(compiler.name);
2170 CamelCase(compilerName);
2171 name = PrintString(platform, "-", compilerName, ".cf");
2173 if(!GetProjectCompilerConfigsDir(path, false, false))
2174 GetIDECompilerConfigsDir(path, false, false);
2176 if(!FileExists(path).isDirectory)
2180 char dirName[MAX_FILENAME];
2181 GetLastDirectory(path, dirName);
2182 if(!strcmp(dirName, ".configs"))
2183 FileSetAttribs(path, FileAttribs { isHidden = true });
2186 PathCatSlash(path, name);
2188 if(FileExists(path))
2191 File f = FileOpen(path, write);
2194 if(compiler.environmentVars && compiler.environmentVars.count)
2196 f.Puts("# ENVIRONMENT VARIABLES\n");
2198 for(e : compiler.environmentVars)
2200 f.Printf("export %s := %s\n", e.name, e.string);
2204 f.Puts("# TOOLCHAIN\n");
2207 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2209 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2212 if(compiler.sysroot && compiler.sysroot[0])
2214 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2215 // Moved this to crossplatform.mk
2216 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2220 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2221 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2222 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2223 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2224 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start $(ECERE_SDK_SRC)/compiler/ecp/ecp.epj -@,%s)\n", compiler.ecpCommand);
2225 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);
2226 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);
2227 f.Printf("EAR := %s\n", compiler.earCommand);
2229 f.Puts("AS := $(GCC_PREFIX)as\n");
2230 f.Puts("LD := $(GCC_PREFIX)ld\n");
2231 f.Puts("AR := $(GCC_PREFIX)ar\n");
2232 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2233 f.Puts("UPX := upx\n");
2236 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2239 f.Puts("EARFLAGS = \n");
2242 f.Puts("ifndef ARCH\n");
2243 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2244 f.Puts(" ifdef WINDOWS_HOST\n");
2245 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2246 f.Puts(" TARGET_ARCH := x86_64\n");
2248 f.Puts(" TARGET_ARCH := i386\n");
2251 f.Puts("endif\n\n");
2253 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2254 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2258 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2262 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2265 if(compiler.includeDirs && compiler.includeDirs.count)
2267 f.Puts("\nCFLAGS +=");
2268 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2271 if(compiler.prepDirectives && compiler.prepDirectives.count)
2273 f.Puts("\nCFLAGS +=");
2274 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2277 if(compiler.libraryDirs && compiler.libraryDirs.count)
2279 f.Puts("\nLDFLAGS +=");
2280 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2281 // We would need a bool option to know whether we want to add to rpath as well...
2282 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
2285 if(compiler.excludeLibs && compiler.excludeLibs.count)
2287 f.Puts("\nEXCLUDED_LIBS =");
2288 for(l : compiler.excludeLibs)
2294 if(compiler.linkerFlags && compiler.linkerFlags.count)
2296 f.Puts("\nLDFLAGS +=");
2297 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
2301 f.Puts("\nOFLAGS += $(LDFLAGS)");
2303 f.Puts("ifdef ARCH_FLAGS\n");
2304 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2305 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2314 delete compilerName;
2318 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2320 bool result = false;
2321 char filePath[MAX_LOCATION];
2322 char makeFile[MAX_LOCATION];
2323 // PathBackup pathBackup { };
2324 // char oldDirectory[MAX_LOCATION];
2327 if(!altMakefilePath)
2329 strcpy(filePath, topNode.path);
2330 CatMakeFileName(makeFile, config);
2331 PathCatSlash(filePath, makeFile);
2334 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2336 /*SetPath(false, compiler, config);
2337 GetWorkingDir(oldDirectory, MAX_LOCATION);
2338 ChangeWorkingDir(topNode.path);*/
2345 char targetDir[MAX_LOCATION];
2346 char objDirExpNoSpaces[MAX_LOCATION];
2347 char objDirNoSpaces[MAX_LOCATION];
2348 char resDirNoSpaces[MAX_LOCATION];
2349 char targetDirExpNoSpaces[MAX_LOCATION];
2350 char fixedModuleName[MAX_FILENAME];
2351 char fixedConfigName[MAX_FILENAME];
2353 // Non-zero if we're building eC code
2354 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2355 int numCObjects = 0;
2357 bool containsCXX = false; // True if the project contains a C++ file
2358 bool sameObjTargetDirs;
2359 String objDirExp = GetObjDirExpression(config);
2360 TargetTypes targetType = GetTargetType(config);
2362 char cfDir[MAX_LOCATION];
2363 int objectsParts = 0, eCsourcesParts = 0;
2364 Array<String> listItems { };
2365 Map<String, int> varStringLenDiffs { };
2366 Map<String, NameCollisionInfo> namesInfo { };
2368 Map<String, int> cflagsVariations { };
2369 Map<intptr, int> nodeCFlagsMapping { };
2371 Map<String, int> ecflagsVariations { };
2372 Map<intptr, int> nodeECFlagsMapping { };
2374 ReplaceSpaces(objDirNoSpaces, objDirExp);
2375 strcpy(targetDir, GetTargetDirExpression(config));
2376 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2378 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2379 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2380 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2381 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2382 ReplaceSpaces(fixedModuleName, moduleName);
2383 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2384 CamelCase(fixedConfigName);
2386 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2388 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2390 f.Puts("# CORE VARIABLES\n\n");
2392 f.Printf("MODULE := %s\n", fixedModuleName);
2393 f.Printf("VERSION := %s\n", property::moduleVersion);
2394 f.Printf("CONFIG := %s\n", fixedConfigName);
2395 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2398 test = GetTargetTypeIsSetByPlatform(config);
2402 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2404 TargetTypes targetType;
2405 PlatformOptions projectPOs, configPOs;
2406 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2407 targetType = platformTargetType;
2413 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2414 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2419 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2424 for(c = 0; c < ifCount; c++)
2430 f.Puts("# FLAGS\n\n");
2432 f.Puts("ECFLAGS =\n");
2433 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2434 f.Puts("PRJ_CFLAGS =\n");
2435 f.Puts("CECFLAGS =\n");
2436 f.Puts("OFLAGS =\n");
2440 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2443 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2444 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2445 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2446 //f.Puts("endif\n");
2449 f.Puts("# INCLUDES\n\n");
2451 if(compilerConfigsDir && compilerConfigsDir[0])
2453 strcpy(cfDir, compilerConfigsDir);
2454 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2459 GetIDECompilerConfigsDir(cfDir, true, true);
2460 // Use CF_DIR environment variable for absolute paths only
2461 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2462 strcpy(cfDir, "$(CF_DIR)");
2465 f.Printf("_CF_DIR = %s\n", cfDir);
2468 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2469 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2472 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2474 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2477 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2480 // test = GetTargetTypeIsSetByPlatform(config);
2482 char target[MAX_LOCATION];
2483 char targetNoSpaces[MAX_LOCATION];
2488 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2490 if(type != targetType)
2495 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2497 GetMakefileTargetFileName(type, target, config);
2498 strcpy(targetNoSpaces, targetDir);
2499 PathCatSlash(targetNoSpaces, target);
2500 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2501 f.Printf("TARGET = %s\n", targetNoSpaces);
2506 GetMakefileTargetFileName(targetType, target, config);
2507 strcpy(targetNoSpaces, targetDir);
2508 PathCatSlash(targetNoSpaces, target);
2509 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2510 f.Printf("TARGET = %s\n", targetNoSpaces);
2516 for(c = 0; c < ifCount; c++)
2523 // Use something fixed here, to not cause Makefile differences across compilers...
2524 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2525 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2527 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2531 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2533 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2536 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2538 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2539 if(eCsourcesParts > 1)
2541 for(c = 1; c <= eCsourcesParts; c++)
2542 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2546 for(c = 0; c < 5; c++)
2548 if(eCsourcesParts > 1)
2551 f.Printf("%s =", map[c][0]);
2552 for(n = 1; n <= eCsourcesParts; n++)
2553 f.Printf(" $(%s%d)", map[c][0], n);
2555 for(n = 1; n <= eCsourcesParts; n++)
2556 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2558 else if(eCsourcesParts == 1)
2559 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2565 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2567 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2568 f.Printf("OBJECTS =%s%s%s\n", numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "", numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "");
2571 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2572 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, numCObjects ? "$(ECSOURCES)" : null);
2575 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2576 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2578 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2580 if((config && config.options && config.options.libraries) ||
2581 (options && options.libraries))
2583 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2585 if(config && config.options && config.options.libraries)
2586 OutputLibraries(f, config.options.libraries);
2587 else if(options && options.libraries)
2588 OutputLibraries(f, options.libraries);
2594 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2595 cflagsVariations, nodeCFlagsMapping,
2596 ecflagsVariations, nodeECFlagsMapping, null);
2598 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2599 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2601 if(platforms || (config && config.platforms))
2604 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2605 //for(platform = win32; platform <= apple; platform++)
2607 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2608 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2610 PlatformOptions projectPlatformOptions, configPlatformOptions;
2611 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2613 if(projectPlatformOptions || configPlatformOptions)
2618 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2621 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2622 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2624 f.Puts("OFLAGS +=");
2625 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2627 bool needWl = false;
2629 for(s : projectPlatformOptions.options.linkerOptions)
2631 if(!IsLinkerOption(s))
2639 for(s : projectPlatformOptions.options.linkerOptions)
2640 if(IsLinkerOption(s))
2644 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2646 bool needWl = false;
2648 for(s : configPlatformOptions.options.linkerOptions)
2650 if(IsLinkerOption(s))
2658 for(s : configPlatformOptions.options.linkerOptions)
2659 if(!IsLinkerOption(s))
2667 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2668 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2669 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2670 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2672 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2673 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2674 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2676 f.Puts("OFLAGS +=");
2677 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2678 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2679 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2680 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2684 if((configPlatformOptions && configPlatformOptions.options.libraries))
2686 if(configPlatformOptions.options.libraries.count)
2689 OutputLibraries(f, configPlatformOptions.options.libraries);
2693 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2695 if(projectPlatformOptions.options.libraries.count)
2698 OutputLibraries(f, projectPlatformOptions.options.libraries);
2709 for(c = 0; c < ifCount; c++)
2715 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
2716 (options && options.linkerOptions && options.linkerOptions.count))
2718 f.Puts("OFLAGS +=");
2721 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
2723 bool needWl = false;
2724 for(s : config.options.linkerOptions)
2726 if(!IsLinkerOption(s))
2734 for(s : config.options.linkerOptions)
2735 if(IsLinkerOption(s))
2739 if(options && options.linkerOptions && options.linkerOptions.count)
2741 bool needWl = false;
2742 for(s : options.linkerOptions)
2744 if(!IsLinkerOption(s))
2752 for(s : options.linkerOptions)
2753 if(IsLinkerOption(s))
2761 f.Puts("CECFLAGS += -cpp $(_CPP)");
2765 if(GetProfile(config))
2766 f.Puts("OFLAGS += -pg\n\n");
2768 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
2770 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2771 f.Puts("OFLAGS +=");
2772 if(config && config.options && config.options.libraryDirs)
2773 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2774 if(options && options.libraryDirs)
2775 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2781 f.Puts("# TARGETS\n");
2784 f.Printf("all: objdir%s $(TARGET)\n", sameObjTargetDirs ? "" : " targetdir");
2787 f.Puts("objdir:\n");
2788 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2789 //f.Puts("# PRE-BUILD COMMANDS\n");
2790 if(options && options.prebuildCommands)
2792 for(s : options.prebuildCommands)
2793 if(s && s[0]) f.Printf("\t%s\n", s);
2795 if(config && config.options && config.options.prebuildCommands)
2797 for(s : config.options.prebuildCommands)
2798 if(s && s[0]) f.Printf("\t%s\n", s);
2800 if(platforms || (config && config.platforms))
2803 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2804 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2806 PlatformOptions projectPOs, configPOs;
2807 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2809 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2810 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2815 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2817 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2819 for(s : projectPOs.options.prebuildCommands)
2820 if(s && s[0]) f.Printf("\t%s\n", s);
2822 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2824 for(s : configPOs.options.prebuildCommands)
2825 if(s && s[0]) f.Printf("\t%s\n", s);
2832 for(c = 0; c < ifCount; c++)
2838 if(!sameObjTargetDirs)
2840 f.Puts("targetdir:\n");
2841 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2847 // Main Module (Linking) for ECERE C modules
2848 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2849 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2850 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n",
2851 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2853 // Main Module (Linking) for ECERE C modules
2854 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2855 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
2856 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2857 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
2858 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n");
2864 // This would not rebuild the target on updated objects
2865 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2867 // This should fix it for good!
2868 f.Puts("$(SYMBOLS): | objdir\n");
2869 f.Puts("$(OBJECTS): | objdir\n");
2871 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2872 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2874 f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
2875 f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
2876 OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
2879 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
2880 OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
2883 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2885 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2886 if(!GetDebug(config))
2888 f.Puts("ifndef NOSTRIP\n");
2889 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2892 if(GetCompress(config))
2894 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
2895 f.Puts("ifdef EXECUTABLE_TARGET\n");
2896 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2899 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2903 if(resNode.files && resNode.files.count && !noResources)
2904 resNode.GenMakefileAddResources(f, resNode.path, config);
2906 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
2908 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
2909 f.Puts("ifdef LINUX_TARGET\n");
2910 f.Puts("ifdef LINUX_HOST\n");
2911 // TODO?: support symlinks for longer version numbers
2912 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
2913 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
2918 //f.Puts("# POST-BUILD COMMANDS\n");
2919 if(options && options.postbuildCommands)
2921 for(s : options.postbuildCommands)
2922 if(s && s[0]) f.Printf("\t%s\n", s);
2924 if(config && config.options && config.options.postbuildCommands)
2926 for(s : config.options.postbuildCommands)
2927 if(s && s[0]) f.Printf("\t%s\n", s);
2929 if(platforms || (config && config.platforms))
2932 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2933 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2935 PlatformOptions projectPOs, configPOs;
2936 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2938 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2939 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2944 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2946 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2948 for(s : projectPOs.options.postbuildCommands)
2949 if(s && s[0]) f.Printf("\t%s\n", s);
2951 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2953 for(s : configPOs.options.postbuildCommands)
2954 if(s && s[0]) f.Printf("\t%s\n", s);
2961 for(c = 0; c < ifCount; c++)
2967 f.Puts("# SYMBOL RULES\n");
2970 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
2972 f.Puts("# C OBJECT RULES\n");
2975 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
2977 f.Puts("# OBJECT RULES\n");
2979 // todo call this still but only generate rules whith specific options
2980 // see we-have-file-specific-options in ProjectNode.ec
2981 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
2984 GenMakefilePrintMainObjectRule(f, config);
2986 f.Printf("cleantarget: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2987 f.Puts("\t$(call rmq,$(TARGET))\n");
2988 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
2989 f.Puts("ifdef LINUX_TARGET\n");
2990 f.Puts("ifdef LINUX_HOST\n");
2991 // TODO?: support symlinks for longer version numbers
2992 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
2993 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
2999 f.Puts("clean: cleantarget\n");
3000 f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3001 OutputCleanActions(f, "_OBJECTS", objectsParts);
3004 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)");
3005 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3006 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3007 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3008 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3009 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3013 f.Puts("realclean: cleantarget\n");
3014 f.Puts("\t$(call rmrq,$(OBJ))\n");
3015 if(!sameObjTargetDirs)
3016 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3019 f.Puts("distclean: cleantarget\n");
3020 if(!sameObjTargetDirs)
3021 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3022 f.Puts("\t$(call rmrq,obj/)\n");
3028 varStringLenDiffs.Free();
3029 delete varStringLenDiffs;
3033 delete cflagsVariations;
3034 delete nodeCFlagsMapping;
3035 delete ecflagsVariations;
3036 delete nodeECFlagsMapping;
3041 // ChangeWorkingDir(oldDirectory);
3042 // delete pathBackup;
3045 config.makingModified = false;
3049 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3051 char extension[MAX_EXTENSION] = "c";
3052 char modulePath[MAX_LOCATION];
3053 char fixedModuleName[MAX_FILENAME];
3056 char objDirNoSpaces[MAX_LOCATION];
3057 String objDirExp = GetObjDirExpression(config);
3059 ReplaceSpaces(objDirNoSpaces, objDirExp);
3060 ReplaceSpaces(fixedModuleName, moduleName);
3062 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3063 //strcat(fixedModuleName, ".main");
3065 #if 0 // TODO: Fix nospaces stuff
3066 // *** Dependency command ***
3067 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3069 // System Includes (from global settings)
3070 for(item : compiler.dirs[Includes])
3072 strcat(command, " -isystem ");
3073 if(strchr(item.name, ' '))
3075 strcat(command, "\"");
3076 strcat(command, item);
3077 strcat(command, "\"");
3080 strcat(command, item);
3083 for(item = includeDirs.first; item; item = item.next)
3085 strcat(command, " -I");
3086 if(strchr(item.name, ' '))
3088 strcat(command, "\"");
3089 strcat(command, item.name);
3090 strcat(command, "\"");
3093 strcat(command, item.name);
3095 for(item = preprocessorDefs.first; item; item = item.next)
3097 strcat(command, " -D");
3098 strcat(command, item.name);
3102 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
3106 bool firstLine = true;
3108 // To do some time: auto save external dependencies?
3111 if(dep.GetLine(line, sizeof(line)-1))
3115 char * colon = strstr(line, ":");
3116 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3130 // If we failed to generate dependencies...
3134 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3135 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n", extension);
3143 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3146 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3148 for(v : cflagsVariations)
3153 f.Printf("%s +=", variableName);
3155 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3156 f.Puts(&v ? &v : "");
3166 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3167 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3169 *projectPlatformOptions = null;
3170 *configPlatformOptions = null;
3175 if(!strcmpi(p.name, platform))
3177 *projectPlatformOptions = p;
3182 if(config && config.platforms)
3184 for(p : config.platforms)
3186 if(!strcmpi(p.name, platform))
3188 *configPlatformOptions = p;
3196 Project LegacyBinaryLoadProject(File f, char * filePath)
3198 Project project = null;
3199 char signature[sizeof(epjSignature)];
3201 f.Read(signature, sizeof(signature), 1);
3202 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3204 char topNodePath[MAX_LOCATION];
3205 /*ProjectConfig newConfig
3207 name = CopyString("Default");
3208 makingModified = true;
3209 compilingModified = true;
3210 linkingModified = true;
3214 project = Project { options = { } };
3215 LegacyBinaryLoadNode(project.topNode, f);
3216 delete project.topNode.path;
3217 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3218 MakeSlashPath(topNodePath);
3220 PathCatSlash(topNodePath, filePath);
3221 project.filePath = topNodePath;
3223 /* THIS IS ALREADY DONE BY filePath property
3224 StripLastDirectory(topNodePath, topNodePath);
3225 project.topNode.path = CopyString(topNodePath);
3227 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3229 // newConfig.options.defaultNameSpace = "";
3230 /*newConfig.objDir.dir = "obj";
3231 newConfig.targetDir.dir = "";*/
3233 //project.configurations = { [ newConfig ] };
3234 //project.config = newConfig;
3241 String targetFileName, targetDirectory, objectsDirectory;
3243 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3244 f.Read(&temp, sizeof(int),1);
3247 case 0: project.options.targetType = executable; break;
3248 case 1: project.options.targetType = sharedLibrary; break;
3249 case 2: project.options.targetType = staticLibrary; break;
3252 f.Read(&len, sizeof(int),1);
3253 targetFileName = new char[len+1];
3254 f.Read(targetFileName, sizeof(char), len+1);
3255 project.options.targetFileName = targetFileName;
3256 delete targetFileName;
3258 f.Read(&len, sizeof(int),1);
3259 targetDirectory = new char[len+1];
3260 f.Read(targetDirectory, sizeof(char), len+1);
3261 project.options.targetDirectory = targetDirectory;
3262 delete targetDirectory;
3264 f.Read(&len, sizeof(int),1);
3265 objectsDirectory = new byte[len+1];
3266 f.Read(objectsDirectory, sizeof(char), len+1);
3267 project.options.objectsDirectory = objectsDirectory;
3268 delete objectsDirectory;
3270 f.Read(&temp, sizeof(int),1);
3271 project./*config.*/options.debug = temp ? true : false;
3272 f.Read(&temp, sizeof(int),1);
3273 project./*config.*/options.optimization = temp ? speed : none;
3274 f.Read(&temp, sizeof(int),1);
3275 project./*config.*/options.profile = temp ? true : false;
3276 f.Read(&temp, sizeof(int),1);
3277 project.options.warnings = temp ? all : unset;
3279 f.Read(&count, sizeof(int),1);
3282 project.options.includeDirs = { };
3283 for(c = 0; c < count; c++)
3286 f.Read(&len, sizeof(int),1);
3287 name = new char[len+1];
3288 f.Read(name, sizeof(char), len+1);
3289 project.options.includeDirs.Add(name);
3293 f.Read(&count, sizeof(int),1);
3296 project.options.libraryDirs = { };
3297 for(c = 0; c < count; c++)
3300 f.Read(&len, sizeof(int),1);
3301 name = new char[len+1];
3302 f.Read(name, sizeof(char), len+1);
3303 project.options.libraryDirs.Add(name);
3307 f.Read(&count, sizeof(int),1);
3310 project.options.libraries = { };
3311 for(c = 0; c < count; c++)
3314 f.Read(&len, sizeof(int),1);
3315 name = new char[len+1];
3316 f.Read(name, sizeof(char), len+1);
3317 project.options.libraries.Add(name);
3321 f.Read(&count, sizeof(int),1);
3324 project.options.preprocessorDefinitions = { };
3325 for(c = 0; c < count; c++)
3328 f.Read(&len, sizeof(int),1);
3329 name = new char[len+1];
3330 f.Read(name, sizeof(char), len+1);
3331 project.options.preprocessorDefinitions.Add(name);
3335 f.Read(&temp, sizeof(int),1);
3336 project.options.console = temp ? true : false;
3339 for(node : project.topNode.files)
3341 if(node.type == resources)
3343 project.resNode = node;
3353 void ProjectConfig::LegacyProjectConfigLoad(File f)
3361 char subSection[128];
3367 f.GetLine(buffer, 65536 - 1);
3368 TrimLSpaces(buffer, buffer);
3369 TrimRSpaces(buffer, buffer);
3372 if(buffer[0] == '-')
3376 TrimLSpaces(equal, equal);
3377 if(!strcmpi(subSection, "LibraryDirs"))
3379 if(!options.libraryDirs)
3380 options.libraryDirs = { [ CopyString(equal) ] };
3382 options.libraryDirs.Add(CopyString(equal));
3384 else if(!strcmpi(subSection, "IncludeDirs"))
3386 if(!options.includeDirs)
3387 options.includeDirs = { [ CopyString(equal) ] };
3389 options.includeDirs.Add(CopyString(equal));
3392 else if(buffer[0] == '+')
3403 TrimLSpaces(equal, equal);
3404 delete name; name = CopyString(equal); // property::name = equal;
3407 else if(!strcmpi(buffer, "Compiler Options"))
3408 strcpy(section, buffer);
3409 else if(!strcmpi(buffer, "IncludeDirs"))
3410 strcpy(subSection, buffer);
3411 else if(!strcmpi(buffer, "Linker Options"))
3412 strcpy(section, buffer);
3413 else if(!strcmpi(buffer, "LibraryDirs"))
3414 strcpy(subSection, buffer);
3415 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3422 equal = strstr(buffer, "=");
3426 TrimRSpaces(buffer, buffer);
3428 TrimLSpaces(equal, equal);
3429 if(!strcmpi(buffer, "Target Name"))
3430 options.targetFileName = /*CopyString(*/equal/*)*/;
3431 else if(!strcmpi(buffer, "Target Type"))
3433 if(!strcmpi(equal, "Executable"))
3434 options.targetType = executable;
3435 else if(!strcmpi(equal, "Shared"))
3436 options.targetType = sharedLibrary;
3437 else if(!strcmpi(equal, "Static"))
3438 options.targetType = staticLibrary;
3440 options.targetType = executable;
3442 else if(!strcmpi(buffer, "Target Directory"))
3443 options.targetDirectory = /*CopyString(*/equal/*)*/;
3444 else if(!strcmpi(buffer, "Console"))
3445 options.console = ParseTrueFalseValue(equal);
3446 else if(!strcmpi(buffer, "Libraries"))
3448 if(!options.libraries) options.libraries = { };
3449 ParseArrayValue(options.libraries, equal);
3451 else if(!strcmpi(buffer, "Intermediate Directory"))
3452 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3453 else if(!strcmpi(buffer, "Debug"))
3454 options.debug = ParseTrueFalseValue(equal);
3455 else if(!strcmpi(buffer, "Optimize"))
3457 if(!strcmpi(equal, "None"))
3458 options.optimization = none;
3459 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3460 options.optimization = speed;
3461 else if(!strcmpi(equal, "Size"))
3462 options.optimization = size;
3464 options.optimization = none;
3466 else if(!strcmpi(buffer, "Compress"))
3467 options.compress = ParseTrueFalseValue(equal);
3468 else if(!strcmpi(buffer, "Profile"))
3469 options.profile = ParseTrueFalseValue(equal);
3470 else if(!strcmpi(buffer, "AllWarnings"))
3471 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3472 else if(!strcmpi(buffer, "MemoryGuard"))
3473 options.memoryGuard = ParseTrueFalseValue(equal);
3474 else if(!strcmpi(buffer, "Default Name Space"))
3475 options.defaultNameSpace = CopyString(equal);
3476 else if(!strcmpi(buffer, "Strict Name Spaces"))
3477 options.strictNameSpaces = ParseTrueFalseValue(equal);
3478 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3480 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3481 ParseArrayValue(options.preprocessorDefinitions, equal);
3487 if(!options.targetDirectory && options.objectsDirectory)
3488 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3489 //if(!objDir.dir) objDir.dir = "obj";
3490 //if(!targetDir.dir) targetDir.dir = "";
3491 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3492 // if(!defaultNameSpace) property::defaultNameSpace = "";
3493 makingModified = true;
3496 Project LegacyAsciiLoadProject(File f, char * filePath)
3498 Project project = null;
3499 ProjectNode node = null;
3501 char parentPath[MAX_LOCATION];
3502 char section[128] = "";
3503 char subSection[128] = "";
3505 bool configurationsPresent = false;
3515 f.GetLine(buffer, 65536 - 1);
3516 TrimLSpaces(buffer, buffer);
3517 TrimRSpaces(buffer, buffer);
3520 if(buffer[0] == '-' || buffer[0] == '=')
3522 bool simple = buffer[0] == '-';
3525 TrimLSpaces(equal, equal);
3526 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3528 if(!project.config.options.libraryDirs)
3529 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3531 project.config.options.libraryDirs.Add(CopyString(equal));
3533 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3535 if(!project.config.options.includeDirs)
3536 project.config.options.includeDirs = { [ CopyString(equal) ] };
3538 project.config.options.includeDirs.Add(CopyString(equal));
3540 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3542 len = strlen(equal);
3545 char temp[MAX_LOCATION];
3546 ProjectNode child { };
3547 // We don't need to do this anymore, fileName is just a property that sets name & path
3548 // child.fileName = CopyString(equal);
3551 child.name = CopyString(equal);
3552 child.path = CopyString(parentPath);
3556 GetLastDirectory(equal, temp);
3557 child.name = CopyString(temp);
3558 StripLastDirectory(equal, temp);
3559 child.path = CopyString(temp);
3561 child.nodeType = file;
3562 child.parent = parent;
3563 child.indent = parent.indent + 1;
3565 child.icon = NodeIcons::SelectFileIcon(child.name);
3566 parent.files.Add(child);
3572 StripLastDirectory(parentPath, parentPath);
3573 parent = parent.parent;
3577 else if(buffer[0] == '+')
3581 TrimLSpaces(equal, equal);
3582 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3584 char temp[MAX_LOCATION];
3585 ProjectNode child { };
3586 // NEW: Folders now have a path set like files
3587 child.name = CopyString(equal);
3588 strcpy(temp, parentPath);
3589 PathCatSlash(temp, child.name);
3590 child.path = CopyString(temp);
3592 child.parent = parent;
3593 child.indent = parent.indent + 1;
3594 child.type = folder;
3595 child.nodeType = folder;
3597 child.icon = folder;
3598 PathCatSlash(parentPath, child.name);
3599 parent.files.Add(child);
3604 else if(!strcmpi(section, "Configurations"))
3606 ProjectConfig newConfig
3608 makingModified = true;
3612 LegacyProjectConfigLoad(newConfig, f);
3613 project.configurations.Add(newConfig);
3616 else if(!strcmpi(buffer, "ECERE Project File"));
3617 else if(!strcmpi(buffer, "Version 0a"))
3618 ; //strcpy(version, "0a");
3619 else if(!strcmpi(buffer, "Version 0.1a"))
3620 ; //strcpy(version, "0.1a");
3621 else if(!strcmpi(buffer, "Configurations"))
3623 project.configurations.Free();
3624 project.config = null;
3625 strcpy(section, buffer);
3626 configurationsPresent = true;
3628 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3630 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3631 char topNodePath[MAX_LOCATION];
3632 // newConfig.defaultNameSpace = "";
3633 //newConfig.objDir.dir = "obj";
3634 //newConfig.targetDir.dir = "";
3635 project = Project { /*options = { }*/ };
3636 project.configurations = { [ newConfig ] };
3637 project.config = newConfig;
3638 // if(project.topNode.path) delete project.topNode.path;
3639 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3640 MakeSlashPath(topNodePath);
3641 PathCatSlash(topNodePath, filePath);
3642 project.filePath = topNodePath;
3643 parentPath[0] = '\0';
3644 parent = project.topNode;
3646 strcpy(section, "Target");
3651 if(equal[0] == '\"')
3653 StripQuotes(equal, equal);
3654 delete project.moduleName; project.moduleName = CopyString(equal);
3658 else if(!strcmpi(buffer, "Compiler Options"));
3659 else if(!strcmpi(buffer, "IncludeDirs"))
3660 strcpy(subSection, buffer);
3661 else if(!strcmpi(buffer, "Linker Options"));
3662 else if(!strcmpi(buffer, "LibraryDirs"))
3663 strcpy(subSection, buffer);
3664 else if(!strcmpi(buffer, "Files"))
3666 strcpy(section, "Target");
3667 strcpy(subSection, buffer);
3669 else if(!strcmpi(buffer, "Resources"))
3671 ProjectNode child { };
3672 parent.files.Add(child);
3673 child.parent = parent;
3674 child.indent = parent.indent + 1;
3675 child.name = CopyString(buffer);
3676 child.path = CopyString("");
3677 child.type = resources;
3679 child.icon = archiveFile;
3680 project.resNode = child;
3683 strcpy(subSection, buffer);
3687 equal = strstr(buffer, "=");
3691 TrimRSpaces(buffer, buffer);
3693 TrimLSpaces(equal, equal);
3695 if(!strcmpi(section, "Target"))
3697 if(!strcmpi(buffer, "Build Exclusions"))
3699 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3701 /*if(node && node.type != NodeTypes::project)
3702 ParseListValue(node.buildExclusions, equal);*/
3705 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3707 delete project.resNode.path;
3708 project.resNode.path = CopyString(equal);
3709 PathCatSlash(parentPath, equal);
3713 else if(!strcmpi(buffer, "Intermediate Directory"))
3714 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3715 else if(!strcmpi(buffer, "Debug"))
3716 project.config.options.debug = ParseTrueFalseValue(equal);
3717 else if(!strcmpi(buffer, "Optimize"))
3719 if(!strcmpi(equal, "None"))
3720 project.config.options.optimization = none;
3721 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3722 project.config.options.optimization = speed;
3723 else if(!strcmpi(equal, "Size"))
3724 project.config.options.optimization = size;
3726 project.config.options.optimization = none;
3728 else if(!strcmpi(buffer, "Profile"))
3729 project.config.options.profile = ParseTrueFalseValue(equal);
3730 else if(!strcmpi(buffer, "MemoryGuard"))
3731 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3734 if(!project.options) project.options = { };
3736 // Project Wide Settings (All configs)
3737 if(!strcmpi(buffer, "Target Name"))
3738 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3739 else if(!strcmpi(buffer, "Target Type"))
3741 if(!strcmpi(equal, "Executable"))
3742 project.options.targetType = executable;
3743 else if(!strcmpi(equal, "Shared"))
3744 project.options.targetType = sharedLibrary;
3745 else if(!strcmpi(equal, "Static"))
3746 project.options.targetType = staticLibrary;
3748 project.options.targetType = executable;
3750 else if(!strcmpi(buffer, "Target Directory"))
3751 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3752 else if(!strcmpi(buffer, "Console"))
3753 project.options.console = ParseTrueFalseValue(equal);
3754 else if(!strcmpi(buffer, "Libraries"))
3756 if(!project.options.libraries) project.options.libraries = { };
3757 ParseArrayValue(project.options.libraries, equal);
3759 else if(!strcmpi(buffer, "AllWarnings"))
3760 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3761 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3763 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3765 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3766 ParseListValue(node.preprocessorDefs, equal);*/
3770 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3771 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3782 SplitPlatformLibraries(project);
3784 if(configurationsPresent)
3785 CombineIdenticalConfigOptions(project);
3789 void SplitPlatformLibraries(Project project)
3791 if(project && project.configurations)
3793 for(cfg : project.configurations)
3795 if(cfg.options.libraries && cfg.options.libraries.count)
3797 Iterator<String> it { cfg.options.libraries };
3801 char * platformName = strstr(l, ":");
3804 PlatformOptions platform = null;
3806 if(!cfg.platforms) cfg.platforms = { };
3807 for(p : cfg.platforms)
3809 if(!strcmpi(platformName, p.name))
3817 platform = { name = CopyString(platformName), options = { libraries = { } } };
3818 cfg.platforms.Add(platform);
3820 *(platformName-1) = 0;
3821 platform.options.libraries.Add(CopyString(l));
3823 cfg.options.libraries.Delete(it.pointer);
3832 void CombineIdenticalConfigOptions(Project project)
3834 if(project && project.configurations && project.configurations.count)
3837 ProjectOptions nullOptions { };
3838 ProjectConfig firstConfig = null;
3839 for(cfg : project.configurations)
3841 if(cfg.options.targetType != staticLibrary)
3848 firstConfig = project.configurations.firstIterator.data;
3850 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3852 if(!member.isProperty)
3854 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3859 for(cfg : project.configurations)
3861 if(cfg != firstConfig)
3863 if(cfg.options.targetType != staticLibrary)
3867 if(type.type == noHeadClass || type.type == normalClass)
3869 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3870 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3871 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3875 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3876 (byte *)firstConfig.options + member.offset + member._class.offset,
3877 (byte *)cfg.options + member.offset + member._class.offset);
3889 if(type.type == noHeadClass || type.type == normalClass)
3891 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3892 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3893 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3898 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3899 (byte *)firstConfig.options + member.offset + member._class.offset,
3900 (byte *)nullOptions + member.offset + member._class.offset))
3904 if(!project.options) project.options = { };
3906 /*if(type.type == noHeadClass || type.type == normalClass)
3908 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
3909 (byte *)project.options + member.offset + member._class.offset,
3910 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3914 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3915 // TOFIX: ListBox::SetData / OnCopy mess
3916 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
3917 (byte *)project.options + member.offset + member._class.offset,
3918 (type.typeSize > 4) ? address :
3919 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3920 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3921 (void *)*(byte *)address )));
3924 (byte *)project.options + member.offset + member._class.offset,
3925 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3927 for(cfg : project.configurations)
3929 if(cfg.options.targetType == staticLibrary)
3933 if(type.type == noHeadClass || type.type == normalClass)
3935 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3936 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3937 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3941 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
3942 (byte *)firstConfig.options + member.offset + member._class.offset,
3943 (byte *)cfg.options + member.offset + member._class.offset);
3948 if(cfg != firstConfig)
3950 if(type.type == noHeadClass || type.type == normalClass)
3952 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
3953 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3957 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
3958 (byte *)cfg.options + member.offset + member._class.offset);
3960 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3963 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3970 // Compare Platform Specific Settings
3973 for(cfg : project.configurations)
3975 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3976 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3982 if(same && firstConfig.platforms)
3984 for(cfg : project.configurations)
3986 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3988 if(cfg != firstConfig)
3990 cfg.platforms.Free();
3991 delete cfg.platforms;
3994 project.platforms = firstConfig.platforms;
3995 firstConfig.platforms = null;
3999 // Static libraries can't contain libraries
4000 for(cfg : project.configurations)
4002 if(cfg.options.targetType == staticLibrary)
4004 if(!cfg.options.libraries) cfg.options.libraries = { };
4005 cfg.options.libraries.Free();
4011 Project LoadProject(char * filePath, char * activeConfigName)
4013 Project project = null;
4014 File f = FileOpen(filePath, read);
4017 project = LegacyBinaryLoadProject(f, filePath);
4020 JSONParser parser { f = f };
4021 JSONResult result = parser.GetObject(class(Project), &project);
4024 char insidePath[MAX_LOCATION];
4026 delete project.topNode.files;
4027 if(!project.files) project.files = { };
4028 project.topNode.files = project.files;
4029 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4030 delete project.resNode.path;
4031 project.resNode.path = project.resourcesPath;
4032 project.resourcesPath = null;
4033 project.resNode.nodeType = (ProjectNodeType)-1;
4034 delete project.resNode.files;
4035 project.resNode.files = project.resources;
4036 project.files = null;
4037 project.resources = null;
4038 if(!project.configurations) project.configurations = { };
4041 char topNodePath[MAX_LOCATION];
4042 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4043 MakeSlashPath(topNodePath);
4044 PathCatSlash(topNodePath, filePath);
4045 project.filePath = topNodePath;//filePath;
4048 project.topNode.FixupNode(insidePath);
4053 project = LegacyAsciiLoadProject(f, filePath);
4059 if(!project.options) project.options = { };
4060 if(activeConfigName && activeConfigName[0] && project.configurations)
4062 for(cfg : project.configurations)
4064 if(!strcmpi(cfg.name, activeConfigName))
4066 project.config = cfg;
4071 if(!project.config && project.configurations)
4072 project.config = project.configurations.firstIterator.data;
4074 if(!project.resNode)
4076 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4079 if(!project.moduleName)
4080 project.moduleName = CopyString(project.name);
4081 if(project.config &&
4082 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4083 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4085 //delete project.config.options.targetFileName;
4087 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4088 project.config.options.optimization = none;
4089 project.config.options.debug = true;
4090 //project.config.options.warnings = unset;
4091 project.config.options.memoryGuard = false;
4092 project.config.compilingModified = true;
4093 project.config.linkingModified = true;
4095 else if(!project.topNode.name && project.config)
4097 project.topNode.name = CopyString(project.config.options.targetFileName);
4100 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4101 project.topNode.configurations = project.configurations;
4102 project.topNode.platforms = project.platforms;
4103 project.topNode.options = project.options;*/