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 String lastBuildConfigName;
852 String lastBuildCompilerName;
854 Map<String, NameCollisionInfo> lastBuildNamesInfo;
856 #ifndef MAKEFILE_GENERATOR
857 FileMonitor fileMonitor
859 this, FileChange { modified = true };
860 bool OnFileNotify(FileChange action, char * param)
862 fileMonitor.StopMonitoring();
863 if(OnProjectModified(action, param))
864 fileMonitor.StartMonitoring();
869 bool StartMonitoring()
871 fileMonitor.fileName = filePath;
872 fileMonitor.StartMonitoring();
876 bool StopMonitoring()
878 fileMonitor.StopMonitoring();
882 bool OnProjectModified(FileChange fileChange, char * param)
885 sprintf(temp, $"The project %s was modified by another application.\n"
886 "Would you like to reload it and lose your changes?", name);
887 if(MessageBox { type = yesNo, master = ide,
888 text = $"Project has been modified", contents = temp }.Modal() == yes)
890 Project project = LoadProject(filePath, config.name);
893 ProjectView projectView = ide.projectView;
894 DataRow prev = topNode.row ? topNode.row.previous : null;
895 FileMonitor fm = fileMonitor;
896 bool confirmation = true;
900 if(projectView.projectSettingsDialog)
902 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
904 projectView.projectSettingsDialog.Destroy(0);
907 projectView.DeleteNode(topNode);
914 topNode.project = this;
918 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
919 projectView.AddNode(topNode, null);
920 topNode.row.Move(prev);
922 projectView.ShowOutputBuildLog(true);
923 projectView.DisplayCompiler(compiler, false);
924 projectView.ProjectUpdateMakefileForAllConfigs(this);
927 eSystem_Delete(project);
939 // This frees contents without freeing the instance
940 // For use from destructor and for file monitor reloading
941 // (To work around JSON loader (LoadProject) always returning a new instance)
944 if(platforms) { platforms.Free(); delete platforms; }
945 if(configurations) { configurations.Free(); delete configurations; }
946 if(files) { files.Free(); delete files; }
947 if(resources) { resources.Free(); delete resources; }
949 delete resourcesPath;
953 delete compilerConfigsDir;
955 delete moduleVersion;
959 delete lastBuildConfigName;
960 delete lastBuildCompilerName;
961 if(lastBuildNamesInfo) { lastBuildNamesInfo.Free(); delete lastBuildNamesInfo; }
966 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
967 topNode.configurations = null;
968 topNode.platforms = null;
969 topNode.options = null;
974 property ProjectConfig config
980 topNode.info = CopyString(GetConfigName(config));
984 property char * filePath
990 char string[MAX_LOCATION];
991 GetLastDirectory(value, string);
993 topNode.name = CopyString(string);
994 StripExtension(string);
996 name = CopyString(string);
997 StripLastDirectory(value, string);
999 topNode.path = CopyString(string);
1001 filePath = CopyString(value);
1006 ProjectConfig GetConfig(char * configName)
1008 ProjectConfig result = null;
1009 if(configName && configName[0] && configurations.count)
1011 for(cfg : configurations; !strcmpi(cfg.name, configName))
1020 ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
1023 if(!lastBuildNamesInfo)
1024 ProjectLoadLastBuildNamesInfo(this, config);
1025 result = topNode.FindByObjectFileName(fileName, type, dotMain, lastBuildNamesInfo);
1029 TargetTypes GetTargetType(ProjectConfig config)
1031 TargetTypes targetType = localTargetType;
1035 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1038 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1040 PlatformOptions projectPOs, configPOs;
1041 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1042 if(platformTargetType)
1048 char * GetObjDirExpression(ProjectConfig config)
1050 // TODO: Support platform options
1051 char * expression = localObjectsDirectory;
1053 expression = settingsObjectsDirectory;
1057 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1059 char * expression = GetObjDirExpression(config);
1060 DirExpression objDir { type = intermediateObjectsDir };
1061 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1065 char * GetTargetDirExpression(ProjectConfig config)
1067 // TODO: Support platform options
1068 char * expression = localTargetDirectory;
1070 expression = settingsTargetDirectory;
1074 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1076 char * expression = GetTargetDirExpression(config);
1077 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1078 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1082 WarningsOption GetWarnings(ProjectConfig config)
1084 WarningsOption warnings = localWarnings;
1088 bool GetDebug(ProjectConfig config)
1090 SetBool debug = localDebug;
1091 return debug == true;
1094 bool GetMemoryGuard(ProjectConfig config)
1096 SetBool memoryGuard = localMemoryGuard;
1097 return memoryGuard == true;
1100 bool GetNoLineNumbers(ProjectConfig config)
1102 SetBool noLineNumbers = localNoLineNumbers;
1103 return noLineNumbers == true;
1106 bool GetProfile(ProjectConfig config)
1108 SetBool profile = localProfile;
1109 return profile == true;
1112 OptimizationStrategy GetOptimization(ProjectConfig config)
1114 OptimizationStrategy optimization = localOptimization;
1115 return optimization;
1118 bool GetFastMath(ProjectConfig config)
1120 SetBool fastMath = localFastMath;
1121 return fastMath == true;
1124 String GetDefaultNameSpace(ProjectConfig config)
1126 String defaultNameSpace = localDefaultNameSpace;
1127 return defaultNameSpace;
1130 bool GetStrictNameSpaces(ProjectConfig config)
1132 SetBool strictNameSpaces = localStrictNameSpaces;
1133 return strictNameSpaces == true;
1136 String GetTargetFileName(ProjectConfig config)
1138 String targetFileName = localTargetFileName;
1139 return targetFileName;
1142 //String targetDirectory;
1143 //String objectsDirectory;
1144 bool GetConsole(ProjectConfig config)
1146 SetBool console = localConsole;
1147 return console == true;
1150 bool GetCompress(ProjectConfig config)
1152 SetBool compress = localCompress;
1153 return compress == true;
1155 //SetBool excludeFromBuild;
1157 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1159 #ifndef MAKEFILE_GENERATOR
1160 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1164 bool GetConfigIsInDebugSession(ProjectConfig config)
1166 #ifndef MAKEFILE_GENERATOR
1167 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1171 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1173 #ifndef MAKEFILE_GENERATOR
1174 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1178 #ifndef MAKEFILE_GENERATOR
1179 bool Save(char * fileName)
1182 /*char output[MAX_LOCATION];
1183 ChangeExtension(fileName, "json", output);
1184 f = FileOpen(output, write);*/
1185 f = FileOpen(fileName, write);
1188 files = topNode.files;
1189 resources = resNode.files;
1190 resourcesPath = resNode.path;
1192 files.Remove(resNode);
1195 WriteJSONObject(f, class(Project), this, 0);
1201 resourcesPath = null;
1208 // This method is only called from Debugger, should be moved to Debugger class?
1209 #ifndef MAKEFILE_GENERATOR
1210 bool GetRelativePath(char * filePath, char * relativePath)
1213 char moduleName[MAX_FILENAME];
1214 GetLastDirectory(filePath, moduleName);
1215 // try with workspace dir first?
1216 if((node = topNode.Find(moduleName, false)))
1218 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1219 PathCatSlash(relativePath, node.name);
1224 // Tweak for automatically resolving symbol loader modules
1225 char * sl = strstr(moduleName, ".main.ec");
1226 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1228 char objDir[MAX_LOCATION];
1229 DirExpression objDirExp;
1230 CompilerConfig compiler = ide.debugger.currentCompiler;
1231 ProjectConfig config = ide.debugger.prjConfig;
1232 int bitDepth = ide.debugger.bitDepth;
1233 // This is not perfect, as multiple source files exist for the symbol loader module...
1234 // We try to set it in the debug config object directory.
1235 if(!compiler || !config)
1237 // If we're not currently debugging, set a breakpoint in the active compiler/config
1238 compiler = GetCompilerConfig();
1239 config = this.config;
1240 // If the current config is not debuggable, set it in the first debuggable config found
1241 if(config && !config.options.debug)
1243 for(c : configurations; c.options.debug)
1250 objDirExp = GetObjDir(compiler, config, bitDepth);
1251 strcpy(objDir, objDirExp.dir);
1253 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1254 ReplaceSpaces(relativePath, objDir);
1256 PathCatSlash(relativePath, moduleName);
1260 // WARNING: On failure, relative path is uninitialized
1265 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1267 TargetTypes targetType = GetTargetType(config);
1268 String targetFileName = GetTargetFileName(config);
1269 if(targetType == staticLibrary)
1271 PathCatSlash(string, "lib");
1272 strcat(string, targetFileName);
1274 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1276 PathCatSlash(string, "lib");
1277 strcat(string, targetFileName);
1280 PathCatSlash(string, targetFileName);
1285 if(compiler.targetPlatform == win32)
1286 strcat(string, ".exe");
1289 if(compiler.targetPlatform == win32)
1290 strcat(string, ".dll");
1291 else if(compiler.targetPlatform == apple)
1292 strcat(string, ".dylib");
1294 strcat(string, ".so");
1295 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1297 strcat(string, ".");
1298 strcat(string, moduleVersion);
1302 strcat(string, ".a");
1307 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1309 bool result = false;
1310 char temp[MAX_LOCATION];
1311 strcpy(cfDir, topNode.path);
1312 if(compilerConfigsDir && compilerConfigsDir[0])
1314 PathCatSlash(cfDir, compilerConfigsDir);
1319 strcpy(temp, cfDir);
1320 // Using a relative path makes it less likely to run into spaces issues
1321 // Even with escaped spaces, there still seems to be issues including a config file
1322 // in a path containing spaces
1324 MakePathRelative(temp, topNode.path, cfDir);
1327 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1331 strcpy(temp, cfDir);
1332 ReplaceSpaces(cfDir, temp);
1337 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1339 char temp[MAX_LOCATION];
1340 bool result = false;
1341 strcpy(cfDir, topNode.path);
1342 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1344 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1349 // Default to <ProjectDir>/.configs if unset
1350 PathCatSlash(cfDir, ".configs");
1355 strcpy(temp, cfDir);
1356 // Using a relative path makes it less likely to run into spaces issues
1357 // Even with escaped spaces, there still seems to be issues including a config file
1358 // in a path containing spaces
1359 if(IsPathInsideOf(cfDir, topNode.path))
1360 MakePathRelative(temp, topNode.path, cfDir);
1362 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1366 strcpy(temp, cfDir);
1367 ReplaceSpaces(cfDir, temp);
1372 void CatMakeFileName(char * string, ProjectConfig config)
1374 char projectName[MAX_LOCATION];
1375 strcpy(projectName, name);
1376 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1379 #ifndef MAKEFILE_GENERATOR
1380 void MarkChanges(ProjectNode node)
1382 for(cfg : topNode.configurations)
1384 ProjectConfig c = null;
1385 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1387 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1388 (!c.options || !cfg.options)))
1389 cfg.symbolGenModified = true;
1390 if(c && ((c.options && cfg.options &&
1391 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1392 || (!c.options || !cfg.options)))
1393 cfg.linkingModified = true;
1395 cfg.makingModified = true;
1399 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1401 for(cfg : configurations)
1404 cfg.makingModified = true;
1406 cfg.compilingModified = true;
1408 cfg.linkingModified = true;
1410 cfg.symbolGenModified = true;
1412 if(compiling || linking)
1414 ide.projectView.modifiedDocument = true;
1415 ide.workspace.modified = true;
1419 void RotateActiveConfig(bool forward)
1421 if(configurations.first && configurations.last != configurations.first)
1423 Iterator<ProjectConfig> cfg { configurations };
1424 while(forward ? cfg.Next() : cfg.Prev())
1425 if(cfg.data == config)
1439 property::config = cfg.data;
1440 ide.UpdateToolBarActiveConfigs(true);
1441 ide.workspace.modified = true;
1442 ide.projectView.Update(null);
1446 bool ProcessPipeOutputRaw(DualPipe f)
1449 while(!f.Eof() && !ide.projectView.stopBuild)
1452 double lastTime = GetTime();
1456 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1458 ide.outputView.buildBox.Logf("%s\n", line);
1460 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1462 //printf("Processing Input...\n");
1463 if(app.ProcessInput(true))
1465 app.UpdateDisplay();
1468 //printf("Waiting...\n");
1471 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1473 if(ide.projectView.stopBuild)
1475 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1478 return !ide.projectView.stopBuild;
1481 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
1482 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1485 bool compiling = false, linking = false, precompiling = false;
1486 int compilingEC = 0;
1487 int numErrors = 0, numWarnings = 0;
1488 bool loggedALine = false;
1489 int lenMakeCommand = strlen(compiler.makeCommand);
1492 char moduleName[MAX_FILENAME];
1493 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1495 DynamicString test { };
1496 DynamicString ecp { };
1497 DynamicString ecc { };
1498 DynamicString ecs { };
1499 DynamicString ear { };
1500 DynamicString prefix { };
1501 DynamicString cpp { };
1502 DynamicString cc { };
1503 DynamicString cxx { };
1504 DynamicString strip { };
1505 DynamicString ar { };
1506 DynamicString windres { };
1508 if(bitDepth == 64 && compiler.targetPlatform == win32)
1509 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1510 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1511 gnuToolchainPrefix = "i686-w64-mingw32-";
1513 ecp.concatx(compiler.ecpCommand, " ");
1514 ecc.concatx(compiler.eccCommand, " ");
1515 ecs.concatx(compiler.ecsCommand, " ");
1516 ear.concatx(compiler.earCommand, " ");
1519 compiler.ccacheEnabled ? "ccache " : "",
1520 compiler.distccEnabled ? "distcc " : "",
1521 gnuToolchainPrefix);
1523 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1524 cc.concatx((String)prefix, compiler.ccCommand, " ");
1525 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1527 strip.concatx(gnuToolchainPrefix, "strip ");
1528 ar.concatx(gnuToolchainPrefix, "ar rcs");
1529 windres.concatx(gnuToolchainPrefix, "windres ");
1531 testLen = Max(testLen, ecp.size);
1532 testLen = Max(testLen, ecc.size);
1533 testLen = Max(testLen, ecs.size);
1534 testLen = Max(testLen, ear.size);
1535 testLen = Max(testLen, cpp.size);
1536 testLen = Max(testLen, cc.size);
1537 testLen = Max(testLen, cxx.size);
1538 testLen = Max(testLen, strip.size);
1539 testLen = Max(testLen, ar.size);
1540 testLen = Max(testLen, windres.size);
1541 testLen = Max(testLen, strlen("mkdir "));
1544 while(!f.Eof() && !ide.projectView.stopBuild)
1547 double lastTime = GetTime();
1551 //printf("Peeking and GetLine...\n");
1552 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1554 char * message = null;
1555 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1556 char * from = strstr(line, stringFrom);
1557 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1558 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1560 char * module = strstr(line, "No rule to make target `");
1564 module = strchr(module, '`') + 1;
1565 end = strchr(module, '\'');
1569 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1570 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1576 //ide.outputView.buildBox.Logf("error: %s\n", line);
1580 else if(strstr(test, "mkdir ") == test);
1581 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1582 else if(strstr(test, ear) == test);
1583 else if(strstr(test, strip) == test);
1584 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1587 bool isPrecomp = false;
1590 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1592 module = strstr(line, " -c ");
1593 if(module) module += 4;
1596 else if(strstr(test, ecc) == test)
1598 module = strstr(line, " -c ");
1599 if(module) module += 4;
1600 //module = line + 3;
1601 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1602 compilingEC = 3;//2;
1605 else if(strstr(test, ecp) == test)
1607 // module = line + 8;
1608 module = strstr(line, " -c ");
1609 if(module) module += 4;
1620 if(!compiling && !isPrecomp)
1622 ide.outputView.buildBox.Logf($"Compiling...\n");
1625 else if(!precompiling && isPrecomp)
1627 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1628 precompiling = true;
1630 // Changed escapeBackSlashes here to handle paths with spaces
1631 Tokenize(module, 1, tokens, true); // false);
1632 GetLastDirectory(module, moduleName);
1633 ide.outputView.buildBox.Logf("%s\n", moduleName);
1635 else if((module = strstr(line, " -o ")))
1638 precompiling = false;
1640 ide.outputView.buildBox.Logf($"Linking...\n");
1644 ide.outputView.buildBox.Logf("%s\n", line);
1645 if(strstr(line, "warning:") || strstr(line, "note:"))
1647 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1651 if(compilingEC) compilingEC--;
1653 else if(strstr(test, windres) == test)
1656 module = strstr(line, " ");
1657 if(module) module++;
1661 Tokenize(module, 1, tokens, true);
1662 GetLastDirectory(module, moduleName);
1663 ide.outputView.buildBox.Logf("%s\n", moduleName);
1666 else if(strstr(test, ar) == test)
1667 ide.outputView.buildBox.Logf($"Building library...\n");
1668 else if(strstr(test, ecs) == test)
1669 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1672 if(linking || compiling || precompiling)
1674 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1675 char * colon = strstr(start, ":"); //, * bracket;
1676 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1677 colon = strstr(colon + 1, ":");
1680 char * sayError = "";
1681 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1684 int len = (int)(colon - start);
1685 char ext[MAX_EXTENSION];
1686 len = Min(len, MAX_LOCATION-1);
1687 // Don't be mistaken by the drive letter colon
1689 // TODO: need to fix colon - line gives char *
1690 // warning: incompatible expression colon - line (char *); expected int
1692 strncpy(moduleName, line, (int)(colon - line));
1693 moduleName[colon - line] = '\0';
1695 strncpy(moduleName, start, len);
1696 moduleName[len] = '\0';
1697 // Remove stuff in brackets
1698 //bracket = strstr(moduleName, "(");
1699 //if(bracket) *bracket = '\0';
1701 GetLastDirectory(moduleName, temp);
1702 GetExtension(temp, ext);
1704 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1706 char * cColon = strstr(colon+1, ":");
1707 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1708 cColon = strstr(cColon + 1, ":");
1711 int len = (int)(cColon - (colon+1));
1712 char mName[MAX_LOCATION];
1713 len = Min(len, MAX_LOCATION-1);
1714 strncpy(mName, colon+1, len);
1716 GetLastDirectory(mName, temp);
1717 GetExtension(temp, ext);
1718 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1721 strcpy(moduleName, mName);
1725 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1728 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1730 message = $"Linker Message: ";
1736 message = $"Linker Error";
1739 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1743 if(!strstr(line, "error:"))
1745 message = $"Linker Error: ";
1751 strcpy(temp, topNode.path);
1752 PathCatSlash(temp, moduleName);
1753 MakePathRelative(temp, topNode.path, moduleName);
1755 error = strstr(line, "error:");
1756 if(!message && error && error > colon)
1760 // Silence warnings for compiled eC
1761 char * objDir = strstr(moduleName, objDirExp.dir);
1765 if((pointer = strstr(line, "undefined")) ||
1766 (pointer = strstr(line, "multiple definition")) ||
1767 (pointer = strstr(line, "No such file")) ||
1768 (pointer = strstr(line, "token")))
1770 strncat(moduleName, colon, pointer - colon);
1771 sayError = "error: ";
1776 else if((pointer = strstr(line, "No such file")))
1778 strncat(moduleName, colon, pointer - colon);
1779 sayError = "error: ";
1783 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1785 else if(strstr(line, "warning:"))
1791 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1792 /*else if(this == ide.workspace.projects.firstIterator.data)
1793 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1796 char fullModuleName[MAX_LOCATION];
1797 FileAttribs found = 0;
1798 Project foundProject = this;
1801 char * loc = strstr(moduleName, ":");
1803 strcpy(fullModuleName, topNode.path);
1804 PathCat(fullModuleName, moduleName);
1805 found = FileExists(fullModuleName);
1806 if(!found && !strcmp(ext, "c"))
1808 char ecName[MAX_LOCATION];
1809 ChangeExtension(fullModuleName, "ec", ecName);
1810 found = FileExists(ecName);
1814 char path[MAX_LOCATION];
1815 if(ide && ide.workspace)
1817 for(prj : ide.workspace.projects)
1820 MakePathRelative(fullModuleName, prj.topNode.path, path);
1822 if((node = prj.topNode.FindWithPath(path, false)))
1824 strcpy(fullModuleName, prj.topNode.path);
1825 PathCatSlash(fullModuleName, node.path);
1826 PathCatSlash(fullModuleName, node.name);
1827 found = FileExists(fullModuleName);
1835 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1837 for(prj : ide.workspace.projects)
1840 if((node = prj.topNode.Find(moduleName, false)))
1842 strcpy(fullModuleName, prj.topNode.path);
1843 PathCatSlash(fullModuleName, node.path);
1844 PathCatSlash(fullModuleName, node.name);
1845 found = FileExists(fullModuleName);
1858 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1859 MakeSystemPath(fullModuleName);
1862 strcpy(fullModuleName, moduleName);
1865 strcat(fullModuleName, ":");
1866 strcat(fullModuleName, loc + 1);
1870 fullModuleName[0] = 0;
1871 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1876 ide.outputView.buildBox.Logf("%s\n", line);
1877 linking = compiling = precompiling = false;
1881 ide.outputView.buildBox.Logf("%s\n", line);
1885 //printf("Done getting line\n");
1886 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1888 //printf("Processing Input...\n");
1889 if(app.ProcessInput(true))
1891 app.UpdateDisplay();
1894 //printf("Waiting...\n");
1897 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1899 if(ide.projectView.stopBuild)
1901 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1904 else if(loggedALine || !isARun)
1906 if(f.GetExitCode() && !numErrors)
1908 bool result = f.GetLine(line, sizeof(line)-1);
1909 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1915 char targetFileName[MAX_LOCATION];
1916 targetFileName[0] = '\0';
1917 CatTargetFileName(targetFileName, compiler, config);
1918 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1921 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1923 ide.outputView.buildBox.Logf($"no error, ");
1926 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1928 ide.outputView.buildBox.Logf($"no warning\n");
1944 return numErrors == 0 && !ide.projectView.stopBuild;
1947 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1950 int lenMakeCommand = strlen(compiler.makeCommand);
1955 double lastTime = GetTime();
1958 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1960 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1961 else if(strstr(line, "mkdir") == line);
1962 else if(strstr(line, "del") == line);
1963 else if(strstr(line, "rm") == line);
1964 else if(strstr(line, "Could Not Find") == line);
1967 ide.outputView.buildBox.Logf(line);
1968 ide.outputView.buildBox.Logf("\n");
1972 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1974 if(app.ProcessInput(true))
1976 app.UpdateDisplay();
1979 //Sleep(1.0 / PEEK_RESOLUTION);
1983 bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
1985 bool result = false;
1987 char targetFileName[MAX_LOCATION] = "";
1988 DynamicString makeTargets { };
1989 char makeFile[MAX_LOCATION];
1990 char makeFilePath[MAX_LOCATION];
1991 char configName[MAX_LOCATION];
1992 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
1993 PathBackup pathBackup { };
1994 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1995 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1997 bool eC_Debug = mode.eC_ToolsDebug;
1998 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
1999 int numJobs = compiler.numJobs;
2000 char command[MAX_F_STRING*4];
2001 char * compilerName = CopyString(compiler.name);
2003 delete lastBuildConfigName;
2004 lastBuildConfigName = CopyString(config ? config.name : "Common");
2005 delete lastBuildCompilerName;
2006 lastBuildCompilerName = CopyString(compiler.name);
2007 ProjectLoadLastBuildNamesInfo(this, config);
2009 CamelCase(compilerName);
2011 strcpy(configName, config ? config.name : "Common");
2013 SetPath(false, compiler, config, bitDepth); //true
2014 CatTargetFileName(targetFileName, compiler, config);
2016 strcpy(makeFilePath, topNode.path);
2017 CatMakeFileName(makeFile, config);
2018 PathCatSlash(makeFilePath, makeFile);
2020 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2023 if(compiler.type.isVC)
2025 PrintLn("compiling a single file is not yet supported");
2030 char pushD[MAX_LOCATION];
2031 char cfDir[MAX_LOCATION];
2032 GetIDECompilerConfigsDir(cfDir, true, true);
2033 GetWorkingDir(pushD, sizeof(pushD));
2034 ChangeWorkingDir(topNode.path);
2035 // Create object dir if it does not exist already
2036 if(!FileExists(objDirExp.dir).isDirectory)
2038 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2039 compiler.makeCommand, cfDir,
2040 crossCompiling ? " TARGET_PLATFORM=" : "",
2042 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2043 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2045 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2047 ide.outputView.buildBox.Logf("%s\n", command);
2051 ChangeWorkingDir(pushD);
2053 for(node : onlyNodes)
2055 if(node.GetIsExcluded(config))
2056 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2060 node.DeleteIntermediateFiles(compiler, config, bitDepth, lastBuildNamesInfo, mode == cObject ? true : false);
2061 node.GetTargets(config, lastBuildNamesInfo, objDirExp.dir, makeTargets);
2067 if(compiler.type.isVC)
2069 bool result = false;
2070 char oldwd[MAX_LOCATION];
2071 GetWorkingDir(oldwd, sizeof(oldwd));
2072 ChangeWorkingDir(topNode.path);
2074 // TODO: support justPrint
2075 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2077 ide.outputView.buildBox.Logf("%s\n", command);
2078 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2080 ProcessPipeOutputRaw(f);
2084 ChangeWorkingDir(oldwd);
2086 else if(onlyNodes && strlen(makeTargets) == 0)
2088 ide.outputView.buildBox.Log("No targets to compile.\n");
2092 char cfDir[MAX_LOCATION];
2093 GetIDECompilerConfigsDir(cfDir, true, true);
2094 sprintf(command, "%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2095 compiler.makeCommand,
2096 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2098 crossCompiling ? " TARGET_PLATFORM=" : "",
2100 bitDepth ? " ARCH=" : "",
2101 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2102 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2103 compilerName, eC_Debug ? "--always-make " : "", numJobs,
2104 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2105 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2106 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2108 ide.outputView.buildBox.Logf("%s\n", command);
2110 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2118 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2124 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2127 ide.outputView.buildBox.Logf("%s\n", line);
2128 if(!error && !found && strstr(line, "echo ") == line)
2130 strcpy(command, line+5);
2133 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2135 strcpy(command, line);
2145 result = ProcessPipeOutputRaw(f);
2147 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config, bitDepth);
2150 ide.outputView.buildBox.Logf("%s\n", command);
2151 else if(justPrint && found)
2152 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2157 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2162 delete compilerName;
2167 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2169 char makeFile[MAX_LOCATION];
2170 char makeFilePath[MAX_LOCATION];
2171 char command[MAX_LOCATION];
2172 char * compilerName;
2174 PathBackup pathBackup { };
2175 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2176 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2178 compilerName = CopyString(compiler.name);
2179 CamelCase(compilerName);
2181 SetPath(false, compiler, config, bitDepth);
2183 strcpy(makeFilePath, topNode.path);
2184 CatMakeFileName(makeFile, config);
2185 PathCatSlash(makeFilePath, makeFile);
2187 if(compiler.type.isVC)
2189 bool result = false;
2190 char oldwd[MAX_LOCATION];
2191 GetWorkingDir(oldwd, sizeof(oldwd));
2192 ChangeWorkingDir(topNode.path);
2194 // TODO: justPrint support
2195 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2197 ide.outputView.buildBox.Logf("%s\n", command);
2198 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2200 ProcessPipeOutputRaw(f);
2204 ChangeWorkingDir(oldwd);
2209 char cfDir[MAX_LOCATION];
2210 GetIDECompilerConfigsDir(cfDir, true, true);
2211 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2212 compiler.makeCommand, cfDir,
2213 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2214 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2216 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2217 topNode.path, justPrint ? " -n": "", makeFilePath);
2219 ide.outputView.buildBox.Logf("%s\n", command);
2220 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2222 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2223 cleanType == realClean ? $"intermediate objects directory" : $"target",
2224 cleanType == clean ? $" and object files" : "");
2226 ProcessPipeOutputRaw(f);
2228 ProcessCleanPipeOutput(f, compiler, config);
2229 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2230 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2231 cleanType == clean ? $" and object files" : "");
2237 delete compilerName;
2240 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2242 String target = new char[maxPathLen];
2243 char oldDirectory[MAX_LOCATION];
2244 char * executableLauncher = compiler.executableLauncher;
2245 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2246 PathBackup pathBackup { };
2248 // Build(project, ideMain, true, null, false);
2250 strcpy(target, topNode.path);
2251 PathCatSlash(target, targetDirExp.dir);
2252 CatTargetFileName(target, compiler, config);
2253 sprintf(target, "%s %s", target, args);
2254 GetWorkingDir(oldDirectory, MAX_LOCATION);
2256 if(strlen(ide.workspace.debugDir))
2258 char temp[MAX_LOCATION];
2259 strcpy(temp, topNode.path);
2260 PathCatSlash(temp, ide.workspace.debugDir);
2261 ChangeWorkingDir(temp);
2264 ChangeWorkingDir(topNode.path);
2265 // ChangeWorkingDir(topNode.path);
2266 SetPath(true, compiler, config, bitDepth);
2267 if(executableLauncher)
2269 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 2];
2270 prefixedTarget[0] = '\0';
2271 strcat(prefixedTarget, executableLauncher);
2272 strcat(prefixedTarget, " ");
2273 strcat(prefixedTarget, target);
2274 Execute(prefixedTarget);
2275 delete prefixedTarget;
2280 ChangeWorkingDir(oldDirectory);
2283 delete targetDirExp;
2287 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2289 return Build(false, nodes, compiler, config, bitDepth, justPrint, mode);
2293 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2296 if(targetType == staticLibrary || targetType == sharedLibrary)
2297 strcat(fileName, "$(LP)");
2298 // !!! ReplaceSpaces must be done after all PathCat calls !!!
2299 // ReplaceSpaces(s, GetTargetFileName(config));
2300 strcat(fileName, GetTargetFileName(config));
2304 strcat(fileName, "$(E)");
2307 strcat(fileName, "$(SO)$(VER)");
2310 strcat(fileName, "$(A)");
2315 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2317 bool result = false;
2318 char path[MAX_LOCATION];
2320 if(!GetProjectCompilerConfigsDir(path, false, false))
2321 GetIDECompilerConfigsDir(path, false, false);
2323 if(!FileExists(path).isDirectory)
2327 char dirName[MAX_FILENAME];
2328 GetLastDirectory(path, dirName);
2329 if(!strcmp(dirName, ".configs"))
2330 FileSetAttribs(path, FileAttribs { isHidden = true });
2333 PathCatSlash(path, "crossplatform.mk");
2335 if(FileExists(path))
2338 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2341 File f = FileOpen(path, write);
2344 include.Seek(0, start);
2345 for(; !include.Eof(); )
2348 int count = include.Read(buffer, 1, 4096);
2349 f.Write(buffer, 1, count);
2355 if(!altCrossPlatformMk)
2362 bool GenerateCompilerCf(CompilerConfig compiler)
2364 bool result = false;
2365 char path[MAX_LOCATION];
2367 char * compilerName;
2368 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2369 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2370 Platform platform = compiler.targetPlatform;
2372 compilerName = CopyString(compiler.name);
2373 CamelCase(compilerName);
2374 name = PrintString(platform, "-", compilerName, ".cf");
2376 if(!GetProjectCompilerConfigsDir(path, false, false))
2377 GetIDECompilerConfigsDir(path, false, false);
2379 if(!FileExists(path).isDirectory)
2383 char dirName[MAX_FILENAME];
2384 GetLastDirectory(path, dirName);
2385 if(!strcmp(dirName, ".configs"))
2386 FileSetAttribs(path, FileAttribs { isHidden = true });
2389 PathCatSlash(path, name);
2391 if(FileExists(path))
2394 File f = FileOpen(path, write);
2397 if(compiler.environmentVars && compiler.environmentVars.count)
2399 f.Puts("# ENVIRONMENT VARIABLES\n");
2401 for(e : compiler.environmentVars)
2403 f.Printf("export %s := %s\n", e.name, e.string);
2408 f.Puts("# TOOLCHAIN\n");
2411 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2413 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2416 if(compiler.sysroot && compiler.sysroot[0])
2418 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2419 // Moved this to crossplatform.mk
2420 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2424 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2425 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2426 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2427 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2428 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
2429 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);
2430 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);
2431 f.Printf("EAR := %s\n", compiler.earCommand);
2433 f.Puts("AS := $(GCC_PREFIX)as\n");
2434 f.Puts("LD := $(GCC_PREFIX)ld\n");
2435 f.Puts("AR := $(GCC_PREFIX)ar\n");
2436 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2437 f.Puts("ifdef WINDOWS_TARGET\n");
2438 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2439 f.Puts(" ifdef ARCH\n");
2440 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2441 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2443 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2444 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2449 f.Puts("UPX := upx\n");
2452 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2455 f.Puts("EARFLAGS = \n");
2458 f.Puts("ifndef ARCH\n");
2459 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2460 f.Puts(" ifdef WINDOWS_HOST\n");
2461 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2462 f.Puts(" TARGET_ARCH := x86_64\n");
2464 f.Puts(" TARGET_ARCH := i386\n");
2467 f.Puts("endif\n\n");
2469 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2470 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2474 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2478 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2481 if(compiler.includeDirs && compiler.includeDirs.count)
2483 f.Puts("\nCFLAGS +=");
2484 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2487 if(compiler.prepDirectives && compiler.prepDirectives.count)
2489 f.Puts("\nCFLAGS +=");
2490 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2493 if(compiler.libraryDirs && compiler.libraryDirs.count)
2495 f.Puts("\nLDFLAGS +=");
2496 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2497 // We would need a bool option to know whether we want to add to rpath as well...
2498 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
2501 if(compiler.excludeLibs && compiler.excludeLibs.count)
2503 f.Puts("\nEXCLUDED_LIBS =");
2504 for(l : compiler.excludeLibs)
2510 if(compiler.compilerFlags && compiler.compilerFlags.count)
2512 f.Puts("\nCFLAGS +=");
2513 OutputListOption(f, "", compiler.compilerFlags, inPlace, true);
2516 if(compiler.linkerFlags && compiler.linkerFlags.count)
2518 f.Puts("\nLDFLAGS +=");
2519 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
2523 f.Puts("\nOFLAGS += $(LDFLAGS)");
2525 f.Puts("ifdef ARCH_FLAGS\n");
2526 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2527 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2536 delete compilerName;
2540 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2542 bool result = false;
2543 char filePath[MAX_LOCATION];
2544 char makeFile[MAX_LOCATION];
2545 // PathBackup pathBackup { };
2546 // char oldDirectory[MAX_LOCATION];
2549 if(!altMakefilePath)
2551 strcpy(filePath, topNode.path);
2552 CatMakeFileName(makeFile, config);
2553 PathCatSlash(filePath, makeFile);
2556 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2558 /*SetPath(false, compiler, config);
2559 GetWorkingDir(oldDirectory, MAX_LOCATION);
2560 ChangeWorkingDir(topNode.path);*/
2567 char targetDir[MAX_LOCATION];
2568 char objDirExpNoSpaces[MAX_LOCATION];
2569 char objDirNoSpaces[MAX_LOCATION];
2570 char resDirNoSpaces[MAX_LOCATION];
2571 char targetDirExpNoSpaces[MAX_LOCATION];
2572 char fixedModuleName[MAX_FILENAME];
2573 char fixedConfigName[MAX_FILENAME];
2575 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2576 // Non-zero if we're building eC code
2577 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2578 int numCObjects = 0;
2580 int numRCObjects = 0;
2581 bool containsCXX = false; // True if the project contains a C++ file
2582 bool relObjDir, sameOrRelObjTargetDirs;
2583 String objDirExp = GetObjDirExpression(config);
2584 TargetTypes targetType = GetTargetType(config);
2586 char cfDir[MAX_LOCATION];
2587 int objectsParts = 0;
2588 int eCsourcesParts = 0;
2589 int rcSourcesParts = 0;
2590 Array<String> listItems { };
2591 Map<String, int> varStringLenDiffs { };
2592 Map<String, NameCollisionInfo> namesInfo { };
2594 Map<String, int> cflagsVariations { };
2595 Map<intptr, int> nodeCFlagsMapping { };
2597 Map<String, int> ecflagsVariations { };
2598 Map<intptr, int> nodeECFlagsMapping { };
2600 ReplaceSpaces(objDirNoSpaces, objDirExp);
2601 strcpy(targetDir, GetTargetDirExpression(config));
2602 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2604 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2605 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2607 char temp[MAX_LOCATION];
2608 ReplaceSpaces(temp, objDirExpNoSpaces);
2609 strcpy(objDirExpNoSpaces, temp);
2611 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2612 ReplaceSpaces(fixedModuleName, moduleName);
2613 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2614 CamelCase(fixedConfigName);
2616 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2617 relObjDir = lenObjDirExpNoSpaces == 0 ||
2618 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2619 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2620 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2621 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2622 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2624 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2626 f.Puts("# CORE VARIABLES\n\n");
2628 f.Printf("MODULE := %s\n", fixedModuleName);
2629 f.Printf("VERSION := %s\n", property::moduleVersion);
2630 f.Printf("CONFIG := %s\n", fixedConfigName);
2631 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2634 test = GetTargetTypeIsSetByPlatform(config);
2638 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2640 TargetTypes targetType;
2641 PlatformOptions projectPOs, configPOs;
2642 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2643 targetType = platformTargetType;
2649 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2650 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2655 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2660 for(c = 0; c < ifCount; c++)
2666 f.Puts("# FLAGS\n\n");
2668 f.Puts("ECFLAGS =\n");
2669 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2670 f.Puts("PRJ_CFLAGS =\n");
2671 f.Puts("CECFLAGS =\n");
2672 f.Puts("OFLAGS =\n");
2676 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2679 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2680 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2681 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2682 //f.Puts("endif\n");
2685 f.Puts("# INCLUDES\n\n");
2687 if(compilerConfigsDir && compilerConfigsDir[0])
2689 strcpy(cfDir, compilerConfigsDir);
2690 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2695 GetIDECompilerConfigsDir(cfDir, true, true);
2696 // Use CF_DIR environment variable for absolute paths only
2697 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2698 strcpy(cfDir, "$(CF_DIR)");
2701 f.Printf("_CF_DIR = %s\n", cfDir);
2704 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2705 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2708 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2710 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2713 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2716 // test = GetTargetTypeIsSetByPlatform(config);
2718 char target[MAX_LOCATION];
2719 char temp[MAX_LOCATION];
2724 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2726 if(type != targetType)
2731 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2733 GetMakefileTargetFileName(type, target, config);
2734 strcpy(temp, targetDir);
2735 PathCatSlash(temp, target);
2736 ReplaceSpaces(target, temp);
2737 f.Printf("TARGET = %s\n", target);
2742 GetMakefileTargetFileName(targetType, target, config);
2743 strcpy(temp, targetDir);
2744 PathCatSlash(temp, target);
2745 ReplaceSpaces(target, temp);
2746 f.Printf("TARGET = %s\n", target);
2752 for(c = 0; c < ifCount; c++)
2759 // Use something fixed here, to not cause Makefile differences across compilers...
2760 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2761 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2763 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2767 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2769 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2772 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2774 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2775 if(eCsourcesParts > 1)
2777 for(c = 1; c <= eCsourcesParts; c++)
2778 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2782 for(c = 0; c < 5; c++)
2784 if(eCsourcesParts > 1)
2787 f.Printf("%s =", map[c][0]);
2788 for(n = 1; n <= eCsourcesParts; n++)
2789 f.Printf(" $(%s%d)", map[c][0], n);
2791 for(n = 1; n <= eCsourcesParts; n++)
2792 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2794 else if(eCsourcesParts == 1)
2795 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2801 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2804 f.Puts("ifdef WINDOWS_TARGET\n\n");
2806 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2808 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2809 if(rcSourcesParts > 1)
2811 for(c = 1; c <= rcSourcesParts; c++)
2812 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2815 if(rcSourcesParts > 1)
2818 f.Printf("%s =", "RCOBJECTS");
2819 for(n = 1; n <= rcSourcesParts; n++)
2820 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2822 for(n = 1; n <= rcSourcesParts; n++)
2823 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2825 else if(rcSourcesParts == 1)
2826 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2830 f.Puts("RCSOURCES =\n");
2831 f.Puts("RCOBJECTS =\n");
2832 f.Puts("endif\n\n");
2835 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2837 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2838 f.Printf("OBJECTS =%s%s%s%s\n",
2839 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2840 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2841 numRCObjects ? " $(RCOBJECTS)" : "");
2844 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2847 if(numCObjects && numRCObjects)
2848 prefix = "$(ECSOURCES) $(RCSOURCES)";
2849 else if(numCObjects)
2850 prefix = "$(ECSOURCES)";
2853 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2857 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2858 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2860 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2862 if((config && config.options && config.options.libraries) ||
2863 (options && options.libraries))
2865 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2867 if(config && config.options && config.options.libraries)
2868 OutputLibraries(f, config.options.libraries);
2869 else if(options && options.libraries)
2870 OutputLibraries(f, options.libraries);
2876 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2877 cflagsVariations, nodeCFlagsMapping,
2878 ecflagsVariations, nodeECFlagsMapping, null);
2880 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2881 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2883 if(platforms || (config && config.platforms))
2886 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2887 //for(platform = win32; platform <= apple; platform++)
2889 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2890 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2892 PlatformOptions projectPlatformOptions, configPlatformOptions;
2893 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2895 if(projectPlatformOptions || configPlatformOptions)
2900 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2903 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2904 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2906 f.Puts("CFLAGS +=");
2907 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2910 for(s : projectPlatformOptions.options.compilerOptions)
2915 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2918 for(s : configPlatformOptions.options.compilerOptions)
2927 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2928 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2930 f.Puts("OFLAGS +=");
2931 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2933 bool needWl = false;
2935 for(s : projectPlatformOptions.options.linkerOptions)
2937 if(!IsLinkerOption(s))
2945 for(s : projectPlatformOptions.options.linkerOptions)
2946 if(IsLinkerOption(s))
2950 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2952 bool needWl = false;
2954 for(s : configPlatformOptions.options.linkerOptions)
2956 if(IsLinkerOption(s))
2964 for(s : configPlatformOptions.options.linkerOptions)
2965 if(!IsLinkerOption(s))
2973 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2974 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2975 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2976 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2978 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2979 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2980 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2982 f.Puts("OFLAGS +=");
2983 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2984 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2985 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2986 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2990 if((configPlatformOptions && configPlatformOptions.options.libraries))
2992 if(configPlatformOptions.options.libraries.count)
2995 OutputLibraries(f, configPlatformOptions.options.libraries);
2999 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3001 if(projectPlatformOptions.options.libraries.count)
3004 OutputLibraries(f, projectPlatformOptions.options.libraries);
3015 for(c = 0; c < ifCount; c++)
3021 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3022 (options && options.linkerOptions && options.linkerOptions.count))
3024 f.Puts("OFLAGS +=");
3027 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3029 bool needWl = false;
3030 for(s : config.options.linkerOptions)
3032 if(!IsLinkerOption(s))
3040 for(s : config.options.linkerOptions)
3041 if(IsLinkerOption(s))
3045 if(options && options.linkerOptions && options.linkerOptions.count)
3047 bool needWl = false;
3048 for(s : options.linkerOptions)
3050 if(!IsLinkerOption(s))
3058 for(s : options.linkerOptions)
3059 if(IsLinkerOption(s))
3067 f.Puts("CECFLAGS += -cpp $(_CPP)");
3071 if(GetProfile(config))
3072 f.Puts("OFLAGS += -pg\n\n");
3074 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3076 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3077 f.Puts("OFLAGS +=");
3078 if(config && config.options && config.options.libraryDirs)
3079 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
3080 if(options && options.libraryDirs)
3081 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
3087 f.Puts("# TARGETS\n");
3090 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3093 f.Puts("objdir:\n");
3095 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3097 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");
3098 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");
3099 //f.Puts("# PRE-BUILD COMMANDS\n");
3100 if(options && options.prebuildCommands)
3102 for(s : options.prebuildCommands)
3103 if(s && s[0]) f.Printf("\t%s\n", s);
3105 if(config && config.options && config.options.prebuildCommands)
3107 for(s : config.options.prebuildCommands)
3108 if(s && s[0]) f.Printf("\t%s\n", s);
3110 if(platforms || (config && config.platforms))
3113 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3114 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3116 PlatformOptions projectPOs, configPOs;
3117 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3119 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3120 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3125 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3127 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3129 for(s : projectPOs.options.prebuildCommands)
3130 if(s && s[0]) f.Printf("\t%s\n", s);
3132 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3134 for(s : configPOs.options.prebuildCommands)
3135 if(s && s[0]) f.Printf("\t%s\n", s);
3142 for(c = 0; c < ifCount; c++)
3148 if(!sameOrRelObjTargetDirs)
3150 f.Puts("targetdir:\n");
3151 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3157 // Main Module (Linking) for ECERE C modules
3158 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3159 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3160 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $@\n",
3161 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3163 // Main Module (Linking) for ECERE C modules
3164 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3165 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3166 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3167 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3168 " -c $(OBJ)$(MODULE).main.ec -o $@ -symbols $(OBJ)\n");
3174 // This would not rebuild the target on updated objects
3175 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3177 // This should fix it for good!
3178 f.Puts("$(SYMBOLS): | objdir\n");
3179 f.Puts("$(OBJECTS): | objdir\n");
3181 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3182 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3183 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3185 f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
3186 f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
3187 OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
3190 f.Puts("ifdef WINDOWS_TARGET\n");
3191 OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
3196 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
3197 OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
3200 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3202 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
3203 if(!GetDebug(config))
3205 f.Puts("ifndef NOSTRIP\n");
3206 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3209 if(GetCompress(config))
3211 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3212 f.Puts("ifdef EXECUTABLE_TARGET\n");
3213 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3216 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3220 if(resNode.files && resNode.files.count && !noResources)
3221 resNode.GenMakefileAddResources(f, resNode.path, config);
3223 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
3225 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3226 f.Puts("ifdef LINUX_TARGET\n");
3227 f.Puts("ifdef LINUX_HOST\n");
3228 // TODO?: support symlinks for longer version numbers
3229 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3230 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3235 //f.Puts("# POST-BUILD COMMANDS\n");
3236 if(options && options.postbuildCommands)
3238 for(s : options.postbuildCommands)
3239 if(s && s[0]) f.Printf("\t%s\n", s);
3241 if(config && config.options && config.options.postbuildCommands)
3243 for(s : config.options.postbuildCommands)
3244 if(s && s[0]) f.Printf("\t%s\n", s);
3246 if(platforms || (config && config.platforms))
3249 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3250 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3252 PlatformOptions projectPOs, configPOs;
3253 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3255 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3256 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3261 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3263 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3265 for(s : projectPOs.options.postbuildCommands)
3266 if(s && s[0]) f.Printf("\t%s\n", s);
3268 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3270 for(s : configPOs.options.postbuildCommands)
3271 if(s && s[0]) f.Printf("\t%s\n", s);
3278 for(c = 0; c < ifCount; c++)
3284 f.Puts("# SYMBOL RULES\n");
3287 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3289 f.Puts("# C OBJECT RULES\n");
3292 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3294 f.Puts("# OBJECT RULES\n");
3296 // todo call this still but only generate rules whith specific options
3297 // see we-have-file-specific-options in ProjectNode.ec
3298 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3301 GenMakefilePrintMainObjectRule(f, config);
3303 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3304 f.Puts("\t$(call rmq,$(TARGET))\n");
3305 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3306 f.Puts("ifdef LINUX_TARGET\n");
3307 f.Puts("ifdef LINUX_HOST\n");
3308 // TODO?: support symlinks for longer version numbers
3309 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3310 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3316 f.Puts("clean: cleantarget\n");
3317 f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3318 OutputCleanActions(f, "_OBJECTS", objectsParts);
3321 f.Puts("ifdef WINDOWS_TARGET\n");
3322 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3327 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)");
3328 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3329 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3330 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3331 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3332 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3336 f.Puts("realclean: cleantarget\n");
3337 f.Puts("\t$(call rmrq,$(OBJ))\n");
3338 if(!sameOrRelObjTargetDirs)
3339 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3342 f.Puts("distclean: cleantarget\n");
3343 if(!sameOrRelObjTargetDirs)
3344 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3346 f.Puts("\t$(call rmrq,obj/)\n");
3352 varStringLenDiffs.Free();
3353 delete varStringLenDiffs;
3357 delete cflagsVariations;
3358 delete nodeCFlagsMapping;
3359 delete ecflagsVariations;
3360 delete nodeECFlagsMapping;
3365 // ChangeWorkingDir(oldDirectory);
3366 // delete pathBackup;
3369 config.makingModified = false;
3373 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3375 char extension[MAX_EXTENSION] = "c";
3376 char modulePath[MAX_LOCATION];
3377 char fixedModuleName[MAX_FILENAME];
3380 char objDirNoSpaces[MAX_LOCATION];
3381 String objDirExp = GetObjDirExpression(config);
3383 ReplaceSpaces(objDirNoSpaces, objDirExp);
3384 ReplaceSpaces(fixedModuleName, moduleName);
3386 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3387 //strcat(fixedModuleName, ".main");
3389 #if 0 // TODO: Fix nospaces stuff
3390 // *** Dependency command ***
3391 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3393 // System Includes (from global settings)
3394 for(item : compiler.dirs[Includes])
3396 strcat(command, " -isystem ");
3397 if(strchr(item.name, ' '))
3399 strcat(command, "\"");
3400 strcat(command, item);
3401 strcat(command, "\"");
3404 strcat(command, item);
3407 for(item = includeDirs.first; item; item = item.next)
3409 strcat(command, " -I");
3410 if(strchr(item.name, ' '))
3412 strcat(command, "\"");
3413 strcat(command, item.name);
3414 strcat(command, "\"");
3417 strcat(command, item.name);
3419 for(item = preprocessorDefs.first; item; item = item.next)
3421 strcat(command, " -D");
3422 strcat(command, item.name);
3426 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
3430 bool firstLine = true;
3432 // To do some time: auto save external dependencies?
3435 if(dep.GetLine(line, sizeof(line)-1))
3439 char * colon = strstr(line, ":");
3440 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3454 // If we failed to generate dependencies...
3458 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3459 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $@\n", extension);
3467 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3470 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3472 for(v : cflagsVariations)
3477 f.Printf("%s +=", variableName);
3479 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3480 f.Puts(&v ? &v : "");
3490 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3491 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3493 *projectPlatformOptions = null;
3494 *configPlatformOptions = null;
3499 if(!strcmpi(p.name, platform))
3501 *projectPlatformOptions = p;
3506 if(config && config.platforms)
3508 for(p : config.platforms)
3510 if(!strcmpi(p.name, platform))
3512 *configPlatformOptions = p;
3520 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3522 if(prj.lastBuildNamesInfo)
3524 prj.lastBuildNamesInfo.Free();
3525 delete prj.lastBuildNamesInfo;
3527 prj.lastBuildNamesInfo = { };
3528 prj.topNode.GenMakefileGetNameCollisionInfo(prj.lastBuildNamesInfo, cfg);
3531 Project LegacyBinaryLoadProject(File f, char * filePath)
3533 Project project = null;
3534 char signature[sizeof(epjSignature)];
3536 f.Read(signature, sizeof(signature), 1);
3537 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3539 char topNodePath[MAX_LOCATION];
3540 /*ProjectConfig newConfig
3542 name = CopyString("Default");
3543 makingModified = true;
3544 compilingModified = true;
3545 linkingModified = true;
3549 project = Project { options = { } };
3550 LegacyBinaryLoadNode(project.topNode, f);
3551 delete project.topNode.path;
3552 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3553 MakeSlashPath(topNodePath);
3555 PathCatSlash(topNodePath, filePath);
3556 project.filePath = topNodePath;
3558 /* THIS IS ALREADY DONE BY filePath property
3559 StripLastDirectory(topNodePath, topNodePath);
3560 project.topNode.path = CopyString(topNodePath);
3562 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3564 // newConfig.options.defaultNameSpace = "";
3565 /*newConfig.objDir.dir = "obj";
3566 newConfig.targetDir.dir = "";*/
3568 //project.configurations = { [ newConfig ] };
3569 //project.config = newConfig;
3576 String targetFileName, targetDirectory, objectsDirectory;
3578 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3579 f.Read(&temp, sizeof(int),1);
3582 case 0: project.options.targetType = executable; break;
3583 case 1: project.options.targetType = sharedLibrary; break;
3584 case 2: project.options.targetType = staticLibrary; break;
3587 f.Read(&len, sizeof(int),1);
3588 targetFileName = new char[len+1];
3589 f.Read(targetFileName, sizeof(char), len+1);
3590 project.options.targetFileName = targetFileName;
3591 delete targetFileName;
3593 f.Read(&len, sizeof(int),1);
3594 targetDirectory = new char[len+1];
3595 f.Read(targetDirectory, sizeof(char), len+1);
3596 project.options.targetDirectory = targetDirectory;
3597 delete targetDirectory;
3599 f.Read(&len, sizeof(int),1);
3600 objectsDirectory = new byte[len+1];
3601 f.Read(objectsDirectory, sizeof(char), len+1);
3602 project.options.objectsDirectory = objectsDirectory;
3603 delete objectsDirectory;
3605 f.Read(&temp, sizeof(int),1);
3606 project./*config.*/options.debug = temp ? true : false;
3607 f.Read(&temp, sizeof(int),1);
3608 project./*config.*/options.optimization = temp ? speed : none;
3609 f.Read(&temp, sizeof(int),1);
3610 project./*config.*/options.profile = temp ? true : false;
3611 f.Read(&temp, sizeof(int),1);
3612 project.options.warnings = temp ? all : unset;
3614 f.Read(&count, sizeof(int),1);
3617 project.options.includeDirs = { };
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.includeDirs.Add(name);
3628 f.Read(&count, sizeof(int),1);
3631 project.options.libraryDirs = { };
3632 for(c = 0; c < count; c++)
3635 f.Read(&len, sizeof(int),1);
3636 name = new char[len+1];
3637 f.Read(name, sizeof(char), len+1);
3638 project.options.libraryDirs.Add(name);
3642 f.Read(&count, sizeof(int),1);
3645 project.options.libraries = { };
3646 for(c = 0; c < count; c++)
3649 f.Read(&len, sizeof(int),1);
3650 name = new char[len+1];
3651 f.Read(name, sizeof(char), len+1);
3652 project.options.libraries.Add(name);
3656 f.Read(&count, sizeof(int),1);
3659 project.options.preprocessorDefinitions = { };
3660 for(c = 0; c < count; c++)
3663 f.Read(&len, sizeof(int),1);
3664 name = new char[len+1];
3665 f.Read(name, sizeof(char), len+1);
3666 project.options.preprocessorDefinitions.Add(name);
3670 f.Read(&temp, sizeof(int),1);
3671 project.options.console = temp ? true : false;
3674 for(node : project.topNode.files)
3676 if(node.type == resources)
3678 project.resNode = node;
3688 void ProjectConfig::LegacyProjectConfigLoad(File f)
3696 char subSection[128];
3702 f.GetLine(buffer, 65536 - 1);
3703 TrimLSpaces(buffer, buffer);
3704 TrimRSpaces(buffer, buffer);
3707 if(buffer[0] == '-')
3711 TrimLSpaces(equal, equal);
3712 if(!strcmpi(subSection, "LibraryDirs"))
3714 if(!options.libraryDirs)
3715 options.libraryDirs = { [ CopyString(equal) ] };
3717 options.libraryDirs.Add(CopyString(equal));
3719 else if(!strcmpi(subSection, "IncludeDirs"))
3721 if(!options.includeDirs)
3722 options.includeDirs = { [ CopyString(equal) ] };
3724 options.includeDirs.Add(CopyString(equal));
3727 else if(buffer[0] == '+')
3738 TrimLSpaces(equal, equal);
3739 delete name; name = CopyString(equal); // property::name = equal;
3742 else if(!strcmpi(buffer, "Compiler Options"))
3743 strcpy(section, buffer);
3744 else if(!strcmpi(buffer, "IncludeDirs"))
3745 strcpy(subSection, buffer);
3746 else if(!strcmpi(buffer, "Linker Options"))
3747 strcpy(section, buffer);
3748 else if(!strcmpi(buffer, "LibraryDirs"))
3749 strcpy(subSection, buffer);
3750 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3757 equal = strstr(buffer, "=");
3761 TrimRSpaces(buffer, buffer);
3763 TrimLSpaces(equal, equal);
3764 if(!strcmpi(buffer, "Target Name"))
3765 options.targetFileName = /*CopyString(*/equal/*)*/;
3766 else if(!strcmpi(buffer, "Target Type"))
3768 if(!strcmpi(equal, "Executable"))
3769 options.targetType = executable;
3770 else if(!strcmpi(equal, "Shared"))
3771 options.targetType = sharedLibrary;
3772 else if(!strcmpi(equal, "Static"))
3773 options.targetType = staticLibrary;
3775 options.targetType = executable;
3777 else if(!strcmpi(buffer, "Target Directory"))
3778 options.targetDirectory = /*CopyString(*/equal/*)*/;
3779 else if(!strcmpi(buffer, "Console"))
3780 options.console = ParseTrueFalseValue(equal);
3781 else if(!strcmpi(buffer, "Libraries"))
3783 if(!options.libraries) options.libraries = { };
3784 ParseArrayValue(options.libraries, equal);
3786 else if(!strcmpi(buffer, "Intermediate Directory"))
3787 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3788 else if(!strcmpi(buffer, "Debug"))
3789 options.debug = ParseTrueFalseValue(equal);
3790 else if(!strcmpi(buffer, "Optimize"))
3792 if(!strcmpi(equal, "None"))
3793 options.optimization = none;
3794 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3795 options.optimization = speed;
3796 else if(!strcmpi(equal, "Size"))
3797 options.optimization = size;
3799 options.optimization = none;
3801 else if(!strcmpi(buffer, "Compress"))
3802 options.compress = ParseTrueFalseValue(equal);
3803 else if(!strcmpi(buffer, "Profile"))
3804 options.profile = ParseTrueFalseValue(equal);
3805 else if(!strcmpi(buffer, "AllWarnings"))
3806 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3807 else if(!strcmpi(buffer, "MemoryGuard"))
3808 options.memoryGuard = ParseTrueFalseValue(equal);
3809 else if(!strcmpi(buffer, "Default Name Space"))
3810 options.defaultNameSpace = CopyString(equal);
3811 else if(!strcmpi(buffer, "Strict Name Spaces"))
3812 options.strictNameSpaces = ParseTrueFalseValue(equal);
3813 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3815 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3816 ParseArrayValue(options.preprocessorDefinitions, equal);
3822 if(!options.targetDirectory && options.objectsDirectory)
3823 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3824 //if(!objDir.dir) objDir.dir = "obj";
3825 //if(!targetDir.dir) targetDir.dir = "";
3826 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3827 // if(!defaultNameSpace) property::defaultNameSpace = "";
3828 makingModified = true;
3831 Project LegacyAsciiLoadProject(File f, char * filePath)
3833 Project project = null;
3834 ProjectNode node = null;
3836 char parentPath[MAX_LOCATION];
3837 char section[128] = "";
3838 char subSection[128] = "";
3840 bool configurationsPresent = false;
3850 f.GetLine(buffer, 65536 - 1);
3851 TrimLSpaces(buffer, buffer);
3852 TrimRSpaces(buffer, buffer);
3855 if(buffer[0] == '-' || buffer[0] == '=')
3857 bool simple = buffer[0] == '-';
3860 TrimLSpaces(equal, equal);
3861 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3863 if(!project.config.options.libraryDirs)
3864 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3866 project.config.options.libraryDirs.Add(CopyString(equal));
3868 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3870 if(!project.config.options.includeDirs)
3871 project.config.options.includeDirs = { [ CopyString(equal) ] };
3873 project.config.options.includeDirs.Add(CopyString(equal));
3875 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3877 len = strlen(equal);
3880 char temp[MAX_LOCATION];
3881 ProjectNode child { };
3882 // We don't need to do this anymore, fileName is just a property that sets name & path
3883 // child.fileName = CopyString(equal);
3886 child.name = CopyString(equal);
3887 child.path = CopyString(parentPath);
3891 GetLastDirectory(equal, temp);
3892 child.name = CopyString(temp);
3893 StripLastDirectory(equal, temp);
3894 child.path = CopyString(temp);
3896 child.nodeType = file;
3897 child.parent = parent;
3898 child.indent = parent.indent + 1;
3900 child.icon = NodeIcons::SelectFileIcon(child.name);
3901 parent.files.Add(child);
3907 StripLastDirectory(parentPath, parentPath);
3908 parent = parent.parent;
3912 else if(buffer[0] == '+')
3916 TrimLSpaces(equal, equal);
3917 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3919 char temp[MAX_LOCATION];
3920 ProjectNode child { };
3921 // NEW: Folders now have a path set like files
3922 child.name = CopyString(equal);
3923 strcpy(temp, parentPath);
3924 PathCatSlash(temp, child.name);
3925 child.path = CopyString(temp);
3927 child.parent = parent;
3928 child.indent = parent.indent + 1;
3929 child.type = folder;
3930 child.nodeType = folder;
3932 child.icon = folder;
3933 PathCatSlash(parentPath, child.name);
3934 parent.files.Add(child);
3939 else if(!strcmpi(section, "Configurations"))
3941 ProjectConfig newConfig
3943 makingModified = true;
3947 LegacyProjectConfigLoad(newConfig, f);
3948 project.configurations.Add(newConfig);
3951 else if(!strcmpi(buffer, "ECERE Project File"));
3952 else if(!strcmpi(buffer, "Version 0a"))
3953 ; //strcpy(version, "0a");
3954 else if(!strcmpi(buffer, "Version 0.1a"))
3955 ; //strcpy(version, "0.1a");
3956 else if(!strcmpi(buffer, "Configurations"))
3958 project.configurations.Free();
3959 project.config = null;
3960 strcpy(section, buffer);
3961 configurationsPresent = true;
3963 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3965 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3966 char topNodePath[MAX_LOCATION];
3967 // newConfig.defaultNameSpace = "";
3968 //newConfig.objDir.dir = "obj";
3969 //newConfig.targetDir.dir = "";
3970 project = Project { /*options = { }*/ };
3971 project.configurations = { [ newConfig ] };
3972 project.config = newConfig;
3973 // if(project.topNode.path) delete project.topNode.path;
3974 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3975 MakeSlashPath(topNodePath);
3976 PathCatSlash(topNodePath, filePath);
3977 project.filePath = topNodePath;
3978 parentPath[0] = '\0';
3979 parent = project.topNode;
3981 strcpy(section, "Target");
3986 if(equal[0] == '\"')
3988 StripQuotes(equal, equal);
3989 delete project.moduleName; project.moduleName = CopyString(equal);
3993 else if(!strcmpi(buffer, "Compiler Options"));
3994 else if(!strcmpi(buffer, "IncludeDirs"))
3995 strcpy(subSection, buffer);
3996 else if(!strcmpi(buffer, "Linker Options"));
3997 else if(!strcmpi(buffer, "LibraryDirs"))
3998 strcpy(subSection, buffer);
3999 else if(!strcmpi(buffer, "Files"))
4001 strcpy(section, "Target");
4002 strcpy(subSection, buffer);
4004 else if(!strcmpi(buffer, "Resources"))
4006 ProjectNode child { };
4007 parent.files.Add(child);
4008 child.parent = parent;
4009 child.indent = parent.indent + 1;
4010 child.name = CopyString(buffer);
4011 child.path = CopyString("");
4012 child.type = resources;
4014 child.icon = archiveFile;
4015 project.resNode = child;
4018 strcpy(subSection, buffer);
4022 equal = strstr(buffer, "=");
4026 TrimRSpaces(buffer, buffer);
4028 TrimLSpaces(equal, equal);
4030 if(!strcmpi(section, "Target"))
4032 if(!strcmpi(buffer, "Build Exclusions"))
4034 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4036 /*if(node && node.type != NodeTypes::project)
4037 ParseListValue(node.buildExclusions, equal);*/
4040 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4042 delete project.resNode.path;
4043 project.resNode.path = CopyString(equal);
4044 PathCatSlash(parentPath, equal);
4048 else if(!strcmpi(buffer, "Intermediate Directory"))
4049 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4050 else if(!strcmpi(buffer, "Debug"))
4051 project.config.options.debug = ParseTrueFalseValue(equal);
4052 else if(!strcmpi(buffer, "Optimize"))
4054 if(!strcmpi(equal, "None"))
4055 project.config.options.optimization = none;
4056 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4057 project.config.options.optimization = speed;
4058 else if(!strcmpi(equal, "Size"))
4059 project.config.options.optimization = size;
4061 project.config.options.optimization = none;
4063 else if(!strcmpi(buffer, "Profile"))
4064 project.config.options.profile = ParseTrueFalseValue(equal);
4065 else if(!strcmpi(buffer, "MemoryGuard"))
4066 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4069 if(!project.options) project.options = { };
4071 // Project Wide Settings (All configs)
4072 if(!strcmpi(buffer, "Target Name"))
4073 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4074 else if(!strcmpi(buffer, "Target Type"))
4076 if(!strcmpi(equal, "Executable"))
4077 project.options.targetType = executable;
4078 else if(!strcmpi(equal, "Shared"))
4079 project.options.targetType = sharedLibrary;
4080 else if(!strcmpi(equal, "Static"))
4081 project.options.targetType = staticLibrary;
4083 project.options.targetType = executable;
4085 else if(!strcmpi(buffer, "Target Directory"))
4086 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4087 else if(!strcmpi(buffer, "Console"))
4088 project.options.console = ParseTrueFalseValue(equal);
4089 else if(!strcmpi(buffer, "Libraries"))
4091 if(!project.options.libraries) project.options.libraries = { };
4092 ParseArrayValue(project.options.libraries, equal);
4094 else if(!strcmpi(buffer, "AllWarnings"))
4095 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4096 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4098 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4100 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4101 ParseListValue(node.preprocessorDefs, equal);*/
4105 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4106 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4117 SplitPlatformLibraries(project);
4119 if(configurationsPresent)
4120 CombineIdenticalConfigOptions(project);
4124 void SplitPlatformLibraries(Project project)
4126 if(project && project.configurations)
4128 for(cfg : project.configurations)
4130 if(cfg.options.libraries && cfg.options.libraries.count)
4132 Iterator<String> it { cfg.options.libraries };
4136 char * platformName = strstr(l, ":");
4139 PlatformOptions platform = null;
4141 if(!cfg.platforms) cfg.platforms = { };
4142 for(p : cfg.platforms)
4144 if(!strcmpi(platformName, p.name))
4152 platform = { name = CopyString(platformName), options = { libraries = { } } };
4153 cfg.platforms.Add(platform);
4155 *(platformName-1) = 0;
4156 platform.options.libraries.Add(CopyString(l));
4158 cfg.options.libraries.Delete(it.pointer);
4167 void CombineIdenticalConfigOptions(Project project)
4169 if(project && project.configurations && project.configurations.count)
4172 ProjectOptions nullOptions { };
4173 ProjectConfig firstConfig = null;
4174 for(cfg : project.configurations)
4176 if(cfg.options.targetType != staticLibrary)
4183 firstConfig = project.configurations.firstIterator.data;
4185 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4187 if(!member.isProperty)
4189 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4194 for(cfg : project.configurations)
4196 if(cfg != firstConfig)
4198 if(cfg.options.targetType != staticLibrary)
4202 if(type.type == noHeadClass || type.type == normalClass)
4204 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4205 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4206 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4210 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4211 (byte *)firstConfig.options + member.offset + member._class.offset,
4212 (byte *)cfg.options + member.offset + member._class.offset);
4224 if(type.type == noHeadClass || type.type == normalClass)
4226 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4227 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4228 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4233 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4234 (byte *)firstConfig.options + member.offset + member._class.offset,
4235 (byte *)nullOptions + member.offset + member._class.offset))
4239 if(!project.options) project.options = { };
4241 /*if(type.type == noHeadClass || type.type == normalClass)
4243 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4244 (byte *)project.options + member.offset + member._class.offset,
4245 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4249 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4250 // TOFIX: ListBox::SetData / OnCopy mess
4251 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4252 (byte *)project.options + member.offset + member._class.offset,
4253 (type.typeSize > 4) ? address :
4254 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4255 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4256 (void *)*(byte *)address )));
4259 (byte *)project.options + member.offset + member._class.offset,
4260 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4262 for(cfg : project.configurations)
4264 if(cfg.options.targetType == staticLibrary)
4268 if(type.type == noHeadClass || type.type == normalClass)
4270 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4271 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4272 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4276 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4277 (byte *)firstConfig.options + member.offset + member._class.offset,
4278 (byte *)cfg.options + member.offset + member._class.offset);
4283 if(cfg != firstConfig)
4285 if(type.type == noHeadClass || type.type == normalClass)
4287 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4288 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4292 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4293 (byte *)cfg.options + member.offset + member._class.offset);
4295 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4298 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4305 // Compare Platform Specific Settings
4308 for(cfg : project.configurations)
4310 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4311 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4317 if(same && firstConfig.platforms)
4319 for(cfg : project.configurations)
4321 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4323 if(cfg != firstConfig)
4325 cfg.platforms.Free();
4326 delete cfg.platforms;
4329 project.platforms = firstConfig.platforms;
4330 firstConfig.platforms = null;
4334 // Static libraries can't contain libraries
4335 for(cfg : project.configurations)
4337 if(cfg.options.targetType == staticLibrary)
4339 if(!cfg.options.libraries) cfg.options.libraries = { };
4340 cfg.options.libraries.Free();
4346 Project LoadProject(char * filePath, char * activeConfigName)
4348 Project project = null;
4349 File f = FileOpen(filePath, read);
4352 project = LegacyBinaryLoadProject(f, filePath);
4355 JSONParser parser { f = f };
4356 JSONResult result = parser.GetObject(class(Project), &project);
4359 char insidePath[MAX_LOCATION];
4361 delete project.topNode.files;
4362 if(!project.files) project.files = { };
4363 project.topNode.files = project.files;
4366 char topNodePath[MAX_LOCATION];
4367 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4368 MakeSlashPath(topNodePath);
4369 PathCatSlash(topNodePath, filePath);
4370 project.filePath = topNodePath;//filePath;
4373 project.topNode.FixupNode(insidePath);
4375 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4376 delete project.resNode.path;
4377 project.resNode.path = project.resourcesPath;
4378 project.resourcesPath = null;
4379 project.resNode.nodeType = (ProjectNodeType)-1;
4380 delete project.resNode.files;
4381 project.resNode.files = project.resources;
4382 project.files = null;
4383 project.resources = null;
4384 if(!project.configurations) project.configurations = { };
4386 project.resNode.FixupNode(insidePath);
4391 project = LegacyAsciiLoadProject(f, filePath);
4397 if(!project.options) project.options = { };
4398 if(activeConfigName && activeConfigName[0] && project.configurations)
4399 project.config = project.GetConfig(activeConfigName);
4400 if(!project.config && project.configurations)
4401 project.config = project.configurations.firstIterator.data;
4403 if(!project.resNode)
4405 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4408 if(!project.moduleName)
4409 project.moduleName = CopyString(project.name);
4410 if(project.config &&
4411 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4412 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4414 //delete project.config.options.targetFileName;
4416 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4417 project.config.options.optimization = none;
4418 project.config.options.debug = true;
4419 //project.config.options.warnings = unset;
4420 project.config.options.memoryGuard = false;
4421 project.config.compilingModified = true;
4422 project.config.linkingModified = true;
4424 else if(!project.topNode.name && project.config)
4426 project.topNode.name = CopyString(project.config.options.targetFileName);
4429 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4430 project.topNode.configurations = project.configurations;
4431 project.topNode.platforms = project.platforms;
4432 project.topNode.options = project.options;*/