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 void ReplaceSpaces(char * output, char * source)
423 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
425 if(ch == ' ') output[dc++] = '\\';
426 if(ch == '\"') output[dc++] = '\\';
427 if(ch == '&') output[dc++] = '\\';
430 if(ch == '(' || ch == ')') output[dc++] = '\\';
440 // This function cannot accept same pointer for source and output
441 void ReplaceUnwantedMakeChars(char * output, char * source)
444 char * s = source, * d = output;
450 if(s != source && *(s-1) == '$')
462 else if(ch == '$' && *(s+1) != '(')
472 static void OutputNoSpace(File f, char * source)
474 char * output = new char[strlen(source)+1024];
475 ReplaceSpaces(output, source);
480 enum ListOutputMethod { inPlace, newLine, lineEach };
482 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
485 const int breakListLength = 1536;
486 const int breakLineLength = 78; // TODO: turn this into an option.
488 int c, len, itemCount = 0;
489 Array<int> breaks { };
493 MapNode<String, int> mn;
494 for(c=0; c<list.count; c++)
496 len = strlen(list[c]) + 3;
497 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
499 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
501 if(strstr(list[c], mn.key))
505 if(charCount + len > breakListLength)
507 breaks.Add(itemCount);
515 breaks.Add(itemCount);
516 numOfBreaks = breaks.count;
521 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
522 for(c=0; c<numOfBreaks; c++)
523 f.Printf(" $(%s%d)", name, c+1);
527 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
533 for(c=0; c<numOfBreaks; c++)
536 f.Printf("%s%d =", name, c+1);
539 itemCount = breaks[c];
540 for(n=offset; n<offset+itemCount; n++)
542 if(false) // TODO: turn this into an option.
544 int itemLen = strlen(list[n]);
545 if(len > 3 && len + itemLen > breakLineLength)
547 f.Printf(" \\\n\t%s", list[n]);
553 f.Printf(" %s", list[n]);
557 f.Printf(" \\\n\t%s", list[n]);
572 void OutputLinkObjectActions(File f, char * name, int parts)
577 for(c=0; c<parts; c++)
578 f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
580 f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
584 void OutputCleanActions(File f, char * name, int parts)
589 for(c=0; c<parts; c++)
590 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
593 f.Printf("\t$(call rmq,$(%s))\n", name);
596 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace, bool noDash)
600 if(method == newLine)
604 if(method == lineEach)
606 f.Printf(" %s%s", noDash ? "" : "-", option);
608 OutputNoSpace(f, item);
610 f.Printf("%s", item);
615 void StringNoSpaceToDynamicString(DynamicString s, char * path)
617 char * output = new char[strlen(path)+1024];
618 ReplaceSpaces(output, path);
623 static void OutputLibraries(File f, Array<String> libraries)
625 for(item : libraries)
627 char ext[MAX_EXTENSION];
628 char temp[MAX_LOCATION];
630 bool usedFunction = false;
631 GetExtension(item, ext);
632 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
636 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
638 if(!strncmp(item, "lib", 3))
639 strcpy(temp, item + 3);
642 StripExtension(temp);
645 f.Puts(" \\\n\t$(call _L,");
654 void CamelCase(char * string)
656 int c, len = strlen(string);
657 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
658 string[c] = (char)tolower(string[c]);
661 CompilerConfig GetCompilerConfig()
663 #ifndef MAKEFILE_GENERATOR
664 CompilerConfig compiler = null;
665 if(ide && ide.workspace)
666 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
669 incref defaultCompiler;
670 return defaultCompiler;
674 define localTargetType = config && config.options && config.options.targetType ?
675 config.options.targetType : options && options.targetType ?
676 options.targetType : TargetTypes::executable;
677 define localWarnings = config && config.options && config.options.warnings ?
678 config.options.warnings : options && options.warnings ?
679 options.warnings : WarningsOption::unset;
680 define localDebug = config && config.options && config.options.debug ?
681 config.options.debug : options && options.debug ?
682 options.debug : SetBool::unset;
683 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
684 config.options.memoryGuard : options && options.memoryGuard ?
685 options.memoryGuard : SetBool::unset;
686 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
687 config.options.noLineNumbers : options && options.noLineNumbers ?
688 options.noLineNumbers : SetBool::unset;
689 define localProfile = config && config.options && config.options.profile ?
690 config.options.profile : options && options.profile ?
691 options.profile : SetBool::unset;
692 define localOptimization = config && config.options && config.options.optimization ?
693 config.options.optimization : options && options.optimization ?
694 options.optimization : OptimizationStrategy::none;
695 define localFastMath = config && config.options && config.options.fastMath ?
696 config.options.fastMath : options && options.fastMath ?
697 options.fastMath : SetBool::unset;
698 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
699 config.options.defaultNameSpace : options && options.defaultNameSpace ?
700 options.defaultNameSpace : null;
701 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
702 config.options.strictNameSpaces : options && options.strictNameSpaces ?
703 options.strictNameSpaces : SetBool::unset;
704 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
705 define localTargetFileName = config && config.options && config.options.targetFileName ?
706 config.options.targetFileName : options && options.targetFileName ?
707 options.targetFileName : "";
708 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
709 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
710 options.targetDirectory : null;
711 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
712 ideSettings.projectDefaultIntermediateObjDir[0] ?
713 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
714 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
715 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
716 options.objectsDirectory : null;
717 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
718 ideSettings.projectDefaultIntermediateObjDir[0] ?
719 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
720 define localConsole = config && config.options && config.options.console ?
721 config.options.console : options && options.console ?
722 options.console : SetBool::unset;
723 define localCompress = config && config.options && config.options.compress ?
724 config.options.compress : options && options.compress ?
725 options.compress : SetBool::unset;
727 define platformTargetType =
728 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
729 configPOs.options.targetType :
730 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
731 projectPOs.options.targetType : TargetTypes::unset;
734 char * PlatformToMakefileTargetVariable(Platform platform)
736 return platform == win32 ? "WINDOWS_TARGET" :
737 platform == tux ? "LINUX_TARGET" :
738 platform == apple ? "OSX_TARGET" :
742 char * TargetTypeToMakefileVariable(TargetTypes targetType)
744 return targetType == executable ? "executable" :
745 targetType == sharedLibrary ? "sharedlib" :
746 targetType == staticLibrary ? "staticlib" :
750 // Move this to ProjectConfig? null vs Common to consider...
751 char * GetConfigName(ProjectConfig config)
753 return config ? config.name : "Common";
756 public enum SingleFileCompileMode
758 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
760 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
763 class Project : struct
765 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
766 // We might want to tweak this default behavior of regular classes ?
767 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
772 property char * moduleVersion
774 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
775 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
776 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
779 property char * description
781 set { delete description; if(value && value[0]) description = CopyString(value); }
782 get { return description ? description : ""; }
783 isset { return description != null && description[0]; }
786 property char * license
788 set { delete license; if(value && value[0]) license = CopyString(value); }
789 get { return license ? license : ""; }
790 isset { return license != null && license[0]; }
793 property char * compilerConfigsDir
795 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
796 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
797 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
800 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
801 property Array<PlatformOptions> platforms
803 get { return platforms; }
806 if(platforms) { platforms.Free(); delete platforms; }
809 List<PlatformOptions> empty { };
810 Iterator<PlatformOptions> it { value };
812 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
813 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
823 if(p.options && !p.options.isEmpty)
830 List<ProjectConfig> configurations;
831 LinkList<ProjectNode> files;
832 String resourcesPath;
833 LinkList<ProjectNode> resources;
836 // topNode.name holds the file name (.epj)
837 ProjectOptions options;
838 Array<PlatformOptions> platforms;
839 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
842 ProjectConfig config;
844 // This is the file name stripped of the epj extension
845 // It should NOT be edited, saved or loaded anywhere
850 String compilerConfigsDir;
851 String moduleVersion;
853 String lastBuildConfigName;
854 String lastBuildCompilerName;
856 Map<String, NameCollisionInfo> lastBuildNamesInfo;
858 #ifndef MAKEFILE_GENERATOR
859 FileMonitor fileMonitor
861 this, FileChange { modified = true };
862 bool OnFileNotify(FileChange action, char * param)
864 fileMonitor.StopMonitoring();
865 if(OnProjectModified(action, param))
866 fileMonitor.StartMonitoring();
871 bool StartMonitoring()
873 fileMonitor.fileName = filePath;
874 fileMonitor.StartMonitoring();
878 bool StopMonitoring()
880 fileMonitor.StopMonitoring();
884 bool OnProjectModified(FileChange fileChange, char * param)
887 sprintf(temp, $"The project %s was modified by another application.\n"
888 "Would you like to reload it and lose your changes?", name);
889 if(MessageBox { type = yesNo, master = ide,
890 text = $"Project has been modified", contents = temp }.Modal() == yes)
892 Project project = LoadProject(filePath, config.name);
895 ProjectView projectView = ide.projectView;
896 DataRow prev = topNode.row ? topNode.row.previous : null;
897 FileMonitor fm = fileMonitor;
898 bool confirmation = true;
902 if(projectView.projectSettingsDialog)
904 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
906 projectView.projectSettingsDialog.Destroy(0);
909 projectView.DeleteNode(topNode);
916 topNode.project = this;
920 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
921 projectView.AddNode(topNode, null);
922 topNode.row.Move(prev);
924 projectView.ShowOutputBuildLog(true);
925 projectView.DisplayCompiler(compiler, false);
926 projectView.ProjectUpdateMakefileForAllConfigs(this);
929 eSystem_Delete(project);
941 // This frees contents without freeing the instance
942 // For use from destructor and for file monitor reloading
943 // (To work around JSON loader (LoadProject) always returning a new instance)
946 if(platforms) { platforms.Free(); delete platforms; }
947 if(configurations) { configurations.Free(); delete configurations; }
948 if(files) { files.Free(); delete files; }
949 if(resources) { resources.Free(); delete resources; }
951 delete resourcesPath;
955 delete compilerConfigsDir;
957 delete moduleVersion;
961 delete lastBuildConfigName;
962 delete lastBuildCompilerName;
963 if(lastBuildNamesInfo) { lastBuildNamesInfo.Free(); delete lastBuildNamesInfo; }
968 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
969 topNode.configurations = null;
970 topNode.platforms = null;
971 topNode.options = null;
976 property ProjectConfig config
982 topNode.info = CopyString(GetConfigName(config));
986 property char * filePath
992 char string[MAX_LOCATION];
993 GetLastDirectory(value, string);
995 topNode.name = CopyString(string);
996 StripExtension(string);
998 name = CopyString(string);
999 StripLastDirectory(value, string);
1000 delete topNode.path;
1001 topNode.path = CopyString(string);
1003 filePath = CopyString(value);
1008 ProjectConfig GetConfig(char * configName)
1010 ProjectConfig result = null;
1011 if(configName && configName[0] && configurations.count)
1013 for(cfg : configurations; !strcmpi(cfg.name, configName))
1022 ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
1025 if(!lastBuildNamesInfo)
1026 ProjectLoadLastBuildNamesInfo(this, config);
1027 result = topNode.FindByObjectFileName(fileName, type, dotMain, lastBuildNamesInfo);
1031 TargetTypes GetTargetType(ProjectConfig config)
1033 TargetTypes targetType = localTargetType;
1037 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1040 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1042 PlatformOptions projectPOs, configPOs;
1043 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1044 if(platformTargetType)
1050 char * GetObjDirExpression(ProjectConfig config)
1052 // TODO: Support platform options
1053 char * expression = localObjectsDirectory;
1055 expression = settingsObjectsDirectory;
1059 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1061 char * expression = GetObjDirExpression(config);
1062 DirExpression objDir { type = intermediateObjectsDir };
1063 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1067 char * GetTargetDirExpression(ProjectConfig config)
1069 // TODO: Support platform options
1070 char * expression = localTargetDirectory;
1072 expression = settingsTargetDirectory;
1076 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1078 char * expression = GetTargetDirExpression(config);
1079 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1080 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1084 WarningsOption GetWarnings(ProjectConfig config)
1086 WarningsOption warnings = localWarnings;
1090 bool GetDebug(ProjectConfig config)
1092 SetBool debug = localDebug;
1093 return debug == true;
1096 bool GetMemoryGuard(ProjectConfig config)
1098 SetBool memoryGuard = localMemoryGuard;
1099 return memoryGuard == true;
1102 bool GetNoLineNumbers(ProjectConfig config)
1104 SetBool noLineNumbers = localNoLineNumbers;
1105 return noLineNumbers == true;
1108 bool GetProfile(ProjectConfig config)
1110 SetBool profile = localProfile;
1111 return profile == true;
1114 OptimizationStrategy GetOptimization(ProjectConfig config)
1116 OptimizationStrategy optimization = localOptimization;
1117 return optimization;
1120 bool GetFastMath(ProjectConfig config)
1122 SetBool fastMath = localFastMath;
1123 return fastMath == true;
1126 String GetDefaultNameSpace(ProjectConfig config)
1128 String defaultNameSpace = localDefaultNameSpace;
1129 return defaultNameSpace;
1132 bool GetStrictNameSpaces(ProjectConfig config)
1134 SetBool strictNameSpaces = localStrictNameSpaces;
1135 return strictNameSpaces == true;
1138 String GetTargetFileName(ProjectConfig config)
1140 String targetFileName = localTargetFileName;
1141 return targetFileName;
1144 //String targetDirectory;
1145 //String objectsDirectory;
1146 bool GetConsole(ProjectConfig config)
1148 SetBool console = localConsole;
1149 return console == true;
1152 bool GetCompress(ProjectConfig config)
1154 SetBool compress = localCompress;
1155 return compress == true;
1157 //SetBool excludeFromBuild;
1159 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1161 #ifndef MAKEFILE_GENERATOR
1162 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1166 bool GetConfigIsInDebugSession(ProjectConfig config)
1168 #ifndef MAKEFILE_GENERATOR
1169 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1173 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1175 #ifndef MAKEFILE_GENERATOR
1176 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1180 #ifndef MAKEFILE_GENERATOR
1181 bool Save(char * fileName)
1184 /*char output[MAX_LOCATION];
1185 ChangeExtension(fileName, "json", output);
1186 f = FileOpen(output, write);*/
1187 f = FileOpen(fileName, write);
1190 files = topNode.files;
1191 resources = resNode.files;
1192 resourcesPath = resNode.path;
1194 files.Remove(resNode);
1197 WriteJSONObject(f, class(Project), this, 0);
1203 resourcesPath = null;
1210 // This method is only called from Debugger, should be moved to Debugger class?
1211 #ifndef MAKEFILE_GENERATOR
1212 bool GetRelativePath(char * filePath, char * relativePath)
1215 char moduleName[MAX_FILENAME];
1216 GetLastDirectory(filePath, moduleName);
1217 // try with workspace dir first?
1218 if((node = topNode.Find(moduleName, false)))
1220 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1221 PathCatSlash(relativePath, node.name);
1226 // Tweak for automatically resolving symbol loader modules
1227 char * sl = strstr(moduleName, ".main.ec");
1228 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1230 char objDir[MAX_LOCATION];
1231 DirExpression objDirExp;
1232 CompilerConfig compiler = ide.debugger.currentCompiler;
1233 ProjectConfig config = ide.debugger.prjConfig;
1234 int bitDepth = ide.debugger.bitDepth;
1235 // This is not perfect, as multiple source files exist for the symbol loader module...
1236 // We try to set it in the debug config object directory.
1237 if(!compiler || !config)
1239 // If we're not currently debugging, set a breakpoint in the active compiler/config
1240 compiler = GetCompilerConfig();
1241 config = this.config;
1242 // If the current config is not debuggable, set it in the first debuggable config found
1243 if(config && !config.options.debug)
1245 for(c : configurations; c.options.debug)
1252 objDirExp = GetObjDir(compiler, config, bitDepth);
1253 strcpy(objDir, objDirExp.dir);
1255 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1256 ReplaceSpaces(relativePath, objDir);
1258 PathCatSlash(relativePath, moduleName);
1262 // WARNING: On failure, relative path is uninitialized
1267 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1269 TargetTypes targetType = GetTargetType(config);
1270 String targetFileName = GetTargetFileName(config);
1271 if(targetType == staticLibrary)
1273 PathCatSlash(string, "lib");
1274 strcat(string, targetFileName);
1276 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1278 PathCatSlash(string, "lib");
1279 strcat(string, targetFileName);
1282 PathCatSlash(string, targetFileName);
1287 if(compiler.targetPlatform == win32)
1288 strcat(string, ".exe");
1291 if(compiler.targetPlatform == win32)
1292 strcat(string, ".dll");
1293 else if(compiler.targetPlatform == apple)
1294 strcat(string, ".dylib");
1296 strcat(string, ".so");
1297 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1299 strcat(string, ".");
1300 strcat(string, moduleVersion);
1304 strcat(string, ".a");
1309 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1311 bool result = false;
1312 char temp[MAX_LOCATION];
1313 strcpy(cfDir, topNode.path);
1314 if(compilerConfigsDir && compilerConfigsDir[0])
1316 PathCatSlash(cfDir, compilerConfigsDir);
1321 strcpy(temp, cfDir);
1322 // Using a relative path makes it less likely to run into spaces issues
1323 // Even with escaped spaces, there still seems to be issues including a config file
1324 // in a path containing spaces
1326 MakePathRelative(temp, topNode.path, cfDir);
1329 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1333 strcpy(temp, cfDir);
1334 ReplaceSpaces(cfDir, temp);
1339 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1341 char temp[MAX_LOCATION];
1342 bool result = false;
1343 strcpy(cfDir, topNode.path);
1344 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1346 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1351 // Default to <ProjectDir>/.configs if unset
1352 PathCatSlash(cfDir, ".configs");
1357 strcpy(temp, cfDir);
1358 // Using a relative path makes it less likely to run into spaces issues
1359 // Even with escaped spaces, there still seems to be issues including a config file
1360 // in a path containing spaces
1361 if(IsPathInsideOf(cfDir, topNode.path))
1362 MakePathRelative(temp, topNode.path, cfDir);
1364 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1368 strcpy(temp, cfDir);
1369 ReplaceSpaces(cfDir, temp);
1374 void CatMakeFileName(char * string, ProjectConfig config)
1376 char projectName[MAX_LOCATION];
1377 strcpy(projectName, name);
1378 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1381 #ifndef MAKEFILE_GENERATOR
1382 void MarkChanges(ProjectNode node)
1384 for(cfg : topNode.configurations)
1386 ProjectConfig c = null;
1387 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1389 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1390 (!c.options || !cfg.options)))
1391 cfg.symbolGenModified = true;
1392 if(c && ((c.options && cfg.options &&
1393 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1394 || (!c.options || !cfg.options)))
1395 cfg.linkingModified = true;
1397 cfg.makingModified = true;
1401 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1403 for(cfg : configurations)
1406 cfg.makingModified = true;
1408 cfg.compilingModified = true;
1410 cfg.linkingModified = true;
1412 cfg.symbolGenModified = true;
1414 if(compiling || linking)
1416 ide.projectView.modifiedDocument = true;
1417 ide.workspace.modified = true;
1421 void RotateActiveConfig(bool forward)
1423 if(configurations.first && configurations.last != configurations.first)
1425 Iterator<ProjectConfig> cfg { configurations };
1426 while(forward ? cfg.Next() : cfg.Prev())
1427 if(cfg.data == config)
1441 property::config = cfg.data;
1442 ide.UpdateToolBarActiveConfigs(true);
1443 ide.workspace.modified = true;
1444 ide.projectView.Update(null);
1448 bool ProcessPipeOutputRaw(DualPipe f)
1451 while(!f.Eof() && !ide.projectView.stopBuild)
1454 double lastTime = GetTime();
1458 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1460 ide.outputView.buildBox.Logf("%s\n", line);
1462 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1464 //printf("Processing Input...\n");
1465 if(app.ProcessInput(true))
1467 app.UpdateDisplay();
1470 //printf("Waiting...\n");
1473 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1475 if(ide.projectView.stopBuild)
1477 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1480 return !ide.projectView.stopBuild;
1483 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
1484 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1487 bool compiling = false, linking = false, precompiling = false;
1488 int compilingEC = 0;
1489 int numErrors = 0, numWarnings = 0;
1490 bool loggedALine = false;
1491 int lenMakeCommand = strlen(compiler.makeCommand);
1494 char moduleName[MAX_FILENAME];
1495 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1497 DynamicString test { };
1498 DynamicString ecp { };
1499 DynamicString ecc { };
1500 DynamicString ecs { };
1501 DynamicString ear { };
1502 DynamicString prefix { };
1503 DynamicString cpp { };
1504 DynamicString cc { };
1505 DynamicString cxx { };
1506 DynamicString strip { };
1507 DynamicString ar { };
1508 DynamicString windres { };
1510 if(bitDepth == 64 && compiler.targetPlatform == win32)
1511 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1512 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1513 gnuToolchainPrefix = "i686-w64-mingw32-";
1515 ecp.concatx(compiler.ecpCommand, " ");
1516 ecc.concatx(compiler.eccCommand, " ");
1517 ecs.concatx(compiler.ecsCommand, " ");
1518 ear.concatx(compiler.earCommand, " ");
1521 compiler.ccacheEnabled ? "ccache " : "",
1522 compiler.distccEnabled ? "distcc " : "",
1523 gnuToolchainPrefix);
1525 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1526 cc.concatx((String)prefix, compiler.ccCommand, " ");
1527 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1529 strip.concatx(gnuToolchainPrefix, "strip ");
1530 ar.concatx(gnuToolchainPrefix, "ar rcs");
1531 windres.concatx(gnuToolchainPrefix, "windres ");
1533 testLen = Max(testLen, ecp.size);
1534 testLen = Max(testLen, ecc.size);
1535 testLen = Max(testLen, ecs.size);
1536 testLen = Max(testLen, ear.size);
1537 testLen = Max(testLen, cpp.size);
1538 testLen = Max(testLen, cc.size);
1539 testLen = Max(testLen, cxx.size);
1540 testLen = Max(testLen, strip.size);
1541 testLen = Max(testLen, ar.size);
1542 testLen = Max(testLen, windres.size);
1543 testLen = Max(testLen, strlen("mkdir "));
1546 while(!f.Eof() && !ide.projectView.stopBuild)
1549 double lastTime = GetTime();
1553 //printf("Peeking and GetLine...\n");
1554 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1556 char * message = null;
1557 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1558 char * from = strstr(line, stringFrom);
1559 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1560 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1562 char * module = strstr(line, "No rule to make target `");
1566 module = strchr(module, '`') + 1;
1567 end = strchr(module, '\'');
1571 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1572 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1578 //ide.outputView.buildBox.Logf("error: %s\n", line);
1582 else if(strstr(test, "mkdir ") == test);
1583 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1584 else if(strstr(test, ear) == test);
1585 else if(strstr(test, strip) == test);
1586 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1589 bool isPrecomp = false;
1592 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1594 module = strstr(line, " -c ");
1595 if(module) module += 4;
1598 else if(strstr(test, ecc) == test)
1600 module = strstr(line, " -c ");
1601 if(module) module += 4;
1602 //module = line + 3;
1603 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1604 compilingEC = 3;//2;
1607 else if(strstr(test, ecp) == test)
1609 // module = line + 8;
1610 module = strstr(line, " -c ");
1611 if(module) module += 4;
1622 if(!compiling && !isPrecomp)
1624 ide.outputView.buildBox.Logf($"Compiling...\n");
1627 else if(!precompiling && isPrecomp)
1629 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1630 precompiling = true;
1632 // Changed escapeBackSlashes here to handle paths with spaces
1633 Tokenize(module, 1, tokens, true); // false);
1634 GetLastDirectory(module, moduleName);
1635 ide.outputView.buildBox.Logf("%s\n", moduleName);
1637 else if((module = strstr(line, " -o ")))
1640 precompiling = false;
1642 ide.outputView.buildBox.Logf($"Linking...\n");
1646 ide.outputView.buildBox.Logf("%s\n", line);
1647 if(strstr(line, "warning:") || strstr(line, "note:"))
1649 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1653 if(compilingEC) compilingEC--;
1655 else if(strstr(test, windres) == test)
1658 module = strstr(line, " ");
1659 if(module) module++;
1663 Tokenize(module, 1, tokens, true);
1664 GetLastDirectory(module, moduleName);
1665 ide.outputView.buildBox.Logf("%s\n", moduleName);
1668 else if(strstr(test, ar) == test)
1669 ide.outputView.buildBox.Logf($"Building library...\n");
1670 else if(strstr(test, ecs) == test)
1671 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1674 if(linking || compiling || precompiling)
1676 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1677 char * colon = strstr(start, ":"); //, * bracket;
1678 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1679 colon = strstr(colon + 1, ":");
1682 char * sayError = "";
1683 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1686 int len = (int)(colon - start);
1687 char ext[MAX_EXTENSION];
1688 len = Min(len, MAX_LOCATION-1);
1689 // Don't be mistaken by the drive letter colon
1691 // TODO: need to fix colon - line gives char *
1692 // warning: incompatible expression colon - line (char *); expected int
1694 strncpy(moduleName, line, (int)(colon - line));
1695 moduleName[colon - line] = '\0';
1697 strncpy(moduleName, start, len);
1698 moduleName[len] = '\0';
1699 // Remove stuff in brackets
1700 //bracket = strstr(moduleName, "(");
1701 //if(bracket) *bracket = '\0';
1703 GetLastDirectory(moduleName, temp);
1704 GetExtension(temp, ext);
1706 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1708 char * cColon = strstr(colon+1, ":");
1709 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1710 cColon = strstr(cColon + 1, ":");
1713 int len = (int)(cColon - (colon+1));
1714 char mName[MAX_LOCATION];
1715 len = Min(len, MAX_LOCATION-1);
1716 strncpy(mName, colon+1, len);
1718 GetLastDirectory(mName, temp);
1719 GetExtension(temp, ext);
1720 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1723 strcpy(moduleName, mName);
1727 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1730 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1732 message = $"Linker Message: ";
1738 message = $"Linker Error";
1741 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1745 if(!strstr(line, "error:"))
1747 message = $"Linker Error: ";
1753 strcpy(temp, topNode.path);
1754 PathCatSlash(temp, moduleName);
1755 MakePathRelative(temp, topNode.path, moduleName);
1757 error = strstr(line, "error:");
1758 if(!message && error && error > colon)
1762 // Silence warnings for compiled eC
1763 char * objDir = strstr(moduleName, objDirExp.dir);
1767 if((pointer = strstr(line, "undefined")) ||
1768 (pointer = strstr(line, "multiple definition")) ||
1769 (pointer = strstr(line, "No such file")) ||
1770 (pointer = strstr(line, "token")))
1772 strncat(moduleName, colon, pointer - colon);
1773 sayError = "error: ";
1778 else if((pointer = strstr(line, "No such file")))
1780 strncat(moduleName, colon, pointer - colon);
1781 sayError = "error: ";
1785 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1787 else if(strstr(line, "warning:"))
1793 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1794 /*else if(this == ide.workspace.projects.firstIterator.data)
1795 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1798 char fullModuleName[MAX_LOCATION];
1799 FileAttribs found = 0;
1800 Project foundProject = this;
1803 char * loc = strstr(moduleName, ":");
1805 strcpy(fullModuleName, topNode.path);
1806 PathCat(fullModuleName, moduleName);
1807 found = FileExists(fullModuleName);
1808 if(!found && !strcmp(ext, "c"))
1810 char ecName[MAX_LOCATION];
1811 ChangeExtension(fullModuleName, "ec", ecName);
1812 found = FileExists(ecName);
1816 char path[MAX_LOCATION];
1817 if(ide && ide.workspace)
1819 for(prj : ide.workspace.projects)
1822 MakePathRelative(fullModuleName, prj.topNode.path, path);
1824 if((node = prj.topNode.FindWithPath(path, false)))
1826 strcpy(fullModuleName, prj.topNode.path);
1827 PathCatSlash(fullModuleName, node.path);
1828 PathCatSlash(fullModuleName, node.name);
1829 found = FileExists(fullModuleName);
1837 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1839 for(prj : ide.workspace.projects)
1842 if((node = prj.topNode.Find(moduleName, false)))
1844 strcpy(fullModuleName, prj.topNode.path);
1845 PathCatSlash(fullModuleName, node.path);
1846 PathCatSlash(fullModuleName, node.name);
1847 found = FileExists(fullModuleName);
1860 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1861 MakeSystemPath(fullModuleName);
1864 strcpy(fullModuleName, moduleName);
1867 strcat(fullModuleName, ":");
1868 strcat(fullModuleName, loc + 1);
1872 fullModuleName[0] = 0;
1873 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1878 ide.outputView.buildBox.Logf("%s\n", line);
1879 linking = compiling = precompiling = false;
1883 ide.outputView.buildBox.Logf("%s\n", line);
1887 //printf("Done getting line\n");
1888 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1890 //printf("Processing Input...\n");
1891 if(app.ProcessInput(true))
1893 app.UpdateDisplay();
1896 //printf("Waiting...\n");
1899 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1901 if(ide.projectView.stopBuild)
1903 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1906 else if(loggedALine || !isARun)
1908 if(f.GetExitCode() && !numErrors)
1910 bool result = f.GetLine(line, sizeof(line)-1);
1911 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1917 char targetFileName[MAX_LOCATION];
1918 targetFileName[0] = '\0';
1919 CatTargetFileName(targetFileName, compiler, config);
1920 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1923 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1925 ide.outputView.buildBox.Logf($"no error, ");
1928 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1930 ide.outputView.buildBox.Logf($"no warning\n");
1946 return numErrors == 0 && !ide.projectView.stopBuild;
1949 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1952 int lenMakeCommand = strlen(compiler.makeCommand);
1957 double lastTime = GetTime();
1960 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1962 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1963 else if(strstr(line, "mkdir") == line);
1964 else if(strstr(line, "del") == line);
1965 else if(strstr(line, "rm") == line);
1966 else if(strstr(line, "Could Not Find") == line);
1969 ide.outputView.buildBox.Logf(line);
1970 ide.outputView.buildBox.Logf("\n");
1974 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1976 if(app.ProcessInput(true))
1978 app.UpdateDisplay();
1981 //Sleep(1.0 / PEEK_RESOLUTION);
1985 bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
1987 bool result = false;
1989 char targetFileName[MAX_LOCATION] = "";
1990 DynamicString makeTargets { };
1991 char makeFile[MAX_LOCATION];
1992 char makeFilePath[MAX_LOCATION];
1993 char configName[MAX_LOCATION];
1994 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
1995 PathBackup pathBackup { };
1996 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1997 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1999 bool eC_Debug = mode.eC_ToolsDebug;
2000 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2001 int numJobs = compiler.numJobs;
2002 char command[MAX_F_STRING*4];
2003 char * compilerName = CopyString(compiler.name);
2005 delete lastBuildConfigName;
2006 lastBuildConfigName = CopyString(config ? config.name : "Common");
2007 delete lastBuildCompilerName;
2008 lastBuildCompilerName = CopyString(compiler.name);
2009 ProjectLoadLastBuildNamesInfo(this, config);
2011 CamelCase(compilerName);
2013 strcpy(configName, config ? config.name : "Common");
2015 SetPath(false, compiler, config, bitDepth); //true
2016 CatTargetFileName(targetFileName, compiler, config);
2018 strcpy(makeFilePath, topNode.path);
2019 CatMakeFileName(makeFile, config);
2020 PathCatSlash(makeFilePath, makeFile);
2022 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2025 if(compiler.type.isVC)
2027 PrintLn("compiling a single file is not yet supported");
2032 char pushD[MAX_LOCATION];
2033 char cfDir[MAX_LOCATION];
2034 GetIDECompilerConfigsDir(cfDir, true, true);
2035 GetWorkingDir(pushD, sizeof(pushD));
2036 ChangeWorkingDir(topNode.path);
2037 // Create object dir if it does not exist already
2038 if(!FileExists(objDirExp.dir).isDirectory)
2040 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2041 compiler.makeCommand, cfDir,
2042 crossCompiling ? " TARGET_PLATFORM=" : "",
2044 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2045 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2047 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2049 ide.outputView.buildBox.Logf("%s\n", command);
2053 ChangeWorkingDir(pushD);
2055 for(node : onlyNodes)
2057 if(node.GetIsExcluded(config))
2058 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2062 node.DeleteIntermediateFiles(compiler, config, bitDepth, lastBuildNamesInfo, mode == cObject ? true : false);
2063 node.GetTargets(config, lastBuildNamesInfo, objDirExp.dir, makeTargets);
2069 if(compiler.type.isVC)
2071 bool result = false;
2072 char oldwd[MAX_LOCATION];
2073 GetWorkingDir(oldwd, sizeof(oldwd));
2074 ChangeWorkingDir(topNode.path);
2076 // TODO: support justPrint
2077 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2079 ide.outputView.buildBox.Logf("%s\n", command);
2080 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2082 ProcessPipeOutputRaw(f);
2086 ChangeWorkingDir(oldwd);
2088 else if(onlyNodes && strlen(makeTargets) == 0)
2090 ide.outputView.buildBox.Log("No targets to compile.\n");
2094 char cfDir[MAX_LOCATION];
2095 GetIDECompilerConfigsDir(cfDir, true, true);
2096 sprintf(command, "%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2097 compiler.makeCommand,
2098 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2100 crossCompiling ? " TARGET_PLATFORM=" : "",
2102 bitDepth ? " ARCH=" : "",
2103 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2104 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2105 compilerName, eC_Debug ? "--always-make " : "", numJobs,
2106 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2107 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2108 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2110 ide.outputView.buildBox.Logf("%s\n", command);
2112 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2120 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2126 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2129 ide.outputView.buildBox.Logf("%s\n", line);
2130 if(!error && !found && strstr(line, "echo ") == line)
2132 strcpy(command, line+5);
2135 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2137 strcpy(command, line);
2147 result = ProcessPipeOutputRaw(f);
2149 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config, bitDepth);
2152 ide.outputView.buildBox.Logf("%s\n", command);
2153 else if(justPrint && found)
2154 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2159 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2164 delete compilerName;
2169 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2171 char makeFile[MAX_LOCATION];
2172 char makeFilePath[MAX_LOCATION];
2173 char command[MAX_LOCATION];
2174 char * compilerName;
2176 PathBackup pathBackup { };
2177 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2178 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2180 compilerName = CopyString(compiler.name);
2181 CamelCase(compilerName);
2183 SetPath(false, compiler, config, bitDepth);
2185 strcpy(makeFilePath, topNode.path);
2186 CatMakeFileName(makeFile, config);
2187 PathCatSlash(makeFilePath, makeFile);
2189 if(compiler.type.isVC)
2191 bool result = false;
2192 char oldwd[MAX_LOCATION];
2193 GetWorkingDir(oldwd, sizeof(oldwd));
2194 ChangeWorkingDir(topNode.path);
2196 // TODO: justPrint support
2197 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2199 ide.outputView.buildBox.Logf("%s\n", command);
2200 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2202 ProcessPipeOutputRaw(f);
2206 ChangeWorkingDir(oldwd);
2211 char cfDir[MAX_LOCATION];
2212 GetIDECompilerConfigsDir(cfDir, true, true);
2213 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2214 compiler.makeCommand, cfDir,
2215 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2216 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2218 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2219 topNode.path, justPrint ? " -n": "", makeFilePath);
2221 ide.outputView.buildBox.Logf("%s\n", command);
2222 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2224 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2225 cleanType == realClean ? $"intermediate objects directory" : $"target",
2226 cleanType == clean ? $" and object files" : "");
2228 ProcessPipeOutputRaw(f);
2230 ProcessCleanPipeOutput(f, compiler, config);
2231 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2232 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2233 cleanType == clean ? $" and object files" : "");
2239 delete compilerName;
2242 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2244 String target = new char[maxPathLen];
2245 char oldDirectory[MAX_LOCATION];
2246 char * executableLauncher = compiler.executableLauncher;
2247 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2248 PathBackup pathBackup { };
2250 // Build(project, ideMain, true, null, false);
2252 strcpy(target, topNode.path);
2253 PathCatSlash(target, targetDirExp.dir);
2254 CatTargetFileName(target, compiler, config);
2255 sprintf(target, "%s %s", target, args);
2256 GetWorkingDir(oldDirectory, MAX_LOCATION);
2258 if(strlen(ide.workspace.debugDir))
2260 char temp[MAX_LOCATION];
2261 strcpy(temp, topNode.path);
2262 PathCatSlash(temp, ide.workspace.debugDir);
2263 ChangeWorkingDir(temp);
2266 ChangeWorkingDir(topNode.path);
2267 // ChangeWorkingDir(topNode.path);
2268 SetPath(true, compiler, config, bitDepth);
2269 if(executableLauncher)
2271 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 2];
2272 prefixedTarget[0] = '\0';
2273 strcat(prefixedTarget, executableLauncher);
2274 strcat(prefixedTarget, " ");
2275 strcat(prefixedTarget, target);
2276 Execute(prefixedTarget);
2277 delete prefixedTarget;
2282 ChangeWorkingDir(oldDirectory);
2285 delete targetDirExp;
2289 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2291 return Build(false, nodes, compiler, config, bitDepth, justPrint, mode);
2295 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2298 if(targetType == staticLibrary || targetType == sharedLibrary)
2299 strcat(fileName, "$(LP)");
2300 // !!! ReplaceSpaces must be done after all PathCat calls !!!
2301 // ReplaceSpaces(s, GetTargetFileName(config));
2302 strcat(fileName, GetTargetFileName(config));
2306 strcat(fileName, "$(E)");
2309 strcat(fileName, "$(SO)$(VER)");
2312 strcat(fileName, "$(A)");
2317 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2319 bool result = false;
2320 char path[MAX_LOCATION];
2322 if(!GetProjectCompilerConfigsDir(path, false, false))
2323 GetIDECompilerConfigsDir(path, false, false);
2325 if(!FileExists(path).isDirectory)
2329 char dirName[MAX_FILENAME];
2330 GetLastDirectory(path, dirName);
2331 if(!strcmp(dirName, ".configs"))
2332 FileSetAttribs(path, FileAttribs { isHidden = true });
2335 PathCatSlash(path, "crossplatform.mk");
2337 if(FileExists(path))
2340 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2343 File f = FileOpen(path, write);
2346 include.Seek(0, start);
2347 for(; !include.Eof(); )
2350 int count = include.Read(buffer, 1, 4096);
2351 f.Write(buffer, 1, count);
2357 if(!altCrossPlatformMk)
2364 bool GenerateCompilerCf(CompilerConfig compiler)
2366 bool result = false;
2367 char path[MAX_LOCATION];
2369 char * compilerName;
2370 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2371 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2372 Platform platform = compiler.targetPlatform;
2374 compilerName = CopyString(compiler.name);
2375 CamelCase(compilerName);
2376 name = PrintString(platform, "-", compilerName, ".cf");
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, name);
2393 if(FileExists(path))
2396 File f = FileOpen(path, write);
2399 if(compiler.environmentVars && compiler.environmentVars.count)
2401 f.Puts("# ENVIRONMENT VARIABLES\n");
2403 for(e : compiler.environmentVars)
2405 f.Printf("export %s := %s\n", e.name, e.string);
2410 f.Puts("# TOOLCHAIN\n");
2413 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2415 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2418 if(compiler.sysroot && compiler.sysroot[0])
2420 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2421 // Moved this to crossplatform.mk
2422 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2426 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2427 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2428 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2429 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2430 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
2431 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);
2432 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);
2433 f.Printf("EAR := %s\n", compiler.earCommand);
2435 f.Puts("AS := $(GCC_PREFIX)as\n");
2436 f.Puts("LD := $(GCC_PREFIX)ld\n");
2437 f.Puts("AR := $(GCC_PREFIX)ar\n");
2438 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2439 f.Puts("ifdef WINDOWS_TARGET\n");
2440 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2441 f.Puts(" ifdef ARCH\n");
2442 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2443 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2445 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2446 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2451 f.Puts("UPX := upx\n");
2454 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2457 f.Puts("EARFLAGS = \n");
2460 f.Puts("ifndef ARCH\n");
2461 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2462 f.Puts(" ifdef WINDOWS_HOST\n");
2463 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2464 f.Puts(" TARGET_ARCH := x86_64\n");
2466 f.Puts(" TARGET_ARCH := i386\n");
2469 f.Puts("endif\n\n");
2471 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2472 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2476 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2480 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2483 if(compiler.includeDirs && compiler.includeDirs.count)
2485 f.Puts("\nCFLAGS +=");
2486 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true, false);
2489 if(compiler.prepDirectives && compiler.prepDirectives.count)
2491 f.Puts("\nCFLAGS +=");
2492 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true, false);
2495 if(compiler.libraryDirs && compiler.libraryDirs.count)
2497 f.Puts("\nLDFLAGS +=");
2498 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true, false);
2499 // We would need a bool option to know whether we want to add to rpath as well...
2500 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true, false);
2503 if(compiler.excludeLibs && compiler.excludeLibs.count)
2505 f.Puts("\nEXCLUDED_LIBS =");
2506 for(l : compiler.excludeLibs)
2512 if(compiler.compilerFlags && compiler.compilerFlags.count)
2514 f.Puts("\nCFLAGS +=");
2515 OutputListOption(f, "", compiler.compilerFlags, inPlace, true, true);
2518 if(compiler.linkerFlags && compiler.linkerFlags.count)
2520 f.Puts("\nLDFLAGS +=");
2521 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true, false);
2525 f.Puts("\nOFLAGS += $(LDFLAGS)");
2527 f.Puts("ifdef ARCH_FLAGS\n");
2528 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2529 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2538 delete compilerName;
2542 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2544 bool result = false;
2545 char filePath[MAX_LOCATION];
2546 char makeFile[MAX_LOCATION];
2547 // PathBackup pathBackup { };
2548 // char oldDirectory[MAX_LOCATION];
2551 if(!altMakefilePath)
2553 strcpy(filePath, topNode.path);
2554 CatMakeFileName(makeFile, config);
2555 PathCatSlash(filePath, makeFile);
2558 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2560 /*SetPath(false, compiler, config);
2561 GetWorkingDir(oldDirectory, MAX_LOCATION);
2562 ChangeWorkingDir(topNode.path);*/
2569 char targetDir[MAX_LOCATION];
2570 char objDirExpNoSpaces[MAX_LOCATION];
2571 char objDirNoSpaces[MAX_LOCATION];
2572 char resDirNoSpaces[MAX_LOCATION];
2573 char targetDirExpNoSpaces[MAX_LOCATION];
2574 char fixedModuleName[MAX_FILENAME];
2575 char fixedConfigName[MAX_FILENAME];
2577 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2578 // Non-zero if we're building eC code
2579 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2580 int numCObjects = 0;
2582 int numRCObjects = 0;
2583 bool containsCXX = false; // True if the project contains a C++ file
2584 bool relObjDir, sameOrRelObjTargetDirs;
2585 String objDirExp = GetObjDirExpression(config);
2586 TargetTypes targetType = GetTargetType(config);
2588 char cfDir[MAX_LOCATION];
2589 int objectsParts = 0;
2590 int eCsourcesParts = 0;
2591 int rcSourcesParts = 0;
2592 Array<String> listItems { };
2593 Map<String, int> varStringLenDiffs { };
2594 Map<String, NameCollisionInfo> namesInfo { };
2596 Map<String, int> cflagsVariations { };
2597 Map<intptr, int> nodeCFlagsMapping { };
2599 Map<String, int> ecflagsVariations { };
2600 Map<intptr, int> nodeECFlagsMapping { };
2602 ReplaceSpaces(objDirNoSpaces, objDirExp);
2603 strcpy(targetDir, GetTargetDirExpression(config));
2604 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2606 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2607 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2609 char temp[MAX_LOCATION];
2610 ReplaceSpaces(temp, objDirExpNoSpaces);
2611 strcpy(objDirExpNoSpaces, temp);
2613 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2614 ReplaceSpaces(fixedModuleName, moduleName);
2615 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2616 CamelCase(fixedConfigName);
2618 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2619 relObjDir = lenObjDirExpNoSpaces == 0 ||
2620 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2621 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2622 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2623 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2624 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2626 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2628 f.Puts("# CORE VARIABLES\n\n");
2630 f.Printf("MODULE := %s\n", fixedModuleName);
2631 f.Printf("VERSION := %s\n", property::moduleVersion);
2632 f.Printf("CONFIG := %s\n", fixedConfigName);
2633 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2636 test = GetTargetTypeIsSetByPlatform(config);
2640 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2642 TargetTypes targetType;
2643 PlatformOptions projectPOs, configPOs;
2644 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2645 targetType = platformTargetType;
2651 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2652 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2657 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2662 for(c = 0; c < ifCount; c++)
2668 f.Puts("# FLAGS\n\n");
2670 f.Puts("ECFLAGS =\n");
2671 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2672 f.Puts("PRJ_CFLAGS =\n");
2673 f.Puts("CECFLAGS =\n");
2674 f.Puts("OFLAGS =\n");
2678 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2681 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2682 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2683 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2684 //f.Puts("endif\n");
2687 f.Puts("# INCLUDES\n\n");
2689 if(compilerConfigsDir && compilerConfigsDir[0])
2691 strcpy(cfDir, compilerConfigsDir);
2692 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2697 GetIDECompilerConfigsDir(cfDir, true, true);
2698 // Use CF_DIR environment variable for absolute paths only
2699 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2700 strcpy(cfDir, "$(CF_DIR)");
2703 f.Printf("_CF_DIR = %s\n", cfDir);
2706 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2707 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2710 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2712 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2715 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2718 // test = GetTargetTypeIsSetByPlatform(config);
2720 char target[MAX_LOCATION];
2721 char temp[MAX_LOCATION];
2726 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2728 if(type != targetType)
2733 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2735 GetMakefileTargetFileName(type, target, config);
2736 strcpy(temp, targetDir);
2737 PathCatSlash(temp, target);
2738 ReplaceSpaces(target, temp);
2739 f.Printf("TARGET = %s\n", target);
2744 GetMakefileTargetFileName(targetType, target, config);
2745 strcpy(temp, targetDir);
2746 PathCatSlash(temp, target);
2747 ReplaceSpaces(target, temp);
2748 f.Printf("TARGET = %s\n", target);
2754 for(c = 0; c < ifCount; c++)
2761 // Use something fixed here, to not cause Makefile differences across compilers...
2762 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2763 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2765 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2769 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2771 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2774 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2776 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2777 if(eCsourcesParts > 1)
2779 for(c = 1; c <= eCsourcesParts; c++)
2780 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2784 for(c = 0; c < 5; c++)
2786 if(eCsourcesParts > 1)
2789 f.Printf("%s =", map[c][0]);
2790 for(n = 1; n <= eCsourcesParts; n++)
2791 f.Printf(" $(%s%d)", map[c][0], n);
2793 for(n = 1; n <= eCsourcesParts; n++)
2794 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2796 else if(eCsourcesParts == 1)
2797 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2803 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2806 f.Puts("ifdef WINDOWS_TARGET\n\n");
2808 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2810 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2811 if(rcSourcesParts > 1)
2813 for(c = 1; c <= rcSourcesParts; c++)
2814 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2817 if(rcSourcesParts > 1)
2820 f.Printf("%s =", "RCOBJECTS");
2821 for(n = 1; n <= rcSourcesParts; n++)
2822 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2824 for(n = 1; n <= rcSourcesParts; n++)
2825 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2827 else if(rcSourcesParts == 1)
2828 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2832 f.Puts("RCSOURCES =\n");
2833 f.Puts("RCOBJECTS =\n");
2834 f.Puts("endif\n\n");
2837 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2839 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2840 f.Printf("OBJECTS =%s%s%s%s\n",
2841 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2842 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2843 numRCObjects ? " $(RCOBJECTS)" : "");
2846 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2849 if(numCObjects && numRCObjects)
2850 prefix = "$(ECSOURCES) $(RCSOURCES)";
2851 else if(numCObjects)
2852 prefix = "$(ECSOURCES)";
2855 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2859 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2860 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2862 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2864 if((config && config.options && config.options.libraries) ||
2865 (options && options.libraries))
2867 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2869 if(config && config.options && config.options.libraries)
2870 OutputLibraries(f, config.options.libraries);
2871 else if(options && options.libraries)
2872 OutputLibraries(f, options.libraries);
2878 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2879 cflagsVariations, nodeCFlagsMapping,
2880 ecflagsVariations, nodeECFlagsMapping, null);
2882 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2883 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2885 if(platforms || (config && config.platforms))
2888 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2889 //for(platform = win32; platform <= apple; platform++)
2891 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2892 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2894 PlatformOptions projectPlatformOptions, configPlatformOptions;
2895 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2897 if(projectPlatformOptions || configPlatformOptions)
2902 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2905 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2906 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2908 f.Puts("CFLAGS +=");
2909 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2912 for(s : projectPlatformOptions.options.compilerOptions)
2915 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2918 for(s : configPlatformOptions.options.compilerOptions)
2925 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2926 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2928 f.Puts("OFLAGS +=");
2929 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2931 bool needWl = false;
2933 for(s : projectPlatformOptions.options.linkerOptions)
2935 if(!IsLinkerOption(s))
2943 for(s : projectPlatformOptions.options.linkerOptions)
2944 if(IsLinkerOption(s))
2948 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2950 bool needWl = false;
2952 for(s : configPlatformOptions.options.linkerOptions)
2954 if(IsLinkerOption(s))
2962 for(s : configPlatformOptions.options.linkerOptions)
2963 if(!IsLinkerOption(s))
2971 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2972 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2973 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2974 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2976 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2977 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2978 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2980 f.Puts("OFLAGS +=");
2981 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2982 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true, false);
2983 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2984 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true, false);
2988 if((configPlatformOptions && configPlatformOptions.options.libraries))
2990 if(configPlatformOptions.options.libraries.count)
2993 OutputLibraries(f, configPlatformOptions.options.libraries);
2997 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2999 if(projectPlatformOptions.options.libraries.count)
3002 OutputLibraries(f, projectPlatformOptions.options.libraries);
3013 for(c = 0; c < ifCount; c++)
3019 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3020 (options && options.compilerOptions && options.compilerOptions.count))
3022 f.Puts("CFLAGS +=");
3025 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3027 for(s : config.options.compilerOptions)
3030 if(options && options.compilerOptions && options.compilerOptions.count)
3032 for(s : options.compilerOptions)
3039 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3040 (options && options.linkerOptions && options.linkerOptions.count))
3042 f.Puts("OFLAGS +=");
3045 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3047 bool needWl = false;
3048 for(s : config.options.linkerOptions)
3050 if(!IsLinkerOption(s))
3058 for(s : config.options.linkerOptions)
3059 if(IsLinkerOption(s))
3063 if(options && options.linkerOptions && options.linkerOptions.count)
3065 bool needWl = false;
3066 for(s : options.linkerOptions)
3068 if(!IsLinkerOption(s))
3076 for(s : options.linkerOptions)
3077 if(IsLinkerOption(s))
3085 f.Puts("CECFLAGS += -cpp $(_CPP)");
3089 if(GetProfile(config))
3090 f.Puts("OFLAGS += -pg\n\n");
3092 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3094 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3095 f.Puts("OFLAGS +=");
3096 if(config && config.options && config.options.libraryDirs)
3097 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true, false);
3098 if(options && options.libraryDirs)
3099 OutputListOption(f, "L", options.libraryDirs, lineEach, true, false);
3105 f.Puts("# TARGETS\n");
3108 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3111 f.Puts("objdir:\n");
3113 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3115 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)/crossplatform.mk) location.)),)\n");
3116 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");
3117 //f.Puts("# PRE-BUILD COMMANDS\n");
3118 if(options && options.prebuildCommands)
3120 for(s : options.prebuildCommands)
3121 if(s && s[0]) f.Printf("\t%s\n", s);
3123 if(config && config.options && config.options.prebuildCommands)
3125 for(s : config.options.prebuildCommands)
3126 if(s && s[0]) f.Printf("\t%s\n", s);
3128 if(platforms || (config && config.platforms))
3131 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3132 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3134 PlatformOptions projectPOs, configPOs;
3135 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3137 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3138 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3143 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3145 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3147 for(s : projectPOs.options.prebuildCommands)
3148 if(s && s[0]) f.Printf("\t%s\n", s);
3150 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3152 for(s : configPOs.options.prebuildCommands)
3153 if(s && s[0]) f.Printf("\t%s\n", s);
3160 for(c = 0; c < ifCount; c++)
3166 if(!sameOrRelObjTargetDirs)
3168 f.Puts("targetdir:\n");
3169 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3175 // Main Module (Linking) for ECERE C modules
3176 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3177 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3178 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $@\n",
3179 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3181 // Main Module (Linking) for ECERE C modules
3182 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3183 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3184 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3185 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3186 " -c $(OBJ)$(MODULE).main.ec -o $@ -symbols $(OBJ)\n");
3192 // This would not rebuild the target on updated objects
3193 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3195 // This should fix it for good!
3196 f.Puts("$(SYMBOLS): | objdir\n");
3197 f.Puts("$(OBJECTS): | objdir\n");
3199 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3200 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3201 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3203 f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
3204 f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
3205 OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
3208 f.Puts("ifdef WINDOWS_TARGET\n");
3209 OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
3214 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
3215 OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
3218 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3220 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
3221 if(!GetDebug(config))
3223 f.Puts("ifndef NOSTRIP\n");
3224 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3227 if(GetCompress(config))
3229 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3230 f.Puts("ifdef EXECUTABLE_TARGET\n");
3231 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3234 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3238 if(resNode.files && resNode.files.count && !noResources)
3239 resNode.GenMakefileAddResources(f, resNode.path, config);
3241 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
3243 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3244 f.Puts("ifdef LINUX_TARGET\n");
3245 f.Puts("ifdef LINUX_HOST\n");
3246 // TODO?: support symlinks for longer version numbers
3247 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3248 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3253 //f.Puts("# POST-BUILD COMMANDS\n");
3254 if(options && options.postbuildCommands)
3256 for(s : options.postbuildCommands)
3257 if(s && s[0]) f.Printf("\t%s\n", s);
3259 if(config && config.options && config.options.postbuildCommands)
3261 for(s : config.options.postbuildCommands)
3262 if(s && s[0]) f.Printf("\t%s\n", s);
3264 if(platforms || (config && config.platforms))
3267 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3268 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3270 PlatformOptions projectPOs, configPOs;
3271 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3273 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3274 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3279 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3281 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3283 for(s : projectPOs.options.postbuildCommands)
3284 if(s && s[0]) f.Printf("\t%s\n", s);
3286 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3288 for(s : configPOs.options.postbuildCommands)
3289 if(s && s[0]) f.Printf("\t%s\n", s);
3296 for(c = 0; c < ifCount; c++)
3302 f.Puts("# SYMBOL RULES\n");
3305 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3307 f.Puts("# C OBJECT RULES\n");
3310 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3312 f.Puts("# OBJECT RULES\n");
3314 // todo call this still but only generate rules whith specific options
3315 // see we-have-file-specific-options in ProjectNode.ec
3316 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3319 GenMakefilePrintMainObjectRule(f, config);
3321 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3322 f.Puts("\t$(call rmq,$(TARGET))\n");
3323 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3324 f.Puts("ifdef LINUX_TARGET\n");
3325 f.Puts("ifdef LINUX_HOST\n");
3326 // TODO?: support symlinks for longer version numbers
3327 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3328 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3334 f.Puts("clean: cleantarget\n");
3335 f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3336 OutputCleanActions(f, "_OBJECTS", objectsParts);
3339 f.Puts("ifdef WINDOWS_TARGET\n");
3340 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3345 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)");
3346 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3347 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3348 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3349 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3350 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3354 f.Puts("realclean: cleantarget\n");
3355 f.Puts("\t$(call rmrq,$(OBJ))\n");
3356 if(!sameOrRelObjTargetDirs)
3357 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3360 f.Puts("distclean: cleantarget\n");
3361 if(!sameOrRelObjTargetDirs)
3362 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3364 f.Puts("\t$(call rmrq,obj/)\n");
3370 varStringLenDiffs.Free();
3371 delete varStringLenDiffs;
3375 delete cflagsVariations;
3376 delete nodeCFlagsMapping;
3377 delete ecflagsVariations;
3378 delete nodeECFlagsMapping;
3383 // ChangeWorkingDir(oldDirectory);
3384 // delete pathBackup;
3387 config.makingModified = false;
3391 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3393 char extension[MAX_EXTENSION] = "c";
3394 char modulePath[MAX_LOCATION];
3395 char fixedModuleName[MAX_FILENAME];
3398 char objDirNoSpaces[MAX_LOCATION];
3399 String objDirExp = GetObjDirExpression(config);
3401 ReplaceSpaces(objDirNoSpaces, objDirExp);
3402 ReplaceSpaces(fixedModuleName, moduleName);
3404 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3405 //strcat(fixedModuleName, ".main");
3407 #if 0 // TODO: Fix nospaces stuff
3408 // *** Dependency command ***
3409 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3411 // System Includes (from global settings)
3412 for(item : compiler.dirs[Includes])
3414 strcat(command, " -isystem ");
3415 if(strchr(item.name, ' '))
3417 strcat(command, "\"");
3418 strcat(command, item);
3419 strcat(command, "\"");
3422 strcat(command, item);
3425 for(item = includeDirs.first; item; item = item.next)
3427 strcat(command, " -I");
3428 if(strchr(item.name, ' '))
3430 strcat(command, "\"");
3431 strcat(command, item.name);
3432 strcat(command, "\"");
3435 strcat(command, item.name);
3437 for(item = preprocessorDefs.first; item; item = item.next)
3439 strcat(command, " -D");
3440 strcat(command, item.name);
3444 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
3448 bool firstLine = true;
3450 // To do some time: auto save external dependencies?
3453 if(dep.GetLine(line, sizeof(line)-1))
3457 char * colon = strstr(line, ":");
3458 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3472 // If we failed to generate dependencies...
3476 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3477 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $@\n", extension);
3485 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3488 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3490 for(v : cflagsVariations)
3495 f.Printf("%s +=", variableName);
3497 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3498 f.Puts(&v ? &v : "");
3506 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3507 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3509 *projectPlatformOptions = null;
3510 *configPlatformOptions = null;
3515 if(!strcmpi(p.name, platform))
3517 *projectPlatformOptions = p;
3522 if(config && config.platforms)
3524 for(p : config.platforms)
3526 if(!strcmpi(p.name, platform))
3528 *configPlatformOptions = p;
3536 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3538 if(prj.lastBuildNamesInfo)
3540 prj.lastBuildNamesInfo.Free();
3541 delete prj.lastBuildNamesInfo;
3543 prj.lastBuildNamesInfo = { };
3544 prj.topNode.GenMakefileGetNameCollisionInfo(prj.lastBuildNamesInfo, cfg);
3547 Project LegacyBinaryLoadProject(File f, char * filePath)
3549 Project project = null;
3550 char signature[sizeof(epjSignature)];
3552 f.Read(signature, sizeof(signature), 1);
3553 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3555 char topNodePath[MAX_LOCATION];
3556 /*ProjectConfig newConfig
3558 name = CopyString("Default");
3559 makingModified = true;
3560 compilingModified = true;
3561 linkingModified = true;
3565 project = Project { options = { } };
3566 LegacyBinaryLoadNode(project.topNode, f);
3567 delete project.topNode.path;
3568 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3569 MakeSlashPath(topNodePath);
3571 PathCatSlash(topNodePath, filePath);
3572 project.filePath = topNodePath;
3574 /* THIS IS ALREADY DONE BY filePath property
3575 StripLastDirectory(topNodePath, topNodePath);
3576 project.topNode.path = CopyString(topNodePath);
3578 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3580 // newConfig.options.defaultNameSpace = "";
3581 /*newConfig.objDir.dir = "obj";
3582 newConfig.targetDir.dir = "";*/
3584 //project.configurations = { [ newConfig ] };
3585 //project.config = newConfig;
3592 String targetFileName, targetDirectory, objectsDirectory;
3594 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3595 f.Read(&temp, sizeof(int),1);
3598 case 0: project.options.targetType = executable; break;
3599 case 1: project.options.targetType = sharedLibrary; break;
3600 case 2: project.options.targetType = staticLibrary; break;
3603 f.Read(&len, sizeof(int),1);
3604 targetFileName = new char[len+1];
3605 f.Read(targetFileName, sizeof(char), len+1);
3606 project.options.targetFileName = targetFileName;
3607 delete targetFileName;
3609 f.Read(&len, sizeof(int),1);
3610 targetDirectory = new char[len+1];
3611 f.Read(targetDirectory, sizeof(char), len+1);
3612 project.options.targetDirectory = targetDirectory;
3613 delete targetDirectory;
3615 f.Read(&len, sizeof(int),1);
3616 objectsDirectory = new byte[len+1];
3617 f.Read(objectsDirectory, sizeof(char), len+1);
3618 project.options.objectsDirectory = objectsDirectory;
3619 delete objectsDirectory;
3621 f.Read(&temp, sizeof(int),1);
3622 project./*config.*/options.debug = temp ? true : false;
3623 f.Read(&temp, sizeof(int),1);
3624 project./*config.*/options.optimization = temp ? speed : none;
3625 f.Read(&temp, sizeof(int),1);
3626 project./*config.*/options.profile = temp ? true : false;
3627 f.Read(&temp, sizeof(int),1);
3628 project.options.warnings = temp ? all : unset;
3630 f.Read(&count, sizeof(int),1);
3633 project.options.includeDirs = { };
3634 for(c = 0; c < count; c++)
3637 f.Read(&len, sizeof(int),1);
3638 name = new char[len+1];
3639 f.Read(name, sizeof(char), len+1);
3640 project.options.includeDirs.Add(name);
3644 f.Read(&count, sizeof(int),1);
3647 project.options.libraryDirs = { };
3648 for(c = 0; c < count; c++)
3651 f.Read(&len, sizeof(int),1);
3652 name = new char[len+1];
3653 f.Read(name, sizeof(char), len+1);
3654 project.options.libraryDirs.Add(name);
3658 f.Read(&count, sizeof(int),1);
3661 project.options.libraries = { };
3662 for(c = 0; c < count; c++)
3665 f.Read(&len, sizeof(int),1);
3666 name = new char[len+1];
3667 f.Read(name, sizeof(char), len+1);
3668 project.options.libraries.Add(name);
3672 f.Read(&count, sizeof(int),1);
3675 project.options.preprocessorDefinitions = { };
3676 for(c = 0; c < count; c++)
3679 f.Read(&len, sizeof(int),1);
3680 name = new char[len+1];
3681 f.Read(name, sizeof(char), len+1);
3682 project.options.preprocessorDefinitions.Add(name);
3686 f.Read(&temp, sizeof(int),1);
3687 project.options.console = temp ? true : false;
3690 for(node : project.topNode.files)
3692 if(node.type == resources)
3694 project.resNode = node;
3704 void ProjectConfig::LegacyProjectConfigLoad(File f)
3712 char subSection[128];
3718 f.GetLine(buffer, 65536 - 1);
3719 TrimLSpaces(buffer, buffer);
3720 TrimRSpaces(buffer, buffer);
3723 if(buffer[0] == '-')
3727 TrimLSpaces(equal, equal);
3728 if(!strcmpi(subSection, "LibraryDirs"))
3730 if(!options.libraryDirs)
3731 options.libraryDirs = { [ CopyString(equal) ] };
3733 options.libraryDirs.Add(CopyString(equal));
3735 else if(!strcmpi(subSection, "IncludeDirs"))
3737 if(!options.includeDirs)
3738 options.includeDirs = { [ CopyString(equal) ] };
3740 options.includeDirs.Add(CopyString(equal));
3743 else if(buffer[0] == '+')
3754 TrimLSpaces(equal, equal);
3755 delete name; name = CopyString(equal); // property::name = equal;
3758 else if(!strcmpi(buffer, "Compiler Options"))
3759 strcpy(section, buffer);
3760 else if(!strcmpi(buffer, "IncludeDirs"))
3761 strcpy(subSection, buffer);
3762 else if(!strcmpi(buffer, "Linker Options"))
3763 strcpy(section, buffer);
3764 else if(!strcmpi(buffer, "LibraryDirs"))
3765 strcpy(subSection, buffer);
3766 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3773 equal = strstr(buffer, "=");
3777 TrimRSpaces(buffer, buffer);
3779 TrimLSpaces(equal, equal);
3780 if(!strcmpi(buffer, "Target Name"))
3781 options.targetFileName = /*CopyString(*/equal/*)*/;
3782 else if(!strcmpi(buffer, "Target Type"))
3784 if(!strcmpi(equal, "Executable"))
3785 options.targetType = executable;
3786 else if(!strcmpi(equal, "Shared"))
3787 options.targetType = sharedLibrary;
3788 else if(!strcmpi(equal, "Static"))
3789 options.targetType = staticLibrary;
3791 options.targetType = executable;
3793 else if(!strcmpi(buffer, "Target Directory"))
3794 options.targetDirectory = /*CopyString(*/equal/*)*/;
3795 else if(!strcmpi(buffer, "Console"))
3796 options.console = ParseTrueFalseValue(equal);
3797 else if(!strcmpi(buffer, "Libraries"))
3799 if(!options.libraries) options.libraries = { };
3800 ParseArrayValue(options.libraries, equal);
3802 else if(!strcmpi(buffer, "Intermediate Directory"))
3803 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3804 else if(!strcmpi(buffer, "Debug"))
3805 options.debug = ParseTrueFalseValue(equal);
3806 else if(!strcmpi(buffer, "Optimize"))
3808 if(!strcmpi(equal, "None"))
3809 options.optimization = none;
3810 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3811 options.optimization = speed;
3812 else if(!strcmpi(equal, "Size"))
3813 options.optimization = size;
3815 options.optimization = none;
3817 else if(!strcmpi(buffer, "Compress"))
3818 options.compress = ParseTrueFalseValue(equal);
3819 else if(!strcmpi(buffer, "Profile"))
3820 options.profile = ParseTrueFalseValue(equal);
3821 else if(!strcmpi(buffer, "AllWarnings"))
3822 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3823 else if(!strcmpi(buffer, "MemoryGuard"))
3824 options.memoryGuard = ParseTrueFalseValue(equal);
3825 else if(!strcmpi(buffer, "Default Name Space"))
3826 options.defaultNameSpace = CopyString(equal);
3827 else if(!strcmpi(buffer, "Strict Name Spaces"))
3828 options.strictNameSpaces = ParseTrueFalseValue(equal);
3829 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3831 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3832 ParseArrayValue(options.preprocessorDefinitions, equal);
3838 if(!options.targetDirectory && options.objectsDirectory)
3839 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3840 //if(!objDir.dir) objDir.dir = "obj";
3841 //if(!targetDir.dir) targetDir.dir = "";
3842 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3843 // if(!defaultNameSpace) property::defaultNameSpace = "";
3844 makingModified = true;
3847 Project LegacyAsciiLoadProject(File f, char * filePath)
3849 Project project = null;
3850 ProjectNode node = null;
3852 char parentPath[MAX_LOCATION];
3853 char section[128] = "";
3854 char subSection[128] = "";
3856 bool configurationsPresent = false;
3866 f.GetLine(buffer, 65536 - 1);
3867 TrimLSpaces(buffer, buffer);
3868 TrimRSpaces(buffer, buffer);
3871 if(buffer[0] == '-' || buffer[0] == '=')
3873 bool simple = buffer[0] == '-';
3876 TrimLSpaces(equal, equal);
3877 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3879 if(!project.config.options.libraryDirs)
3880 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3882 project.config.options.libraryDirs.Add(CopyString(equal));
3884 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3886 if(!project.config.options.includeDirs)
3887 project.config.options.includeDirs = { [ CopyString(equal) ] };
3889 project.config.options.includeDirs.Add(CopyString(equal));
3891 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3893 len = strlen(equal);
3896 char temp[MAX_LOCATION];
3897 ProjectNode child { };
3898 // We don't need to do this anymore, fileName is just a property that sets name & path
3899 // child.fileName = CopyString(equal);
3902 child.name = CopyString(equal);
3903 child.path = CopyString(parentPath);
3907 GetLastDirectory(equal, temp);
3908 child.name = CopyString(temp);
3909 StripLastDirectory(equal, temp);
3910 child.path = CopyString(temp);
3912 child.nodeType = file;
3913 child.parent = parent;
3914 child.indent = parent.indent + 1;
3916 child.icon = NodeIcons::SelectFileIcon(child.name);
3917 parent.files.Add(child);
3923 StripLastDirectory(parentPath, parentPath);
3924 parent = parent.parent;
3928 else if(buffer[0] == '+')
3932 TrimLSpaces(equal, equal);
3933 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3935 char temp[MAX_LOCATION];
3936 ProjectNode child { };
3937 // NEW: Folders now have a path set like files
3938 child.name = CopyString(equal);
3939 strcpy(temp, parentPath);
3940 PathCatSlash(temp, child.name);
3941 child.path = CopyString(temp);
3943 child.parent = parent;
3944 child.indent = parent.indent + 1;
3945 child.type = folder;
3946 child.nodeType = folder;
3948 child.icon = folder;
3949 PathCatSlash(parentPath, child.name);
3950 parent.files.Add(child);
3955 else if(!strcmpi(section, "Configurations"))
3957 ProjectConfig newConfig
3959 makingModified = true;
3963 LegacyProjectConfigLoad(newConfig, f);
3964 project.configurations.Add(newConfig);
3967 else if(!strcmpi(buffer, "ECERE Project File"));
3968 else if(!strcmpi(buffer, "Version 0a"))
3969 ; //strcpy(version, "0a");
3970 else if(!strcmpi(buffer, "Version 0.1a"))
3971 ; //strcpy(version, "0.1a");
3972 else if(!strcmpi(buffer, "Configurations"))
3974 project.configurations.Free();
3975 project.config = null;
3976 strcpy(section, buffer);
3977 configurationsPresent = true;
3979 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3981 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3982 char topNodePath[MAX_LOCATION];
3983 // newConfig.defaultNameSpace = "";
3984 //newConfig.objDir.dir = "obj";
3985 //newConfig.targetDir.dir = "";
3986 project = Project { /*options = { }*/ };
3987 project.configurations = { [ newConfig ] };
3988 project.config = newConfig;
3989 // if(project.topNode.path) delete project.topNode.path;
3990 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3991 MakeSlashPath(topNodePath);
3992 PathCatSlash(topNodePath, filePath);
3993 project.filePath = topNodePath;
3994 parentPath[0] = '\0';
3995 parent = project.topNode;
3997 strcpy(section, "Target");
4002 if(equal[0] == '\"')
4004 StripQuotes(equal, equal);
4005 delete project.moduleName; project.moduleName = CopyString(equal);
4009 else if(!strcmpi(buffer, "Compiler Options"));
4010 else if(!strcmpi(buffer, "IncludeDirs"))
4011 strcpy(subSection, buffer);
4012 else if(!strcmpi(buffer, "Linker Options"));
4013 else if(!strcmpi(buffer, "LibraryDirs"))
4014 strcpy(subSection, buffer);
4015 else if(!strcmpi(buffer, "Files"))
4017 strcpy(section, "Target");
4018 strcpy(subSection, buffer);
4020 else if(!strcmpi(buffer, "Resources"))
4022 ProjectNode child { };
4023 parent.files.Add(child);
4024 child.parent = parent;
4025 child.indent = parent.indent + 1;
4026 child.name = CopyString(buffer);
4027 child.path = CopyString("");
4028 child.type = resources;
4030 child.icon = archiveFile;
4031 project.resNode = child;
4034 strcpy(subSection, buffer);
4038 equal = strstr(buffer, "=");
4042 TrimRSpaces(buffer, buffer);
4044 TrimLSpaces(equal, equal);
4046 if(!strcmpi(section, "Target"))
4048 if(!strcmpi(buffer, "Build Exclusions"))
4050 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4052 /*if(node && node.type != NodeTypes::project)
4053 ParseListValue(node.buildExclusions, equal);*/
4056 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4058 delete project.resNode.path;
4059 project.resNode.path = CopyString(equal);
4060 PathCatSlash(parentPath, equal);
4064 else if(!strcmpi(buffer, "Intermediate Directory"))
4065 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4066 else if(!strcmpi(buffer, "Debug"))
4067 project.config.options.debug = ParseTrueFalseValue(equal);
4068 else if(!strcmpi(buffer, "Optimize"))
4070 if(!strcmpi(equal, "None"))
4071 project.config.options.optimization = none;
4072 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4073 project.config.options.optimization = speed;
4074 else if(!strcmpi(equal, "Size"))
4075 project.config.options.optimization = size;
4077 project.config.options.optimization = none;
4079 else if(!strcmpi(buffer, "Profile"))
4080 project.config.options.profile = ParseTrueFalseValue(equal);
4081 else if(!strcmpi(buffer, "MemoryGuard"))
4082 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4085 if(!project.options) project.options = { };
4087 // Project Wide Settings (All configs)
4088 if(!strcmpi(buffer, "Target Name"))
4089 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4090 else if(!strcmpi(buffer, "Target Type"))
4092 if(!strcmpi(equal, "Executable"))
4093 project.options.targetType = executable;
4094 else if(!strcmpi(equal, "Shared"))
4095 project.options.targetType = sharedLibrary;
4096 else if(!strcmpi(equal, "Static"))
4097 project.options.targetType = staticLibrary;
4099 project.options.targetType = executable;
4101 else if(!strcmpi(buffer, "Target Directory"))
4102 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4103 else if(!strcmpi(buffer, "Console"))
4104 project.options.console = ParseTrueFalseValue(equal);
4105 else if(!strcmpi(buffer, "Libraries"))
4107 if(!project.options.libraries) project.options.libraries = { };
4108 ParseArrayValue(project.options.libraries, equal);
4110 else if(!strcmpi(buffer, "AllWarnings"))
4111 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4112 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4114 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4116 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4117 ParseListValue(node.preprocessorDefs, equal);*/
4121 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4122 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4133 SplitPlatformLibraries(project);
4135 if(configurationsPresent)
4136 CombineIdenticalConfigOptions(project);
4140 void SplitPlatformLibraries(Project project)
4142 if(project && project.configurations)
4144 for(cfg : project.configurations)
4146 if(cfg.options.libraries && cfg.options.libraries.count)
4148 Iterator<String> it { cfg.options.libraries };
4152 char * platformName = strstr(l, ":");
4155 PlatformOptions platform = null;
4157 if(!cfg.platforms) cfg.platforms = { };
4158 for(p : cfg.platforms)
4160 if(!strcmpi(platformName, p.name))
4168 platform = { name = CopyString(platformName), options = { libraries = { } } };
4169 cfg.platforms.Add(platform);
4171 *(platformName-1) = 0;
4172 platform.options.libraries.Add(CopyString(l));
4174 cfg.options.libraries.Delete(it.pointer);
4183 void CombineIdenticalConfigOptions(Project project)
4185 if(project && project.configurations && project.configurations.count)
4188 ProjectOptions nullOptions { };
4189 ProjectConfig firstConfig = null;
4190 for(cfg : project.configurations)
4192 if(cfg.options.targetType != staticLibrary)
4199 firstConfig = project.configurations.firstIterator.data;
4201 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4203 if(!member.isProperty)
4205 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4210 for(cfg : project.configurations)
4212 if(cfg != firstConfig)
4214 if(cfg.options.targetType != staticLibrary)
4218 if(type.type == noHeadClass || type.type == normalClass)
4220 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4221 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4222 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4226 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4227 (byte *)firstConfig.options + member.offset + member._class.offset,
4228 (byte *)cfg.options + member.offset + member._class.offset);
4240 if(type.type == noHeadClass || type.type == normalClass)
4242 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4243 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4244 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4249 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4250 (byte *)firstConfig.options + member.offset + member._class.offset,
4251 (byte *)nullOptions + member.offset + member._class.offset))
4255 if(!project.options) project.options = { };
4257 /*if(type.type == noHeadClass || type.type == normalClass)
4259 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4260 (byte *)project.options + member.offset + member._class.offset,
4261 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4265 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4266 // TOFIX: ListBox::SetData / OnCopy mess
4267 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4268 (byte *)project.options + member.offset + member._class.offset,
4269 (type.typeSize > 4) ? address :
4270 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4271 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4272 (void *)*(byte *)address )));
4275 (byte *)project.options + member.offset + member._class.offset,
4276 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4278 for(cfg : project.configurations)
4280 if(cfg.options.targetType == staticLibrary)
4284 if(type.type == noHeadClass || type.type == normalClass)
4286 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4287 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4288 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4292 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4293 (byte *)firstConfig.options + member.offset + member._class.offset,
4294 (byte *)cfg.options + member.offset + member._class.offset);
4299 if(cfg != firstConfig)
4301 if(type.type == noHeadClass || type.type == normalClass)
4303 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4304 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4308 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4309 (byte *)cfg.options + member.offset + member._class.offset);
4311 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4314 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4321 // Compare Platform Specific Settings
4324 for(cfg : project.configurations)
4326 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4327 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4333 if(same && firstConfig.platforms)
4335 for(cfg : project.configurations)
4337 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4339 if(cfg != firstConfig)
4341 cfg.platforms.Free();
4342 delete cfg.platforms;
4345 project.platforms = firstConfig.platforms;
4346 firstConfig.platforms = null;
4350 // Static libraries can't contain libraries
4351 for(cfg : project.configurations)
4353 if(cfg.options.targetType == staticLibrary)
4355 if(!cfg.options.libraries) cfg.options.libraries = { };
4356 cfg.options.libraries.Free();
4362 Project LoadProject(char * filePath, char * activeConfigName)
4364 Project project = null;
4365 File f = FileOpen(filePath, read);
4368 project = LegacyBinaryLoadProject(f, filePath);
4371 JSONParser parser { f = f };
4372 JSONResult result = parser.GetObject(class(Project), &project);
4375 char insidePath[MAX_LOCATION];
4377 delete project.topNode.files;
4378 if(!project.files) project.files = { };
4379 project.topNode.files = project.files;
4382 char topNodePath[MAX_LOCATION];
4383 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4384 MakeSlashPath(topNodePath);
4385 PathCatSlash(topNodePath, filePath);
4386 project.filePath = topNodePath;//filePath;
4389 project.topNode.FixupNode(insidePath);
4391 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4392 delete project.resNode.path;
4393 project.resNode.path = project.resourcesPath;
4394 project.resourcesPath = null;
4395 project.resNode.nodeType = (ProjectNodeType)-1;
4396 delete project.resNode.files;
4397 project.resNode.files = project.resources;
4398 project.files = null;
4399 project.resources = null;
4400 if(!project.configurations) project.configurations = { };
4402 project.resNode.FixupNode(insidePath);
4407 project = LegacyAsciiLoadProject(f, filePath);
4413 if(!project.options) project.options = { };
4414 if(activeConfigName && activeConfigName[0] && project.configurations)
4415 project.config = project.GetConfig(activeConfigName);
4416 if(!project.config && project.configurations)
4417 project.config = project.configurations.firstIterator.data;
4419 if(!project.resNode)
4421 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4424 if(!project.moduleName)
4425 project.moduleName = CopyString(project.name);
4426 if(project.config &&
4427 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4428 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4430 //delete project.config.options.targetFileName;
4432 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4433 project.config.options.optimization = none;
4434 project.config.options.debug = true;
4435 //project.config.options.warnings = unset;
4436 project.config.options.memoryGuard = false;
4437 project.config.compilingModified = true;
4438 project.config.linkingModified = true;
4440 else if(!project.topNode.name && project.config)
4442 project.topNode.name = CopyString(project.config.options.targetFileName);
4445 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4446 project.topNode.configurations = project.configurations;
4447 project.topNode.platforms = project.platforms;
4448 project.topNode.options = project.options;*/