2 public import static "ecere"
9 #ifndef MAKEFILE_GENERATOR
11 // We should have the .sln/.vcproj generation even on other platforms
12 // e.g. detect from an environment variable pointing to a Windows drive
18 import "ProjectConfig"
24 static __attribute__((unused)) void DummyFunction()
32 extern int __ecereVMethodID_class_OnCompare;
33 extern int __ecereVMethodID_class_OnFree;
35 IDESettings ideSettings;
37 IDESettingsContainer settingsContainer
40 dataOwner = &ideSettings;
41 dataClass = class(IDESettings);
43 void OnLoad(GlobalSettingsData data)
45 #ifndef MAKEFILE_GENERATOR
46 IDESettings settings = (IDESettings)data;
47 globalSettingsDialog.ideSettings = settings;
48 ide.UpdateRecentMenus();
49 ide.UpdateCompilerConfigs(true);
54 #ifdef MAKEFILE_GENERATOR
55 CompilerConfig defaultCompiler;
58 // LEGACY BINARY EPJ LOADING
60 SetBool ParseTrueFalseValue(char * string)
62 if(!strcmpi(string, "True")) return true;
66 void ParseArrayValue(Array<String> array, char * equal)
68 char * start, * comma;
70 string = CopyString(equal);
74 comma = strstr(start, ",");
77 array.Add(CopyString(start));
87 void ProjectNode::LegacyBinaryLoadNode(File f)
92 f.Read(&len, sizeof(len), 1);
93 name = new char[len+1];
95 f.Read(name, sizeof(char), len+1);
96 f.Read(&len, sizeof(len), 1);
98 path = new char[len+1];
99 f.Read(path, sizeof(char), len+1);
102 fileName = new char[fileNameLen+2];
103 strcpy(fileName, path);
104 if(fileName[0]) strcat(fileName, "/");
105 strcat(fileName, name);
108 f.Read(&type, sizeof(type), 1);
109 f.Read(&count, sizeof(count), 1);
114 icon = NodeIcons::SelectFileIcon(name);
119 icon = NodeIcons::SelectNodeIcon(type);
122 if(count && !files) files = { };
123 for(c = 0; c < count; c++)
125 ProjectNode child { };
128 child.indent = indent + 1;
129 LegacyBinaryLoadNode(child, f);
133 /*void LegacyBinarySaveNode(File f)
138 f.Write(&len, sizeof(len), 1);
139 f.Write(name, sizeof(char), len+1);
143 // Projects Absolute Path Are Not Saved
145 f.Write(&len, sizeof(len), 1);
146 f.Write(&len, sizeof(char), 1);
151 f.Write(&len, sizeof(len), 1);
152 f.Write(path, sizeof(char), len+1);
154 f.Write(&type, sizeof(type), 1);
155 f.Write(&children.count, sizeof(children.count), 1);
156 for(child = children.first; child; child.next)
160 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
163 char printPath[MAX_LOCATION];
165 if(type == project && (files.count /*|| preprocessorDefs.first*/))
167 f.Printf("\n Files\n");
169 else if(type == file)
171 if(!strcmp(path, insidePath))
172 f.Printf("%s - %s\n", indentation, name);
175 strcpy(printPath, path);
176 len = strlen(printPath);
178 if(printPath[len-1] != '/')
179 strcat(printPath, "/");
180 strcat(printPath, name);
181 f.Printf("%s = %s\n", indentation, printPath);
184 f.Printf("\nError\n\n");
186 else if(type == folder)
188 f.Printf("%s + %s\n", indentation, name);
190 else if(type == resources && files.count)
192 PathCatSlash(insidePath, path);
193 f.Printf("\n%sResources\n", indentation);
195 f.Printf("%s Path = %s\n", indentation, path);
198 /*if(buildExclusions.first && type != project)
200 for(item = buildExclusions.first; item; item = item.next)
202 if(item == buildExclusions.first)
203 f.Printf("%s Build Exclusions = %s", indentation, item.name);
205 f.Printf(", %s", item.name);
210 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
212 for(item = preprocessorDefs.first; item; item = item.next)
214 if(item == preprocessorDefs.first)
215 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
217 f.Printf(", %s", item.name);
223 if(type == project && (files.count /*|| preprocessorDefs.first*/))
227 LegacyAsciiSaveNode(child, f, indentation, insidePath);
229 else if(type == folder)
231 strcat(indentation, " ");
232 // WHAT WAS THIS: strcpy(printPath, path);
233 // TOCHECK: why is Unix/PathCat not used here
234 len = strlen(insidePath);
236 if(insidePath[len-1] != '/')
237 strcat(insidePath, "/");
238 strcat(insidePath, name);
241 LegacyAsciiSaveNode(child, f, indentation, insidePath);
242 f.Printf("%s -\n", indentation);
243 indentation[strlen(indentation) - 3] = '\0';
244 StripLastDirectory(insidePath, insidePath);
246 else if(type == resources && files.count)
250 LegacyAsciiSaveNode(child, f, indentation, insidePath);
251 StripLastDirectory(insidePath, insidePath);
256 void ProjectConfig::LegacyProjectConfigSave(File f)
258 char * indentation = " ";
260 //f.Printf("\n * Common\n");
262 f.Printf("\n + %s\n", name);
263 f.Printf("\n Compiler\n\n");
264 if(objDir.expression[0])
265 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
266 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
267 switch(options.optimization)
269 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
270 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
271 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
273 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
275 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
276 if(options.memoryGuard == true)
277 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
278 if(options.strictNameSpaces == true)
279 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
280 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
281 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
282 TOFIX: Compiler Bug {
283 if(options.preprocessorDefinitions.count)
286 for(item : options.preprocessorDefinitions)
290 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
294 f.Printf(", %s", item);
299 if(options.includeDirs.count)
301 f.Printf("\n%sInclude Directories\n", indentation);
302 for(item : options.includeDirs)
303 f.Printf("%s - %s\n", indentation, name);
307 f.Printf("\n%sLinker\n\n", indentation);
308 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
309 switch(options.targetType)
311 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
312 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
313 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
315 if(targetDir.expression[0])
316 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
318 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
320 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
321 if(options.libraries.count)
324 for(item : options.libraries)
328 f.Printf("\n%sLibraries = %s", indentation, name);
332 f.Printf(", %s", item);
336 if(options.libraryDirs.count)
338 f.Printf("\n%sLibrary Directories\n\n", indentation);
339 for(item : options.libraryDirs)
340 f.Printf(" - %s\n", indentation, item);
344 void LegacyAsciiSaveProject(File f, Project project)
346 char indentation[128*3];
347 char path[MAX_LOCATION];
349 f.Printf("\nECERE Project File : Format Version 0.1b\n");
350 f.Printf("\nDescription\n%s\n.\n", project.description);
351 f.Printf("\nLicense\n%s\n.\n", project.license);
352 f.Printf("\nModule Name = %s\n", project.moduleName);
353 f.Printf("\n Configurations\n");
354 //////////////////////////////////////commonConfig.Save(f, true);
355 for(cfg : project.configurations)
356 LegacyProjectConfigSave(cfg, f);
358 strcpy(indentation, " ");
360 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
366 // *** NEW JSON PROJECT FORMAT ***
367 public enum ProjectNodeType { file, folder };
369 // *******************************
371 define PEEK_RESOLUTION = (18.2 * 10);
377 static Array<const String> notLinkerOptions
399 static bool IsLinkerOption(String s)
401 for(i : notLinkerOptions)
402 if(strstr(s, "-Wl,") || !strcmp(s, i))
407 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
409 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources, rcSources };
411 define WorkspaceExtension = "ews";
412 define ProjectExtension = "epj";
414 define stringInFileIncludedFrom = "In file included from ";
415 define stringFrom = " from ";
417 // chars refused for project name: windowsFileNameCharsNotAllowed + " &,."
419 //define gnuMakeCharsNeedEscaping = "$%";
421 //define windowsFileNameCharsNotAllowed = "*/:<>?\\\"|";
422 //define linuxFileNameCharsNotAllowed = "/";
424 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
425 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
427 // NOTES: - this function should get only unescaped unix style paths
428 // - paths with literal $(somestring) in them are not supported
429 // my_$(messed_up)_path would likely become my__path
430 void EscapeForMake(char * output, const char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
432 char ch, *o = output;
433 const char *i = input;
436 int len = strlen(input);
437 if(len && ((input[0] == '"' && input[len-1] == '"') || strchr(input, '\\') || strchr(input, 127) || (!allowDblQuote && strchr(input, '"'))))
438 PrintLn("Invalid input for EscapeForMake! -- ", input);
444 if(i-1 != input && *(i-2) == '$' && allowVars)
451 if(inVar == true && allowVars)
456 else if(ch == '$' && *i != '(')
478 void EscapeForMakeToFile(File output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
480 char * buf = new char[strlen(input)*2+1];
481 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
486 void EscapeForMakeToDynString(DynamicString output, const char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
488 char * buf = new char[strlen(input)*2+1];
489 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
494 int OutputFileList(File f, const char * name, Array<String> list, Map<String, int> varStringLenDiffs, const char * prefix)
497 const int breakListLength = 1536;
498 const int breakLineLength = 78; // TODO: turn this into an option.
500 int c, len, itemCount = 0;
501 Array<int> breaks { };
505 MapNode<String, int> mn;
506 for(c=0; c<list.count; c++)
508 len = strlen(list[c]) + 3;
509 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
511 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
513 if(strstr(list[c], mn.key))
517 if(charCount + len > breakListLength)
519 breaks.Add(itemCount);
527 breaks.Add(itemCount);
528 numOfBreaks = breaks.count;
533 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
534 for(c=0; c<numOfBreaks; c++)
535 f.Printf(" $(%s%d)", name, c+1);
539 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
545 for(c=0; c<numOfBreaks; c++)
548 f.Printf("%s%d =", name, c+1);
551 itemCount = breaks[c];
552 for(n=offset; n<offset+itemCount; n++)
554 if(false) // TODO: turn this into an option.
556 int itemLen = strlen(list[n]);
557 if(len > 3 && len + itemLen > breakLineLength)
559 f.Printf(" \\\n\t%s", list[n]);
565 f.Printf(" %s", list[n]);
569 f.Printf(" \\\n\t%s", list[n]);
584 void OutputFileListActions(File f, const char * name, int parts, const char * fileName)
589 for(c=0; c<parts; c++)
590 f.Printf("\t@$(call echo,$(%s%d)) >> %s\n", name, c+1, fileName);
592 f.Printf("\t@$(call echo,$(%s)) >> %s\n", name, fileName);
596 void OutputCleanActions(File f, const char * name, int parts)
601 for(c=0; c<parts; c++)
602 f.Printf("\t$(call rmq,$(_%s%d))\n", name, c+1);
605 f.Printf("\t$(call rmq,$(_%s))\n", name);
608 enum LineOutputMethod { inPlace, newLine, lineEach };
609 enum StringOutputMethod { asIs, escape, escapePath};
611 enum ToolchainFlag { any, _D, _I, _isystem, _Wl, _L/*, _Wl-rpath*/ };
612 const String flagNames[ToolchainFlag] = { "", "-D", "-I", "-isystem ", "-Wl,", /*"-Wl,--library-path="*/"-L"/*, "-Wl,-rpath "*/ };
613 void OutputFlags(File f, ToolchainFlag flag, Array<String> list, LineOutputMethod lineMethod)
617 if(lineMethod == newLine)
621 if(lineMethod == lineEach)
623 f.Printf(" %s", flagNames[flag]);
624 if(flag != _D && flag != _Wl && flag != any)
626 char * tmp = new char[strlen(item)*2+1];
627 EscapeForMake(tmp, item, false, true, false);
628 f.Printf("$(call quote_path,%s)", tmp);
632 EscapeForMakeToFile(f, item, false, true, true);
637 static void OutputLibraries(File f, Array<String> libraries)
639 for(item : libraries)
641 char ext[MAX_EXTENSION];
642 char temp[MAX_LOCATION];
644 bool usedFunction = false;
645 GetExtension(item, ext);
646 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
650 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
652 if(!strncmp(item, "lib", 3))
653 strcpy(temp, item + 3);
656 StripExtension(temp);
659 f.Puts(" \\\n\t$(call _L,");
662 EscapeForMakeToFile(f, s, false, false, false);
668 void CamelCase(char * string)
672 int c, len = strlen(string);
673 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
674 string[c] = (char)tolower(string[c]);
678 CompilerConfig GetCompilerConfig()
680 #ifndef MAKEFILE_GENERATOR
681 CompilerConfig compiler = null;
682 if(ide && ide.workspace)
683 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
686 incref defaultCompiler;
687 return defaultCompiler;
691 define localTargetType = config && config.options && config.options.targetType ?
692 config.options.targetType : options && options.targetType ?
693 options.targetType : TargetTypes::executable;
694 define localWarnings = config && config.options && config.options.warnings ?
695 config.options.warnings : options && options.warnings ?
696 options.warnings : WarningsOption::unset;
697 define localDebug = config && config.options && config.options.debug ?
698 config.options.debug : options && options.debug ?
699 options.debug : SetBool::unset;
700 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
701 config.options.memoryGuard : options && options.memoryGuard ?
702 options.memoryGuard : SetBool::unset;
703 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
704 config.options.noLineNumbers : options && options.noLineNumbers ?
705 options.noLineNumbers : SetBool::unset;
706 define localProfile = config && config.options && config.options.profile ?
707 config.options.profile : options && options.profile ?
708 options.profile : SetBool::unset;
709 define localOptimization = config && config.options && config.options.optimization ?
710 config.options.optimization : options && options.optimization ?
711 options.optimization : OptimizationStrategy::none;
712 define localFastMath = config && config.options && config.options.fastMath ?
713 config.options.fastMath : options && options.fastMath ?
714 options.fastMath : SetBool::unset;
715 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
716 config.options.defaultNameSpace : options && options.defaultNameSpace ?
717 options.defaultNameSpace : null;
718 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
719 config.options.strictNameSpaces : options && options.strictNameSpaces ?
720 options.strictNameSpaces : SetBool::unset;
721 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
722 define localTargetFileName = config && config.options && config.options.targetFileName ?
723 config.options.targetFileName : options && options.targetFileName ?
724 options.targetFileName : "";
725 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
726 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
727 options.targetDirectory : null;
728 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
729 ideSettings.projectDefaultIntermediateObjDir[0] ?
730 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
731 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
732 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
733 options.objectsDirectory : null;
734 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
735 ideSettings.projectDefaultIntermediateObjDir[0] ?
736 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
737 define localConsole = config && config.options && config.options.console ?
738 config.options.console : options && options.console ?
739 options.console : SetBool::unset;
740 define localCompress = config && config.options && config.options.compress ?
741 config.options.compress : options && options.compress ?
742 options.compress : SetBool::unset;
744 define platformTargetType =
745 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
746 configPOs.options.targetType :
747 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
748 projectPOs.options.targetType : TargetTypes::unset;
751 const char * PlatformToMakefileTargetVariable(Platform platform)
753 return platform == win32 ? "WINDOWS_TARGET" :
754 platform == tux ? "LINUX_TARGET" :
755 platform == apple ? "OSX_TARGET" :
759 const char * TargetTypeToMakefileVariable(TargetTypes targetType)
761 return targetType == executable ? "executable" :
762 targetType == sharedLibrary ? "sharedlib" :
763 targetType == staticLibrary ? "staticlib" :
767 // Move this to ProjectConfig? null vs Common to consider...
768 const char * GetConfigName(ProjectConfig config)
770 return config ? config.name : "Common";
773 public enum SingleFileCompileMode
775 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
777 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
780 class Project : struct
782 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
783 // We might want to tweak this default behavior of regular classes ?
784 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
789 property const char * moduleVersion
791 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
792 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
793 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
796 property const char * description
798 set { delete description; if(value && value[0]) description = CopyString(value); }
799 get { return description ? description : ""; }
800 isset { return description != null && description[0]; }
803 property const char * license
805 set { delete license; if(value && value[0]) license = CopyString(value); }
806 get { return license ? license : ""; }
807 isset { return license != null && license[0]; }
810 property const char * compilerConfigsDir
812 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
813 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
814 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
817 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
818 property Array<PlatformOptions> platforms
820 get { return platforms; }
823 if(platforms) { platforms.Free(); delete platforms; }
826 List<PlatformOptions> empty { };
827 Iterator<PlatformOptions> it { value };
829 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
830 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
840 if(p.options && !p.options.isEmpty)
847 List<ProjectConfig> configurations;
848 LinkList<ProjectNode> files;
849 String resourcesPath;
850 LinkList<ProjectNode> resources;
853 // topNode.name holds the file name (.epj)
854 ProjectOptions options;
855 Array<PlatformOptions> platforms;
856 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
859 ProjectConfig config;
861 // This is the file name stripped of the epj extension
862 // It should NOT be edited, saved or loaded anywhere
867 String compilerConfigsDir;
868 String moduleVersion;
870 String lastBuildConfigName;
871 String lastBuildCompilerName;
873 Map<String, Map<String, NameCollisionInfo>> configsNameCollisions { };
875 #ifndef MAKEFILE_GENERATOR
876 FileMonitor fileMonitor
878 this, FileChange { modified = true };
879 bool OnFileNotify(FileChange action, const char * param)
881 fileMonitor.StopMonitoring();
882 if(OnProjectModified(action, param))
883 fileMonitor.StartMonitoring();
888 bool StartMonitoring()
890 fileMonitor.fileName = filePath;
891 fileMonitor.StartMonitoring();
895 bool StopMonitoring()
897 fileMonitor.StopMonitoring();
901 bool OnProjectModified(FileChange fileChange, const char * param)
904 sprintf(temp, $"The project %s was modified by another application.\n"
905 "Would you like to reload it and lose your changes?", name);
906 if(MessageBox { type = yesNo, master = ide,
907 text = $"Project has been modified", contents = temp }.Modal() == yes)
909 Project project = LoadProject(filePath, config ? config.name : null);
912 ProjectView projectView = ide.projectView;
913 DataRow prev = topNode.row ? topNode.row.previous : null;
914 FileMonitor fm = fileMonitor;
915 bool confirmation = true;
919 if(projectView.projectSettingsDialog)
921 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
923 projectView.projectSettingsDialog.Destroy(0);
926 projectView.DeleteNode(topNode);
933 topNode.project = this;
937 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
938 projectView.AddNode(topNode, null);
939 topNode.row.Move(prev);
941 projectView.ShowOutputBuildLog(true);
942 projectView.DisplayCompiler(compiler, false);
943 projectView.ProjectUpdateMakefileForAllConfigs(this);
946 eSystem_Delete(project);
958 // This frees contents without freeing the instance
959 // For use from destructor and for file monitor reloading
960 // (To work around JSON loader (LoadProject) always returning a new instance)
963 if(platforms) { platforms.Free(); delete platforms; }
964 if(configurations) { configurations.Free(); delete configurations; }
965 if(files) { files.Free(); delete files; }
966 if(resources) { resources.Free(); delete resources; }
968 delete resourcesPath;
972 delete compilerConfigsDir;
974 delete moduleVersion;
978 delete lastBuildConfigName;
979 delete lastBuildCompilerName;
980 for(map : configsNameCollisions)
982 configsNameCollisions.Free();
987 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
988 topNode.configurations = null;
989 topNode.platforms = null;
990 topNode.options = null;
995 property ProjectConfig config
1000 delete topNode.info;
1001 topNode.info = CopyString(GetConfigName(config));
1005 property const char * filePath
1011 char string[MAX_LOCATION];
1012 GetLastDirectory(value, string);
1013 delete topNode.name;
1014 topNode.name = CopyString(string);
1015 StripExtension(string);
1017 name = CopyString(string);
1018 StripLastDirectory(value, string);
1019 delete topNode.path;
1020 topNode.path = CopyString(string);
1022 filePath = CopyString(value);
1027 ProjectConfig GetConfig(const char * configName)
1029 ProjectConfig result = null;
1030 if(configName && configName[0] && configurations.count)
1032 for(cfg : configurations; !strcmpi(cfg.name, configName))
1041 ProjectNode FindNodeByObjectFileName(const char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
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]);
1054 TargetTypes GetTargetType(ProjectConfig config)
1056 TargetTypes targetType = localTargetType;
1060 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1063 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1065 PlatformOptions projectPOs, configPOs;
1066 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1067 if(platformTargetType)
1073 const char * GetObjDirExpression(ProjectConfig config)
1075 // TODO: Support platform options
1076 const char * expression = localObjectsDirectory;
1078 expression = settingsObjectsDirectory;
1082 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1084 const char * expression = GetObjDirExpression(config);
1085 DirExpression objDir { type = intermediateObjectsDir };
1086 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1090 const char * GetTargetDirExpression(ProjectConfig config)
1092 // TODO: Support platform options
1093 const char * expression = localTargetDirectory;
1095 expression = settingsTargetDirectory;
1099 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1101 const char * expression = GetTargetDirExpression(config);
1102 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1103 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1107 WarningsOption GetWarnings(ProjectConfig config)
1109 WarningsOption warnings = localWarnings;
1113 bool GetDebug(ProjectConfig config)
1115 SetBool debug = localDebug;
1116 return debug == true;
1119 bool GetMemoryGuard(ProjectConfig config)
1121 SetBool memoryGuard = localMemoryGuard;
1122 return memoryGuard == true;
1125 bool GetNoLineNumbers(ProjectConfig config)
1127 SetBool noLineNumbers = localNoLineNumbers;
1128 return noLineNumbers == true;
1131 bool GetProfile(ProjectConfig config)
1133 SetBool profile = localProfile;
1134 return profile == true;
1137 OptimizationStrategy GetOptimization(ProjectConfig config)
1139 OptimizationStrategy optimization = localOptimization;
1140 return optimization;
1143 bool GetFastMath(ProjectConfig config)
1145 SetBool fastMath = localFastMath;
1146 return fastMath == true;
1149 const String GetDefaultNameSpace(ProjectConfig config)
1151 const String defaultNameSpace = localDefaultNameSpace;
1152 return defaultNameSpace;
1155 bool GetStrictNameSpaces(ProjectConfig config)
1157 SetBool strictNameSpaces = localStrictNameSpaces;
1158 return strictNameSpaces == true;
1161 const String GetTargetFileName(ProjectConfig config)
1163 const String targetFileName = localTargetFileName;
1164 return targetFileName;
1167 //String targetDirectory;
1168 //String objectsDirectory;
1169 bool GetConsole(ProjectConfig config)
1171 SetBool console = localConsole;
1172 return console == true;
1175 bool GetCompress(ProjectConfig config)
1177 SetBool compress = localCompress;
1178 return compress == true;
1180 //SetBool excludeFromBuild;
1182 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1184 #ifndef MAKEFILE_GENERATOR
1185 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1191 bool GetConfigIsInDebugSession(ProjectConfig config)
1193 #ifndef MAKEFILE_GENERATOR
1194 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1200 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1202 #ifndef MAKEFILE_GENERATOR
1203 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1207 #ifndef MAKEFILE_GENERATOR
1208 bool Save(const char * fileName)
1211 /*char output[MAX_LOCATION];
1212 ChangeExtension(fileName, "json", output);
1213 f = FileOpen(output, write);*/
1214 f = FileOpen(fileName, write);
1217 files = topNode.files;
1218 resources = resNode.files;
1219 resourcesPath = resNode.path;
1221 files.Remove(resNode);
1224 WriteJSONObject(f, class(Project), this, 0);
1230 resourcesPath = null;
1237 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1239 TargetTypes targetType = GetTargetType(config);
1240 const String targetFileName = GetTargetFileName(config);
1241 if(targetType == staticLibrary)
1243 PathCatSlash(string, "lib");
1244 strcat(string, targetFileName);
1246 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1248 PathCatSlash(string, "lib");
1249 strcat(string, targetFileName);
1252 PathCatSlash(string, targetFileName);
1257 if(compiler.targetPlatform == win32)
1258 strcat(string, ".exe");
1261 if(compiler.targetPlatform == win32)
1262 strcat(string, ".dll");
1263 else if(compiler.targetPlatform == apple)
1264 strcat(string, ".dylib");
1266 strcat(string, ".so");
1267 if(compiler.targetPlatform == tux && __runtimePlatform == tux && moduleVersion && moduleVersion[0])
1269 strcat(string, ".");
1270 strcat(string, moduleVersion);
1274 strcat(string, ".a");
1279 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1281 bool result = false;
1282 char temp[MAX_LOCATION];
1283 strcpy(cfDir, topNode.path);
1284 if(compilerConfigsDir && compilerConfigsDir[0])
1286 PathCatSlash(cfDir, compilerConfigsDir);
1291 strcpy(temp, cfDir);
1292 // Using a relative path makes it less likely to run into spaces issues
1293 // Even with escaped spaces, there still seems to be issues including a config file
1294 // in a path containing spaces
1296 MakePathRelative(temp, topNode.path, cfDir);
1299 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1303 strcpy(temp, cfDir);
1304 ReplaceSpaces(cfDir, temp);
1309 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1311 char temp[MAX_LOCATION];
1312 bool result = false;
1313 strcpy(cfDir, topNode.path);
1314 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1316 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1321 // Default to <ProjectDir>/.configs if unset
1322 PathCatSlash(cfDir, ".configs");
1327 strcpy(temp, cfDir);
1328 // Using a relative path makes it less likely to run into spaces issues
1329 // Even with escaped spaces, there still seems to be issues including a config file
1330 // in a path containing spaces
1331 if(IsPathInsideOf(cfDir, topNode.path))
1332 MakePathRelative(temp, topNode.path, cfDir);
1334 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1338 strcpy(temp, cfDir);
1339 ReplaceSpaces(cfDir, temp);
1344 void CatMakeFileName(char * string, ProjectConfig config)
1346 char projectName[MAX_LOCATION];
1347 strcpy(projectName, name);
1348 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1351 #ifndef MAKEFILE_GENERATOR
1352 void MarkChanges(ProjectNode node)
1354 for(cfg : topNode.configurations)
1356 ProjectConfig c = null;
1357 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1359 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1360 (!c.options || !cfg.options)))
1361 cfg.symbolGenModified = true;
1362 if(c && ((c.options && cfg.options &&
1363 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1364 || (!c.options || !cfg.options)))
1365 cfg.linkingModified = true;
1367 cfg.makingModified = true;
1371 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1373 Map<String, NameCollisionInfo> cfgNameCollision;
1374 MapIterator<const String, Map<String, NameCollisionInfo>> it { map = configsNameCollisions };
1375 if(it.Index("", false))
1377 cfgNameCollision = it.data;
1378 cfgNameCollision.Free();
1379 delete cfgNameCollision;
1382 for(cfg : configurations)
1386 cfg.makingModified = true;
1387 if(it.Index(cfg.name, false))
1389 cfgNameCollision = it.data;
1390 cfgNameCollision.Free();
1391 delete cfgNameCollision;
1396 cfg.compilingModified = true;
1398 cfg.linkingModified = true;
1400 cfg.symbolGenModified = true;
1402 if(compiling || linking)
1404 ide.projectView.modifiedDocument = true;
1405 ide.workspace.modified = true;
1409 void RotateActiveConfig(bool forward, bool syncAllProjects)
1411 if(configurations.first && configurations.last != configurations.first)
1413 Iterator<ProjectConfig> cfg { configurations };
1414 while(forward ? cfg.Next() : cfg.Prev())
1415 if(cfg.data == config)
1430 ide.workspace.SelectActiveConfig(cfg.data.name);
1433 property::config = cfg.data;
1434 ide.UpdateToolBarActiveConfigs(true);
1435 ide.workspace.modified = true;
1436 ide.projectView.Update(null);
1441 bool ProcessPipeOutputRaw(DualPipe f)
1444 while(!f.Eof() && !ide.projectView.stopBuild)
1447 double lastTime = GetTime();
1451 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1453 ide.outputView.buildBox.Logf("%s\n", line);
1455 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1457 //printf("Processing Input...\n");
1458 if(app.ProcessInput(true))
1460 app.UpdateDisplay();
1463 //printf("Waiting...\n");
1466 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1468 if(ide.projectView.stopBuild)
1470 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1473 return !ide.projectView.stopBuild;
1476 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, BuildType buildType, List<ProjectNode> onlyNodes,
1477 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1481 bool compiling = false, linking = false, precompiling = false;
1482 int compilingEC = 0;
1483 int numErrors = 0, numWarnings = 0;
1484 bool loggedALine = false;
1485 int lenMakeCommand = strlen(compiler.makeCommand);
1487 const char * t, * s, * s2;
1488 char moduleName[MAX_FILENAME];
1489 const char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1491 DynamicString test { };
1492 DynamicString ecp { };
1493 DynamicString ecc { };
1494 DynamicString ecs { };
1495 DynamicString ear { };
1496 DynamicString prefix { };
1497 DynamicString cpp { };
1498 DynamicString cc { };
1499 DynamicString cxx { };
1500 DynamicString strip { };
1501 DynamicString ar { };
1502 DynamicString windres { };
1505 if(bitDepth == 64 && compiler.targetPlatform == win32)
1506 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1507 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1508 gnuToolchainPrefix = "i686-w64-mingw32-";
1510 ecp.concatx(compiler.ecpCommand, " ");
1511 ecc.concatx(compiler.eccCommand, " ");
1512 ecs.concatx(compiler.ecsCommand, " ");
1513 ear.concatx(compiler.earCommand, " ");
1516 compiler.ccacheEnabled ? "ccache " : "",
1517 compiler.distccEnabled ? "distcc " : "",
1518 gnuToolchainPrefix);
1520 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1521 cc.concatx((String)prefix, compiler.ccCommand, " ");
1522 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1524 strip.concatx(gnuToolchainPrefix, "strip ");
1525 ar.concatx(gnuToolchainPrefix, "ar rcs");
1526 windres.concatx(gnuToolchainPrefix, "windres ");
1528 testLen = Max(testLen, ecp.size);
1529 testLen = Max(testLen, ecc.size);
1530 testLen = Max(testLen, ecs.size);
1531 testLen = Max(testLen, ear.size);
1532 testLen = Max(testLen, cpp.size);
1533 testLen = Max(testLen, cc.size);
1534 testLen = Max(testLen, cxx.size);
1535 testLen = Max(testLen, strip.size);
1536 testLen = Max(testLen, ar.size);
1537 testLen = Max(testLen, windres.size);
1538 testLen = Max(testLen, strlen("mkdir "));
1541 while(!f.Eof() && !ide.projectView.stopBuild)
1543 double lastTime = GetTime();
1545 while(!f.Eof() && !ide.projectView.stopBuild)
1548 bool lineDone = f.GetLinePeek(line + linePos, sizeof(line)-linePos-1, &nChars);
1552 Sleep(0.5 / PEEK_RESOLUTION);
1559 const char * message = null;
1560 const char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1561 const char * from = strstr(line, stringFrom);
1562 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1563 if((t = strstr(line, (s=": recipe for target"))) && (t = strstr(t+strlen(s), (s2 = " failed"))) && (t+strlen(s2))[0] == '\0')
1564 ; // ignore this new gnu make error but what is it about?
1565 else if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1567 const char * module = strstr(line, "No rule to make target `");
1571 module = strchr(module, '`') + 1;
1572 end = strchr(module, '\'');
1576 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1577 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1583 //ide.outputView.buildBox.Logf("error: %s\n", line);
1587 else if(strstr(test, "mkdir ") == test);
1588 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1589 else if(strstr(test, ear) == test);
1590 else if(strstr(test, strip) == test);
1591 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1593 char * module = null;
1594 bool isPrecomp = false;
1597 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1599 module = strstr(line, " -c ");
1600 if(module) module += 4;
1603 else if(strstr(test, ecc) == test)
1605 module = strstr(line, " -c ");
1606 if(module) module += 4;
1607 //module = line + 3;
1608 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1609 compilingEC = 3;//2;
1612 else if(strstr(test, ecp) == test)
1614 // module = line + 8;
1615 module = strstr(line, " -c ");
1616 if(module) module += 4;
1627 if(!compiling && !isPrecomp)
1629 ide.outputView.buildBox.Logf($"Compiling...\n");
1632 else if(!precompiling && isPrecomp)
1634 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1635 precompiling = true;
1637 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1638 GetLastDirectory(tokens[0], moduleName);
1639 ide.outputView.buildBox.Logf("%s\n", moduleName);
1641 else if((module = strstr(line, " -o ")))
1644 precompiling = false;
1646 ide.outputView.buildBox.Logf($"Linking...\n");
1650 ide.outputView.buildBox.Logf("%s\n", line);
1651 if(strstr(line, "warning:") || strstr(line, "note:"))
1653 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1657 if(compilingEC) compilingEC--;
1659 else if(strstr(test, windres) == test)
1662 module = strstr(line, " ");
1663 if(module) module++;
1667 char * dashF = strstr(module, "-F ");
1671 while(*dashF && *dashF != ' ') dashF++;
1672 while(*dashF && *dashF == ' ') dashF++;
1675 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1676 GetLastDirectory(module, moduleName);
1677 ide.outputView.buildBox.Logf("%s\n", moduleName);
1680 else if(strstr(test, ar) == test)
1681 ide.outputView.buildBox.Logf($"Building library...\n");
1682 else if(strstr(test, ecs) == test)
1683 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1686 if(linking || compiling || precompiling)
1688 const char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1689 const char * colon = strstr(start, ":"); //, * bracket;
1690 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1691 colon = strstr(colon + 1, ":");
1694 const char * sayError = "";
1695 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1698 int len = (int)(colon - start);
1699 char ext[MAX_EXTENSION];
1700 len = Min(len, MAX_LOCATION-1);
1701 // Don't be mistaken by the drive letter colon
1703 // TODO: need to fix colon - line gives char *
1704 // warning: incompatible expression colon - line (char *); expected int
1706 strncpy(moduleName, line, (int)(colon - line));
1707 moduleName[colon - line] = '\0';
1709 strncpy(moduleName, start, len);
1710 moduleName[len] = '\0';
1711 // Remove stuff in brackets
1712 //bracket = strstr(moduleName, "(");
1713 //if(bracket) *bracket = '\0';
1715 GetLastDirectory(moduleName, temp);
1716 GetExtension(temp, ext);
1718 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1720 char * cColon = strstr(colon+1, ":");
1721 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1722 cColon = strstr(cColon + 1, ":");
1725 int len = (int)(cColon - (colon+1));
1726 char mName[MAX_LOCATION];
1727 len = Min(len, MAX_LOCATION-1);
1728 strncpy(mName, colon+1, len);
1730 GetLastDirectory(mName, temp);
1731 GetExtension(temp, ext);
1732 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1735 strcpy(moduleName, mName);
1739 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1742 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1744 message = $"Linker Message: ";
1750 message = $"Linker Error: ";
1753 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1757 if(strstr(colon, "Warning:") == colon)
1759 message = $"Linker ";
1762 else if(!strstr(line, "error:"))
1764 message = $"Linker Error: ";
1770 strcpy(temp, topNode.path);
1771 PathCatSlash(temp, moduleName);
1772 MakePathRelative(temp, topNode.path, moduleName);
1774 error = strstr(line, "error:");
1775 if(!message && error && error > colon)
1779 // Silence warnings for compiled eC
1780 //char * objDir = strstr(moduleName, objDirExp.dir);
1784 if((pointer = strstr(line, "undefined")) ||
1785 (pointer = strstr(line, "multiple definition")) ||
1786 (pointer = strstr(line, "No such file")) ||
1787 (pointer = strstr(line, "token")))
1789 strncat(moduleName, colon, pointer - colon);
1790 sayError = "error: ";
1795 else if((pointer = strstr(line, "No such file")))
1797 strncat(moduleName, colon, pointer - colon);
1798 sayError = "error: ";
1802 else //if(compilingEC == 1 || (objDir && objDir == moduleName))
1806 // Filter out these warnings caused by eC generated C code:
1808 // Declaration ordering bugs -- Awaiting topo sort implementation
1810 if(strstr(line, "declared inside parameter list")) skip = true;
1811 else if(strstr(line, "its scope is only this definition")) skip = true;
1812 else if(strstr(line, "from incompatible pointer type")) skip = true;
1813 else if(strstr(line, "note: expected 'struct ") || strstr(line, "note: expected ‘struct "))
1815 #define STRUCT_A "'struct "
1816 #define STRUCT_B "‘struct "
1817 char * struct1, * struct2, ch1, ch2;
1818 struct1 = strstr(line, STRUCT_A);
1819 if(struct1) { struct1 += sizeof(STRUCT_A)-1; } else { struct1 = strstr(line, STRUCT_B); struct1 += sizeof(STRUCT_B)-1; };
1821 struct2 = strstr(struct1, STRUCT_A);
1822 if(struct2) { struct2 += sizeof(STRUCT_A)-1; } else { struct2 = strstr(struct1, STRUCT_B); if(struct2) struct2 += sizeof(STRUCT_B)-1; };
1824 if(struct1 && struct2)
1826 while(ch1 = *(struct1++), ch2 = *(struct2++), ch1 && ch2 && (ch1 == '_' || isalnum(ch1)) && (ch2 == '_' || isalnum(ch2)));
1832 // For preprocessed code from objidl.h (MinGW-w64 headers)
1833 else if(strstr(line, "declaration does not declare anything")) skip = true;
1835 // Location information that could apply to ignored warnings
1836 else if(strstr(line, "In function '") || strstr(line, "In function ‘") ) skip = true;
1837 else if(strstr(line, "At top level")) skip = true;
1838 else if(strstr(line, "(near initialization for '") || strstr(line, "(near initialization for ‘")) skip = true;
1843 /*else if(strstr(line, "warning:"))
1849 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1850 /*else if(this == ide.workspace.projects.firstIterator.data)
1851 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1854 char fullModuleName[MAX_LOCATION];
1855 FileAttribs found = 0;
1856 //Project foundProject = this;
1859 char * loc = strstr(moduleName, ":");
1861 strcpy(fullModuleName, topNode.path);
1862 PathCat(fullModuleName, moduleName);
1863 found = FileExists(fullModuleName);
1864 if(!found && !strcmp(ext, "c"))
1866 char ecName[MAX_LOCATION];
1867 ChangeExtension(fullModuleName, "ec", ecName);
1868 found = FileExists(ecName);
1872 char path[MAX_LOCATION];
1873 if(ide && ide.workspace)
1875 for(prj : ide.workspace.projects)
1878 MakePathRelative(fullModuleName, prj.topNode.path, path);
1880 if((node = prj.topNode.FindWithPath(path, false)))
1882 strcpy(fullModuleName, prj.topNode.path);
1883 PathCatSlash(fullModuleName, node.path);
1884 PathCatSlash(fullModuleName, node.name);
1885 found = FileExists(fullModuleName);
1888 //foundProject = prj;
1893 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1895 for(prj : ide.workspace.projects)
1898 if((node = prj.topNode.Find(moduleName, false)))
1900 strcpy(fullModuleName, prj.topNode.path);
1901 PathCatSlash(fullModuleName, node.path);
1902 PathCatSlash(fullModuleName, node.name);
1903 found = FileExists(fullModuleName);
1906 //foundProject = prj;
1916 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1917 MakeSystemPath(fullModuleName);
1920 strcpy(fullModuleName, moduleName);
1923 strcat(fullModuleName, ":");
1924 strcat(fullModuleName, loc + 1);
1928 fullModuleName[0] = 0;
1929 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1934 ide.outputView.buildBox.Logf("%s\n", line);
1935 linking = compiling = precompiling = false;
1939 ide.outputView.buildBox.Logf("%s\n", line);
1944 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1946 //printf("Processing Input...\n");
1947 if(app.ProcessInput(true))
1949 app.UpdateDisplay();
1952 //printf("Waiting...\n");
1955 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1957 if(ide.projectView.stopBuild)
1959 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1962 else if(loggedALine || buildType != run)
1964 if(f.GetExitCode() && !numErrors)
1966 /*bool result = */f.GetLine(line, sizeof(line)-1);
1967 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1969 else if(buildType != install)
1973 char targetFileName[MAX_LOCATION];
1974 targetFileName[0] = '\0';
1975 CatTargetFileName(targetFileName, compiler, config);
1976 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1979 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1981 ide.outputView.buildBox.Logf($"no error, ");
1984 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1986 ide.outputView.buildBox.Logf($"no warning\n");
2003 return numErrors == 0 && !ide.projectView.stopBuild;
2006 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
2009 int lenMakeCommand = strlen(compiler.makeCommand);
2014 double lastTime = GetTime();
2017 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2019 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
2020 else if(strstr(line, "mkdir") == line);
2021 else if(strstr(line, "del") == line);
2022 else if(strstr(line, "rm") == line);
2023 else if(strstr(line, "Could Not Find") == line);
2026 ide.outputView.buildBox.Logf(line);
2027 ide.outputView.buildBox.Logf("\n");
2031 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
2033 if(app.ProcessInput(true))
2035 app.UpdateDisplay();
2038 //Sleep(1.0 / PEEK_RESOLUTION);
2042 bool Build(BuildType buildType, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2044 bool result = false;
2046 char targetFileName[MAX_LOCATION] = "";
2047 DynamicString makeTargets { };
2048 char makeFile[MAX_LOCATION];
2049 char makeFilePath[MAX_LOCATION];
2050 char configName[MAX_LOCATION];
2051 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
2052 PathBackup pathBackup { };
2053 bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
2054 const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2056 bool eC_Debug = mode.eC_ToolsDebug;
2057 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2058 int numJobs = compiler.numJobs;
2059 char command[MAX_F_STRING*4];
2060 char * compilerName = CopyString(compiler.name);
2061 Map<String, NameCollisionInfo> cfgNameCollisions;
2063 delete lastBuildConfigName;
2064 lastBuildConfigName = CopyString(config ? config.name : "Common");
2065 delete lastBuildCompilerName;
2066 lastBuildCompilerName = CopyString(compiler.name);
2067 ProjectLoadLastBuildNamesInfo(this, config);
2068 cfgNameCollisions = configsNameCollisions[config ? config.name : ""];
2070 CamelCase(compilerName);
2072 strcpy(configName, config ? config.name : "Common");
2074 SetPath(false, compiler, config, bitDepth); //true
2075 CatTargetFileName(targetFileName, compiler, config);
2077 strcpy(makeFilePath, topNode.path);
2078 CatMakeFileName(makeFile, config);
2079 PathCatSlash(makeFilePath, makeFile);
2081 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2082 if(buildType == install)
2083 makeTargets.concat(" install");
2086 if(compiler.type.isVC)
2088 PrintLn("compiling a single file is not yet supported");
2092 char pushD[MAX_LOCATION];
2093 char cfDir[MAX_LOCATION];
2094 GetIDECompilerConfigsDir(cfDir, true, true);
2095 GetWorkingDir(pushD, sizeof(pushD));
2096 ChangeWorkingDir(topNode.path);
2097 // Create object dir if it does not exist already
2098 if(!FileExists(objDirExp.dir).isDirectory)
2100 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2101 compiler.makeCommand, cfDir,
2102 crossCompiling ? " TARGET_PLATFORM=" : "",
2104 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2105 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2107 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2109 ide.outputView.buildBox.Logf("%s\n", command);
2113 ChangeWorkingDir(pushD);
2115 for(node : onlyNodes)
2117 if(node.GetIsExcluded(config))
2118 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2122 node.DeleteIntermediateFiles(compiler, config, bitDepth, cfgNameCollisions, mode == cObject ? true : false);
2123 node.GetTargets(config, cfgNameCollisions, objDirExp.dir, makeTargets);
2129 if(compiler.type.isVC)
2131 //bool result = false;
2132 char oldwd[MAX_LOCATION];
2133 GetWorkingDir(oldwd, sizeof(oldwd));
2134 ChangeWorkingDir(topNode.path);
2136 // TODO: support justPrint
2137 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2139 ide.outputView.buildBox.Logf("%s\n", command);
2140 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
2142 ProcessPipeOutputRaw(f);
2146 ChangeWorkingDir(oldwd);
2148 else if(onlyNodes && strlen(makeTargets) == 0)
2150 ide.outputView.buildBox.Log("No targets to compile.\n");
2154 GccVersionInfo ccVersion = GetGccVersionInfo(compiler, compiler.ccCommand);
2155 GccVersionInfo cxxVersion = GetGccVersionInfo(compiler, compiler.cxxCommand);
2156 char cfDir[MAX_LOCATION];
2157 GetIDECompilerConfigsDir(cfDir, true, true);
2158 sprintf(command, "%s%s %sCF_DIR=\"%s\"%s%s%s%s%s%s COMPILER=%s %s%s%s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2159 #if defined(__WIN32__)
2162 buildType == install ? "pkexec --user root " : "",
2164 compiler.makeCommand,
2165 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2167 crossCompiling ? " TARGET_PLATFORM=" : "",
2169 bitDepth ? " ARCH=" : "",
2170 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2171 ide.workspace.useValgrind ? " DISABLED_POOLING=1" : "",
2172 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2173 compilerName, eC_Debug ? "--always-make " : "",
2174 ccVersion == post4_8 ? "GCC_CC_FLAGS=-fno-diagnostics-show-caret " : "",
2175 cxxVersion == post4_8 ? "GCC_CXX_FLAGS=-fno-diagnostics-show-caret " : "",
2177 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2178 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2179 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2181 ide.outputView.buildBox.Logf("%s\n", command);
2183 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2191 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2197 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2200 ide.outputView.buildBox.Logf("%s\n", line);
2201 if(!error && !found && strstr(line, "echo ") == line && strstr(line, "ECERE_SDK_SRC"))
2203 strcpy(command, line+5);
2206 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2208 strcpy(command, line);
2218 result = ProcessPipeOutputRaw(f);
2220 result = ProcessBuildPipeOutput(f, objDirExp, buildType, onlyNodes, compiler, config, bitDepth);
2223 ide.outputView.buildBox.Logf("%s\n", command);
2224 else if(justPrint && found)
2225 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2230 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2235 delete compilerName;
2240 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2242 char makeFile[MAX_LOCATION];
2243 char makeFilePath[MAX_LOCATION];
2244 char command[MAX_LOCATION];
2245 char * compilerName;
2247 PathBackup pathBackup { };
2248 bool crossCompiling = (compiler.targetPlatform != __runtimePlatform);
2249 const char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2251 compilerName = CopyString(compiler.name);
2252 CamelCase(compilerName);
2254 SetPath(false, compiler, config, bitDepth);
2256 strcpy(makeFilePath, topNode.path);
2257 CatMakeFileName(makeFile, config);
2258 PathCatSlash(makeFilePath, makeFile);
2260 if(compiler.type.isVC)
2262 //bool result = false;
2263 char oldwd[MAX_LOCATION];
2264 GetWorkingDir(oldwd, sizeof(oldwd));
2265 ChangeWorkingDir(topNode.path);
2267 // TODO: justPrint support
2268 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2270 ide.outputView.buildBox.Logf("%s\n", command);
2271 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2273 ProcessPipeOutputRaw(f);
2277 ChangeWorkingDir(oldwd);
2282 char cfDir[MAX_LOCATION];
2283 GetIDECompilerConfigsDir(cfDir, true, true);
2284 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2285 compiler.makeCommand, cfDir,
2286 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2287 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2289 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2290 topNode.path, justPrint ? " -n": "", makeFilePath);
2292 ide.outputView.buildBox.Logf("%s\n", command);
2293 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2295 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2296 cleanType == realClean ? $"intermediate objects directory" : $"target",
2297 cleanType == clean ? $" and object files" : "");
2299 ProcessPipeOutputRaw(f);
2301 ProcessCleanPipeOutput(f, compiler, config);
2302 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2303 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2304 cleanType == clean ? $" and object files" : "");
2310 delete compilerName;
2313 void Run(const char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2315 String target = new char[maxPathLen];
2316 char oldDirectory[MAX_LOCATION];
2317 char * executableLauncher = compiler.executableLauncher;
2318 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2319 PathBackup pathBackup { };
2321 // Build(project, ideMain, true, null, false);
2323 strcpy(target, topNode.path);
2324 PathCatSlash(target, targetDirExp.dir);
2325 CatTargetFileName(target, compiler, config);
2326 sprintf(target, "%s %s", target, args);
2327 GetWorkingDir(oldDirectory, MAX_LOCATION);
2329 if(strlen(ide.workspace.debugDir))
2331 char temp[MAX_LOCATION];
2332 strcpy(temp, topNode.path);
2333 PathCatSlash(temp, ide.workspace.debugDir);
2334 ChangeWorkingDir(temp);
2337 ChangeWorkingDir(topNode.path);
2338 SetPath(true, compiler, config, bitDepth);
2339 if(executableLauncher)
2341 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 8];
2342 prefixedTarget[0] = '\0';
2343 strcat(prefixedTarget, executableLauncher);
2344 strcat(prefixedTarget, " ");
2345 strcat(prefixedTarget, target);
2346 Execute(prefixedTarget);
2347 delete prefixedTarget;
2352 ChangeWorkingDir(oldDirectory);
2355 delete targetDirExp;
2359 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2361 return Build(build, nodes, compiler, config, bitDepth, justPrint, mode);
2365 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2368 if(targetType == staticLibrary || targetType == sharedLibrary)
2369 strcat(fileName, "$(LP)");
2370 strcat(fileName, GetTargetFileName(config));
2374 strcat(fileName, "$(E)");
2377 strcat(fileName, "$(SO)$(VER)");
2380 strcat(fileName, "$(A)");
2385 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2387 bool result = false;
2388 char path[MAX_LOCATION];
2390 if(!GetProjectCompilerConfigsDir(path, false, false))
2391 GetIDECompilerConfigsDir(path, false, false);
2393 if(!FileExists(path).isDirectory)
2397 char dirName[MAX_FILENAME];
2398 GetLastDirectory(path, dirName);
2399 if(!strcmp(dirName, ".configs"))
2400 FileSetAttribs(path, FileAttribs { isHidden = true });
2403 PathCatSlash(path, "crossplatform.mk");
2405 if(FileExists(path))
2408 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2411 File f = FileOpen(path, write);
2414 include.Seek(0, start);
2415 for(; !include.Eof(); )
2418 int count = include.Read(buffer, 1, 4096);
2419 f.Write(buffer, 1, count);
2425 if(!altCrossPlatformMk)
2432 bool GenerateCompilerCf(CompilerConfig compiler, bool eC)
2434 bool result = false;
2435 char path[MAX_LOCATION];
2437 char * compilerName;
2438 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2439 const char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2440 Platform platform = compiler.targetPlatform;
2442 compilerName = CopyString(compiler.name);
2443 CamelCase(compilerName);
2444 name = PrintString(platform, "-", compilerName, ".cf");
2446 if(!GetProjectCompilerConfigsDir(path, false, false))
2447 GetIDECompilerConfigsDir(path, false, false);
2449 if(!FileExists(path).isDirectory)
2453 char dirName[MAX_FILENAME];
2454 GetLastDirectory(path, dirName);
2455 if(!strcmp(dirName, ".configs"))
2456 FileSetAttribs(path, FileAttribs { isHidden = true });
2459 PathCatSlash(path, name);
2461 if(FileExists(path))
2464 File f = FileOpen(path, write);
2467 if(compiler.environmentVars && compiler.environmentVars.count)
2469 f.Puts("# ENVIRONMENT VARIABLES\n");
2471 for(e : compiler.environmentVars)
2473 f.Printf("export %s := %s\n", e.name, e.string);
2478 f.Puts("# TOOLCHAIN\n");
2481 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2483 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2486 if(compiler.sysroot && compiler.sysroot[0])
2488 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2489 // Moved this to crossplatform.mk
2490 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2494 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2495 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2496 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)\n", compiler.ccCommand);
2497 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CXX_FLAGS),$(space)$(GCC_CXX_FLAGS),)\n", compiler.cxxCommand);
2500 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);
2501 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);
2502 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);
2506 f.Printf("ECP := %s\n", compiler.ecpCommand);
2507 f.Printf("ECC := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2508 f.Printf("ECS := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)$(if $(DISABLED_POOLING), -disabled-pooling,)\n", compiler.ecsCommand);
2510 f.Printf("EAR := %s\n", compiler.earCommand);
2512 f.Puts("AS := $(GCC_PREFIX)as\n");
2513 f.Puts("LD := $(GCC_PREFIX)ld\n");
2514 f.Puts("AR := $(GCC_PREFIX)ar\n");
2515 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2516 f.Puts("ifdef WINDOWS_TARGET\n");
2517 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2518 f.Puts(" ifdef ARCH\n");
2519 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2520 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2522 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2523 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2528 f.Puts("UPX := upx\n");
2531 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2534 f.Puts("EARFLAGS = \n");
2537 f.Puts("ifndef ARCH\n");
2538 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2539 f.Puts(" ifdef WINDOWS_HOST\n");
2540 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2541 f.Puts(" TARGET_ARCH := x86_64\n");
2543 f.Puts(" TARGET_ARCH := i386\n");
2546 f.Puts("endif\n\n");
2548 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2549 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2553 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2557 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2560 if(compiler.includeDirs && compiler.includeDirs.count)
2562 f.Puts("\nCFLAGS +=");
2563 OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
2566 if(compiler.prepDirectives && compiler.prepDirectives.count)
2568 f.Puts("\nCFLAGS +=");
2569 OutputFlags(f, _D, compiler.prepDirectives, inPlace);
2572 if(compiler.libraryDirs && compiler.libraryDirs.count)
2574 f.Puts("\nLDFLAGS +=");
2575 OutputFlags(f, _L, compiler.libraryDirs, lineEach);
2576 // We would need a bool option to know whether we want to add to rpath as well...
2577 // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
2580 if(compiler.excludeLibs && compiler.excludeLibs.count)
2582 f.Puts("\nEXCLUDED_LIBS =");
2583 for(l : compiler.excludeLibs)
2589 if(compiler.eCcompilerFlags && compiler.eCcompilerFlags.count)
2591 f.Puts("\nECFLAGS +=");
2592 OutputFlags(f, any, compiler.eCcompilerFlags, inPlace);
2595 if(compiler.compilerFlags && compiler.compilerFlags.count)
2597 f.Puts("\nCFLAGS +=");
2598 OutputFlags(f, any, compiler.compilerFlags, inPlace);
2601 if(compiler.linkerFlags && compiler.linkerFlags.count)
2603 f.Puts("\nLDFLAGS +=");
2604 OutputFlags(f, _Wl, compiler.linkerFlags, inPlace);
2608 f.Puts("\nOFLAGS += $(LDFLAGS)");
2610 f.Puts("ifdef ARCH_FLAGS\n");
2611 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2612 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2621 delete compilerName;
2625 bool GenerateMakefile(const char * altMakefilePath, bool noResources, const char * includemkPath, ProjectConfig config)
2627 bool result = false;
2628 char filePath[MAX_LOCATION];
2629 char makeFile[MAX_LOCATION];
2630 // PathBackup pathBackup { };
2631 // char oldDirectory[MAX_LOCATION];
2634 if(!altMakefilePath)
2636 strcpy(filePath, topNode.path);
2637 CatMakeFileName(makeFile, config);
2638 PathCatSlash(filePath, makeFile);
2641 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2643 /*SetPath(false, compiler, config);
2644 GetWorkingDir(oldDirectory, MAX_LOCATION);
2645 ChangeWorkingDir(topNode.path);*/
2652 char targetDir[MAX_LOCATION];
2653 char objDirExpNoSpaces[MAX_LOCATION];
2654 char objDirNoSpaces[MAX_LOCATION];
2655 char resDirNoSpaces[MAX_LOCATION];
2656 char targetDirExpNoSpaces[MAX_LOCATION];
2657 char fixedModuleName[MAX_FILENAME];
2658 char fixedConfigName[MAX_FILENAME];
2660 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2661 // Non-zero if we're building eC code
2662 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2663 int numCObjects = 0;
2665 int numRCObjects = 0;
2666 bool containsCXX = false; // True if the project contains a C++ file
2667 bool relObjDir, sameOrRelObjTargetDirs;
2668 const String objDirExp = GetObjDirExpression(config);
2669 TargetTypes targetType = GetTargetType(config);
2671 char cfDir[MAX_LOCATION];
2672 int objectsParts = 0;
2673 int eCsourcesParts = 0;
2674 int rcSourcesParts = 0;
2675 Array<String> listItems { };
2676 Map<String, int> varStringLenDiffs { };
2677 Map<String, NameCollisionInfo> namesInfo { };
2679 Map<String, int> cflagsVariations { };
2680 Map<intptr, int> nodeCFlagsMapping { };
2682 Map<String, int> ecflagsVariations { };
2683 Map<intptr, int> nodeECFlagsMapping { };
2685 ReplaceSpaces(objDirNoSpaces, objDirExp);
2686 strcpy(targetDir, GetTargetDirExpression(config));
2687 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2689 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2690 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2692 char temp[MAX_LOCATION];
2693 ReplaceSpaces(temp, objDirExpNoSpaces);
2694 strcpy(objDirExpNoSpaces, temp);
2696 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2697 ReplaceSpaces(fixedModuleName, moduleName);
2698 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2699 CamelCase(fixedConfigName);
2701 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2702 relObjDir = lenObjDirExpNoSpaces == 0 ||
2703 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2704 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2705 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2706 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2707 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2709 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2711 f.Puts("# CORE VARIABLES\n\n");
2713 f.Printf("MODULE := %s\n", fixedModuleName);
2714 f.Printf("VERSION := %s\n", property::moduleVersion);
2715 f.Printf("CONFIG := %s\n", fixedConfigName);
2716 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2719 test = GetTargetTypeIsSetByPlatform(config);
2723 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2725 TargetTypes targetType;
2726 PlatformOptions projectPOs, configPOs;
2727 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2728 targetType = platformTargetType;
2734 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2735 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2740 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2745 for(c = 0; c < ifCount; c++)
2751 f.Puts("# FLAGS\n\n");
2753 f.Puts("ECFLAGS =\n");
2754 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2755 f.Puts("PRJ_CFLAGS =\n");
2756 f.Puts("CECFLAGS =\n");
2757 f.Puts("OFLAGS =\n");
2761 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2764 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2765 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2766 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2767 //f.Puts("endif\n");
2770 f.Puts("# INCLUDES\n\n");
2772 if(compilerConfigsDir && compilerConfigsDir[0])
2774 strcpy(cfDir, compilerConfigsDir);
2775 if(cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2780 GetIDECompilerConfigsDir(cfDir, true, true);
2781 // Use CF_DIR environment variable for absolute paths only
2782 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2783 strcpy(cfDir, "$(CF_DIR)");
2786 f.Printf("_CF_DIR = %s\n", cfDir);
2789 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2790 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2793 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2795 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2798 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2801 // test = GetTargetTypeIsSetByPlatform(config);
2803 char target[MAX_LOCATION];
2804 char temp[MAX_LOCATION];
2809 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2811 if(type != targetType)
2816 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2818 GetMakefileTargetFileName(type, target, config);
2819 strcpy(temp, targetDir);
2820 PathCatSlash(temp, target);
2821 ReplaceSpaces(target, temp);
2822 f.Printf("TARGET = %s\n", target);
2827 GetMakefileTargetFileName(targetType, target, config);
2828 strcpy(temp, targetDir);
2829 PathCatSlash(temp, target);
2830 ReplaceSpaces(target, temp);
2831 f.Printf("TARGET = %s\n", target);
2837 for(c = 0; c < ifCount; c++)
2844 // Use something fixed here, to not cause Makefile differences across compilers...
2845 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2846 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2848 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2852 const char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2854 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2857 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2859 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2860 if(eCsourcesParts > 1)
2862 for(c = 1; c <= eCsourcesParts; c++)
2863 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2867 for(c = 0; c < 5; c++)
2869 if(eCsourcesParts > 1)
2872 f.Printf("_%s =", map[c][0]);
2873 for(n = 1; n <= eCsourcesParts; n++)
2874 f.Printf(" $(%s%d)", map[c][0], n);
2876 for(n = 1; n <= eCsourcesParts; n++)
2877 f.Printf("_%s%d = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d))))\n", map[c][0], n, map[c][1], n);
2879 else if(eCsourcesParts == 1)
2880 f.Printf("_%s = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES))))\n", map[c][0], map[c][1]);
2884 for(c = 0; c < 5; c++)
2886 if(eCsourcesParts > 1)
2889 f.Printf("%s =", map[c][0]);
2890 for(n = 1; n <= eCsourcesParts; n++)
2891 f.Printf(" $(%s%d)", map[c][0], n);
2893 for(n = 1; n <= eCsourcesParts; n++)
2894 f.Printf("%s%d = $(call shwspace,$(_%s%d))\n", map[c][0], n, map[c][0], n);
2896 else if(eCsourcesParts == 1)
2897 f.Printf("%s = $(call shwspace,$(_%s))\n", map[c][0], map[c][0]);
2903 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2906 f.Puts("ifdef WINDOWS_TARGET\n\n");
2908 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2910 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2911 if(rcSourcesParts > 1)
2913 for(c = 1; c <= rcSourcesParts; c++)
2914 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2917 if(rcSourcesParts > 1)
2920 f.Printf("%s =", "RCOBJECTS");
2921 for(n = 1; n <= rcSourcesParts; n++)
2922 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2924 for(n = 1; n <= rcSourcesParts; n++)
2925 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2927 else if(rcSourcesParts == 1)
2928 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2932 f.Puts("RCSOURCES =\n");
2933 f.Puts("RCOBJECTS =\n");
2934 f.Puts("endif\n\n");
2937 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2939 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2940 f.Printf("OBJECTS =%s%s%s%s\n",
2941 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2942 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2943 numRCObjects ? " $(RCOBJECTS)" : "");
2946 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2948 const char * prefix;
2949 if(numCObjects && numRCObjects)
2950 prefix = "$(ECSOURCES) $(RCSOURCES)";
2951 else if(numCObjects)
2952 prefix = "$(ECSOURCES)";
2955 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2959 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2960 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2962 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2964 if((config && config.options && config.options.libraries) ||
2965 (options && options.libraries))
2967 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2969 if(config && config.options && config.options.libraries)
2970 OutputLibraries(f, config.options.libraries);
2971 else if(options && options.libraries)
2972 OutputLibraries(f, options.libraries);
2978 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects != 0,
2979 cflagsVariations, nodeCFlagsMapping,
2980 ecflagsVariations, nodeECFlagsMapping, null);
2982 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2983 f.Puts("ECFLAGS += -module $(MODULE)\n");
2984 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2986 if(platforms || (config && config.platforms))
2989 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2990 //for(platform = win32; platform <= apple; platform++)
2992 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2993 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2995 PlatformOptions projectPlatformOptions, configPlatformOptions;
2996 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2998 if(projectPlatformOptions || configPlatformOptions)
3003 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3006 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
3007 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
3009 f.Puts("CFLAGS +=");
3010 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
3013 for(s : projectPlatformOptions.options.compilerOptions)
3016 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
3019 for(s : configPlatformOptions.options.compilerOptions)
3026 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
3027 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
3029 f.Puts("OFLAGS +=");
3030 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
3032 bool needWl = false;
3034 for(s : projectPlatformOptions.options.linkerOptions)
3036 if(!IsLinkerOption(s))
3044 for(s : projectPlatformOptions.options.linkerOptions)
3045 if(IsLinkerOption(s))
3049 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
3051 bool needWl = false;
3053 for(s : configPlatformOptions.options.linkerOptions)
3055 if(IsLinkerOption(s))
3063 for(s : configPlatformOptions.options.linkerOptions)
3064 if(!IsLinkerOption(s))
3072 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3073 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
3074 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
3075 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
3077 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3078 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3079 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
3081 f.Puts("OFLAGS +=");
3082 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
3083 OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
3084 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
3085 OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
3089 if(configPlatformOptions && configPlatformOptions.options.libraries)
3091 if(configPlatformOptions.options.libraries.count)
3094 OutputLibraries(f, configPlatformOptions.options.libraries);
3098 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3100 if(projectPlatformOptions.options.libraries.count)
3103 OutputLibraries(f, projectPlatformOptions.options.libraries);
3114 for(c = 0; c < ifCount; c++)
3120 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3121 (options && options.compilerOptions && options.compilerOptions.count))
3123 f.Puts("CFLAGS +=");
3126 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3128 for(s : config.options.compilerOptions)
3131 if(options && options.compilerOptions && options.compilerOptions.count)
3133 for(s : options.compilerOptions)
3140 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3141 (options && options.linkerOptions && options.linkerOptions.count))
3143 f.Puts("OFLAGS +=");
3146 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3148 bool needWl = false;
3149 for(s : config.options.linkerOptions)
3151 if(!IsLinkerOption(s))
3159 for(s : config.options.linkerOptions)
3160 if(IsLinkerOption(s))
3164 if(options && options.linkerOptions && options.linkerOptions.count)
3166 bool needWl = false;
3167 for(s : options.linkerOptions)
3169 if(!IsLinkerOption(s))
3177 for(s : options.linkerOptions)
3178 if(IsLinkerOption(s))
3186 f.Puts("CECFLAGS += -cpp $(_CPP)");
3190 if(GetProfile(config))
3191 f.Puts("OFLAGS += -pg\n\n");
3193 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3195 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3196 f.Puts("OFLAGS +=");
3197 if(config && config.options && config.options.libraryDirs)
3198 OutputFlags(f, _L, config.options.libraryDirs, lineEach);
3199 if(options && options.libraryDirs)
3200 OutputFlags(f, _L, options.libraryDirs, lineEach);
3206 f.Puts("# TARGETS\n");
3209 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3212 f.Puts("objdir:\n");
3214 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3217 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");
3218 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");
3220 //f.Puts("# PRE-BUILD COMMANDS\n");
3221 if(options && options.prebuildCommands)
3223 for(s : options.prebuildCommands)
3224 if(s && s[0]) f.Printf("\t%s\n", s);
3226 if(config && config.options && config.options.prebuildCommands)
3228 for(s : config.options.prebuildCommands)
3229 if(s && s[0]) f.Printf("\t%s\n", s);
3231 if(platforms || (config && config.platforms))
3234 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3235 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3237 PlatformOptions projectPOs, configPOs;
3238 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3240 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3241 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3246 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3248 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3250 for(s : projectPOs.options.prebuildCommands)
3251 if(s && s[0]) f.Printf("\t%s\n", s);
3253 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3255 for(s : configPOs.options.prebuildCommands)
3256 if(s && s[0]) f.Printf("\t%s\n", s);
3263 for(c = 0; c < ifCount; c++)
3269 if(!sameOrRelObjTargetDirs)
3271 f.Puts("targetdir:\n");
3272 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3278 // Main Module (Linking) for ECERE C modules
3279 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3280 f.Printf("\t@$(call rmq,$(OBJ)symbols.lst)\n");
3281 f.Printf("\t@$(call touch,$(OBJ)symbols.lst)\n");
3282 OutputFileListActions(f, "SYMBOLS", eCsourcesParts, "$(OBJ)symbols.lst");
3283 OutputFileListActions(f, "IMPORTS", eCsourcesParts, "$(OBJ)symbols.lst");
3284 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3285 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) @$(OBJ)symbols.lst -symbols %s -o $(call quote_path,$@)\n",
3286 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3288 // Main Module (Linking) for ECERE C modules
3289 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3290 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3291 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3292 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3293 " -c $(OBJ)$(MODULE).main.ec -o $(call quote_path,$@) -symbols $(OBJ)\n");
3299 // This would not rebuild the target on updated objects
3300 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3302 // This should fix it for good!
3303 f.Puts("$(SYMBOLS): | objdir\n");
3304 f.Puts("$(OBJECTS): | objdir\n");
3306 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3307 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3308 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3310 f.Printf("\t@$(call rmq,$(OBJ)objects.lst)\n");
3311 f.Printf("\t@$(call touch,$(OBJ)objects.lst)\n");
3312 OutputFileListActions(f, "_OBJECTS", objectsParts, "$(OBJ)objects.lst");
3315 f.Puts("ifdef WINDOWS_TARGET\n");
3316 OutputFileListActions(f, "RCOBJECTS", rcSourcesParts, "$(OBJ)objects.lst");
3321 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)objects.lst\n");
3322 OutputFileListActions(f, "ECOBJECTS", eCsourcesParts, "$(OBJ)objects.lst");
3325 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3327 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)objects.lst $(LIBS) -o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC");
3328 if(!GetDebug(config))
3330 f.Puts("ifndef NOSTRIP\n");
3331 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3334 if(GetCompress(config))
3336 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3337 f.Puts("ifdef EXECUTABLE_TARGET\n");
3338 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3341 //f.Puts("ifneq \"$(TARGET_ARCH)\" \"x86_64\"\n");
3342 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3343 //f.Puts("endif\n");
3347 if(resNode.files && resNode.files.count && !noResources)
3348 resNode.GenMakefileAddResources(f, resNode.path, config);
3350 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)objects.lst $(LIBS)\n");
3352 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3353 f.Puts("ifdef LINUX_TARGET\n");
3354 f.Puts("ifdef LINUX_HOST\n");
3355 // TODO?: support symlinks for longer version numbers
3356 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3357 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3362 //f.Puts("# POST-BUILD COMMANDS\n");
3363 if(options && options.postbuildCommands)
3365 for(s : options.postbuildCommands)
3366 if(s && s[0]) f.Printf("\t%s\n", s);
3368 if(config && config.options && config.options.postbuildCommands)
3370 for(s : config.options.postbuildCommands)
3371 if(s && s[0]) f.Printf("\t%s\n", s);
3373 if(platforms || (config && config.platforms))
3376 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3377 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3379 PlatformOptions projectPOs, configPOs;
3380 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3382 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3383 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3388 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3390 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3392 for(s : projectPOs.options.postbuildCommands)
3393 if(s && s[0]) f.Printf("\t%s\n", s);
3395 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3397 for(s : configPOs.options.postbuildCommands)
3398 if(s && s[0]) f.Printf("\t%s\n", s);
3405 for(c = 0; c < ifCount; c++)
3412 if(platforms || (config && config.platforms))
3414 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3416 PlatformOptions projectPOs, configPOs;
3417 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3419 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3420 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3427 if(test || (options && options.installCommands) ||
3428 (config && config.options && config.options.installCommands))
3430 f.Puts("install:\n");
3431 if(options && options.installCommands)
3433 for(s : options.installCommands)
3434 if(s && s[0]) f.Printf("\t%s\n", s);
3436 if(config && config.options && config.options.installCommands)
3438 for(s : config.options.installCommands)
3439 if(s && s[0]) f.Printf("\t%s\n", s);
3441 if(platforms || (config && config.platforms))
3444 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3446 PlatformOptions projectPOs, configPOs;
3447 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3449 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3450 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3455 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3457 if(projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count)
3459 for(s : projectPOs.options.installCommands)
3460 if(s && s[0]) f.Printf("\t%s\n", s);
3462 if(configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count)
3464 for(s : configPOs.options.installCommands)
3465 if(s && s[0]) f.Printf("\t%s\n", s);
3472 for(c = 0; c < ifCount; c++)
3479 f.Puts("# SYMBOL RULES\n");
3482 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3484 f.Puts("# C OBJECT RULES\n");
3487 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3489 f.Puts("# OBJECT RULES\n");
3491 // todo call this still but only generate rules whith specific options
3492 // see we-have-file-specific-options in ProjectNode.ec
3493 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3496 GenMakefilePrintMainObjectRule(f, config);
3498 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3501 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)");
3502 f.Printf("\t$(call rmq,$(OBJ)symbols.lst)\n");
3504 f.Printf("\t$(call rmq,$(OBJ)objects.lst)\n");
3505 f.Puts("\t$(call rmq,$(TARGET))\n");
3506 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3507 f.Puts("ifdef LINUX_TARGET\n");
3508 f.Puts("ifdef LINUX_HOST\n");
3509 // TODO?: support symlinks for longer version numbers
3510 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3511 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3517 f.Puts("clean: cleantarget\n");
3518 OutputCleanActions(f, "OBJECTS", objectsParts);
3521 f.Puts("ifdef WINDOWS_TARGET\n");
3522 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3527 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3528 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3529 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3530 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3531 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3535 f.Puts("realclean: cleantarget\n");
3536 f.Puts("\t$(call rmrq,$(OBJ))\n");
3537 if(!sameOrRelObjTargetDirs)
3538 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3541 f.Puts("distclean: cleantarget\n");
3542 if(!sameOrRelObjTargetDirs)
3543 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3545 f.Puts("\t$(call rmrq,obj/)\n");
3551 varStringLenDiffs.Free();
3552 delete varStringLenDiffs;
3556 delete cflagsVariations;
3557 delete nodeCFlagsMapping;
3558 delete ecflagsVariations;
3559 delete nodeECFlagsMapping;
3564 // ChangeWorkingDir(oldDirectory);
3565 // delete pathBackup;
3568 config.makingModified = false;
3572 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3574 char extension[MAX_EXTENSION] = "c";
3575 //char modulePath[MAX_LOCATION];
3576 char fixedModuleName[MAX_FILENAME];
3578 //char command[2048];
3579 char objDirNoSpaces[MAX_LOCATION];
3580 const String objDirExp = GetObjDirExpression(config);
3582 ReplaceSpaces(objDirNoSpaces, objDirExp);
3583 ReplaceSpaces(fixedModuleName, moduleName);
3585 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3586 //strcat(fixedModuleName, ".main");
3588 #if 0 // TODO: Fix nospaces stuff
3589 // *** Dependency command ***
3590 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3592 // System Includes (from global settings)
3593 for(item : compiler.dirs[Includes])
3595 strcat(command, " -isystem ");
3596 if(strchr(item.name, ' '))
3598 strcat(command, "\"");
3599 strcat(command, item);
3600 strcat(command, "\"");
3603 strcat(command, item);
3606 for(item = includeDirs.first; item; item = item.next)
3608 strcat(command, " -I");
3609 if(strchr(item.name, ' '))
3611 strcat(command, "\"");
3612 strcat(command, item.name);
3613 strcat(command, "\"");
3616 strcat(command, item.name);
3618 for(item = preprocessorDefs.first; item; item = item.next)
3620 strcat(command, " -D");
3621 strcat(command, item.name);
3625 if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
3629 bool firstLine = true;
3631 // To do some time: auto save external dependencies?
3634 if(dep.GetLine(line, sizeof(line)-1))
3638 char * colon = strstr(line, ":");
3639 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3653 // If we failed to generate dependencies...
3657 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3658 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(call quote_path,$@)\n", extension);
3666 void GenMakePrintCustomFlags(File f, const String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3669 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3671 for(v : cflagsVariations)
3676 f.Printf("%s +=", variableName);
3678 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3679 f.Puts(&v ? &v : "");
3687 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3688 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3690 *projectPlatformOptions = null;
3691 *configPlatformOptions = null;
3696 if(!strcmpi(p.name, platform))
3698 *projectPlatformOptions = p;
3703 if(config && config.platforms)
3705 for(p : config.platforms)
3707 if(!strcmpi(p.name, platform))
3709 *configPlatformOptions = p;
3717 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3719 const char * cfgName = cfg ? cfg.name : "";
3720 Map<String, NameCollisionInfo> cfgNameCollisions = prj.configsNameCollisions[cfgName];
3721 if(cfgNameCollisions)
3723 cfgNameCollisions.Free();
3724 delete cfgNameCollisions;
3726 prj.configsNameCollisions[cfgName] = cfgNameCollisions = { };
3727 prj.topNode.GenMakefileGetNameCollisionInfo(cfgNameCollisions, cfg);
3730 Project LegacyBinaryLoadProject(File f, const char * filePath)
3732 Project project = null;
3733 char signature[sizeof(epjSignature)];
3735 f.Read(signature, sizeof(signature), 1);
3736 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3738 char topNodePath[MAX_LOCATION];
3739 /*ProjectConfig newConfig
3741 name = CopyString("Default");
3742 makingModified = true;
3743 compilingModified = true;
3744 linkingModified = true;
3748 project = Project { options = { } };
3749 LegacyBinaryLoadNode(project.topNode, f);
3750 delete project.topNode.path;
3751 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3752 MakeSlashPath(topNodePath);
3754 PathCatSlash(topNodePath, filePath);
3755 project.filePath = topNodePath;
3757 /* THIS IS ALREADY DONE BY filePath property
3758 StripLastDirectory(topNodePath, topNodePath);
3759 project.topNode.path = CopyString(topNodePath);
3761 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3763 // newConfig.options.defaultNameSpace = "";
3764 /*newConfig.objDir.dir = "obj";
3765 newConfig.targetDir.dir = "";*/
3767 //project.configurations = { [ newConfig ] };
3768 //project.config = newConfig;
3775 String targetFileName, targetDirectory, objectsDirectory;
3777 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3778 f.Read(&temp, sizeof(int),1);
3781 case 0: project.options.targetType = executable; break;
3782 case 1: project.options.targetType = sharedLibrary; break;
3783 case 2: project.options.targetType = staticLibrary; break;
3786 f.Read(&len, sizeof(int),1);
3787 targetFileName = new char[len+1];
3788 f.Read(targetFileName, sizeof(char), len+1);
3789 project.options.targetFileName = targetFileName;
3790 delete targetFileName;
3792 f.Read(&len, sizeof(int),1);
3793 targetDirectory = new char[len+1];
3794 f.Read(targetDirectory, sizeof(char), len+1);
3795 project.options.targetDirectory = targetDirectory;
3796 delete targetDirectory;
3798 f.Read(&len, sizeof(int),1);
3799 objectsDirectory = new byte[len+1];
3800 f.Read(objectsDirectory, sizeof(char), len+1);
3801 project.options.objectsDirectory = objectsDirectory;
3802 delete objectsDirectory;
3804 f.Read(&temp, sizeof(int),1);
3805 project./*config.*/options.debug = temp ? true : false;
3806 f.Read(&temp, sizeof(int),1);
3807 project./*config.*/options.optimization = temp ? speed : none;
3808 f.Read(&temp, sizeof(int),1);
3809 project./*config.*/options.profile = temp ? true : false;
3810 f.Read(&temp, sizeof(int),1);
3811 project.options.warnings = temp ? all : unset;
3813 f.Read(&count, sizeof(int),1);
3816 project.options.includeDirs = { };
3817 for(c = 0; c < count; c++)
3820 f.Read(&len, sizeof(int),1);
3821 name = new char[len+1];
3822 f.Read(name, sizeof(char), len+1);
3823 project.options.includeDirs.Add(name);
3827 f.Read(&count, sizeof(int),1);
3830 project.options.libraryDirs = { };
3831 for(c = 0; c < count; c++)
3834 f.Read(&len, sizeof(int),1);
3835 name = new char[len+1];
3836 f.Read(name, sizeof(char), len+1);
3837 project.options.libraryDirs.Add(name);
3841 f.Read(&count, sizeof(int),1);
3844 project.options.libraries = { };
3845 for(c = 0; c < count; c++)
3848 f.Read(&len, sizeof(int),1);
3849 name = new char[len+1];
3850 f.Read(name, sizeof(char), len+1);
3851 project.options.libraries.Add(name);
3855 f.Read(&count, sizeof(int),1);
3858 project.options.preprocessorDefinitions = { };
3859 for(c = 0; c < count; c++)
3862 f.Read(&len, sizeof(int),1);
3863 name = new char[len+1];
3864 f.Read(name, sizeof(char), len+1);
3865 project.options.preprocessorDefinitions.Add(name);
3869 f.Read(&temp, sizeof(int),1);
3870 project.options.console = temp ? true : false;
3873 for(node : project.topNode.files)
3875 if(node.type == resources)
3877 project.resNode = node;
3887 void ProjectConfig::LegacyProjectConfigLoad(File f)
3895 char subSection[128];
3900 f.GetLine(buffer, 65536 - 1);
3901 TrimLSpaces(buffer, buffer);
3902 TrimRSpaces(buffer, buffer);
3905 if(buffer[0] == '-')
3909 TrimLSpaces(equal, equal);
3910 if(!strcmpi(subSection, "LibraryDirs"))
3912 if(!options.libraryDirs)
3913 options.libraryDirs = { [ CopyString(equal) ] };
3915 options.libraryDirs.Add(CopyString(equal));
3917 else if(!strcmpi(subSection, "IncludeDirs"))
3919 if(!options.includeDirs)
3920 options.includeDirs = { [ CopyString(equal) ] };
3922 options.includeDirs.Add(CopyString(equal));
3925 else if(buffer[0] == '+')
3936 TrimLSpaces(equal, equal);
3937 delete name; name = CopyString(equal); // property::name = equal;
3940 else if(!strcmpi(buffer, "Compiler Options"))
3941 strcpy(section, buffer);
3942 else if(!strcmpi(buffer, "IncludeDirs"))
3943 strcpy(subSection, buffer);
3944 else if(!strcmpi(buffer, "Linker Options"))
3945 strcpy(section, buffer);
3946 else if(!strcmpi(buffer, "LibraryDirs"))
3947 strcpy(subSection, buffer);
3948 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3955 equal = strstr(buffer, "=");
3959 TrimRSpaces(buffer, buffer);
3961 TrimLSpaces(equal, equal);
3962 if(!strcmpi(buffer, "Target Name"))
3963 options.targetFileName = /*CopyString(*/equal/*)*/;
3964 else if(!strcmpi(buffer, "Target Type"))
3966 if(!strcmpi(equal, "Executable"))
3967 options.targetType = executable;
3968 else if(!strcmpi(equal, "Shared"))
3969 options.targetType = sharedLibrary;
3970 else if(!strcmpi(equal, "Static"))
3971 options.targetType = staticLibrary;
3973 options.targetType = executable;
3975 else if(!strcmpi(buffer, "Target Directory"))
3976 options.targetDirectory = /*CopyString(*/equal/*)*/;
3977 else if(!strcmpi(buffer, "Console"))
3978 options.console = ParseTrueFalseValue(equal);
3979 else if(!strcmpi(buffer, "Libraries"))
3981 if(!options.libraries) options.libraries = { };
3982 ParseArrayValue(options.libraries, equal);
3984 else if(!strcmpi(buffer, "Intermediate Directory"))
3985 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3986 else if(!strcmpi(buffer, "Debug"))
3987 options.debug = ParseTrueFalseValue(equal);
3988 else if(!strcmpi(buffer, "Optimize"))
3990 if(!strcmpi(equal, "None"))
3991 options.optimization = none;
3992 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3993 options.optimization = speed;
3994 else if(!strcmpi(equal, "Size"))
3995 options.optimization = size;
3997 options.optimization = none;
3999 else if(!strcmpi(buffer, "Compress"))
4000 options.compress = ParseTrueFalseValue(equal);
4001 else if(!strcmpi(buffer, "Profile"))
4002 options.profile = ParseTrueFalseValue(equal);
4003 else if(!strcmpi(buffer, "AllWarnings"))
4004 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4005 else if(!strcmpi(buffer, "MemoryGuard"))
4006 options.memoryGuard = ParseTrueFalseValue(equal);
4007 else if(!strcmpi(buffer, "Default Name Space"))
4008 options.defaultNameSpace = CopyString(equal);
4009 else if(!strcmpi(buffer, "Strict Name Spaces"))
4010 options.strictNameSpaces = ParseTrueFalseValue(equal);
4011 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4013 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
4014 ParseArrayValue(options.preprocessorDefinitions, equal);
4020 if(!options.targetDirectory && options.objectsDirectory)
4021 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
4022 //if(!objDir.dir) objDir.dir = "obj";
4023 //if(!targetDir.dir) targetDir.dir = "";
4024 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
4025 // if(!defaultNameSpace) property::defaultNameSpace = "";
4026 makingModified = true;
4029 Project LegacyAsciiLoadProject(File f, const char * filePath)
4031 Project project = null;
4033 char parentPath[MAX_LOCATION];
4034 char section[128] = "";
4035 char subSection[128] = "";
4036 ProjectNode parent = null;
4037 bool configurationsPresent = false;
4047 f.GetLine(buffer, 65536 - 1);
4048 TrimLSpaces(buffer, buffer);
4049 TrimRSpaces(buffer, buffer);
4052 if(buffer[0] == '-' || buffer[0] == '=')
4054 bool simple = buffer[0] == '-';
4057 TrimLSpaces(equal, equal);
4058 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
4060 if(!project.config.options.libraryDirs)
4061 project.config.options.libraryDirs = { [ CopyString(equal) ] };
4063 project.config.options.libraryDirs.Add(CopyString(equal));
4065 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
4067 if(!project.config.options.includeDirs)
4068 project.config.options.includeDirs = { [ CopyString(equal) ] };
4070 project.config.options.includeDirs.Add(CopyString(equal));
4072 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4074 len = strlen(equal);
4077 char temp[MAX_LOCATION];
4078 ProjectNode child { };
4079 // We don't need to do this anymore, fileName is just a property that sets name & path
4080 // child.fileName = CopyString(equal);
4083 child.name = CopyString(equal);
4084 child.path = CopyString(parentPath);
4088 GetLastDirectory(equal, temp);
4089 child.name = CopyString(temp);
4090 StripLastDirectory(equal, temp);
4091 child.path = CopyString(temp);
4093 child.nodeType = file;
4094 child.parent = parent;
4095 child.indent = parent.indent + 1;
4097 child.icon = NodeIcons::SelectFileIcon(child.name);
4098 parent.files.Add(child);
4104 StripLastDirectory(parentPath, parentPath);
4105 parent = parent.parent;
4109 else if(buffer[0] == '+')
4113 TrimLSpaces(equal, equal);
4114 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4116 char temp[MAX_LOCATION];
4117 ProjectNode child { };
4118 // NEW: Folders now have a path set like files
4119 child.name = CopyString(equal);
4120 strcpy(temp, parentPath);
4121 PathCatSlash(temp, child.name);
4122 child.path = CopyString(temp);
4124 child.parent = parent;
4125 child.indent = parent.indent + 1;
4126 child.type = folder;
4127 child.nodeType = folder;
4129 child.icon = folder;
4130 PathCatSlash(parentPath, child.name);
4131 parent.files.Add(child);
4136 else if(!strcmpi(section, "Configurations"))
4138 ProjectConfig newConfig
4140 makingModified = true;
4144 LegacyProjectConfigLoad(newConfig, f);
4145 project.configurations.Add(newConfig);
4148 else if(!strcmpi(buffer, "ECERE Project File"));
4149 else if(!strcmpi(buffer, "Version 0a"))
4150 ; //strcpy(version, "0a");
4151 else if(!strcmpi(buffer, "Version 0.1a"))
4152 ; //strcpy(version, "0.1a");
4153 else if(!strcmpi(buffer, "Configurations"))
4155 project.configurations.Free();
4156 project.config = null;
4157 strcpy(section, buffer);
4158 configurationsPresent = true;
4160 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
4162 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
4163 char topNodePath[MAX_LOCATION];
4164 // newConfig.defaultNameSpace = "";
4165 //newConfig.objDir.dir = "obj";
4166 //newConfig.targetDir.dir = "";
4167 project = Project { /*options = { }*/ };
4168 project.configurations = { [ newConfig ] };
4169 project.config = newConfig;
4170 // if(project.topNode.path) delete project.topNode.path;
4171 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4172 MakeSlashPath(topNodePath);
4173 PathCatSlash(topNodePath, filePath);
4174 project.filePath = topNodePath;
4175 parentPath[0] = '\0';
4176 parent = project.topNode;
4178 strcpy(section, "Target");
4183 if(equal[0] == '\"')
4185 StripQuotes(equal, equal);
4186 delete project.moduleName; project.moduleName = CopyString(equal);
4190 else if(!strcmpi(buffer, "Compiler Options"));
4191 else if(!strcmpi(buffer, "IncludeDirs"))
4192 strcpy(subSection, buffer);
4193 else if(!strcmpi(buffer, "Linker Options"));
4194 else if(!strcmpi(buffer, "LibraryDirs"))
4195 strcpy(subSection, buffer);
4196 else if(!strcmpi(buffer, "Files"))
4198 strcpy(section, "Target");
4199 strcpy(subSection, buffer);
4201 else if(!strcmpi(buffer, "Resources"))
4203 ProjectNode child { };
4204 parent.files.Add(child);
4205 child.parent = parent;
4206 child.indent = parent.indent + 1;
4207 child.name = CopyString(buffer);
4208 child.path = CopyString("");
4209 child.type = resources;
4211 child.icon = archiveFile;
4212 project.resNode = child;
4215 strcpy(subSection, buffer);
4219 equal = strstr(buffer, "=");
4223 TrimRSpaces(buffer, buffer);
4225 TrimLSpaces(equal, equal);
4227 if(!strcmpi(section, "Target"))
4229 if(!strcmpi(buffer, "Build Exclusions"))
4231 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4233 /*if(node && node.type != NodeTypes::project)
4234 ParseListValue(node.buildExclusions, equal);*/
4237 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4239 delete project.resNode.path;
4240 project.resNode.path = CopyString(equal);
4241 PathCatSlash(parentPath, equal);
4245 else if(!strcmpi(buffer, "Intermediate Directory"))
4246 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4247 else if(!strcmpi(buffer, "Debug"))
4248 project.config.options.debug = ParseTrueFalseValue(equal);
4249 else if(!strcmpi(buffer, "Optimize"))
4251 if(!strcmpi(equal, "None"))
4252 project.config.options.optimization = none;
4253 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4254 project.config.options.optimization = speed;
4255 else if(!strcmpi(equal, "Size"))
4256 project.config.options.optimization = size;
4258 project.config.options.optimization = none;
4260 else if(!strcmpi(buffer, "Profile"))
4261 project.config.options.profile = ParseTrueFalseValue(equal);
4262 else if(!strcmpi(buffer, "MemoryGuard"))
4263 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4266 if(!project.options) project.options = { };
4268 // Project Wide Settings (All configs)
4269 if(!strcmpi(buffer, "Target Name"))
4270 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4271 else if(!strcmpi(buffer, "Target Type"))
4273 if(!strcmpi(equal, "Executable"))
4274 project.options.targetType = executable;
4275 else if(!strcmpi(equal, "Shared"))
4276 project.options.targetType = sharedLibrary;
4277 else if(!strcmpi(equal, "Static"))
4278 project.options.targetType = staticLibrary;
4280 project.options.targetType = executable;
4282 else if(!strcmpi(buffer, "Target Directory"))
4283 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4284 else if(!strcmpi(buffer, "Console"))
4285 project.options.console = ParseTrueFalseValue(equal);
4286 else if(!strcmpi(buffer, "Libraries"))
4288 if(!project.options.libraries) project.options.libraries = { };
4289 ParseArrayValue(project.options.libraries, equal);
4291 else if(!strcmpi(buffer, "AllWarnings"))
4292 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4293 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4295 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4297 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4298 ParseListValue(node.preprocessorDefs, equal);*/
4302 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4303 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4314 SplitPlatformLibraries(project);
4316 if(configurationsPresent)
4317 CombineIdenticalConfigOptions(project);
4321 void SplitPlatformLibraries(Project project)
4323 if(project && project.configurations)
4325 for(cfg : project.configurations)
4327 if(cfg.options.libraries && cfg.options.libraries.count)
4329 Iterator<String> it { cfg.options.libraries };
4333 char * platformName = strstr(l, ":");
4336 PlatformOptions platform = null;
4338 if(!cfg.platforms) cfg.platforms = { };
4339 for(p : cfg.platforms)
4341 if(!strcmpi(platformName, p.name))
4349 platform = { name = CopyString(platformName), options = { libraries = { } } };
4350 cfg.platforms.Add(platform);
4352 *(platformName-1) = 0;
4353 platform.options.libraries.Add(CopyString(l));
4355 cfg.options.libraries.Delete(it.pointer);
4364 void CombineIdenticalConfigOptions(Project project)
4366 if(project && project.configurations && project.configurations.count)
4369 ProjectOptions nullOptions { };
4370 ProjectConfig firstConfig = null;
4371 for(cfg : project.configurations)
4373 if(cfg.options.targetType != staticLibrary)
4380 firstConfig = project.configurations.firstIterator.data;
4382 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4384 if(!member.isProperty)
4386 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4391 for(cfg : project.configurations)
4393 if(cfg != firstConfig)
4395 if(cfg.options.targetType != staticLibrary)
4399 if(type.type == noHeadClass || type.type == normalClass)
4401 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4402 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4403 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4407 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4408 (byte *)firstConfig.options + member.offset + member._class.offset,
4409 (byte *)cfg.options + member.offset + member._class.offset);
4421 if(type.type == noHeadClass || type.type == normalClass)
4423 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4424 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4425 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4430 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4431 (byte *)firstConfig.options + member.offset + member._class.offset,
4432 (byte *)nullOptions + member.offset + member._class.offset))
4436 if(!project.options) project.options = { };
4438 /*if(type.type == noHeadClass || type.type == normalClass)
4440 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4441 (byte *)project.options + member.offset + member._class.offset,
4442 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4446 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4447 // TOFIX: ListBox::SetData / OnCopy mess
4448 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4449 (byte *)project.options + member.offset + member._class.offset,
4450 (type.typeSize > 4) ? address :
4451 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4452 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4453 (void *)*(byte *)address )));
4456 (byte *)project.options + member.offset + member._class.offset,
4457 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4459 for(cfg : project.configurations)
4461 if(cfg.options.targetType == staticLibrary)
4465 if(type.type == noHeadClass || type.type == normalClass)
4467 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4468 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4469 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4473 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4474 (byte *)firstConfig.options + member.offset + member._class.offset,
4475 (byte *)cfg.options + member.offset + member._class.offset);
4480 if(cfg != firstConfig)
4482 if(type.type == noHeadClass || type.type == normalClass)
4484 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4485 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4489 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4490 (byte *)cfg.options + member.offset + member._class.offset);
4492 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4495 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4502 // Compare Platform Specific Settings
4505 for(cfg : project.configurations)
4507 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4508 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4514 if(same && firstConfig.platforms)
4516 for(cfg : project.configurations)
4518 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4520 if(cfg != firstConfig)
4522 cfg.platforms = null;
4525 project.platforms = firstConfig.platforms;
4526 *&firstConfig.platforms = null;
4530 // Static libraries can't contain libraries
4531 for(cfg : project.configurations)
4533 if(cfg.options.targetType == staticLibrary)
4535 if(!cfg.options.libraries) cfg.options.libraries = { };
4536 cfg.options.libraries.Free();
4542 Project LoadProject(const char * filePath, const char * activeConfigName)
4544 Project project = null;
4545 File f = FileOpen(filePath, read);
4548 project = LegacyBinaryLoadProject(f, filePath);
4551 JSONParser parser { f = f };
4552 /*JSONResult result = */parser.GetObject(class(Project), &project);
4555 char insidePath[MAX_LOCATION];
4557 delete project.topNode.files;
4558 if(!project.files) project.files = { };
4559 project.topNode.files = project.files;
4562 char topNodePath[MAX_LOCATION];
4563 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4564 MakeSlashPath(topNodePath);
4565 PathCatSlash(topNodePath, filePath);
4566 project.filePath = topNodePath;//filePath;
4569 project.topNode.FixupNode(insidePath);
4571 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4572 delete project.resNode.path;
4573 project.resNode.path = project.resourcesPath;
4574 project.resourcesPath = null;
4575 project.resNode.nodeType = (ProjectNodeType)-1;
4576 delete project.resNode.files;
4577 project.resNode.files = project.resources;
4578 project.files = null;
4579 project.resources = null;
4580 if(!project.configurations) project.configurations = { };
4582 project.resNode.FixupNode(insidePath);
4587 project = LegacyAsciiLoadProject(f, filePath);
4593 if(!project.options) project.options = { };
4594 if(activeConfigName && activeConfigName[0] && project.configurations)
4595 project.config = project.GetConfig(activeConfigName);
4596 if(!project.config && project.configurations)
4597 project.config = project.configurations.firstIterator.data;
4599 if(!project.resNode)
4601 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4604 if(!project.moduleName)
4605 project.moduleName = CopyString(project.name);
4606 if(project.config &&
4607 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4608 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4610 //delete project.config.options.targetFileName;
4612 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4613 project.config.options.optimization = none;
4614 project.config.options.debug = true;
4615 //project.config.options.warnings = unset;
4616 project.config.options.memoryGuard = false;
4617 project.config.compilingModified = true;
4618 project.config.linkingModified = true;
4620 else if(!project.topNode.name && project.config)
4622 project.topNode.name = CopyString(project.config.options.targetFileName);
4625 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4626 project.topNode.configurations = project.configurations;
4627 project.topNode.platforms = project.platforms;
4628 project.topNode.options = project.options;*/
4634 #ifndef MAKEFILE_GENERATOR
4635 static GccVersionInfo GetGccVersionInfo(CompilerConfig compiler, const String compilerCommand)
4637 GccVersionInfo result = unknown;
4638 if(compiler.ccCommand)
4640 char command[MAX_F_STRING*4];
4642 sprintf(command, "%s%s --version", compiler.gccPrefix ? compiler.gccPrefix : "", compilerCommand);
4643 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
4645 bool firstLine = true;
4650 if(f.GetLine(line,sizeof(line)))
4654 uint count = Tokenize(line, sizeof(tokens)/sizeof(tokens[0]), tokens,false);
4655 char * token = null;
4658 for(i = 0; i < count; i++)
4660 if(tokens[i][0] == '(')
4662 if(tokens[i][strlen(tokens[i])-1] != ')')
4665 else if(tokens[i][0] && tokens[i][strlen(tokens[i])-1] == ')')
4667 else if(!inPar && isdigit(tokens[i][0]) && strchr(tokens[i], '.'))
4671 result = GccVersionInfo::GetVersionInfo(token);
4682 static enum GccVersionInfo
4684 unknown, pre4_8, post4_8;
4686 GccVersionInfo ::GetVersionInfo(char * version)
4688 GccVersionInfo result = unknown;
4690 char * s = CopyString(version);
4692 uint count = TokenizeWith(s, sizeof(tokens)/sizeof(tokens[0]), tokens, ".", false);
4693 ver = count > 1 ? atoi(tokens[1]) : 0;
4694 ver += count ? atoi(tokens[0]) * 1000 : 0;