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.activeCompiler);
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.activeCompiler);
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 f = FileOpen(fileName, write);
1214 files = topNode.files;
1215 resources = resNode.files;
1216 resourcesPath = resNode.path;
1218 files.Remove(resNode);
1221 WriteJSONObject(f, class(Project), this, 0);
1227 resourcesPath = null;
1234 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1236 TargetTypes targetType = GetTargetType(config);
1237 const String targetFileName = GetTargetFileName(config);
1238 if(targetType == staticLibrary)
1240 PathCatSlash(string, "lib");
1241 strcat(string, targetFileName);
1243 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1245 PathCatSlash(string, "lib");
1246 strcat(string, targetFileName);
1249 PathCatSlash(string, targetFileName);
1254 if(compiler.targetPlatform == win32)
1255 strcat(string, ".exe");
1258 if(compiler.targetPlatform == win32)
1259 strcat(string, ".dll");
1260 else if(compiler.targetPlatform == apple)
1261 strcat(string, ".dylib");
1263 strcat(string, ".so");
1264 if(compiler.targetPlatform == tux && __runtimePlatform == tux && moduleVersion && moduleVersion[0])
1266 strcat(string, ".");
1267 strcat(string, moduleVersion);
1271 strcat(string, ".a");
1276 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1278 bool result = false;
1279 char temp[MAX_LOCATION];
1280 strcpy(cfDir, topNode.path);
1281 if(compilerConfigsDir && compilerConfigsDir[0])
1283 PathCatSlash(cfDir, compilerConfigsDir);
1288 strcpy(temp, cfDir);
1289 // Using a relative path makes it less likely to run into spaces issues
1290 // Even with escaped spaces, there still seems to be issues including a config file
1291 // in a path containing spaces
1293 MakePathRelative(temp, topNode.path, cfDir);
1296 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1300 strcpy(temp, cfDir);
1301 ReplaceSpaces(cfDir, temp);
1306 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1308 char temp[MAX_LOCATION];
1309 bool result = false;
1310 strcpy(cfDir, topNode.path);
1311 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1313 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1318 // Default to <ProjectDir>/.configs if unset
1319 PathCatSlash(cfDir, ".configs");
1324 strcpy(temp, cfDir);
1325 // Using a relative path makes it less likely to run into spaces issues
1326 // Even with escaped spaces, there still seems to be issues including a config file
1327 // in a path containing spaces
1328 if(IsPathInsideOf(cfDir, topNode.path))
1329 MakePathRelative(temp, topNode.path, cfDir);
1331 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1335 strcpy(temp, cfDir);
1336 ReplaceSpaces(cfDir, temp);
1341 void CatMakeFileName(char * string, ProjectConfig config)
1343 char projectName[MAX_LOCATION];
1344 strcpy(projectName, name);
1345 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1348 #ifndef MAKEFILE_GENERATOR
1349 ProjectNode GetObjectFileNode(const char * filePath, const char * objectFileExt)
1351 ProjectNode node = null;
1352 char ext[MAX_EXTENSION];
1353 GetExtension(filePath, ext);
1356 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
1359 char fileName[MAX_FILENAME];
1360 GetLastDirectory(filePath, fileName);
1363 DotMain dotMain = DotMain::FromFileName(fileName);
1364 node = FindNodeByObjectFileName(fileName, type, dotMain, null, objectFileExt);
1371 bool GetAbsoluteFromRelativePath(const char * relativePath, char * absolutePath, const char * objectFileExt)
1373 ProjectNode node = topNode.FindWithPath(relativePath, false);
1375 node = GetObjectFileNode(relativePath, objectFileExt);
1378 strcpy(absolutePath, node.project.topNode.path);
1379 PathCat(absolutePath, relativePath);
1380 MakeSlashPath(absolutePath);
1382 return node != null;
1385 void MarkChanges(ProjectNode node)
1387 for(cfg : topNode.configurations)
1389 ProjectConfig c = null;
1390 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1392 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1393 (!c.options || !cfg.options)))
1394 cfg.symbolGenModified = true;
1395 if(c && ((c.options && cfg.options &&
1396 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1397 || (!c.options || !cfg.options)))
1398 cfg.linkingModified = true;
1400 cfg.makingModified = true;
1404 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1406 Map<String, NameCollisionInfo> cfgNameCollision;
1407 MapIterator<const String, Map<String, NameCollisionInfo>> it { map = configsNameCollisions };
1408 if(it.Index("", false))
1410 cfgNameCollision = it.data;
1411 cfgNameCollision.Free();
1412 delete cfgNameCollision;
1415 for(cfg : configurations)
1419 cfg.makingModified = true;
1420 if(it.Index(cfg.name, false))
1422 cfgNameCollision = it.data;
1423 cfgNameCollision.Free();
1424 delete cfgNameCollision;
1429 cfg.compilingModified = true;
1431 cfg.linkingModified = true;
1433 cfg.symbolGenModified = true;
1435 if(compiling || linking)
1437 ide.projectView.modifiedDocument = true;
1438 ide.workspace.modified = true;
1442 void RotateActiveConfig(bool forward, bool syncAllProjects)
1444 if(configurations.first && configurations.last != configurations.first)
1446 Iterator<ProjectConfig> cfg { configurations };
1447 while(forward ? cfg.Next() : cfg.Prev())
1448 if(cfg.data == config)
1463 ide.workspace.SelectActiveConfig(cfg.data.name);
1466 property::config = cfg.data;
1467 ide.UpdateToolBarActiveConfigs(true);
1468 ide.workspace.modified = true;
1469 ide.projectView.Update(null);
1474 bool ProcessPipeOutputRaw(DualPipe f)
1477 while(!f.Eof() && !ide.projectView.stopBuild)
1480 double lastTime = GetTime();
1484 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1486 ide.outputView.buildBox.Logf("%s\n", line);
1488 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1490 //printf("Processing Input...\n");
1491 if(app.ProcessInput(true))
1493 app.UpdateDisplay();
1496 //printf("Waiting...\n");
1499 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1501 if(ide.projectView.stopBuild)
1503 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1506 return !ide.projectView.stopBuild;
1509 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, BuildType buildType, List<ProjectNode> onlyNodes,
1510 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1514 bool compiling = false, linking = false, precompiling = false;
1515 int compilingEC = 0;
1516 int numErrors = 0, numWarnings = 0;
1517 bool loggedALine = false;
1518 int lenMakeCommand = strlen(compiler.makeCommand);
1520 const char * t, * s, * s2;
1521 char moduleName[MAX_FILENAME];
1522 const char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1524 DynamicString test { };
1525 DynamicString ecp { };
1526 DynamicString ecc { };
1527 DynamicString ecs { };
1528 DynamicString ear { };
1529 DynamicString prefix { };
1530 DynamicString cpp { };
1531 DynamicString cc { };
1532 DynamicString cxx { };
1533 DynamicString strip { };
1534 DynamicString ar { };
1535 DynamicString windres { };
1538 if(bitDepth == 64 && compiler.targetPlatform == win32)
1539 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1540 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1541 gnuToolchainPrefix = "i686-w64-mingw32-";
1543 ecp.concatx(compiler.ecpCommand, " ");
1544 ecc.concatx(compiler.eccCommand, " ");
1545 ecs.concatx(compiler.ecsCommand, " ");
1546 ear.concatx(compiler.earCommand, " ");
1549 compiler.ccacheEnabled ? "ccache " : "",
1550 compiler.distccEnabled ? "distcc " : "",
1551 gnuToolchainPrefix);
1553 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1554 cc.concatx((String)prefix, compiler.ccCommand, " ");
1555 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1557 strip.concatx(gnuToolchainPrefix, "strip ");
1558 ar.concatx(gnuToolchainPrefix, "ar rcs");
1559 windres.concatx(gnuToolchainPrefix, "windres ");
1561 testLen = Max(testLen, ecp.size);
1562 testLen = Max(testLen, ecc.size);
1563 testLen = Max(testLen, ecs.size);
1564 testLen = Max(testLen, ear.size);
1565 testLen = Max(testLen, cpp.size);
1566 testLen = Max(testLen, cc.size);
1567 testLen = Max(testLen, cxx.size);
1568 testLen = Max(testLen, strip.size);
1569 testLen = Max(testLen, ar.size);
1570 testLen = Max(testLen, windres.size);
1571 testLen = Max(testLen, strlen("mkdir "));
1574 while(!f.Eof() && !ide.projectView.stopBuild)
1576 double lastTime = GetTime();
1578 while(!f.Eof() && !ide.projectView.stopBuild)
1581 bool lineDone = f.GetLinePeek(line + linePos, sizeof(line)-linePos-1, &nChars);
1585 Sleep(0.5 / PEEK_RESOLUTION);
1592 const char * message = null;
1593 const char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1594 const char * from = strstr(line, stringFrom);
1595 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1596 if((t = strstr(line, (s=": recipe for target"))) && (t = strstr(t+strlen(s), (s2 = " failed"))) && (t+strlen(s2))[0] == '\0')
1597 ; // ignore this new gnu make error but what is it about?
1598 else if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1600 const char * moduleBackTick = strstr(line, "No rule to make target `");
1601 const char * module = moduleBackTick ? moduleBackTick : strstr(line, "No rule to make target '");
1605 module = strchr(module, moduleBackTick ? '`' : '\'') + 1;
1606 end = strchr(module, '\'');
1610 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1611 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1617 //ide.outputView.buildBox.Logf("error: %s\n", line);
1621 else if(strstr(test, "mkdir ") == test);
1622 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1623 else if(strstr(test, ear) == test);
1624 else if(strstr(test, strip) == test);
1625 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1627 char * module = null;
1628 bool isPrecomp = false;
1631 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1633 module = strstr(line, " -c ");
1634 if(module) module += 4;
1637 else if(strstr(test, ecc) == test)
1639 module = strstr(line, " -c ");
1640 if(module) module += 4;
1641 //module = line + 3;
1642 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1643 compilingEC = 3;//2;
1646 else if(strstr(test, ecp) == test)
1648 // module = line + 8;
1649 module = strstr(line, " -c ");
1650 if(module) module += 4;
1661 if(!compiling && !isPrecomp)
1663 ide.outputView.buildBox.Logf($"Compiling...\n");
1666 else if(!precompiling && isPrecomp)
1668 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1669 precompiling = true;
1671 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1672 GetLastDirectory(tokens[0], moduleName);
1673 ide.outputView.buildBox.Logf("%s\n", moduleName);
1675 else if((module = strstr(line, " -o ")))
1678 precompiling = false;
1680 ide.outputView.buildBox.Logf($"Linking...\n");
1684 ide.outputView.buildBox.Logf("%s\n", line);
1685 if(strstr(line, "warning:") || strstr(line, "note:"))
1687 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1691 if(compilingEC) compilingEC--;
1693 else if(strstr(test, windres) == test)
1696 module = strstr(line, " ");
1701 while(*module == ' ') module++;
1702 dashF = strstr(module, "-F ");
1706 while(*dashF && *dashF != ' ') dashF++;
1707 while(*dashF == ' ') dashF++;
1710 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1711 GetLastDirectory(module, moduleName);
1712 ide.outputView.buildBox.Logf("%s\n", moduleName);
1715 else if(strstr(test, ar) == test)
1716 ide.outputView.buildBox.Logf($"Building library...\n");
1717 else if(strstr(test, ecs) == test)
1718 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1721 if(linking || compiling || precompiling)
1723 const char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1724 const char * colon = strstr(start, ":"); //, * bracket;
1725 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1726 colon = strstr(colon + 1, ":");
1729 const char * sayError = "";
1730 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1733 int len = (int)(colon - start);
1734 char ext[MAX_EXTENSION];
1735 len = Min(len, MAX_LOCATION-1);
1736 // Don't be mistaken by the drive letter colon
1738 // TODO: need to fix colon - line gives char *
1739 // warning: incompatible expression colon - line (char *); expected int
1741 strncpy(moduleName, line, (int)(colon - line));
1742 moduleName[colon - line] = '\0';
1744 strncpy(moduleName, start, len);
1745 moduleName[len] = '\0';
1746 // Remove stuff in brackets
1747 //bracket = strstr(moduleName, "(");
1748 //if(bracket) *bracket = '\0';
1750 GetLastDirectory(moduleName, temp);
1751 GetExtension(temp, ext);
1753 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1755 char * cColon = strstr(colon+1, ":");
1756 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1757 cColon = strstr(cColon + 1, ":");
1760 int len = (int)(cColon - (colon+1));
1761 char mName[MAX_LOCATION];
1762 len = Min(len, MAX_LOCATION-1);
1763 strncpy(mName, colon+1, len);
1765 GetLastDirectory(mName, temp);
1766 GetExtension(temp, ext);
1767 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1770 strcpy(moduleName, mName);
1774 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1777 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1779 message = $"Linker Message: ";
1782 else if(SearchString(colon, 0, "warning:", false, false))
1784 message = $"Linker Warning: ";
1790 message = $"Linker Error: ";
1793 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1797 if(strstr(colon, "Warning:") == colon)
1799 message = $"Linker ";
1802 else if(strstr(line, "error:"))
1804 message = $"Linker Error: ";
1810 strcpy(temp, topNode.path);
1811 PathCatSlash(temp, moduleName);
1812 MakePathRelative(temp, topNode.path, moduleName);
1814 error = strstr(line, "error:");
1815 if(!message && error && error > colon)
1819 // Silence warnings for compiled eC
1820 //char * objDir = strstr(moduleName, objDirExp.dir);
1824 if((pointer = strstr(line, "undefined")) ||
1825 (pointer = strstr(line, "multiple definition")) ||
1826 (pointer = strstr(line, "No such file")) ||
1827 (pointer = strstr(line, "token")))
1829 strncat(moduleName, colon, pointer - colon);
1830 sayError = "error: ";
1835 else if((pointer = strstr(line, "No such file")))
1837 strncat(moduleName, colon, pointer - colon);
1838 sayError = "error: ";
1842 else //if(compilingEC == 1 || (objDir && objDir == moduleName))
1846 // Filter out these warnings caused by eC generated C code:
1848 // Declaration ordering bugs -- Awaiting topo sort implementation
1850 if(strstr(line, "declared inside parameter list")) skip = true;
1851 else if(strstr(line, "its scope is only this definition")) skip = true;
1852 else if(strstr(line, "from incompatible pointer type")) skip = true;
1853 else if(strstr(line, "note: expected 'struct ") || strstr(line, "note: expected ‘struct "))
1855 #define STRUCT_A "'struct "
1856 #define STRUCT_B "‘struct "
1857 char * struct1, * struct2, ch1, ch2;
1858 struct1 = strstr(line, STRUCT_A);
1859 if(struct1) { struct1 += sizeof(STRUCT_A)-1; } else { struct1 = strstr(line, STRUCT_B); struct1 += sizeof(STRUCT_B)-1; };
1861 struct2 = strstr(struct1, STRUCT_A);
1862 if(struct2) { struct2 += sizeof(STRUCT_A)-1; } else { struct2 = strstr(struct1, STRUCT_B); if(struct2) struct2 += sizeof(STRUCT_B)-1; };
1864 if(struct1 && struct2)
1866 while(ch1 = *(struct1++), ch2 = *(struct2++), ch1 && ch2 && (ch1 == '_' || isalnum(ch1)) && (ch2 == '_' || isalnum(ch2)));
1872 // For preprocessed code from objidl.h (MinGW-w64 headers)
1873 else if(strstr(line, "declaration does not declare anything")) skip = true;
1875 // Location information that could apply to ignored warnings
1876 else if(strstr(line, "In function '") || strstr(line, "In function ‘") ) skip = true;
1877 else if(strstr(line, "At top level")) skip = true;
1878 else if(strstr(line, "(near initialization for '") || strstr(line, "(near initialization for ‘")) skip = true;
1883 /*else if(strstr(line, "warning:"))
1889 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1890 /*else if(this == ide.workspace.projects.firstIterator.data)
1891 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1894 char fullModuleName[MAX_LOCATION];
1895 FileAttribs found = 0;
1896 //Project foundProject = this;
1899 char * loc = strstr(moduleName, ":");
1901 strcpy(fullModuleName, topNode.path);
1902 PathCat(fullModuleName, moduleName);
1903 found = FileExists(fullModuleName);
1904 if(!found && !strcmp(ext, "c"))
1906 char ecName[MAX_LOCATION];
1907 ChangeExtension(fullModuleName, "ec", ecName);
1908 found = FileExists(ecName);
1912 char path[MAX_LOCATION];
1913 if(ide && ide.workspace)
1915 for(prj : ide.workspace.projects)
1918 MakePathRelative(fullModuleName, prj.topNode.path, path);
1920 if((node = prj.topNode.FindWithPath(path, false)))
1922 strcpy(fullModuleName, prj.topNode.path);
1923 PathCatSlash(fullModuleName, node.path);
1924 PathCatSlash(fullModuleName, node.name);
1925 found = FileExists(fullModuleName);
1928 //foundProject = prj;
1933 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1935 for(prj : ide.workspace.projects)
1938 if((node = prj.topNode.Find(moduleName, false)))
1940 strcpy(fullModuleName, prj.topNode.path);
1941 PathCatSlash(fullModuleName, node.path);
1942 PathCatSlash(fullModuleName, node.name);
1943 found = FileExists(fullModuleName);
1946 //foundProject = prj;
1956 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1957 MakeSystemPath(fullModuleName);
1960 strcpy(fullModuleName, moduleName);
1963 strcat(fullModuleName, ":");
1964 strcat(fullModuleName, loc + 1);
1968 fullModuleName[0] = 0;
1969 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1974 ide.outputView.buildBox.Logf("%s\n", line);
1975 linking = compiling = precompiling = false;
1979 ide.outputView.buildBox.Logf("%s\n", line);
1984 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1986 //printf("Processing Input...\n");
1987 if(app.ProcessInput(true))
1989 app.UpdateDisplay();
1992 //printf("Waiting...\n");
1995 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1997 if(ide.projectView.stopBuild)
1999 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
2002 else if(loggedALine || buildType != run)
2004 if(f.GetExitCode() && !numErrors)
2006 /*bool result = */f.GetLine(line, sizeof(line)-1);
2007 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
2009 else if(buildType != install)
2013 char targetFileName[MAX_LOCATION];
2014 targetFileName[0] = '\0';
2015 CatTargetFileName(targetFileName, compiler, config);
2016 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
2019 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
2021 ide.outputView.buildBox.Logf($"no error, ");
2024 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
2026 ide.outputView.buildBox.Logf($"no warning\n");
2043 return numErrors == 0 && !ide.projectView.stopBuild;
2046 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
2049 int lenMakeCommand = strlen(compiler.makeCommand);
2054 double lastTime = GetTime();
2057 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2059 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
2060 else if(strstr(line, "mkdir") == line);
2061 else if(strstr(line, "del") == line);
2062 else if(strstr(line, "rm") == line);
2063 else if(strstr(line, "Could Not Find") == line);
2066 ide.outputView.buildBox.Logf(line);
2067 ide.outputView.buildBox.Logf("\n");
2071 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
2073 if(app.ProcessInput(true))
2075 app.UpdateDisplay();
2078 //Sleep(1.0 / PEEK_RESOLUTION);
2082 bool Build(BuildType buildType, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, bool raw, SingleFileCompileMode mode)
2084 bool result = false;
2086 char targetFileName[MAX_LOCATION] = "";
2087 DynamicString makeTargets { };
2088 char makeFile[MAX_LOCATION];
2089 char makeFilePath[MAX_LOCATION];
2090 char configName[MAX_LOCATION];
2091 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
2092 PathBackup pathBackup { };
2093 bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
2094 const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2096 bool eC_Debug = mode.eC_ToolsDebug;
2097 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2098 int numJobs = compiler.numJobs;
2099 char command[MAX_F_STRING*4];
2100 char * compilerName = CopyString(compiler.name);
2101 Map<String, NameCollisionInfo> cfgNameCollisions;
2102 const char * objFileExt = strcmp(compiler.objectFileExt, objectDefaultFileExt) != 0 ? compiler.objectFileExt : null;
2104 delete lastBuildConfigName;
2105 lastBuildConfigName = CopyString(config ? config.name : "Common");
2106 delete lastBuildCompilerName;
2107 lastBuildCompilerName = CopyString(compiler.name);
2108 ProjectLoadLastBuildNamesInfo(this, config);
2109 cfgNameCollisions = configsNameCollisions[config ? config.name : ""];
2111 CamelCase(compilerName);
2113 strcpy(configName, config ? config.name : "Common");
2115 SetPath(false, compiler, config, bitDepth); //true
2116 CatTargetFileName(targetFileName, compiler, config);
2118 strcpy(makeFilePath, topNode.path);
2119 CatMakeFileName(makeFile, config);
2120 PathCatSlash(makeFilePath, makeFile);
2122 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2123 if(buildType == install)
2124 makeTargets.concat(" install");
2127 if(compiler.type.isVC)
2129 PrintLn("compiling a single file is not yet supported");
2133 char pushD[MAX_LOCATION];
2134 char cfDir[MAX_LOCATION];
2135 GetIDECompilerConfigsDir(cfDir, true, true);
2136 GetWorkingDir(pushD, sizeof(pushD));
2137 ChangeWorkingDir(topNode.path);
2138 // Create object dir if it does not exist already
2139 if(!FileExists(objDirExp.dir).isDirectory)
2141 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s%s%s objdir -C \"%s\"%s -f \"%s\"",
2142 compiler.makeCommand, cfDir,
2143 crossCompiling ? " TARGET_PLATFORM=" : "",
2145 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2146 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2148 objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
2149 topNode.path, justPrint ? " -n" : "", makeFilePath);
2150 if(justPrint || raw)
2151 ide.outputView.buildBox.Logf("%s\n", command);
2155 ChangeWorkingDir(pushD);
2157 for(node : onlyNodes)
2159 if(node.GetIsExcludedForCompiler(config, compiler))
2160 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2164 node.DeleteIntermediateFiles(compiler, config, bitDepth, cfgNameCollisions, mode == cObject ? true : false);
2165 node.GetTargets(config, cfgNameCollisions, objDirExp.dir, compiler.objectFileExt, makeTargets);
2171 if(compiler.type.isVC)
2173 //bool result = false;
2174 char oldwd[MAX_LOCATION];
2175 GetWorkingDir(oldwd, sizeof(oldwd));
2176 ChangeWorkingDir(topNode.path);
2178 // TODO: support justPrint
2179 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2180 if(justPrint || raw)
2181 ide.outputView.buildBox.Logf("%s\n", command);
2182 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
2184 ProcessPipeOutputRaw(f);
2188 ChangeWorkingDir(oldwd);
2190 else if(onlyNodes && strlen(makeTargets) == 0)
2192 ide.outputView.buildBox.Log("No targets to compile.\n");
2196 GccVersionInfo ccVersion = GetGccVersionInfo(compiler, compiler.ccCommand);
2197 GccVersionInfo cxxVersion = GetGccVersionInfo(compiler, compiler.cxxCommand);
2198 char cfDir[MAX_LOCATION];
2199 GetIDECompilerConfigsDir(cfDir, true, true);
2200 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\"",
2201 #if defined(__WIN32__)
2204 buildType == install ? "pkexec --user root " : "",
2206 compiler.makeCommand,
2207 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2209 crossCompiling ? " TARGET_PLATFORM=" : "",
2211 bitDepth ? " ARCH=" : "",
2212 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2213 ide.workspace.useValgrind ? " DISABLED_POOLING=1" : "",
2214 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2216 objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
2217 eC_Debug ? "--always-make " : "",
2218 ccVersion == post4_8 ? "GCC_CC_FLAGS=-fno-diagnostics-show-caret " : "",
2219 cxxVersion == post4_8 ? "GCC_CXX_FLAGS=-fno-diagnostics-show-caret " : "",
2221 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2222 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2223 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2224 if(justPrint || raw)
2225 ide.outputView.buildBox.Logf("%s\n", command);
2227 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2235 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2241 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2244 ide.outputView.buildBox.Logf("%s\n", line);
2245 if(!error && !found && strstr(line, "echo ") == line && strstr(line, "ECERE_SDK_SRC"))
2247 strcpy(command, line+5);
2250 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2252 strcpy(command, line);
2261 else if(justPrint || raw)
2262 result = ProcessPipeOutputRaw(f);
2264 result = ProcessBuildPipeOutput(f, objDirExp, buildType, onlyNodes, compiler, config, bitDepth);
2267 ide.outputView.buildBox.Logf("%s\n", command);
2268 else if(justPrint && found)
2269 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2274 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2279 delete compilerName;
2284 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint, bool raw)
2286 char makeFile[MAX_LOCATION];
2287 char makeFilePath[MAX_LOCATION];
2288 char command[MAX_LOCATION];
2289 char * compilerName;
2291 PathBackup pathBackup { };
2292 bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
2293 const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2294 const char * objFileExt = strcmp(compiler.objectFileExt, objectDefaultFileExt) ? compiler.objectFileExt : null;
2296 compilerName = CopyString(compiler.name);
2297 CamelCase(compilerName);
2299 SetPath(false, compiler, config, bitDepth);
2301 strcpy(makeFilePath, topNode.path);
2302 CatMakeFileName(makeFile, config);
2303 PathCatSlash(makeFilePath, makeFile);
2305 if(compiler.type.isVC)
2307 //bool result = false;
2308 char oldwd[MAX_LOCATION];
2309 GetWorkingDir(oldwd, sizeof(oldwd));
2310 ChangeWorkingDir(topNode.path);
2312 // TODO: justPrint support
2313 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2314 if(justPrint || raw)
2315 ide.outputView.buildBox.Logf("%s\n", command);
2316 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2318 ProcessPipeOutputRaw(f);
2322 ChangeWorkingDir(oldwd);
2327 char cfDir[MAX_LOCATION];
2328 GetIDECompilerConfigsDir(cfDir, true, true);
2329 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s%s%s %sclean%s -C \"%s\"%s -f \"%s\"",
2330 compiler.makeCommand, cfDir,
2331 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2332 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2334 objFileExt ? " O=." : "", objFileExt ? objFileExt : "",
2335 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2336 topNode.path, justPrint ? " -n": "", makeFilePath);
2337 if(justPrint || raw)
2338 ide.outputView.buildBox.Logf("%s\n", command);
2339 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2341 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2342 cleanType == realClean ? $"intermediate objects directory" : $"target",
2343 cleanType == clean ? $" and object files" : "");
2344 if(justPrint || raw)
2345 ProcessPipeOutputRaw(f);
2347 ProcessCleanPipeOutput(f, compiler, config);
2348 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2349 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2350 cleanType == clean ? $" and object files" : "");
2356 delete compilerName;
2359 void Run(const char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2361 String target = new char[maxPathLen];
2362 char oldDirectory[MAX_LOCATION];
2363 char * executableLauncher = compiler.executableLauncher;
2364 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2365 PathBackup pathBackup { };
2367 // Build(project, ideMain, true, null, false);
2369 strcpy(target, topNode.path);
2370 PathCatSlash(target, targetDirExp.dir);
2371 CatTargetFileName(target, compiler, config);
2372 sprintf(target, "%s %s", target, args);
2373 GetWorkingDir(oldDirectory, MAX_LOCATION);
2375 if(ide.workspace.debugDir && strlen(ide.workspace.debugDir))
2377 char temp[MAX_LOCATION];
2378 strcpy(temp, topNode.path);
2379 PathCatSlash(temp, ide.workspace.debugDir);
2380 ChangeWorkingDir(temp);
2383 ChangeWorkingDir(topNode.path);
2384 SetPath(true, compiler, config, bitDepth);
2385 if(executableLauncher)
2387 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 8];
2388 prefixedTarget[0] = '\0';
2389 strcat(prefixedTarget, executableLauncher);
2390 strcat(prefixedTarget, " ");
2391 strcat(prefixedTarget, target);
2392 Execute(prefixedTarget);
2393 delete prefixedTarget;
2398 ChangeWorkingDir(oldDirectory);
2401 delete targetDirExp;
2405 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, bool raw, SingleFileCompileMode mode)
2407 return Build(build, nodes, compiler, config, bitDepth, justPrint, raw, mode);
2411 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2414 if(targetType == staticLibrary || targetType == sharedLibrary)
2415 strcat(fileName, "$(LP)");
2416 strcat(fileName, GetTargetFileName(config));
2417 strcat(fileName, "$(OUT)");
2420 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2422 bool result = false;
2423 char path[MAX_LOCATION];
2425 if(!GetProjectCompilerConfigsDir(path, false, false))
2426 GetIDECompilerConfigsDir(path, false, false);
2428 if(!FileExists(path).isDirectory)
2432 char dirName[MAX_FILENAME];
2433 GetLastDirectory(path, dirName);
2434 if(!strcmp(dirName, ".configs"))
2435 FileSetAttribs(path, FileAttribs { isHidden = true });
2438 PathCatSlash(path, "crossplatform.mk");
2440 if(FileExists(path))
2443 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2446 File f = FileOpen(path, write);
2449 include.Seek(0, start);
2450 for(; !include.Eof(); )
2453 int count = include.Read(buffer, 1, 4096);
2454 f.Write(buffer, 1, count);
2460 if(!altCrossPlatformMk)
2467 bool GenerateCompilerCf(CompilerConfig compiler, bool eC)
2469 bool result = false;
2470 char path[MAX_LOCATION];
2472 char * compilerName;
2473 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2474 const char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2475 Platform platform = compiler.targetPlatform;
2477 compilerName = CopyString(compiler.name);
2478 CamelCase(compilerName);
2479 name = PrintString(platform, "-", compilerName, ".cf");
2481 if(!GetProjectCompilerConfigsDir(path, false, false))
2482 GetIDECompilerConfigsDir(path, false, false);
2484 if(!FileExists(path).isDirectory)
2488 char dirName[MAX_FILENAME];
2489 GetLastDirectory(path, dirName);
2490 if(!strcmp(dirName, ".configs"))
2491 FileSetAttribs(path, FileAttribs { isHidden = true });
2494 PathCatSlash(path, name);
2496 if(FileExists(path))
2499 File f = FileOpen(path, write);
2502 if(compiler.environmentVars && compiler.environmentVars.count)
2504 f.Puts("# ENVIRONMENT VARIABLES\n");
2506 for(e : compiler.environmentVars)
2508 ChangeCh(e.string, '\\', '/');
2509 f.Printf("export %s := %s\n", e.name, e.string);
2510 ChangeCh(e.string, '/', '\\');
2515 f.Puts("# TOOLCHAIN\n");
2518 f.Puts("# EXTENSIONS\n");
2519 if(compiler.outputFileExt)
2520 f.Printf("OUT := %s\n", compiler.outputFileExt);
2522 f.Puts("OUT := $(if $(STATIC_LIBRARY_TARGET),$(A),$(if $(SHARED_LIBRARY_TARGET),$(SO)$(VER),$(if $(EXECUTABLE_TARGET),$(E),.x)))\n");
2524 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2526 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2529 if(compiler.sysroot && compiler.sysroot[0])
2531 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2532 // Moved this to crossplatform.mk
2533 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2537 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2538 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2539 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)\n", compiler.ccCommand);
2540 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CXX_FLAGS),$(space)$(GCC_CXX_FLAGS),)\n", compiler.cxxCommand);
2543 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);
2544 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);
2545 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);
2549 f.Printf("ECP := %s\n", compiler.ecpCommand);
2550 f.Printf("ECC := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2551 f.Printf("ECS := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)$(if $(DISABLED_POOLING), -disabled-pooling,)\n", compiler.ecsCommand);
2553 f.Printf("EAR := %s\n", compiler.earCommand);
2555 f.Puts("AS := $(GCC_PREFIX)as\n");
2556 f.Printf("LD := $(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_LD_FLAGS),$(space)$(GCC_LD_FLAGS),)\n", compiler.ldCommand);
2557 f.Printf("AR := $(GCC_PREFIX)%s\n", compiler.arCommand);
2558 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2559 f.Puts("ifdef WINDOWS_TARGET\n");
2560 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2561 f.Puts(" ifdef ARCH\n");
2562 f.Puts(" ifeq ($(ARCH),x32)\n");
2563 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2565 f.Puts(" ifeq ($(ARCH),x64)\n");
2566 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2571 f.Puts("UPX := upx\n");
2574 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2577 f.Puts("EARFLAGS = \n");
2580 f.Puts("ifndef ARCH\n");
2581 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2582 f.Puts(" ifdef WINDOWS_HOST\n");
2583 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2584 f.Puts(" TARGET_ARCH := x86_64\n");
2586 f.Puts(" TARGET_ARCH := i386\n");
2589 f.Puts("endif\n\n");
2591 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2592 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2596 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2600 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2603 if(compiler.includeDirs && compiler.includeDirs.count)
2605 f.Puts("\nCFLAGS +=");
2606 OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
2609 if(compiler.prepDirectives && compiler.prepDirectives.count)
2611 f.Puts("\nCFLAGS +=");
2612 OutputFlags(f, _D, compiler.prepDirectives, inPlace);
2615 if(compiler.libraryDirs && compiler.libraryDirs.count)
2617 f.Puts("\nLDFLAGS +=");
2618 OutputFlags(f, _L, compiler.libraryDirs, lineEach);
2619 // We would need a bool option to know whether we want to add to rpath as well...
2620 // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
2623 if(compiler.excludeLibs && compiler.excludeLibs.count)
2625 f.Puts("\nEXCLUDED_LIBS =");
2626 for(l : compiler.excludeLibs)
2632 if(compiler.eCcompilerFlags && compiler.eCcompilerFlags.count)
2634 f.Puts("\nECFLAGS +=");
2635 OutputFlags(f, any, compiler.eCcompilerFlags, inPlace);
2638 if(compiler.compilerFlags && compiler.compilerFlags.count)
2640 f.Puts("\nCFLAGS +=");
2641 OutputFlags(f, any, compiler.compilerFlags, inPlace);
2644 if(compiler.linkerFlags && compiler.linkerFlags.count)
2646 f.Puts("\nLDFLAGS +=");
2647 OutputFlags(f, _Wl, compiler.linkerFlags, inPlace);
2651 f.Puts("\nOFLAGS += $(LDFLAGS)");
2653 f.Puts("ifdef ARCH_FLAGS\n");
2654 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2655 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2664 delete compilerName;
2668 bool GenerateMakefile(const char * altMakefilePath, bool noResources, const char * includemkPath, ProjectConfig config, const char * ldCommand)
2670 bool result = false;
2671 char filePath[MAX_LOCATION];
2672 char makeFile[MAX_LOCATION];
2673 // PathBackup pathBackup { };
2674 // char oldDirectory[MAX_LOCATION];
2677 if(!altMakefilePath)
2679 strcpy(filePath, topNode.path);
2680 CatMakeFileName(makeFile, config);
2681 PathCatSlash(filePath, makeFile);
2684 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2686 /*SetPath(false, compiler, config);
2687 GetWorkingDir(oldDirectory, MAX_LOCATION);
2688 ChangeWorkingDir(topNode.path);*/
2695 char targetDir[MAX_LOCATION];
2696 char objDirExpNoSpaces[MAX_LOCATION];
2697 char objDirNoSpaces[MAX_LOCATION];
2698 char resDirNoSpaces[MAX_LOCATION];
2699 char targetDirExpNoSpaces[MAX_LOCATION];
2700 char fixedModuleName[MAX_FILENAME];
2701 char fixedConfigName[MAX_FILENAME];
2703 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2704 // Non-zero if we're building eC code
2705 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2706 int numCObjects = 0;
2708 int numRCObjects = 0;
2709 bool containsCXX = false; // True if the project contains a C++ file
2710 bool relObjDir, sameOrRelObjTargetDirs;
2711 const String objDirExp = GetObjDirExpression(config);
2712 TargetTypes targetType = GetTargetType(config);
2714 char cfDir[MAX_LOCATION];
2715 int objectsParts = 0;
2716 int eCsourcesParts = 0;
2717 int rcSourcesParts = 0;
2718 Array<String> listItems { };
2719 Map<String, int> varStringLenDiffs { };
2720 Map<String, NameCollisionInfo> namesInfo { };
2722 Map<String, int> cflagsVariations { };
2723 Map<intptr, int> nodeCFlagsMapping { };
2725 Map<String, int> ecflagsVariations { };
2726 Map<intptr, int> nodeECFlagsMapping { };
2728 ReplaceSpaces(objDirNoSpaces, objDirExp);
2729 strcpy(targetDir, GetTargetDirExpression(config));
2730 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2732 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2733 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2735 char temp[MAX_LOCATION];
2736 ReplaceSpaces(temp, objDirExpNoSpaces);
2737 strcpy(objDirExpNoSpaces, temp);
2739 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2740 ReplaceSpaces(fixedModuleName, moduleName);
2741 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2742 CamelCase(fixedConfigName);
2744 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2745 relObjDir = lenObjDirExpNoSpaces == 0 ||
2746 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2747 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2748 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2749 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2750 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2752 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2754 f.Puts("# CORE VARIABLES\n\n");
2756 f.Printf("MODULE := %s\n", fixedModuleName);
2757 f.Printf("VERSION := %s\n", property::moduleVersion);
2758 f.Printf("CONFIG := %s\n", fixedConfigName);
2759 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2762 test = GetTargetTypeIsSetByPlatform(config);
2766 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2768 TargetTypes targetType;
2769 PlatformOptions projectPOs, configPOs;
2770 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2771 targetType = platformTargetType;
2777 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2778 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2783 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2788 for(c = 0; c < ifCount; c++)
2794 f.Puts("# FLAGS\n\n");
2796 f.Puts("ECFLAGS =\n");
2797 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2798 f.Puts("PRJ_CFLAGS =\n");
2799 f.Puts("CECFLAGS =\n");
2800 f.Puts("OFLAGS =\n");
2804 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2807 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2808 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2809 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2810 //f.Puts("endif\n");
2813 f.Puts("# INCLUDES\n\n");
2815 if(compilerConfigsDir && compilerConfigsDir[0])
2817 strcpy(cfDir, compilerConfigsDir);
2818 if(cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2823 GetIDECompilerConfigsDir(cfDir, true, true);
2824 // Use CF_DIR environment variable for absolute paths only
2825 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2826 strcpy(cfDir, "$(CF_DIR)");
2829 f.Printf("_CF_DIR = %s\n", cfDir);
2832 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2833 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2836 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2838 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2841 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2844 // test = GetTargetTypeIsSetByPlatform(config);
2846 char target[MAX_LOCATION];
2847 char temp[MAX_LOCATION];
2852 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2854 if(type != targetType)
2859 f.Printf("ifeq ($(TARGET_TYPE),%s)\n", TargetTypeToMakefileVariable(type));
2861 GetMakefileTargetFileName(type, target, config);
2862 strcpy(temp, targetDir);
2863 PathCatSlash(temp, target);
2864 ReplaceSpaces(target, temp);
2865 f.Printf("TARGET = %s\n", target);
2870 GetMakefileTargetFileName(targetType, target, config);
2871 strcpy(temp, targetDir);
2872 PathCatSlash(temp, target);
2873 ReplaceSpaces(target, temp);
2874 f.Printf("TARGET = %s\n", target);
2880 for(c = 0; c < ifCount; c++)
2887 // Use something fixed here, to not cause Makefile differences across compilers...
2888 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2889 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2891 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2895 const char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2897 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2900 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2902 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2903 if(eCsourcesParts > 1)
2905 for(c = 1; c <= eCsourcesParts; c++)
2906 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2910 for(c = 0; c < 5; c++)
2912 if(eCsourcesParts > 1)
2915 f.Printf("_%s =", map[c][0]);
2916 for(n = 1; n <= eCsourcesParts; n++)
2917 f.Printf(" $(%s%d)", map[c][0], n);
2919 for(n = 1; n <= eCsourcesParts; n++)
2920 f.Printf("_%s%d = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d))))\n", map[c][0], n, map[c][1], n);
2922 else if(eCsourcesParts == 1)
2923 f.Printf("_%s = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES))))\n", map[c][0], map[c][1]);
2927 for(c = 0; c < 5; c++)
2929 if(eCsourcesParts > 1)
2932 f.Printf("%s =", map[c][0]);
2933 for(n = 1; n <= eCsourcesParts; n++)
2934 f.Printf(" $(%s%d)", map[c][0], n);
2936 for(n = 1; n <= eCsourcesParts; n++)
2937 f.Printf("%s%d = $(call shwspace,$(_%s%d))\n", map[c][0], n, map[c][0], n);
2939 else if(eCsourcesParts == 1)
2940 f.Printf("%s = $(call shwspace,$(_%s))\n", map[c][0], map[c][0]);
2946 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2949 f.Puts("ifdef WINDOWS_TARGET\n\n");
2951 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2953 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2954 if(rcSourcesParts > 1)
2956 for(c = 1; c <= rcSourcesParts; c++)
2957 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2960 if(rcSourcesParts > 1)
2963 f.Printf("%s =", "RCOBJECTS");
2964 for(n = 1; n <= rcSourcesParts; n++)
2965 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2967 for(n = 1; n <= rcSourcesParts; n++)
2968 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2970 else if(rcSourcesParts == 1)
2971 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2975 f.Puts("RCSOURCES =\n");
2976 f.Puts("RCOBJECTS =\n");
2977 f.Puts("endif\n\n");
2980 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2982 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2983 f.Printf("OBJECTS =%s%s%s%s\n",
2984 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2985 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2986 numRCObjects ? " $(RCOBJECTS)" : "");
2989 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2991 const char * prefix;
2992 if(numCObjects && numRCObjects)
2993 prefix = "$(ECSOURCES) $(RCSOURCES)";
2994 else if(numCObjects)
2995 prefix = "$(ECSOURCES)";
2998 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
3002 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
3003 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
3005 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
3007 if((config && config.options && config.options.libraries) ||
3008 (options && options.libraries))
3010 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3012 if(config && config.options && config.options.libraries)
3013 OutputLibraries(f, config.options.libraries);
3014 else if(options && options.libraries)
3015 OutputLibraries(f, options.libraries);
3021 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects != 0,
3022 cflagsVariations, nodeCFlagsMapping,
3023 ecflagsVariations, nodeECFlagsMapping, null);
3025 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
3026 f.Puts("ECFLAGS += -module $(MODULE)\n");
3027 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
3029 if(platforms || (config && config.platforms))
3032 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
3033 //for(platform = win32; platform <= apple; platform++)
3035 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
3036 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3038 PlatformOptions projectPlatformOptions, configPlatformOptions;
3039 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
3041 if(projectPlatformOptions || configPlatformOptions)
3046 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3049 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
3050 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
3052 f.Puts("CFLAGS +=");
3053 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
3056 for(s : projectPlatformOptions.options.compilerOptions)
3059 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
3062 for(s : configPlatformOptions.options.compilerOptions)
3069 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
3070 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
3072 f.Puts("OFLAGS +=");
3073 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
3075 bool needWl = false;
3077 for(s : projectPlatformOptions.options.linkerOptions)
3079 if(!IsLinkerOption(s))
3087 for(s : projectPlatformOptions.options.linkerOptions)
3088 if(IsLinkerOption(s))
3092 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
3094 bool needWl = false;
3096 for(s : configPlatformOptions.options.linkerOptions)
3098 if(IsLinkerOption(s))
3106 for(s : configPlatformOptions.options.linkerOptions)
3107 if(!IsLinkerOption(s))
3115 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3116 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
3117 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
3118 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
3120 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3121 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3122 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
3124 f.Puts("OFLAGS +=");
3125 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
3126 OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
3127 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
3128 OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
3132 if(configPlatformOptions && configPlatformOptions.options.libraries)
3134 if(configPlatformOptions.options.libraries.count)
3137 OutputLibraries(f, configPlatformOptions.options.libraries);
3141 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3143 if(projectPlatformOptions.options.libraries.count)
3146 OutputLibraries(f, projectPlatformOptions.options.libraries);
3157 for(c = 0; c < ifCount; c++)
3163 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3164 (options && options.compilerOptions && options.compilerOptions.count))
3166 f.Puts("CFLAGS +=");
3169 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3171 for(s : config.options.compilerOptions)
3174 if(options && options.compilerOptions && options.compilerOptions.count)
3176 for(s : options.compilerOptions)
3183 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3184 (options && options.linkerOptions && options.linkerOptions.count))
3186 f.Puts("OFLAGS +=");
3189 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3191 bool needWl = false;
3192 for(s : config.options.linkerOptions)
3194 if(!IsLinkerOption(s))
3202 for(s : config.options.linkerOptions)
3203 if(IsLinkerOption(s))
3207 if(options && options.linkerOptions && options.linkerOptions.count)
3209 bool needWl = false;
3210 for(s : options.linkerOptions)
3212 if(!IsLinkerOption(s))
3220 for(s : options.linkerOptions)
3221 if(IsLinkerOption(s))
3229 f.Puts("CECFLAGS += -cpp $(_CPP)");
3233 if(GetProfile(config))
3234 f.Puts("OFLAGS += -pg\n\n");
3236 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3238 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3239 f.Puts("OFLAGS +=");
3240 if(config && config.options && config.options.libraryDirs)
3241 OutputFlags(f, _L, config.options.libraryDirs, lineEach);
3242 if(options && options.libraryDirs)
3243 OutputFlags(f, _L, options.libraryDirs, lineEach);
3249 f.Puts("# TARGETS\n");
3252 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3255 f.Puts("objdir:\n");
3257 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3260 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");
3261 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");
3263 //f.Puts("# PRE-BUILD COMMANDS\n");
3264 if(options && options.prebuildCommands)
3266 for(s : options.prebuildCommands)
3267 if(s && s[0]) f.Printf("\t%s\n", s);
3269 if(config && config.options && config.options.prebuildCommands)
3271 for(s : config.options.prebuildCommands)
3272 if(s && s[0]) f.Printf("\t%s\n", s);
3274 if(platforms || (config && config.platforms))
3277 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3278 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3280 PlatformOptions projectPOs, configPOs;
3281 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3283 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3284 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3289 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3291 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3293 for(s : projectPOs.options.prebuildCommands)
3294 if(s && s[0]) f.Printf("\t%s\n", s);
3296 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3298 for(s : configPOs.options.prebuildCommands)
3299 if(s && s[0]) f.Printf("\t%s\n", s);
3306 for(c = 0; c < ifCount; c++)
3312 if(!sameOrRelObjTargetDirs)
3314 f.Puts("targetdir:\n");
3315 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3321 // Main Module (Linking) for ECERE C modules
3322 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3323 f.Printf("\t@$(call rmq,$(OBJ)symbols.lst)\n");
3324 f.Printf("\t@$(call touch,$(OBJ)symbols.lst)\n");
3325 OutputFileListActions(f, "SYMBOLS", eCsourcesParts, "$(OBJ)symbols.lst");
3326 OutputFileListActions(f, "IMPORTS", eCsourcesParts, "$(OBJ)symbols.lst");
3327 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3328 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) @$(OBJ)symbols.lst -symbols %s -o $(call quote_path,$@)\n",
3329 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3331 // Main Module (Linking) for ECERE C modules
3332 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3333 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3334 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3335 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3336 " -c $(OBJ)$(MODULE).main.ec -o $(call quote_path,$@) -symbols $(OBJ)\n");
3342 // This would not rebuild the target on updated objects
3343 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3345 // This should fix it for good!
3346 f.Puts("$(SYMBOLS): | objdir\n");
3347 f.Puts("$(OBJECTS): | objdir\n");
3349 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3350 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3351 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3353 f.Printf("\t@$(call rmq,$(OBJ)objects.lst)\n");
3354 f.Printf("\t@$(call touch,$(OBJ)objects.lst)\n");
3355 OutputFileListActions(f, "_OBJECTS", objectsParts, "$(OBJ)objects.lst");
3358 f.Puts("ifdef WINDOWS_TARGET\n");
3359 OutputFileListActions(f, "RCOBJECTS", rcSourcesParts, "$(OBJ)objects.lst");
3364 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)objects.lst\n");
3365 OutputFileListActions(f, "ECOBJECTS", eCsourcesParts, "$(OBJ)objects.lst");
3368 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3370 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)objects.lst $(LIBS) -o $(TARGET) $(INSTALLNAME)\n", ldCommand && ldCommand[0] ? "LD" : containsCXX ? "CXX" : "CC");
3371 if(!GetDebug(config))
3373 f.Puts("ifndef NOSTRIP\n");
3374 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3377 if(GetCompress(config))
3379 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3380 f.Puts("ifdef EXECUTABLE_TARGET\n");
3381 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3384 //f.Puts("ifneq ($(TARGET_ARCH),x86_64)\n");
3385 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3386 //f.Puts("endif\n");
3390 if(resNode.files && resNode.files.count && !noResources)
3391 resNode.GenMakefileAddResources(f, resNode.path, config);
3393 f.Puts("ifdef WINDOWS_HOST\n");
3394 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)objects.lst $(LIBS)\n");
3396 f.Puts("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
3399 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3400 f.Puts("ifdef LINUX_TARGET\n");
3401 f.Puts("ifdef LINUX_HOST\n");
3402 // TODO?: support symlinks for longer version numbers
3403 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3404 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3409 //f.Puts("# POST-BUILD COMMANDS\n");
3410 if(options && options.postbuildCommands)
3412 for(s : options.postbuildCommands)
3413 if(s && s[0]) f.Printf("\t%s\n", s);
3415 if(config && config.options && config.options.postbuildCommands)
3417 for(s : config.options.postbuildCommands)
3418 if(s && s[0]) f.Printf("\t%s\n", s);
3420 if(platforms || (config && config.platforms))
3423 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3424 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3426 PlatformOptions projectPOs, configPOs;
3427 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3429 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3430 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3435 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3437 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3439 for(s : projectPOs.options.postbuildCommands)
3440 if(s && s[0]) f.Printf("\t%s\n", s);
3442 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3444 for(s : configPOs.options.postbuildCommands)
3445 if(s && s[0]) f.Printf("\t%s\n", s);
3452 for(c = 0; c < ifCount; c++)
3459 if(platforms || (config && config.platforms))
3461 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3463 PlatformOptions projectPOs, configPOs;
3464 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3466 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3467 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3474 if(test || (options && options.installCommands) ||
3475 (config && config.options && config.options.installCommands))
3477 f.Puts("install:\n");
3478 if(options && options.installCommands)
3480 for(s : options.installCommands)
3481 if(s && s[0]) f.Printf("\t%s\n", s);
3483 if(config && config.options && config.options.installCommands)
3485 for(s : config.options.installCommands)
3486 if(s && s[0]) f.Printf("\t%s\n", s);
3488 if(platforms || (config && config.platforms))
3491 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3493 PlatformOptions projectPOs, configPOs;
3494 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3496 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3497 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3502 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3504 if(projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count)
3506 for(s : projectPOs.options.installCommands)
3507 if(s && s[0]) f.Printf("\t%s\n", s);
3509 if(configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count)
3511 for(s : configPOs.options.installCommands)
3512 if(s && s[0]) f.Printf("\t%s\n", s);
3519 for(c = 0; c < ifCount; c++)
3526 f.Puts("# SYMBOL RULES\n");
3529 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3531 f.Puts("# C OBJECT RULES\n");
3534 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3536 f.Puts("# OBJECT RULES\n");
3538 // todo call this still but only generate rules whith specific options
3539 // see we-have-file-specific-options in ProjectNode.ec
3540 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3543 GenMakefilePrintMainObjectRule(f, config);
3545 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3548 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)");
3549 f.Printf("\t$(call rmq,$(OBJ)symbols.lst)\n");
3551 f.Printf("\t$(call rmq,$(OBJ)objects.lst)\n");
3552 f.Puts("\t$(call rmq,$(TARGET))\n");
3553 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3554 f.Puts("ifdef LINUX_TARGET\n");
3555 f.Puts("ifdef LINUX_HOST\n");
3556 // TODO?: support symlinks for longer version numbers
3557 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3558 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3564 f.Puts("clean: cleantarget\n");
3565 OutputCleanActions(f, "OBJECTS", objectsParts);
3568 f.Puts("ifdef WINDOWS_TARGET\n");
3569 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3574 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3575 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3576 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3577 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3578 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3582 f.Puts("realclean: cleantarget\n");
3583 f.Puts("\t$(call rmrq,$(OBJ))\n");
3584 if(!sameOrRelObjTargetDirs)
3585 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3588 f.Puts("distclean: cleantarget\n");
3589 if(!sameOrRelObjTargetDirs)
3590 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3592 f.Puts("\t$(call rmrq,obj/)\n");
3598 varStringLenDiffs.Free();
3599 delete varStringLenDiffs;
3603 delete cflagsVariations;
3604 delete nodeCFlagsMapping;
3605 delete ecflagsVariations;
3606 delete nodeECFlagsMapping;
3611 // ChangeWorkingDir(oldDirectory);
3612 // delete pathBackup;
3615 config.makingModified = false;
3619 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3621 char extension[MAX_EXTENSION] = "c";
3622 //char modulePath[MAX_LOCATION];
3623 char fixedModuleName[MAX_FILENAME];
3625 //char command[2048];
3626 char objDirNoSpaces[MAX_LOCATION];
3627 const String objDirExp = GetObjDirExpression(config);
3629 ReplaceSpaces(objDirNoSpaces, objDirExp);
3630 ReplaceSpaces(fixedModuleName, moduleName);
3632 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3633 //strcat(fixedModuleName, ".main");
3635 #if 0 // TODO: Fix nospaces stuff
3636 // *** Dependency command ***
3637 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3639 // System Includes (from global settings)
3640 for(item : compiler.dirs[Includes])
3642 strcat(command, " -isystem ");
3643 if(strchr(item.name, ' '))
3645 strcat(command, "\"");
3646 strcat(command, item);
3647 strcat(command, "\"");
3650 strcat(command, item);
3653 for(item = includeDirs.first; item; item = item.next)
3655 strcat(command, " -I");
3656 if(strchr(item.name, ' '))
3658 strcat(command, "\"");
3659 strcat(command, item.name);
3660 strcat(command, "\"");
3663 strcat(command, item.name);
3665 for(item = preprocessorDefs.first; item; item = item.next)
3667 strcat(command, " -D");
3668 strcat(command, item.name);
3672 if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
3676 bool firstLine = true;
3678 // To do some time: auto save external dependencies?
3681 if(dep.GetLine(line, sizeof(line)-1))
3685 char * colon = strstr(line, ":");
3686 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3700 // If we failed to generate dependencies...
3704 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3705 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(call quote_path,$@)\n", extension);
3713 void GenMakePrintCustomFlags(File f, const String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3716 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3718 for(v : cflagsVariations)
3723 f.Printf("%s +=", variableName);
3725 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3726 f.Puts(&v ? &v : "");
3734 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3735 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3737 *projectPlatformOptions = null;
3738 *configPlatformOptions = null;
3743 if(!strcmpi(p.name, platform))
3745 *projectPlatformOptions = p;
3750 if(config && config.platforms)
3752 for(p : config.platforms)
3754 if(!strcmpi(p.name, platform))
3756 *configPlatformOptions = p;
3764 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3766 const char * cfgName = cfg ? cfg.name : "";
3767 Map<String, NameCollisionInfo> cfgNameCollisions = prj.configsNameCollisions[cfgName];
3768 if(cfgNameCollisions)
3770 cfgNameCollisions.Free();
3771 delete cfgNameCollisions;
3773 prj.configsNameCollisions[cfgName] = cfgNameCollisions = { };
3774 prj.topNode.GenMakefileGetNameCollisionInfo(cfgNameCollisions, cfg);
3777 Project LegacyBinaryLoadProject(File f, const char * filePath)
3779 Project project = null;
3780 char signature[sizeof(epjSignature)];
3782 f.Read(signature, sizeof(signature), 1);
3783 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3785 char topNodePath[MAX_LOCATION];
3786 /*ProjectConfig newConfig
3788 name = CopyString("Default");
3789 makingModified = true;
3790 compilingModified = true;
3791 linkingModified = true;
3795 project = Project { options = { } };
3796 LegacyBinaryLoadNode(project.topNode, f);
3797 delete project.topNode.path;
3798 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3799 MakeSlashPath(topNodePath);
3801 PathCatSlash(topNodePath, filePath);
3802 project.filePath = topNodePath;
3804 /* THIS IS ALREADY DONE BY filePath property
3805 StripLastDirectory(topNodePath, topNodePath);
3806 project.topNode.path = CopyString(topNodePath);
3808 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3810 // newConfig.options.defaultNameSpace = "";
3811 /*newConfig.objDir.dir = "obj";
3812 newConfig.targetDir.dir = "";*/
3814 //project.configurations = { [ newConfig ] };
3815 //project.config = newConfig;
3822 String targetFileName, targetDirectory, objectsDirectory;
3824 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3825 f.Read(&temp, sizeof(int),1);
3828 case 0: project.options.targetType = executable; break;
3829 case 1: project.options.targetType = sharedLibrary; break;
3830 case 2: project.options.targetType = staticLibrary; break;
3833 f.Read(&len, sizeof(int),1);
3834 targetFileName = new char[len+1];
3835 f.Read(targetFileName, sizeof(char), len+1);
3836 project.options.targetFileName = targetFileName;
3837 delete targetFileName;
3839 f.Read(&len, sizeof(int),1);
3840 targetDirectory = new char[len+1];
3841 f.Read(targetDirectory, sizeof(char), len+1);
3842 project.options.targetDirectory = targetDirectory;
3843 delete targetDirectory;
3845 f.Read(&len, sizeof(int),1);
3846 objectsDirectory = new byte[len+1];
3847 f.Read(objectsDirectory, sizeof(char), len+1);
3848 project.options.objectsDirectory = objectsDirectory;
3849 delete objectsDirectory;
3851 f.Read(&temp, sizeof(int),1);
3852 project./*config.*/options.debug = temp ? true : false;
3853 f.Read(&temp, sizeof(int),1);
3854 project./*config.*/options.optimization = temp ? speed : none;
3855 f.Read(&temp, sizeof(int),1);
3856 project./*config.*/options.profile = temp ? true : false;
3857 f.Read(&temp, sizeof(int),1);
3858 project.options.warnings = temp ? all : unset;
3860 f.Read(&count, sizeof(int),1);
3863 project.options.includeDirs = { };
3864 for(c = 0; c < count; c++)
3867 f.Read(&len, sizeof(int),1);
3868 name = new char[len+1];
3869 f.Read(name, sizeof(char), len+1);
3870 project.options.includeDirs.Add(name);
3874 f.Read(&count, sizeof(int),1);
3877 project.options.libraryDirs = { };
3878 for(c = 0; c < count; c++)
3881 f.Read(&len, sizeof(int),1);
3882 name = new char[len+1];
3883 f.Read(name, sizeof(char), len+1);
3884 project.options.libraryDirs.Add(name);
3888 f.Read(&count, sizeof(int),1);
3891 project.options.libraries = { };
3892 for(c = 0; c < count; c++)
3895 f.Read(&len, sizeof(int),1);
3896 name = new char[len+1];
3897 f.Read(name, sizeof(char), len+1);
3898 project.options.libraries.Add(name);
3902 f.Read(&count, sizeof(int),1);
3905 project.options.preprocessorDefinitions = { };
3906 for(c = 0; c < count; c++)
3909 f.Read(&len, sizeof(int),1);
3910 name = new char[len+1];
3911 f.Read(name, sizeof(char), len+1);
3912 project.options.preprocessorDefinitions.Add(name);
3916 f.Read(&temp, sizeof(int),1);
3917 project.options.console = temp ? true : false;
3920 for(node : project.topNode.files)
3922 if(node.type == resources)
3924 project.resNode = node;
3934 void ProjectConfig::LegacyProjectConfigLoad(File f)
3942 char subSection[128];
3947 f.GetLine(buffer, 65536 - 1);
3948 TrimLSpaces(buffer, buffer);
3949 TrimRSpaces(buffer, buffer);
3952 if(buffer[0] == '-')
3956 TrimLSpaces(equal, equal);
3957 if(!strcmpi(subSection, "LibraryDirs"))
3959 if(!options.libraryDirs)
3960 options.libraryDirs = { [ CopyString(equal) ] };
3962 options.libraryDirs.Add(CopyString(equal));
3964 else if(!strcmpi(subSection, "IncludeDirs"))
3966 if(!options.includeDirs)
3967 options.includeDirs = { [ CopyString(equal) ] };
3969 options.includeDirs.Add(CopyString(equal));
3972 else if(buffer[0] == '+')
3983 TrimLSpaces(equal, equal);
3984 delete name; name = CopyString(equal); // property::name = equal;
3987 else if(!strcmpi(buffer, "Compiler Options"))
3988 strcpy(section, buffer);
3989 else if(!strcmpi(buffer, "IncludeDirs"))
3990 strcpy(subSection, buffer);
3991 else if(!strcmpi(buffer, "Linker Options"))
3992 strcpy(section, buffer);
3993 else if(!strcmpi(buffer, "LibraryDirs"))
3994 strcpy(subSection, buffer);
3995 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
4002 equal = strstr(buffer, "=");
4006 TrimRSpaces(buffer, buffer);
4008 TrimLSpaces(equal, equal);
4009 if(!strcmpi(buffer, "Target Name"))
4010 options.targetFileName = /*CopyString(*/equal/*)*/;
4011 else if(!strcmpi(buffer, "Target Type"))
4013 if(!strcmpi(equal, "Executable"))
4014 options.targetType = executable;
4015 else if(!strcmpi(equal, "Shared"))
4016 options.targetType = sharedLibrary;
4017 else if(!strcmpi(equal, "Static"))
4018 options.targetType = staticLibrary;
4020 options.targetType = executable;
4022 else if(!strcmpi(buffer, "Target Directory"))
4023 options.targetDirectory = /*CopyString(*/equal/*)*/;
4024 else if(!strcmpi(buffer, "Console"))
4025 options.console = ParseTrueFalseValue(equal);
4026 else if(!strcmpi(buffer, "Libraries"))
4028 if(!options.libraries) options.libraries = { };
4029 ParseArrayValue(options.libraries, equal);
4031 else if(!strcmpi(buffer, "Intermediate Directory"))
4032 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4033 else if(!strcmpi(buffer, "Debug"))
4034 options.debug = ParseTrueFalseValue(equal);
4035 else if(!strcmpi(buffer, "Optimize"))
4037 if(!strcmpi(equal, "None"))
4038 options.optimization = none;
4039 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4040 options.optimization = speed;
4041 else if(!strcmpi(equal, "Size"))
4042 options.optimization = size;
4044 options.optimization = none;
4046 else if(!strcmpi(buffer, "Compress"))
4047 options.compress = ParseTrueFalseValue(equal);
4048 else if(!strcmpi(buffer, "Profile"))
4049 options.profile = ParseTrueFalseValue(equal);
4050 else if(!strcmpi(buffer, "AllWarnings"))
4051 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4052 else if(!strcmpi(buffer, "MemoryGuard"))
4053 options.memoryGuard = ParseTrueFalseValue(equal);
4054 else if(!strcmpi(buffer, "Default Name Space"))
4055 options.defaultNameSpace = CopyString(equal);
4056 else if(!strcmpi(buffer, "Strict Name Spaces"))
4057 options.strictNameSpaces = ParseTrueFalseValue(equal);
4058 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4060 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
4061 ParseArrayValue(options.preprocessorDefinitions, equal);
4067 if(!options.targetDirectory && options.objectsDirectory)
4068 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
4069 //if(!objDir.dir) objDir.dir = "obj";
4070 //if(!targetDir.dir) targetDir.dir = "";
4071 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
4072 // if(!defaultNameSpace) property::defaultNameSpace = "";
4073 makingModified = true;
4076 Project LegacyAsciiLoadProject(File f, const char * filePath)
4078 Project project = null;
4080 char parentPath[MAX_LOCATION];
4081 char section[128] = "";
4082 char subSection[128] = "";
4083 ProjectNode parent = null;
4084 bool configurationsPresent = false;
4094 f.GetLine(buffer, 65536 - 1);
4095 TrimLSpaces(buffer, buffer);
4096 TrimRSpaces(buffer, buffer);
4099 if(buffer[0] == '-' || buffer[0] == '=')
4101 bool simple = buffer[0] == '-';
4104 TrimLSpaces(equal, equal);
4105 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
4107 if(!project.config.options.libraryDirs)
4108 project.config.options.libraryDirs = { [ CopyString(equal) ] };
4110 project.config.options.libraryDirs.Add(CopyString(equal));
4112 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
4114 if(!project.config.options.includeDirs)
4115 project.config.options.includeDirs = { [ CopyString(equal) ] };
4117 project.config.options.includeDirs.Add(CopyString(equal));
4119 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4121 len = strlen(equal);
4124 char temp[MAX_LOCATION];
4125 ProjectNode child { };
4126 // We don't need to do this anymore, fileName is just a property that sets name & path
4127 // child.fileName = CopyString(equal);
4130 child.name = CopyString(equal);
4131 child.path = CopyString(parentPath);
4135 GetLastDirectory(equal, temp);
4136 child.name = CopyString(temp);
4137 StripLastDirectory(equal, temp);
4138 child.path = CopyString(temp);
4140 child.nodeType = file;
4141 child.parent = parent;
4142 child.indent = parent.indent + 1;
4144 child.icon = NodeIcons::SelectFileIcon(child.name);
4145 parent.files.Add(child);
4151 StripLastDirectory(parentPath, parentPath);
4152 parent = parent.parent;
4156 else if(buffer[0] == '+')
4160 TrimLSpaces(equal, equal);
4161 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4163 char temp[MAX_LOCATION];
4164 ProjectNode child { };
4165 // NEW: Folders now have a path set like files
4166 child.name = CopyString(equal);
4167 strcpy(temp, parentPath);
4168 PathCatSlash(temp, child.name);
4169 child.path = CopyString(temp);
4171 child.parent = parent;
4172 child.indent = parent.indent + 1;
4173 child.type = folder;
4174 child.nodeType = folder;
4176 child.icon = folder;
4177 PathCatSlash(parentPath, child.name);
4178 parent.files.Add(child);
4183 else if(!strcmpi(section, "Configurations"))
4185 ProjectConfig newConfig
4187 makingModified = true;
4191 LegacyProjectConfigLoad(newConfig, f);
4192 project.configurations.Add(newConfig);
4195 else if(!strcmpi(buffer, "ECERE Project File"));
4196 else if(!strcmpi(buffer, "Version 0a"))
4197 ; //strcpy(version, "0a");
4198 else if(!strcmpi(buffer, "Version 0.1a"))
4199 ; //strcpy(version, "0.1a");
4200 else if(!strcmpi(buffer, "Configurations"))
4202 project.configurations.Free();
4203 project.config = null;
4204 strcpy(section, buffer);
4205 configurationsPresent = true;
4207 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
4209 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
4210 char topNodePath[MAX_LOCATION];
4211 // newConfig.defaultNameSpace = "";
4212 //newConfig.objDir.dir = "obj";
4213 //newConfig.targetDir.dir = "";
4214 project = Project { /*options = { }*/ };
4215 project.configurations = { [ newConfig ] };
4216 project.config = newConfig;
4217 // if(project.topNode.path) delete project.topNode.path;
4218 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4219 MakeSlashPath(topNodePath);
4220 PathCatSlash(topNodePath, filePath);
4221 project.filePath = topNodePath;
4222 parentPath[0] = '\0';
4223 parent = project.topNode;
4225 strcpy(section, "Target");
4230 if(equal[0] == '\"')
4232 StripQuotes(equal, equal);
4233 delete project.moduleName; project.moduleName = CopyString(equal);
4237 else if(!strcmpi(buffer, "Compiler Options"));
4238 else if(!strcmpi(buffer, "IncludeDirs"))
4239 strcpy(subSection, buffer);
4240 else if(!strcmpi(buffer, "Linker Options"));
4241 else if(!strcmpi(buffer, "LibraryDirs"))
4242 strcpy(subSection, buffer);
4243 else if(!strcmpi(buffer, "Files"))
4245 strcpy(section, "Target");
4246 strcpy(subSection, buffer);
4248 else if(!strcmpi(buffer, "Resources"))
4250 ProjectNode child { };
4251 parent.files.Add(child);
4252 child.parent = parent;
4253 child.indent = parent.indent + 1;
4254 child.name = CopyString(buffer);
4255 child.path = CopyString("");
4256 child.type = resources;
4258 child.icon = archiveFile;
4259 project.resNode = child;
4262 strcpy(subSection, buffer);
4266 equal = strstr(buffer, "=");
4270 TrimRSpaces(buffer, buffer);
4272 TrimLSpaces(equal, equal);
4274 if(!strcmpi(section, "Target"))
4276 if(!strcmpi(buffer, "Build Exclusions"))
4278 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4280 /*if(node && node.type != NodeTypes::project)
4281 ParseListValue(node.buildExclusions, equal);*/
4284 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4286 delete project.resNode.path;
4287 project.resNode.path = CopyString(equal);
4288 PathCatSlash(parentPath, equal);
4292 else if(!strcmpi(buffer, "Intermediate Directory"))
4293 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4294 else if(!strcmpi(buffer, "Debug"))
4295 project.config.options.debug = ParseTrueFalseValue(equal);
4296 else if(!strcmpi(buffer, "Optimize"))
4298 if(!strcmpi(equal, "None"))
4299 project.config.options.optimization = none;
4300 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4301 project.config.options.optimization = speed;
4302 else if(!strcmpi(equal, "Size"))
4303 project.config.options.optimization = size;
4305 project.config.options.optimization = none;
4307 else if(!strcmpi(buffer, "Profile"))
4308 project.config.options.profile = ParseTrueFalseValue(equal);
4309 else if(!strcmpi(buffer, "MemoryGuard"))
4310 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4313 if(!project.options) project.options = { };
4315 // Project Wide Settings (All configs)
4316 if(!strcmpi(buffer, "Target Name"))
4317 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4318 else if(!strcmpi(buffer, "Target Type"))
4320 if(!strcmpi(equal, "Executable"))
4321 project.options.targetType = executable;
4322 else if(!strcmpi(equal, "Shared"))
4323 project.options.targetType = sharedLibrary;
4324 else if(!strcmpi(equal, "Static"))
4325 project.options.targetType = staticLibrary;
4327 project.options.targetType = executable;
4329 else if(!strcmpi(buffer, "Target Directory"))
4330 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4331 else if(!strcmpi(buffer, "Console"))
4332 project.options.console = ParseTrueFalseValue(equal);
4333 else if(!strcmpi(buffer, "Libraries"))
4335 if(!project.options.libraries) project.options.libraries = { };
4336 ParseArrayValue(project.options.libraries, equal);
4338 else if(!strcmpi(buffer, "AllWarnings"))
4339 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4340 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4342 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4344 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4345 ParseListValue(node.preprocessorDefs, equal);*/
4349 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4350 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4361 SplitPlatformLibraries(project);
4363 if(configurationsPresent)
4364 CombineIdenticalConfigOptions(project);
4368 void SplitPlatformLibraries(Project project)
4370 if(project && project.configurations)
4372 for(cfg : project.configurations)
4374 if(cfg.options.libraries && cfg.options.libraries.count)
4376 Iterator<String> it { cfg.options.libraries };
4380 char * platformName = strstr(l, ":");
4383 PlatformOptions platform = null;
4385 if(!cfg.platforms) cfg.platforms = { };
4386 for(p : cfg.platforms)
4388 if(!strcmpi(platformName, p.name))
4396 platform = { name = CopyString(platformName), options = { libraries = { } } };
4397 cfg.platforms.Add(platform);
4399 *(platformName-1) = 0;
4400 platform.options.libraries.Add(CopyString(l));
4402 cfg.options.libraries.Delete(it.pointer);
4411 void CombineIdenticalConfigOptions(Project project)
4413 if(project && project.configurations && project.configurations.count)
4416 ProjectOptions nullOptions { };
4417 ProjectConfig firstConfig = null;
4418 for(cfg : project.configurations)
4420 if(cfg.options.targetType != staticLibrary)
4427 firstConfig = project.configurations.firstIterator.data;
4429 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4431 if(!member.isProperty)
4433 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4438 for(cfg : project.configurations)
4440 if(cfg != firstConfig)
4442 if(cfg.options.targetType != staticLibrary)
4446 if(type.type == noHeadClass || type.type == normalClass)
4448 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4449 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4450 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4454 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4455 (byte *)firstConfig.options + member.offset + member._class.offset,
4456 (byte *)cfg.options + member.offset + member._class.offset);
4468 if(type.type == noHeadClass || type.type == normalClass)
4470 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4471 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4472 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4477 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4478 (byte *)firstConfig.options + member.offset + member._class.offset,
4479 (byte *)nullOptions + member.offset + member._class.offset))
4483 if(!project.options) project.options = { };
4485 /*if(type.type == noHeadClass || type.type == normalClass)
4487 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4488 (byte *)project.options + member.offset + member._class.offset,
4489 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4493 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4494 // TOFIX: ListBox::SetData / OnCopy mess
4495 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4496 (byte *)project.options + member.offset + member._class.offset,
4497 (type.typeSize > 4) ? address :
4498 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4499 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4500 (void *)*(byte *)address )));
4503 (byte *)project.options + member.offset + member._class.offset,
4504 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4506 for(cfg : project.configurations)
4508 if(cfg.options.targetType == staticLibrary)
4512 if(type.type == noHeadClass || type.type == normalClass)
4514 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4515 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4516 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4520 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4521 (byte *)firstConfig.options + member.offset + member._class.offset,
4522 (byte *)cfg.options + member.offset + member._class.offset);
4527 if(cfg != firstConfig)
4529 if(type.type == noHeadClass || type.type == normalClass)
4531 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4532 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4536 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4537 (byte *)cfg.options + member.offset + member._class.offset);
4539 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4542 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4549 // Compare Platform Specific Settings
4552 for(cfg : project.configurations)
4554 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4555 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4561 if(same && firstConfig.platforms)
4563 for(cfg : project.configurations)
4565 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4567 if(cfg != firstConfig)
4569 cfg.platforms = null;
4572 project.platforms = firstConfig.platforms;
4573 *&firstConfig.platforms = null;
4577 // Static libraries can't contain libraries
4578 for(cfg : project.configurations)
4580 if(cfg.options.targetType == staticLibrary)
4582 if(!cfg.options.libraries) cfg.options.libraries = { };
4583 cfg.options.libraries.Free();
4589 Project LoadProject(const char * filePath, const char * activeConfigName)
4591 Project project = null;
4592 File f = FileOpen(filePath, read);
4595 project = LegacyBinaryLoadProject(f, filePath);
4598 JSONParser parser { f = f };
4599 /*JSONResult result = */parser.GetObject(class(Project), &project);
4602 char insidePath[MAX_LOCATION];
4604 delete project.topNode.files;
4605 if(!project.files) project.files = { };
4606 project.topNode.files = project.files;
4609 char topNodePath[MAX_LOCATION];
4610 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4611 MakeSlashPath(topNodePath);
4612 PathCatSlash(topNodePath, filePath);
4613 project.filePath = topNodePath;//filePath;
4616 project.topNode.FixupNode(insidePath);
4618 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4619 delete project.resNode.path;
4620 project.resNode.path = project.resourcesPath;
4621 project.resourcesPath = null;
4622 project.resNode.nodeType = (ProjectNodeType)-1;
4623 delete project.resNode.files;
4624 project.resNode.files = project.resources;
4625 project.files = null;
4626 project.resources = null;
4627 if(!project.configurations) project.configurations = { };
4629 project.resNode.FixupNode(insidePath);
4634 project = LegacyAsciiLoadProject(f, filePath);
4640 if(!project.options) project.options = { };
4641 if(activeConfigName && activeConfigName[0] && project.configurations)
4642 project.config = project.GetConfig(activeConfigName);
4643 if(!project.config && project.configurations)
4644 project.config = project.configurations.firstIterator.data;
4646 if(!project.resNode)
4648 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4651 if(!project.moduleName)
4652 project.moduleName = CopyString(project.name);
4653 if(project.config &&
4654 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4655 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4657 //delete project.config.options.targetFileName;
4659 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4660 project.config.options.optimization = none;
4661 project.config.options.debug = true;
4662 //project.config.options.warnings = unset;
4663 project.config.options.memoryGuard = false;
4664 project.config.compilingModified = true;
4665 project.config.linkingModified = true;
4667 else if(!project.topNode.name && project.config)
4669 project.topNode.name = CopyString(project.config.options.targetFileName);
4672 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4673 project.topNode.configurations = project.configurations;
4674 project.topNode.platforms = project.platforms;
4675 project.topNode.options = project.options;*/
4681 #ifndef MAKEFILE_GENERATOR
4682 static GccVersionInfo GetGccVersionInfo(CompilerConfig compiler, const String compilerCommand)
4684 GccVersionInfo result = unknown;
4685 if(compiler.ccCommand)
4687 char command[MAX_F_STRING*4];
4689 sprintf(command, "%s%s --version", compiler.gccPrefix ? compiler.gccPrefix : "", compilerCommand);
4690 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
4692 bool firstLine = true;
4697 if(f.GetLine(line,sizeof(line)))
4701 uint count = Tokenize(line, sizeof(tokens)/sizeof(tokens[0]), tokens,false);
4702 char * token = null;
4705 for(i = 0; i < count; i++)
4707 if(tokens[i][0] == '(')
4709 if(tokens[i][strlen(tokens[i])-1] != ')')
4712 else if(tokens[i][0] && tokens[i][strlen(tokens[i])-1] == ')')
4714 else if(!inPar && isdigit(tokens[i][0]) && strchr(tokens[i], '.'))
4718 result = GccVersionInfo::GetVersionInfo(token);
4729 static enum GccVersionInfo
4731 unknown, pre4_8, post4_8;
4733 GccVersionInfo ::GetVersionInfo(char * version)
4735 GccVersionInfo result = unknown;
4737 char * s = CopyString(version);
4739 uint count = TokenizeWith(s, sizeof(tokens)/sizeof(tokens[0]), tokens, ".", false);
4740 ver = count > 1 ? atoi(tokens[1]) : 0;
4741 ver += count ? atoi(tokens[0]) * 1000 : 0;