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++] = '\\';
428 if(ch == '(' || ch == ')') output[dc++] = '\\';
438 // This function cannot accept same pointer for source and output
439 void ReplaceUnwantedMakeChars(char * output, char * source)
442 char * s = source, * d = output;
448 if(s != source && *(s-1) == '$')
460 else if(ch == '$' && *(s+1) != '(')
470 static void OutputNoSpace(File f, char * source)
472 char * output = new char[strlen(source)+1024];
473 ReplaceSpaces(output, source);
478 enum ListOutputMethod { inPlace, newLine, lineEach };
480 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
483 const int breakListLength = 1536;
484 const int breakLineLength = 78; // TODO: turn this into an option.
486 int c, len, itemCount = 0;
487 Array<int> breaks { };
491 MapNode<String, int> mn;
492 for(c=0; c<list.count; c++)
494 len = strlen(list[c]) + 3;
495 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
497 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
499 if(strstr(list[c], mn.key))
503 if(charCount + len > breakListLength)
505 breaks.Add(itemCount);
513 breaks.Add(itemCount);
514 numOfBreaks = breaks.count;
519 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
520 for(c=0; c<numOfBreaks; c++)
521 f.Printf(" $(%s%d)", name, c+1);
525 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
531 for(c=0; c<numOfBreaks; c++)
534 f.Printf("%s%d =", name, c+1);
537 itemCount = breaks[c];
538 for(n=offset; n<offset+itemCount; n++)
540 if(false) // TODO: turn this into an option.
542 int itemLen = strlen(list[n]);
543 if(len > 3 && len + itemLen > breakLineLength)
545 f.Printf(" \\\n\t%s", list[n]);
551 f.Printf(" %s", list[n]);
555 f.Printf(" \\\n\t%s", list[n]);
570 void OutputLinkObjectActions(File f, char * name, int parts)
575 for(c=0; c<parts; c++)
576 f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
578 f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
582 void OutputCleanActions(File f, char * name, int parts)
587 for(c=0; c<parts; c++)
588 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
591 f.Printf("\t$(call rmq,$(%s))\n", name);
594 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
598 if(method == newLine)
602 if(method == lineEach)
604 f.Printf(" -%s", option);
606 OutputNoSpace(f, item);
608 f.Printf("%s", item);
613 void StringNoSpaceToDynamicString(DynamicString s, char * path)
615 char * output = new char[strlen(path)+1024];
616 ReplaceSpaces(output, path);
621 static void OutputLibraries(File f, Array<String> libraries)
623 for(item : libraries)
625 char ext[MAX_EXTENSION];
626 char temp[MAX_LOCATION];
628 bool usedFunction = false;
629 GetExtension(item, ext);
630 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
634 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
636 if(!strncmp(item, "lib", 3))
637 strcpy(temp, item + 3);
640 StripExtension(temp);
643 f.Puts(" \\\n\t$(call _L,");
652 void CamelCase(char * string)
654 int c, len = strlen(string);
655 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
656 string[c] = (char)tolower(string[c]);
659 CompilerConfig GetCompilerConfig()
661 #ifndef MAKEFILE_GENERATOR
662 CompilerConfig compiler = null;
663 if(ide && ide.workspace)
664 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
667 incref defaultCompiler;
668 return defaultCompiler;
672 define localTargetType = config && config.options && config.options.targetType ?
673 config.options.targetType : options && options.targetType ?
674 options.targetType : TargetTypes::executable;
675 define localWarnings = config && config.options && config.options.warnings ?
676 config.options.warnings : options && options.warnings ?
677 options.warnings : WarningsOption::unset;
678 define localDebug = config && config.options && config.options.debug ?
679 config.options.debug : options && options.debug ?
680 options.debug : SetBool::unset;
681 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
682 config.options.memoryGuard : options && options.memoryGuard ?
683 options.memoryGuard : SetBool::unset;
684 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
685 config.options.noLineNumbers : options && options.noLineNumbers ?
686 options.noLineNumbers : SetBool::unset;
687 define localProfile = config && config.options && config.options.profile ?
688 config.options.profile : options && options.profile ?
689 options.profile : SetBool::unset;
690 define localOptimization = config && config.options && config.options.optimization ?
691 config.options.optimization : options && options.optimization ?
692 options.optimization : OptimizationStrategy::none;
693 define localFastMath = config && config.options && config.options.fastMath ?
694 config.options.fastMath : options && options.fastMath ?
695 options.fastMath : SetBool::unset;
696 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
697 config.options.defaultNameSpace : options && options.defaultNameSpace ?
698 options.defaultNameSpace : null;
699 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
700 config.options.strictNameSpaces : options && options.strictNameSpaces ?
701 options.strictNameSpaces : SetBool::unset;
702 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
703 define localTargetFileName = config && config.options && config.options.targetFileName ?
704 config.options.targetFileName : options && options.targetFileName ?
705 options.targetFileName : "";
706 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
707 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
708 options.targetDirectory : null;
709 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
710 ideSettings.projectDefaultIntermediateObjDir[0] ?
711 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
712 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
713 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
714 options.objectsDirectory : null;
715 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
716 ideSettings.projectDefaultIntermediateObjDir[0] ?
717 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
718 define localConsole = config && config.options && config.options.console ?
719 config.options.console : options && options.console ?
720 options.console : SetBool::unset;
721 define localCompress = config && config.options && config.options.compress ?
722 config.options.compress : options && options.compress ?
723 options.compress : SetBool::unset;
725 define platformTargetType =
726 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
727 configPOs.options.targetType :
728 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
729 projectPOs.options.targetType : TargetTypes::unset;
732 char * PlatformToMakefileTargetVariable(Platform platform)
734 return platform == win32 ? "WINDOWS_TARGET" :
735 platform == tux ? "LINUX_TARGET" :
736 platform == apple ? "OSX_TARGET" :
740 char * TargetTypeToMakefileVariable(TargetTypes targetType)
742 return targetType == executable ? "executable" :
743 targetType == sharedLibrary ? "sharedlib" :
744 targetType == staticLibrary ? "staticlib" :
748 // Move this to ProjectConfig? null vs Common to consider...
749 char * GetConfigName(ProjectConfig config)
751 return config ? config.name : "Common";
754 public enum SingleFileCompileMode
756 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
758 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
761 class Project : struct
763 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
764 // We might want to tweak this default behavior of regular classes ?
765 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
770 property char * moduleVersion
772 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
773 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
774 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
777 property char * description
779 set { delete description; if(value && value[0]) description = CopyString(value); }
780 get { return description ? description : ""; }
781 isset { return description != null && description[0]; }
784 property char * license
786 set { delete license; if(value && value[0]) license = CopyString(value); }
787 get { return license ? license : ""; }
788 isset { return license != null && license[0]; }
791 property char * compilerConfigsDir
793 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
794 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
795 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
798 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
799 property Array<PlatformOptions> platforms
801 get { return platforms; }
804 if(platforms) { platforms.Free(); delete platforms; }
807 List<PlatformOptions> empty { };
808 Iterator<PlatformOptions> it { value };
810 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
811 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
821 if(p.options && !p.options.isEmpty)
828 List<ProjectConfig> configurations;
829 LinkList<ProjectNode> files;
830 String resourcesPath;
831 LinkList<ProjectNode> resources;
834 // topNode.name holds the file name (.epj)
835 ProjectOptions options;
836 Array<PlatformOptions> platforms;
837 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
840 ProjectConfig config;
842 // This is the file name stripped of the epj extension
843 // It should NOT be edited, saved or loaded anywhere
848 String compilerConfigsDir;
849 String moduleVersion;
851 #ifndef MAKEFILE_GENERATOR
852 FileMonitor fileMonitor
854 this, FileChange { modified = true };
855 bool OnFileNotify(FileChange action, char * param)
857 fileMonitor.StopMonitoring();
858 if(OnProjectModified(action, param))
859 fileMonitor.StartMonitoring();
864 bool StartMonitoring()
866 fileMonitor.fileName = filePath;
867 fileMonitor.StartMonitoring();
871 bool StopMonitoring()
873 fileMonitor.StopMonitoring();
877 bool OnProjectModified(FileChange fileChange, char * param)
880 sprintf(temp, $"The project %s was modified by another application.\n"
881 "Would you like to reload it and lose your changes?", name);
882 if(MessageBox { type = yesNo, master = ide,
883 text = $"Project has been modified", contents = temp }.Modal() == yes)
885 Project project = LoadProject(filePath, config.name);
888 ProjectView projectView = ide.projectView;
889 DataRow prev = topNode.row ? topNode.row.previous : null;
890 FileMonitor fm = fileMonitor;
891 bool confirmation = true;
895 if(projectView.projectSettingsDialog)
897 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
899 projectView.projectSettingsDialog.Destroy(0);
902 projectView.DeleteNode(topNode);
909 topNode.project = this;
913 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
914 projectView.AddNode(topNode, null);
915 topNode.row.Move(prev);
917 projectView.ShowOutputBuildLog(true);
918 projectView.DisplayCompiler(compiler, false);
919 projectView.ProjectUpdateMakefileForAllConfigs(this);
922 eSystem_Delete(project);
934 // This frees contents without freeing the instance
935 // For use from destructor and for file monitor reloading
936 // (To work around JSON loader (LoadProject) always returning a new instance)
939 if(platforms) { platforms.Free(); delete platforms; }
940 if(configurations) { configurations.Free(); delete configurations; }
941 if(files) { files.Free(); delete files; }
942 if(resources) { resources.Free(); delete resources; }
944 delete resourcesPath;
948 delete compilerConfigsDir;
950 delete moduleVersion;
958 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
959 topNode.configurations = null;
960 topNode.platforms = null;
961 topNode.options = null;
966 property ProjectConfig config
972 topNode.info = CopyString(GetConfigName(config));
975 property char * filePath
981 char string[MAX_LOCATION];
982 GetLastDirectory(value, string);
984 topNode.name = CopyString(string);
985 StripExtension(string);
987 name = CopyString(string);
988 StripLastDirectory(value, string);
990 topNode.path = CopyString(string);
992 filePath = CopyString(value);
997 TargetTypes GetTargetType(ProjectConfig config)
999 TargetTypes targetType = localTargetType;
1003 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1006 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1008 PlatformOptions projectPOs, configPOs;
1009 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1010 if(platformTargetType)
1017 char * GetObjDirExpression(ProjectConfig config)
1019 // TODO: Support platform options
1020 char * expression = localObjectsDirectory;
1022 expression = settingsObjectsDirectory;
1026 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1028 char * expression = GetObjDirExpression(config);
1029 DirExpression objDir { type = intermediateObjectsDir };
1030 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1034 char * GetTargetDirExpression(ProjectConfig config)
1036 // TODO: Support platform options
1037 char * expression = localTargetDirectory;
1039 expression = settingsTargetDirectory;
1043 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1045 char * expression = GetTargetDirExpression(config);
1046 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1047 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1051 WarningsOption GetWarnings(ProjectConfig config)
1053 WarningsOption warnings = localWarnings;
1057 bool GetDebug(ProjectConfig config)
1059 SetBool debug = localDebug;
1060 return debug == true;
1063 bool GetMemoryGuard(ProjectConfig config)
1065 SetBool memoryGuard = localMemoryGuard;
1066 return memoryGuard == true;
1069 bool GetNoLineNumbers(ProjectConfig config)
1071 SetBool noLineNumbers = localNoLineNumbers;
1072 return noLineNumbers == true;
1075 bool GetProfile(ProjectConfig config)
1077 SetBool profile = localProfile;
1078 return profile == true;
1081 OptimizationStrategy GetOptimization(ProjectConfig config)
1083 OptimizationStrategy optimization = localOptimization;
1084 return optimization;
1087 bool GetFastMath(ProjectConfig config)
1089 SetBool fastMath = localFastMath;
1090 return fastMath == true;
1093 String GetDefaultNameSpace(ProjectConfig config)
1095 String defaultNameSpace = localDefaultNameSpace;
1096 return defaultNameSpace;
1099 bool GetStrictNameSpaces(ProjectConfig config)
1101 SetBool strictNameSpaces = localStrictNameSpaces;
1102 return strictNameSpaces == true;
1105 String GetTargetFileName(ProjectConfig config)
1107 String targetFileName = localTargetFileName;
1108 return targetFileName;
1111 //String targetDirectory;
1112 //String objectsDirectory;
1113 bool GetConsole(ProjectConfig config)
1115 SetBool console = localConsole;
1116 return console == true;
1119 bool GetCompress(ProjectConfig config)
1121 SetBool compress = localCompress;
1122 return compress == true;
1124 //SetBool excludeFromBuild;
1126 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1128 #ifndef MAKEFILE_GENERATOR
1129 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1133 bool GetConfigIsInDebugSession(ProjectConfig config)
1135 #ifndef MAKEFILE_GENERATOR
1136 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1140 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1142 #ifndef MAKEFILE_GENERATOR
1143 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1147 #ifndef MAKEFILE_GENERATOR
1148 bool Save(char * fileName)
1151 /*char output[MAX_LOCATION];
1152 ChangeExtension(fileName, "json", output);
1153 f = FileOpen(output, write);*/
1154 f = FileOpen(fileName, write);
1157 files = topNode.files;
1158 resources = resNode.files;
1159 resourcesPath = resNode.path;
1161 files.Remove(resNode);
1164 WriteJSONObject(f, class(Project), this, 0);
1170 resourcesPath = null;
1177 // This method is only called from Debugger, should be moved to Debugger class?
1178 #ifndef MAKEFILE_GENERATOR
1179 bool GetRelativePath(char * filePath, char * relativePath)
1182 char moduleName[MAX_FILENAME];
1183 GetLastDirectory(filePath, moduleName);
1184 // try with workspace dir first?
1185 if((node = topNode.Find(moduleName, false)))
1187 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1188 PathCatSlash(relativePath, node.name);
1193 // Tweak for automatically resolving symbol loader modules
1194 char * sl = strstr(moduleName, ".main.ec");
1195 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1197 char objDir[MAX_LOCATION];
1198 DirExpression objDirExp;
1199 CompilerConfig compiler = ide.debugger.currentCompiler;
1200 ProjectConfig config = ide.debugger.prjConfig;
1201 int bitDepth = ide.debugger.bitDepth;
1202 // This is not perfect, as multiple source files exist for the symbol loader module...
1203 // We try to set it in the debug config object directory.
1204 if(!compiler || !config)
1206 // If we're not currently debugging, set a breakpoint in the active compiler/config
1207 compiler = GetCompilerConfig();
1208 config = this.config;
1209 // If the current config is not debuggable, set it in the first debuggable config found
1210 if(config && !config.options.debug)
1212 for(c : configurations; c.options.debug)
1219 objDirExp = GetObjDir(compiler, config, bitDepth);
1220 strcpy(objDir, objDirExp.dir);
1222 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1223 ReplaceSpaces(relativePath, objDir);
1225 PathCatSlash(relativePath, moduleName);
1229 // WARNING: On failure, relative path is uninitialized
1234 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1236 TargetTypes targetType = GetTargetType(config);
1237 String targetFileName = GetTargetFileName(config);
1238 if(targetType == staticLibrary)
1240 PathCatSlash(string, "lib");
1241 strcat(string, targetFileName);
1243 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1245 PathCatSlash(string, "lib");
1246 strcat(string, targetFileName);
1249 PathCatSlash(string, targetFileName);
1254 if(compiler.targetPlatform == win32)
1255 strcat(string, ".exe");
1258 if(compiler.targetPlatform == win32)
1259 strcat(string, ".dll");
1260 else if(compiler.targetPlatform == apple)
1261 strcat(string, ".dylib");
1263 strcat(string, ".so");
1264 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1266 strcat(string, ".");
1267 strcat(string, moduleVersion);
1271 strcat(string, ".a");
1276 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1278 bool result = false;
1279 char temp[MAX_LOCATION];
1280 strcpy(cfDir, topNode.path);
1281 if(compilerConfigsDir && compilerConfigsDir[0])
1283 PathCatSlash(cfDir, compilerConfigsDir);
1288 strcpy(temp, cfDir);
1289 // Using a relative path makes it less likely to run into spaces issues
1290 // Even with escaped spaces, there still seems to be issues including a config file
1291 // in a path containing spaces
1293 MakePathRelative(temp, topNode.path, cfDir);
1296 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1300 strcpy(temp, cfDir);
1301 ReplaceSpaces(cfDir, temp);
1306 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1308 char temp[MAX_LOCATION];
1309 bool result = false;
1310 strcpy(cfDir, topNode.path);
1311 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1313 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1318 // Default to <ProjectDir>/.configs if unset
1319 PathCatSlash(cfDir, ".configs");
1324 strcpy(temp, cfDir);
1325 // Using a relative path makes it less likely to run into spaces issues
1326 // Even with escaped spaces, there still seems to be issues including a config file
1327 // in a path containing spaces
1328 if(IsPathInsideOf(cfDir, topNode.path))
1329 MakePathRelative(temp, topNode.path, cfDir);
1331 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1335 strcpy(temp, cfDir);
1336 ReplaceSpaces(cfDir, temp);
1341 void CatMakeFileName(char * string, ProjectConfig config)
1343 char projectName[MAX_LOCATION];
1344 strcpy(projectName, name);
1345 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1348 #ifndef MAKEFILE_GENERATOR
1349 void MarkChanges(ProjectNode node)
1351 for(cfg : topNode.configurations)
1353 ProjectConfig c = null;
1354 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1356 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1357 (!c.options || !cfg.options)))
1358 cfg.symbolGenModified = true;
1359 if(c && ((c.options && cfg.options &&
1360 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1361 || (!c.options || !cfg.options)))
1362 cfg.linkingModified = true;
1364 cfg.makingModified = true;
1368 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1370 for(cfg : configurations)
1373 cfg.makingModified = true;
1375 cfg.compilingModified = true;
1377 cfg.linkingModified = true;
1379 cfg.symbolGenModified = true;
1381 if(compiling || linking)
1383 ide.projectView.modifiedDocument = true;
1384 ide.workspace.modified = true;
1388 void RotateActiveConfig(bool forward)
1390 if(configurations.first && configurations.last != configurations.first)
1392 Iterator<ProjectConfig> cfg { configurations };
1393 while(forward ? cfg.Next() : cfg.Prev())
1394 if(cfg.data == config)
1408 property::config = cfg.data;
1409 ide.UpdateToolBarActiveConfigs(true);
1410 ide.workspace.modified = true;
1411 ide.projectView.Update(null);
1415 bool ProcessPipeOutputRaw(DualPipe f)
1418 while(!f.Eof() && !ide.projectView.stopBuild)
1421 double lastTime = GetTime();
1425 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1427 ide.outputView.buildBox.Logf("%s\n", line);
1429 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1431 //printf("Processing Input...\n");
1432 if(app.ProcessInput(true))
1434 app.UpdateDisplay();
1437 //printf("Waiting...\n");
1440 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1442 if(ide.projectView.stopBuild)
1444 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1447 return !ide.projectView.stopBuild;
1450 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
1451 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1454 bool compiling = false, linking = false, precompiling = false;
1455 int compilingEC = 0;
1456 int numErrors = 0, numWarnings = 0;
1457 bool loggedALine = false;
1458 char * configName = config ? config.name : "Common";
1459 int lenMakeCommand = strlen(compiler.makeCommand);
1462 char moduleName[MAX_FILENAME];
1463 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1465 DynamicString test { };
1466 DynamicString ecp { };
1467 DynamicString ecc { };
1468 DynamicString ecs { };
1469 DynamicString ear { };
1470 DynamicString prefix { };
1471 DynamicString cpp { };
1472 DynamicString cc { };
1473 DynamicString cxx { };
1474 DynamicString strip { };
1475 DynamicString ar { };
1476 DynamicString windres { };
1478 if(bitDepth == 64 && compiler.targetPlatform == win32)
1479 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1480 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1481 gnuToolchainPrefix = "i686-w64-mingw32-";
1483 ecp.concatx(compiler.ecpCommand, " ");
1484 ecc.concatx(compiler.eccCommand, " ");
1485 ecs.concatx(compiler.ecsCommand, " ");
1486 ear.concatx(compiler.earCommand, " ");
1489 compiler.ccacheEnabled ? "ccache " : "",
1490 compiler.distccEnabled ? "distcc " : "",
1491 gnuToolchainPrefix);
1493 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1494 cc.concatx((String)prefix, compiler.ccCommand, " ");
1495 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1497 strip.concatx(gnuToolchainPrefix, "strip ");
1498 ar.concatx(gnuToolchainPrefix, "ar rcs");
1499 windres.concatx(gnuToolchainPrefix, "windres ");
1501 testLen = Max(testLen, ecp.size);
1502 testLen = Max(testLen, ecc.size);
1503 testLen = Max(testLen, ecs.size);
1504 testLen = Max(testLen, ear.size);
1505 testLen = Max(testLen, cpp.size);
1506 testLen = Max(testLen, cc.size);
1507 testLen = Max(testLen, cxx.size);
1508 testLen = Max(testLen, strip.size);
1509 testLen = Max(testLen, ar.size);
1510 testLen = Max(testLen, windres.size);
1511 testLen = Max(testLen, strlen("mkdir "));
1514 while(!f.Eof() && !ide.projectView.stopBuild)
1517 double lastTime = GetTime();
1521 //printf("Peeking and GetLine...\n");
1522 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1524 char * message = null;
1525 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1526 char * from = strstr(line, stringFrom);
1527 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1528 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1530 char * module = strstr(line, "No rule to make target `");
1534 module = strchr(module, '`') + 1;
1535 end = strchr(module, '\'');
1539 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1540 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1546 //ide.outputView.buildBox.Logf("error: %s\n", line);
1550 else if(strstr(test, "mkdir ") == test);
1551 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1552 else if(strstr(test, ear) == test);
1553 else if(strstr(test, strip) == test);
1554 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1557 bool isPrecomp = false;
1560 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1562 module = strstr(line, " -c ");
1563 if(module) module += 4;
1566 else if(strstr(test, ecc) == test)
1568 module = strstr(line, " -c ");
1569 if(module) module += 4;
1570 //module = line + 3;
1571 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1572 compilingEC = 3;//2;
1575 else if(strstr(test, ecp) == test)
1577 // module = line + 8;
1578 module = strstr(line, " -c ");
1579 if(module) module += 4;
1590 if(!compiling && !isPrecomp)
1592 ide.outputView.buildBox.Logf($"Compiling...\n");
1595 else if(!precompiling && isPrecomp)
1597 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1598 precompiling = true;
1600 // Changed escapeBackSlashes here to handle paths with spaces
1601 Tokenize(module, 1, tokens, true); // false);
1602 GetLastDirectory(module, moduleName);
1603 ide.outputView.buildBox.Logf("%s\n", moduleName);
1605 else if((module = strstr(line, " -o ")))
1608 precompiling = false;
1610 ide.outputView.buildBox.Logf($"Linking...\n");
1614 ide.outputView.buildBox.Logf("%s\n", line);
1615 if(strstr(line, "warning:") || strstr(line, "note:"))
1617 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1621 if(compilingEC) compilingEC--;
1623 else if(strstr(test, windres) == test)
1626 module = strstr(line, " ");
1627 if(module) module++;
1631 Tokenize(module, 1, tokens, true);
1632 GetLastDirectory(module, moduleName);
1633 ide.outputView.buildBox.Logf("%s\n", moduleName);
1636 else if(strstr(test, ar) == test)
1637 ide.outputView.buildBox.Logf($"Building library...\n");
1638 else if(strstr(test, ecs) == test)
1639 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1642 if(linking || compiling || precompiling)
1644 char * colon = strstr(line, ":"); //, * bracket;
1645 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1646 colon = strstr(colon + 1, ":");
1649 char * sayError = "";
1650 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1653 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1654 int len = (int)(colon - start);
1655 char ext[MAX_EXTENSION];
1656 len = Min(len, MAX_LOCATION-1);
1657 // Don't be mistaken by the drive letter colon
1659 // TODO: need to fix colon - line gives char *
1660 // warning: incompatible expression colon - line (char *); expected int
1662 strncpy(moduleName, line, (int)(colon - line));
1663 moduleName[colon - line] = '\0';
1665 strncpy(moduleName, start, len);
1666 moduleName[len] = '\0';
1667 // Remove stuff in brackets
1668 //bracket = strstr(moduleName, "(");
1669 //if(bracket) *bracket = '\0';
1671 GetLastDirectory(moduleName, temp);
1672 GetExtension(temp, ext);
1674 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1676 char * cColon = strstr(colon+1, ":");
1677 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1678 cColon = strstr(cColon + 1, ":");
1681 int len = (int)(cColon - (colon+1));
1682 char mName[MAX_LOCATION];
1683 len = Min(len, MAX_LOCATION-1);
1684 strncpy(mName, colon+1, len);
1686 GetLastDirectory(mName, temp);
1687 GetExtension(temp, ext);
1688 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1691 strcpy(moduleName, mName);
1695 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1698 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1700 message = $"Linker Message: ";
1706 message = $"Linker Error";
1709 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1713 if(!strstr(line, "error:"))
1715 message = $"Linker Error: ";
1721 strcpy(temp, topNode.path);
1722 PathCatSlash(temp, moduleName);
1723 MakePathRelative(temp, topNode.path, moduleName);
1725 error = strstr(line, "error:");
1726 if(!message && error && error > colon)
1730 // Silence warnings for compiled eC
1731 char * objDir = strstr(moduleName, objDirExp.dir);
1735 if((pointer = strstr(line, "undefined")) ||
1736 (pointer = strstr(line, "multiple definition")) ||
1737 (pointer = strstr(line, "No such file")) ||
1738 (pointer = strstr(line, "token")))
1740 strncat(moduleName, colon, pointer - colon);
1741 sayError = "error: ";
1746 else if((pointer = strstr(line, "No such file")))
1748 strncat(moduleName, colon, pointer - colon);
1749 sayError = "error: ";
1753 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1755 else if(strstr(line, "warning:"))
1761 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1762 /*else if(this == ide.workspace.projects.firstIterator.data)
1763 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1766 char fullModuleName[MAX_LOCATION];
1767 FileAttribs found = 0;
1768 Project foundProject = this;
1771 char * loc = strstr(moduleName, ":");
1773 strcpy(fullModuleName, topNode.path);
1774 PathCat(fullModuleName, moduleName);
1775 found = FileExists(fullModuleName);
1776 if(!found && !strcmp(ext, "c"))
1778 char ecName[MAX_LOCATION];
1779 ChangeExtension(fullModuleName, "ec", ecName);
1780 found = FileExists(ecName);
1784 char path[MAX_LOCATION];
1785 if(ide && ide.workspace)
1787 for(prj : ide.workspace.projects)
1790 MakePathRelative(fullModuleName, prj.topNode.path, path);
1792 if((node = prj.topNode.FindWithPath(path, false)))
1794 strcpy(fullModuleName, prj.topNode.path);
1795 PathCatSlash(fullModuleName, node.path);
1796 PathCatSlash(fullModuleName, node.name);
1797 found = FileExists(fullModuleName);
1805 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1807 for(prj : ide.workspace.projects)
1810 if((node = prj.topNode.Find(moduleName, false)))
1812 strcpy(fullModuleName, prj.topNode.path);
1813 PathCatSlash(fullModuleName, node.path);
1814 PathCatSlash(fullModuleName, node.name);
1815 found = FileExists(fullModuleName);
1828 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1829 MakeSystemPath(fullModuleName);
1832 strcpy(fullModuleName, moduleName);
1835 strcat(fullModuleName, ":");
1836 strcat(fullModuleName, loc + 1);
1840 fullModuleName[0] = 0;
1841 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1846 ide.outputView.buildBox.Logf("%s\n", line);
1847 linking = compiling = precompiling = false;
1851 ide.outputView.buildBox.Logf("%s\n", line);
1855 //printf("Done getting line\n");
1856 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1858 //printf("Processing Input...\n");
1859 if(app.ProcessInput(true))
1861 app.UpdateDisplay();
1864 //printf("Waiting...\n");
1867 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1869 if(ide.projectView.stopBuild)
1871 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1874 else if(loggedALine || !isARun)
1876 if(f.GetExitCode() && !numErrors)
1878 bool result = f.GetLine(line, sizeof(line)-1);
1879 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1885 char targetFileName[MAX_LOCATION];
1886 targetFileName[0] = '\0';
1887 CatTargetFileName(targetFileName, compiler, config);
1888 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, configName);
1891 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1893 ide.outputView.buildBox.Logf($"no error, ");
1896 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1898 ide.outputView.buildBox.Logf($"no warning\n");
1914 return numErrors == 0 && !ide.projectView.stopBuild;
1917 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1920 int lenMakeCommand = strlen(compiler.makeCommand);
1925 double lastTime = GetTime();
1928 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1930 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1931 else if(strstr(line, "mkdir") == line);
1932 else if(strstr(line, "del") == line);
1933 else if(strstr(line, "rm") == line);
1934 else if(strstr(line, "Could Not Find") == line);
1937 ide.outputView.buildBox.Logf(line);
1938 ide.outputView.buildBox.Logf("\n");
1942 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1944 if(app.ProcessInput(true))
1946 app.UpdateDisplay();
1949 //Sleep(1.0 / PEEK_RESOLUTION);
1953 bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
1955 bool result = false;
1957 char targetFileName[MAX_LOCATION] = "";
1958 DynamicString makeTargets { };
1959 char makeFile[MAX_LOCATION];
1960 char makeFilePath[MAX_LOCATION];
1961 char configName[MAX_LOCATION];
1962 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
1963 PathBackup pathBackup { };
1964 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1965 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1967 bool eC_Debug = mode.eC_ToolsDebug;
1968 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
1969 int numJobs = compiler.numJobs;
1970 char command[MAX_F_STRING*4];
1971 char * compilerName;
1973 compilerName = CopyString(compiler.name);
1974 CamelCase(compilerName);
1976 strcpy(configName, config ? config.name : "Common");
1978 SetPath(false, compiler, config, bitDepth); //true
1979 CatTargetFileName(targetFileName, compiler, config);
1981 strcpy(makeFilePath, topNode.path);
1982 CatMakeFileName(makeFile, config);
1983 PathCatSlash(makeFilePath, makeFile);
1985 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1988 if(compiler.type.isVC)
1990 PrintLn("compiling a single file is not yet supported");
1995 char pushD[MAX_LOCATION];
1996 char cfDir[MAX_LOCATION];
1997 Map<String, NameCollisionInfo> namesInfo { };
1998 GetIDECompilerConfigsDir(cfDir, true, true);
1999 GetWorkingDir(pushD, sizeof(pushD));
2000 ChangeWorkingDir(topNode.path);
2001 // Create object dir if it does not exist already
2002 if(!FileExists(objDirExp.dir).isDirectory)
2004 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2005 compiler.makeCommand, cfDir,
2006 crossCompiling ? " TARGET_PLATFORM=" : "",
2008 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2009 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2011 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2013 ide.outputView.buildBox.Logf("%s\n", command);
2017 ChangeWorkingDir(pushD);
2019 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2020 for(node : onlyNodes)
2022 if(node.GetIsExcluded(config))
2023 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2027 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, mode == cObject ? true : false);
2028 node.GetTargets(config, namesInfo, objDirExp.dir, makeTargets);
2036 if(compiler.type.isVC)
2038 bool result = false;
2039 char oldwd[MAX_LOCATION];
2040 GetWorkingDir(oldwd, sizeof(oldwd));
2041 ChangeWorkingDir(topNode.path);
2043 // TODO: support justPrint
2044 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2046 ide.outputView.buildBox.Logf("%s\n", command);
2047 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2049 ProcessPipeOutputRaw(f);
2053 ChangeWorkingDir(oldwd);
2055 else if(onlyNodes && strlen(makeTargets) == 0)
2057 ide.outputView.buildBox.Log("No targets to compile.\n");
2061 char cfDir[MAX_LOCATION];
2062 GetIDECompilerConfigsDir(cfDir, true, true);
2063 sprintf(command, "%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2064 compiler.makeCommand,
2065 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2067 crossCompiling ? " TARGET_PLATFORM=" : "",
2069 bitDepth ? " ARCH=" : "",
2070 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2071 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2072 compilerName, eC_Debug ? "--always-make " : "", numJobs,
2073 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2074 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2075 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2077 ide.outputView.buildBox.Logf("%s\n", command);
2079 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2087 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2093 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2096 ide.outputView.buildBox.Logf("%s\n", line);
2097 if(!error && !found && strstr(line, "echo ") == line)
2099 strcpy(command, line+5);
2102 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2104 strcpy(command, line);
2114 result = ProcessPipeOutputRaw(f);
2116 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config, bitDepth);
2119 ide.outputView.buildBox.Logf("%s\n", command);
2120 else if(justPrint && found)
2121 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2126 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2131 delete compilerName;
2136 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2138 char makeFile[MAX_LOCATION];
2139 char makeFilePath[MAX_LOCATION];
2140 char command[MAX_LOCATION];
2141 char * compilerName;
2143 PathBackup pathBackup { };
2144 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2145 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2147 compilerName = CopyString(compiler.name);
2148 CamelCase(compilerName);
2150 SetPath(false, compiler, config, bitDepth);
2152 strcpy(makeFilePath, topNode.path);
2153 CatMakeFileName(makeFile, config);
2154 PathCatSlash(makeFilePath, makeFile);
2156 if(compiler.type.isVC)
2158 bool result = false;
2159 char oldwd[MAX_LOCATION];
2160 GetWorkingDir(oldwd, sizeof(oldwd));
2161 ChangeWorkingDir(topNode.path);
2163 // TODO: justPrint support
2164 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2166 ide.outputView.buildBox.Logf("%s\n", command);
2167 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2169 ProcessPipeOutputRaw(f);
2173 ChangeWorkingDir(oldwd);
2178 char cfDir[MAX_LOCATION];
2179 GetIDECompilerConfigsDir(cfDir, true, true);
2180 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2181 compiler.makeCommand, cfDir,
2182 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2183 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2185 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2186 topNode.path, justPrint ? " -n": "", makeFilePath);
2188 ide.outputView.buildBox.Logf("%s\n", command);
2189 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2191 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2192 cleanType == realClean ? $"intermediate objects directory" : $"target",
2193 cleanType == clean ? $" and object files" : "");
2195 ProcessPipeOutputRaw(f);
2197 ProcessCleanPipeOutput(f, compiler, config);
2198 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2199 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2200 cleanType == clean ? $" and object files" : "");
2206 delete compilerName;
2209 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2211 String target = new char[maxPathLen];
2212 char oldDirectory[MAX_LOCATION];
2213 char * executableLauncher = compiler.executableLauncher;
2214 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2215 PathBackup pathBackup { };
2217 // Build(project, ideMain, true, null, false);
2219 strcpy(target, topNode.path);
2220 PathCatSlash(target, targetDirExp.dir);
2221 CatTargetFileName(target, compiler, config);
2222 sprintf(target, "%s %s", target, args);
2223 GetWorkingDir(oldDirectory, MAX_LOCATION);
2225 if(strlen(ide.workspace.debugDir))
2227 char temp[MAX_LOCATION];
2228 strcpy(temp, topNode.path);
2229 PathCatSlash(temp, ide.workspace.debugDir);
2230 ChangeWorkingDir(temp);
2233 ChangeWorkingDir(topNode.path);
2234 // ChangeWorkingDir(topNode.path);
2235 SetPath(true, compiler, config, bitDepth);
2236 if(executableLauncher)
2238 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 2];
2239 prefixedTarget[0] = '\0';
2240 strcat(prefixedTarget, executableLauncher);
2241 strcat(prefixedTarget, " ");
2242 strcat(prefixedTarget, target);
2243 Execute(prefixedTarget);
2244 delete prefixedTarget;
2249 ChangeWorkingDir(oldDirectory);
2252 delete targetDirExp;
2256 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2258 return Build(false, nodes, compiler, config, bitDepth, justPrint, mode);
2262 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2265 if(targetType == staticLibrary || targetType == sharedLibrary)
2266 strcat(fileName, "$(LP)");
2267 // !!! ReplaceSpaces must be done after all PathCat calls !!!
2268 // ReplaceSpaces(s, GetTargetFileName(config));
2269 strcat(fileName, GetTargetFileName(config));
2273 strcat(fileName, "$(E)");
2276 strcat(fileName, "$(SO)$(VER)");
2279 strcat(fileName, "$(A)");
2284 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2286 bool result = false;
2287 char path[MAX_LOCATION];
2289 if(!GetProjectCompilerConfigsDir(path, false, false))
2290 GetIDECompilerConfigsDir(path, false, false);
2292 if(!FileExists(path).isDirectory)
2296 char dirName[MAX_FILENAME];
2297 GetLastDirectory(path, dirName);
2298 if(!strcmp(dirName, ".configs"))
2299 FileSetAttribs(path, FileAttribs { isHidden = true });
2302 PathCatSlash(path, "crossplatform.mk");
2304 if(FileExists(path))
2307 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2310 File f = FileOpen(path, write);
2313 include.Seek(0, start);
2314 for(; !include.Eof(); )
2317 int count = include.Read(buffer, 1, 4096);
2318 f.Write(buffer, 1, count);
2324 if(!altCrossPlatformMk)
2331 bool GenerateCompilerCf(CompilerConfig compiler)
2333 bool result = false;
2334 char path[MAX_LOCATION];
2336 char * compilerName;
2337 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2338 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2339 Platform platform = compiler.targetPlatform;
2341 compilerName = CopyString(compiler.name);
2342 CamelCase(compilerName);
2343 name = PrintString(platform, "-", compilerName, ".cf");
2345 if(!GetProjectCompilerConfigsDir(path, false, false))
2346 GetIDECompilerConfigsDir(path, false, false);
2348 if(!FileExists(path).isDirectory)
2352 char dirName[MAX_FILENAME];
2353 GetLastDirectory(path, dirName);
2354 if(!strcmp(dirName, ".configs"))
2355 FileSetAttribs(path, FileAttribs { isHidden = true });
2358 PathCatSlash(path, name);
2360 if(FileExists(path))
2363 File f = FileOpen(path, write);
2366 if(compiler.environmentVars && compiler.environmentVars.count)
2368 f.Puts("# ENVIRONMENT VARIABLES\n");
2370 for(e : compiler.environmentVars)
2372 f.Printf("export %s := %s\n", e.name, e.string);
2377 f.Puts("# TOOLCHAIN\n");
2380 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2382 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2385 if(compiler.sysroot && compiler.sysroot[0])
2387 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2388 // Moved this to crossplatform.mk
2389 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2393 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2394 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2395 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2396 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2397 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
2398 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);
2399 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);
2400 f.Printf("EAR := %s\n", compiler.earCommand);
2402 f.Puts("AS := $(GCC_PREFIX)as\n");
2403 f.Puts("LD := $(GCC_PREFIX)ld\n");
2404 f.Puts("AR := $(GCC_PREFIX)ar\n");
2405 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2406 f.Puts("ifdef WINDOWS_TARGET\n");
2407 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2408 f.Puts(" ifdef ARCH\n");
2409 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2410 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2412 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2413 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2418 f.Puts("UPX := upx\n");
2421 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2424 f.Puts("EARFLAGS = \n");
2427 f.Puts("ifndef ARCH\n");
2428 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2429 f.Puts(" ifdef WINDOWS_HOST\n");
2430 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2431 f.Puts(" TARGET_ARCH := x86_64\n");
2433 f.Puts(" TARGET_ARCH := i386\n");
2436 f.Puts("endif\n\n");
2438 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2439 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2443 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2447 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2450 if(compiler.includeDirs && compiler.includeDirs.count)
2452 f.Puts("\nCFLAGS +=");
2453 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2456 if(compiler.prepDirectives && compiler.prepDirectives.count)
2458 f.Puts("\nCFLAGS +=");
2459 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2462 if(compiler.libraryDirs && compiler.libraryDirs.count)
2464 f.Puts("\nLDFLAGS +=");
2465 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2466 // We would need a bool option to know whether we want to add to rpath as well...
2467 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
2470 if(compiler.excludeLibs && compiler.excludeLibs.count)
2472 f.Puts("\nEXCLUDED_LIBS =");
2473 for(l : compiler.excludeLibs)
2479 if(compiler.compilerFlags && compiler.compilerFlags.count)
2481 f.Puts("\nCFLAGS +=");
2482 OutputListOption(f, "", compiler.compilerFlags, inPlace, true);
2485 if(compiler.linkerFlags && compiler.linkerFlags.count)
2487 f.Puts("\nLDFLAGS +=");
2488 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
2492 f.Puts("\nOFLAGS += $(LDFLAGS)");
2494 f.Puts("ifdef ARCH_FLAGS\n");
2495 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2496 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2505 delete compilerName;
2509 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2511 bool result = false;
2512 char filePath[MAX_LOCATION];
2513 char makeFile[MAX_LOCATION];
2514 // PathBackup pathBackup { };
2515 // char oldDirectory[MAX_LOCATION];
2518 if(!altMakefilePath)
2520 strcpy(filePath, topNode.path);
2521 CatMakeFileName(makeFile, config);
2522 PathCatSlash(filePath, makeFile);
2525 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2527 /*SetPath(false, compiler, config);
2528 GetWorkingDir(oldDirectory, MAX_LOCATION);
2529 ChangeWorkingDir(topNode.path);*/
2536 char targetDir[MAX_LOCATION];
2537 char objDirExpNoSpaces[MAX_LOCATION];
2538 char objDirNoSpaces[MAX_LOCATION];
2539 char resDirNoSpaces[MAX_LOCATION];
2540 char targetDirExpNoSpaces[MAX_LOCATION];
2541 char fixedModuleName[MAX_FILENAME];
2542 char fixedConfigName[MAX_FILENAME];
2544 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2545 // Non-zero if we're building eC code
2546 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2547 int numCObjects = 0;
2549 int numRCObjects = 0;
2550 bool containsCXX = false; // True if the project contains a C++ file
2551 bool relObjDir, sameOrRelObjTargetDirs;
2552 String objDirExp = GetObjDirExpression(config);
2553 TargetTypes targetType = GetTargetType(config);
2555 char cfDir[MAX_LOCATION];
2556 int objectsParts = 0;
2557 int eCsourcesParts = 0;
2558 int rcSourcesParts = 0;
2559 Array<String> listItems { };
2560 Map<String, int> varStringLenDiffs { };
2561 Map<String, NameCollisionInfo> namesInfo { };
2563 Map<String, int> cflagsVariations { };
2564 Map<intptr, int> nodeCFlagsMapping { };
2566 Map<String, int> ecflagsVariations { };
2567 Map<intptr, int> nodeECFlagsMapping { };
2569 ReplaceSpaces(objDirNoSpaces, objDirExp);
2570 strcpy(targetDir, GetTargetDirExpression(config));
2571 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2573 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2574 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2576 char temp[MAX_LOCATION];
2577 ReplaceSpaces(temp, objDirExpNoSpaces);
2578 strcpy(objDirExpNoSpaces, temp);
2580 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2581 ReplaceSpaces(fixedModuleName, moduleName);
2582 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2583 CamelCase(fixedConfigName);
2585 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2586 relObjDir = lenObjDirExpNoSpaces == 0 ||
2587 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2588 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2589 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2590 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2591 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2593 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2595 f.Puts("# CORE VARIABLES\n\n");
2597 f.Printf("MODULE := %s\n", fixedModuleName);
2598 f.Printf("VERSION := %s\n", property::moduleVersion);
2599 f.Printf("CONFIG := %s\n", fixedConfigName);
2600 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2603 test = GetTargetTypeIsSetByPlatform(config);
2607 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2609 TargetTypes targetType;
2610 PlatformOptions projectPOs, configPOs;
2611 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2612 targetType = platformTargetType;
2618 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2619 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2624 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2629 for(c = 0; c < ifCount; c++)
2635 f.Puts("# FLAGS\n\n");
2637 f.Puts("ECFLAGS =\n");
2638 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2639 f.Puts("PRJ_CFLAGS =\n");
2640 f.Puts("CECFLAGS =\n");
2641 f.Puts("OFLAGS =\n");
2645 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2648 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2649 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2650 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2651 //f.Puts("endif\n");
2654 f.Puts("# INCLUDES\n\n");
2656 if(compilerConfigsDir && compilerConfigsDir[0])
2658 strcpy(cfDir, compilerConfigsDir);
2659 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2664 GetIDECompilerConfigsDir(cfDir, true, true);
2665 // Use CF_DIR environment variable for absolute paths only
2666 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2667 strcpy(cfDir, "$(CF_DIR)");
2670 f.Printf("_CF_DIR = %s\n", cfDir);
2673 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2674 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2677 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2679 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2682 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2685 // test = GetTargetTypeIsSetByPlatform(config);
2687 char target[MAX_LOCATION];
2688 char temp[MAX_LOCATION];
2693 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2695 if(type != targetType)
2700 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2702 GetMakefileTargetFileName(type, target, config);
2703 strcpy(temp, targetDir);
2704 PathCatSlash(temp, target);
2705 ReplaceSpaces(target, temp);
2706 f.Printf("TARGET = %s\n", target);
2711 GetMakefileTargetFileName(targetType, target, config);
2712 strcpy(temp, targetDir);
2713 PathCatSlash(temp, target);
2714 ReplaceSpaces(target, temp);
2715 f.Printf("TARGET = %s\n", target);
2721 for(c = 0; c < ifCount; c++)
2728 // Use something fixed here, to not cause Makefile differences across compilers...
2729 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2730 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2732 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2736 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2738 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2741 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2743 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2744 if(eCsourcesParts > 1)
2746 for(c = 1; c <= eCsourcesParts; c++)
2747 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2751 for(c = 0; c < 5; c++)
2753 if(eCsourcesParts > 1)
2756 f.Printf("%s =", map[c][0]);
2757 for(n = 1; n <= eCsourcesParts; n++)
2758 f.Printf(" $(%s%d)", map[c][0], n);
2760 for(n = 1; n <= eCsourcesParts; n++)
2761 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2763 else if(eCsourcesParts == 1)
2764 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2770 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2773 f.Puts("ifdef WINDOWS_TARGET\n\n");
2775 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2777 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2778 if(rcSourcesParts > 1)
2780 for(c = 1; c <= rcSourcesParts; c++)
2781 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2784 if(rcSourcesParts > 1)
2787 f.Printf("%s =", "RCOBJECTS");
2788 for(n = 1; n <= rcSourcesParts; n++)
2789 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2791 for(n = 1; n <= rcSourcesParts; n++)
2792 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2794 else if(rcSourcesParts == 1)
2795 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2799 f.Puts("RCSOURCES =\n");
2800 f.Puts("RCOBJECTS =\n");
2801 f.Puts("endif\n\n");
2804 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2806 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2807 f.Printf("OBJECTS =%s%s%s%s\n",
2808 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2809 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2810 numRCObjects ? " $(RCOBJECTS)" : "");
2813 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2816 if(numCObjects && numRCObjects)
2817 prefix = "$(ECSOURCES) $(RCSOURCES)";
2818 else if(numCObjects)
2819 prefix = "$(ECSOURCES)";
2822 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2826 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2827 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2829 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2831 if((config && config.options && config.options.libraries) ||
2832 (options && options.libraries))
2834 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2836 if(config && config.options && config.options.libraries)
2837 OutputLibraries(f, config.options.libraries);
2838 else if(options && options.libraries)
2839 OutputLibraries(f, options.libraries);
2845 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2846 cflagsVariations, nodeCFlagsMapping,
2847 ecflagsVariations, nodeECFlagsMapping, null);
2849 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2850 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2852 if(platforms || (config && config.platforms))
2855 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2856 //for(platform = win32; platform <= apple; platform++)
2858 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2859 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2861 PlatformOptions projectPlatformOptions, configPlatformOptions;
2862 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2864 if(projectPlatformOptions || configPlatformOptions)
2869 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2872 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2873 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2875 f.Puts("CFLAGS +=");
2876 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2879 for(s : projectPlatformOptions.options.compilerOptions)
2884 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2887 for(s : configPlatformOptions.options.compilerOptions)
2896 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2897 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2899 f.Puts("OFLAGS +=");
2900 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2902 bool needWl = false;
2904 for(s : projectPlatformOptions.options.linkerOptions)
2906 if(!IsLinkerOption(s))
2914 for(s : projectPlatformOptions.options.linkerOptions)
2915 if(IsLinkerOption(s))
2919 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2921 bool needWl = false;
2923 for(s : configPlatformOptions.options.linkerOptions)
2925 if(IsLinkerOption(s))
2933 for(s : configPlatformOptions.options.linkerOptions)
2934 if(!IsLinkerOption(s))
2942 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2943 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2944 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2945 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2947 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2948 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2949 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2951 f.Puts("OFLAGS +=");
2952 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2953 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2954 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2955 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2959 if((configPlatformOptions && configPlatformOptions.options.libraries))
2961 if(configPlatformOptions.options.libraries.count)
2964 OutputLibraries(f, configPlatformOptions.options.libraries);
2968 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2970 if(projectPlatformOptions.options.libraries.count)
2973 OutputLibraries(f, projectPlatformOptions.options.libraries);
2984 for(c = 0; c < ifCount; c++)
2990 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
2991 (options && options.linkerOptions && options.linkerOptions.count))
2993 f.Puts("OFLAGS +=");
2996 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
2998 bool needWl = false;
2999 for(s : config.options.linkerOptions)
3001 if(!IsLinkerOption(s))
3009 for(s : config.options.linkerOptions)
3010 if(IsLinkerOption(s))
3014 if(options && options.linkerOptions && options.linkerOptions.count)
3016 bool needWl = false;
3017 for(s : options.linkerOptions)
3019 if(!IsLinkerOption(s))
3027 for(s : options.linkerOptions)
3028 if(IsLinkerOption(s))
3036 f.Puts("CECFLAGS += -cpp $(_CPP)");
3040 if(GetProfile(config))
3041 f.Puts("OFLAGS += -pg\n\n");
3043 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3045 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3046 f.Puts("OFLAGS +=");
3047 if(config && config.options && config.options.libraryDirs)
3048 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
3049 if(options && options.libraryDirs)
3050 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
3056 f.Puts("# TARGETS\n");
3059 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3062 f.Puts("objdir:\n");
3064 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3066 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");
3067 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");
3068 //f.Puts("# PRE-BUILD COMMANDS\n");
3069 if(options && options.prebuildCommands)
3071 for(s : options.prebuildCommands)
3072 if(s && s[0]) f.Printf("\t%s\n", s);
3074 if(config && config.options && config.options.prebuildCommands)
3076 for(s : config.options.prebuildCommands)
3077 if(s && s[0]) f.Printf("\t%s\n", s);
3079 if(platforms || (config && config.platforms))
3082 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3083 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3085 PlatformOptions projectPOs, configPOs;
3086 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3088 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3089 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3094 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3096 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3098 for(s : projectPOs.options.prebuildCommands)
3099 if(s && s[0]) f.Printf("\t%s\n", s);
3101 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3103 for(s : configPOs.options.prebuildCommands)
3104 if(s && s[0]) f.Printf("\t%s\n", s);
3111 for(c = 0; c < ifCount; c++)
3117 if(!sameOrRelObjTargetDirs)
3119 f.Puts("targetdir:\n");
3120 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3126 // Main Module (Linking) for ECERE C modules
3127 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3128 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3129 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $@\n",
3130 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3132 // Main Module (Linking) for ECERE C modules
3133 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3134 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3135 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3136 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3137 " -c $(OBJ)$(MODULE).main.ec -o $@ -symbols $(OBJ)\n");
3143 // This would not rebuild the target on updated objects
3144 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3146 // This should fix it for good!
3147 f.Puts("$(SYMBOLS): | objdir\n");
3148 f.Puts("$(OBJECTS): | objdir\n");
3150 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3151 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3152 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3154 f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
3155 f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
3156 OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
3159 f.Puts("ifdef WINDOWS_TARGET\n");
3160 OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
3165 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
3166 OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
3169 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3171 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
3172 if(!GetDebug(config))
3174 f.Puts("ifndef NOSTRIP\n");
3175 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3178 if(GetCompress(config))
3180 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3181 f.Puts("ifdef EXECUTABLE_TARGET\n");
3182 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3185 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3189 if(resNode.files && resNode.files.count && !noResources)
3190 resNode.GenMakefileAddResources(f, resNode.path, config);
3192 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
3194 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3195 f.Puts("ifdef LINUX_TARGET\n");
3196 f.Puts("ifdef LINUX_HOST\n");
3197 // TODO?: support symlinks for longer version numbers
3198 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3199 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3204 //f.Puts("# POST-BUILD COMMANDS\n");
3205 if(options && options.postbuildCommands)
3207 for(s : options.postbuildCommands)
3208 if(s && s[0]) f.Printf("\t%s\n", s);
3210 if(config && config.options && config.options.postbuildCommands)
3212 for(s : config.options.postbuildCommands)
3213 if(s && s[0]) f.Printf("\t%s\n", s);
3215 if(platforms || (config && config.platforms))
3218 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3219 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3221 PlatformOptions projectPOs, configPOs;
3222 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3224 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3225 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3230 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3232 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3234 for(s : projectPOs.options.postbuildCommands)
3235 if(s && s[0]) f.Printf("\t%s\n", s);
3237 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3239 for(s : configPOs.options.postbuildCommands)
3240 if(s && s[0]) f.Printf("\t%s\n", s);
3247 for(c = 0; c < ifCount; c++)
3253 f.Puts("# SYMBOL RULES\n");
3256 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3258 f.Puts("# C OBJECT RULES\n");
3261 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3263 f.Puts("# OBJECT RULES\n");
3265 // todo call this still but only generate rules whith specific options
3266 // see we-have-file-specific-options in ProjectNode.ec
3267 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3270 GenMakefilePrintMainObjectRule(f, config);
3272 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3273 f.Puts("\t$(call rmq,$(TARGET))\n");
3274 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3275 f.Puts("ifdef LINUX_TARGET\n");
3276 f.Puts("ifdef LINUX_HOST\n");
3277 // TODO?: support symlinks for longer version numbers
3278 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3279 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3285 f.Puts("clean: cleantarget\n");
3286 f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3287 OutputCleanActions(f, "_OBJECTS", objectsParts);
3290 f.Puts("ifdef WINDOWS_TARGET\n");
3291 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3296 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)");
3297 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3298 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3299 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3300 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3301 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3305 f.Puts("realclean: cleantarget\n");
3306 f.Puts("\t$(call rmrq,$(OBJ))\n");
3307 if(!sameOrRelObjTargetDirs)
3308 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3311 f.Puts("distclean: cleantarget\n");
3312 if(!sameOrRelObjTargetDirs)
3313 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3315 f.Puts("\t$(call rmrq,obj/)\n");
3321 varStringLenDiffs.Free();
3322 delete varStringLenDiffs;
3326 delete cflagsVariations;
3327 delete nodeCFlagsMapping;
3328 delete ecflagsVariations;
3329 delete nodeECFlagsMapping;
3334 // ChangeWorkingDir(oldDirectory);
3335 // delete pathBackup;
3338 config.makingModified = false;
3342 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3344 char extension[MAX_EXTENSION] = "c";
3345 char modulePath[MAX_LOCATION];
3346 char fixedModuleName[MAX_FILENAME];
3349 char objDirNoSpaces[MAX_LOCATION];
3350 String objDirExp = GetObjDirExpression(config);
3352 ReplaceSpaces(objDirNoSpaces, objDirExp);
3353 ReplaceSpaces(fixedModuleName, moduleName);
3355 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3356 //strcat(fixedModuleName, ".main");
3358 #if 0 // TODO: Fix nospaces stuff
3359 // *** Dependency command ***
3360 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3362 // System Includes (from global settings)
3363 for(item : compiler.dirs[Includes])
3365 strcat(command, " -isystem ");
3366 if(strchr(item.name, ' '))
3368 strcat(command, "\"");
3369 strcat(command, item);
3370 strcat(command, "\"");
3373 strcat(command, item);
3376 for(item = includeDirs.first; item; item = item.next)
3378 strcat(command, " -I");
3379 if(strchr(item.name, ' '))
3381 strcat(command, "\"");
3382 strcat(command, item.name);
3383 strcat(command, "\"");
3386 strcat(command, item.name);
3388 for(item = preprocessorDefs.first; item; item = item.next)
3390 strcat(command, " -D");
3391 strcat(command, item.name);
3395 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
3399 bool firstLine = true;
3401 // To do some time: auto save external dependencies?
3404 if(dep.GetLine(line, sizeof(line)-1))
3408 char * colon = strstr(line, ":");
3409 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3423 // If we failed to generate dependencies...
3427 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3428 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $@\n", extension);
3436 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3439 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3441 for(v : cflagsVariations)
3446 f.Printf("%s +=", variableName);
3448 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3449 f.Puts(&v ? &v : "");
3459 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3460 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3462 *projectPlatformOptions = null;
3463 *configPlatformOptions = null;
3468 if(!strcmpi(p.name, platform))
3470 *projectPlatformOptions = p;
3475 if(config && config.platforms)
3477 for(p : config.platforms)
3479 if(!strcmpi(p.name, platform))
3481 *configPlatformOptions = p;
3489 Project LegacyBinaryLoadProject(File f, char * filePath)
3491 Project project = null;
3492 char signature[sizeof(epjSignature)];
3494 f.Read(signature, sizeof(signature), 1);
3495 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3497 char topNodePath[MAX_LOCATION];
3498 /*ProjectConfig newConfig
3500 name = CopyString("Default");
3501 makingModified = true;
3502 compilingModified = true;
3503 linkingModified = true;
3507 project = Project { options = { } };
3508 LegacyBinaryLoadNode(project.topNode, f);
3509 delete project.topNode.path;
3510 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3511 MakeSlashPath(topNodePath);
3513 PathCatSlash(topNodePath, filePath);
3514 project.filePath = topNodePath;
3516 /* THIS IS ALREADY DONE BY filePath property
3517 StripLastDirectory(topNodePath, topNodePath);
3518 project.topNode.path = CopyString(topNodePath);
3520 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3522 // newConfig.options.defaultNameSpace = "";
3523 /*newConfig.objDir.dir = "obj";
3524 newConfig.targetDir.dir = "";*/
3526 //project.configurations = { [ newConfig ] };
3527 //project.config = newConfig;
3534 String targetFileName, targetDirectory, objectsDirectory;
3536 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3537 f.Read(&temp, sizeof(int),1);
3540 case 0: project.options.targetType = executable; break;
3541 case 1: project.options.targetType = sharedLibrary; break;
3542 case 2: project.options.targetType = staticLibrary; break;
3545 f.Read(&len, sizeof(int),1);
3546 targetFileName = new char[len+1];
3547 f.Read(targetFileName, sizeof(char), len+1);
3548 project.options.targetFileName = targetFileName;
3549 delete targetFileName;
3551 f.Read(&len, sizeof(int),1);
3552 targetDirectory = new char[len+1];
3553 f.Read(targetDirectory, sizeof(char), len+1);
3554 project.options.targetDirectory = targetDirectory;
3555 delete targetDirectory;
3557 f.Read(&len, sizeof(int),1);
3558 objectsDirectory = new byte[len+1];
3559 f.Read(objectsDirectory, sizeof(char), len+1);
3560 project.options.objectsDirectory = objectsDirectory;
3561 delete objectsDirectory;
3563 f.Read(&temp, sizeof(int),1);
3564 project./*config.*/options.debug = temp ? true : false;
3565 f.Read(&temp, sizeof(int),1);
3566 project./*config.*/options.optimization = temp ? speed : none;
3567 f.Read(&temp, sizeof(int),1);
3568 project./*config.*/options.profile = temp ? true : false;
3569 f.Read(&temp, sizeof(int),1);
3570 project.options.warnings = temp ? all : unset;
3572 f.Read(&count, sizeof(int),1);
3575 project.options.includeDirs = { };
3576 for(c = 0; c < count; c++)
3579 f.Read(&len, sizeof(int),1);
3580 name = new char[len+1];
3581 f.Read(name, sizeof(char), len+1);
3582 project.options.includeDirs.Add(name);
3586 f.Read(&count, sizeof(int),1);
3589 project.options.libraryDirs = { };
3590 for(c = 0; c < count; c++)
3593 f.Read(&len, sizeof(int),1);
3594 name = new char[len+1];
3595 f.Read(name, sizeof(char), len+1);
3596 project.options.libraryDirs.Add(name);
3600 f.Read(&count, sizeof(int),1);
3603 project.options.libraries = { };
3604 for(c = 0; c < count; c++)
3607 f.Read(&len, sizeof(int),1);
3608 name = new char[len+1];
3609 f.Read(name, sizeof(char), len+1);
3610 project.options.libraries.Add(name);
3614 f.Read(&count, sizeof(int),1);
3617 project.options.preprocessorDefinitions = { };
3618 for(c = 0; c < count; c++)
3621 f.Read(&len, sizeof(int),1);
3622 name = new char[len+1];
3623 f.Read(name, sizeof(char), len+1);
3624 project.options.preprocessorDefinitions.Add(name);
3628 f.Read(&temp, sizeof(int),1);
3629 project.options.console = temp ? true : false;
3632 for(node : project.topNode.files)
3634 if(node.type == resources)
3636 project.resNode = node;
3646 void ProjectConfig::LegacyProjectConfigLoad(File f)
3654 char subSection[128];
3660 f.GetLine(buffer, 65536 - 1);
3661 TrimLSpaces(buffer, buffer);
3662 TrimRSpaces(buffer, buffer);
3665 if(buffer[0] == '-')
3669 TrimLSpaces(equal, equal);
3670 if(!strcmpi(subSection, "LibraryDirs"))
3672 if(!options.libraryDirs)
3673 options.libraryDirs = { [ CopyString(equal) ] };
3675 options.libraryDirs.Add(CopyString(equal));
3677 else if(!strcmpi(subSection, "IncludeDirs"))
3679 if(!options.includeDirs)
3680 options.includeDirs = { [ CopyString(equal) ] };
3682 options.includeDirs.Add(CopyString(equal));
3685 else if(buffer[0] == '+')
3696 TrimLSpaces(equal, equal);
3697 delete name; name = CopyString(equal); // property::name = equal;
3700 else if(!strcmpi(buffer, "Compiler Options"))
3701 strcpy(section, buffer);
3702 else if(!strcmpi(buffer, "IncludeDirs"))
3703 strcpy(subSection, buffer);
3704 else if(!strcmpi(buffer, "Linker Options"))
3705 strcpy(section, buffer);
3706 else if(!strcmpi(buffer, "LibraryDirs"))
3707 strcpy(subSection, buffer);
3708 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3715 equal = strstr(buffer, "=");
3719 TrimRSpaces(buffer, buffer);
3721 TrimLSpaces(equal, equal);
3722 if(!strcmpi(buffer, "Target Name"))
3723 options.targetFileName = /*CopyString(*/equal/*)*/;
3724 else if(!strcmpi(buffer, "Target Type"))
3726 if(!strcmpi(equal, "Executable"))
3727 options.targetType = executable;
3728 else if(!strcmpi(equal, "Shared"))
3729 options.targetType = sharedLibrary;
3730 else if(!strcmpi(equal, "Static"))
3731 options.targetType = staticLibrary;
3733 options.targetType = executable;
3735 else if(!strcmpi(buffer, "Target Directory"))
3736 options.targetDirectory = /*CopyString(*/equal/*)*/;
3737 else if(!strcmpi(buffer, "Console"))
3738 options.console = ParseTrueFalseValue(equal);
3739 else if(!strcmpi(buffer, "Libraries"))
3741 if(!options.libraries) options.libraries = { };
3742 ParseArrayValue(options.libraries, equal);
3744 else if(!strcmpi(buffer, "Intermediate Directory"))
3745 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3746 else if(!strcmpi(buffer, "Debug"))
3747 options.debug = ParseTrueFalseValue(equal);
3748 else if(!strcmpi(buffer, "Optimize"))
3750 if(!strcmpi(equal, "None"))
3751 options.optimization = none;
3752 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3753 options.optimization = speed;
3754 else if(!strcmpi(equal, "Size"))
3755 options.optimization = size;
3757 options.optimization = none;
3759 else if(!strcmpi(buffer, "Compress"))
3760 options.compress = ParseTrueFalseValue(equal);
3761 else if(!strcmpi(buffer, "Profile"))
3762 options.profile = ParseTrueFalseValue(equal);
3763 else if(!strcmpi(buffer, "AllWarnings"))
3764 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3765 else if(!strcmpi(buffer, "MemoryGuard"))
3766 options.memoryGuard = ParseTrueFalseValue(equal);
3767 else if(!strcmpi(buffer, "Default Name Space"))
3768 options.defaultNameSpace = CopyString(equal);
3769 else if(!strcmpi(buffer, "Strict Name Spaces"))
3770 options.strictNameSpaces = ParseTrueFalseValue(equal);
3771 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3773 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3774 ParseArrayValue(options.preprocessorDefinitions, equal);
3780 if(!options.targetDirectory && options.objectsDirectory)
3781 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3782 //if(!objDir.dir) objDir.dir = "obj";
3783 //if(!targetDir.dir) targetDir.dir = "";
3784 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3785 // if(!defaultNameSpace) property::defaultNameSpace = "";
3786 makingModified = true;
3789 Project LegacyAsciiLoadProject(File f, char * filePath)
3791 Project project = null;
3792 ProjectNode node = null;
3794 char parentPath[MAX_LOCATION];
3795 char section[128] = "";
3796 char subSection[128] = "";
3798 bool configurationsPresent = false;
3808 f.GetLine(buffer, 65536 - 1);
3809 TrimLSpaces(buffer, buffer);
3810 TrimRSpaces(buffer, buffer);
3813 if(buffer[0] == '-' || buffer[0] == '=')
3815 bool simple = buffer[0] == '-';
3818 TrimLSpaces(equal, equal);
3819 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3821 if(!project.config.options.libraryDirs)
3822 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3824 project.config.options.libraryDirs.Add(CopyString(equal));
3826 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3828 if(!project.config.options.includeDirs)
3829 project.config.options.includeDirs = { [ CopyString(equal) ] };
3831 project.config.options.includeDirs.Add(CopyString(equal));
3833 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3835 len = strlen(equal);
3838 char temp[MAX_LOCATION];
3839 ProjectNode child { };
3840 // We don't need to do this anymore, fileName is just a property that sets name & path
3841 // child.fileName = CopyString(equal);
3844 child.name = CopyString(equal);
3845 child.path = CopyString(parentPath);
3849 GetLastDirectory(equal, temp);
3850 child.name = CopyString(temp);
3851 StripLastDirectory(equal, temp);
3852 child.path = CopyString(temp);
3854 child.nodeType = file;
3855 child.parent = parent;
3856 child.indent = parent.indent + 1;
3858 child.icon = NodeIcons::SelectFileIcon(child.name);
3859 parent.files.Add(child);
3865 StripLastDirectory(parentPath, parentPath);
3866 parent = parent.parent;
3870 else if(buffer[0] == '+')
3874 TrimLSpaces(equal, equal);
3875 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3877 char temp[MAX_LOCATION];
3878 ProjectNode child { };
3879 // NEW: Folders now have a path set like files
3880 child.name = CopyString(equal);
3881 strcpy(temp, parentPath);
3882 PathCatSlash(temp, child.name);
3883 child.path = CopyString(temp);
3885 child.parent = parent;
3886 child.indent = parent.indent + 1;
3887 child.type = folder;
3888 child.nodeType = folder;
3890 child.icon = folder;
3891 PathCatSlash(parentPath, child.name);
3892 parent.files.Add(child);
3897 else if(!strcmpi(section, "Configurations"))
3899 ProjectConfig newConfig
3901 makingModified = true;
3905 LegacyProjectConfigLoad(newConfig, f);
3906 project.configurations.Add(newConfig);
3909 else if(!strcmpi(buffer, "ECERE Project File"));
3910 else if(!strcmpi(buffer, "Version 0a"))
3911 ; //strcpy(version, "0a");
3912 else if(!strcmpi(buffer, "Version 0.1a"))
3913 ; //strcpy(version, "0.1a");
3914 else if(!strcmpi(buffer, "Configurations"))
3916 project.configurations.Free();
3917 project.config = null;
3918 strcpy(section, buffer);
3919 configurationsPresent = true;
3921 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3923 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3924 char topNodePath[MAX_LOCATION];
3925 // newConfig.defaultNameSpace = "";
3926 //newConfig.objDir.dir = "obj";
3927 //newConfig.targetDir.dir = "";
3928 project = Project { /*options = { }*/ };
3929 project.configurations = { [ newConfig ] };
3930 project.config = newConfig;
3931 // if(project.topNode.path) delete project.topNode.path;
3932 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3933 MakeSlashPath(topNodePath);
3934 PathCatSlash(topNodePath, filePath);
3935 project.filePath = topNodePath;
3936 parentPath[0] = '\0';
3937 parent = project.topNode;
3939 strcpy(section, "Target");
3944 if(equal[0] == '\"')
3946 StripQuotes(equal, equal);
3947 delete project.moduleName; project.moduleName = CopyString(equal);
3951 else if(!strcmpi(buffer, "Compiler Options"));
3952 else if(!strcmpi(buffer, "IncludeDirs"))
3953 strcpy(subSection, buffer);
3954 else if(!strcmpi(buffer, "Linker Options"));
3955 else if(!strcmpi(buffer, "LibraryDirs"))
3956 strcpy(subSection, buffer);
3957 else if(!strcmpi(buffer, "Files"))
3959 strcpy(section, "Target");
3960 strcpy(subSection, buffer);
3962 else if(!strcmpi(buffer, "Resources"))
3964 ProjectNode child { };
3965 parent.files.Add(child);
3966 child.parent = parent;
3967 child.indent = parent.indent + 1;
3968 child.name = CopyString(buffer);
3969 child.path = CopyString("");
3970 child.type = resources;
3972 child.icon = archiveFile;
3973 project.resNode = child;
3976 strcpy(subSection, buffer);
3980 equal = strstr(buffer, "=");
3984 TrimRSpaces(buffer, buffer);
3986 TrimLSpaces(equal, equal);
3988 if(!strcmpi(section, "Target"))
3990 if(!strcmpi(buffer, "Build Exclusions"))
3992 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3994 /*if(node && node.type != NodeTypes::project)
3995 ParseListValue(node.buildExclusions, equal);*/
3998 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4000 delete project.resNode.path;
4001 project.resNode.path = CopyString(equal);
4002 PathCatSlash(parentPath, equal);
4006 else if(!strcmpi(buffer, "Intermediate Directory"))
4007 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4008 else if(!strcmpi(buffer, "Debug"))
4009 project.config.options.debug = ParseTrueFalseValue(equal);
4010 else if(!strcmpi(buffer, "Optimize"))
4012 if(!strcmpi(equal, "None"))
4013 project.config.options.optimization = none;
4014 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4015 project.config.options.optimization = speed;
4016 else if(!strcmpi(equal, "Size"))
4017 project.config.options.optimization = size;
4019 project.config.options.optimization = none;
4021 else if(!strcmpi(buffer, "Profile"))
4022 project.config.options.profile = ParseTrueFalseValue(equal);
4023 else if(!strcmpi(buffer, "MemoryGuard"))
4024 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4027 if(!project.options) project.options = { };
4029 // Project Wide Settings (All configs)
4030 if(!strcmpi(buffer, "Target Name"))
4031 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4032 else if(!strcmpi(buffer, "Target Type"))
4034 if(!strcmpi(equal, "Executable"))
4035 project.options.targetType = executable;
4036 else if(!strcmpi(equal, "Shared"))
4037 project.options.targetType = sharedLibrary;
4038 else if(!strcmpi(equal, "Static"))
4039 project.options.targetType = staticLibrary;
4041 project.options.targetType = executable;
4043 else if(!strcmpi(buffer, "Target Directory"))
4044 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4045 else if(!strcmpi(buffer, "Console"))
4046 project.options.console = ParseTrueFalseValue(equal);
4047 else if(!strcmpi(buffer, "Libraries"))
4049 if(!project.options.libraries) project.options.libraries = { };
4050 ParseArrayValue(project.options.libraries, equal);
4052 else if(!strcmpi(buffer, "AllWarnings"))
4053 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4054 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4056 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4058 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4059 ParseListValue(node.preprocessorDefs, equal);*/
4063 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4064 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4075 SplitPlatformLibraries(project);
4077 if(configurationsPresent)
4078 CombineIdenticalConfigOptions(project);
4082 void SplitPlatformLibraries(Project project)
4084 if(project && project.configurations)
4086 for(cfg : project.configurations)
4088 if(cfg.options.libraries && cfg.options.libraries.count)
4090 Iterator<String> it { cfg.options.libraries };
4094 char * platformName = strstr(l, ":");
4097 PlatformOptions platform = null;
4099 if(!cfg.platforms) cfg.platforms = { };
4100 for(p : cfg.platforms)
4102 if(!strcmpi(platformName, p.name))
4110 platform = { name = CopyString(platformName), options = { libraries = { } } };
4111 cfg.platforms.Add(platform);
4113 *(platformName-1) = 0;
4114 platform.options.libraries.Add(CopyString(l));
4116 cfg.options.libraries.Delete(it.pointer);
4125 void CombineIdenticalConfigOptions(Project project)
4127 if(project && project.configurations && project.configurations.count)
4130 ProjectOptions nullOptions { };
4131 ProjectConfig firstConfig = null;
4132 for(cfg : project.configurations)
4134 if(cfg.options.targetType != staticLibrary)
4141 firstConfig = project.configurations.firstIterator.data;
4143 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4145 if(!member.isProperty)
4147 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4152 for(cfg : project.configurations)
4154 if(cfg != firstConfig)
4156 if(cfg.options.targetType != staticLibrary)
4160 if(type.type == noHeadClass || type.type == normalClass)
4162 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4163 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4164 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4168 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4169 (byte *)firstConfig.options + member.offset + member._class.offset,
4170 (byte *)cfg.options + member.offset + member._class.offset);
4182 if(type.type == noHeadClass || type.type == normalClass)
4184 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4185 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4186 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4191 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4192 (byte *)firstConfig.options + member.offset + member._class.offset,
4193 (byte *)nullOptions + member.offset + member._class.offset))
4197 if(!project.options) project.options = { };
4199 /*if(type.type == noHeadClass || type.type == normalClass)
4201 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4202 (byte *)project.options + member.offset + member._class.offset,
4203 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4207 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4208 // TOFIX: ListBox::SetData / OnCopy mess
4209 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4210 (byte *)project.options + member.offset + member._class.offset,
4211 (type.typeSize > 4) ? address :
4212 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4213 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4214 (void *)*(byte *)address )));
4217 (byte *)project.options + member.offset + member._class.offset,
4218 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4220 for(cfg : project.configurations)
4222 if(cfg.options.targetType == staticLibrary)
4226 if(type.type == noHeadClass || type.type == normalClass)
4228 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4229 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4230 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4234 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4235 (byte *)firstConfig.options + member.offset + member._class.offset,
4236 (byte *)cfg.options + member.offset + member._class.offset);
4241 if(cfg != firstConfig)
4243 if(type.type == noHeadClass || type.type == normalClass)
4245 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4246 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4250 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4251 (byte *)cfg.options + member.offset + member._class.offset);
4253 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4256 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4263 // Compare Platform Specific Settings
4266 for(cfg : project.configurations)
4268 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4269 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4275 if(same && firstConfig.platforms)
4277 for(cfg : project.configurations)
4279 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4281 if(cfg != firstConfig)
4283 cfg.platforms.Free();
4284 delete cfg.platforms;
4287 project.platforms = firstConfig.platforms;
4288 firstConfig.platforms = null;
4292 // Static libraries can't contain libraries
4293 for(cfg : project.configurations)
4295 if(cfg.options.targetType == staticLibrary)
4297 if(!cfg.options.libraries) cfg.options.libraries = { };
4298 cfg.options.libraries.Free();
4304 Project LoadProject(char * filePath, char * activeConfigName)
4306 Project project = null;
4307 File f = FileOpen(filePath, read);
4310 project = LegacyBinaryLoadProject(f, filePath);
4313 JSONParser parser { f = f };
4314 JSONResult result = parser.GetObject(class(Project), &project);
4317 char insidePath[MAX_LOCATION];
4319 delete project.topNode.files;
4320 if(!project.files) project.files = { };
4321 project.topNode.files = project.files;
4324 char topNodePath[MAX_LOCATION];
4325 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4326 MakeSlashPath(topNodePath);
4327 PathCatSlash(topNodePath, filePath);
4328 project.filePath = topNodePath;//filePath;
4331 project.topNode.FixupNode(insidePath);
4333 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4334 delete project.resNode.path;
4335 project.resNode.path = project.resourcesPath;
4336 project.resourcesPath = null;
4337 project.resNode.nodeType = (ProjectNodeType)-1;
4338 delete project.resNode.files;
4339 project.resNode.files = project.resources;
4340 project.files = null;
4341 project.resources = null;
4342 if(!project.configurations) project.configurations = { };
4344 project.resNode.FixupNode(insidePath);
4349 project = LegacyAsciiLoadProject(f, filePath);
4355 if(!project.options) project.options = { };
4356 if(activeConfigName && activeConfigName[0] && project.configurations)
4358 for(cfg : project.configurations)
4360 if(!strcmpi(cfg.name, activeConfigName))
4362 project.config = cfg;
4367 if(!project.config && project.configurations)
4368 project.config = project.configurations.firstIterator.data;
4370 if(!project.resNode)
4372 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4375 if(!project.moduleName)
4376 project.moduleName = CopyString(project.name);
4377 if(project.config &&
4378 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4379 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4381 //delete project.config.options.targetFileName;
4383 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4384 project.config.options.optimization = none;
4385 project.config.options.debug = true;
4386 //project.config.options.warnings = unset;
4387 project.config.options.memoryGuard = false;
4388 project.config.compilingModified = true;
4389 project.config.linkingModified = true;
4391 else if(!project.topNode.name && project.config)
4393 project.topNode.name = CopyString(project.config.options.targetFileName);
4396 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4397 project.topNode.configurations = project.configurations;
4398 project.topNode.platforms = project.platforms;
4399 project.topNode.options = project.options;*/