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, rcSources };
411 define WorkspaceExtension = "ews";
412 define ProjectExtension = "epj";
414 define stringInFileIncludedFrom = "In file included from ";
415 define stringFrom = " from ";
417 // This function cannot accept same pointer for source and output
418 // todo: rename ReplaceSpaces to EscapeSpaceAndSpecialChars or something
419 void ReplaceSpaces(char * output, char * source)
424 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
426 if(ch == ' ') output[dc++] = '\\';
427 if(ch == '\"') output[dc++] = '\\';
428 if(ch == '&') output[dc++] = '\\';
431 if(ch == '(' || ch == ')') output[dc++] = '\\';
441 // chars refused for project name: windowsFileNameCharsNotAllowed + " &,."
443 //define gnuMakeCharsNeedEscaping = "$%";
445 //define windowsFileNameCharsNotAllowed = "*/:<>?\\\"|";
446 //define linuxFileNameCharsNotAllowed = "/";
448 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
449 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
451 // NOTES: - this function should get only unescaped unix style paths
452 // - paths with literal $(somestring) in them are not supported
453 // my_$(messed_up)_path would likely become my__path
454 void EscapeForMake(char * output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
456 char ch, *i = input, *o = output;
459 int len = strlen(input);
460 if(len && ((input[0] == '"' && input[len-1] == '"') || strchr(input, '\\') || strchr(input, 127) || (!allowDblQuote && strchr(input, '"'))))
461 PrintLn("Invalid input for EscapeForMake! -- ", input);
467 if(i-1 != input && *(i-2) == '$' && allowVars)
474 if(inVar == true && allowVars)
479 else if(ch == '$' && *i != '(')
501 void EscapeForMakeToFile(File output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
503 char * buf = new char[strlen(input)*2+1];
504 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
509 void EscapeForMakeToDynString(DynamicString output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
511 char * buf = new char[strlen(input)*2+1];
512 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
517 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
520 const int breakListLength = 1536;
521 const int breakLineLength = 78; // TODO: turn this into an option.
523 int c, len, itemCount = 0;
524 Array<int> breaks { };
528 MapNode<String, int> mn;
529 for(c=0; c<list.count; c++)
531 len = strlen(list[c]) + 3;
532 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
534 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
536 if(strstr(list[c], mn.key))
540 if(charCount + len > breakListLength)
542 breaks.Add(itemCount);
550 breaks.Add(itemCount);
551 numOfBreaks = breaks.count;
556 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
557 for(c=0; c<numOfBreaks; c++)
558 f.Printf(" $(%s%d)", name, c+1);
562 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
568 for(c=0; c<numOfBreaks; c++)
571 f.Printf("%s%d =", name, c+1);
574 itemCount = breaks[c];
575 for(n=offset; n<offset+itemCount; n++)
577 if(false) // TODO: turn this into an option.
579 int itemLen = strlen(list[n]);
580 if(len > 3 && len + itemLen > breakLineLength)
582 f.Printf(" \\\n\t%s", list[n]);
588 f.Printf(" %s", list[n]);
592 f.Printf(" \\\n\t%s", list[n]);
607 void OutputLinkObjectActions(File f, char * name, int parts)
612 for(c=0; c<parts; c++)
613 f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
615 f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
619 void OutputCleanActions(File f, char * name, int parts)
624 for(c=0; c<parts; c++)
625 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
628 f.Printf("\t$(call rmq,$(%s))\n", name);
631 enum LineOutputMethod { inPlace, newLine, lineEach };
632 enum StringOutputMethod { asIs, escape, escapePath};
634 enum ToolchainFlag { any, _D, _I, _isystem, _Wl, _L/*, _Wl-rpath*/ };
635 String flagNames[ToolchainFlag] = { "", "-D", "-I", "-isystem ", "-Wl,", /*"-Wl,--library-path="*/"-L"/*, "-Wl,-rpath "*/ };
636 void OutputFlags(File f, ToolchainFlag flag, Array<String> list, LineOutputMethod lineMethod)
640 if(lineMethod == newLine)
644 if(lineMethod == lineEach)
646 f.Printf(" %s", flagNames[flag]);
647 if(flag != _D && flag != _Wl && flag != any)
649 char * tmp = new char[strlen(item)*2+1];
650 EscapeForMake(tmp, item, false, true, false);
651 f.Printf("$(call quote_path,%s)", tmp);
655 EscapeForMakeToFile(f, item, false, true, true);
660 static void OutputLibraries(File f, Array<String> libraries)
662 for(item : libraries)
664 char ext[MAX_EXTENSION];
665 char temp[MAX_LOCATION];
667 bool usedFunction = false;
668 GetExtension(item, ext);
669 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
673 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
675 if(!strncmp(item, "lib", 3))
676 strcpy(temp, item + 3);
679 StripExtension(temp);
682 f.Puts(" \\\n\t$(call _L,");
685 EscapeForMakeToFile(f, s, false, false, false);
691 void CamelCase(char * string)
693 int c, len = strlen(string);
694 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
695 string[c] = (char)tolower(string[c]);
698 CompilerConfig GetCompilerConfig()
700 #ifndef MAKEFILE_GENERATOR
701 CompilerConfig compiler = null;
702 if(ide && ide.workspace)
703 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
706 incref defaultCompiler;
707 return defaultCompiler;
711 define localTargetType = config && config.options && config.options.targetType ?
712 config.options.targetType : options && options.targetType ?
713 options.targetType : TargetTypes::executable;
714 define localWarnings = config && config.options && config.options.warnings ?
715 config.options.warnings : options && options.warnings ?
716 options.warnings : WarningsOption::unset;
717 define localDebug = config && config.options && config.options.debug ?
718 config.options.debug : options && options.debug ?
719 options.debug : SetBool::unset;
720 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
721 config.options.memoryGuard : options && options.memoryGuard ?
722 options.memoryGuard : SetBool::unset;
723 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
724 config.options.noLineNumbers : options && options.noLineNumbers ?
725 options.noLineNumbers : SetBool::unset;
726 define localProfile = config && config.options && config.options.profile ?
727 config.options.profile : options && options.profile ?
728 options.profile : SetBool::unset;
729 define localOptimization = config && config.options && config.options.optimization ?
730 config.options.optimization : options && options.optimization ?
731 options.optimization : OptimizationStrategy::none;
732 define localFastMath = config && config.options && config.options.fastMath ?
733 config.options.fastMath : options && options.fastMath ?
734 options.fastMath : SetBool::unset;
735 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
736 config.options.defaultNameSpace : options && options.defaultNameSpace ?
737 options.defaultNameSpace : null;
738 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
739 config.options.strictNameSpaces : options && options.strictNameSpaces ?
740 options.strictNameSpaces : SetBool::unset;
741 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
742 define localTargetFileName = config && config.options && config.options.targetFileName ?
743 config.options.targetFileName : options && options.targetFileName ?
744 options.targetFileName : "";
745 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
746 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
747 options.targetDirectory : null;
748 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
749 ideSettings.projectDefaultIntermediateObjDir[0] ?
750 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
751 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
752 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
753 options.objectsDirectory : null;
754 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
755 ideSettings.projectDefaultIntermediateObjDir[0] ?
756 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
757 define localConsole = config && config.options && config.options.console ?
758 config.options.console : options && options.console ?
759 options.console : SetBool::unset;
760 define localCompress = config && config.options && config.options.compress ?
761 config.options.compress : options && options.compress ?
762 options.compress : SetBool::unset;
764 define platformTargetType =
765 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
766 configPOs.options.targetType :
767 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
768 projectPOs.options.targetType : TargetTypes::unset;
771 char * PlatformToMakefileTargetVariable(Platform platform)
773 return platform == win32 ? "WINDOWS_TARGET" :
774 platform == tux ? "LINUX_TARGET" :
775 platform == apple ? "OSX_TARGET" :
779 char * TargetTypeToMakefileVariable(TargetTypes targetType)
781 return targetType == executable ? "executable" :
782 targetType == sharedLibrary ? "sharedlib" :
783 targetType == staticLibrary ? "staticlib" :
787 // Move this to ProjectConfig? null vs Common to consider...
788 char * GetConfigName(ProjectConfig config)
790 return config ? config.name : "Common";
793 public enum SingleFileCompileMode
795 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
797 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
800 class Project : struct
802 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
803 // We might want to tweak this default behavior of regular classes ?
804 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
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)
816 property char * description
818 set { delete description; if(value && value[0]) description = CopyString(value); }
819 get { return description ? description : ""; }
820 isset { return description != null && description[0]; }
823 property char * license
825 set { delete license; if(value && value[0]) license = CopyString(value); }
826 get { return license ? license : ""; }
827 isset { return license != null && license[0]; }
830 property char * compilerConfigsDir
832 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
833 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
834 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
837 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
838 property Array<PlatformOptions> platforms
840 get { return platforms; }
843 if(platforms) { platforms.Free(); delete platforms; }
846 List<PlatformOptions> empty { };
847 Iterator<PlatformOptions> it { value };
849 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
850 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
860 if(p.options && !p.options.isEmpty)
867 List<ProjectConfig> configurations;
868 LinkList<ProjectNode> files;
869 String resourcesPath;
870 LinkList<ProjectNode> resources;
873 // topNode.name holds the file name (.epj)
874 ProjectOptions options;
875 Array<PlatformOptions> platforms;
876 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
879 ProjectConfig config;
881 // This is the file name stripped of the epj extension
882 // It should NOT be edited, saved or loaded anywhere
887 String compilerConfigsDir;
888 String moduleVersion;
890 String lastBuildConfigName;
891 String lastBuildCompilerName;
893 Map<String, NameCollisionInfo> lastBuildNamesInfo;
895 #ifndef MAKEFILE_GENERATOR
896 FileMonitor fileMonitor
898 this, FileChange { modified = true };
899 bool OnFileNotify(FileChange action, char * param)
901 fileMonitor.StopMonitoring();
902 if(OnProjectModified(action, param))
903 fileMonitor.StartMonitoring();
908 bool StartMonitoring()
910 fileMonitor.fileName = filePath;
911 fileMonitor.StartMonitoring();
915 bool StopMonitoring()
917 fileMonitor.StopMonitoring();
921 bool OnProjectModified(FileChange fileChange, char * param)
924 sprintf(temp, $"The project %s was modified by another application.\n"
925 "Would you like to reload it and lose your changes?", name);
926 if(MessageBox { type = yesNo, master = ide,
927 text = $"Project has been modified", contents = temp }.Modal() == yes)
929 Project project = LoadProject(filePath, config ? config.name : null);
932 ProjectView projectView = ide.projectView;
933 DataRow prev = topNode.row ? topNode.row.previous : null;
934 FileMonitor fm = fileMonitor;
935 bool confirmation = true;
939 if(projectView.projectSettingsDialog)
941 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
943 projectView.projectSettingsDialog.Destroy(0);
946 projectView.DeleteNode(topNode);
953 topNode.project = this;
957 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
958 projectView.AddNode(topNode, null);
959 topNode.row.Move(prev);
961 projectView.ShowOutputBuildLog(true);
962 projectView.DisplayCompiler(compiler, false);
963 projectView.ProjectUpdateMakefileForAllConfigs(this);
966 eSystem_Delete(project);
978 // This frees contents without freeing the instance
979 // For use from destructor and for file monitor reloading
980 // (To work around JSON loader (LoadProject) always returning a new instance)
983 if(platforms) { platforms.Free(); delete platforms; }
984 if(configurations) { configurations.Free(); delete configurations; }
985 if(files) { files.Free(); delete files; }
986 if(resources) { resources.Free(); delete resources; }
988 delete resourcesPath;
992 delete compilerConfigsDir;
994 delete moduleVersion;
998 delete lastBuildConfigName;
999 delete lastBuildCompilerName;
1000 if(lastBuildNamesInfo) { lastBuildNamesInfo.Free(); delete lastBuildNamesInfo; }
1005 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
1006 topNode.configurations = null;
1007 topNode.platforms = null;
1008 topNode.options = null;
1013 property ProjectConfig config
1018 delete topNode.info;
1019 topNode.info = CopyString(GetConfigName(config));
1023 property char * filePath
1029 char string[MAX_LOCATION];
1030 GetLastDirectory(value, string);
1031 delete topNode.name;
1032 topNode.name = CopyString(string);
1033 StripExtension(string);
1035 name = CopyString(string);
1036 StripLastDirectory(value, string);
1037 delete topNode.path;
1038 topNode.path = CopyString(string);
1040 filePath = CopyString(value);
1045 ProjectConfig GetConfig(char * configName)
1047 ProjectConfig result = null;
1048 if(configName && configName[0] && configurations.count)
1050 for(cfg : configurations; !strcmpi(cfg.name, configName))
1059 ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
1062 if(!lastBuildNamesInfo)
1063 ProjectLoadLastBuildNamesInfo(this, config);
1064 result = topNode.FindByObjectFileName(fileName, type, dotMain, lastBuildNamesInfo);
1068 TargetTypes GetTargetType(ProjectConfig config)
1070 TargetTypes targetType = localTargetType;
1074 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1077 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1079 PlatformOptions projectPOs, configPOs;
1080 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1081 if(platformTargetType)
1087 char * GetObjDirExpression(ProjectConfig config)
1089 // TODO: Support platform options
1090 char * expression = localObjectsDirectory;
1092 expression = settingsObjectsDirectory;
1096 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1098 char * expression = GetObjDirExpression(config);
1099 DirExpression objDir { type = intermediateObjectsDir };
1100 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1104 char * GetTargetDirExpression(ProjectConfig config)
1106 // TODO: Support platform options
1107 char * expression = localTargetDirectory;
1109 expression = settingsTargetDirectory;
1113 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1115 char * expression = GetTargetDirExpression(config);
1116 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1117 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1121 WarningsOption GetWarnings(ProjectConfig config)
1123 WarningsOption warnings = localWarnings;
1127 bool GetDebug(ProjectConfig config)
1129 SetBool debug = localDebug;
1130 return debug == true;
1133 bool GetMemoryGuard(ProjectConfig config)
1135 SetBool memoryGuard = localMemoryGuard;
1136 return memoryGuard == true;
1139 bool GetNoLineNumbers(ProjectConfig config)
1141 SetBool noLineNumbers = localNoLineNumbers;
1142 return noLineNumbers == true;
1145 bool GetProfile(ProjectConfig config)
1147 SetBool profile = localProfile;
1148 return profile == true;
1151 OptimizationStrategy GetOptimization(ProjectConfig config)
1153 OptimizationStrategy optimization = localOptimization;
1154 return optimization;
1157 bool GetFastMath(ProjectConfig config)
1159 SetBool fastMath = localFastMath;
1160 return fastMath == true;
1163 String GetDefaultNameSpace(ProjectConfig config)
1165 String defaultNameSpace = localDefaultNameSpace;
1166 return defaultNameSpace;
1169 bool GetStrictNameSpaces(ProjectConfig config)
1171 SetBool strictNameSpaces = localStrictNameSpaces;
1172 return strictNameSpaces == true;
1175 String GetTargetFileName(ProjectConfig config)
1177 String targetFileName = localTargetFileName;
1178 return targetFileName;
1181 //String targetDirectory;
1182 //String objectsDirectory;
1183 bool GetConsole(ProjectConfig config)
1185 SetBool console = localConsole;
1186 return console == true;
1189 bool GetCompress(ProjectConfig config)
1191 SetBool compress = localCompress;
1192 return compress == true;
1194 //SetBool excludeFromBuild;
1196 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1198 #ifndef MAKEFILE_GENERATOR
1199 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1203 bool GetConfigIsInDebugSession(ProjectConfig config)
1205 #ifndef MAKEFILE_GENERATOR
1206 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1210 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1212 #ifndef MAKEFILE_GENERATOR
1213 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1217 #ifndef MAKEFILE_GENERATOR
1218 bool Save(char * fileName)
1221 /*char output[MAX_LOCATION];
1222 ChangeExtension(fileName, "json", output);
1223 f = FileOpen(output, write);*/
1224 f = FileOpen(fileName, write);
1227 files = topNode.files;
1228 resources = resNode.files;
1229 resourcesPath = resNode.path;
1231 files.Remove(resNode);
1234 WriteJSONObject(f, class(Project), this, 0);
1240 resourcesPath = null;
1247 // This method is only called from Debugger, should be moved to Debugger class?
1248 #ifndef MAKEFILE_GENERATOR
1249 bool GetRelativePath(char * filePath, char * relativePath)
1252 char moduleName[MAX_FILENAME];
1253 GetLastDirectory(filePath, moduleName);
1254 // try with workspace dir first?
1255 if((node = topNode.Find(moduleName, false)))
1257 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1258 PathCatSlash(relativePath, node.name);
1263 // Tweak for automatically resolving symbol loader modules
1264 char * sl = strstr(moduleName, ".main.ec");
1265 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1267 char objDir[MAX_LOCATION];
1268 DirExpression objDirExp;
1269 CompilerConfig compiler = ide.debugger.currentCompiler;
1270 ProjectConfig config = ide.debugger.prjConfig;
1271 int bitDepth = ide.debugger.bitDepth;
1272 // This is not perfect, as multiple source files exist for the symbol loader module...
1273 // We try to set it in the debug config object directory.
1274 if(!compiler || !config)
1276 // If we're not currently debugging, set a breakpoint in the active compiler/config
1277 compiler = GetCompilerConfig();
1278 config = this.config;
1279 // If the current config is not debuggable, set it in the first debuggable config found
1280 if(config && !config.options.debug)
1282 for(c : configurations; c.options.debug)
1289 objDirExp = GetObjDir(compiler, config, bitDepth);
1290 strcpy(objDir, objDirExp.dir);
1292 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1293 ReplaceSpaces(relativePath, objDir);
1295 PathCatSlash(relativePath, moduleName);
1299 // WARNING: On failure, relative path is uninitialized
1304 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1306 TargetTypes targetType = GetTargetType(config);
1307 String targetFileName = GetTargetFileName(config);
1308 if(targetType == staticLibrary)
1310 PathCatSlash(string, "lib");
1311 strcat(string, targetFileName);
1313 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1315 PathCatSlash(string, "lib");
1316 strcat(string, targetFileName);
1319 PathCatSlash(string, targetFileName);
1324 if(compiler.targetPlatform == win32)
1325 strcat(string, ".exe");
1328 if(compiler.targetPlatform == win32)
1329 strcat(string, ".dll");
1330 else if(compiler.targetPlatform == apple)
1331 strcat(string, ".dylib");
1333 strcat(string, ".so");
1334 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1336 strcat(string, ".");
1337 strcat(string, moduleVersion);
1341 strcat(string, ".a");
1346 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1348 bool result = false;
1349 char temp[MAX_LOCATION];
1350 strcpy(cfDir, topNode.path);
1351 if(compilerConfigsDir && compilerConfigsDir[0])
1353 PathCatSlash(cfDir, compilerConfigsDir);
1358 strcpy(temp, cfDir);
1359 // Using a relative path makes it less likely to run into spaces issues
1360 // Even with escaped spaces, there still seems to be issues including a config file
1361 // in a path containing spaces
1363 MakePathRelative(temp, topNode.path, cfDir);
1366 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1370 strcpy(temp, cfDir);
1371 ReplaceSpaces(cfDir, temp);
1376 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1378 char temp[MAX_LOCATION];
1379 bool result = false;
1380 strcpy(cfDir, topNode.path);
1381 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1383 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1388 // Default to <ProjectDir>/.configs if unset
1389 PathCatSlash(cfDir, ".configs");
1394 strcpy(temp, cfDir);
1395 // Using a relative path makes it less likely to run into spaces issues
1396 // Even with escaped spaces, there still seems to be issues including a config file
1397 // in a path containing spaces
1398 if(IsPathInsideOf(cfDir, topNode.path))
1399 MakePathRelative(temp, topNode.path, cfDir);
1401 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1405 strcpy(temp, cfDir);
1406 ReplaceSpaces(cfDir, temp);
1411 void CatMakeFileName(char * string, ProjectConfig config)
1413 char projectName[MAX_LOCATION];
1414 strcpy(projectName, name);
1415 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1418 #ifndef MAKEFILE_GENERATOR
1419 void MarkChanges(ProjectNode node)
1421 for(cfg : topNode.configurations)
1423 ProjectConfig c = null;
1424 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1426 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1427 (!c.options || !cfg.options)))
1428 cfg.symbolGenModified = true;
1429 if(c && ((c.options && cfg.options &&
1430 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1431 || (!c.options || !cfg.options)))
1432 cfg.linkingModified = true;
1434 cfg.makingModified = true;
1438 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1440 for(cfg : configurations)
1443 cfg.makingModified = true;
1445 cfg.compilingModified = true;
1447 cfg.linkingModified = true;
1449 cfg.symbolGenModified = true;
1451 if(compiling || linking)
1453 ide.projectView.modifiedDocument = true;
1454 ide.workspace.modified = true;
1458 void RotateActiveConfig(bool forward, bool syncAllProjects)
1460 if(configurations.first && configurations.last != configurations.first)
1462 Iterator<ProjectConfig> cfg { configurations };
1463 while(forward ? cfg.Next() : cfg.Prev())
1464 if(cfg.data == config)
1479 ide.workspace.SelectActiveConfig(cfg.data.name);
1482 property::config = cfg.data;
1483 ide.UpdateToolBarActiveConfigs(true);
1484 ide.workspace.modified = true;
1485 ide.projectView.Update(null);
1490 bool ProcessPipeOutputRaw(DualPipe f)
1493 while(!f.Eof() && !ide.projectView.stopBuild)
1496 double lastTime = GetTime();
1500 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1502 ide.outputView.buildBox.Logf("%s\n", line);
1504 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1506 //printf("Processing Input...\n");
1507 if(app.ProcessInput(true))
1509 app.UpdateDisplay();
1512 //printf("Waiting...\n");
1515 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1517 if(ide.projectView.stopBuild)
1519 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1522 return !ide.projectView.stopBuild;
1525 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, BuildType buildType, List<ProjectNode> onlyNodes,
1526 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1529 bool compiling = false, linking = false, precompiling = false;
1530 int compilingEC = 0;
1531 int numErrors = 0, numWarnings = 0;
1532 bool loggedALine = false;
1533 int lenMakeCommand = strlen(compiler.makeCommand);
1536 char moduleName[MAX_FILENAME];
1537 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1539 DynamicString test { };
1540 DynamicString ecp { };
1541 DynamicString ecc { };
1542 DynamicString ecs { };
1543 DynamicString ear { };
1544 DynamicString prefix { };
1545 DynamicString cpp { };
1546 DynamicString cc { };
1547 DynamicString cxx { };
1548 DynamicString strip { };
1549 DynamicString ar { };
1550 DynamicString windres { };
1553 if(bitDepth == 64 && compiler.targetPlatform == win32)
1554 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1555 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1556 gnuToolchainPrefix = "i686-w64-mingw32-";
1558 ecp.concatx(compiler.ecpCommand, " ");
1559 ecc.concatx(compiler.eccCommand, " ");
1560 ecs.concatx(compiler.ecsCommand, " ");
1561 ear.concatx(compiler.earCommand, " ");
1564 compiler.ccacheEnabled ? "ccache " : "",
1565 compiler.distccEnabled ? "distcc " : "",
1566 gnuToolchainPrefix);
1568 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1569 cc.concatx((String)prefix, compiler.ccCommand, " ");
1570 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1572 strip.concatx(gnuToolchainPrefix, "strip ");
1573 ar.concatx(gnuToolchainPrefix, "ar rcs");
1574 windres.concatx(gnuToolchainPrefix, "windres ");
1576 testLen = Max(testLen, ecp.size);
1577 testLen = Max(testLen, ecc.size);
1578 testLen = Max(testLen, ecs.size);
1579 testLen = Max(testLen, ear.size);
1580 testLen = Max(testLen, cpp.size);
1581 testLen = Max(testLen, cc.size);
1582 testLen = Max(testLen, cxx.size);
1583 testLen = Max(testLen, strip.size);
1584 testLen = Max(testLen, ar.size);
1585 testLen = Max(testLen, windres.size);
1586 testLen = Max(testLen, strlen("mkdir "));
1589 while(!f.Eof() && !ide.projectView.stopBuild)
1592 double lastTime = GetTime();
1596 //printf("Peeking and GetLine...\n");
1597 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1599 char * message = null;
1600 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1601 char * from = strstr(line, stringFrom);
1602 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1603 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1605 char * module = strstr(line, "No rule to make target `");
1609 module = strchr(module, '`') + 1;
1610 end = strchr(module, '\'');
1614 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1615 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1621 //ide.outputView.buildBox.Logf("error: %s\n", line);
1625 else if(strstr(test, "mkdir ") == test);
1626 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1627 else if(strstr(test, ear) == test);
1628 else if(strstr(test, strip) == test);
1629 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1632 bool isPrecomp = false;
1635 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1637 module = strstr(line, " -c ");
1638 if(module) module += 4;
1641 else if(strstr(test, ecc) == test)
1643 module = strstr(line, " -c ");
1644 if(module) module += 4;
1645 //module = line + 3;
1646 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1647 compilingEC = 3;//2;
1650 else if(strstr(test, ecp) == test)
1652 // module = line + 8;
1653 module = strstr(line, " -c ");
1654 if(module) module += 4;
1665 if(!compiling && !isPrecomp)
1667 ide.outputView.buildBox.Logf($"Compiling...\n");
1670 else if(!precompiling && isPrecomp)
1672 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1673 precompiling = true;
1675 // Changed escapeBackSlashes here to handle paths with spaces
1676 Tokenize(module, 1, tokens, (BackSlashEscaping)true); // fix #139
1677 GetLastDirectory(module, moduleName);
1678 ide.outputView.buildBox.Logf("%s\n", moduleName);
1680 else if((module = strstr(line, " -o ")))
1683 precompiling = false;
1685 ide.outputView.buildBox.Logf($"Linking...\n");
1689 ide.outputView.buildBox.Logf("%s\n", line);
1690 if(strstr(line, "warning:") || strstr(line, "note:"))
1692 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1696 if(compilingEC) compilingEC--;
1698 else if(strstr(test, windres) == test)
1701 module = strstr(line, " ");
1702 if(module) module++;
1706 char * dashF = strstr(module, "-F ");
1710 while(*dashF && *dashF != ' ') dashF++;
1711 while(*dashF && *dashF == ' ') dashF++;
1714 Tokenize(module, 1, tokens, (BackSlashEscaping)true); // fix #139
1715 GetLastDirectory(module, moduleName);
1716 ide.outputView.buildBox.Logf("%s\n", moduleName);
1719 else if(strstr(test, ar) == test)
1720 ide.outputView.buildBox.Logf($"Building library...\n");
1721 else if(strstr(test, ecs) == test)
1722 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1725 if(linking || compiling || precompiling)
1727 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1728 char * colon = strstr(start, ":"); //, * bracket;
1729 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1730 colon = strstr(colon + 1, ":");
1733 char * sayError = "";
1734 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1737 int len = (int)(colon - start);
1738 char ext[MAX_EXTENSION];
1739 len = Min(len, MAX_LOCATION-1);
1740 // Don't be mistaken by the drive letter colon
1742 // TODO: need to fix colon - line gives char *
1743 // warning: incompatible expression colon - line (char *); expected int
1745 strncpy(moduleName, line, (int)(colon - line));
1746 moduleName[colon - line] = '\0';
1748 strncpy(moduleName, start, len);
1749 moduleName[len] = '\0';
1750 // Remove stuff in brackets
1751 //bracket = strstr(moduleName, "(");
1752 //if(bracket) *bracket = '\0';
1754 GetLastDirectory(moduleName, temp);
1755 GetExtension(temp, ext);
1757 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1759 char * cColon = strstr(colon+1, ":");
1760 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1761 cColon = strstr(cColon + 1, ":");
1764 int len = (int)(cColon - (colon+1));
1765 char mName[MAX_LOCATION];
1766 len = Min(len, MAX_LOCATION-1);
1767 strncpy(mName, colon+1, len);
1769 GetLastDirectory(mName, temp);
1770 GetExtension(temp, ext);
1771 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1774 strcpy(moduleName, mName);
1778 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1781 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1783 message = $"Linker Message: ";
1789 message = $"Linker Error: ";
1792 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1796 if(!strstr(line, "error:"))
1798 message = $"Linker Error: ";
1804 strcpy(temp, topNode.path);
1805 PathCatSlash(temp, moduleName);
1806 MakePathRelative(temp, topNode.path, moduleName);
1808 error = strstr(line, "error:");
1809 if(!message && error && error > colon)
1813 // Silence warnings for compiled eC
1814 char * objDir = strstr(moduleName, objDirExp.dir);
1818 if((pointer = strstr(line, "undefined")) ||
1819 (pointer = strstr(line, "multiple definition")) ||
1820 (pointer = strstr(line, "No such file")) ||
1821 (pointer = strstr(line, "token")))
1823 strncat(moduleName, colon, pointer - colon);
1824 sayError = "error: ";
1829 else if((pointer = strstr(line, "No such file")))
1831 strncat(moduleName, colon, pointer - colon);
1832 sayError = "error: ";
1836 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1838 else if(strstr(line, "warning:"))
1844 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1845 /*else if(this == ide.workspace.projects.firstIterator.data)
1846 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1849 char fullModuleName[MAX_LOCATION];
1850 FileAttribs found = 0;
1851 Project foundProject = this;
1854 char * loc = strstr(moduleName, ":");
1856 strcpy(fullModuleName, topNode.path);
1857 PathCat(fullModuleName, moduleName);
1858 found = FileExists(fullModuleName);
1859 if(!found && !strcmp(ext, "c"))
1861 char ecName[MAX_LOCATION];
1862 ChangeExtension(fullModuleName, "ec", ecName);
1863 found = FileExists(ecName);
1867 char path[MAX_LOCATION];
1868 if(ide && ide.workspace)
1870 for(prj : ide.workspace.projects)
1873 MakePathRelative(fullModuleName, prj.topNode.path, path);
1875 if((node = prj.topNode.FindWithPath(path, false)))
1877 strcpy(fullModuleName, prj.topNode.path);
1878 PathCatSlash(fullModuleName, node.path);
1879 PathCatSlash(fullModuleName, node.name);
1880 found = FileExists(fullModuleName);
1888 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1890 for(prj : ide.workspace.projects)
1893 if((node = prj.topNode.Find(moduleName, false)))
1895 strcpy(fullModuleName, prj.topNode.path);
1896 PathCatSlash(fullModuleName, node.path);
1897 PathCatSlash(fullModuleName, node.name);
1898 found = FileExists(fullModuleName);
1911 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1912 MakeSystemPath(fullModuleName);
1915 strcpy(fullModuleName, moduleName);
1918 strcat(fullModuleName, ":");
1919 strcat(fullModuleName, loc + 1);
1923 fullModuleName[0] = 0;
1924 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1929 ide.outputView.buildBox.Logf("%s\n", line);
1930 linking = compiling = precompiling = false;
1934 ide.outputView.buildBox.Logf("%s\n", line);
1938 //printf("Done getting line\n");
1939 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1941 //printf("Processing Input...\n");
1942 if(app.ProcessInput(true))
1944 app.UpdateDisplay();
1947 //printf("Waiting...\n");
1950 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1952 if(ide.projectView.stopBuild)
1954 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1957 else if(loggedALine || buildType != run)
1959 if(f.GetExitCode() && !numErrors)
1961 bool result = f.GetLine(line, sizeof(line)-1);
1962 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1964 else if(buildType != install)
1968 char targetFileName[MAX_LOCATION];
1969 targetFileName[0] = '\0';
1970 CatTargetFileName(targetFileName, compiler, config);
1971 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1974 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1976 ide.outputView.buildBox.Logf($"no error, ");
1979 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1981 ide.outputView.buildBox.Logf($"no warning\n");
1998 return numErrors == 0 && !ide.projectView.stopBuild;
2001 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
2004 int lenMakeCommand = strlen(compiler.makeCommand);
2009 double lastTime = GetTime();
2012 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2014 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
2015 else if(strstr(line, "mkdir") == line);
2016 else if(strstr(line, "del") == line);
2017 else if(strstr(line, "rm") == line);
2018 else if(strstr(line, "Could Not Find") == line);
2021 ide.outputView.buildBox.Logf(line);
2022 ide.outputView.buildBox.Logf("\n");
2026 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
2028 if(app.ProcessInput(true))
2030 app.UpdateDisplay();
2033 //Sleep(1.0 / PEEK_RESOLUTION);
2037 bool Build(BuildType buildType, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2039 bool result = false;
2041 char targetFileName[MAX_LOCATION] = "";
2042 DynamicString makeTargets { };
2043 char makeFile[MAX_LOCATION];
2044 char makeFilePath[MAX_LOCATION];
2045 char configName[MAX_LOCATION];
2046 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
2047 PathBackup pathBackup { };
2048 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2049 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2051 bool eC_Debug = mode.eC_ToolsDebug;
2052 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2053 int numJobs = compiler.numJobs;
2054 char command[MAX_F_STRING*4];
2055 char * compilerName = CopyString(compiler.name);
2057 delete lastBuildConfigName;
2058 lastBuildConfigName = CopyString(config ? config.name : "Common");
2059 delete lastBuildCompilerName;
2060 lastBuildCompilerName = CopyString(compiler.name);
2061 ProjectLoadLastBuildNamesInfo(this, config);
2063 CamelCase(compilerName);
2065 strcpy(configName, config ? config.name : "Common");
2067 SetPath(false, compiler, config, bitDepth); //true
2068 CatTargetFileName(targetFileName, compiler, config);
2070 strcpy(makeFilePath, topNode.path);
2071 CatMakeFileName(makeFile, config);
2072 PathCatSlash(makeFilePath, makeFile);
2074 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2075 if(buildType == install)
2076 makeTargets.concat(" install");
2079 if(compiler.type.isVC)
2081 PrintLn("compiling a single file is not yet supported");
2086 char pushD[MAX_LOCATION];
2087 char cfDir[MAX_LOCATION];
2088 GetIDECompilerConfigsDir(cfDir, true, true);
2089 GetWorkingDir(pushD, sizeof(pushD));
2090 ChangeWorkingDir(topNode.path);
2091 // Create object dir if it does not exist already
2092 if(!FileExists(objDirExp.dir).isDirectory)
2094 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2095 compiler.makeCommand, cfDir,
2096 crossCompiling ? " TARGET_PLATFORM=" : "",
2098 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2099 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2101 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2103 ide.outputView.buildBox.Logf("%s\n", command);
2107 ChangeWorkingDir(pushD);
2109 for(node : onlyNodes)
2111 if(node.GetIsExcluded(config))
2112 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2116 node.DeleteIntermediateFiles(compiler, config, bitDepth, lastBuildNamesInfo, mode == cObject ? true : false);
2117 node.GetTargets(config, lastBuildNamesInfo, objDirExp.dir, makeTargets);
2123 if(compiler.type.isVC)
2125 bool result = false;
2126 char oldwd[MAX_LOCATION];
2127 GetWorkingDir(oldwd, sizeof(oldwd));
2128 ChangeWorkingDir(topNode.path);
2130 // TODO: support justPrint
2131 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2133 ide.outputView.buildBox.Logf("%s\n", command);
2134 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2136 ProcessPipeOutputRaw(f);
2140 ChangeWorkingDir(oldwd);
2142 else if(onlyNodes && strlen(makeTargets) == 0)
2144 ide.outputView.buildBox.Log("No targets to compile.\n");
2148 char cfDir[MAX_LOCATION];
2149 GetIDECompilerConfigsDir(cfDir, true, true);
2150 sprintf(command, "%s%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2151 #if defined(__WIN32__)
2154 buildType == install ? "pkexec --user root " : "",
2156 compiler.makeCommand,
2157 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2159 crossCompiling ? " TARGET_PLATFORM=" : "",
2161 bitDepth ? " ARCH=" : "",
2162 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2163 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2164 compilerName, eC_Debug ? "--always-make " : "", numJobs,
2165 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2166 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2167 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2169 ide.outputView.buildBox.Logf("%s\n", command);
2171 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2179 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2185 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2188 ide.outputView.buildBox.Logf("%s\n", line);
2189 if(!error && !found && strstr(line, "echo ") == line)
2191 strcpy(command, line+5);
2194 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2196 strcpy(command, line);
2206 result = ProcessPipeOutputRaw(f);
2208 result = ProcessBuildPipeOutput(f, objDirExp, buildType, onlyNodes, compiler, config, bitDepth);
2211 ide.outputView.buildBox.Logf("%s\n", command);
2212 else if(justPrint && found)
2213 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2218 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2223 delete compilerName;
2228 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2230 char makeFile[MAX_LOCATION];
2231 char makeFilePath[MAX_LOCATION];
2232 char command[MAX_LOCATION];
2233 char * compilerName;
2235 PathBackup pathBackup { };
2236 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2237 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2239 compilerName = CopyString(compiler.name);
2240 CamelCase(compilerName);
2242 SetPath(false, compiler, config, bitDepth);
2244 strcpy(makeFilePath, topNode.path);
2245 CatMakeFileName(makeFile, config);
2246 PathCatSlash(makeFilePath, makeFile);
2248 if(compiler.type.isVC)
2250 bool result = false;
2251 char oldwd[MAX_LOCATION];
2252 GetWorkingDir(oldwd, sizeof(oldwd));
2253 ChangeWorkingDir(topNode.path);
2255 // TODO: justPrint support
2256 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2258 ide.outputView.buildBox.Logf("%s\n", command);
2259 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2261 ProcessPipeOutputRaw(f);
2265 ChangeWorkingDir(oldwd);
2270 char cfDir[MAX_LOCATION];
2271 GetIDECompilerConfigsDir(cfDir, true, true);
2272 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2273 compiler.makeCommand, cfDir,
2274 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2275 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2277 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2278 topNode.path, justPrint ? " -n": "", makeFilePath);
2280 ide.outputView.buildBox.Logf("%s\n", command);
2281 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2283 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2284 cleanType == realClean ? $"intermediate objects directory" : $"target",
2285 cleanType == clean ? $" and object files" : "");
2287 ProcessPipeOutputRaw(f);
2289 ProcessCleanPipeOutput(f, compiler, config);
2290 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2291 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2292 cleanType == clean ? $" and object files" : "");
2298 delete compilerName;
2301 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2303 String target = new char[maxPathLen];
2304 char oldDirectory[MAX_LOCATION];
2305 char * executableLauncher = compiler.executableLauncher;
2306 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2307 PathBackup pathBackup { };
2309 // Build(project, ideMain, true, null, false);
2311 strcpy(target, topNode.path);
2312 PathCatSlash(target, targetDirExp.dir);
2313 CatTargetFileName(target, compiler, config);
2314 sprintf(target, "%s %s", target, args);
2315 GetWorkingDir(oldDirectory, MAX_LOCATION);
2317 if(strlen(ide.workspace.debugDir))
2319 char temp[MAX_LOCATION];
2320 strcpy(temp, topNode.path);
2321 PathCatSlash(temp, ide.workspace.debugDir);
2322 ChangeWorkingDir(temp);
2325 ChangeWorkingDir(topNode.path);
2326 SetPath(true, compiler, config, bitDepth);
2327 if(executableLauncher)
2329 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 8];
2330 prefixedTarget[0] = '\0';
2331 strcat(prefixedTarget, executableLauncher);
2332 strcat(prefixedTarget, " ");
2333 strcat(prefixedTarget, target);
2334 Execute(prefixedTarget);
2335 delete prefixedTarget;
2340 ChangeWorkingDir(oldDirectory);
2343 delete targetDirExp;
2347 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2349 return Build(build, nodes, compiler, config, bitDepth, justPrint, mode);
2353 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2356 if(targetType == staticLibrary || targetType == sharedLibrary)
2357 strcat(fileName, "$(LP)");
2358 strcat(fileName, GetTargetFileName(config));
2362 strcat(fileName, "$(E)");
2365 strcat(fileName, "$(SO)$(VER)");
2368 strcat(fileName, "$(A)");
2373 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2375 bool result = false;
2376 char path[MAX_LOCATION];
2378 if(!GetProjectCompilerConfigsDir(path, false, false))
2379 GetIDECompilerConfigsDir(path, false, false);
2381 if(!FileExists(path).isDirectory)
2385 char dirName[MAX_FILENAME];
2386 GetLastDirectory(path, dirName);
2387 if(!strcmp(dirName, ".configs"))
2388 FileSetAttribs(path, FileAttribs { isHidden = true });
2391 PathCatSlash(path, "crossplatform.mk");
2393 if(FileExists(path))
2396 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2399 File f = FileOpen(path, write);
2402 include.Seek(0, start);
2403 for(; !include.Eof(); )
2406 int count = include.Read(buffer, 1, 4096);
2407 f.Write(buffer, 1, count);
2413 if(!altCrossPlatformMk)
2420 bool GenerateCompilerCf(CompilerConfig compiler)
2422 bool result = false;
2423 char path[MAX_LOCATION];
2425 char * compilerName;
2426 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2427 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2428 Platform platform = compiler.targetPlatform;
2430 compilerName = CopyString(compiler.name);
2431 CamelCase(compilerName);
2432 name = PrintString(platform, "-", compilerName, ".cf");
2434 if(!GetProjectCompilerConfigsDir(path, false, false))
2435 GetIDECompilerConfigsDir(path, false, false);
2437 if(!FileExists(path).isDirectory)
2441 char dirName[MAX_FILENAME];
2442 GetLastDirectory(path, dirName);
2443 if(!strcmp(dirName, ".configs"))
2444 FileSetAttribs(path, FileAttribs { isHidden = true });
2447 PathCatSlash(path, name);
2449 if(FileExists(path))
2452 File f = FileOpen(path, write);
2455 if(compiler.environmentVars && compiler.environmentVars.count)
2457 f.Puts("# ENVIRONMENT VARIABLES\n");
2459 for(e : compiler.environmentVars)
2461 f.Printf("export %s := %s\n", e.name, e.string);
2466 f.Puts("# TOOLCHAIN\n");
2469 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2471 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2474 if(compiler.sysroot && compiler.sysroot[0])
2476 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2477 // Moved this to crossplatform.mk
2478 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2482 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2483 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2484 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2485 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2486 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
2487 f.Printf("ECC := $(if $(ECC_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecc/ecc.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2488 f.Printf("ECS := $(if $(ECS_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecs/ecs.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)\n", compiler.ecsCommand);
2489 f.Printf("EAR := %s\n", compiler.earCommand);
2491 f.Puts("AS := $(GCC_PREFIX)as\n");
2492 f.Puts("LD := $(GCC_PREFIX)ld\n");
2493 f.Puts("AR := $(GCC_PREFIX)ar\n");
2494 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2495 f.Puts("ifdef WINDOWS_TARGET\n");
2496 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2497 f.Puts(" ifdef ARCH\n");
2498 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2499 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2501 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2502 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2507 f.Puts("UPX := upx\n");
2510 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2513 f.Puts("EARFLAGS = \n");
2516 f.Puts("ifndef ARCH\n");
2517 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2518 f.Puts(" ifdef WINDOWS_HOST\n");
2519 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2520 f.Puts(" TARGET_ARCH := x86_64\n");
2522 f.Puts(" TARGET_ARCH := i386\n");
2525 f.Puts("endif\n\n");
2527 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2528 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2532 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2536 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2539 if(compiler.includeDirs && compiler.includeDirs.count)
2541 f.Puts("\nCFLAGS +=");
2542 OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
2545 if(compiler.prepDirectives && compiler.prepDirectives.count)
2547 f.Puts("\nCFLAGS +=");
2548 OutputFlags(f, _D, compiler.prepDirectives, inPlace);
2551 if(compiler.libraryDirs && compiler.libraryDirs.count)
2553 f.Puts("\nLDFLAGS +=");
2554 OutputFlags(f, _L, compiler.libraryDirs, lineEach);
2555 // We would need a bool option to know whether we want to add to rpath as well...
2556 // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
2559 if(compiler.excludeLibs && compiler.excludeLibs.count)
2561 f.Puts("\nEXCLUDED_LIBS =");
2562 for(l : compiler.excludeLibs)
2568 if(compiler.compilerFlags && compiler.compilerFlags.count)
2570 f.Puts("\nCFLAGS +=");
2571 OutputFlags(f, any, compiler.compilerFlags, inPlace);
2574 if(compiler.linkerFlags && compiler.linkerFlags.count)
2576 f.Puts("\nLDFLAGS +=");
2577 OutputFlags(f, _Wl, compiler.linkerFlags, inPlace);
2581 f.Puts("\nOFLAGS += $(LDFLAGS)");
2583 f.Puts("ifdef ARCH_FLAGS\n");
2584 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2585 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2594 delete compilerName;
2598 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2600 bool result = false;
2601 char filePath[MAX_LOCATION];
2602 char makeFile[MAX_LOCATION];
2603 // PathBackup pathBackup { };
2604 // char oldDirectory[MAX_LOCATION];
2607 if(!altMakefilePath)
2609 strcpy(filePath, topNode.path);
2610 CatMakeFileName(makeFile, config);
2611 PathCatSlash(filePath, makeFile);
2614 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2616 /*SetPath(false, compiler, config);
2617 GetWorkingDir(oldDirectory, MAX_LOCATION);
2618 ChangeWorkingDir(topNode.path);*/
2625 char targetDir[MAX_LOCATION];
2626 char objDirExpNoSpaces[MAX_LOCATION];
2627 char objDirNoSpaces[MAX_LOCATION];
2628 char resDirNoSpaces[MAX_LOCATION];
2629 char targetDirExpNoSpaces[MAX_LOCATION];
2630 char fixedModuleName[MAX_FILENAME];
2631 char fixedConfigName[MAX_FILENAME];
2633 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2634 // Non-zero if we're building eC code
2635 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2636 int numCObjects = 0;
2638 int numRCObjects = 0;
2639 bool containsCXX = false; // True if the project contains a C++ file
2640 bool relObjDir, sameOrRelObjTargetDirs;
2641 String objDirExp = GetObjDirExpression(config);
2642 TargetTypes targetType = GetTargetType(config);
2644 char cfDir[MAX_LOCATION];
2645 int objectsParts = 0;
2646 int eCsourcesParts = 0;
2647 int rcSourcesParts = 0;
2648 Array<String> listItems { };
2649 Map<String, int> varStringLenDiffs { };
2650 Map<String, NameCollisionInfo> namesInfo { };
2652 Map<String, int> cflagsVariations { };
2653 Map<intptr, int> nodeCFlagsMapping { };
2655 Map<String, int> ecflagsVariations { };
2656 Map<intptr, int> nodeECFlagsMapping { };
2658 ReplaceSpaces(objDirNoSpaces, objDirExp);
2659 strcpy(targetDir, GetTargetDirExpression(config));
2660 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2662 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2663 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2665 char temp[MAX_LOCATION];
2666 ReplaceSpaces(temp, objDirExpNoSpaces);
2667 strcpy(objDirExpNoSpaces, temp);
2669 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2670 ReplaceSpaces(fixedModuleName, moduleName);
2671 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2672 CamelCase(fixedConfigName);
2674 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2675 relObjDir = lenObjDirExpNoSpaces == 0 ||
2676 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2677 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2678 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2679 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2680 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2682 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2684 f.Puts("# CORE VARIABLES\n\n");
2686 f.Printf("MODULE := %s\n", fixedModuleName);
2687 f.Printf("VERSION := %s\n", property::moduleVersion);
2688 f.Printf("CONFIG := %s\n", fixedConfigName);
2689 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2692 test = GetTargetTypeIsSetByPlatform(config);
2696 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2698 TargetTypes targetType;
2699 PlatformOptions projectPOs, configPOs;
2700 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2701 targetType = platformTargetType;
2707 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2708 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2713 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2718 for(c = 0; c < ifCount; c++)
2724 f.Puts("# FLAGS\n\n");
2726 f.Puts("ECFLAGS =\n");
2727 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2728 f.Puts("PRJ_CFLAGS =\n");
2729 f.Puts("CECFLAGS =\n");
2730 f.Puts("OFLAGS =\n");
2734 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2737 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2738 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2739 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2740 //f.Puts("endif\n");
2743 f.Puts("# INCLUDES\n\n");
2745 if(compilerConfigsDir && compilerConfigsDir[0])
2747 strcpy(cfDir, compilerConfigsDir);
2748 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2753 GetIDECompilerConfigsDir(cfDir, true, true);
2754 // Use CF_DIR environment variable for absolute paths only
2755 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2756 strcpy(cfDir, "$(CF_DIR)");
2759 f.Printf("_CF_DIR = %s\n", cfDir);
2762 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2763 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2766 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2768 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2771 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2774 // test = GetTargetTypeIsSetByPlatform(config);
2776 char target[MAX_LOCATION];
2777 char temp[MAX_LOCATION];
2782 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2784 if(type != targetType)
2789 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2791 GetMakefileTargetFileName(type, target, config);
2792 strcpy(temp, targetDir);
2793 PathCatSlash(temp, target);
2794 ReplaceSpaces(target, temp);
2795 f.Printf("TARGET = %s\n", target);
2800 GetMakefileTargetFileName(targetType, target, config);
2801 strcpy(temp, targetDir);
2802 PathCatSlash(temp, target);
2803 ReplaceSpaces(target, temp);
2804 f.Printf("TARGET = %s\n", target);
2810 for(c = 0; c < ifCount; c++)
2817 // Use something fixed here, to not cause Makefile differences across compilers...
2818 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2819 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2821 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2825 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2827 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2830 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2832 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2833 if(eCsourcesParts > 1)
2835 for(c = 1; c <= eCsourcesParts; c++)
2836 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2840 for(c = 0; c < 5; c++)
2842 if(eCsourcesParts > 1)
2845 f.Printf("%s =", map[c][0]);
2846 for(n = 1; n <= eCsourcesParts; n++)
2847 f.Printf(" $(%s%d)", map[c][0], n);
2849 for(n = 1; n <= eCsourcesParts; n++)
2850 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2852 else if(eCsourcesParts == 1)
2853 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2859 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2862 f.Puts("ifdef WINDOWS_TARGET\n\n");
2864 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2866 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2867 if(rcSourcesParts > 1)
2869 for(c = 1; c <= rcSourcesParts; c++)
2870 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2873 if(rcSourcesParts > 1)
2876 f.Printf("%s =", "RCOBJECTS");
2877 for(n = 1; n <= rcSourcesParts; n++)
2878 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2880 for(n = 1; n <= rcSourcesParts; n++)
2881 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2883 else if(rcSourcesParts == 1)
2884 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2888 f.Puts("RCSOURCES =\n");
2889 f.Puts("RCOBJECTS =\n");
2890 f.Puts("endif\n\n");
2893 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2895 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2896 f.Printf("OBJECTS =%s%s%s%s\n",
2897 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2898 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2899 numRCObjects ? " $(RCOBJECTS)" : "");
2902 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2905 if(numCObjects && numRCObjects)
2906 prefix = "$(ECSOURCES) $(RCSOURCES)";
2907 else if(numCObjects)
2908 prefix = "$(ECSOURCES)";
2911 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2915 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2916 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2918 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2920 if((config && config.options && config.options.libraries) ||
2921 (options && options.libraries))
2923 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2925 if(config && config.options && config.options.libraries)
2926 OutputLibraries(f, config.options.libraries);
2927 else if(options && options.libraries)
2928 OutputLibraries(f, options.libraries);
2934 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2935 cflagsVariations, nodeCFlagsMapping,
2936 ecflagsVariations, nodeECFlagsMapping, null);
2938 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2939 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2941 if(platforms || (config && config.platforms))
2944 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2945 //for(platform = win32; platform <= apple; platform++)
2947 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2948 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2950 PlatformOptions projectPlatformOptions, configPlatformOptions;
2951 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2953 if(projectPlatformOptions || configPlatformOptions)
2958 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2961 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2962 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2964 f.Puts("CFLAGS +=");
2965 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2968 for(s : projectPlatformOptions.options.compilerOptions)
2971 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2974 for(s : configPlatformOptions.options.compilerOptions)
2981 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2982 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2984 f.Puts("OFLAGS +=");
2985 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2987 bool needWl = false;
2989 for(s : projectPlatformOptions.options.linkerOptions)
2991 if(!IsLinkerOption(s))
2999 for(s : projectPlatformOptions.options.linkerOptions)
3000 if(IsLinkerOption(s))
3004 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
3006 bool needWl = false;
3008 for(s : configPlatformOptions.options.linkerOptions)
3010 if(IsLinkerOption(s))
3018 for(s : configPlatformOptions.options.linkerOptions)
3019 if(!IsLinkerOption(s))
3027 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3028 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
3029 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
3030 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
3032 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3033 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3034 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
3036 f.Puts("OFLAGS +=");
3037 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
3038 OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
3039 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
3040 OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
3044 if(configPlatformOptions && configPlatformOptions.options.libraries)
3046 if(configPlatformOptions.options.libraries.count)
3049 OutputLibraries(f, configPlatformOptions.options.libraries);
3053 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3055 if(projectPlatformOptions.options.libraries.count)
3058 OutputLibraries(f, projectPlatformOptions.options.libraries);
3069 for(c = 0; c < ifCount; c++)
3075 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3076 (options && options.compilerOptions && options.compilerOptions.count))
3078 f.Puts("CFLAGS +=");
3081 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3083 for(s : config.options.compilerOptions)
3086 if(options && options.compilerOptions && options.compilerOptions.count)
3088 for(s : options.compilerOptions)
3095 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3096 (options && options.linkerOptions && options.linkerOptions.count))
3098 f.Puts("OFLAGS +=");
3101 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3103 bool needWl = false;
3104 for(s : config.options.linkerOptions)
3106 if(!IsLinkerOption(s))
3114 for(s : config.options.linkerOptions)
3115 if(IsLinkerOption(s))
3119 if(options && options.linkerOptions && options.linkerOptions.count)
3121 bool needWl = false;
3122 for(s : options.linkerOptions)
3124 if(!IsLinkerOption(s))
3132 for(s : options.linkerOptions)
3133 if(IsLinkerOption(s))
3141 f.Puts("CECFLAGS += -cpp $(_CPP)");
3145 if(GetProfile(config))
3146 f.Puts("OFLAGS += -pg\n\n");
3148 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3150 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3151 f.Puts("OFLAGS +=");
3152 if(config && config.options && config.options.libraryDirs)
3153 OutputFlags(f, _L, config.options.libraryDirs, lineEach);
3154 if(options && options.libraryDirs)
3155 OutputFlags(f, _L, options.libraryDirs, lineEach);
3161 f.Puts("# TARGETS\n");
3164 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3167 f.Puts("objdir:\n");
3169 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3171 f.Puts("\t$(if $(ECERE_SDK_SRC),$(if $(wildcard $(call escspace,$(ECERE_SDK_SRC)/crossplatform.mk)),,@$(call echo,Ecere SDK Source Warning: The value of ECERE_SDK_SRC is pointing to an incorrect ($(ECERE_SDK_SRC)) location.)),)\n");
3172 f.Puts("\t$(if $(ECERE_SDK_SRC),,$(if $(ECP_DEBUG)$(ECC_DEBUG)$(ECS_DEBUG),@$(call echo,ECC Debug Warning: Please define ECERE_SDK_SRC before using ECP_DEBUG, ECC_DEBUG or ECS_DEBUG),))\n");
3173 //f.Puts("# PRE-BUILD COMMANDS\n");
3174 if(options && options.prebuildCommands)
3176 for(s : options.prebuildCommands)
3177 if(s && s[0]) f.Printf("\t%s\n", s);
3179 if(config && config.options && config.options.prebuildCommands)
3181 for(s : config.options.prebuildCommands)
3182 if(s && s[0]) f.Printf("\t%s\n", s);
3184 if(platforms || (config && config.platforms))
3187 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3188 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3190 PlatformOptions projectPOs, configPOs;
3191 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3193 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3194 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3199 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3201 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3203 for(s : projectPOs.options.prebuildCommands)
3204 if(s && s[0]) f.Printf("\t%s\n", s);
3206 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3208 for(s : configPOs.options.prebuildCommands)
3209 if(s && s[0]) f.Printf("\t%s\n", s);
3216 for(c = 0; c < ifCount; c++)
3222 if(!sameOrRelObjTargetDirs)
3224 f.Puts("targetdir:\n");
3225 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3231 // Main Module (Linking) for ECERE C modules
3232 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3233 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3234 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(call escspace,$@)\n",
3235 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3237 // Main Module (Linking) for ECERE C modules
3238 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3239 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3240 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3241 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3242 " -c $(OBJ)$(MODULE).main.ec -o $(call escspace,$@) -symbols $(OBJ)\n");
3248 // This would not rebuild the target on updated objects
3249 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3251 // This should fix it for good!
3252 f.Puts("$(SYMBOLS): | objdir\n");
3253 f.Puts("$(OBJECTS): | objdir\n");
3255 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3256 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3257 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3259 f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
3260 f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
3261 OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
3264 f.Puts("ifdef WINDOWS_TARGET\n");
3265 OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
3270 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
3271 OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
3274 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3276 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
3277 if(!GetDebug(config))
3279 f.Puts("ifndef NOSTRIP\n");
3280 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3283 if(GetCompress(config))
3285 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3286 f.Puts("ifdef EXECUTABLE_TARGET\n");
3287 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3290 f.Puts("ifneq \"$(TARGET_ARCH)\" \"x86_64\"\n");
3291 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3296 if(resNode.files && resNode.files.count && !noResources)
3297 resNode.GenMakefileAddResources(f, resNode.path, config);
3299 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
3301 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3302 f.Puts("ifdef LINUX_TARGET\n");
3303 f.Puts("ifdef LINUX_HOST\n");
3304 // TODO?: support symlinks for longer version numbers
3305 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3306 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3311 //f.Puts("# POST-BUILD COMMANDS\n");
3312 if(options && options.postbuildCommands)
3314 for(s : options.postbuildCommands)
3315 if(s && s[0]) f.Printf("\t%s\n", s);
3317 if(config && config.options && config.options.postbuildCommands)
3319 for(s : config.options.postbuildCommands)
3320 if(s && s[0]) f.Printf("\t%s\n", s);
3322 if(platforms || (config && config.platforms))
3325 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3326 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3328 PlatformOptions projectPOs, configPOs;
3329 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3331 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3332 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3337 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3339 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3341 for(s : projectPOs.options.postbuildCommands)
3342 if(s && s[0]) f.Printf("\t%s\n", s);
3344 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3346 for(s : configPOs.options.postbuildCommands)
3347 if(s && s[0]) f.Printf("\t%s\n", s);
3354 for(c = 0; c < ifCount; c++)
3361 if(platforms || (config && config.platforms))
3363 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3365 PlatformOptions projectPOs, configPOs;
3366 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3368 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3369 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3376 if(test || (options && options.installCommands) ||
3377 (config && config.options && config.options.installCommands))
3379 f.Puts("install:\n");
3380 if(options && options.installCommands)
3382 for(s : options.installCommands)
3383 if(s && s[0]) f.Printf("\t%s\n", s);
3385 if(config && config.options && config.options.installCommands)
3387 for(s : config.options.installCommands)
3388 if(s && s[0]) f.Printf("\t%s\n", s);
3390 if(platforms || (config && config.platforms))
3393 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3395 PlatformOptions projectPOs, configPOs;
3396 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3398 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3399 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3404 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3406 if(projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count)
3408 for(s : projectPOs.options.installCommands)
3409 if(s && s[0]) f.Printf("\t%s\n", s);
3411 if(configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count)
3413 for(s : configPOs.options.installCommands)
3414 if(s && s[0]) f.Printf("\t%s\n", s);
3421 for(c = 0; c < ifCount; c++)
3428 f.Puts("# SYMBOL RULES\n");
3431 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3433 f.Puts("# C OBJECT RULES\n");
3436 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3438 f.Puts("# OBJECT RULES\n");
3440 // todo call this still but only generate rules whith specific options
3441 // see we-have-file-specific-options in ProjectNode.ec
3442 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3445 GenMakefilePrintMainObjectRule(f, config);
3447 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3448 f.Puts("\t$(call rmq,$(TARGET))\n");
3449 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3450 f.Puts("ifdef LINUX_TARGET\n");
3451 f.Puts("ifdef LINUX_HOST\n");
3452 // TODO?: support symlinks for longer version numbers
3453 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3454 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3460 f.Puts("clean: cleantarget\n");
3461 f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3462 OutputCleanActions(f, "_OBJECTS", objectsParts);
3465 f.Puts("ifdef WINDOWS_TARGET\n");
3466 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3471 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)");
3472 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3473 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3474 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3475 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3476 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3480 f.Puts("realclean: cleantarget\n");
3481 f.Puts("\t$(call rmrq,$(OBJ))\n");
3482 if(!sameOrRelObjTargetDirs)
3483 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3486 f.Puts("distclean: cleantarget\n");
3487 if(!sameOrRelObjTargetDirs)
3488 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3490 f.Puts("\t$(call rmrq,obj/)\n");
3496 varStringLenDiffs.Free();
3497 delete varStringLenDiffs;
3501 delete cflagsVariations;
3502 delete nodeCFlagsMapping;
3503 delete ecflagsVariations;
3504 delete nodeECFlagsMapping;
3509 // ChangeWorkingDir(oldDirectory);
3510 // delete pathBackup;
3513 config.makingModified = false;
3517 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3519 char extension[MAX_EXTENSION] = "c";
3520 char modulePath[MAX_LOCATION];
3521 char fixedModuleName[MAX_FILENAME];
3524 char objDirNoSpaces[MAX_LOCATION];
3525 String objDirExp = GetObjDirExpression(config);
3527 ReplaceSpaces(objDirNoSpaces, objDirExp);
3528 ReplaceSpaces(fixedModuleName, moduleName);
3530 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3531 //strcat(fixedModuleName, ".main");
3533 #if 0 // TODO: Fix nospaces stuff
3534 // *** Dependency command ***
3535 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3537 // System Includes (from global settings)
3538 for(item : compiler.dirs[Includes])
3540 strcat(command, " -isystem ");
3541 if(strchr(item.name, ' '))
3543 strcat(command, "\"");
3544 strcat(command, item);
3545 strcat(command, "\"");
3548 strcat(command, item);
3551 for(item = includeDirs.first; item; item = item.next)
3553 strcat(command, " -I");
3554 if(strchr(item.name, ' '))
3556 strcat(command, "\"");
3557 strcat(command, item.name);
3558 strcat(command, "\"");
3561 strcat(command, item.name);
3563 for(item = preprocessorDefs.first; item; item = item.next)
3565 strcat(command, " -D");
3566 strcat(command, item.name);
3570 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
3574 bool firstLine = true;
3576 // To do some time: auto save external dependencies?
3579 if(dep.GetLine(line, sizeof(line)-1))
3583 char * colon = strstr(line, ":");
3584 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3598 // If we failed to generate dependencies...
3602 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3603 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(call escspace,$@)\n", extension);
3611 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3614 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3616 for(v : cflagsVariations)
3621 f.Printf("%s +=", variableName);
3623 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3624 f.Puts(&v ? &v : "");
3632 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3633 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3635 *projectPlatformOptions = null;
3636 *configPlatformOptions = null;
3641 if(!strcmpi(p.name, platform))
3643 *projectPlatformOptions = p;
3648 if(config && config.platforms)
3650 for(p : config.platforms)
3652 if(!strcmpi(p.name, platform))
3654 *configPlatformOptions = p;
3662 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3664 if(prj.lastBuildNamesInfo)
3666 prj.lastBuildNamesInfo.Free();
3667 delete prj.lastBuildNamesInfo;
3669 prj.lastBuildNamesInfo = { };
3670 prj.topNode.GenMakefileGetNameCollisionInfo(prj.lastBuildNamesInfo, cfg);
3673 Project LegacyBinaryLoadProject(File f, char * filePath)
3675 Project project = null;
3676 char signature[sizeof(epjSignature)];
3678 f.Read(signature, sizeof(signature), 1);
3679 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3681 char topNodePath[MAX_LOCATION];
3682 /*ProjectConfig newConfig
3684 name = CopyString("Default");
3685 makingModified = true;
3686 compilingModified = true;
3687 linkingModified = true;
3691 project = Project { options = { } };
3692 LegacyBinaryLoadNode(project.topNode, f);
3693 delete project.topNode.path;
3694 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3695 MakeSlashPath(topNodePath);
3697 PathCatSlash(topNodePath, filePath);
3698 project.filePath = topNodePath;
3700 /* THIS IS ALREADY DONE BY filePath property
3701 StripLastDirectory(topNodePath, topNodePath);
3702 project.topNode.path = CopyString(topNodePath);
3704 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3706 // newConfig.options.defaultNameSpace = "";
3707 /*newConfig.objDir.dir = "obj";
3708 newConfig.targetDir.dir = "";*/
3710 //project.configurations = { [ newConfig ] };
3711 //project.config = newConfig;
3718 String targetFileName, targetDirectory, objectsDirectory;
3720 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3721 f.Read(&temp, sizeof(int),1);
3724 case 0: project.options.targetType = executable; break;
3725 case 1: project.options.targetType = sharedLibrary; break;
3726 case 2: project.options.targetType = staticLibrary; break;
3729 f.Read(&len, sizeof(int),1);
3730 targetFileName = new char[len+1];
3731 f.Read(targetFileName, sizeof(char), len+1);
3732 project.options.targetFileName = targetFileName;
3733 delete targetFileName;
3735 f.Read(&len, sizeof(int),1);
3736 targetDirectory = new char[len+1];
3737 f.Read(targetDirectory, sizeof(char), len+1);
3738 project.options.targetDirectory = targetDirectory;
3739 delete targetDirectory;
3741 f.Read(&len, sizeof(int),1);
3742 objectsDirectory = new byte[len+1];
3743 f.Read(objectsDirectory, sizeof(char), len+1);
3744 project.options.objectsDirectory = objectsDirectory;
3745 delete objectsDirectory;
3747 f.Read(&temp, sizeof(int),1);
3748 project./*config.*/options.debug = temp ? true : false;
3749 f.Read(&temp, sizeof(int),1);
3750 project./*config.*/options.optimization = temp ? speed : none;
3751 f.Read(&temp, sizeof(int),1);
3752 project./*config.*/options.profile = temp ? true : false;
3753 f.Read(&temp, sizeof(int),1);
3754 project.options.warnings = temp ? all : unset;
3756 f.Read(&count, sizeof(int),1);
3759 project.options.includeDirs = { };
3760 for(c = 0; c < count; c++)
3763 f.Read(&len, sizeof(int),1);
3764 name = new char[len+1];
3765 f.Read(name, sizeof(char), len+1);
3766 project.options.includeDirs.Add(name);
3770 f.Read(&count, sizeof(int),1);
3773 project.options.libraryDirs = { };
3774 for(c = 0; c < count; c++)
3777 f.Read(&len, sizeof(int),1);
3778 name = new char[len+1];
3779 f.Read(name, sizeof(char), len+1);
3780 project.options.libraryDirs.Add(name);
3784 f.Read(&count, sizeof(int),1);
3787 project.options.libraries = { };
3788 for(c = 0; c < count; c++)
3791 f.Read(&len, sizeof(int),1);
3792 name = new char[len+1];
3793 f.Read(name, sizeof(char), len+1);
3794 project.options.libraries.Add(name);
3798 f.Read(&count, sizeof(int),1);
3801 project.options.preprocessorDefinitions = { };
3802 for(c = 0; c < count; c++)
3805 f.Read(&len, sizeof(int),1);
3806 name = new char[len+1];
3807 f.Read(name, sizeof(char), len+1);
3808 project.options.preprocessorDefinitions.Add(name);
3812 f.Read(&temp, sizeof(int),1);
3813 project.options.console = temp ? true : false;
3816 for(node : project.topNode.files)
3818 if(node.type == resources)
3820 project.resNode = node;
3830 void ProjectConfig::LegacyProjectConfigLoad(File f)
3838 char subSection[128];
3844 f.GetLine(buffer, 65536 - 1);
3845 TrimLSpaces(buffer, buffer);
3846 TrimRSpaces(buffer, buffer);
3849 if(buffer[0] == '-')
3853 TrimLSpaces(equal, equal);
3854 if(!strcmpi(subSection, "LibraryDirs"))
3856 if(!options.libraryDirs)
3857 options.libraryDirs = { [ CopyString(equal) ] };
3859 options.libraryDirs.Add(CopyString(equal));
3861 else if(!strcmpi(subSection, "IncludeDirs"))
3863 if(!options.includeDirs)
3864 options.includeDirs = { [ CopyString(equal) ] };
3866 options.includeDirs.Add(CopyString(equal));
3869 else if(buffer[0] == '+')
3880 TrimLSpaces(equal, equal);
3881 delete name; name = CopyString(equal); // property::name = equal;
3884 else if(!strcmpi(buffer, "Compiler Options"))
3885 strcpy(section, buffer);
3886 else if(!strcmpi(buffer, "IncludeDirs"))
3887 strcpy(subSection, buffer);
3888 else if(!strcmpi(buffer, "Linker Options"))
3889 strcpy(section, buffer);
3890 else if(!strcmpi(buffer, "LibraryDirs"))
3891 strcpy(subSection, buffer);
3892 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3899 equal = strstr(buffer, "=");
3903 TrimRSpaces(buffer, buffer);
3905 TrimLSpaces(equal, equal);
3906 if(!strcmpi(buffer, "Target Name"))
3907 options.targetFileName = /*CopyString(*/equal/*)*/;
3908 else if(!strcmpi(buffer, "Target Type"))
3910 if(!strcmpi(equal, "Executable"))
3911 options.targetType = executable;
3912 else if(!strcmpi(equal, "Shared"))
3913 options.targetType = sharedLibrary;
3914 else if(!strcmpi(equal, "Static"))
3915 options.targetType = staticLibrary;
3917 options.targetType = executable;
3919 else if(!strcmpi(buffer, "Target Directory"))
3920 options.targetDirectory = /*CopyString(*/equal/*)*/;
3921 else if(!strcmpi(buffer, "Console"))
3922 options.console = ParseTrueFalseValue(equal);
3923 else if(!strcmpi(buffer, "Libraries"))
3925 if(!options.libraries) options.libraries = { };
3926 ParseArrayValue(options.libraries, equal);
3928 else if(!strcmpi(buffer, "Intermediate Directory"))
3929 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3930 else if(!strcmpi(buffer, "Debug"))
3931 options.debug = ParseTrueFalseValue(equal);
3932 else if(!strcmpi(buffer, "Optimize"))
3934 if(!strcmpi(equal, "None"))
3935 options.optimization = none;
3936 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3937 options.optimization = speed;
3938 else if(!strcmpi(equal, "Size"))
3939 options.optimization = size;
3941 options.optimization = none;
3943 else if(!strcmpi(buffer, "Compress"))
3944 options.compress = ParseTrueFalseValue(equal);
3945 else if(!strcmpi(buffer, "Profile"))
3946 options.profile = ParseTrueFalseValue(equal);
3947 else if(!strcmpi(buffer, "AllWarnings"))
3948 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3949 else if(!strcmpi(buffer, "MemoryGuard"))
3950 options.memoryGuard = ParseTrueFalseValue(equal);
3951 else if(!strcmpi(buffer, "Default Name Space"))
3952 options.defaultNameSpace = CopyString(equal);
3953 else if(!strcmpi(buffer, "Strict Name Spaces"))
3954 options.strictNameSpaces = ParseTrueFalseValue(equal);
3955 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3957 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3958 ParseArrayValue(options.preprocessorDefinitions, equal);
3964 if(!options.targetDirectory && options.objectsDirectory)
3965 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3966 //if(!objDir.dir) objDir.dir = "obj";
3967 //if(!targetDir.dir) targetDir.dir = "";
3968 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3969 // if(!defaultNameSpace) property::defaultNameSpace = "";
3970 makingModified = true;
3973 Project LegacyAsciiLoadProject(File f, char * filePath)
3975 Project project = null;
3976 ProjectNode node = null;
3978 char parentPath[MAX_LOCATION];
3979 char section[128] = "";
3980 char subSection[128] = "";
3982 bool configurationsPresent = false;
3992 f.GetLine(buffer, 65536 - 1);
3993 TrimLSpaces(buffer, buffer);
3994 TrimRSpaces(buffer, buffer);
3997 if(buffer[0] == '-' || buffer[0] == '=')
3999 bool simple = buffer[0] == '-';
4002 TrimLSpaces(equal, equal);
4003 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
4005 if(!project.config.options.libraryDirs)
4006 project.config.options.libraryDirs = { [ CopyString(equal) ] };
4008 project.config.options.libraryDirs.Add(CopyString(equal));
4010 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
4012 if(!project.config.options.includeDirs)
4013 project.config.options.includeDirs = { [ CopyString(equal) ] };
4015 project.config.options.includeDirs.Add(CopyString(equal));
4017 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4019 len = strlen(equal);
4022 char temp[MAX_LOCATION];
4023 ProjectNode child { };
4024 // We don't need to do this anymore, fileName is just a property that sets name & path
4025 // child.fileName = CopyString(equal);
4028 child.name = CopyString(equal);
4029 child.path = CopyString(parentPath);
4033 GetLastDirectory(equal, temp);
4034 child.name = CopyString(temp);
4035 StripLastDirectory(equal, temp);
4036 child.path = CopyString(temp);
4038 child.nodeType = file;
4039 child.parent = parent;
4040 child.indent = parent.indent + 1;
4042 child.icon = NodeIcons::SelectFileIcon(child.name);
4043 parent.files.Add(child);
4049 StripLastDirectory(parentPath, parentPath);
4050 parent = parent.parent;
4054 else if(buffer[0] == '+')
4058 TrimLSpaces(equal, equal);
4059 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4061 char temp[MAX_LOCATION];
4062 ProjectNode child { };
4063 // NEW: Folders now have a path set like files
4064 child.name = CopyString(equal);
4065 strcpy(temp, parentPath);
4066 PathCatSlash(temp, child.name);
4067 child.path = CopyString(temp);
4069 child.parent = parent;
4070 child.indent = parent.indent + 1;
4071 child.type = folder;
4072 child.nodeType = folder;
4074 child.icon = folder;
4075 PathCatSlash(parentPath, child.name);
4076 parent.files.Add(child);
4081 else if(!strcmpi(section, "Configurations"))
4083 ProjectConfig newConfig
4085 makingModified = true;
4089 LegacyProjectConfigLoad(newConfig, f);
4090 project.configurations.Add(newConfig);
4093 else if(!strcmpi(buffer, "ECERE Project File"));
4094 else if(!strcmpi(buffer, "Version 0a"))
4095 ; //strcpy(version, "0a");
4096 else if(!strcmpi(buffer, "Version 0.1a"))
4097 ; //strcpy(version, "0.1a");
4098 else if(!strcmpi(buffer, "Configurations"))
4100 project.configurations.Free();
4101 project.config = null;
4102 strcpy(section, buffer);
4103 configurationsPresent = true;
4105 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
4107 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
4108 char topNodePath[MAX_LOCATION];
4109 // newConfig.defaultNameSpace = "";
4110 //newConfig.objDir.dir = "obj";
4111 //newConfig.targetDir.dir = "";
4112 project = Project { /*options = { }*/ };
4113 project.configurations = { [ newConfig ] };
4114 project.config = newConfig;
4115 // if(project.topNode.path) delete project.topNode.path;
4116 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4117 MakeSlashPath(topNodePath);
4118 PathCatSlash(topNodePath, filePath);
4119 project.filePath = topNodePath;
4120 parentPath[0] = '\0';
4121 parent = project.topNode;
4123 strcpy(section, "Target");
4128 if(equal[0] == '\"')
4130 StripQuotes(equal, equal);
4131 delete project.moduleName; project.moduleName = CopyString(equal);
4135 else if(!strcmpi(buffer, "Compiler Options"));
4136 else if(!strcmpi(buffer, "IncludeDirs"))
4137 strcpy(subSection, buffer);
4138 else if(!strcmpi(buffer, "Linker Options"));
4139 else if(!strcmpi(buffer, "LibraryDirs"))
4140 strcpy(subSection, buffer);
4141 else if(!strcmpi(buffer, "Files"))
4143 strcpy(section, "Target");
4144 strcpy(subSection, buffer);
4146 else if(!strcmpi(buffer, "Resources"))
4148 ProjectNode child { };
4149 parent.files.Add(child);
4150 child.parent = parent;
4151 child.indent = parent.indent + 1;
4152 child.name = CopyString(buffer);
4153 child.path = CopyString("");
4154 child.type = resources;
4156 child.icon = archiveFile;
4157 project.resNode = child;
4160 strcpy(subSection, buffer);
4164 equal = strstr(buffer, "=");
4168 TrimRSpaces(buffer, buffer);
4170 TrimLSpaces(equal, equal);
4172 if(!strcmpi(section, "Target"))
4174 if(!strcmpi(buffer, "Build Exclusions"))
4176 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4178 /*if(node && node.type != NodeTypes::project)
4179 ParseListValue(node.buildExclusions, equal);*/
4182 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4184 delete project.resNode.path;
4185 project.resNode.path = CopyString(equal);
4186 PathCatSlash(parentPath, equal);
4190 else if(!strcmpi(buffer, "Intermediate Directory"))
4191 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4192 else if(!strcmpi(buffer, "Debug"))
4193 project.config.options.debug = ParseTrueFalseValue(equal);
4194 else if(!strcmpi(buffer, "Optimize"))
4196 if(!strcmpi(equal, "None"))
4197 project.config.options.optimization = none;
4198 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4199 project.config.options.optimization = speed;
4200 else if(!strcmpi(equal, "Size"))
4201 project.config.options.optimization = size;
4203 project.config.options.optimization = none;
4205 else if(!strcmpi(buffer, "Profile"))
4206 project.config.options.profile = ParseTrueFalseValue(equal);
4207 else if(!strcmpi(buffer, "MemoryGuard"))
4208 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4211 if(!project.options) project.options = { };
4213 // Project Wide Settings (All configs)
4214 if(!strcmpi(buffer, "Target Name"))
4215 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4216 else if(!strcmpi(buffer, "Target Type"))
4218 if(!strcmpi(equal, "Executable"))
4219 project.options.targetType = executable;
4220 else if(!strcmpi(equal, "Shared"))
4221 project.options.targetType = sharedLibrary;
4222 else if(!strcmpi(equal, "Static"))
4223 project.options.targetType = staticLibrary;
4225 project.options.targetType = executable;
4227 else if(!strcmpi(buffer, "Target Directory"))
4228 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4229 else if(!strcmpi(buffer, "Console"))
4230 project.options.console = ParseTrueFalseValue(equal);
4231 else if(!strcmpi(buffer, "Libraries"))
4233 if(!project.options.libraries) project.options.libraries = { };
4234 ParseArrayValue(project.options.libraries, equal);
4236 else if(!strcmpi(buffer, "AllWarnings"))
4237 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4238 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4240 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4242 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4243 ParseListValue(node.preprocessorDefs, equal);*/
4247 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4248 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4259 SplitPlatformLibraries(project);
4261 if(configurationsPresent)
4262 CombineIdenticalConfigOptions(project);
4266 void SplitPlatformLibraries(Project project)
4268 if(project && project.configurations)
4270 for(cfg : project.configurations)
4272 if(cfg.options.libraries && cfg.options.libraries.count)
4274 Iterator<String> it { cfg.options.libraries };
4278 char * platformName = strstr(l, ":");
4281 PlatformOptions platform = null;
4283 if(!cfg.platforms) cfg.platforms = { };
4284 for(p : cfg.platforms)
4286 if(!strcmpi(platformName, p.name))
4294 platform = { name = CopyString(platformName), options = { libraries = { } } };
4295 cfg.platforms.Add(platform);
4297 *(platformName-1) = 0;
4298 platform.options.libraries.Add(CopyString(l));
4300 cfg.options.libraries.Delete(it.pointer);
4309 void CombineIdenticalConfigOptions(Project project)
4311 if(project && project.configurations && project.configurations.count)
4314 ProjectOptions nullOptions { };
4315 ProjectConfig firstConfig = null;
4316 for(cfg : project.configurations)
4318 if(cfg.options.targetType != staticLibrary)
4325 firstConfig = project.configurations.firstIterator.data;
4327 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4329 if(!member.isProperty)
4331 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4336 for(cfg : project.configurations)
4338 if(cfg != firstConfig)
4340 if(cfg.options.targetType != staticLibrary)
4344 if(type.type == noHeadClass || type.type == normalClass)
4346 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4347 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4348 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4352 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4353 (byte *)firstConfig.options + member.offset + member._class.offset,
4354 (byte *)cfg.options + member.offset + member._class.offset);
4366 if(type.type == noHeadClass || type.type == normalClass)
4368 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4369 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4370 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4375 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4376 (byte *)firstConfig.options + member.offset + member._class.offset,
4377 (byte *)nullOptions + member.offset + member._class.offset))
4381 if(!project.options) project.options = { };
4383 /*if(type.type == noHeadClass || type.type == normalClass)
4385 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4386 (byte *)project.options + member.offset + member._class.offset,
4387 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4391 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4392 // TOFIX: ListBox::SetData / OnCopy mess
4393 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4394 (byte *)project.options + member.offset + member._class.offset,
4395 (type.typeSize > 4) ? address :
4396 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4397 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4398 (void *)*(byte *)address )));
4401 (byte *)project.options + member.offset + member._class.offset,
4402 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4404 for(cfg : project.configurations)
4406 if(cfg.options.targetType == staticLibrary)
4410 if(type.type == noHeadClass || type.type == normalClass)
4412 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4413 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4414 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4418 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4419 (byte *)firstConfig.options + member.offset + member._class.offset,
4420 (byte *)cfg.options + member.offset + member._class.offset);
4425 if(cfg != firstConfig)
4427 if(type.type == noHeadClass || type.type == normalClass)
4429 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4430 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4434 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4435 (byte *)cfg.options + member.offset + member._class.offset);
4437 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4440 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4447 // Compare Platform Specific Settings
4450 for(cfg : project.configurations)
4452 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4453 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4459 if(same && firstConfig.platforms)
4461 for(cfg : project.configurations)
4463 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4465 if(cfg != firstConfig)
4467 cfg.platforms.Free();
4468 delete cfg.platforms;
4471 project.platforms = firstConfig.platforms;
4472 firstConfig.platforms = null;
4476 // Static libraries can't contain libraries
4477 for(cfg : project.configurations)
4479 if(cfg.options.targetType == staticLibrary)
4481 if(!cfg.options.libraries) cfg.options.libraries = { };
4482 cfg.options.libraries.Free();
4488 Project LoadProject(char * filePath, char * activeConfigName)
4490 Project project = null;
4491 File f = FileOpen(filePath, read);
4494 project = LegacyBinaryLoadProject(f, filePath);
4497 JSONParser parser { f = f };
4498 JSONResult result = parser.GetObject(class(Project), &project);
4501 char insidePath[MAX_LOCATION];
4503 delete project.topNode.files;
4504 if(!project.files) project.files = { };
4505 project.topNode.files = project.files;
4508 char topNodePath[MAX_LOCATION];
4509 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4510 MakeSlashPath(topNodePath);
4511 PathCatSlash(topNodePath, filePath);
4512 project.filePath = topNodePath;//filePath;
4515 project.topNode.FixupNode(insidePath);
4517 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4518 delete project.resNode.path;
4519 project.resNode.path = project.resourcesPath;
4520 project.resourcesPath = null;
4521 project.resNode.nodeType = (ProjectNodeType)-1;
4522 delete project.resNode.files;
4523 project.resNode.files = project.resources;
4524 project.files = null;
4525 project.resources = null;
4526 if(!project.configurations) project.configurations = { };
4528 project.resNode.FixupNode(insidePath);
4533 project = LegacyAsciiLoadProject(f, filePath);
4539 if(!project.options) project.options = { };
4540 if(activeConfigName && activeConfigName[0] && project.configurations)
4541 project.config = project.GetConfig(activeConfigName);
4542 if(!project.config && project.configurations)
4543 project.config = project.configurations.firstIterator.data;
4545 if(!project.resNode)
4547 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4550 if(!project.moduleName)
4551 project.moduleName = CopyString(project.name);
4552 if(project.config &&
4553 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4554 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4556 //delete project.config.options.targetFileName;
4558 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4559 project.config.options.optimization = none;
4560 project.config.options.debug = true;
4561 //project.config.options.warnings = unset;
4562 project.config.options.memoryGuard = false;
4563 project.config.compilingModified = true;
4564 project.config.linkingModified = true;
4566 else if(!project.topNode.name && project.config)
4568 project.topNode.name = CopyString(project.config.options.targetFileName);
4571 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4572 project.topNode.configurations = project.configurations;
4573 project.topNode.platforms = project.platforms;
4574 project.topNode.options = project.options;*/