2 public import static "ecere"
9 #ifndef MAKEFILE_GENERATOR
11 // We should have the .sln/.vcproj generation even on other platforms
12 // e.g. detect from an environment variable pointing to a Windows drive
18 import "ProjectConfig"
24 static void DummyFunction()
32 extern int __ecereVMethodID_class_OnCompare;
33 extern int __ecereVMethodID_class_OnFree;
35 IDESettings ideSettings;
37 IDESettingsContainer settingsContainer
40 dataOwner = &ideSettings;
41 dataClass = class(IDESettings);
43 void OnLoad(GlobalSettingsData data)
45 IDESettings settings = (IDESettings)data;
46 #ifndef MAKEFILE_GENERATOR
47 globalSettingsDialog.ideSettings = settings;
48 ide.UpdateRecentMenus();
49 ide.UpdateCompilerConfigs(true);
54 #ifdef MAKEFILE_GENERATOR
55 CompilerConfig defaultCompiler;
58 // LEGACY BINARY EPJ LOADING
60 SetBool ParseTrueFalseValue(char * string)
62 if(!strcmpi(string, "True")) return true;
66 void ParseArrayValue(Array<String> array, char * equal)
68 char * start, * comma;
70 string = CopyString(equal);
74 comma = strstr(start, ",");
77 array.Add(CopyString(start));
87 void ProjectNode::LegacyBinaryLoadNode(File f)
92 f.Read(&len, sizeof(len), 1);
93 name = new char[len+1];
95 f.Read(name, sizeof(char), len+1);
96 f.Read(&len, sizeof(len), 1);
98 path = new char[len+1];
99 f.Read(path, sizeof(char), len+1);
102 fileName = new char[fileNameLen+2];
103 strcpy(fileName, path);
104 if(fileName[0]) strcat(fileName, "/");
105 strcat(fileName, name);
108 f.Read(&type, sizeof(type), 1);
109 f.Read(&count, sizeof(count), 1);
114 icon = NodeIcons::SelectFileIcon(name);
119 icon = NodeIcons::SelectNodeIcon(type);
122 if(count && !files) files = { };
123 for(c = 0; c < count; c++)
125 ProjectNode child { };
128 child.indent = indent + 1;
129 LegacyBinaryLoadNode(child, f);
133 /*void LegacyBinarySaveNode(File f)
138 f.Write(&len, sizeof(len), 1);
139 f.Write(name, sizeof(char), len+1);
143 // Projects Absolute Path Are Not Saved
145 f.Write(&len, sizeof(len), 1);
146 f.Write(&len, sizeof(char), 1);
151 f.Write(&len, sizeof(len), 1);
152 f.Write(path, sizeof(char), len+1);
154 f.Write(&type, sizeof(type), 1);
155 f.Write(&children.count, sizeof(children.count), 1);
156 for(child = children.first; child; child.next)
160 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
163 char printPath[MAX_LOCATION];
165 if(type == project && (files.count /*|| preprocessorDefs.first*/))
167 f.Printf("\n Files\n");
169 else if(type == file)
171 if(!strcmp(path, insidePath))
172 f.Printf("%s - %s\n", indentation, name);
175 strcpy(printPath, path);
176 len = strlen(printPath);
178 if(printPath[len-1] != '/')
179 strcat(printPath, "/");
180 strcat(printPath, name);
181 f.Printf("%s = %s\n", indentation, printPath);
184 f.Printf("\nError\n\n");
186 else if(type == folder)
188 f.Printf("%s + %s\n", indentation, name);
190 else if(type == resources && files.count)
192 PathCatSlash(insidePath, path);
193 f.Printf("\n%sResources\n", indentation);
195 f.Printf("%s Path = %s\n", indentation, path);
198 /*if(buildExclusions.first && type != project)
200 for(item = buildExclusions.first; item; item = item.next)
202 if(item == buildExclusions.first)
203 f.Printf("%s Build Exclusions = %s", indentation, item.name);
205 f.Printf(", %s", item.name);
210 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
212 for(item = preprocessorDefs.first; item; item = item.next)
214 if(item == preprocessorDefs.first)
215 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
217 f.Printf(", %s", item.name);
223 if(type == project && (files.count /*|| preprocessorDefs.first*/))
227 LegacyAsciiSaveNode(child, f, indentation, insidePath);
229 else if(type == folder)
231 strcat(indentation, " ");
232 // WHAT WAS THIS: strcpy(printPath, path);
233 // TOCHECK: why is Unix/PathCat not used here
234 len = strlen(insidePath);
236 if(insidePath[len-1] != '/')
237 strcat(insidePath, "/");
238 strcat(insidePath, name);
241 LegacyAsciiSaveNode(child, f, indentation, insidePath);
242 f.Printf("%s -\n", indentation);
243 indentation[strlen(indentation) - 3] = '\0';
244 StripLastDirectory(insidePath, insidePath);
246 else if(type == resources && files.count)
250 LegacyAsciiSaveNode(child, f, indentation, insidePath);
251 StripLastDirectory(insidePath, insidePath);
256 void ProjectConfig::LegacyProjectConfigSave(File f)
258 char * indentation = " ";
260 //f.Printf("\n * Common\n");
262 f.Printf("\n + %s\n", name);
263 f.Printf("\n Compiler\n\n");
264 if(objDir.expression[0])
265 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
266 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
267 switch(options.optimization)
269 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
270 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
271 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
273 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
275 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
276 if(options.memoryGuard == true)
277 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
278 if(options.strictNameSpaces == true)
279 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
280 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
281 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
282 TOFIX: Compiler Bug {
283 if(options.preprocessorDefinitions.count)
286 for(item : options.preprocessorDefinitions)
290 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
294 f.Printf(", %s", item);
299 if(options.includeDirs.count)
301 f.Printf("\n%sInclude Directories\n", indentation);
302 for(item : options.includeDirs)
303 f.Printf("%s - %s\n", indentation, name);
307 f.Printf("\n%sLinker\n\n", indentation);
308 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
309 switch(options.targetType)
311 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
312 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
313 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
315 if(targetDir.expression[0])
316 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
318 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
320 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
321 if(options.libraries.count)
324 for(item : options.libraries)
328 f.Printf("\n%sLibraries = %s", indentation, name);
332 f.Printf(", %s", item);
336 if(options.libraryDirs.count)
338 f.Printf("\n%sLibrary Directories\n\n", indentation);
339 for(item : options.libraryDirs)
340 f.Printf(" - %s\n", indentation, item);
344 void LegacyAsciiSaveProject(File f, Project project)
346 char indentation[128*3];
347 char path[MAX_LOCATION];
349 f.Printf("\nECERE Project File : Format Version 0.1b\n");
350 f.Printf("\nDescription\n%s\n.\n", project.description);
351 f.Printf("\nLicense\n%s\n.\n", project.license);
352 f.Printf("\nModule Name = %s\n", project.moduleName);
353 f.Printf("\n Configurations\n");
354 //////////////////////////////////////commonConfig.Save(f, true);
355 for(cfg : project.configurations)
356 LegacyProjectConfigSave(cfg, f);
358 strcpy(indentation, " ");
360 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
366 // *** NEW JSON PROJECT FORMAT ***
367 public enum ProjectNodeType { file, folder };
369 // *******************************
371 define PEEK_RESOLUTION = (18.2 * 10);
377 static Array<String> notLinkerOptions
399 static bool IsLinkerOption(String s)
401 for(i : notLinkerOptions)
402 if(strstr(s, "-Wl,") || !strcmp(s, i))
407 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
409 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources, rcSources };
411 define WorkspaceExtension = "ews";
412 define ProjectExtension = "epj";
414 define stringInFileIncludedFrom = "In file included from ";
415 define stringFrom = " from ";
417 // 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, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
432 char ch, *i = input, *o = output;
435 int len = strlen(input);
436 if(len && ((input[0] == '"' && input[len-1] == '"') || strchr(input, '\\') || strchr(input, 127) || (!allowDblQuote && strchr(input, '"'))))
437 PrintLn("Invalid input for EscapeForMake! -- ", input);
443 if(i-1 != input && *(i-2) == '$' && allowVars)
450 if(inVar == true && allowVars)
455 else if(ch == '$' && *i != '(')
477 void EscapeForMakeToFile(File output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
479 char * buf = new char[strlen(input)*2+1];
480 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
485 void EscapeForMakeToDynString(DynamicString output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
487 char * buf = new char[strlen(input)*2+1];
488 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
493 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
496 const int breakListLength = 1536;
497 const int breakLineLength = 78; // TODO: turn this into an option.
499 int c, len, itemCount = 0;
500 Array<int> breaks { };
504 MapNode<String, int> mn;
505 for(c=0; c<list.count; c++)
507 len = strlen(list[c]) + 3;
508 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
510 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
512 if(strstr(list[c], mn.key))
516 if(charCount + len > breakListLength)
518 breaks.Add(itemCount);
526 breaks.Add(itemCount);
527 numOfBreaks = breaks.count;
532 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
533 for(c=0; c<numOfBreaks; c++)
534 f.Printf(" $(%s%d)", name, c+1);
538 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
544 for(c=0; c<numOfBreaks; c++)
547 f.Printf("%s%d =", name, c+1);
550 itemCount = breaks[c];
551 for(n=offset; n<offset+itemCount; n++)
553 if(false) // TODO: turn this into an option.
555 int itemLen = strlen(list[n]);
556 if(len > 3 && len + itemLen > breakLineLength)
558 f.Printf(" \\\n\t%s", list[n]);
564 f.Printf(" %s", list[n]);
568 f.Printf(" \\\n\t%s", list[n]);
583 void OutputFileListActions(File f, char * name, int parts, char * fileName)
588 for(c=0; c<parts; c++)
589 f.Printf("\t@$(call echo,$(%s%d)) >> %s\n", name, c+1, fileName);
591 f.Printf("\t@$(call echo,$(%s)) >> %s\n", name, fileName);
595 void OutputCleanActions(File f, char * name, int parts)
600 for(c=0; c<parts; c++)
601 f.Printf("\t$(call rmq,$(_%s%d))\n", name, c+1);
604 f.Printf("\t$(call rmq,$(_%s))\n", name);
607 enum LineOutputMethod { inPlace, newLine, lineEach };
608 enum StringOutputMethod { asIs, escape, escapePath};
610 enum ToolchainFlag { any, _D, _I, _isystem, _Wl, _L/*, _Wl-rpath*/ };
611 String flagNames[ToolchainFlag] = { "", "-D", "-I", "-isystem ", "-Wl,", /*"-Wl,--library-path="*/"-L"/*, "-Wl,-rpath "*/ };
612 void OutputFlags(File f, ToolchainFlag flag, Array<String> list, LineOutputMethod lineMethod)
616 if(lineMethod == newLine)
620 if(lineMethod == lineEach)
622 f.Printf(" %s", flagNames[flag]);
623 if(flag != _D && flag != _Wl && flag != any)
625 char * tmp = new char[strlen(item)*2+1];
626 EscapeForMake(tmp, item, false, true, false);
627 f.Printf("$(call quote_path,%s)", tmp);
631 EscapeForMakeToFile(f, item, false, true, true);
636 static void OutputLibraries(File f, Array<String> libraries)
638 for(item : libraries)
640 char ext[MAX_EXTENSION];
641 char temp[MAX_LOCATION];
643 bool usedFunction = false;
644 GetExtension(item, ext);
645 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
649 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
651 if(!strncmp(item, "lib", 3))
652 strcpy(temp, item + 3);
655 StripExtension(temp);
658 f.Puts(" \\\n\t$(call _L,");
661 EscapeForMakeToFile(f, s, false, false, false);
667 void CamelCase(char * string)
669 int c, len = strlen(string);
670 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
671 string[c] = (char)tolower(string[c]);
674 CompilerConfig GetCompilerConfig()
676 #ifndef MAKEFILE_GENERATOR
677 CompilerConfig compiler = null;
678 if(ide && ide.workspace)
679 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
682 incref defaultCompiler;
683 return defaultCompiler;
687 define localTargetType = config && config.options && config.options.targetType ?
688 config.options.targetType : options && options.targetType ?
689 options.targetType : TargetTypes::executable;
690 define localWarnings = config && config.options && config.options.warnings ?
691 config.options.warnings : options && options.warnings ?
692 options.warnings : WarningsOption::unset;
693 define localDebug = config && config.options && config.options.debug ?
694 config.options.debug : options && options.debug ?
695 options.debug : SetBool::unset;
696 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
697 config.options.memoryGuard : options && options.memoryGuard ?
698 options.memoryGuard : SetBool::unset;
699 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
700 config.options.noLineNumbers : options && options.noLineNumbers ?
701 options.noLineNumbers : SetBool::unset;
702 define localProfile = config && config.options && config.options.profile ?
703 config.options.profile : options && options.profile ?
704 options.profile : SetBool::unset;
705 define localOptimization = config && config.options && config.options.optimization ?
706 config.options.optimization : options && options.optimization ?
707 options.optimization : OptimizationStrategy::none;
708 define localFastMath = config && config.options && config.options.fastMath ?
709 config.options.fastMath : options && options.fastMath ?
710 options.fastMath : SetBool::unset;
711 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
712 config.options.defaultNameSpace : options && options.defaultNameSpace ?
713 options.defaultNameSpace : null;
714 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
715 config.options.strictNameSpaces : options && options.strictNameSpaces ?
716 options.strictNameSpaces : SetBool::unset;
717 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
718 define localTargetFileName = config && config.options && config.options.targetFileName ?
719 config.options.targetFileName : options && options.targetFileName ?
720 options.targetFileName : "";
721 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
722 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
723 options.targetDirectory : null;
724 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
725 ideSettings.projectDefaultIntermediateObjDir[0] ?
726 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
727 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
728 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
729 options.objectsDirectory : null;
730 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
731 ideSettings.projectDefaultIntermediateObjDir[0] ?
732 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
733 define localConsole = config && config.options && config.options.console ?
734 config.options.console : options && options.console ?
735 options.console : SetBool::unset;
736 define localCompress = config && config.options && config.options.compress ?
737 config.options.compress : options && options.compress ?
738 options.compress : SetBool::unset;
740 define platformTargetType =
741 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
742 configPOs.options.targetType :
743 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
744 projectPOs.options.targetType : TargetTypes::unset;
747 char * PlatformToMakefileTargetVariable(Platform platform)
749 return platform == win32 ? "WINDOWS_TARGET" :
750 platform == tux ? "LINUX_TARGET" :
751 platform == apple ? "OSX_TARGET" :
755 char * TargetTypeToMakefileVariable(TargetTypes targetType)
757 return targetType == executable ? "executable" :
758 targetType == sharedLibrary ? "sharedlib" :
759 targetType == staticLibrary ? "staticlib" :
763 // Move this to ProjectConfig? null vs Common to consider...
764 char * GetConfigName(ProjectConfig config)
766 return config ? config.name : "Common";
769 public enum SingleFileCompileMode
771 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
773 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
776 class Project : struct
778 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
779 // We might want to tweak this default behavior of regular classes ?
780 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
785 property char * moduleVersion
787 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
788 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
789 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
792 property char * description
794 set { delete description; if(value && value[0]) description = CopyString(value); }
795 get { return description ? description : ""; }
796 isset { return description != null && description[0]; }
799 property char * license
801 set { delete license; if(value && value[0]) license = CopyString(value); }
802 get { return license ? license : ""; }
803 isset { return license != null && license[0]; }
806 property char * compilerConfigsDir
808 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
809 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
810 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
813 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
814 property Array<PlatformOptions> platforms
816 get { return platforms; }
819 if(platforms) { platforms.Free(); delete platforms; }
822 List<PlatformOptions> empty { };
823 Iterator<PlatformOptions> it { value };
825 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
826 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
836 if(p.options && !p.options.isEmpty)
843 List<ProjectConfig> configurations;
844 LinkList<ProjectNode> files;
845 String resourcesPath;
846 LinkList<ProjectNode> resources;
849 // topNode.name holds the file name (.epj)
850 ProjectOptions options;
851 Array<PlatformOptions> platforms;
852 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
855 ProjectConfig config;
857 // This is the file name stripped of the epj extension
858 // It should NOT be edited, saved or loaded anywhere
863 String compilerConfigsDir;
864 String moduleVersion;
866 String lastBuildConfigName;
867 String lastBuildCompilerName;
869 Map<String, Map<String, NameCollisionInfo>> configsNameCollisions { };
871 #ifndef MAKEFILE_GENERATOR
872 FileMonitor fileMonitor
874 this, FileChange { modified = true };
875 bool OnFileNotify(FileChange action, char * param)
877 fileMonitor.StopMonitoring();
878 if(OnProjectModified(action, param))
879 fileMonitor.StartMonitoring();
884 bool StartMonitoring()
886 fileMonitor.fileName = filePath;
887 fileMonitor.StartMonitoring();
891 bool StopMonitoring()
893 fileMonitor.StopMonitoring();
897 bool OnProjectModified(FileChange fileChange, char * param)
900 sprintf(temp, $"The project %s was modified by another application.\n"
901 "Would you like to reload it and lose your changes?", name);
902 if(MessageBox { type = yesNo, master = ide,
903 text = $"Project has been modified", contents = temp }.Modal() == yes)
905 Project project = LoadProject(filePath, config ? config.name : null);
908 ProjectView projectView = ide.projectView;
909 DataRow prev = topNode.row ? topNode.row.previous : null;
910 FileMonitor fm = fileMonitor;
911 bool confirmation = true;
915 if(projectView.projectSettingsDialog)
917 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
919 projectView.projectSettingsDialog.Destroy(0);
922 projectView.DeleteNode(topNode);
929 topNode.project = this;
933 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
934 projectView.AddNode(topNode, null);
935 topNode.row.Move(prev);
937 projectView.ShowOutputBuildLog(true);
938 projectView.DisplayCompiler(compiler, false);
939 projectView.ProjectUpdateMakefileForAllConfigs(this);
942 eSystem_Delete(project);
954 // This frees contents without freeing the instance
955 // For use from destructor and for file monitor reloading
956 // (To work around JSON loader (LoadProject) always returning a new instance)
959 if(platforms) { platforms.Free(); delete platforms; }
960 if(configurations) { configurations.Free(); delete configurations; }
961 if(files) { files.Free(); delete files; }
962 if(resources) { resources.Free(); delete resources; }
964 delete resourcesPath;
968 delete compilerConfigsDir;
970 delete moduleVersion;
974 delete lastBuildConfigName;
975 delete lastBuildCompilerName;
976 for(map : configsNameCollisions)
978 configsNameCollisions.Free();
983 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
984 topNode.configurations = null;
985 topNode.platforms = null;
986 topNode.options = null;
991 property ProjectConfig config
997 topNode.info = CopyString(GetConfigName(config));
1001 property char * filePath
1007 char string[MAX_LOCATION];
1008 GetLastDirectory(value, string);
1009 delete topNode.name;
1010 topNode.name = CopyString(string);
1011 StripExtension(string);
1013 name = CopyString(string);
1014 StripLastDirectory(value, string);
1015 delete topNode.path;
1016 topNode.path = CopyString(string);
1018 filePath = CopyString(value);
1023 ProjectConfig GetConfig(char * configName)
1025 ProjectConfig result = null;
1026 if(configName && configName[0] && configurations.count)
1028 for(cfg : configurations; !strcmpi(cfg.name, configName))
1037 ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
1042 config = this.config;
1043 cfgName = config ? config.name : "";
1044 if(!configsNameCollisions[cfgName])
1045 ProjectLoadLastBuildNamesInfo(this, config);
1046 result = topNode.FindByObjectFileName(fileName, type, dotMain, configsNameCollisions[cfgName]);
1050 TargetTypes GetTargetType(ProjectConfig config)
1052 TargetTypes targetType = localTargetType;
1056 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1059 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1061 PlatformOptions projectPOs, configPOs;
1062 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1063 if(platformTargetType)
1069 char * GetObjDirExpression(ProjectConfig config)
1071 // TODO: Support platform options
1072 char * expression = localObjectsDirectory;
1074 expression = settingsObjectsDirectory;
1078 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1080 char * expression = GetObjDirExpression(config);
1081 DirExpression objDir { type = intermediateObjectsDir };
1082 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1086 char * GetTargetDirExpression(ProjectConfig config)
1088 // TODO: Support platform options
1089 char * expression = localTargetDirectory;
1091 expression = settingsTargetDirectory;
1095 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1097 char * expression = GetTargetDirExpression(config);
1098 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1099 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1103 WarningsOption GetWarnings(ProjectConfig config)
1105 WarningsOption warnings = localWarnings;
1109 bool GetDebug(ProjectConfig config)
1111 SetBool debug = localDebug;
1112 return debug == true;
1115 bool GetMemoryGuard(ProjectConfig config)
1117 SetBool memoryGuard = localMemoryGuard;
1118 return memoryGuard == true;
1121 bool GetNoLineNumbers(ProjectConfig config)
1123 SetBool noLineNumbers = localNoLineNumbers;
1124 return noLineNumbers == true;
1127 bool GetProfile(ProjectConfig config)
1129 SetBool profile = localProfile;
1130 return profile == true;
1133 OptimizationStrategy GetOptimization(ProjectConfig config)
1135 OptimizationStrategy optimization = localOptimization;
1136 return optimization;
1139 bool GetFastMath(ProjectConfig config)
1141 SetBool fastMath = localFastMath;
1142 return fastMath == true;
1145 String GetDefaultNameSpace(ProjectConfig config)
1147 String defaultNameSpace = localDefaultNameSpace;
1148 return defaultNameSpace;
1151 bool GetStrictNameSpaces(ProjectConfig config)
1153 SetBool strictNameSpaces = localStrictNameSpaces;
1154 return strictNameSpaces == true;
1157 String GetTargetFileName(ProjectConfig config)
1159 String targetFileName = localTargetFileName;
1160 return targetFileName;
1163 //String targetDirectory;
1164 //String objectsDirectory;
1165 bool GetConsole(ProjectConfig config)
1167 SetBool console = localConsole;
1168 return console == true;
1171 bool GetCompress(ProjectConfig config)
1173 SetBool compress = localCompress;
1174 return compress == true;
1176 //SetBool excludeFromBuild;
1178 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1180 #ifndef MAKEFILE_GENERATOR
1181 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1185 bool GetConfigIsInDebugSession(ProjectConfig config)
1187 #ifndef MAKEFILE_GENERATOR
1188 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1192 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1194 #ifndef MAKEFILE_GENERATOR
1195 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1199 #ifndef MAKEFILE_GENERATOR
1200 bool Save(char * fileName)
1203 /*char output[MAX_LOCATION];
1204 ChangeExtension(fileName, "json", output);
1205 f = FileOpen(output, write);*/
1206 f = FileOpen(fileName, write);
1209 files = topNode.files;
1210 resources = resNode.files;
1211 resourcesPath = resNode.path;
1213 files.Remove(resNode);
1216 WriteJSONObject(f, class(Project), this, 0);
1222 resourcesPath = null;
1229 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1231 TargetTypes targetType = GetTargetType(config);
1232 String targetFileName = GetTargetFileName(config);
1233 if(targetType == staticLibrary)
1235 PathCatSlash(string, "lib");
1236 strcat(string, targetFileName);
1238 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1240 PathCatSlash(string, "lib");
1241 strcat(string, targetFileName);
1244 PathCatSlash(string, targetFileName);
1249 if(compiler.targetPlatform == win32)
1250 strcat(string, ".exe");
1253 if(compiler.targetPlatform == win32)
1254 strcat(string, ".dll");
1255 else if(compiler.targetPlatform == apple)
1256 strcat(string, ".dylib");
1258 strcat(string, ".so");
1259 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1261 strcat(string, ".");
1262 strcat(string, moduleVersion);
1266 strcat(string, ".a");
1271 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1273 bool result = false;
1274 char temp[MAX_LOCATION];
1275 strcpy(cfDir, topNode.path);
1276 if(compilerConfigsDir && compilerConfigsDir[0])
1278 PathCatSlash(cfDir, compilerConfigsDir);
1283 strcpy(temp, cfDir);
1284 // Using a relative path makes it less likely to run into spaces issues
1285 // Even with escaped spaces, there still seems to be issues including a config file
1286 // in a path containing spaces
1288 MakePathRelative(temp, topNode.path, cfDir);
1291 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1295 strcpy(temp, cfDir);
1296 ReplaceSpaces(cfDir, temp);
1301 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1303 char temp[MAX_LOCATION];
1304 bool result = false;
1305 strcpy(cfDir, topNode.path);
1306 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1308 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1313 // Default to <ProjectDir>/.configs if unset
1314 PathCatSlash(cfDir, ".configs");
1319 strcpy(temp, cfDir);
1320 // Using a relative path makes it less likely to run into spaces issues
1321 // Even with escaped spaces, there still seems to be issues including a config file
1322 // in a path containing spaces
1323 if(IsPathInsideOf(cfDir, topNode.path))
1324 MakePathRelative(temp, topNode.path, cfDir);
1326 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1330 strcpy(temp, cfDir);
1331 ReplaceSpaces(cfDir, temp);
1336 void CatMakeFileName(char * string, ProjectConfig config)
1338 char projectName[MAX_LOCATION];
1339 strcpy(projectName, name);
1340 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1343 #ifndef MAKEFILE_GENERATOR
1344 void MarkChanges(ProjectNode node)
1346 for(cfg : topNode.configurations)
1348 ProjectConfig c = null;
1349 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1351 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1352 (!c.options || !cfg.options)))
1353 cfg.symbolGenModified = true;
1354 if(c && ((c.options && cfg.options &&
1355 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1356 || (!c.options || !cfg.options)))
1357 cfg.linkingModified = true;
1359 cfg.makingModified = true;
1363 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1365 Map<String, NameCollisionInfo> cfgNameCollision;
1366 MapIterator<String, Map<String, NameCollisionInfo>> it { map = configsNameCollisions };
1367 if(it.Index("", false))
1369 cfgNameCollision = it.data;
1370 cfgNameCollision.Free();
1371 delete cfgNameCollision;
1374 for(cfg : configurations)
1378 cfg.makingModified = true;
1379 if(it.Index(cfg.name, false))
1381 cfgNameCollision = it.data;
1382 cfgNameCollision.Free();
1383 delete cfgNameCollision;
1388 cfg.compilingModified = true;
1390 cfg.linkingModified = true;
1392 cfg.symbolGenModified = true;
1394 if(compiling || linking)
1396 ide.projectView.modifiedDocument = true;
1397 ide.workspace.modified = true;
1401 void RotateActiveConfig(bool forward, bool syncAllProjects)
1403 if(configurations.first && configurations.last != configurations.first)
1405 Iterator<ProjectConfig> cfg { configurations };
1406 while(forward ? cfg.Next() : cfg.Prev())
1407 if(cfg.data == config)
1422 ide.workspace.SelectActiveConfig(cfg.data.name);
1425 property::config = cfg.data;
1426 ide.UpdateToolBarActiveConfigs(true);
1427 ide.workspace.modified = true;
1428 ide.projectView.Update(null);
1433 bool ProcessPipeOutputRaw(DualPipe f)
1436 while(!f.Eof() && !ide.projectView.stopBuild)
1439 double lastTime = GetTime();
1443 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1445 ide.outputView.buildBox.Logf("%s\n", line);
1447 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1449 //printf("Processing Input...\n");
1450 if(app.ProcessInput(true))
1452 app.UpdateDisplay();
1455 //printf("Waiting...\n");
1458 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1460 if(ide.projectView.stopBuild)
1462 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1465 return !ide.projectView.stopBuild;
1468 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, BuildType buildType, List<ProjectNode> onlyNodes,
1469 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1472 bool compiling = false, linking = false, precompiling = false;
1473 int compilingEC = 0;
1474 int numErrors = 0, numWarnings = 0;
1475 bool loggedALine = false;
1476 int lenMakeCommand = strlen(compiler.makeCommand);
1479 char moduleName[MAX_FILENAME];
1480 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1482 DynamicString test { };
1483 DynamicString ecp { };
1484 DynamicString ecc { };
1485 DynamicString ecs { };
1486 DynamicString ear { };
1487 DynamicString prefix { };
1488 DynamicString cpp { };
1489 DynamicString cc { };
1490 DynamicString cxx { };
1491 DynamicString strip { };
1492 DynamicString ar { };
1493 DynamicString windres { };
1496 if(bitDepth == 64 && compiler.targetPlatform == win32)
1497 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1498 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1499 gnuToolchainPrefix = "i686-w64-mingw32-";
1501 ecp.concatx(compiler.ecpCommand, " ");
1502 ecc.concatx(compiler.eccCommand, " ");
1503 ecs.concatx(compiler.ecsCommand, " ");
1504 ear.concatx(compiler.earCommand, " ");
1507 compiler.ccacheEnabled ? "ccache " : "",
1508 compiler.distccEnabled ? "distcc " : "",
1509 gnuToolchainPrefix);
1511 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1512 cc.concatx((String)prefix, compiler.ccCommand, " ");
1513 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1515 strip.concatx(gnuToolchainPrefix, "strip ");
1516 ar.concatx(gnuToolchainPrefix, "ar rcs");
1517 windres.concatx(gnuToolchainPrefix, "windres ");
1519 testLen = Max(testLen, ecp.size);
1520 testLen = Max(testLen, ecc.size);
1521 testLen = Max(testLen, ecs.size);
1522 testLen = Max(testLen, ear.size);
1523 testLen = Max(testLen, cpp.size);
1524 testLen = Max(testLen, cc.size);
1525 testLen = Max(testLen, cxx.size);
1526 testLen = Max(testLen, strip.size);
1527 testLen = Max(testLen, ar.size);
1528 testLen = Max(testLen, windres.size);
1529 testLen = Max(testLen, strlen("mkdir "));
1532 while(!f.Eof() && !ide.projectView.stopBuild)
1535 double lastTime = GetTime();
1539 //printf("Peeking and GetLine...\n");
1540 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1542 char * message = null;
1543 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1544 char * from = strstr(line, stringFrom);
1545 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1546 if((t = strstr(line, (s=": recipe for target"))) && (t = strstr(t+strlen(s), (s=" failed"))) && (t+strlen(s))[0] == '\0')
1547 ; // ignore this new gnu make error but what is it about?
1548 else if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1550 char * module = strstr(line, "No rule to make target `");
1554 module = strchr(module, '`') + 1;
1555 end = strchr(module, '\'');
1559 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1560 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1566 //ide.outputView.buildBox.Logf("error: %s\n", line);
1570 else if(strstr(test, "mkdir ") == test);
1571 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1572 else if(strstr(test, ear) == test);
1573 else if(strstr(test, strip) == test);
1574 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1577 bool isPrecomp = false;
1580 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1582 module = strstr(line, " -c ");
1583 if(module) module += 4;
1586 else if(strstr(test, ecc) == test)
1588 module = strstr(line, " -c ");
1589 if(module) module += 4;
1590 //module = line + 3;
1591 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1592 compilingEC = 3;//2;
1595 else if(strstr(test, ecp) == test)
1597 // module = line + 8;
1598 module = strstr(line, " -c ");
1599 if(module) module += 4;
1610 if(!compiling && !isPrecomp)
1612 ide.outputView.buildBox.Logf($"Compiling...\n");
1615 else if(!precompiling && isPrecomp)
1617 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1618 precompiling = true;
1620 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1621 GetLastDirectory(tokens[0], moduleName);
1622 ide.outputView.buildBox.Logf("%s\n", moduleName);
1624 else if((module = strstr(line, " -o ")))
1627 precompiling = false;
1629 ide.outputView.buildBox.Logf($"Linking...\n");
1633 ide.outputView.buildBox.Logf("%s\n", line);
1634 if(strstr(line, "warning:") || strstr(line, "note:"))
1636 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1640 if(compilingEC) compilingEC--;
1642 else if(strstr(test, windres) == test)
1645 module = strstr(line, " ");
1646 if(module) module++;
1650 char * dashF = strstr(module, "-F ");
1654 while(*dashF && *dashF != ' ') dashF++;
1655 while(*dashF && *dashF == ' ') dashF++;
1658 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1659 GetLastDirectory(module, moduleName);
1660 ide.outputView.buildBox.Logf("%s\n", moduleName);
1663 else if(strstr(test, ar) == test)
1664 ide.outputView.buildBox.Logf($"Building library...\n");
1665 else if(strstr(test, ecs) == test)
1666 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1669 if(linking || compiling || precompiling)
1671 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1672 char * colon = strstr(start, ":"); //, * bracket;
1673 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1674 colon = strstr(colon + 1, ":");
1677 char * sayError = "";
1678 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1681 int len = (int)(colon - start);
1682 char ext[MAX_EXTENSION];
1683 len = Min(len, MAX_LOCATION-1);
1684 // Don't be mistaken by the drive letter colon
1686 // TODO: need to fix colon - line gives char *
1687 // warning: incompatible expression colon - line (char *); expected int
1689 strncpy(moduleName, line, (int)(colon - line));
1690 moduleName[colon - line] = '\0';
1692 strncpy(moduleName, start, len);
1693 moduleName[len] = '\0';
1694 // Remove stuff in brackets
1695 //bracket = strstr(moduleName, "(");
1696 //if(bracket) *bracket = '\0';
1698 GetLastDirectory(moduleName, temp);
1699 GetExtension(temp, ext);
1701 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1703 char * cColon = strstr(colon+1, ":");
1704 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1705 cColon = strstr(cColon + 1, ":");
1708 int len = (int)(cColon - (colon+1));
1709 char mName[MAX_LOCATION];
1710 len = Min(len, MAX_LOCATION-1);
1711 strncpy(mName, colon+1, len);
1713 GetLastDirectory(mName, temp);
1714 GetExtension(temp, ext);
1715 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1718 strcpy(moduleName, mName);
1722 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1725 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1727 message = $"Linker Message: ";
1733 message = $"Linker Error: ";
1736 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1740 if(strstr(colon, "Warning:") == colon)
1742 message = $"Linker ";
1745 else if(!strstr(line, "error:"))
1747 message = $"Linker Error: ";
1753 strcpy(temp, topNode.path);
1754 PathCatSlash(temp, moduleName);
1755 MakePathRelative(temp, topNode.path, moduleName);
1757 error = strstr(line, "error:");
1758 if(!message && error && error > colon)
1762 // Silence warnings for compiled eC
1763 char * objDir = strstr(moduleName, objDirExp.dir);
1767 if((pointer = strstr(line, "undefined")) ||
1768 (pointer = strstr(line, "multiple definition")) ||
1769 (pointer = strstr(line, "No such file")) ||
1770 (pointer = strstr(line, "token")))
1772 strncat(moduleName, colon, pointer - colon);
1773 sayError = "error: ";
1778 else if((pointer = strstr(line, "No such file")))
1780 strncat(moduleName, colon, pointer - colon);
1781 sayError = "error: ";
1785 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1787 else if(strstr(line, "warning:"))
1793 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1794 /*else if(this == ide.workspace.projects.firstIterator.data)
1795 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1798 char fullModuleName[MAX_LOCATION];
1799 FileAttribs found = 0;
1800 Project foundProject = this;
1803 char * loc = strstr(moduleName, ":");
1805 strcpy(fullModuleName, topNode.path);
1806 PathCat(fullModuleName, moduleName);
1807 found = FileExists(fullModuleName);
1808 if(!found && !strcmp(ext, "c"))
1810 char ecName[MAX_LOCATION];
1811 ChangeExtension(fullModuleName, "ec", ecName);
1812 found = FileExists(ecName);
1816 char path[MAX_LOCATION];
1817 if(ide && ide.workspace)
1819 for(prj : ide.workspace.projects)
1822 MakePathRelative(fullModuleName, prj.topNode.path, path);
1824 if((node = prj.topNode.FindWithPath(path, false)))
1826 strcpy(fullModuleName, prj.topNode.path);
1827 PathCatSlash(fullModuleName, node.path);
1828 PathCatSlash(fullModuleName, node.name);
1829 found = FileExists(fullModuleName);
1837 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1839 for(prj : ide.workspace.projects)
1842 if((node = prj.topNode.Find(moduleName, false)))
1844 strcpy(fullModuleName, prj.topNode.path);
1845 PathCatSlash(fullModuleName, node.path);
1846 PathCatSlash(fullModuleName, node.name);
1847 found = FileExists(fullModuleName);
1860 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1861 MakeSystemPath(fullModuleName);
1864 strcpy(fullModuleName, moduleName);
1867 strcat(fullModuleName, ":");
1868 strcat(fullModuleName, loc + 1);
1872 fullModuleName[0] = 0;
1873 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1878 ide.outputView.buildBox.Logf("%s\n", line);
1879 linking = compiling = precompiling = false;
1883 ide.outputView.buildBox.Logf("%s\n", line);
1887 //printf("Done getting line\n");
1888 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1890 //printf("Processing Input...\n");
1891 if(app.ProcessInput(true))
1893 app.UpdateDisplay();
1896 //printf("Waiting...\n");
1899 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1901 if(ide.projectView.stopBuild)
1903 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1906 else if(loggedALine || buildType != run)
1908 if(f.GetExitCode() && !numErrors)
1910 bool result = f.GetLine(line, sizeof(line)-1);
1911 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1913 else if(buildType != install)
1917 char targetFileName[MAX_LOCATION];
1918 targetFileName[0] = '\0';
1919 CatTargetFileName(targetFileName, compiler, config);
1920 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1923 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1925 ide.outputView.buildBox.Logf($"no error, ");
1928 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1930 ide.outputView.buildBox.Logf($"no warning\n");
1947 return numErrors == 0 && !ide.projectView.stopBuild;
1950 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1953 int lenMakeCommand = strlen(compiler.makeCommand);
1958 double lastTime = GetTime();
1961 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1963 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1964 else if(strstr(line, "mkdir") == line);
1965 else if(strstr(line, "del") == line);
1966 else if(strstr(line, "rm") == line);
1967 else if(strstr(line, "Could Not Find") == line);
1970 ide.outputView.buildBox.Logf(line);
1971 ide.outputView.buildBox.Logf("\n");
1975 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1977 if(app.ProcessInput(true))
1979 app.UpdateDisplay();
1982 //Sleep(1.0 / PEEK_RESOLUTION);
1986 bool Build(BuildType buildType, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
1988 bool result = false;
1990 char targetFileName[MAX_LOCATION] = "";
1991 DynamicString makeTargets { };
1992 char makeFile[MAX_LOCATION];
1993 char makeFilePath[MAX_LOCATION];
1994 char configName[MAX_LOCATION];
1995 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
1996 PathBackup pathBackup { };
1997 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1998 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2000 bool eC_Debug = mode.eC_ToolsDebug;
2001 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2002 int numJobs = compiler.numJobs;
2003 char command[MAX_F_STRING*4];
2004 char * compilerName = CopyString(compiler.name);
2005 Map<String, NameCollisionInfo> cfgNameCollisions;
2007 delete lastBuildConfigName;
2008 lastBuildConfigName = CopyString(config ? config.name : "Common");
2009 delete lastBuildCompilerName;
2010 lastBuildCompilerName = CopyString(compiler.name);
2011 ProjectLoadLastBuildNamesInfo(this, config);
2012 cfgNameCollisions = configsNameCollisions[config ? config.name : ""];
2014 CamelCase(compilerName);
2016 strcpy(configName, config ? config.name : "Common");
2018 SetPath(false, compiler, config, bitDepth); //true
2019 CatTargetFileName(targetFileName, compiler, config);
2021 strcpy(makeFilePath, topNode.path);
2022 CatMakeFileName(makeFile, config);
2023 PathCatSlash(makeFilePath, makeFile);
2025 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2026 if(buildType == install)
2027 makeTargets.concat(" install");
2030 if(compiler.type.isVC)
2032 PrintLn("compiling a single file is not yet supported");
2037 char pushD[MAX_LOCATION];
2038 char cfDir[MAX_LOCATION];
2039 GetIDECompilerConfigsDir(cfDir, true, true);
2040 GetWorkingDir(pushD, sizeof(pushD));
2041 ChangeWorkingDir(topNode.path);
2042 // Create object dir if it does not exist already
2043 if(!FileExists(objDirExp.dir).isDirectory)
2045 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2046 compiler.makeCommand, cfDir,
2047 crossCompiling ? " TARGET_PLATFORM=" : "",
2049 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2050 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2052 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2054 ide.outputView.buildBox.Logf("%s\n", command);
2058 ChangeWorkingDir(pushD);
2060 for(node : onlyNodes)
2062 if(node.GetIsExcluded(config))
2063 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2067 node.DeleteIntermediateFiles(compiler, config, bitDepth, cfgNameCollisions, mode == cObject ? true : false);
2068 node.GetTargets(config, cfgNameCollisions, objDirExp.dir, makeTargets);
2074 if(compiler.type.isVC)
2076 bool result = false;
2077 char oldwd[MAX_LOCATION];
2078 GetWorkingDir(oldwd, sizeof(oldwd));
2079 ChangeWorkingDir(topNode.path);
2081 // TODO: support justPrint
2082 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2084 ide.outputView.buildBox.Logf("%s\n", command);
2085 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
2087 ProcessPipeOutputRaw(f);
2091 ChangeWorkingDir(oldwd);
2093 else if(onlyNodes && strlen(makeTargets) == 0)
2095 ide.outputView.buildBox.Log("No targets to compile.\n");
2099 GccVersionInfo ccVersion = GetGccVersionInfo(compiler, compiler.ccCommand);
2100 GccVersionInfo cxxVersion = GetGccVersionInfo(compiler, compiler.cxxCommand);
2101 char cfDir[MAX_LOCATION];
2102 GetIDECompilerConfigsDir(cfDir, true, true);
2103 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\"",
2104 #if defined(__WIN32__)
2107 buildType == install ? "pkexec --user root " : "",
2109 compiler.makeCommand,
2110 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2112 crossCompiling ? " TARGET_PLATFORM=" : "",
2114 bitDepth ? " ARCH=" : "",
2115 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2116 ide.workspace.useValgrind ? " DISABLED_POOLING=1" : "",
2117 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2118 compilerName, eC_Debug ? "--always-make " : "",
2119 ccVersion == post4_8 ? "GCC_CC_FLAGS=-fno-diagnostics-show-caret " : "",
2120 cxxVersion == post4_8 ? "GCC_CXX_FLAGS=-fno-diagnostics-show-caret " : "",
2122 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2123 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2124 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2126 ide.outputView.buildBox.Logf("%s\n", command);
2128 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2136 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2142 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2145 ide.outputView.buildBox.Logf("%s\n", line);
2146 if(!error && !found && strstr(line, "echo ") == line && strstr(line, "ECERE_SDK_SRC"))
2148 strcpy(command, line+5);
2151 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2153 strcpy(command, line);
2163 result = ProcessPipeOutputRaw(f);
2165 result = ProcessBuildPipeOutput(f, objDirExp, buildType, onlyNodes, compiler, config, bitDepth);
2168 ide.outputView.buildBox.Logf("%s\n", command);
2169 else if(justPrint && found)
2170 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2175 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2180 delete compilerName;
2185 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2187 char makeFile[MAX_LOCATION];
2188 char makeFilePath[MAX_LOCATION];
2189 char command[MAX_LOCATION];
2190 char * compilerName;
2192 PathBackup pathBackup { };
2193 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2194 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2196 compilerName = CopyString(compiler.name);
2197 CamelCase(compilerName);
2199 SetPath(false, compiler, config, bitDepth);
2201 strcpy(makeFilePath, topNode.path);
2202 CatMakeFileName(makeFile, config);
2203 PathCatSlash(makeFilePath, makeFile);
2205 if(compiler.type.isVC)
2207 bool result = false;
2208 char oldwd[MAX_LOCATION];
2209 GetWorkingDir(oldwd, sizeof(oldwd));
2210 ChangeWorkingDir(topNode.path);
2212 // TODO: justPrint support
2213 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2215 ide.outputView.buildBox.Logf("%s\n", command);
2216 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2218 ProcessPipeOutputRaw(f);
2222 ChangeWorkingDir(oldwd);
2227 char cfDir[MAX_LOCATION];
2228 GetIDECompilerConfigsDir(cfDir, true, true);
2229 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2230 compiler.makeCommand, cfDir,
2231 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2232 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2234 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2235 topNode.path, justPrint ? " -n": "", makeFilePath);
2237 ide.outputView.buildBox.Logf("%s\n", command);
2238 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2240 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2241 cleanType == realClean ? $"intermediate objects directory" : $"target",
2242 cleanType == clean ? $" and object files" : "");
2244 ProcessPipeOutputRaw(f);
2246 ProcessCleanPipeOutput(f, compiler, config);
2247 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2248 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2249 cleanType == clean ? $" and object files" : "");
2255 delete compilerName;
2258 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2260 String target = new char[maxPathLen];
2261 char oldDirectory[MAX_LOCATION];
2262 char * executableLauncher = compiler.executableLauncher;
2263 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2264 PathBackup pathBackup { };
2266 // Build(project, ideMain, true, null, false);
2268 strcpy(target, topNode.path);
2269 PathCatSlash(target, targetDirExp.dir);
2270 CatTargetFileName(target, compiler, config);
2271 sprintf(target, "%s %s", target, args);
2272 GetWorkingDir(oldDirectory, MAX_LOCATION);
2274 if(strlen(ide.workspace.debugDir))
2276 char temp[MAX_LOCATION];
2277 strcpy(temp, topNode.path);
2278 PathCatSlash(temp, ide.workspace.debugDir);
2279 ChangeWorkingDir(temp);
2282 ChangeWorkingDir(topNode.path);
2283 SetPath(true, compiler, config, bitDepth);
2284 if(executableLauncher)
2286 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 8];
2287 prefixedTarget[0] = '\0';
2288 strcat(prefixedTarget, executableLauncher);
2289 strcat(prefixedTarget, " ");
2290 strcat(prefixedTarget, target);
2291 Execute(prefixedTarget);
2292 delete prefixedTarget;
2297 ChangeWorkingDir(oldDirectory);
2300 delete targetDirExp;
2304 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2306 return Build(build, nodes, compiler, config, bitDepth, justPrint, mode);
2310 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2313 if(targetType == staticLibrary || targetType == sharedLibrary)
2314 strcat(fileName, "$(LP)");
2315 strcat(fileName, GetTargetFileName(config));
2319 strcat(fileName, "$(E)");
2322 strcat(fileName, "$(SO)$(VER)");
2325 strcat(fileName, "$(A)");
2330 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2332 bool result = false;
2333 char path[MAX_LOCATION];
2335 if(!GetProjectCompilerConfigsDir(path, false, false))
2336 GetIDECompilerConfigsDir(path, false, false);
2338 if(!FileExists(path).isDirectory)
2342 char dirName[MAX_FILENAME];
2343 GetLastDirectory(path, dirName);
2344 if(!strcmp(dirName, ".configs"))
2345 FileSetAttribs(path, FileAttribs { isHidden = true });
2348 PathCatSlash(path, "crossplatform.mk");
2350 if(FileExists(path))
2353 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2356 File f = FileOpen(path, write);
2359 include.Seek(0, start);
2360 for(; !include.Eof(); )
2363 int count = include.Read(buffer, 1, 4096);
2364 f.Write(buffer, 1, count);
2370 if(!altCrossPlatformMk)
2377 bool GenerateCompilerCf(CompilerConfig compiler, bool eC)
2379 bool result = false;
2380 char path[MAX_LOCATION];
2382 char * compilerName;
2383 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2384 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2385 Platform platform = compiler.targetPlatform;
2387 compilerName = CopyString(compiler.name);
2388 CamelCase(compilerName);
2389 name = PrintString(platform, "-", compilerName, ".cf");
2391 if(!GetProjectCompilerConfigsDir(path, false, false))
2392 GetIDECompilerConfigsDir(path, false, false);
2394 if(!FileExists(path).isDirectory)
2398 char dirName[MAX_FILENAME];
2399 GetLastDirectory(path, dirName);
2400 if(!strcmp(dirName, ".configs"))
2401 FileSetAttribs(path, FileAttribs { isHidden = true });
2404 PathCatSlash(path, name);
2406 if(FileExists(path))
2409 File f = FileOpen(path, write);
2412 if(compiler.environmentVars && compiler.environmentVars.count)
2414 f.Puts("# ENVIRONMENT VARIABLES\n");
2416 for(e : compiler.environmentVars)
2418 f.Printf("export %s := %s\n", e.name, e.string);
2423 f.Puts("# TOOLCHAIN\n");
2426 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2428 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2431 if(compiler.sysroot && compiler.sysroot[0])
2433 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2434 // Moved this to crossplatform.mk
2435 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2439 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2440 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2441 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CC_FLAGS),$(space)$(GCC_CC_FLAGS),)\n", compiler.ccCommand);
2442 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)$(if $(GCC_CXX_FLAGS),$(space)$(GCC_CXX_FLAGS),)\n", compiler.cxxCommand);
2445 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);
2446 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);
2447 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);
2451 f.Printf("ECP := %s\n", compiler.ecpCommand);
2452 f.Printf("ECC := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2453 f.Printf("ECS := %s$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)$(if $(DISABLED_POOLING), -disabled-pooling,)\n", compiler.ecsCommand);
2455 f.Printf("EAR := %s\n", compiler.earCommand);
2457 f.Puts("AS := $(GCC_PREFIX)as\n");
2458 f.Puts("LD := $(GCC_PREFIX)ld\n");
2459 f.Puts("AR := $(GCC_PREFIX)ar\n");
2460 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2461 f.Puts("ifdef WINDOWS_TARGET\n");
2462 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2463 f.Puts(" ifdef ARCH\n");
2464 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2465 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2467 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2468 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2473 f.Puts("UPX := upx\n");
2476 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2479 f.Puts("EARFLAGS = \n");
2482 f.Puts("ifndef ARCH\n");
2483 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2484 f.Puts(" ifdef WINDOWS_HOST\n");
2485 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2486 f.Puts(" TARGET_ARCH := x86_64\n");
2488 f.Puts(" TARGET_ARCH := i386\n");
2491 f.Puts("endif\n\n");
2493 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2494 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2498 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2502 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2505 if(compiler.includeDirs && compiler.includeDirs.count)
2507 f.Puts("\nCFLAGS +=");
2508 OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
2511 if(compiler.prepDirectives && compiler.prepDirectives.count)
2513 f.Puts("\nCFLAGS +=");
2514 OutputFlags(f, _D, compiler.prepDirectives, inPlace);
2517 if(compiler.libraryDirs && compiler.libraryDirs.count)
2519 f.Puts("\nLDFLAGS +=");
2520 OutputFlags(f, _L, compiler.libraryDirs, lineEach);
2521 // We would need a bool option to know whether we want to add to rpath as well...
2522 // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
2525 if(compiler.excludeLibs && compiler.excludeLibs.count)
2527 f.Puts("\nEXCLUDED_LIBS =");
2528 for(l : compiler.excludeLibs)
2534 if(compiler.eCcompilerFlags && compiler.eCcompilerFlags.count)
2536 f.Puts("\nECFLAGS +=");
2537 OutputFlags(f, any, compiler.eCcompilerFlags, inPlace);
2540 if(compiler.compilerFlags && compiler.compilerFlags.count)
2542 f.Puts("\nCFLAGS +=");
2543 OutputFlags(f, any, compiler.compilerFlags, inPlace);
2546 if(compiler.linkerFlags && compiler.linkerFlags.count)
2548 f.Puts("\nLDFLAGS +=");
2549 OutputFlags(f, _Wl, compiler.linkerFlags, inPlace);
2553 f.Puts("\nOFLAGS += $(LDFLAGS)");
2555 f.Puts("ifdef ARCH_FLAGS\n");
2556 f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2557 f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2566 delete compilerName;
2570 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2572 bool result = false;
2573 char filePath[MAX_LOCATION];
2574 char makeFile[MAX_LOCATION];
2575 // PathBackup pathBackup { };
2576 // char oldDirectory[MAX_LOCATION];
2579 if(!altMakefilePath)
2581 strcpy(filePath, topNode.path);
2582 CatMakeFileName(makeFile, config);
2583 PathCatSlash(filePath, makeFile);
2586 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2588 /*SetPath(false, compiler, config);
2589 GetWorkingDir(oldDirectory, MAX_LOCATION);
2590 ChangeWorkingDir(topNode.path);*/
2597 char targetDir[MAX_LOCATION];
2598 char objDirExpNoSpaces[MAX_LOCATION];
2599 char objDirNoSpaces[MAX_LOCATION];
2600 char resDirNoSpaces[MAX_LOCATION];
2601 char targetDirExpNoSpaces[MAX_LOCATION];
2602 char fixedModuleName[MAX_FILENAME];
2603 char fixedConfigName[MAX_FILENAME];
2605 int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2606 // Non-zero if we're building eC code
2607 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2608 int numCObjects = 0;
2610 int numRCObjects = 0;
2611 bool containsCXX = false; // True if the project contains a C++ file
2612 bool relObjDir, sameOrRelObjTargetDirs;
2613 String objDirExp = GetObjDirExpression(config);
2614 TargetTypes targetType = GetTargetType(config);
2616 char cfDir[MAX_LOCATION];
2617 int objectsParts = 0;
2618 int eCsourcesParts = 0;
2619 int rcSourcesParts = 0;
2620 Array<String> listItems { };
2621 Map<String, int> varStringLenDiffs { };
2622 Map<String, NameCollisionInfo> namesInfo { };
2624 Map<String, int> cflagsVariations { };
2625 Map<intptr, int> nodeCFlagsMapping { };
2627 Map<String, int> ecflagsVariations { };
2628 Map<intptr, int> nodeECFlagsMapping { };
2630 ReplaceSpaces(objDirNoSpaces, objDirExp);
2631 strcpy(targetDir, GetTargetDirExpression(config));
2632 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2634 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2635 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2637 char temp[MAX_LOCATION];
2638 ReplaceSpaces(temp, objDirExpNoSpaces);
2639 strcpy(objDirExpNoSpaces, temp);
2641 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2642 ReplaceSpaces(fixedModuleName, moduleName);
2643 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2644 CamelCase(fixedConfigName);
2646 lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2647 relObjDir = lenObjDirExpNoSpaces == 0 ||
2648 (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2649 lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2650 sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2651 (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2652 !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2654 f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2656 f.Puts("# CORE VARIABLES\n\n");
2658 f.Printf("MODULE := %s\n", fixedModuleName);
2659 f.Printf("VERSION := %s\n", property::moduleVersion);
2660 f.Printf("CONFIG := %s\n", fixedConfigName);
2661 f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2664 test = GetTargetTypeIsSetByPlatform(config);
2668 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2670 TargetTypes targetType;
2671 PlatformOptions projectPOs, configPOs;
2672 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2673 targetType = platformTargetType;
2679 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2680 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2685 f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2690 for(c = 0; c < ifCount; c++)
2696 f.Puts("# FLAGS\n\n");
2698 f.Puts("ECFLAGS =\n");
2699 f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2700 f.Puts("PRJ_CFLAGS =\n");
2701 f.Puts("CECFLAGS =\n");
2702 f.Puts("OFLAGS =\n");
2706 f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2709 // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2710 //f.Puts("ifdef EXECUTABLE_TARGET\n");
2711 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2712 //f.Puts("endif\n");
2715 f.Puts("# INCLUDES\n\n");
2717 if(compilerConfigsDir && compilerConfigsDir[0])
2719 strcpy(cfDir, compilerConfigsDir);
2720 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2725 GetIDECompilerConfigsDir(cfDir, true, true);
2726 // Use CF_DIR environment variable for absolute paths only
2727 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2728 strcpy(cfDir, "$(CF_DIR)");
2731 f.Printf("_CF_DIR = %s\n", cfDir);
2734 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2735 f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2738 f.Puts("# POST-INCLUDES VARIABLES\n\n");
2740 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2743 f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2746 // test = GetTargetTypeIsSetByPlatform(config);
2748 char target[MAX_LOCATION];
2749 char temp[MAX_LOCATION];
2754 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2756 if(type != targetType)
2761 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2763 GetMakefileTargetFileName(type, target, config);
2764 strcpy(temp, targetDir);
2765 PathCatSlash(temp, target);
2766 ReplaceSpaces(target, temp);
2767 f.Printf("TARGET = %s\n", target);
2772 GetMakefileTargetFileName(targetType, target, config);
2773 strcpy(temp, targetDir);
2774 PathCatSlash(temp, target);
2775 ReplaceSpaces(target, temp);
2776 f.Printf("TARGET = %s\n", target);
2782 for(c = 0; c < ifCount; c++)
2789 // Use something fixed here, to not cause Makefile differences across compilers...
2790 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2791 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2793 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2797 char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2799 numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2802 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2804 f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2805 if(eCsourcesParts > 1)
2807 for(c = 1; c <= eCsourcesParts; c++)
2808 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2812 for(c = 0; c < 5; c++)
2814 if(eCsourcesParts > 1)
2817 f.Printf("_%s =", map[c][0]);
2818 for(n = 1; n <= eCsourcesParts; n++)
2819 f.Printf(" $(%s%d)", map[c][0], n);
2821 for(n = 1; n <= eCsourcesParts; n++)
2822 f.Printf("_%s%d = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d))))\n", map[c][0], n, map[c][1], n);
2824 else if(eCsourcesParts == 1)
2825 f.Printf("_%s = $(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES))))\n", map[c][0], map[c][1]);
2829 for(c = 0; c < 5; c++)
2831 if(eCsourcesParts > 1)
2834 f.Printf("%s =", map[c][0]);
2835 for(n = 1; n <= eCsourcesParts; n++)
2836 f.Printf(" $(%s%d)", map[c][0], n);
2838 for(n = 1; n <= eCsourcesParts; n++)
2839 f.Printf("%s%d = $(call shwspace,$(_%s%d))\n", map[c][0], n, map[c][0], n);
2841 else if(eCsourcesParts == 1)
2842 f.Printf("%s = $(call shwspace,$(_%s))\n", map[c][0], map[c][0]);
2848 numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2851 f.Puts("ifdef WINDOWS_TARGET\n\n");
2853 rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2855 f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2856 if(rcSourcesParts > 1)
2858 for(c = 1; c <= rcSourcesParts; c++)
2859 f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2862 if(rcSourcesParts > 1)
2865 f.Printf("%s =", "RCOBJECTS");
2866 for(n = 1; n <= rcSourcesParts; n++)
2867 f.Printf(" $(%s%d)", "RCOBJECTS", n);
2869 for(n = 1; n <= rcSourcesParts; n++)
2870 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2872 else if(rcSourcesParts == 1)
2873 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2877 f.Puts("RCSOURCES =\n");
2878 f.Puts("RCOBJECTS =\n");
2879 f.Puts("endif\n\n");
2882 numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2884 objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2885 f.Printf("OBJECTS =%s%s%s%s\n",
2886 numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2887 numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2888 numRCObjects ? " $(RCOBJECTS)" : "");
2891 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2894 if(numCObjects && numRCObjects)
2895 prefix = "$(ECSOURCES) $(RCSOURCES)";
2896 else if(numCObjects)
2897 prefix = "$(ECSOURCES)";
2900 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2904 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2905 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2907 f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2909 if((config && config.options && config.options.libraries) ||
2910 (options && options.libraries))
2912 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2914 if(config && config.options && config.options.libraries)
2915 OutputLibraries(f, config.options.libraries);
2916 else if(options && options.libraries)
2917 OutputLibraries(f, options.libraries);
2923 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects != 0,
2924 cflagsVariations, nodeCFlagsMapping,
2925 ecflagsVariations, nodeECFlagsMapping, null);
2927 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2928 f.Puts("ECFLAGS += -module $(MODULE)\n");
2929 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2931 if(platforms || (config && config.platforms))
2934 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2935 //for(platform = win32; platform <= apple; platform++)
2937 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2938 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2940 PlatformOptions projectPlatformOptions, configPlatformOptions;
2941 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2943 if(projectPlatformOptions || configPlatformOptions)
2948 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2951 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2952 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2954 f.Puts("CFLAGS +=");
2955 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2958 for(s : projectPlatformOptions.options.compilerOptions)
2961 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2964 for(s : configPlatformOptions.options.compilerOptions)
2971 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2972 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2974 f.Puts("OFLAGS +=");
2975 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2977 bool needWl = false;
2979 for(s : projectPlatformOptions.options.linkerOptions)
2981 if(!IsLinkerOption(s))
2989 for(s : projectPlatformOptions.options.linkerOptions)
2990 if(IsLinkerOption(s))
2994 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2996 bool needWl = false;
2998 for(s : configPlatformOptions.options.linkerOptions)
3000 if(IsLinkerOption(s))
3008 for(s : configPlatformOptions.options.linkerOptions)
3009 if(!IsLinkerOption(s))
3017 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3018 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
3019 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
3020 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
3022 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3023 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3024 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
3026 f.Puts("OFLAGS +=");
3027 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
3028 OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
3029 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
3030 OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
3034 if(configPlatformOptions && configPlatformOptions.options.libraries)
3036 if(configPlatformOptions.options.libraries.count)
3039 OutputLibraries(f, configPlatformOptions.options.libraries);
3043 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3045 if(projectPlatformOptions.options.libraries.count)
3048 OutputLibraries(f, projectPlatformOptions.options.libraries);
3059 for(c = 0; c < ifCount; c++)
3065 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3066 (options && options.compilerOptions && options.compilerOptions.count))
3068 f.Puts("CFLAGS +=");
3071 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3073 for(s : config.options.compilerOptions)
3076 if(options && options.compilerOptions && options.compilerOptions.count)
3078 for(s : options.compilerOptions)
3085 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3086 (options && options.linkerOptions && options.linkerOptions.count))
3088 f.Puts("OFLAGS +=");
3091 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3093 bool needWl = false;
3094 for(s : config.options.linkerOptions)
3096 if(!IsLinkerOption(s))
3104 for(s : config.options.linkerOptions)
3105 if(IsLinkerOption(s))
3109 if(options && options.linkerOptions && options.linkerOptions.count)
3111 bool needWl = false;
3112 for(s : options.linkerOptions)
3114 if(!IsLinkerOption(s))
3122 for(s : options.linkerOptions)
3123 if(IsLinkerOption(s))
3131 f.Puts("CECFLAGS += -cpp $(_CPP)");
3135 if(GetProfile(config))
3136 f.Puts("OFLAGS += -pg\n\n");
3138 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3140 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3141 f.Puts("OFLAGS +=");
3142 if(config && config.options && config.options.libraryDirs)
3143 OutputFlags(f, _L, config.options.libraryDirs, lineEach);
3144 if(options && options.libraryDirs)
3145 OutputFlags(f, _L, options.libraryDirs, lineEach);
3151 f.Puts("# TARGETS\n");
3154 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3157 f.Puts("objdir:\n");
3159 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3162 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");
3163 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");
3165 //f.Puts("# PRE-BUILD COMMANDS\n");
3166 if(options && options.prebuildCommands)
3168 for(s : options.prebuildCommands)
3169 if(s && s[0]) f.Printf("\t%s\n", s);
3171 if(config && config.options && config.options.prebuildCommands)
3173 for(s : config.options.prebuildCommands)
3174 if(s && s[0]) f.Printf("\t%s\n", s);
3176 if(platforms || (config && config.platforms))
3179 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3180 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3182 PlatformOptions projectPOs, configPOs;
3183 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3185 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3186 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3191 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3193 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3195 for(s : projectPOs.options.prebuildCommands)
3196 if(s && s[0]) f.Printf("\t%s\n", s);
3198 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3200 for(s : configPOs.options.prebuildCommands)
3201 if(s && s[0]) f.Printf("\t%s\n", s);
3208 for(c = 0; c < ifCount; c++)
3214 if(!sameOrRelObjTargetDirs)
3216 f.Puts("targetdir:\n");
3217 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3223 // Main Module (Linking) for ECERE C modules
3224 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3225 f.Printf("\t@$(call rmq,$(OBJ)symbols.lst)\n");
3226 f.Printf("\t@$(call touch,$(OBJ)symbols.lst)\n");
3227 OutputFileListActions(f, "SYMBOLS", eCsourcesParts, "$(OBJ)symbols.lst");
3228 OutputFileListActions(f, "IMPORTS", eCsourcesParts, "$(OBJ)symbols.lst");
3229 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3230 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) @$(OBJ)symbols.lst -symbols %s -o $(call quote_path,$@)\n",
3231 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3233 // Main Module (Linking) for ECERE C modules
3234 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3235 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3236 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3237 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3238 " -c $(OBJ)$(MODULE).main.ec -o $(call quote_path,$@) -symbols $(OBJ)\n");
3244 // This would not rebuild the target on updated objects
3245 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3247 // This should fix it for good!
3248 f.Puts("$(SYMBOLS): | objdir\n");
3249 f.Puts("$(OBJECTS): | objdir\n");
3251 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3252 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3253 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3255 f.Printf("\t@$(call rmq,$(OBJ)objects.lst)\n");
3256 f.Printf("\t@$(call touch,$(OBJ)objects.lst)\n");
3257 OutputFileListActions(f, "_OBJECTS", objectsParts, "$(OBJ)objects.lst");
3260 f.Puts("ifdef WINDOWS_TARGET\n");
3261 OutputFileListActions(f, "RCOBJECTS", rcSourcesParts, "$(OBJ)objects.lst");
3266 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)objects.lst\n");
3267 OutputFileListActions(f, "ECOBJECTS", eCsourcesParts, "$(OBJ)objects.lst");
3270 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3272 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)objects.lst $(LIBS) -o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC");
3273 if(!GetDebug(config))
3275 f.Puts("ifndef NOSTRIP\n");
3276 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3279 if(GetCompress(config))
3281 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3282 f.Puts("ifdef EXECUTABLE_TARGET\n");
3283 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3286 //f.Puts("ifneq \"$(TARGET_ARCH)\" \"x86_64\"\n");
3287 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3288 //f.Puts("endif\n");
3292 if(resNode.files && resNode.files.count && !noResources)
3293 resNode.GenMakefileAddResources(f, resNode.path, config);
3295 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)objects.lst $(LIBS)\n");
3297 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3298 f.Puts("ifdef LINUX_TARGET\n");
3299 f.Puts("ifdef LINUX_HOST\n");
3300 // TODO?: support symlinks for longer version numbers
3301 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3302 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3307 //f.Puts("# POST-BUILD COMMANDS\n");
3308 if(options && options.postbuildCommands)
3310 for(s : options.postbuildCommands)
3311 if(s && s[0]) f.Printf("\t%s\n", s);
3313 if(config && config.options && config.options.postbuildCommands)
3315 for(s : config.options.postbuildCommands)
3316 if(s && s[0]) f.Printf("\t%s\n", s);
3318 if(platforms || (config && config.platforms))
3321 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3322 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3324 PlatformOptions projectPOs, configPOs;
3325 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3327 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3328 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3333 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3335 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3337 for(s : projectPOs.options.postbuildCommands)
3338 if(s && s[0]) f.Printf("\t%s\n", s);
3340 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3342 for(s : configPOs.options.postbuildCommands)
3343 if(s && s[0]) f.Printf("\t%s\n", s);
3350 for(c = 0; c < ifCount; c++)
3357 if(platforms || (config && config.platforms))
3359 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3361 PlatformOptions projectPOs, configPOs;
3362 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3364 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3365 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3372 if(test || (options && options.installCommands) ||
3373 (config && config.options && config.options.installCommands))
3375 f.Puts("install:\n");
3376 if(options && options.installCommands)
3378 for(s : options.installCommands)
3379 if(s && s[0]) f.Printf("\t%s\n", s);
3381 if(config && config.options && config.options.installCommands)
3383 for(s : config.options.installCommands)
3384 if(s && s[0]) f.Printf("\t%s\n", s);
3386 if(platforms || (config && config.platforms))
3389 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3391 PlatformOptions projectPOs, configPOs;
3392 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3394 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3395 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3400 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3402 if(projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count)
3404 for(s : projectPOs.options.installCommands)
3405 if(s && s[0]) f.Printf("\t%s\n", s);
3407 if(configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count)
3409 for(s : configPOs.options.installCommands)
3410 if(s && s[0]) f.Printf("\t%s\n", s);
3417 for(c = 0; c < ifCount; c++)
3424 f.Puts("# SYMBOL RULES\n");
3427 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3429 f.Puts("# C OBJECT RULES\n");
3432 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3434 f.Puts("# OBJECT RULES\n");
3436 // todo call this still but only generate rules whith specific options
3437 // see we-have-file-specific-options in ProjectNode.ec
3438 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3441 GenMakefilePrintMainObjectRule(f, config);
3443 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3446 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)");
3447 f.Printf("\t$(call rmq,$(OBJ)symbols.lst)\n");
3449 f.Printf("\t$(call rmq,$(OBJ)objects.lst)\n");
3450 f.Puts("\t$(call rmq,$(TARGET))\n");
3451 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3452 f.Puts("ifdef LINUX_TARGET\n");
3453 f.Puts("ifdef LINUX_HOST\n");
3454 // TODO?: support symlinks for longer version numbers
3455 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3456 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3462 f.Puts("clean: cleantarget\n");
3463 OutputCleanActions(f, "OBJECTS", objectsParts);
3466 f.Puts("ifdef WINDOWS_TARGET\n");
3467 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3472 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3473 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3474 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3475 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3476 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3480 f.Puts("realclean: cleantarget\n");
3481 f.Puts("\t$(call rmrq,$(OBJ))\n");
3482 if(!sameOrRelObjTargetDirs)
3483 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3486 f.Puts("distclean: cleantarget\n");
3487 if(!sameOrRelObjTargetDirs)
3488 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3490 f.Puts("\t$(call rmrq,obj/)\n");
3496 varStringLenDiffs.Free();
3497 delete varStringLenDiffs;
3501 delete cflagsVariations;
3502 delete nodeCFlagsMapping;
3503 delete ecflagsVariations;
3504 delete nodeECFlagsMapping;
3509 // ChangeWorkingDir(oldDirectory);
3510 // delete pathBackup;
3513 config.makingModified = false;
3517 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3519 char extension[MAX_EXTENSION] = "c";
3520 char modulePath[MAX_LOCATION];
3521 char fixedModuleName[MAX_FILENAME];
3524 char objDirNoSpaces[MAX_LOCATION];
3525 String objDirExp = GetObjDirExpression(config);
3527 ReplaceSpaces(objDirNoSpaces, objDirExp);
3528 ReplaceSpaces(fixedModuleName, moduleName);
3530 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3531 //strcat(fixedModuleName, ".main");
3533 #if 0 // TODO: Fix nospaces stuff
3534 // *** Dependency command ***
3535 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3537 // System Includes (from global settings)
3538 for(item : compiler.dirs[Includes])
3540 strcat(command, " -isystem ");
3541 if(strchr(item.name, ' '))
3543 strcat(command, "\"");
3544 strcat(command, item);
3545 strcat(command, "\"");
3548 strcat(command, item);
3551 for(item = includeDirs.first; item; item = item.next)
3553 strcat(command, " -I");
3554 if(strchr(item.name, ' '))
3556 strcat(command, "\"");
3557 strcat(command, item.name);
3558 strcat(command, "\"");
3561 strcat(command, item.name);
3563 for(item = preprocessorDefs.first; item; item = item.next)
3565 strcat(command, " -D");
3566 strcat(command, item.name);
3570 if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
3574 bool firstLine = true;
3576 // To do some time: auto save external dependencies?
3579 if(dep.GetLine(line, sizeof(line)-1))
3583 char * colon = strstr(line, ":");
3584 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3598 // If we failed to generate dependencies...
3602 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3603 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(call quote_path,$@)\n", extension);
3611 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3614 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3616 for(v : cflagsVariations)
3621 f.Printf("%s +=", variableName);
3623 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3624 f.Puts(&v ? &v : "");
3632 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3633 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3635 *projectPlatformOptions = null;
3636 *configPlatformOptions = null;
3641 if(!strcmpi(p.name, platform))
3643 *projectPlatformOptions = p;
3648 if(config && config.platforms)
3650 for(p : config.platforms)
3652 if(!strcmpi(p.name, platform))
3654 *configPlatformOptions = p;
3662 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3664 char * cfgName = cfg ? cfg.name : "";
3665 Map<String, NameCollisionInfo> cfgNameCollisions = prj.configsNameCollisions[cfgName];
3666 if(cfgNameCollisions)
3668 cfgNameCollisions.Free();
3669 delete cfgNameCollisions;
3671 prj.configsNameCollisions[cfgName] = cfgNameCollisions = { };
3672 prj.topNode.GenMakefileGetNameCollisionInfo(cfgNameCollisions, cfg);
3675 Project LegacyBinaryLoadProject(File f, char * filePath)
3677 Project project = null;
3678 char signature[sizeof(epjSignature)];
3680 f.Read(signature, sizeof(signature), 1);
3681 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3683 char topNodePath[MAX_LOCATION];
3684 /*ProjectConfig newConfig
3686 name = CopyString("Default");
3687 makingModified = true;
3688 compilingModified = true;
3689 linkingModified = true;
3693 project = Project { options = { } };
3694 LegacyBinaryLoadNode(project.topNode, f);
3695 delete project.topNode.path;
3696 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3697 MakeSlashPath(topNodePath);
3699 PathCatSlash(topNodePath, filePath);
3700 project.filePath = topNodePath;
3702 /* THIS IS ALREADY DONE BY filePath property
3703 StripLastDirectory(topNodePath, topNodePath);
3704 project.topNode.path = CopyString(topNodePath);
3706 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3708 // newConfig.options.defaultNameSpace = "";
3709 /*newConfig.objDir.dir = "obj";
3710 newConfig.targetDir.dir = "";*/
3712 //project.configurations = { [ newConfig ] };
3713 //project.config = newConfig;
3720 String targetFileName, targetDirectory, objectsDirectory;
3722 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3723 f.Read(&temp, sizeof(int),1);
3726 case 0: project.options.targetType = executable; break;
3727 case 1: project.options.targetType = sharedLibrary; break;
3728 case 2: project.options.targetType = staticLibrary; break;
3731 f.Read(&len, sizeof(int),1);
3732 targetFileName = new char[len+1];
3733 f.Read(targetFileName, sizeof(char), len+1);
3734 project.options.targetFileName = targetFileName;
3735 delete targetFileName;
3737 f.Read(&len, sizeof(int),1);
3738 targetDirectory = new char[len+1];
3739 f.Read(targetDirectory, sizeof(char), len+1);
3740 project.options.targetDirectory = targetDirectory;
3741 delete targetDirectory;
3743 f.Read(&len, sizeof(int),1);
3744 objectsDirectory = new byte[len+1];
3745 f.Read(objectsDirectory, sizeof(char), len+1);
3746 project.options.objectsDirectory = objectsDirectory;
3747 delete objectsDirectory;
3749 f.Read(&temp, sizeof(int),1);
3750 project./*config.*/options.debug = temp ? true : false;
3751 f.Read(&temp, sizeof(int),1);
3752 project./*config.*/options.optimization = temp ? speed : none;
3753 f.Read(&temp, sizeof(int),1);
3754 project./*config.*/options.profile = temp ? true : false;
3755 f.Read(&temp, sizeof(int),1);
3756 project.options.warnings = temp ? all : unset;
3758 f.Read(&count, sizeof(int),1);
3761 project.options.includeDirs = { };
3762 for(c = 0; c < count; c++)
3765 f.Read(&len, sizeof(int),1);
3766 name = new char[len+1];
3767 f.Read(name, sizeof(char), len+1);
3768 project.options.includeDirs.Add(name);
3772 f.Read(&count, sizeof(int),1);
3775 project.options.libraryDirs = { };
3776 for(c = 0; c < count; c++)
3779 f.Read(&len, sizeof(int),1);
3780 name = new char[len+1];
3781 f.Read(name, sizeof(char), len+1);
3782 project.options.libraryDirs.Add(name);
3786 f.Read(&count, sizeof(int),1);
3789 project.options.libraries = { };
3790 for(c = 0; c < count; c++)
3793 f.Read(&len, sizeof(int),1);
3794 name = new char[len+1];
3795 f.Read(name, sizeof(char), len+1);
3796 project.options.libraries.Add(name);
3800 f.Read(&count, sizeof(int),1);
3803 project.options.preprocessorDefinitions = { };
3804 for(c = 0; c < count; c++)
3807 f.Read(&len, sizeof(int),1);
3808 name = new char[len+1];
3809 f.Read(name, sizeof(char), len+1);
3810 project.options.preprocessorDefinitions.Add(name);
3814 f.Read(&temp, sizeof(int),1);
3815 project.options.console = temp ? true : false;
3818 for(node : project.topNode.files)
3820 if(node.type == resources)
3822 project.resNode = node;
3832 void ProjectConfig::LegacyProjectConfigLoad(File f)
3840 char subSection[128];
3846 f.GetLine(buffer, 65536 - 1);
3847 TrimLSpaces(buffer, buffer);
3848 TrimRSpaces(buffer, buffer);
3851 if(buffer[0] == '-')
3855 TrimLSpaces(equal, equal);
3856 if(!strcmpi(subSection, "LibraryDirs"))
3858 if(!options.libraryDirs)
3859 options.libraryDirs = { [ CopyString(equal) ] };
3861 options.libraryDirs.Add(CopyString(equal));
3863 else if(!strcmpi(subSection, "IncludeDirs"))
3865 if(!options.includeDirs)
3866 options.includeDirs = { [ CopyString(equal) ] };
3868 options.includeDirs.Add(CopyString(equal));
3871 else if(buffer[0] == '+')
3882 TrimLSpaces(equal, equal);
3883 delete name; name = CopyString(equal); // property::name = equal;
3886 else if(!strcmpi(buffer, "Compiler Options"))
3887 strcpy(section, buffer);
3888 else if(!strcmpi(buffer, "IncludeDirs"))
3889 strcpy(subSection, buffer);
3890 else if(!strcmpi(buffer, "Linker Options"))
3891 strcpy(section, buffer);
3892 else if(!strcmpi(buffer, "LibraryDirs"))
3893 strcpy(subSection, buffer);
3894 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3901 equal = strstr(buffer, "=");
3905 TrimRSpaces(buffer, buffer);
3907 TrimLSpaces(equal, equal);
3908 if(!strcmpi(buffer, "Target Name"))
3909 options.targetFileName = /*CopyString(*/equal/*)*/;
3910 else if(!strcmpi(buffer, "Target Type"))
3912 if(!strcmpi(equal, "Executable"))
3913 options.targetType = executable;
3914 else if(!strcmpi(equal, "Shared"))
3915 options.targetType = sharedLibrary;
3916 else if(!strcmpi(equal, "Static"))
3917 options.targetType = staticLibrary;
3919 options.targetType = executable;
3921 else if(!strcmpi(buffer, "Target Directory"))
3922 options.targetDirectory = /*CopyString(*/equal/*)*/;
3923 else if(!strcmpi(buffer, "Console"))
3924 options.console = ParseTrueFalseValue(equal);
3925 else if(!strcmpi(buffer, "Libraries"))
3927 if(!options.libraries) options.libraries = { };
3928 ParseArrayValue(options.libraries, equal);
3930 else if(!strcmpi(buffer, "Intermediate Directory"))
3931 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3932 else if(!strcmpi(buffer, "Debug"))
3933 options.debug = ParseTrueFalseValue(equal);
3934 else if(!strcmpi(buffer, "Optimize"))
3936 if(!strcmpi(equal, "None"))
3937 options.optimization = none;
3938 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3939 options.optimization = speed;
3940 else if(!strcmpi(equal, "Size"))
3941 options.optimization = size;
3943 options.optimization = none;
3945 else if(!strcmpi(buffer, "Compress"))
3946 options.compress = ParseTrueFalseValue(equal);
3947 else if(!strcmpi(buffer, "Profile"))
3948 options.profile = ParseTrueFalseValue(equal);
3949 else if(!strcmpi(buffer, "AllWarnings"))
3950 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3951 else if(!strcmpi(buffer, "MemoryGuard"))
3952 options.memoryGuard = ParseTrueFalseValue(equal);
3953 else if(!strcmpi(buffer, "Default Name Space"))
3954 options.defaultNameSpace = CopyString(equal);
3955 else if(!strcmpi(buffer, "Strict Name Spaces"))
3956 options.strictNameSpaces = ParseTrueFalseValue(equal);
3957 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3959 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3960 ParseArrayValue(options.preprocessorDefinitions, equal);
3966 if(!options.targetDirectory && options.objectsDirectory)
3967 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3968 //if(!objDir.dir) objDir.dir = "obj";
3969 //if(!targetDir.dir) targetDir.dir = "";
3970 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3971 // if(!defaultNameSpace) property::defaultNameSpace = "";
3972 makingModified = true;
3975 Project LegacyAsciiLoadProject(File f, char * filePath)
3977 Project project = null;
3978 ProjectNode node = null;
3980 char parentPath[MAX_LOCATION];
3981 char section[128] = "";
3982 char subSection[128] = "";
3984 bool configurationsPresent = false;
3994 f.GetLine(buffer, 65536 - 1);
3995 TrimLSpaces(buffer, buffer);
3996 TrimRSpaces(buffer, buffer);
3999 if(buffer[0] == '-' || buffer[0] == '=')
4001 bool simple = buffer[0] == '-';
4004 TrimLSpaces(equal, equal);
4005 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
4007 if(!project.config.options.libraryDirs)
4008 project.config.options.libraryDirs = { [ CopyString(equal) ] };
4010 project.config.options.libraryDirs.Add(CopyString(equal));
4012 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
4014 if(!project.config.options.includeDirs)
4015 project.config.options.includeDirs = { [ CopyString(equal) ] };
4017 project.config.options.includeDirs.Add(CopyString(equal));
4019 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4021 len = strlen(equal);
4024 char temp[MAX_LOCATION];
4025 ProjectNode child { };
4026 // We don't need to do this anymore, fileName is just a property that sets name & path
4027 // child.fileName = CopyString(equal);
4030 child.name = CopyString(equal);
4031 child.path = CopyString(parentPath);
4035 GetLastDirectory(equal, temp);
4036 child.name = CopyString(temp);
4037 StripLastDirectory(equal, temp);
4038 child.path = CopyString(temp);
4040 child.nodeType = file;
4041 child.parent = parent;
4042 child.indent = parent.indent + 1;
4044 child.icon = NodeIcons::SelectFileIcon(child.name);
4045 parent.files.Add(child);
4051 StripLastDirectory(parentPath, parentPath);
4052 parent = parent.parent;
4056 else if(buffer[0] == '+')
4060 TrimLSpaces(equal, equal);
4061 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4063 char temp[MAX_LOCATION];
4064 ProjectNode child { };
4065 // NEW: Folders now have a path set like files
4066 child.name = CopyString(equal);
4067 strcpy(temp, parentPath);
4068 PathCatSlash(temp, child.name);
4069 child.path = CopyString(temp);
4071 child.parent = parent;
4072 child.indent = parent.indent + 1;
4073 child.type = folder;
4074 child.nodeType = folder;
4076 child.icon = folder;
4077 PathCatSlash(parentPath, child.name);
4078 parent.files.Add(child);
4083 else if(!strcmpi(section, "Configurations"))
4085 ProjectConfig newConfig
4087 makingModified = true;
4091 LegacyProjectConfigLoad(newConfig, f);
4092 project.configurations.Add(newConfig);
4095 else if(!strcmpi(buffer, "ECERE Project File"));
4096 else if(!strcmpi(buffer, "Version 0a"))
4097 ; //strcpy(version, "0a");
4098 else if(!strcmpi(buffer, "Version 0.1a"))
4099 ; //strcpy(version, "0.1a");
4100 else if(!strcmpi(buffer, "Configurations"))
4102 project.configurations.Free();
4103 project.config = null;
4104 strcpy(section, buffer);
4105 configurationsPresent = true;
4107 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
4109 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
4110 char topNodePath[MAX_LOCATION];
4111 // newConfig.defaultNameSpace = "";
4112 //newConfig.objDir.dir = "obj";
4113 //newConfig.targetDir.dir = "";
4114 project = Project { /*options = { }*/ };
4115 project.configurations = { [ newConfig ] };
4116 project.config = newConfig;
4117 // if(project.topNode.path) delete project.topNode.path;
4118 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4119 MakeSlashPath(topNodePath);
4120 PathCatSlash(topNodePath, filePath);
4121 project.filePath = topNodePath;
4122 parentPath[0] = '\0';
4123 parent = project.topNode;
4125 strcpy(section, "Target");
4130 if(equal[0] == '\"')
4132 StripQuotes(equal, equal);
4133 delete project.moduleName; project.moduleName = CopyString(equal);
4137 else if(!strcmpi(buffer, "Compiler Options"));
4138 else if(!strcmpi(buffer, "IncludeDirs"))
4139 strcpy(subSection, buffer);
4140 else if(!strcmpi(buffer, "Linker Options"));
4141 else if(!strcmpi(buffer, "LibraryDirs"))
4142 strcpy(subSection, buffer);
4143 else if(!strcmpi(buffer, "Files"))
4145 strcpy(section, "Target");
4146 strcpy(subSection, buffer);
4148 else if(!strcmpi(buffer, "Resources"))
4150 ProjectNode child { };
4151 parent.files.Add(child);
4152 child.parent = parent;
4153 child.indent = parent.indent + 1;
4154 child.name = CopyString(buffer);
4155 child.path = CopyString("");
4156 child.type = resources;
4158 child.icon = archiveFile;
4159 project.resNode = child;
4162 strcpy(subSection, buffer);
4166 equal = strstr(buffer, "=");
4170 TrimRSpaces(buffer, buffer);
4172 TrimLSpaces(equal, equal);
4174 if(!strcmpi(section, "Target"))
4176 if(!strcmpi(buffer, "Build Exclusions"))
4178 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4180 /*if(node && node.type != NodeTypes::project)
4181 ParseListValue(node.buildExclusions, equal);*/
4184 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4186 delete project.resNode.path;
4187 project.resNode.path = CopyString(equal);
4188 PathCatSlash(parentPath, equal);
4192 else if(!strcmpi(buffer, "Intermediate Directory"))
4193 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4194 else if(!strcmpi(buffer, "Debug"))
4195 project.config.options.debug = ParseTrueFalseValue(equal);
4196 else if(!strcmpi(buffer, "Optimize"))
4198 if(!strcmpi(equal, "None"))
4199 project.config.options.optimization = none;
4200 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4201 project.config.options.optimization = speed;
4202 else if(!strcmpi(equal, "Size"))
4203 project.config.options.optimization = size;
4205 project.config.options.optimization = none;
4207 else if(!strcmpi(buffer, "Profile"))
4208 project.config.options.profile = ParseTrueFalseValue(equal);
4209 else if(!strcmpi(buffer, "MemoryGuard"))
4210 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4213 if(!project.options) project.options = { };
4215 // Project Wide Settings (All configs)
4216 if(!strcmpi(buffer, "Target Name"))
4217 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4218 else if(!strcmpi(buffer, "Target Type"))
4220 if(!strcmpi(equal, "Executable"))
4221 project.options.targetType = executable;
4222 else if(!strcmpi(equal, "Shared"))
4223 project.options.targetType = sharedLibrary;
4224 else if(!strcmpi(equal, "Static"))
4225 project.options.targetType = staticLibrary;
4227 project.options.targetType = executable;
4229 else if(!strcmpi(buffer, "Target Directory"))
4230 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4231 else if(!strcmpi(buffer, "Console"))
4232 project.options.console = ParseTrueFalseValue(equal);
4233 else if(!strcmpi(buffer, "Libraries"))
4235 if(!project.options.libraries) project.options.libraries = { };
4236 ParseArrayValue(project.options.libraries, equal);
4238 else if(!strcmpi(buffer, "AllWarnings"))
4239 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4240 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4242 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4244 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4245 ParseListValue(node.preprocessorDefs, equal);*/
4249 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4250 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4261 SplitPlatformLibraries(project);
4263 if(configurationsPresent)
4264 CombineIdenticalConfigOptions(project);
4268 void SplitPlatformLibraries(Project project)
4270 if(project && project.configurations)
4272 for(cfg : project.configurations)
4274 if(cfg.options.libraries && cfg.options.libraries.count)
4276 Iterator<String> it { cfg.options.libraries };
4280 char * platformName = strstr(l, ":");
4283 PlatformOptions platform = null;
4285 if(!cfg.platforms) cfg.platforms = { };
4286 for(p : cfg.platforms)
4288 if(!strcmpi(platformName, p.name))
4296 platform = { name = CopyString(platformName), options = { libraries = { } } };
4297 cfg.platforms.Add(platform);
4299 *(platformName-1) = 0;
4300 platform.options.libraries.Add(CopyString(l));
4302 cfg.options.libraries.Delete(it.pointer);
4311 void CombineIdenticalConfigOptions(Project project)
4313 if(project && project.configurations && project.configurations.count)
4316 ProjectOptions nullOptions { };
4317 ProjectConfig firstConfig = null;
4318 for(cfg : project.configurations)
4320 if(cfg.options.targetType != staticLibrary)
4327 firstConfig = project.configurations.firstIterator.data;
4329 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4331 if(!member.isProperty)
4333 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4338 for(cfg : project.configurations)
4340 if(cfg != firstConfig)
4342 if(cfg.options.targetType != staticLibrary)
4346 if(type.type == noHeadClass || type.type == normalClass)
4348 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4349 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4350 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4354 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4355 (byte *)firstConfig.options + member.offset + member._class.offset,
4356 (byte *)cfg.options + member.offset + member._class.offset);
4368 if(type.type == noHeadClass || type.type == normalClass)
4370 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4371 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4372 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4377 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4378 (byte *)firstConfig.options + member.offset + member._class.offset,
4379 (byte *)nullOptions + member.offset + member._class.offset))
4383 if(!project.options) project.options = { };
4385 /*if(type.type == noHeadClass || type.type == normalClass)
4387 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4388 (byte *)project.options + member.offset + member._class.offset,
4389 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4393 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4394 // TOFIX: ListBox::SetData / OnCopy mess
4395 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4396 (byte *)project.options + member.offset + member._class.offset,
4397 (type.typeSize > 4) ? address :
4398 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4399 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4400 (void *)*(byte *)address )));
4403 (byte *)project.options + member.offset + member._class.offset,
4404 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4406 for(cfg : project.configurations)
4408 if(cfg.options.targetType == staticLibrary)
4412 if(type.type == noHeadClass || type.type == normalClass)
4414 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4415 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4416 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4420 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4421 (byte *)firstConfig.options + member.offset + member._class.offset,
4422 (byte *)cfg.options + member.offset + member._class.offset);
4427 if(cfg != firstConfig)
4429 if(type.type == noHeadClass || type.type == normalClass)
4431 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4432 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4436 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4437 (byte *)cfg.options + member.offset + member._class.offset);
4439 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4442 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4449 // Compare Platform Specific Settings
4452 for(cfg : project.configurations)
4454 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4455 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4461 if(same && firstConfig.platforms)
4463 for(cfg : project.configurations)
4465 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4467 if(cfg != firstConfig)
4469 cfg.platforms = null;
4472 project.platforms = firstConfig.platforms;
4473 *&firstConfig.platforms = null;
4477 // Static libraries can't contain libraries
4478 for(cfg : project.configurations)
4480 if(cfg.options.targetType == staticLibrary)
4482 if(!cfg.options.libraries) cfg.options.libraries = { };
4483 cfg.options.libraries.Free();
4489 Project LoadProject(char * filePath, char * activeConfigName)
4491 Project project = null;
4492 File f = FileOpen(filePath, read);
4495 project = LegacyBinaryLoadProject(f, filePath);
4498 JSONParser parser { f = f };
4499 JSONResult result = parser.GetObject(class(Project), &project);
4502 char insidePath[MAX_LOCATION];
4504 delete project.topNode.files;
4505 if(!project.files) project.files = { };
4506 project.topNode.files = project.files;
4509 char topNodePath[MAX_LOCATION];
4510 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4511 MakeSlashPath(topNodePath);
4512 PathCatSlash(topNodePath, filePath);
4513 project.filePath = topNodePath;//filePath;
4516 project.topNode.FixupNode(insidePath);
4518 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4519 delete project.resNode.path;
4520 project.resNode.path = project.resourcesPath;
4521 project.resourcesPath = null;
4522 project.resNode.nodeType = (ProjectNodeType)-1;
4523 delete project.resNode.files;
4524 project.resNode.files = project.resources;
4525 project.files = null;
4526 project.resources = null;
4527 if(!project.configurations) project.configurations = { };
4529 project.resNode.FixupNode(insidePath);
4534 project = LegacyAsciiLoadProject(f, filePath);
4540 if(!project.options) project.options = { };
4541 if(activeConfigName && activeConfigName[0] && project.configurations)
4542 project.config = project.GetConfig(activeConfigName);
4543 if(!project.config && project.configurations)
4544 project.config = project.configurations.firstIterator.data;
4546 if(!project.resNode)
4548 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4551 if(!project.moduleName)
4552 project.moduleName = CopyString(project.name);
4553 if(project.config &&
4554 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4555 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4557 //delete project.config.options.targetFileName;
4559 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4560 project.config.options.optimization = none;
4561 project.config.options.debug = true;
4562 //project.config.options.warnings = unset;
4563 project.config.options.memoryGuard = false;
4564 project.config.compilingModified = true;
4565 project.config.linkingModified = true;
4567 else if(!project.topNode.name && project.config)
4569 project.topNode.name = CopyString(project.config.options.targetFileName);
4572 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4573 project.topNode.configurations = project.configurations;
4574 project.topNode.platforms = project.platforms;
4575 project.topNode.options = project.options;*/
4581 static GccVersionInfo GetGccVersionInfo(CompilerConfig compiler, String compilerCommand)
4583 GccVersionInfo result = unknown;
4584 if(compiler.ccCommand)
4586 char command[MAX_F_STRING*4];
4588 sprintf(command, "%s%s --version", compiler.gccPrefix ? compiler.gccPrefix : "", compilerCommand);
4589 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
4591 bool firstLine = true;
4596 if(f.GetLine(line,sizeof(line)))
4600 uint count = Tokenize(line, sizeof(tokens)/sizeof(tokens[0]), tokens,false);
4601 char * token = null;
4604 for(i = 0; i < count; i++)
4606 if(tokens[i][0] == '(')
4608 if(tokens[i][strlen(tokens[i])-1] != ')')
4611 else if(tokens[i][0] && tokens[i][strlen(tokens[i])-1] == ')')
4613 else if(!inPar && isdigit(tokens[i][0]) && strchr(tokens[i], '.'))
4617 result = GccVersionInfo::GetVersionInfo(token);
4628 static enum GccVersionInfo
4630 unknown, pre4_8, post4_8;
4632 GccVersionInfo ::GetVersionInfo(char * version)
4634 GccVersionInfo result = unknown;
4636 char * s = CopyString(version);
4638 uint count = TokenizeWith(s, sizeof(tokens)/sizeof(tokens[0]), tokens, ".", false);
4639 ver = count > 1 ? atoi(tokens[1]) : 0;
4640 ver += count ? atoi(tokens[0]) * 1000 : 0;