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 __attribute__((unused)) 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 #ifndef MAKEFILE_GENERATOR
46 IDESettings settings = (IDESettings)data;
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<const 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 // chars refused for project name: windowsFileNameCharsNotAllowed + " &,."
419 //define gnuMakeCharsNeedEscaping = "$%";
421 //define windowsFileNameCharsNotAllowed = "*/:<>?\\\"|";
422 //define linuxFileNameCharsNotAllowed = "/";
424 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
425 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
427 // NOTES: - this function should get only unescaped unix style paths
428 // - paths with literal $(somestring) in them are not supported
429 // my_$(messed_up)_path would likely become my__path
430 void EscapeForMake(char * output, const char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
432 char ch, *o = output;
433 const char *i = input;
436 int len = strlen(input);
437 if(len && ((input[0] == '"' && input[len-1] == '"') || strchr(input, '\\') || strchr(input, 127) || (!allowDblQuote && strchr(input, '"'))))
438 PrintLn("Invalid input for EscapeForMake! -- ", input);
444 if(i-1 != input && *(i-2) == '$' && allowVars)
451 if(inVar == true && allowVars)
456 else if(ch == '$' && *i != '(')
478 void EscapeForMakeToFile(File output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
480 char * buf = new char[strlen(input)*2+1];
481 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
486 void EscapeForMakeToDynString(DynamicString output, const char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
488 char * buf = new char[strlen(input)*2+1];
489 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
494 int OutputFileList(File f, const char * name, Array<String> list, Map<String, int> varStringLenDiffs, const char * prefix)
497 const int breakListLength = 1536;
498 const int breakLineLength = 78; // TODO: turn this into an option.
500 int c, len, itemCount = 0;
501 Array<int> breaks { };
505 MapNode<String, int> mn;
506 for(c=0; c<list.count; c++)
508 len = strlen(list[c]) + 3;
509 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
511 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
513 if(strstr(list[c], mn.key))
517 if(charCount + len > breakListLength)
519 breaks.Add(itemCount);
527 breaks.Add(itemCount);
528 numOfBreaks = breaks.count;
533 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
534 for(c=0; c<numOfBreaks; c++)
535 f.Printf(" $(%s%d)", name, c+1);
539 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
545 for(c=0; c<numOfBreaks; c++)
548 f.Printf("%s%d =", name, c+1);
551 itemCount = breaks[c];
552 for(n=offset; n<offset+itemCount; n++)
554 if(false) // TODO: turn this into an option.
556 int itemLen = strlen(list[n]);
557 if(len > 3 && len + itemLen > breakLineLength)
559 f.Printf(" \\\n\t%s", list[n]);
565 f.Printf(" %s", list[n]);
569 f.Printf(" \\\n\t%s", list[n]);
584 void OutputFileListActions(File f, const char * name, int parts, const char * fileName)
589 for(c=0; c<parts; c++)
590 f.Printf("\t@$(call echo,$(%s%d)) >> %s\n", name, c+1, fileName);
592 f.Printf("\t@$(call echo,$(%s)) >> %s\n", name, fileName);
596 void OutputCleanActions(File f, const char * name, int parts)
601 for(c=0; c<parts; c++)
602 f.Printf("\t$(call rmq,$(_%s%d))\n", name, c+1);
605 f.Printf("\t$(call rmq,$(_%s))\n", name);
608 enum LineOutputMethod { inPlace, newLine, lineEach };
609 enum StringOutputMethod { asIs, escape, escapePath};
611 enum ToolchainFlag { any, _D, _I, _isystem, _Wl, _L/*, _Wl-rpath*/ };
612 const String flagNames[ToolchainFlag] = { "", "-D", "-I", "-isystem ", "-Wl,", /*"-Wl,--library-path="*/"-L"/*, "-Wl,-rpath "*/ };
613 void OutputFlags(File f, ToolchainFlag flag, Array<String> list, LineOutputMethod lineMethod)
617 if(lineMethod == newLine)
621 if(lineMethod == lineEach)
623 f.Printf(" %s", flagNames[flag]);
624 if(flag != _D && flag != _Wl && flag != any)
626 char * tmp = new char[strlen(item)*2+1];
627 EscapeForMake(tmp, item, false, true, false);
628 f.Printf("$(call quote_path,%s)", tmp);
632 EscapeForMakeToFile(f, item, false, true, true);
637 static void OutputLibraries(File f, Array<String> libraries)
639 for(item : libraries)
641 char ext[MAX_EXTENSION];
642 char temp[MAX_LOCATION];
644 bool usedFunction = false;
645 GetExtension(item, ext);
646 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
650 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
652 if(!strncmp(item, "lib", 3))
653 strcpy(temp, item + 3);
656 StripExtension(temp);
659 f.Puts(" \\\n\t$(call _L,");
662 EscapeForMakeToFile(f, s, false, false, false);
668 void CamelCase(char * string)
672 int c, len = strlen(string);
673 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
674 string[c] = (char)tolower(string[c]);
678 CompilerConfig GetCompilerConfig()
680 #ifndef MAKEFILE_GENERATOR
681 CompilerConfig compiler = null;
682 if(ide && ide.workspace)
683 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
686 incref defaultCompiler;
687 return defaultCompiler;
691 define localTargetType = config && config.options && config.options.targetType ?
692 config.options.targetType : options && options.targetType ?
693 options.targetType : TargetTypes::executable;
694 define localWarnings = config && config.options && config.options.warnings ?
695 config.options.warnings : options && options.warnings ?
696 options.warnings : WarningsOption::unset;
697 define localDebug = config && config.options && config.options.debug ?
698 config.options.debug : options && options.debug ?
699 options.debug : SetBool::unset;
700 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
701 config.options.memoryGuard : options && options.memoryGuard ?
702 options.memoryGuard : SetBool::unset;
703 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
704 config.options.noLineNumbers : options && options.noLineNumbers ?
705 options.noLineNumbers : SetBool::unset;
706 define localProfile = config && config.options && config.options.profile ?
707 config.options.profile : options && options.profile ?
708 options.profile : SetBool::unset;
709 define localOptimization = config && config.options && config.options.optimization ?
710 config.options.optimization : options && options.optimization ?
711 options.optimization : OptimizationStrategy::none;
712 define localFastMath = config && config.options && config.options.fastMath ?
713 config.options.fastMath : options && options.fastMath ?
714 options.fastMath : SetBool::unset;
715 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
716 config.options.defaultNameSpace : options && options.defaultNameSpace ?
717 options.defaultNameSpace : null;
718 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
719 config.options.strictNameSpaces : options && options.strictNameSpaces ?
720 options.strictNameSpaces : SetBool::unset;
721 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
722 define localTargetFileName = config && config.options && config.options.targetFileName ?
723 config.options.targetFileName : options && options.targetFileName ?
724 options.targetFileName : "";
725 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
726 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
727 options.targetDirectory : null;
728 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
729 ideSettings.projectDefaultIntermediateObjDir[0] ?
730 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
731 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
732 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
733 options.objectsDirectory : null;
734 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
735 ideSettings.projectDefaultIntermediateObjDir[0] ?
736 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
737 define localConsole = config && config.options && config.options.console ?
738 config.options.console : options && options.console ?
739 options.console : SetBool::unset;
740 define localCompress = config && config.options && config.options.compress ?
741 config.options.compress : options && options.compress ?
742 options.compress : SetBool::unset;
744 define platformTargetType =
745 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
746 configPOs.options.targetType :
747 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
748 projectPOs.options.targetType : TargetTypes::unset;
751 const char * PlatformToMakefileTargetVariable(Platform platform)
753 return platform == win32 ? "WINDOWS_TARGET" :
754 platform == tux ? "LINUX_TARGET" :
755 platform == apple ? "OSX_TARGET" :
759 const char * TargetTypeToMakefileVariable(TargetTypes targetType)
761 return targetType == executable ? "executable" :
762 targetType == sharedLibrary ? "sharedlib" :
763 targetType == staticLibrary ? "staticlib" :
767 // Move this to ProjectConfig? null vs Common to consider...
768 const char * GetConfigName(ProjectConfig config)
770 return config ? config.name : "Common";
773 public enum SingleFileCompileMode
775 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
777 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
780 class Project : struct
782 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
783 // We might want to tweak this default behavior of regular classes ?
784 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
789 property const char * moduleVersion
791 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
792 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
793 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
796 property const char * description
798 set { delete description; if(value && value[0]) description = CopyString(value); }
799 get { return description ? description : ""; }
800 isset { return description != null && description[0]; }
803 property const char * license
805 set { delete license; if(value && value[0]) license = CopyString(value); }
806 get { return license ? license : ""; }
807 isset { return license != null && license[0]; }
810 property const char * compilerConfigsDir
812 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
813 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
814 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
817 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
818 property Array<PlatformOptions> platforms
820 get { return platforms; }
823 if(platforms) { platforms.Free(); delete platforms; }
826 List<PlatformOptions> empty { };
827 Iterator<PlatformOptions> it { value };
829 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
830 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
840 if(p.options && !p.options.isEmpty)
847 List<ProjectConfig> configurations;
848 LinkList<ProjectNode> files;
849 String resourcesPath;
850 LinkList<ProjectNode> resources;
853 // topNode.name holds the file name (.epj)
854 ProjectOptions options;
855 Array<PlatformOptions> platforms;
856 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
859 ProjectConfig config;
861 // This is the file name stripped of the epj extension
862 // It should NOT be edited, saved or loaded anywhere
867 String compilerConfigsDir;
868 String moduleVersion;
870 String lastBuildConfigName;
871 String lastBuildCompilerName;
873 Map<String, Map<String, NameCollisionInfo>> configsNameCollisions { };
875 #ifndef MAKEFILE_GENERATOR
876 FileMonitor fileMonitor
878 this, FileChange { modified = true };
879 bool OnFileNotify(FileChange action, const char * param)
881 fileMonitor.StopMonitoring();
882 if(OnProjectModified(action, param))
883 fileMonitor.StartMonitoring();
888 bool StartMonitoring()
890 fileMonitor.fileName = filePath;
891 fileMonitor.StartMonitoring();
895 bool StopMonitoring()
897 fileMonitor.StopMonitoring();
901 bool OnProjectModified(FileChange fileChange, const char * param)
904 sprintf(temp, $"The project %s was modified by another application.\n"
905 "Would you like to reload it and lose your changes?", name);
906 if(MessageBox { type = yesNo, master = ide,
907 text = $"Project has been modified", contents = temp }.Modal() == yes)
909 Project project = LoadProject(filePath, config ? config.name : null);
912 ProjectView projectView = ide.projectView;
913 DataRow prev = topNode.row ? topNode.row.previous : null;
914 FileMonitor fm = fileMonitor;
915 bool confirmation = true;
919 if(projectView.projectSettingsDialog)
921 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
923 projectView.projectSettingsDialog.Destroy(0);
926 projectView.DeleteNode(topNode);
933 topNode.project = this;
937 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
938 projectView.AddNode(topNode, null);
939 topNode.row.Move(prev);
941 projectView.ShowOutputBuildLog(true);
942 projectView.DisplayCompiler(compiler, false);
943 projectView.ProjectUpdateMakefileForAllConfigs(this);
946 eSystem_Delete(project);
958 // This frees contents without freeing the instance
959 // For use from destructor and for file monitor reloading
960 // (To work around JSON loader (LoadProject) always returning a new instance)
963 if(platforms) { platforms.Free(); delete platforms; }
964 if(configurations) { configurations.Free(); delete configurations; }
965 if(files) { files.Free(); delete files; }
966 if(resources) { resources.Free(); delete resources; }
968 delete resourcesPath;
972 delete compilerConfigsDir;
974 delete moduleVersion;
978 delete lastBuildConfigName;
979 delete lastBuildCompilerName;
980 for(map : configsNameCollisions)
982 configsNameCollisions.Free();
987 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
988 topNode.configurations = null;
989 topNode.platforms = null;
990 topNode.options = null;
995 property ProjectConfig config
1000 delete topNode.info;
1001 topNode.info = CopyString(GetConfigName(config));
1005 property const char * filePath
1011 char string[MAX_LOCATION];
1012 GetLastDirectory(value, string);
1013 delete topNode.name;
1014 topNode.name = CopyString(string);
1015 StripExtension(string);
1017 name = CopyString(string);
1018 StripLastDirectory(value, string);
1019 delete topNode.path;
1020 topNode.path = CopyString(string);
1022 filePath = CopyString(value);
1027 ProjectConfig GetConfig(const char * configName)
1029 ProjectConfig result = null;
1030 if(configName && configName[0] && configurations.count)
1032 for(cfg : configurations; !strcmpi(cfg.name, configName))
1041 ProjectNode FindNodeByObjectFileName(const char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config, const char * objectFileExt)
1044 const char * cfgName;
1046 config = this.config;
1047 cfgName = config ? config.name : "";
1048 if(!configsNameCollisions[cfgName])
1049 ProjectLoadLastBuildNamesInfo(this, config);
1050 result = topNode.FindByObjectFileName(fileName, type, dotMain, configsNameCollisions[cfgName], objectFileExt);
1054 TargetTypes GetTargetType(ProjectConfig config)
1056 TargetTypes targetType = localTargetType;
1060 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1063 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1065 PlatformOptions projectPOs, configPOs;
1066 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1067 if(platformTargetType)
1073 const char * GetObjDirExpression(ProjectConfig config)
1075 // TODO: Support platform options
1076 const char * expression = localObjectsDirectory;
1078 expression = settingsObjectsDirectory;
1082 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1084 const char * expression = GetObjDirExpression(config);
1085 DirExpression objDir { type = intermediateObjectsDir };
1086 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1090 const char * GetTargetDirExpression(ProjectConfig config)
1092 // TODO: Support platform options
1093 const char * expression = localTargetDirectory;
1095 expression = settingsTargetDirectory;
1099 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1101 const char * expression = GetTargetDirExpression(config);
1102 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1103 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1107 WarningsOption GetWarnings(ProjectConfig config)
1109 WarningsOption warnings = localWarnings;
1113 bool GetDebug(ProjectConfig config)
1115 SetBool debug = localDebug;
1116 return debug == true;
1119 bool GetMemoryGuard(ProjectConfig config)
1121 SetBool memoryGuard = localMemoryGuard;
1122 return memoryGuard == true;
1125 bool GetNoLineNumbers(ProjectConfig config)
1127 SetBool noLineNumbers = localNoLineNumbers;
1128 return noLineNumbers == true;
1131 bool GetProfile(ProjectConfig config)
1133 SetBool profile = localProfile;
1134 return profile == true;
1137 OptimizationStrategy GetOptimization(ProjectConfig config)
1139 OptimizationStrategy optimization = localOptimization;
1140 return optimization;
1143 bool GetFastMath(ProjectConfig config)
1145 SetBool fastMath = localFastMath;
1146 return fastMath == true;
1149 const String GetDefaultNameSpace(ProjectConfig config)
1151 const String defaultNameSpace = localDefaultNameSpace;
1152 return defaultNameSpace;
1155 bool GetStrictNameSpaces(ProjectConfig config)
1157 SetBool strictNameSpaces = localStrictNameSpaces;
1158 return strictNameSpaces == true;
1161 const String GetTargetFileName(ProjectConfig config)
1163 const String targetFileName = localTargetFileName;
1164 return targetFileName;
1167 //String targetDirectory;
1168 //String objectsDirectory;
1169 bool GetConsole(ProjectConfig config)
1171 SetBool console = localConsole;
1172 return console == true;
1175 bool GetCompress(ProjectConfig config)
1177 SetBool compress = localCompress;
1178 return compress == true;
1180 //SetBool excludeFromBuild;
1182 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1184 #ifndef MAKEFILE_GENERATOR
1185 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1191 bool GetConfigIsInDebugSession(ProjectConfig config)
1193 #ifndef MAKEFILE_GENERATOR
1194 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1200 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1202 #ifndef MAKEFILE_GENERATOR
1203 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1207 #ifndef MAKEFILE_GENERATOR
1208 bool Save(const char * fileName)
1211 /*char output[MAX_LOCATION];
1212 ChangeExtension(fileName, "json", output);
1213 f = FileOpen(output, write);*/
1214 f = FileOpen(fileName, write);
1217 files = topNode.files;
1218 resources = resNode.files;
1219 resourcesPath = resNode.path;
1221 files.Remove(resNode);
1224 WriteJSONObject(f, class(Project), this, 0);
1230 resourcesPath = null;
1237 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1239 TargetTypes targetType = GetTargetType(config);
1240 const String targetFileName = GetTargetFileName(config);
1241 if(targetType == staticLibrary)
1243 PathCatSlash(string, "lib");
1244 strcat(string, targetFileName);
1246 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1248 PathCatSlash(string, "lib");
1249 strcat(string, targetFileName);
1252 PathCatSlash(string, targetFileName);
1257 if(compiler.targetPlatform == win32)
1258 strcat(string, ".exe");
1261 if(compiler.targetPlatform == win32)
1262 strcat(string, ".dll");
1263 else if(compiler.targetPlatform == apple)
1264 strcat(string, ".dylib");
1266 strcat(string, ".so");
1267 if(compiler.targetPlatform == tux && __runtimePlatform == tux && moduleVersion && moduleVersion[0])
1269 strcat(string, ".");
1270 strcat(string, moduleVersion);
1274 strcat(string, ".a");
1279 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1281 bool result = false;
1282 char temp[MAX_LOCATION];
1283 strcpy(cfDir, topNode.path);
1284 if(compilerConfigsDir && compilerConfigsDir[0])
1286 PathCatSlash(cfDir, compilerConfigsDir);
1291 strcpy(temp, cfDir);
1292 // Using a relative path makes it less likely to run into spaces issues
1293 // Even with escaped spaces, there still seems to be issues including a config file
1294 // in a path containing spaces
1296 MakePathRelative(temp, topNode.path, cfDir);
1299 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1303 strcpy(temp, cfDir);
1304 ReplaceSpaces(cfDir, temp);
1309 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1311 char temp[MAX_LOCATION];
1312 bool result = false;
1313 strcpy(cfDir, topNode.path);
1314 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1316 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1321 // Default to <ProjectDir>/.configs if unset
1322 PathCatSlash(cfDir, ".configs");
1327 strcpy(temp, cfDir);
1328 // Using a relative path makes it less likely to run into spaces issues
1329 // Even with escaped spaces, there still seems to be issues including a config file
1330 // in a path containing spaces
1331 if(IsPathInsideOf(cfDir, topNode.path))
1332 MakePathRelative(temp, topNode.path, cfDir);
1334 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1338 strcpy(temp, cfDir);
1339 ReplaceSpaces(cfDir, temp);
1344 void CatMakeFileName(char * string, ProjectConfig config)
1346 char projectName[MAX_LOCATION];
1347 strcpy(projectName, name);
1348 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1351 #ifndef MAKEFILE_GENERATOR
1352 ProjectNode GetObjectFileNode(const char * filePath, const char * objectFileExt)
1354 ProjectNode node = null;
1355 char ext[MAX_EXTENSION];
1356 GetExtension(filePath, ext);
1359 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
1362 char fileName[MAX_FILENAME];
1363 GetLastDirectory(filePath, fileName);
1366 DotMain dotMain = DotMain::FromFileName(fileName);
1367 node = FindNodeByObjectFileName(fileName, type, dotMain, null, objectFileExt);
1374 bool GetAbsoluteFromRelativePath(const char * relativePath, char * absolutePath, const char * objectFileExt)
1376 ProjectNode node = topNode.FindWithPath(relativePath, false);
1378 node = GetObjectFileNode(relativePath, objectFileExt);
1381 strcpy(absolutePath, node.project.topNode.path);
1382 PathCat(absolutePath, relativePath);
1383 MakeSlashPath(absolutePath);
1385 return node != null;
1388 void MarkChanges(ProjectNode node)
1390 for(cfg : topNode.configurations)
1392 ProjectConfig c = null;
1393 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1395 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1396 (!c.options || !cfg.options)))
1397 cfg.symbolGenModified = true;
1398 if(c && ((c.options && cfg.options &&
1399 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1400 || (!c.options || !cfg.options)))
1401 cfg.linkingModified = true;
1403 cfg.makingModified = true;
1407 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1409 Map<String, NameCollisionInfo> cfgNameCollision;
1410 MapIterator<const String, Map<String, NameCollisionInfo>> it { map = configsNameCollisions };
1411 if(it.Index("", false))
1413 cfgNameCollision = it.data;
1414 cfgNameCollision.Free();
1415 delete cfgNameCollision;
1418 for(cfg : configurations)
1422 cfg.makingModified = true;
1423 if(it.Index(cfg.name, false))
1425 cfgNameCollision = it.data;
1426 cfgNameCollision.Free();
1427 delete cfgNameCollision;
1432 cfg.compilingModified = true;
1434 cfg.linkingModified = true;
1436 cfg.symbolGenModified = true;
1438 if(compiling || linking)
1440 ide.projectView.modifiedDocument = true;
1441 ide.workspace.modified = true;
1445 void RotateActiveConfig(bool forward, bool syncAllProjects)
1447 if(configurations.first && configurations.last != configurations.first)
1449 Iterator<ProjectConfig> cfg { configurations };
1450 while(forward ? cfg.Next() : cfg.Prev())
1451 if(cfg.data == config)
1466 ide.workspace.SelectActiveConfig(cfg.data.name);
1469 property::config = cfg.data;
1470 ide.UpdateToolBarActiveConfigs(true);
1471 ide.workspace.modified = true;
1472 ide.projectView.Update(null);
1477 bool ProcessPipeOutputRaw(DualPipe f)
1480 while(!f.Eof() && !ide.projectView.stopBuild)
1483 double lastTime = GetTime();
1487 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1489 ide.outputView.buildBox.Logf("%s\n", line);
1491 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1493 //printf("Processing Input...\n");
1494 if(app.ProcessInput(true))
1496 app.UpdateDisplay();
1499 //printf("Waiting...\n");
1502 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1504 if(ide.projectView.stopBuild)
1506 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1509 return !ide.projectView.stopBuild;
1512 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, BuildType buildType, List<ProjectNode> onlyNodes,
1513 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1517 bool compiling = false, linking = false, precompiling = false;
1518 int compilingEC = 0;
1519 int numErrors = 0, numWarnings = 0;
1520 bool loggedALine = false;
1521 int lenMakeCommand = strlen(compiler.makeCommand);
1523 const char * t, * s, * s2;
1524 char moduleName[MAX_FILENAME];
1525 const char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1527 DynamicString test { };
1528 DynamicString ecp { };
1529 DynamicString ecc { };
1530 DynamicString ecs { };
1531 DynamicString ear { };
1532 DynamicString prefix { };
1533 DynamicString cpp { };
1534 DynamicString cc { };
1535 DynamicString cxx { };
1536 DynamicString strip { };
1537 DynamicString ar { };
1538 DynamicString windres { };
1541 if(bitDepth == 64 && compiler.targetPlatform == win32)
1542 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1543 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1544 gnuToolchainPrefix = "i686-w64-mingw32-";
1546 ecp.concatx(compiler.ecpCommand, " ");
1547 ecc.concatx(compiler.eccCommand, " ");
1548 ecs.concatx(compiler.ecsCommand, " ");
1549 ear.concatx(compiler.earCommand, " ");
1552 compiler.ccacheEnabled ? "ccache " : "",
1553 compiler.distccEnabled ? "distcc " : "",
1554 gnuToolchainPrefix);
1556 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1557 cc.concatx((String)prefix, compiler.ccCommand, " ");
1558 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1560 strip.concatx(gnuToolchainPrefix, "strip ");
1561 ar.concatx(gnuToolchainPrefix, "ar rcs");
1562 windres.concatx(gnuToolchainPrefix, "windres ");
1564 testLen = Max(testLen, ecp.size);
1565 testLen = Max(testLen, ecc.size);
1566 testLen = Max(testLen, ecs.size);
1567 testLen = Max(testLen, ear.size);
1568 testLen = Max(testLen, cpp.size);
1569 testLen = Max(testLen, cc.size);
1570 testLen = Max(testLen, cxx.size);
1571 testLen = Max(testLen, strip.size);
1572 testLen = Max(testLen, ar.size);
1573 testLen = Max(testLen, windres.size);
1574 testLen = Max(testLen, strlen("mkdir "));
1577 while(!f.Eof() && !ide.projectView.stopBuild)
1579 double lastTime = GetTime();
1581 while(!f.Eof() && !ide.projectView.stopBuild)
1584 bool lineDone = f.GetLinePeek(line + linePos, sizeof(line)-linePos-1, &nChars);
1588 Sleep(0.5 / PEEK_RESOLUTION);
1595 const char * message = null;
1596 const char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1597 const char * from = strstr(line, stringFrom);
1598 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1599 if((t = strstr(line, (s=": recipe for target"))) && (t = strstr(t+strlen(s), (s2 = " failed"))) && (t+strlen(s2))[0] == '\0')
1600 ; // ignore this new gnu make error but what is it about?
1601 else if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1603 const char * moduleBackTick = strstr(line, "No rule to make target `");
1604 const char * module = moduleBackTick ? moduleBackTick : strstr(line, "No rule to make target '");
1608 module = strchr(module, moduleBackTick ? '`' : '\'') + 1;
1609 end = strchr(module, '\'');
1613 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1614 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1620 //ide.outputView.buildBox.Logf("error: %s\n", line);
1624 else if(strstr(test, "mkdir ") == test);
1625 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1626 else if(strstr(test, ear) == test);
1627 else if(strstr(test, strip) == test);
1628 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1630 char * module = null;
1631 bool isPrecomp = false;
1634 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1636 module = strstr(line, " -c ");
1637 if(module) module += 4;
1640 else if(strstr(test, ecc) == test)
1642 module = strstr(line, " -c ");
1643 if(module) module += 4;
1644 //module = line + 3;
1645 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1646 compilingEC = 3;//2;
1649 else if(strstr(test, ecp) == test)
1651 // module = line + 8;
1652 module = strstr(line, " -c ");
1653 if(module) module += 4;
1664 if(!compiling && !isPrecomp)
1666 ide.outputView.buildBox.Logf($"Compiling...\n");
1669 else if(!precompiling && isPrecomp)
1671 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1672 precompiling = true;
1674 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1675 GetLastDirectory(tokens[0], moduleName);
1676 ide.outputView.buildBox.Logf("%s\n", moduleName);
1678 else if((module = strstr(line, " -o ")))
1681 precompiling = false;
1683 ide.outputView.buildBox.Logf($"Linking...\n");
1687 ide.outputView.buildBox.Logf("%s\n", line);
1688 if(strstr(line, "warning:") || strstr(line, "note:"))
1690 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1694 if(compilingEC) compilingEC--;
1696 else if(strstr(test, windres) == test)
1699 module = strstr(line, " ");
1700 if(module) module++;
1704 char * dashF = strstr(module, "-F ");
1708 while(*dashF && *dashF != ' ') dashF++;
1709 while(*dashF && *dashF == ' ') dashF++;
1712 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1713 GetLastDirectory(module, moduleName);
1714 ide.outputView.buildBox.Logf("%s\n", moduleName);
1717 else if(strstr(test, ar) == test)
1718 ide.outputView.buildBox.Logf($"Building library...\n");
1719 else if(strstr(test, ecs) == test)
1720 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1723 if(linking || compiling || precompiling)
1725 const char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1726 const char * colon = strstr(start, ":"); //, * bracket;
1727 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1728 colon = strstr(colon + 1, ":");
1731 const char * sayError = "";
1732 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1735 int len = (int)(colon - start);
1736 char ext[MAX_EXTENSION];
1737 len = Min(len, MAX_LOCATION-1);
1738 // Don't be mistaken by the drive letter colon
1740 // TODO: need to fix colon - line gives char *
1741 // warning: incompatible expression colon - line (char *); expected int
1743 strncpy(moduleName, line, (int)(colon - line));
1744 moduleName[colon - line] = '\0';
1746 strncpy(moduleName, start, len);
1747 moduleName[len] = '\0';
1748 // Remove stuff in brackets
1749 //bracket = strstr(moduleName, "(");
1750 //if(bracket) *bracket = '\0';
1752 GetLastDirectory(moduleName, temp);
1753 GetExtension(temp, ext);
1755 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1757 char * cColon = strstr(colon+1, ":");
1758 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1759 cColon = strstr(cColon + 1, ":");
1762 int len = (int)(cColon - (colon+1));
1763 char mName[MAX_LOCATION];
1764 len = Min(len, MAX_LOCATION-1);
1765 strncpy(mName, colon+1, len);
1767 GetLastDirectory(mName, temp);
1768 GetExtension(temp, ext);
1769 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1772 strcpy(moduleName, mName);
1776 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1779 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1781 message = $"Linker Message: ";
1784 else if(SearchString(colon, 0, "warning:", false, false))
1786 message = $"Linker Warning: ";
1792 message = $"Linker Error: ";
1795 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1799 if(strstr(colon, "Warning:") == colon)
1801 message = $"Linker ";
1804 else if(strstr(line, "error:"))
1806 message = $"Linker Error: ";
1812 strcpy(temp, topNode.path);
1813 PathCatSlash(temp, moduleName);
1814 MakePathRelative(temp, topNode.path, moduleName);
1816 error = strstr(line, "error:");
1817 if(!message && error && error > colon)
1821 // Silence warnings for compiled eC
1822 //char * objDir = strstr(moduleName, objDirExp.dir);
1826 if((pointer = strstr(line, "undefined")) ||
1827 (pointer = strstr(line, "multiple definition")) ||
1828 (pointer = strstr(line, "No such file")) ||
1829 (pointer = strstr(line, "token")))
1831 strncat(moduleName, colon, pointer - colon);
1832 sayError = "error: ";
1837 else if((pointer = strstr(line, "No such file")))
1839 strncat(moduleName, colon, pointer - colon);
1840 sayError = "error: ";
1844 else //if(compilingEC == 1 || (objDir && objDir == moduleName))
1848 // Filter out these warnings caused by eC generated C code:
1850 // Declaration ordering bugs -- Awaiting topo sort implementation
1852 if(strstr(line, "declared inside parameter list")) skip = true;
1853 else if(strstr(line, "its scope is only this definition")) skip = true;
1854 else if(strstr(line, "from incompatible pointer type")) skip = true;
1855 else if(strstr(line, "note: expected 'struct ") || strstr(line, "note: expected ‘struct "))
1857 #define STRUCT_A "'struct "
1858 #define STRUCT_B "‘struct "
1859 char * struct1, * struct2, ch1, ch2;
1860 struct1 = strstr(line, STRUCT_A);
1861 if(struct1) { struct1 += sizeof(STRUCT_A)-1; } else { struct1 = strstr(line, STRUCT_B); struct1 += sizeof(STRUCT_B)-1; };
1863 struct2 = strstr(struct1, STRUCT_A);
1864 if(struct2) { struct2 += sizeof(STRUCT_A)-1; } else { struct2 = strstr(struct1, STRUCT_B); if(struct2) struct2 += sizeof(STRUCT_B)-1; };
1866 if(struct1 && struct2)
1868 while(ch1 = *(struct1++), ch2 = *(struct2++), ch1 && ch2 && (ch1 == '_' || isalnum(ch1)) && (ch2 == '_' || isalnum(ch2)));
1874 // For preprocessed code from objidl.h (MinGW-w64 headers)
1875 else if(strstr(line, "declaration does not declare anything")) skip = true;
1877 // Location information that could apply to ignored warnings
1878 else if(strstr(line, "In function '") || strstr(line, "In function ‘") ) skip = true;
1879 else if(strstr(line, "At top level")) skip = true;
1880 else if(strstr(line, "(near initialization for '") || strstr(line, "(near initialization for ‘")) skip = true;
1885 /*else if(strstr(line, "warning:"))
1891 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1892 /*else if(this == ide.workspace.projects.firstIterator.data)
1893 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1896 char fullModuleName[MAX_LOCATION];
1897 FileAttribs found = 0;
1898 //Project foundProject = this;
1901 char * loc = strstr(moduleName, ":");
1903 strcpy(fullModuleName, topNode.path);
1904 PathCat(fullModuleName, moduleName);
1905 found = FileExists(fullModuleName);
1906 if(!found && !strcmp(ext, "c"))
1908 char ecName[MAX_LOCATION];
1909 ChangeExtension(fullModuleName, "ec", ecName);
1910 found = FileExists(ecName);
1914 char path[MAX_LOCATION];
1915 if(ide && ide.workspace)
1917 for(prj : ide.workspace.projects)
1920 MakePathRelative(fullModuleName, prj.topNode.path, path);
1922 if((node = prj.topNode.FindWithPath(path, false)))
1924 strcpy(fullModuleName, prj.topNode.path);
1925 PathCatSlash(fullModuleName, node.path);
1926 PathCatSlash(fullModuleName, node.name);
1927 found = FileExists(fullModuleName);
1930 //foundProject = prj;
1935 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1937 for(prj : ide.workspace.projects)
1940 if((node = prj.topNode.Find(moduleName, false)))
1942 strcpy(fullModuleName, prj.topNode.path);
1943 PathCatSlash(fullModuleName, node.path);
1944 PathCatSlash(fullModuleName, node.name);
1945 found = FileExists(fullModuleName);
1948 //foundProject = prj;
1958 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1959 MakeSystemPath(fullModuleName);
1962 strcpy(fullModuleName, moduleName);
1965 strcat(fullModuleName, ":");
1966 strcat(fullModuleName, loc + 1);
1970 fullModuleName[0] = 0;
1971 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1976 ide.outputView.buildBox.Logf("%s\n", line);
1977 linking = compiling = precompiling = false;
1981 ide.outputView.buildBox.Logf("%s\n", line);
1986 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1988 //printf("Processing Input...\n");
1989 if(app.ProcessInput(true))
1991 app.UpdateDisplay();
1994 //printf("Waiting...\n");
1997 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1999 if(ide.projectView.stopBuild)
2001 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
2004 else if(loggedALine || buildType != run)
2006 if(f.GetExitCode() && !numErrors)
2008 /*bool result = */f.GetLine(line, sizeof(line)-1);
2009 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
2011 else if(buildType != install)
2015 char targetFileName[MAX_LOCATION];
2016 targetFileName[0] = '\0';
2017 CatTargetFileName(targetFileName, compiler, config);
2018 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
2021 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
2023 ide.outputView.buildBox.Logf($"no error, ");
2026 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
2028 ide.outputView.buildBox.Logf($"no warning\n");
2045 return numErrors == 0 && !ide.projectView.stopBuild;
2048 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
2051 int lenMakeCommand = strlen(compiler.makeCommand);
2056 double lastTime = GetTime();
2059 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2061 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
2062 else if(strstr(line, "mkdir") == line);
2063 else if(strstr(line, "del") == line);
2064 else if(strstr(line, "rm") == line);
2065 else if(strstr(line, "Could Not Find") == line);
2068 ide.outputView.buildBox.Logf(line);
2069 ide.outputView.buildBox.Logf("\n");
2073 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
2075 if(app.ProcessInput(true))
2077 app.UpdateDisplay();
2080 //Sleep(1.0 / PEEK_RESOLUTION);
2084 bool Build(BuildType buildType, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, bool raw, SingleFileCompileMode mode)
2086 bool result = false;
2088 char targetFileName[MAX_LOCATION] = "";
2089 DynamicString makeTargets { };
2090 char makeFile[MAX_LOCATION];
2091 char makeFilePath[MAX_LOCATION];
2092 char configName[MAX_LOCATION];
2093 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
2094 PathBackup pathBackup { };
2095 bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
2096 const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2098 bool eC_Debug = mode.eC_ToolsDebug;
2099 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2100 int numJobs = compiler.numJobs;
2101 char command[MAX_F_STRING*4];
2102 char * compilerName = CopyString(compiler.name);
2103 Map<String, NameCollisionInfo> cfgNameCollisions;
2104 const char * objFileExt = strcmp(compiler.objectFileExt, objectDefaultFileExt) != 0 ? compiler.objectFileExt : null;
2106 delete lastBuildConfigName;
2107 lastBuildConfigName = CopyString(config ? config.name : "Common");
2108 delete lastBuildCompilerName;
2109 lastBuildCompilerName = CopyString(compiler.name);
2110 ProjectLoadLastBuildNamesInfo(this, config);
2111 cfgNameCollisions = configsNameCollisions[config ? config.name : ""];
2113 CamelCase(compilerName);
2115 strcpy(configName, config ? config.name : "Common");
2117 SetPath(false, compiler, config, bitDepth); //true
2118 CatTargetFileName(targetFileName, compiler, config);
2120 strcpy(makeFilePath, topNode.path);
2121 CatMakeFileName(makeFile, config);
2122 PathCatSlash(makeFilePath, makeFile);
2124 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2125 if(buildType == install)
2126 makeTargets.concat(" install");
2129 if(compiler.type.isVC)
2131 PrintLn("compiling a single file is not yet supported");
2135 char pushD[MAX_LOCATION];
2136 char cfDir[MAX_LOCATION];
2137 GetIDECompilerConfigsDir(cfDir, true, true);
2138 GetWorkingDir(pushD, sizeof(pushD));
2139 ChangeWorkingDir(topNode.path);
2140 // Create object dir if it does not exist already
2141 if(!FileExists(objDirExp.dir).isDirectory)
2143 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s%s%s objdir -C \"%s\"%s -f \"%s\"",
2144 compiler.makeCommand, cfDir,
2145 crossCompiling ? " TARGET_PLATFORM=" : "",
2147 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2148 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2151 objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
2152 topNode.path, justPrint ? " -n" : "", makeFilePath);
2153 if(justPrint || raw)
2154 ide.outputView.buildBox.Logf("%s\n", command);
2158 ChangeWorkingDir(pushD);
2160 for(node : onlyNodes)
2162 if(node.GetIsExcludedForCompiler(config, compiler))
2163 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2167 node.DeleteIntermediateFiles(compiler, config, bitDepth, cfgNameCollisions, mode == cObject ? true : false);
2168 node.GetTargets(config, cfgNameCollisions, objDirExp.dir, compiler.objectFileExt, makeTargets);
2174 if(compiler.type.isVC)
2176 //bool result = false;
2177 char oldwd[MAX_LOCATION];
2178 GetWorkingDir(oldwd, sizeof(oldwd));
2179 ChangeWorkingDir(topNode.path);
2181 // TODO: support justPrint
2182 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2183 if(justPrint || raw)
2184 ide.outputView.buildBox.Logf("%s\n", command);
2185 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
2187 ProcessPipeOutputRaw(f);
2191 ChangeWorkingDir(oldwd);
2193 else if(onlyNodes && strlen(makeTargets) == 0)
2195 ide.outputView.buildBox.Log("No targets to compile.\n");
2199 GccVersionInfo ccVersion = GetGccVersionInfo(compiler, compiler.ccCommand);
2200 GccVersionInfo cxxVersion = GetGccVersionInfo(compiler, compiler.cxxCommand);
2201 char cfDir[MAX_LOCATION];
2202 GetIDECompilerConfigsDir(cfDir, true, true);
2203 sprintf(command, "%s%s %sCF_DIR=\"%s\"%s%s%s%s%s%s COMPILER=%s%s%s %s%s%s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2204 #if defined(__WIN32__)
2207 buildType == install ? "pkexec --user root " : "",
2209 compiler.makeCommand,
2210 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2212 crossCompiling ? " TARGET_PLATFORM=" : "",
2214 bitDepth ? " ARCH=" : "",
2215 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2216 ide.workspace.useValgrind ? " DISABLED_POOLING=1" : "",
2217 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2219 objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
2220 eC_Debug ? "--always-make " : "",
2221 ccVersion == post4_8 ? "GCC_CC_FLAGS=-fno-diagnostics-show-caret " : "",
2222 cxxVersion == post4_8 ? "GCC_CXX_FLAGS=-fno-diagnostics-show-caret " : "",
2224 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2225 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2226 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2227 if(justPrint || raw)
2228 ide.outputView.buildBox.Logf("%s\n", command);
2230 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2238 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2244 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2247 ide.outputView.buildBox.Logf("%s\n", line);
2248 if(!error && !found && strstr(line, "echo ") == line && strstr(line, "ECERE_SDK_SRC"))
2250 strcpy(command, line+5);
2253 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2255 strcpy(command, line);
2264 else if(justPrint || raw)
2265 result = ProcessPipeOutputRaw(f);
2267 result = ProcessBuildPipeOutput(f, objDirExp, buildType, onlyNodes, compiler, config, bitDepth);
2270 ide.outputView.buildBox.Logf("%s\n", command);
2271 else if(justPrint && found)
2272 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2277 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2282 delete compilerName;
2287 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint, bool raw)
2289 char makeFile[MAX_LOCATION];
2290 char makeFilePath[MAX_LOCATION];
2291 char command[MAX_LOCATION];
2292 char * compilerName;
2294 PathBackup pathBackup { };
2295 bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
2296 const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2297 const char * objFileExt = strcmp(compiler.objectFileExt, objectDefaultFileExt) ? compiler.objectFileExt : null;
2299 compilerName = CopyString(compiler.name);
2300 CamelCase(compilerName);
2302 SetPath(false, compiler, config, bitDepth);
2304 strcpy(makeFilePath, topNode.path);
2305 CatMakeFileName(makeFile, config);
2306 PathCatSlash(makeFilePath, makeFile);
2308 if(compiler.type.isVC)
2310 //bool result = false;
2311 char oldwd[MAX_LOCATION];
2312 GetWorkingDir(oldwd, sizeof(oldwd));
2313 ChangeWorkingDir(topNode.path);
2315 // TODO: justPrint support
2316 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2317 if(justPrint || raw)
2318 ide.outputView.buildBox.Logf("%s\n", command);
2319 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2321 ProcessPipeOutputRaw(f);
2325 ChangeWorkingDir(oldwd);
2330 char cfDir[MAX_LOCATION];
2331 GetIDECompilerConfigsDir(cfDir, true, true);
2332 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s%s%s %sclean%s -C \"%s\"%s -f \"%s\"",
2333 compiler.makeCommand, cfDir,
2334 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2335 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2337 objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
2338 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2339 topNode.path, justPrint ? " -n": "", makeFilePath);
2340 if(justPrint || raw)
2341 ide.outputView.buildBox.Logf("%s\n", command);
2342 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2344 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2345 cleanType == realClean ? $"intermediate objects directory" : $"target",
2346 cleanType == clean ? $" and object files" : "");
2347 if(justPrint || raw)
2348 ProcessPipeOutputRaw(f);
2350 ProcessCleanPipeOutput(f, compiler, config);
2351 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2352 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2353 cleanType == clean ? $" and object files" : "");
2359 delete compilerName;
2362 void Run(const char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2364 String target = new char[maxPathLen];
2365 char oldDirectory[MAX_LOCATION];
2366 char * executableLauncher = compiler.executableLauncher;
2367 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2368 PathBackup pathBackup { };
2370 // Build(project, ideMain, true, null, false);
2372 strcpy(target, topNode.path);
2373 PathCatSlash(target, targetDirExp.dir);
2374 CatTargetFileName(target, compiler, config);
2375 sprintf(target, "%s %s", target, args);
2376 GetWorkingDir(oldDirectory, MAX_LOCATION);
2378 if(strlen(ide.workspace.debugDir))
2380 char temp[MAX_LOCATION];
2381 strcpy(temp, topNode.path);
2382 PathCatSlash(temp, ide.workspace.debugDir);
2383 ChangeWorkingDir(temp);
2386 ChangeWorkingDir(topNode.path);
2387 SetPath(true, compiler, config, bitDepth);
2388 if(executableLauncher)
2390 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 8];
2391 prefixedTarget[0] = '\0';
2392 strcat(prefixedTarget, executableLauncher);
2393 strcat(prefixedTarget, " ");
2394 strcat(prefixedTarget, target);
2395 Execute(prefixedTarget);
2396 delete prefixedTarget;
2401 ChangeWorkingDir(oldDirectory);
2404 delete targetDirExp;
2408 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, bool raw, SingleFileCompileMode mode)
2410 return Build(build, nodes, compiler, config, bitDepth, justPrint, raw, mode);
2414 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2417 if(targetType == staticLibrary || targetType == sharedLibrary)
2418 strcat(fileName, "$(LP)");
2419 strcat(fileName, GetTargetFileName(config));
2420 strcat(fileName, "$(OUT)");
2423 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2425 bool result = false;
2426 char path[MAX_LOCATION];
2428 if(!GetProjectCompilerConfigsDir(path, false, false))
2429 GetIDECompilerConfigsDir(path, false, false);
2431 if(!FileExists(path).isDirectory)
2435 char dirName[MAX_FILENAME];
2436 GetLastDirectory(path, dirName);
2437 if(!strcmp(dirName, ".configs"))
2438 FileSetAttribs(path, FileAttribs { isHidden = true });
2441 PathCatSlash(path, "crossplatform.mk");
2443 if(FileExists(path))
2446 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2449 File f = FileOpen(path, write);
2452 include.Seek(0, start);
2453 for(; !include.Eof(); )
2456 int count = include.Read(buffer, 1, 4096);
2457 f.Write(buffer, 1, count);
2463 if(!altCrossPlatformMk)
2470 bool GenerateCompilerCf(CompilerConfig compiler, bool eC)
2472 bool result = false;
2473 char path[MAX_LOCATION];
2475 char * compilerName;
2476 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2477 const char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2478 Platform platform = compiler.targetPlatform;
2480 compilerName = CopyString(compiler.name);
2481 CamelCase(compilerName);
2482 name = PrintString(platform, "-", compilerName, ".cf");
2484 if(!GetProjectCompilerConfigsDir(path, false, false))
2485 GetIDECompilerConfigsDir(path, false, false);
2487 if(!FileExists(path).isDirectory)
2491 char dirName[MAX_FILENAME];
2492 GetLastDirectory(path, dirName);
2493 if(!strcmp(dirName, ".configs"))
2494 FileSetAttribs(path, FileAttribs { isHidden = true });
2497 PathCatSlash(path, name);
2499 if(FileExists(path))
2502 File f = FileOpen(path, write);
2505 if(compiler.environmentVars && compiler.environmentVars.count)
2507 f.Puts("# ENVIRONMENT VARIABLES\n");
2509 for(e : compiler.environmentVars)
2511 #if defined(__WIN32__)
2512 ChangeCh(e.string, '\\', '/');
2514 f.Printf("export %s := %s\n", e.name, e.string);
2515 #if defined(__WIN32__)
2516 ChangeCh(e.string, '/', '\\');
2522 f.Puts("# TOOLCHAIN\n");
2525 f.Puts("# EXTENSIONS\n");
2526 if(compiler.outputFileExt)
2527 f.Printf("OUT := %s\n", compiler.outputFileExt);
2529 f.Puts("OUT := $(if $(STATIC_LIBRARY_TARGET),$(A),$(if $(SHARED_LIBRARY_TARGET),$(SO)$(VER),$(if $(EXECUTABLE_TARGET),$(E),.x)))\n");
2531 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2533 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2536 if(compiler.sysroot && compiler.sysroot[0])
2538 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2539 // Moved this to crossplatform.mk
2540 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2544 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2545 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2546 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)\n", compiler.ccCommand);
2547 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CXX_FLAGS),$(space)$(GCC_CXX_FLAGS),)\n", compiler.cxxCommand);
2550 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)\n", compiler.ecpCommand);
2551 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),)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)\n", compiler.eccCommand);
2552 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,)$(if $(DISABLED_POOLING), -disabled-pooling,)\n", compiler.ecsCommand);
2556 f.Printf("ECP := %s\n", compiler.ecpCommand);
2557 f.Printf("ECC := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2558 f.Printf("ECS := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)$(if $(DISABLED_POOLING), -disabled-pooling,)\n", compiler.ecsCommand);
2560 f.Printf("EAR := %s\n", compiler.earCommand);
2562 f.Puts("AS := $(GCC_PREFIX)as\n");
2563 f.Printf("LD := $(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_LD_FLAGS),$(space)$(GCC_LD_FLAGS),)\n", compiler.ldCommand);
2564 f.Printf("AR := $(GCC_PREFIX)%s\n", compiler.arCommand);
2565 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2566 f.Puts("ifdef WINDOWS_TARGET\n");
2567 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2568 f.Puts(" ifdef ARCH\n");
2569 f.Puts(" ifeq ($(ARCH),x32)\n");
2570 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2572 f.Puts(" ifeq ($(ARCH),x64)\n");
2573 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2578 f.Puts("UPX := upx\n");
2581 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2584 f.Puts("EARFLAGS = \n");
2587 f.Puts("ifndef ARCH\n");
2588 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2589 f.Puts(" ifdef WINDOWS_HOST\n");
2590 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2591 f.Puts(" TARGET_ARCH := x86_64\n");
2593 f.Puts(" TARGET_ARCH := i386\n");
2596 f.Puts("endif\n\n");
2598 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2599 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2603 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2607 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2610 if(compiler.includeDirs && compiler.includeDirs.count)
2612 f.Puts("\nCFLAGS +=");
2613 OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
2616 if(compiler.prepDirectives && compiler.prepDirectives.count)
2618 f.Puts("\nCFLAGS +=");
2619 OutputFlags(f, _D, compiler.prepDirectives, inPlace);
2622 if(compiler.libraryDirs && compiler.libraryDirs.count)
2624 f.Puts("\nLDFLAGS +=");
2625 OutputFlags(f, _L, compiler.libraryDirs, lineEach);
2626 // We would need a bool option to know whether we want to add to rpath as well...
2627 // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
2630 if(compiler.excludeLibs && compiler.excludeLibs.count)
2632 f.Puts("\nEXCLUDED_LIBS =");
2633 for(l : compiler.excludeLibs)
2639 if(compiler.eCcompilerFlags && compiler.eCcompilerFlags.count)
2641 f.Puts("\nECFLAGS +=");
2642 OutputFlags(f, any, compiler.eCcompilerFlags, inPlace);
2645 if(compiler.compilerFlags && compiler.compilerFlags.count)
2647 f.Puts("\nCFLAGS +=");
2648 OutputFlags(f, any, compiler.compilerFlags, inPlace);
2651 if(compiler.linkerFlags && compiler.linkerFlags.count)
2653 f.Puts("\nLDFLAGS +=");
2654 OutputFlags(f, _Wl, compiler.linkerFlags, inPlace);
2658 f.Puts("\nOFLAGS += $(LDFLAGS)");
2660 f.Puts("ifdef ARCH_FLAGS\n");
2661 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2662 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2671 delete compilerName;
2675 bool GenerateMakefile(const char * altMakefilePath, bool noResources, const char * includemkPath, ProjectConfig config, const char * ldCommand)
2677 bool result = false;
2678 char filePath[MAX_LOCATION];
2679 char makeFile[MAX_LOCATION];
2680 // PathBackup pathBackup { };
2681 // char oldDirectory[MAX_LOCATION];
2684 if(!altMakefilePath)
2686 strcpy(filePath, topNode.path);
2687 CatMakeFileName(makeFile, config);
2688 PathCatSlash(filePath, makeFile);
2691 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2693 /*SetPath(false, compiler, config);
2694 GetWorkingDir(oldDirectory, MAX_LOCATION);
2695 ChangeWorkingDir(topNode.path);*/
2702 char targetDir[MAX_LOCATION];
2703 char objDirExpNoSpaces[MAX_LOCATION];
2704 char objDirNoSpaces[MAX_LOCATION];
2705 char resDirNoSpaces[MAX_LOCATION];
2706 char targetDirExpNoSpaces[MAX_LOCATION];
2707 char fixedModuleName[MAX_FILENAME];
2708 char fixedConfigName[MAX_FILENAME];
2710 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2711 // Non-zero if we're building eC code
2712 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2713 int numCObjects = 0;
2715 int numRCObjects = 0;
2716 bool containsCXX = false; // True if the project contains a C++ file
2717 bool relObjDir, sameOrRelObjTargetDirs;
2718 const String objDirExp = GetObjDirExpression(config);
2719 TargetTypes targetType = GetTargetType(config);
2721 char cfDir[MAX_LOCATION];
2722 int objectsParts = 0;
2723 int eCsourcesParts = 0;
2724 int rcSourcesParts = 0;
2725 Array<String> listItems { };
2726 Map<String, int> varStringLenDiffs { };
2727 Map<String, NameCollisionInfo> namesInfo { };
2729 Map<String, int> cflagsVariations { };
2730 Map<intptr, int> nodeCFlagsMapping { };
2732 Map<String, int> ecflagsVariations { };
2733 Map<intptr, int> nodeECFlagsMapping { };
2735 ReplaceSpaces(objDirNoSpaces, objDirExp);
2736 strcpy(targetDir, GetTargetDirExpression(config));
2737 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2739 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2740 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2742 char temp[MAX_LOCATION];
2743 ReplaceSpaces(temp, objDirExpNoSpaces);
2744 strcpy(objDirExpNoSpaces, temp);
2746 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2747 ReplaceSpaces(fixedModuleName, moduleName);
2748 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2749 CamelCase(fixedConfigName);
2751 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2752 relObjDir = lenObjDirExpNoSpaces == 0 ||
2753 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2754 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2755 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2756 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2757 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2759 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2761 f.Puts("# CORE VARIABLES\n\n");
2763 f.Printf("MODULE := %s\n", fixedModuleName);
2764 f.Printf("VERSION := %s\n", property::moduleVersion);
2765 f.Printf("CONFIG := %s\n", fixedConfigName);
2766 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2769 test = GetTargetTypeIsSetByPlatform(config);
2773 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2775 TargetTypes targetType;
2776 PlatformOptions projectPOs, configPOs;
2777 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2778 targetType = platformTargetType;
2784 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2785 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2790 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2795 for(c = 0; c < ifCount; c++)
2801 f.Puts("# FLAGS\n\n");
2803 f.Puts("ECFLAGS =\n");
2804 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2805 f.Puts("PRJ_CFLAGS =\n");
2806 f.Puts("CECFLAGS =\n");
2807 f.Puts("OFLAGS =\n");
2811 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2814 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2815 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2816 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2817 //f.Puts("endif\n");
2820 f.Puts("# INCLUDES\n\n");
2822 if(compilerConfigsDir && compilerConfigsDir[0])
2824 strcpy(cfDir, compilerConfigsDir);
2825 if(cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2830 GetIDECompilerConfigsDir(cfDir, true, true);
2831 // Use CF_DIR environment variable for absolute paths only
2832 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2833 strcpy(cfDir, "$(CF_DIR)");
2836 f.Printf("_CF_DIR = %s\n", cfDir);
2839 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2840 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2843 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2845 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2848 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2851 // test = GetTargetTypeIsSetByPlatform(config);
2853 char target[MAX_LOCATION];
2854 char temp[MAX_LOCATION];
2859 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2861 if(type != targetType)
2866 f.Printf("ifeq ($(TARGET_TYPE),%s)\n", TargetTypeToMakefileVariable(type));
2868 GetMakefileTargetFileName(type, target, config);
2869 strcpy(temp, targetDir);
2870 PathCatSlash(temp, target);
2871 ReplaceSpaces(target, temp);
2872 f.Printf("TARGET = %s\n", target);
2877 GetMakefileTargetFileName(targetType, target, config);
2878 strcpy(temp, targetDir);
2879 PathCatSlash(temp, target);
2880 ReplaceSpaces(target, temp);
2881 f.Printf("TARGET = %s\n", target);
2887 for(c = 0; c < ifCount; c++)
2894 // Use something fixed here, to not cause Makefile differences across compilers...
2895 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2896 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2898 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2902 const char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2904 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2907 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2909 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2910 if(eCsourcesParts > 1)
2912 for(c = 1; c <= eCsourcesParts; c++)
2913 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2917 for(c = 0; c < 5; c++)
2919 if(eCsourcesParts > 1)
2922 f.Printf("_%s =", map[c][0]);
2923 for(n = 1; n <= eCsourcesParts; n++)
2924 f.Printf(" $(%s%d)", map[c][0], n);
2926 for(n = 1; n <= eCsourcesParts; n++)
2927 f.Printf("_%s%d = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d))))\n", map[c][0], n, map[c][1], n);
2929 else if(eCsourcesParts == 1)
2930 f.Printf("_%s = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES))))\n", map[c][0], map[c][1]);
2934 for(c = 0; c < 5; c++)
2936 if(eCsourcesParts > 1)
2939 f.Printf("%s =", map[c][0]);
2940 for(n = 1; n <= eCsourcesParts; n++)
2941 f.Printf(" $(%s%d)", map[c][0], n);
2943 for(n = 1; n <= eCsourcesParts; n++)
2944 f.Printf("%s%d = $(call shwspace,$(_%s%d))\n", map[c][0], n, map[c][0], n);
2946 else if(eCsourcesParts == 1)
2947 f.Printf("%s = $(call shwspace,$(_%s))\n", map[c][0], map[c][0]);
2953 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2956 f.Puts("ifdef WINDOWS_TARGET\n\n");
2958 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2960 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2961 if(rcSourcesParts > 1)
2963 for(c = 1; c <= rcSourcesParts; c++)
2964 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2967 if(rcSourcesParts > 1)
2970 f.Printf("%s =", "RCOBJECTS");
2971 for(n = 1; n <= rcSourcesParts; n++)
2972 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2974 for(n = 1; n <= rcSourcesParts; n++)
2975 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2977 else if(rcSourcesParts == 1)
2978 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2982 f.Puts("RCSOURCES =\n");
2983 f.Puts("RCOBJECTS =\n");
2984 f.Puts("endif\n\n");
2987 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2989 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2990 f.Printf("OBJECTS =%s%s%s%s\n",
2991 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2992 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2993 numRCObjects ? " $(RCOBJECTS)" : "");
2996 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2998 const char * prefix;
2999 if(numCObjects && numRCObjects)
3000 prefix = "$(ECSOURCES) $(RCSOURCES)";
3001 else if(numCObjects)
3002 prefix = "$(ECSOURCES)";
3005 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
3009 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
3010 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
3012 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
3014 if((config && config.options && config.options.libraries) ||
3015 (options && options.libraries))
3017 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3019 if(config && config.options && config.options.libraries)
3020 OutputLibraries(f, config.options.libraries);
3021 else if(options && options.libraries)
3022 OutputLibraries(f, options.libraries);
3028 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects != 0,
3029 cflagsVariations, nodeCFlagsMapping,
3030 ecflagsVariations, nodeECFlagsMapping, null);
3032 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
3033 f.Puts("ECFLAGS += -module $(MODULE)\n");
3034 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
3036 if(platforms || (config && config.platforms))
3039 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
3040 //for(platform = win32; platform <= apple; platform++)
3042 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
3043 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3045 PlatformOptions projectPlatformOptions, configPlatformOptions;
3046 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
3048 if(projectPlatformOptions || configPlatformOptions)
3053 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3056 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
3057 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
3059 f.Puts("CFLAGS +=");
3060 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
3063 for(s : projectPlatformOptions.options.compilerOptions)
3066 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
3069 for(s : configPlatformOptions.options.compilerOptions)
3076 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
3077 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
3079 f.Puts("OFLAGS +=");
3080 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
3082 bool needWl = false;
3084 for(s : projectPlatformOptions.options.linkerOptions)
3086 if(!IsLinkerOption(s))
3094 for(s : projectPlatformOptions.options.linkerOptions)
3095 if(IsLinkerOption(s))
3099 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
3101 bool needWl = false;
3103 for(s : configPlatformOptions.options.linkerOptions)
3105 if(IsLinkerOption(s))
3113 for(s : configPlatformOptions.options.linkerOptions)
3114 if(!IsLinkerOption(s))
3122 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3123 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
3124 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
3125 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
3127 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3128 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3129 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
3131 f.Puts("OFLAGS +=");
3132 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
3133 OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
3134 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
3135 OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
3139 if(configPlatformOptions && configPlatformOptions.options.libraries)
3141 if(configPlatformOptions.options.libraries.count)
3144 OutputLibraries(f, configPlatformOptions.options.libraries);
3148 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3150 if(projectPlatformOptions.options.libraries.count)
3153 OutputLibraries(f, projectPlatformOptions.options.libraries);
3164 for(c = 0; c < ifCount; c++)
3170 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3171 (options && options.compilerOptions && options.compilerOptions.count))
3173 f.Puts("CFLAGS +=");
3176 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3178 for(s : config.options.compilerOptions)
3181 if(options && options.compilerOptions && options.compilerOptions.count)
3183 for(s : options.compilerOptions)
3190 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3191 (options && options.linkerOptions && options.linkerOptions.count))
3193 f.Puts("OFLAGS +=");
3196 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3198 bool needWl = false;
3199 for(s : config.options.linkerOptions)
3201 if(!IsLinkerOption(s))
3209 for(s : config.options.linkerOptions)
3210 if(IsLinkerOption(s))
3214 if(options && options.linkerOptions && options.linkerOptions.count)
3216 bool needWl = false;
3217 for(s : options.linkerOptions)
3219 if(!IsLinkerOption(s))
3227 for(s : options.linkerOptions)
3228 if(IsLinkerOption(s))
3236 f.Puts("CECFLAGS += -cpp $(_CPP)");
3240 if(GetProfile(config))
3241 f.Puts("OFLAGS += -pg\n\n");
3243 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3245 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3246 f.Puts("OFLAGS +=");
3247 if(config && config.options && config.options.libraryDirs)
3248 OutputFlags(f, _L, config.options.libraryDirs, lineEach);
3249 if(options && options.libraryDirs)
3250 OutputFlags(f, _L, options.libraryDirs, lineEach);
3256 f.Puts("# TARGETS\n");
3259 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3262 f.Puts("objdir:\n");
3264 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3267 f.Puts("\t$(if $(ECERE_SDK_SRC),$(if $(wildcard $(call escspace,$(ECERE_SDK_SRC)/crossplatform.mk)),,@$(call echo,Ecere SDK Source Warning: The value of ECERE_SDK_SRC is pointing to an incorrect ($(ECERE_SDK_SRC)) location.)),)\n");
3268 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");
3270 //f.Puts("# PRE-BUILD COMMANDS\n");
3271 if(options && options.prebuildCommands)
3273 for(s : options.prebuildCommands)
3274 if(s && s[0]) f.Printf("\t%s\n", s);
3276 if(config && config.options && config.options.prebuildCommands)
3278 for(s : config.options.prebuildCommands)
3279 if(s && s[0]) f.Printf("\t%s\n", s);
3281 if(platforms || (config && config.platforms))
3284 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3285 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3287 PlatformOptions projectPOs, configPOs;
3288 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3290 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3291 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3296 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3298 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3300 for(s : projectPOs.options.prebuildCommands)
3301 if(s && s[0]) f.Printf("\t%s\n", s);
3303 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3305 for(s : configPOs.options.prebuildCommands)
3306 if(s && s[0]) f.Printf("\t%s\n", s);
3313 for(c = 0; c < ifCount; c++)
3319 if(!sameOrRelObjTargetDirs)
3321 f.Puts("targetdir:\n");
3322 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3328 // Main Module (Linking) for ECERE C modules
3329 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3330 f.Printf("\t@$(call rmq,$(OBJ)symbols.lst)\n");
3331 f.Printf("\t@$(call touch,$(OBJ)symbols.lst)\n");
3332 OutputFileListActions(f, "SYMBOLS", eCsourcesParts, "$(OBJ)symbols.lst");
3333 OutputFileListActions(f, "IMPORTS", eCsourcesParts, "$(OBJ)symbols.lst");
3334 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3335 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) @$(OBJ)symbols.lst -symbols %s -o $(call quote_path,$@)\n",
3336 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3338 // Main Module (Linking) for ECERE C modules
3339 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3340 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3341 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3342 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3343 " -c $(OBJ)$(MODULE).main.ec -o $(call quote_path,$@) -symbols $(OBJ)\n");
3349 // This would not rebuild the target on updated objects
3350 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3352 // This should fix it for good!
3353 f.Puts("$(SYMBOLS): | objdir\n");
3354 f.Puts("$(OBJECTS): | objdir\n");
3356 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3357 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3358 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3360 f.Printf("\t@$(call rmq,$(OBJ)objects.lst)\n");
3361 f.Printf("\t@$(call touch,$(OBJ)objects.lst)\n");
3362 OutputFileListActions(f, "_OBJECTS", objectsParts, "$(OBJ)objects.lst");
3365 f.Puts("ifdef WINDOWS_TARGET\n");
3366 OutputFileListActions(f, "RCOBJECTS", rcSourcesParts, "$(OBJ)objects.lst");
3371 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)objects.lst\n");
3372 OutputFileListActions(f, "ECOBJECTS", eCsourcesParts, "$(OBJ)objects.lst");
3375 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3377 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)objects.lst $(LIBS) -o $(TARGET) $(INSTALLNAME)\n", ldCommand && ldCommand[0] ? "LD" : containsCXX ? "CXX" : "CC");
3378 if(!GetDebug(config))
3380 f.Puts("ifndef NOSTRIP\n");
3381 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3384 if(GetCompress(config))
3386 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3387 f.Puts("ifdef EXECUTABLE_TARGET\n");
3388 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3391 //f.Puts("ifneq ($(TARGET_ARCH),x86_64)\n");
3392 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3393 //f.Puts("endif\n");
3397 if(resNode.files && resNode.files.count && !noResources)
3398 resNode.GenMakefileAddResources(f, resNode.path, config);
3400 f.Puts("ifdef WINDOWS_HOST\n");
3401 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)objects.lst $(LIBS)\n");
3403 f.Puts("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
3406 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3407 f.Puts("ifdef LINUX_TARGET\n");
3408 f.Puts("ifdef LINUX_HOST\n");
3409 // TODO?: support symlinks for longer version numbers
3410 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3411 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3416 //f.Puts("# POST-BUILD COMMANDS\n");
3417 if(options && options.postbuildCommands)
3419 for(s : options.postbuildCommands)
3420 if(s && s[0]) f.Printf("\t%s\n", s);
3422 if(config && config.options && config.options.postbuildCommands)
3424 for(s : config.options.postbuildCommands)
3425 if(s && s[0]) f.Printf("\t%s\n", s);
3427 if(platforms || (config && config.platforms))
3430 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3431 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3433 PlatformOptions projectPOs, configPOs;
3434 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3436 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3437 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3442 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3444 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3446 for(s : projectPOs.options.postbuildCommands)
3447 if(s && s[0]) f.Printf("\t%s\n", s);
3449 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3451 for(s : configPOs.options.postbuildCommands)
3452 if(s && s[0]) f.Printf("\t%s\n", s);
3459 for(c = 0; c < ifCount; c++)
3466 if(platforms || (config && config.platforms))
3468 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3470 PlatformOptions projectPOs, configPOs;
3471 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3473 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3474 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3481 if(test || (options && options.installCommands) ||
3482 (config && config.options && config.options.installCommands))
3484 f.Puts("install:\n");
3485 if(options && options.installCommands)
3487 for(s : options.installCommands)
3488 if(s && s[0]) f.Printf("\t%s\n", s);
3490 if(config && config.options && config.options.installCommands)
3492 for(s : config.options.installCommands)
3493 if(s && s[0]) f.Printf("\t%s\n", s);
3495 if(platforms || (config && config.platforms))
3498 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3500 PlatformOptions projectPOs, configPOs;
3501 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3503 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3504 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3509 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3511 if(projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count)
3513 for(s : projectPOs.options.installCommands)
3514 if(s && s[0]) f.Printf("\t%s\n", s);
3516 if(configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count)
3518 for(s : configPOs.options.installCommands)
3519 if(s && s[0]) f.Printf("\t%s\n", s);
3526 for(c = 0; c < ifCount; c++)
3533 f.Puts("# SYMBOL RULES\n");
3536 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3538 f.Puts("# C OBJECT RULES\n");
3541 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3543 f.Puts("# OBJECT RULES\n");
3545 // todo call this still but only generate rules whith specific options
3546 // see we-have-file-specific-options in ProjectNode.ec
3547 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3550 GenMakefilePrintMainObjectRule(f, config);
3552 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3555 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)");
3556 f.Printf("\t$(call rmq,$(OBJ)symbols.lst)\n");
3558 f.Printf("\t$(call rmq,$(OBJ)objects.lst)\n");
3559 f.Puts("\t$(call rmq,$(TARGET))\n");
3560 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3561 f.Puts("ifdef LINUX_TARGET\n");
3562 f.Puts("ifdef LINUX_HOST\n");
3563 // TODO?: support symlinks for longer version numbers
3564 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3565 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3571 f.Puts("clean: cleantarget\n");
3572 OutputCleanActions(f, "OBJECTS", objectsParts);
3575 f.Puts("ifdef WINDOWS_TARGET\n");
3576 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3581 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3582 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3583 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3584 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3585 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3589 f.Puts("realclean: cleantarget\n");
3590 f.Puts("\t$(call rmrq,$(OBJ))\n");
3591 if(!sameOrRelObjTargetDirs)
3592 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3595 f.Puts("distclean: cleantarget\n");
3596 if(!sameOrRelObjTargetDirs)
3597 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3599 f.Puts("\t$(call rmrq,obj/)\n");
3605 varStringLenDiffs.Free();
3606 delete varStringLenDiffs;
3610 delete cflagsVariations;
3611 delete nodeCFlagsMapping;
3612 delete ecflagsVariations;
3613 delete nodeECFlagsMapping;
3618 // ChangeWorkingDir(oldDirectory);
3619 // delete pathBackup;
3622 config.makingModified = false;
3626 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3628 char extension[MAX_EXTENSION] = "c";
3629 //char modulePath[MAX_LOCATION];
3630 char fixedModuleName[MAX_FILENAME];
3632 //char command[2048];
3633 char objDirNoSpaces[MAX_LOCATION];
3634 const String objDirExp = GetObjDirExpression(config);
3636 ReplaceSpaces(objDirNoSpaces, objDirExp);
3637 ReplaceSpaces(fixedModuleName, moduleName);
3639 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3640 //strcat(fixedModuleName, ".main");
3642 #if 0 // TODO: Fix nospaces stuff
3643 // *** Dependency command ***
3644 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3646 // System Includes (from global settings)
3647 for(item : compiler.dirs[Includes])
3649 strcat(command, " -isystem ");
3650 if(strchr(item.name, ' '))
3652 strcat(command, "\"");
3653 strcat(command, item);
3654 strcat(command, "\"");
3657 strcat(command, item);
3660 for(item = includeDirs.first; item; item = item.next)
3662 strcat(command, " -I");
3663 if(strchr(item.name, ' '))
3665 strcat(command, "\"");
3666 strcat(command, item.name);
3667 strcat(command, "\"");
3670 strcat(command, item.name);
3672 for(item = preprocessorDefs.first; item; item = item.next)
3674 strcat(command, " -D");
3675 strcat(command, item.name);
3679 if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
3683 bool firstLine = true;
3685 // To do some time: auto save external dependencies?
3688 if(dep.GetLine(line, sizeof(line)-1))
3692 char * colon = strstr(line, ":");
3693 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3707 // If we failed to generate dependencies...
3711 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3712 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(call quote_path,$@)\n", extension);
3720 void GenMakePrintCustomFlags(File f, const String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3723 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3725 for(v : cflagsVariations)
3730 f.Printf("%s +=", variableName);
3732 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3733 f.Puts(&v ? &v : "");
3741 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3742 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3744 *projectPlatformOptions = null;
3745 *configPlatformOptions = null;
3750 if(!strcmpi(p.name, platform))
3752 *projectPlatformOptions = p;
3757 if(config && config.platforms)
3759 for(p : config.platforms)
3761 if(!strcmpi(p.name, platform))
3763 *configPlatformOptions = p;
3771 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3773 const char * cfgName = cfg ? cfg.name : "";
3774 Map<String, NameCollisionInfo> cfgNameCollisions = prj.configsNameCollisions[cfgName];
3775 if(cfgNameCollisions)
3777 cfgNameCollisions.Free();
3778 delete cfgNameCollisions;
3780 prj.configsNameCollisions[cfgName] = cfgNameCollisions = { };
3781 prj.topNode.GenMakefileGetNameCollisionInfo(cfgNameCollisions, cfg);
3784 Project LegacyBinaryLoadProject(File f, const char * filePath)
3786 Project project = null;
3787 char signature[sizeof(epjSignature)];
3789 f.Read(signature, sizeof(signature), 1);
3790 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3792 char topNodePath[MAX_LOCATION];
3793 /*ProjectConfig newConfig
3795 name = CopyString("Default");
3796 makingModified = true;
3797 compilingModified = true;
3798 linkingModified = true;
3802 project = Project { options = { } };
3803 LegacyBinaryLoadNode(project.topNode, f);
3804 delete project.topNode.path;
3805 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3806 MakeSlashPath(topNodePath);
3808 PathCatSlash(topNodePath, filePath);
3809 project.filePath = topNodePath;
3811 /* THIS IS ALREADY DONE BY filePath property
3812 StripLastDirectory(topNodePath, topNodePath);
3813 project.topNode.path = CopyString(topNodePath);
3815 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3817 // newConfig.options.defaultNameSpace = "";
3818 /*newConfig.objDir.dir = "obj";
3819 newConfig.targetDir.dir = "";*/
3821 //project.configurations = { [ newConfig ] };
3822 //project.config = newConfig;
3829 String targetFileName, targetDirectory, objectsDirectory;
3831 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3832 f.Read(&temp, sizeof(int),1);
3835 case 0: project.options.targetType = executable; break;
3836 case 1: project.options.targetType = sharedLibrary; break;
3837 case 2: project.options.targetType = staticLibrary; break;
3840 f.Read(&len, sizeof(int),1);
3841 targetFileName = new char[len+1];
3842 f.Read(targetFileName, sizeof(char), len+1);
3843 project.options.targetFileName = targetFileName;
3844 delete targetFileName;
3846 f.Read(&len, sizeof(int),1);
3847 targetDirectory = new char[len+1];
3848 f.Read(targetDirectory, sizeof(char), len+1);
3849 project.options.targetDirectory = targetDirectory;
3850 delete targetDirectory;
3852 f.Read(&len, sizeof(int),1);
3853 objectsDirectory = new byte[len+1];
3854 f.Read(objectsDirectory, sizeof(char), len+1);
3855 project.options.objectsDirectory = objectsDirectory;
3856 delete objectsDirectory;
3858 f.Read(&temp, sizeof(int),1);
3859 project./*config.*/options.debug = temp ? true : false;
3860 f.Read(&temp, sizeof(int),1);
3861 project./*config.*/options.optimization = temp ? speed : none;
3862 f.Read(&temp, sizeof(int),1);
3863 project./*config.*/options.profile = temp ? true : false;
3864 f.Read(&temp, sizeof(int),1);
3865 project.options.warnings = temp ? all : unset;
3867 f.Read(&count, sizeof(int),1);
3870 project.options.includeDirs = { };
3871 for(c = 0; c < count; c++)
3874 f.Read(&len, sizeof(int),1);
3875 name = new char[len+1];
3876 f.Read(name, sizeof(char), len+1);
3877 project.options.includeDirs.Add(name);
3881 f.Read(&count, sizeof(int),1);
3884 project.options.libraryDirs = { };
3885 for(c = 0; c < count; c++)
3888 f.Read(&len, sizeof(int),1);
3889 name = new char[len+1];
3890 f.Read(name, sizeof(char), len+1);
3891 project.options.libraryDirs.Add(name);
3895 f.Read(&count, sizeof(int),1);
3898 project.options.libraries = { };
3899 for(c = 0; c < count; c++)
3902 f.Read(&len, sizeof(int),1);
3903 name = new char[len+1];
3904 f.Read(name, sizeof(char), len+1);
3905 project.options.libraries.Add(name);
3909 f.Read(&count, sizeof(int),1);
3912 project.options.preprocessorDefinitions = { };
3913 for(c = 0; c < count; c++)
3916 f.Read(&len, sizeof(int),1);
3917 name = new char[len+1];
3918 f.Read(name, sizeof(char), len+1);
3919 project.options.preprocessorDefinitions.Add(name);
3923 f.Read(&temp, sizeof(int),1);
3924 project.options.console = temp ? true : false;
3927 for(node : project.topNode.files)
3929 if(node.type == resources)
3931 project.resNode = node;
3941 void ProjectConfig::LegacyProjectConfigLoad(File f)
3949 char subSection[128];
3954 f.GetLine(buffer, 65536 - 1);
3955 TrimLSpaces(buffer, buffer);
3956 TrimRSpaces(buffer, buffer);
3959 if(buffer[0] == '-')
3963 TrimLSpaces(equal, equal);
3964 if(!strcmpi(subSection, "LibraryDirs"))
3966 if(!options.libraryDirs)
3967 options.libraryDirs = { [ CopyString(equal) ] };
3969 options.libraryDirs.Add(CopyString(equal));
3971 else if(!strcmpi(subSection, "IncludeDirs"))
3973 if(!options.includeDirs)
3974 options.includeDirs = { [ CopyString(equal) ] };
3976 options.includeDirs.Add(CopyString(equal));
3979 else if(buffer[0] == '+')
3990 TrimLSpaces(equal, equal);
3991 delete name; name = CopyString(equal); // property::name = equal;
3994 else if(!strcmpi(buffer, "Compiler Options"))
3995 strcpy(section, buffer);
3996 else if(!strcmpi(buffer, "IncludeDirs"))
3997 strcpy(subSection, buffer);
3998 else if(!strcmpi(buffer, "Linker Options"))
3999 strcpy(section, buffer);
4000 else if(!strcmpi(buffer, "LibraryDirs"))
4001 strcpy(subSection, buffer);
4002 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
4009 equal = strstr(buffer, "=");
4013 TrimRSpaces(buffer, buffer);
4015 TrimLSpaces(equal, equal);
4016 if(!strcmpi(buffer, "Target Name"))
4017 options.targetFileName = /*CopyString(*/equal/*)*/;
4018 else if(!strcmpi(buffer, "Target Type"))
4020 if(!strcmpi(equal, "Executable"))
4021 options.targetType = executable;
4022 else if(!strcmpi(equal, "Shared"))
4023 options.targetType = sharedLibrary;
4024 else if(!strcmpi(equal, "Static"))
4025 options.targetType = staticLibrary;
4027 options.targetType = executable;
4029 else if(!strcmpi(buffer, "Target Directory"))
4030 options.targetDirectory = /*CopyString(*/equal/*)*/;
4031 else if(!strcmpi(buffer, "Console"))
4032 options.console = ParseTrueFalseValue(equal);
4033 else if(!strcmpi(buffer, "Libraries"))
4035 if(!options.libraries) options.libraries = { };
4036 ParseArrayValue(options.libraries, equal);
4038 else if(!strcmpi(buffer, "Intermediate Directory"))
4039 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4040 else if(!strcmpi(buffer, "Debug"))
4041 options.debug = ParseTrueFalseValue(equal);
4042 else if(!strcmpi(buffer, "Optimize"))
4044 if(!strcmpi(equal, "None"))
4045 options.optimization = none;
4046 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4047 options.optimization = speed;
4048 else if(!strcmpi(equal, "Size"))
4049 options.optimization = size;
4051 options.optimization = none;
4053 else if(!strcmpi(buffer, "Compress"))
4054 options.compress = ParseTrueFalseValue(equal);
4055 else if(!strcmpi(buffer, "Profile"))
4056 options.profile = ParseTrueFalseValue(equal);
4057 else if(!strcmpi(buffer, "AllWarnings"))
4058 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4059 else if(!strcmpi(buffer, "MemoryGuard"))
4060 options.memoryGuard = ParseTrueFalseValue(equal);
4061 else if(!strcmpi(buffer, "Default Name Space"))
4062 options.defaultNameSpace = CopyString(equal);
4063 else if(!strcmpi(buffer, "Strict Name Spaces"))
4064 options.strictNameSpaces = ParseTrueFalseValue(equal);
4065 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4067 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
4068 ParseArrayValue(options.preprocessorDefinitions, equal);
4074 if(!options.targetDirectory && options.objectsDirectory)
4075 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
4076 //if(!objDir.dir) objDir.dir = "obj";
4077 //if(!targetDir.dir) targetDir.dir = "";
4078 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
4079 // if(!defaultNameSpace) property::defaultNameSpace = "";
4080 makingModified = true;
4083 Project LegacyAsciiLoadProject(File f, const char * filePath)
4085 Project project = null;
4087 char parentPath[MAX_LOCATION];
4088 char section[128] = "";
4089 char subSection[128] = "";
4090 ProjectNode parent = null;
4091 bool configurationsPresent = false;
4101 f.GetLine(buffer, 65536 - 1);
4102 TrimLSpaces(buffer, buffer);
4103 TrimRSpaces(buffer, buffer);
4106 if(buffer[0] == '-' || buffer[0] == '=')
4108 bool simple = buffer[0] == '-';
4111 TrimLSpaces(equal, equal);
4112 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
4114 if(!project.config.options.libraryDirs)
4115 project.config.options.libraryDirs = { [ CopyString(equal) ] };
4117 project.config.options.libraryDirs.Add(CopyString(equal));
4119 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
4121 if(!project.config.options.includeDirs)
4122 project.config.options.includeDirs = { [ CopyString(equal) ] };
4124 project.config.options.includeDirs.Add(CopyString(equal));
4126 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4128 len = strlen(equal);
4131 char temp[MAX_LOCATION];
4132 ProjectNode child { };
4133 // We don't need to do this anymore, fileName is just a property that sets name & path
4134 // child.fileName = CopyString(equal);
4137 child.name = CopyString(equal);
4138 child.path = CopyString(parentPath);
4142 GetLastDirectory(equal, temp);
4143 child.name = CopyString(temp);
4144 StripLastDirectory(equal, temp);
4145 child.path = CopyString(temp);
4147 child.nodeType = file;
4148 child.parent = parent;
4149 child.indent = parent.indent + 1;
4151 child.icon = NodeIcons::SelectFileIcon(child.name);
4152 parent.files.Add(child);
4158 StripLastDirectory(parentPath, parentPath);
4159 parent = parent.parent;
4163 else if(buffer[0] == '+')
4167 TrimLSpaces(equal, equal);
4168 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4170 char temp[MAX_LOCATION];
4171 ProjectNode child { };
4172 // NEW: Folders now have a path set like files
4173 child.name = CopyString(equal);
4174 strcpy(temp, parentPath);
4175 PathCatSlash(temp, child.name);
4176 child.path = CopyString(temp);
4178 child.parent = parent;
4179 child.indent = parent.indent + 1;
4180 child.type = folder;
4181 child.nodeType = folder;
4183 child.icon = folder;
4184 PathCatSlash(parentPath, child.name);
4185 parent.files.Add(child);
4190 else if(!strcmpi(section, "Configurations"))
4192 ProjectConfig newConfig
4194 makingModified = true;
4198 LegacyProjectConfigLoad(newConfig, f);
4199 project.configurations.Add(newConfig);
4202 else if(!strcmpi(buffer, "ECERE Project File"));
4203 else if(!strcmpi(buffer, "Version 0a"))
4204 ; //strcpy(version, "0a");
4205 else if(!strcmpi(buffer, "Version 0.1a"))
4206 ; //strcpy(version, "0.1a");
4207 else if(!strcmpi(buffer, "Configurations"))
4209 project.configurations.Free();
4210 project.config = null;
4211 strcpy(section, buffer);
4212 configurationsPresent = true;
4214 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
4216 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
4217 char topNodePath[MAX_LOCATION];
4218 // newConfig.defaultNameSpace = "";
4219 //newConfig.objDir.dir = "obj";
4220 //newConfig.targetDir.dir = "";
4221 project = Project { /*options = { }*/ };
4222 project.configurations = { [ newConfig ] };
4223 project.config = newConfig;
4224 // if(project.topNode.path) delete project.topNode.path;
4225 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4226 MakeSlashPath(topNodePath);
4227 PathCatSlash(topNodePath, filePath);
4228 project.filePath = topNodePath;
4229 parentPath[0] = '\0';
4230 parent = project.topNode;
4232 strcpy(section, "Target");
4237 if(equal[0] == '\"')
4239 StripQuotes(equal, equal);
4240 delete project.moduleName; project.moduleName = CopyString(equal);
4244 else if(!strcmpi(buffer, "Compiler Options"));
4245 else if(!strcmpi(buffer, "IncludeDirs"))
4246 strcpy(subSection, buffer);
4247 else if(!strcmpi(buffer, "Linker Options"));
4248 else if(!strcmpi(buffer, "LibraryDirs"))
4249 strcpy(subSection, buffer);
4250 else if(!strcmpi(buffer, "Files"))
4252 strcpy(section, "Target");
4253 strcpy(subSection, buffer);
4255 else if(!strcmpi(buffer, "Resources"))
4257 ProjectNode child { };
4258 parent.files.Add(child);
4259 child.parent = parent;
4260 child.indent = parent.indent + 1;
4261 child.name = CopyString(buffer);
4262 child.path = CopyString("");
4263 child.type = resources;
4265 child.icon = archiveFile;
4266 project.resNode = child;
4269 strcpy(subSection, buffer);
4273 equal = strstr(buffer, "=");
4277 TrimRSpaces(buffer, buffer);
4279 TrimLSpaces(equal, equal);
4281 if(!strcmpi(section, "Target"))
4283 if(!strcmpi(buffer, "Build Exclusions"))
4285 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4287 /*if(node && node.type != NodeTypes::project)
4288 ParseListValue(node.buildExclusions, equal);*/
4291 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4293 delete project.resNode.path;
4294 project.resNode.path = CopyString(equal);
4295 PathCatSlash(parentPath, equal);
4299 else if(!strcmpi(buffer, "Intermediate Directory"))
4300 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4301 else if(!strcmpi(buffer, "Debug"))
4302 project.config.options.debug = ParseTrueFalseValue(equal);
4303 else if(!strcmpi(buffer, "Optimize"))
4305 if(!strcmpi(equal, "None"))
4306 project.config.options.optimization = none;
4307 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4308 project.config.options.optimization = speed;
4309 else if(!strcmpi(equal, "Size"))
4310 project.config.options.optimization = size;
4312 project.config.options.optimization = none;
4314 else if(!strcmpi(buffer, "Profile"))
4315 project.config.options.profile = ParseTrueFalseValue(equal);
4316 else if(!strcmpi(buffer, "MemoryGuard"))
4317 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4320 if(!project.options) project.options = { };
4322 // Project Wide Settings (All configs)
4323 if(!strcmpi(buffer, "Target Name"))
4324 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4325 else if(!strcmpi(buffer, "Target Type"))
4327 if(!strcmpi(equal, "Executable"))
4328 project.options.targetType = executable;
4329 else if(!strcmpi(equal, "Shared"))
4330 project.options.targetType = sharedLibrary;
4331 else if(!strcmpi(equal, "Static"))
4332 project.options.targetType = staticLibrary;
4334 project.options.targetType = executable;
4336 else if(!strcmpi(buffer, "Target Directory"))
4337 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4338 else if(!strcmpi(buffer, "Console"))
4339 project.options.console = ParseTrueFalseValue(equal);
4340 else if(!strcmpi(buffer, "Libraries"))
4342 if(!project.options.libraries) project.options.libraries = { };
4343 ParseArrayValue(project.options.libraries, equal);
4345 else if(!strcmpi(buffer, "AllWarnings"))
4346 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4347 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4349 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4351 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4352 ParseListValue(node.preprocessorDefs, equal);*/
4356 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4357 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4368 SplitPlatformLibraries(project);
4370 if(configurationsPresent)
4371 CombineIdenticalConfigOptions(project);
4375 void SplitPlatformLibraries(Project project)
4377 if(project && project.configurations)
4379 for(cfg : project.configurations)
4381 if(cfg.options.libraries && cfg.options.libraries.count)
4383 Iterator<String> it { cfg.options.libraries };
4387 char * platformName = strstr(l, ":");
4390 PlatformOptions platform = null;
4392 if(!cfg.platforms) cfg.platforms = { };
4393 for(p : cfg.platforms)
4395 if(!strcmpi(platformName, p.name))
4403 platform = { name = CopyString(platformName), options = { libraries = { } } };
4404 cfg.platforms.Add(platform);
4406 *(platformName-1) = 0;
4407 platform.options.libraries.Add(CopyString(l));
4409 cfg.options.libraries.Delete(it.pointer);
4418 void CombineIdenticalConfigOptions(Project project)
4420 if(project && project.configurations && project.configurations.count)
4423 ProjectOptions nullOptions { };
4424 ProjectConfig firstConfig = null;
4425 for(cfg : project.configurations)
4427 if(cfg.options.targetType != staticLibrary)
4434 firstConfig = project.configurations.firstIterator.data;
4436 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4438 if(!member.isProperty)
4440 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4445 for(cfg : project.configurations)
4447 if(cfg != firstConfig)
4449 if(cfg.options.targetType != staticLibrary)
4453 if(type.type == noHeadClass || type.type == normalClass)
4455 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4456 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4457 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4461 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4462 (byte *)firstConfig.options + member.offset + member._class.offset,
4463 (byte *)cfg.options + member.offset + member._class.offset);
4475 if(type.type == noHeadClass || type.type == normalClass)
4477 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4478 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4479 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4484 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4485 (byte *)firstConfig.options + member.offset + member._class.offset,
4486 (byte *)nullOptions + member.offset + member._class.offset))
4490 if(!project.options) project.options = { };
4492 /*if(type.type == noHeadClass || type.type == normalClass)
4494 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4495 (byte *)project.options + member.offset + member._class.offset,
4496 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4500 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4501 // TOFIX: ListBox::SetData / OnCopy mess
4502 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4503 (byte *)project.options + member.offset + member._class.offset,
4504 (type.typeSize > 4) ? address :
4505 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4506 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4507 (void *)*(byte *)address )));
4510 (byte *)project.options + member.offset + member._class.offset,
4511 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4513 for(cfg : project.configurations)
4515 if(cfg.options.targetType == staticLibrary)
4519 if(type.type == noHeadClass || type.type == normalClass)
4521 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4522 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4523 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4527 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4528 (byte *)firstConfig.options + member.offset + member._class.offset,
4529 (byte *)cfg.options + member.offset + member._class.offset);
4534 if(cfg != firstConfig)
4536 if(type.type == noHeadClass || type.type == normalClass)
4538 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4539 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4543 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4544 (byte *)cfg.options + member.offset + member._class.offset);
4546 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4549 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4556 // Compare Platform Specific Settings
4559 for(cfg : project.configurations)
4561 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4562 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4568 if(same && firstConfig.platforms)
4570 for(cfg : project.configurations)
4572 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4574 if(cfg != firstConfig)
4576 cfg.platforms = null;
4579 project.platforms = firstConfig.platforms;
4580 *&firstConfig.platforms = null;
4584 // Static libraries can't contain libraries
4585 for(cfg : project.configurations)
4587 if(cfg.options.targetType == staticLibrary)
4589 if(!cfg.options.libraries) cfg.options.libraries = { };
4590 cfg.options.libraries.Free();
4596 Project LoadProject(const char * filePath, const char * activeConfigName)
4598 Project project = null;
4599 File f = FileOpen(filePath, read);
4602 project = LegacyBinaryLoadProject(f, filePath);
4605 JSONParser parser { f = f };
4606 /*JSONResult result = */parser.GetObject(class(Project), &project);
4609 char insidePath[MAX_LOCATION];
4611 delete project.topNode.files;
4612 if(!project.files) project.files = { };
4613 project.topNode.files = project.files;
4616 char topNodePath[MAX_LOCATION];
4617 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4618 MakeSlashPath(topNodePath);
4619 PathCatSlash(topNodePath, filePath);
4620 project.filePath = topNodePath;//filePath;
4623 project.topNode.FixupNode(insidePath);
4625 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4626 delete project.resNode.path;
4627 project.resNode.path = project.resourcesPath;
4628 project.resourcesPath = null;
4629 project.resNode.nodeType = (ProjectNodeType)-1;
4630 delete project.resNode.files;
4631 project.resNode.files = project.resources;
4632 project.files = null;
4633 project.resources = null;
4634 if(!project.configurations) project.configurations = { };
4636 project.resNode.FixupNode(insidePath);
4641 project = LegacyAsciiLoadProject(f, filePath);
4647 if(!project.options) project.options = { };
4648 if(activeConfigName && activeConfigName[0] && project.configurations)
4649 project.config = project.GetConfig(activeConfigName);
4650 if(!project.config && project.configurations)
4651 project.config = project.configurations.firstIterator.data;
4653 if(!project.resNode)
4655 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4658 if(!project.moduleName)
4659 project.moduleName = CopyString(project.name);
4660 if(project.config &&
4661 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4662 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4664 //delete project.config.options.targetFileName;
4666 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4667 project.config.options.optimization = none;
4668 project.config.options.debug = true;
4669 //project.config.options.warnings = unset;
4670 project.config.options.memoryGuard = false;
4671 project.config.compilingModified = true;
4672 project.config.linkingModified = true;
4674 else if(!project.topNode.name && project.config)
4676 project.topNode.name = CopyString(project.config.options.targetFileName);
4679 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4680 project.topNode.configurations = project.configurations;
4681 project.topNode.platforms = project.platforms;
4682 project.topNode.options = project.options;*/
4688 #ifndef MAKEFILE_GENERATOR
4689 static GccVersionInfo GetGccVersionInfo(CompilerConfig compiler, const String compilerCommand)
4691 GccVersionInfo result = unknown;
4692 if(compiler.ccCommand)
4694 char command[MAX_F_STRING*4];
4696 sprintf(command, "%s%s --version", compiler.gccPrefix ? compiler.gccPrefix : "", compilerCommand);
4697 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
4699 bool firstLine = true;
4704 if(f.GetLine(line,sizeof(line)))
4708 uint count = Tokenize(line, sizeof(tokens)/sizeof(tokens[0]), tokens,false);
4709 char * token = null;
4712 for(i = 0; i < count; i++)
4714 if(tokens[i][0] == '(')
4716 if(tokens[i][strlen(tokens[i])-1] != ')')
4719 else if(tokens[i][0] && tokens[i][strlen(tokens[i])-1] == ')')
4721 else if(!inPar && isdigit(tokens[i][0]) && strchr(tokens[i], '.'))
4725 result = GccVersionInfo::GetVersionInfo(token);
4736 static enum GccVersionInfo
4738 unknown, pre4_8, post4_8;
4740 GccVersionInfo ::GetVersionInfo(char * version)
4742 GccVersionInfo result = unknown;
4744 char * s = CopyString(version);
4746 uint count = TokenizeWith(s, sizeof(tokens)/sizeof(tokens[0]), tokens, ".", false);
4747 ver = count > 1 ? atoi(tokens[1]) : 0;
4748 ver += count ? atoi(tokens[0]) * 1000 : 0;